1 /* Declaration statement matcher
2 Copyright (C) 2002-2019 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"
27 #include "stringpool.h"
30 #include "constructor.h"
33 /* Macros to access allocate memory for gfc_data_variable,
34 gfc_data_value and gfc_data. */
35 #define gfc_get_data_variable() XCNEW (gfc_data_variable)
36 #define gfc_get_data_value() XCNEW (gfc_data_value)
37 #define gfc_get_data() XCNEW (gfc_data)
40 static bool set_binding_label (const char **, const char *, int);
43 /* This flag is set if an old-style length selector is matched
44 during a type-declaration statement. */
46 static int old_char_selector
;
48 /* When variables acquire types and attributes from a declaration
49 statement, they get them from the following static variables. The
50 first part of a declaration sets these variables and the second
51 part copies these into symbol structures. */
53 static gfc_typespec current_ts
;
55 static symbol_attribute current_attr
;
56 static gfc_array_spec
*current_as
;
57 static int colon_seen
;
60 /* The current binding label (if any). */
61 static const char* curr_binding_label
;
62 /* Need to know how many identifiers are on the current data declaration
63 line in case we're given the BIND(C) attribute with a NAME= specifier. */
64 static int num_idents_on_line
;
65 /* Need to know if a NAME= specifier was found during gfc_match_bind_c so we
66 can supply a name if the curr_binding_label is nil and NAME= was not. */
67 static int has_name_equals
= 0;
69 /* Initializer of the previous enumerator. */
71 static gfc_expr
*last_initializer
;
73 /* History of all the enumerators is maintained, so that
74 kind values of all the enumerators could be updated depending
75 upon the maximum initialized value. */
77 typedef struct enumerator_history
80 gfc_expr
*initializer
;
81 struct enumerator_history
*next
;
85 /* Header of enum history chain. */
87 static enumerator_history
*enum_history
= NULL
;
89 /* Pointer of enum history node containing largest initializer. */
91 static enumerator_history
*max_enum
= NULL
;
93 /* gfc_new_block points to the symbol of a newly matched block. */
95 gfc_symbol
*gfc_new_block
;
97 bool gfc_matching_function
;
99 /* Set upon parsing a !GCC$ unroll n directive for use in the next loop. */
100 int directive_unroll
= -1;
102 /* Map of middle-end built-ins that should be vectorized. */
103 hash_map
<nofree_string_hash
, int> *gfc_vectorized_builtins
;
105 /* If a kind expression of a component of a parameterized derived type is
106 parameterized, temporarily store the expression here. */
107 static gfc_expr
*saved_kind_expr
= NULL
;
109 /* Used to store the parameter list arising in a PDT declaration and
110 in the typespec of a PDT variable or component. */
111 static gfc_actual_arglist
*decl_type_param_list
;
112 static gfc_actual_arglist
*type_param_spec_list
;
114 /********************* DATA statement subroutines *********************/
116 static bool in_match_data
= false;
119 gfc_in_match_data (void)
121 return in_match_data
;
125 set_in_match_data (bool set_value
)
127 in_match_data
= set_value
;
130 /* Free a gfc_data_variable structure and everything beneath it. */
133 free_variable (gfc_data_variable
*p
)
135 gfc_data_variable
*q
;
140 gfc_free_expr (p
->expr
);
141 gfc_free_iterator (&p
->iter
, 0);
142 free_variable (p
->list
);
148 /* Free a gfc_data_value structure and everything beneath it. */
151 free_value (gfc_data_value
*p
)
158 mpz_clear (p
->repeat
);
159 gfc_free_expr (p
->expr
);
165 /* Free a list of gfc_data structures. */
168 gfc_free_data (gfc_data
*p
)
175 free_variable (p
->var
);
176 free_value (p
->value
);
182 /* Free all data in a namespace. */
185 gfc_free_data_all (gfc_namespace
*ns
)
197 /* Reject data parsed since the last restore point was marked. */
200 gfc_reject_data (gfc_namespace
*ns
)
204 while (ns
->data
&& ns
->data
!= ns
->old_data
)
212 static match
var_element (gfc_data_variable
*);
214 /* Match a list of variables terminated by an iterator and a right
218 var_list (gfc_data_variable
*parent
)
220 gfc_data_variable
*tail
, var
;
223 m
= var_element (&var
);
224 if (m
== MATCH_ERROR
)
229 tail
= gfc_get_data_variable ();
236 if (gfc_match_char (',') != MATCH_YES
)
239 m
= gfc_match_iterator (&parent
->iter
, 1);
242 if (m
== MATCH_ERROR
)
245 m
= var_element (&var
);
246 if (m
== MATCH_ERROR
)
251 tail
->next
= gfc_get_data_variable ();
257 if (gfc_match_char (')') != MATCH_YES
)
262 gfc_syntax_error (ST_DATA
);
267 /* Match a single element in a data variable list, which can be a
268 variable-iterator list. */
271 var_element (gfc_data_variable
*new_var
)
276 memset (new_var
, 0, sizeof (gfc_data_variable
));
278 if (gfc_match_char ('(') == MATCH_YES
)
279 return var_list (new_var
);
281 m
= gfc_match_variable (&new_var
->expr
, 0);
285 if (new_var
->expr
->expr_type
== EXPR_CONSTANT
286 && new_var
->expr
->symtree
== NULL
)
288 gfc_error ("Inquiry parameter cannot appear in a "
289 "data-stmt-object-list at %C");
293 sym
= new_var
->expr
->symtree
->n
.sym
;
295 /* Symbol should already have an associated type. */
296 if (!gfc_check_symbol_typed (sym
, gfc_current_ns
, false, gfc_current_locus
))
299 if (!sym
->attr
.function
&& gfc_current_ns
->parent
300 && gfc_current_ns
->parent
== sym
->ns
)
302 gfc_error ("Host associated variable %qs may not be in the DATA "
303 "statement at %C", sym
->name
);
307 if (gfc_current_state () != COMP_BLOCK_DATA
308 && sym
->attr
.in_common
309 && !gfc_notify_std (GFC_STD_GNU
, "initialization of "
310 "common block variable %qs in DATA statement at %C",
314 if (!gfc_add_data (&sym
->attr
, sym
->name
, &new_var
->expr
->where
))
321 /* Match the top-level list of data variables. */
324 top_var_list (gfc_data
*d
)
326 gfc_data_variable var
, *tail
, *new_var
;
333 m
= var_element (&var
);
336 if (m
== MATCH_ERROR
)
339 new_var
= gfc_get_data_variable ();
342 new_var
->expr
->where
= gfc_current_locus
;
347 tail
->next
= new_var
;
351 if (gfc_match_char ('/') == MATCH_YES
)
353 if (gfc_match_char (',') != MATCH_YES
)
360 gfc_syntax_error (ST_DATA
);
361 gfc_free_data_all (gfc_current_ns
);
367 match_data_constant (gfc_expr
**result
)
369 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
370 gfc_symbol
*sym
, *dt_sym
= NULL
;
375 m
= gfc_match_literal_constant (&expr
, 1);
382 if (m
== MATCH_ERROR
)
385 m
= gfc_match_null (result
);
389 old_loc
= gfc_current_locus
;
391 /* Should this be a structure component, try to match it
392 before matching a name. */
393 m
= gfc_match_rvalue (result
);
394 if (m
== MATCH_ERROR
)
397 if (m
== MATCH_YES
&& (*result
)->expr_type
== EXPR_STRUCTURE
)
399 if (!gfc_simplify_expr (*result
, 0))
403 else if (m
== MATCH_YES
)
405 /* If a parameter inquiry ends up here, symtree is NULL but **result
406 contains the right constant expression. Check here. */
407 if ((*result
)->symtree
== NULL
408 && (*result
)->expr_type
== EXPR_CONSTANT
409 && ((*result
)->ts
.type
== BT_INTEGER
410 || (*result
)->ts
.type
== BT_REAL
))
413 /* F2018:R845 data-stmt-constant is initial-data-target.
414 A data-stmt-constant shall be ... initial-data-target if and
415 only if the corresponding data-stmt-object has the POINTER
416 attribute. ... If data-stmt-constant is initial-data-target
417 the corresponding data statement object shall be
418 data-pointer-initialization compatible (7.5.4.6) with the initial
419 data target; the data statement object is initially associated
421 if ((*result
)->symtree
->n
.sym
->attr
.save
422 && (*result
)->symtree
->n
.sym
->attr
.target
)
424 gfc_free_expr (*result
);
427 gfc_current_locus
= old_loc
;
429 m
= gfc_match_name (name
);
433 if (gfc_find_symbol (name
, NULL
, 1, &sym
))
436 if (sym
&& sym
->attr
.generic
)
437 dt_sym
= gfc_find_dt_in_generic (sym
);
440 || (sym
->attr
.flavor
!= FL_PARAMETER
441 && (!dt_sym
|| !gfc_fl_struct (dt_sym
->attr
.flavor
))))
443 gfc_error ("Symbol %qs must be a PARAMETER in DATA statement at %C",
448 else if (dt_sym
&& gfc_fl_struct (dt_sym
->attr
.flavor
))
449 return gfc_match_structure_constructor (dt_sym
, result
);
451 /* Check to see if the value is an initialization array expression. */
452 if (sym
->value
->expr_type
== EXPR_ARRAY
)
454 gfc_current_locus
= old_loc
;
456 m
= gfc_match_init_expr (result
);
457 if (m
== MATCH_ERROR
)
462 if (!gfc_simplify_expr (*result
, 0))
465 if ((*result
)->expr_type
== EXPR_CONSTANT
)
469 gfc_error ("Invalid initializer %s in Data statement at %C", name
);
475 *result
= gfc_copy_expr (sym
->value
);
480 /* Match a list of values in a DATA statement. The leading '/' has
481 already been seen at this point. */
484 top_val_list (gfc_data
*data
)
486 gfc_data_value
*new_val
, *tail
;
494 m
= match_data_constant (&expr
);
497 if (m
== MATCH_ERROR
)
500 new_val
= gfc_get_data_value ();
501 mpz_init (new_val
->repeat
);
504 data
->value
= new_val
;
506 tail
->next
= new_val
;
510 if (expr
->ts
.type
!= BT_INTEGER
|| gfc_match_char ('*') != MATCH_YES
)
513 mpz_set_ui (tail
->repeat
, 1);
517 mpz_set (tail
->repeat
, expr
->value
.integer
);
518 gfc_free_expr (expr
);
520 m
= match_data_constant (&tail
->expr
);
523 if (m
== MATCH_ERROR
)
527 if (gfc_match_char ('/') == MATCH_YES
)
529 if (gfc_match_char (',') == MATCH_NO
)
536 gfc_syntax_error (ST_DATA
);
537 gfc_free_data_all (gfc_current_ns
);
542 /* Matches an old style initialization. */
545 match_old_style_init (const char *name
)
552 /* Set up data structure to hold initializers. */
553 gfc_find_sym_tree (name
, NULL
, 0, &st
);
556 newdata
= gfc_get_data ();
557 newdata
->var
= gfc_get_data_variable ();
558 newdata
->var
->expr
= gfc_get_variable_expr (st
);
559 newdata
->var
->expr
->where
= sym
->declared_at
;
560 newdata
->where
= gfc_current_locus
;
562 /* Match initial value list. This also eats the terminal '/'. */
563 m
= top_val_list (newdata
);
572 gfc_error ("Initialization at %C is not allowed in a PURE procedure");
576 gfc_unset_implicit_pure (gfc_current_ns
->proc_name
);
578 /* Mark the variable as having appeared in a data statement. */
579 if (!gfc_add_data (&sym
->attr
, sym
->name
, &sym
->declared_at
))
585 /* Chain in namespace list of DATA initializers. */
586 newdata
->next
= gfc_current_ns
->data
;
587 gfc_current_ns
->data
= newdata
;
593 /* Match the stuff following a DATA statement. If ERROR_FLAG is set,
594 we are matching a DATA statement and are therefore issuing an error
595 if we encounter something unexpected, if not, we're trying to match
596 an old-style initialization expression of the form INTEGER I /2/. */
599 gfc_match_data (void)
606 /* Before parsing the rest of a DATA statement, check F2008:c1206. */
607 if ((gfc_current_state () == COMP_FUNCTION
608 || gfc_current_state () == COMP_SUBROUTINE
)
609 && gfc_state_stack
->previous
->state
== COMP_INTERFACE
)
611 gfc_error ("DATA statement at %C cannot appear within an INTERFACE");
615 set_in_match_data (true);
619 new_data
= gfc_get_data ();
620 new_data
->where
= gfc_current_locus
;
622 m
= top_var_list (new_data
);
626 if (new_data
->var
->iter
.var
627 && new_data
->var
->iter
.var
->ts
.type
== BT_INTEGER
628 && new_data
->var
->iter
.var
->symtree
->n
.sym
->attr
.implied_index
== 1
629 && new_data
->var
->list
630 && new_data
->var
->list
->expr
631 && new_data
->var
->list
->expr
->ts
.type
== BT_CHARACTER
632 && new_data
->var
->list
->expr
->ref
633 && new_data
->var
->list
->expr
->ref
->type
== REF_SUBSTRING
)
635 gfc_error ("Invalid substring in data-implied-do at %L in DATA "
636 "statement", &new_data
->var
->list
->expr
->where
);
640 /* Check for an entity with an allocatable component, which is not
642 e
= new_data
->var
->expr
;
648 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
649 if ((ref
->type
== REF_COMPONENT
650 && ref
->u
.c
.component
->attr
.allocatable
)
651 || (ref
->type
== REF_ARRAY
652 && e
->symtree
->n
.sym
->attr
.pointer
!= 1
653 && ref
->u
.ar
.as
&& ref
->u
.ar
.as
->type
== AS_DEFERRED
))
658 gfc_error ("Allocatable component or deferred-shaped array "
659 "near %C in DATA statement");
663 /* F2008:C567 (R536) A data-i-do-object or a variable that appears
664 as a data-stmt-object shall not be an object designator in which
665 a pointer appears other than as the entire rightmost part-ref. */
667 if (e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
668 && e
->symtree
->n
.sym
->attr
.pointer
669 && ref
->type
== REF_COMPONENT
)
672 for (; ref
; ref
= ref
->next
)
673 if (ref
->type
== REF_COMPONENT
674 && ref
->u
.c
.component
->attr
.pointer
679 m
= top_val_list (new_data
);
683 new_data
->next
= gfc_current_ns
->data
;
684 gfc_current_ns
->data
= new_data
;
686 if (gfc_match_eos () == MATCH_YES
)
689 gfc_match_char (','); /* Optional comma */
692 set_in_match_data (false);
696 gfc_error ("DATA statement at %C is not allowed in a PURE procedure");
699 gfc_unset_implicit_pure (gfc_current_ns
->proc_name
);
705 gfc_error ("part-ref with pointer attribute near %L is not "
706 "rightmost part-ref of data-stmt-object",
710 set_in_match_data (false);
711 gfc_free_data (new_data
);
716 /************************ Declaration statements *********************/
719 /* Like gfc_match_init_expr, but matches a 'clist' (old-style initialization
720 list). The difference here is the expression is a list of constants
721 and is surrounded by '/'.
722 The typespec ts must match the typespec of the variable which the
723 clist is initializing.
724 The arrayspec tells whether this should match a list of constants
725 corresponding to array elements or a scalar (as == NULL). */
728 match_clist_expr (gfc_expr
**result
, gfc_typespec
*ts
, gfc_array_spec
*as
)
730 gfc_constructor_base array_head
= NULL
;
731 gfc_expr
*expr
= NULL
;
732 match m
= MATCH_ERROR
;
734 mpz_t repeat
, cons_size
, as_size
;
740 /* We have already matched '/' - now look for a constant list, as with
741 top_val_list from decl.c, but append the result to an array. */
742 if (gfc_match ("/") == MATCH_YES
)
744 gfc_error ("Empty old style initializer list at %C");
748 where
= gfc_current_locus
;
749 scalar
= !as
|| !as
->rank
;
751 if (!scalar
&& !spec_size (as
, &as_size
))
753 gfc_error ("Array in initializer list at %L must have an explicit shape",
754 as
->type
== AS_EXPLICIT
? &as
->upper
[0]->where
: &where
);
755 /* Nothing to cleanup yet. */
759 mpz_init_set_ui (repeat
, 0);
763 m
= match_data_constant (&expr
);
765 expr
= NULL
; /* match_data_constant may set expr to garbage */
768 if (m
== MATCH_ERROR
)
771 /* Found r in repeat spec r*c; look for the constant to repeat. */
772 if ( gfc_match_char ('*') == MATCH_YES
)
776 gfc_error ("Repeat spec invalid in scalar initializer at %C");
779 if (expr
->ts
.type
!= BT_INTEGER
)
781 gfc_error ("Repeat spec must be an integer at %C");
784 mpz_set (repeat
, expr
->value
.integer
);
785 gfc_free_expr (expr
);
788 m
= match_data_constant (&expr
);
792 gfc_error ("Expected data constant after repeat spec at %C");
797 /* No repeat spec, we matched the data constant itself. */
799 mpz_set_ui (repeat
, 1);
803 /* Add the constant initializer as many times as repeated. */
804 for (; mpz_cmp_ui (repeat
, 0) > 0; mpz_sub_ui (repeat
, repeat
, 1))
806 /* Make sure types of elements match */
807 if(ts
&& !gfc_compare_types (&expr
->ts
, ts
)
808 && !gfc_convert_type (expr
, ts
, 1))
811 gfc_constructor_append_expr (&array_head
,
812 gfc_copy_expr (expr
), &gfc_current_locus
);
815 gfc_free_expr (expr
);
819 /* For scalar initializers quit after one element. */
822 if(gfc_match_char ('/') != MATCH_YES
)
824 gfc_error ("End of scalar initializer expected at %C");
830 if (gfc_match_char ('/') == MATCH_YES
)
832 if (gfc_match_char (',') == MATCH_NO
)
836 /* If we break early from here out, we encountered an error. */
839 /* Set up expr as an array constructor. */
842 expr
= gfc_get_array_expr (ts
->type
, ts
->kind
, &where
);
844 expr
->value
.constructor
= array_head
;
846 expr
->rank
= as
->rank
;
847 expr
->shape
= gfc_get_shape (expr
->rank
);
849 /* Validate sizes. We built expr ourselves, so cons_size will be
850 constant (we fail above for non-constant expressions).
851 We still need to verify that the sizes match. */
852 gcc_assert (gfc_array_size (expr
, &cons_size
));
853 cmp
= mpz_cmp (cons_size
, as_size
);
855 gfc_error ("Not enough elements in array initializer at %C");
857 gfc_error ("Too many elements in array initializer at %C");
858 mpz_clear (cons_size
);
863 /* Make sure scalar types match. */
864 else if (!gfc_compare_types (&expr
->ts
, ts
)
865 && !gfc_convert_type (expr
, ts
, 1))
869 expr
->ts
.u
.cl
->length_from_typespec
= 1;
877 gfc_error ("Syntax error in old style initializer list at %C");
881 expr
->value
.constructor
= NULL
;
882 gfc_free_expr (expr
);
883 gfc_constructor_free (array_head
);
893 /* Auxiliary function to merge DIMENSION and CODIMENSION array specs. */
896 merge_array_spec (gfc_array_spec
*from
, gfc_array_spec
*to
, bool copy
)
900 if ((from
->type
== AS_ASSUMED_RANK
&& to
->corank
)
901 || (to
->type
== AS_ASSUMED_RANK
&& from
->corank
))
903 gfc_error ("The assumed-rank array at %C shall not have a codimension");
907 if (to
->rank
== 0 && from
->rank
> 0)
909 to
->rank
= from
->rank
;
910 to
->type
= from
->type
;
911 to
->cray_pointee
= from
->cray_pointee
;
912 to
->cp_was_assumed
= from
->cp_was_assumed
;
914 for (i
= 0; i
< to
->corank
; i
++)
916 /* Do not exceed the limits on lower[] and upper[]. gfortran
917 cleans up elsewhere. */
919 if (j
>= GFC_MAX_DIMENSIONS
)
922 to
->lower
[j
] = to
->lower
[i
];
923 to
->upper
[j
] = to
->upper
[i
];
925 for (i
= 0; i
< from
->rank
; i
++)
929 to
->lower
[i
] = gfc_copy_expr (from
->lower
[i
]);
930 to
->upper
[i
] = gfc_copy_expr (from
->upper
[i
]);
934 to
->lower
[i
] = from
->lower
[i
];
935 to
->upper
[i
] = from
->upper
[i
];
939 else if (to
->corank
== 0 && from
->corank
> 0)
941 to
->corank
= from
->corank
;
942 to
->cotype
= from
->cotype
;
944 for (i
= 0; i
< from
->corank
; i
++)
946 /* Do not exceed the limits on lower[] and upper[]. gfortran
947 cleans up elsewhere. */
949 if (j
>= GFC_MAX_DIMENSIONS
)
954 to
->lower
[j
] = gfc_copy_expr (from
->lower
[i
]);
955 to
->upper
[j
] = gfc_copy_expr (from
->upper
[i
]);
959 to
->lower
[j
] = from
->lower
[i
];
960 to
->upper
[j
] = from
->upper
[i
];
965 if (to
->rank
+ to
->corank
> GFC_MAX_DIMENSIONS
)
967 gfc_error ("Sum of array rank %d and corank %d at %C exceeds maximum "
968 "allowed dimensions of %d",
969 to
->rank
, to
->corank
, GFC_MAX_DIMENSIONS
);
970 to
->corank
= GFC_MAX_DIMENSIONS
- to
->rank
;
977 /* Match an intent specification. Since this can only happen after an
978 INTENT word, a legal intent-spec must follow. */
981 match_intent_spec (void)
984 if (gfc_match (" ( in out )") == MATCH_YES
)
986 if (gfc_match (" ( in )") == MATCH_YES
)
988 if (gfc_match (" ( out )") == MATCH_YES
)
991 gfc_error ("Bad INTENT specification at %C");
992 return INTENT_UNKNOWN
;
996 /* Matches a character length specification, which is either a
997 specification expression, '*', or ':'. */
1000 char_len_param_value (gfc_expr
**expr
, bool *deferred
)
1007 if (gfc_match_char ('*') == MATCH_YES
)
1010 if (gfc_match_char (':') == MATCH_YES
)
1012 if (!gfc_notify_std (GFC_STD_F2003
, "deferred type parameter at %C"))
1020 m
= gfc_match_expr (expr
);
1022 if (m
== MATCH_NO
|| m
== MATCH_ERROR
)
1025 if (!gfc_expr_check_typed (*expr
, gfc_current_ns
, false))
1028 if ((*expr
)->expr_type
== EXPR_FUNCTION
)
1030 if ((*expr
)->ts
.type
== BT_INTEGER
1031 || ((*expr
)->ts
.type
== BT_UNKNOWN
1032 && strcmp((*expr
)->symtree
->name
, "null") != 0))
1037 else if ((*expr
)->expr_type
== EXPR_CONSTANT
)
1039 /* F2008, 4.4.3.1: The length is a type parameter; its kind is
1040 processor dependent and its value is greater than or equal to zero.
1041 F2008, 4.4.3.2: If the character length parameter value evaluates
1042 to a negative value, the length of character entities declared
1045 if ((*expr
)->ts
.type
== BT_INTEGER
)
1047 if (mpz_cmp_si ((*expr
)->value
.integer
, 0) < 0)
1048 mpz_set_si ((*expr
)->value
.integer
, 0);
1053 else if ((*expr
)->expr_type
== EXPR_ARRAY
)
1055 else if ((*expr
)->expr_type
== EXPR_VARIABLE
)
1060 e
= gfc_copy_expr (*expr
);
1062 /* This catches the invalid code "[character(m(2:3)) :: 'x', 'y']",
1063 which causes an ICE if gfc_reduce_init_expr() is called. */
1064 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
1065 && e
->ref
->u
.ar
.type
== AR_UNKNOWN
1066 && e
->ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
)
1069 t
= gfc_reduce_init_expr (e
);
1071 if (!t
&& e
->ts
.type
== BT_UNKNOWN
1072 && e
->symtree
->n
.sym
->attr
.untyped
== 1
1073 && (flag_implicit_none
1074 || e
->symtree
->n
.sym
->ns
->seen_implicit_none
== 1
1075 || e
->symtree
->n
.sym
->ns
->parent
->seen_implicit_none
== 1))
1081 if ((e
->ref
&& e
->ref
->type
== REF_ARRAY
1082 && e
->ref
->u
.ar
.type
!= AR_ELEMENT
)
1083 || (!e
->ref
&& e
->expr_type
== EXPR_ARRAY
))
1095 gfc_error ("Scalar INTEGER expression expected at %L", &(*expr
)->where
);
1100 /* A character length is a '*' followed by a literal integer or a
1101 char_len_param_value in parenthesis. */
1104 match_char_length (gfc_expr
**expr
, bool *deferred
, bool obsolescent_check
)
1110 m
= gfc_match_char ('*');
1114 m
= gfc_match_small_literal_int (&length
, NULL
);
1115 if (m
== MATCH_ERROR
)
1120 if (obsolescent_check
1121 && !gfc_notify_std (GFC_STD_F95_OBS
, "Old-style character length at %C"))
1123 *expr
= gfc_get_int_expr (gfc_charlen_int_kind
, NULL
, length
);
1127 if (gfc_match_char ('(') == MATCH_NO
)
1130 m
= char_len_param_value (expr
, deferred
);
1131 if (m
!= MATCH_YES
&& gfc_matching_function
)
1133 gfc_undo_symbols ();
1137 if (m
== MATCH_ERROR
)
1142 if (gfc_match_char (')') == MATCH_NO
)
1144 gfc_free_expr (*expr
);
1152 gfc_error ("Syntax error in character length specification at %C");
1157 /* Special subroutine for finding a symbol. Check if the name is found
1158 in the current name space. If not, and we're compiling a function or
1159 subroutine and the parent compilation unit is an interface, then check
1160 to see if the name we've been given is the name of the interface
1161 (located in another namespace). */
1164 find_special (const char *name
, gfc_symbol
**result
, bool allow_subroutine
)
1170 i
= gfc_get_sym_tree (name
, NULL
, &st
, allow_subroutine
);
1173 *result
= st
? st
->n
.sym
: NULL
;
1177 if (gfc_current_state () != COMP_SUBROUTINE
1178 && gfc_current_state () != COMP_FUNCTION
)
1181 s
= gfc_state_stack
->previous
;
1185 if (s
->state
!= COMP_INTERFACE
)
1188 goto end
; /* Nameless interface. */
1190 if (strcmp (name
, s
->sym
->name
) == 0)
1201 /* Special subroutine for getting a symbol node associated with a
1202 procedure name, used in SUBROUTINE and FUNCTION statements. The
1203 symbol is created in the parent using with symtree node in the
1204 child unit pointing to the symbol. If the current namespace has no
1205 parent, then the symbol is just created in the current unit. */
1208 get_proc_name (const char *name
, gfc_symbol
**result
, bool module_fcn_entry
)
1214 /* Module functions have to be left in their own namespace because
1215 they have potentially (almost certainly!) already been referenced.
1216 In this sense, they are rather like external functions. This is
1217 fixed up in resolve.c(resolve_entries), where the symbol name-
1218 space is set to point to the master function, so that the fake
1219 result mechanism can work. */
1220 if (module_fcn_entry
)
1222 /* Present if entry is declared to be a module procedure. */
1223 rc
= gfc_find_symbol (name
, gfc_current_ns
->parent
, 0, result
);
1225 if (*result
== NULL
)
1226 rc
= gfc_get_symbol (name
, NULL
, result
);
1227 else if (!gfc_get_symbol (name
, NULL
, &sym
) && sym
1228 && (*result
)->ts
.type
== BT_UNKNOWN
1229 && sym
->attr
.flavor
== FL_UNKNOWN
)
1230 /* Pick up the typespec for the entry, if declared in the function
1231 body. Note that this symbol is FL_UNKNOWN because it will
1232 only have appeared in a type declaration. The local symtree
1233 is set to point to the module symbol and a unique symtree
1234 to the local version. This latter ensures a correct clearing
1237 /* If the ENTRY proceeds its specification, we need to ensure
1238 that this does not raise a "has no IMPLICIT type" error. */
1239 if (sym
->ts
.type
== BT_UNKNOWN
)
1240 sym
->attr
.untyped
= 1;
1242 (*result
)->ts
= sym
->ts
;
1244 /* Put the symbol in the procedure namespace so that, should
1245 the ENTRY precede its specification, the specification
1247 (*result
)->ns
= gfc_current_ns
;
1249 gfc_find_sym_tree (name
, gfc_current_ns
, 0, &st
);
1250 st
->n
.sym
= *result
;
1251 st
= gfc_get_unique_symtree (gfc_current_ns
);
1257 rc
= gfc_get_symbol (name
, gfc_current_ns
->parent
, result
);
1263 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1266 if (sym
->attr
.module_procedure
&& sym
->attr
.if_source
== IFSRC_IFBODY
)
1268 /* Create a partially populated interface symbol to carry the
1269 characteristics of the procedure and the result. */
1270 sym
->tlink
= gfc_new_symbol (name
, sym
->ns
);
1271 gfc_add_type (sym
->tlink
, &(sym
->ts
), &gfc_current_locus
);
1272 gfc_copy_attr (&sym
->tlink
->attr
, &sym
->attr
, NULL
);
1273 if (sym
->attr
.dimension
)
1274 sym
->tlink
->as
= gfc_copy_array_spec (sym
->as
);
1276 /* Ideally, at this point, a copy would be made of the formal
1277 arguments and their namespace. However, this does not appear
1278 to be necessary, albeit at the expense of not being able to
1279 use gfc_compare_interfaces directly. */
1281 if (sym
->result
&& sym
->result
!= sym
)
1283 sym
->tlink
->result
= sym
->result
;
1286 else if (sym
->result
)
1288 sym
->tlink
->result
= sym
->tlink
;
1291 else if (sym
&& !sym
->gfc_new
1292 && gfc_current_state () != COMP_INTERFACE
)
1294 /* Trap another encompassed procedure with the same name. All
1295 these conditions are necessary to avoid picking up an entry
1296 whose name clashes with that of the encompassing procedure;
1297 this is handled using gsymbols to register unique, globally
1298 accessible names. */
1299 if (sym
->attr
.flavor
!= 0
1300 && sym
->attr
.proc
!= 0
1301 && (sym
->attr
.subroutine
|| sym
->attr
.function
|| sym
->attr
.entry
)
1302 && sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
1304 gfc_error_now ("Procedure %qs at %C is already defined at %L",
1305 name
, &sym
->declared_at
);
1308 if (sym
->attr
.flavor
!= 0
1309 && sym
->attr
.entry
&& sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
1311 gfc_error_now ("Procedure %qs at %C is already defined at %L",
1312 name
, &sym
->declared_at
);
1316 if (sym
->attr
.external
&& sym
->attr
.procedure
1317 && gfc_current_state () == COMP_CONTAINS
)
1319 gfc_error_now ("Contained procedure %qs at %C clashes with "
1320 "procedure defined at %L",
1321 name
, &sym
->declared_at
);
1325 /* Trap a procedure with a name the same as interface in the
1326 encompassing scope. */
1327 if (sym
->attr
.generic
!= 0
1328 && (sym
->attr
.subroutine
|| sym
->attr
.function
)
1329 && !sym
->attr
.mod_proc
)
1331 gfc_error_now ("Name %qs at %C is already defined"
1332 " as a generic interface at %L",
1333 name
, &sym
->declared_at
);
1337 /* Trap declarations of attributes in encompassing scope. The
1338 signature for this is that ts.kind is set. Legitimate
1339 references only set ts.type. */
1340 if (sym
->ts
.kind
!= 0
1341 && !sym
->attr
.implicit_type
1342 && sym
->attr
.proc
== 0
1343 && gfc_current_ns
->parent
!= NULL
1344 && sym
->attr
.access
== 0
1345 && !module_fcn_entry
)
1347 gfc_error_now ("Procedure %qs at %C has an explicit interface "
1348 "from a previous declaration", name
);
1353 /* C1246 (R1225) MODULE shall appear only in the function-stmt or
1354 subroutine-stmt of a module subprogram or of a nonabstract interface
1355 body that is declared in the scoping unit of a module or submodule. */
1356 if (sym
->attr
.external
1357 && (sym
->attr
.subroutine
|| sym
->attr
.function
)
1358 && sym
->attr
.if_source
== IFSRC_IFBODY
1359 && !current_attr
.module_procedure
1360 && sym
->attr
.proc
== PROC_MODULE
1361 && gfc_state_stack
->state
== COMP_CONTAINS
)
1363 gfc_error_now ("Procedure %qs defined in interface body at %L "
1364 "clashes with internal procedure defined at %C",
1365 name
, &sym
->declared_at
);
1369 if (sym
&& !sym
->gfc_new
1370 && sym
->attr
.flavor
!= FL_UNKNOWN
1371 && sym
->attr
.referenced
== 0 && sym
->attr
.subroutine
== 1
1372 && gfc_state_stack
->state
== COMP_CONTAINS
1373 && gfc_state_stack
->previous
->state
== COMP_SUBROUTINE
)
1375 gfc_error_now ("Procedure %qs at %C is already defined at %L",
1376 name
, &sym
->declared_at
);
1380 if (gfc_current_ns
->parent
== NULL
|| *result
== NULL
)
1383 /* Module function entries will already have a symtree in
1384 the current namespace but will need one at module level. */
1385 if (module_fcn_entry
)
1387 /* Present if entry is declared to be a module procedure. */
1388 rc
= gfc_find_sym_tree (name
, gfc_current_ns
->parent
, 0, &st
);
1390 st
= gfc_new_symtree (&gfc_current_ns
->parent
->sym_root
, name
);
1393 st
= gfc_new_symtree (&gfc_current_ns
->sym_root
, name
);
1398 /* See if the procedure should be a module procedure. */
1400 if (((sym
->ns
->proc_name
!= NULL
1401 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
1402 && sym
->attr
.proc
!= PROC_MODULE
)
1403 || (module_fcn_entry
&& sym
->attr
.proc
!= PROC_MODULE
))
1404 && !gfc_add_procedure (&sym
->attr
, PROC_MODULE
, sym
->name
, NULL
))
1411 /* Verify that the given symbol representing a parameter is C
1412 interoperable, by checking to see if it was marked as such after
1413 its declaration. If the given symbol is not interoperable, a
1414 warning is reported, thus removing the need to return the status to
1415 the calling function. The standard does not require the user use
1416 one of the iso_c_binding named constants to declare an
1417 interoperable parameter, but we can't be sure if the param is C
1418 interop or not if the user doesn't. For example, integer(4) may be
1419 legal Fortran, but doesn't have meaning in C. It may interop with
1420 a number of the C types, which causes a problem because the
1421 compiler can't know which one. This code is almost certainly not
1422 portable, and the user will get what they deserve if the C type
1423 across platforms isn't always interoperable with integer(4). If
1424 the user had used something like integer(c_int) or integer(c_long),
1425 the compiler could have automatically handled the varying sizes
1426 across platforms. */
1429 gfc_verify_c_interop_param (gfc_symbol
*sym
)
1431 int is_c_interop
= 0;
1434 /* We check implicitly typed variables in symbol.c:gfc_set_default_type().
1435 Don't repeat the checks here. */
1436 if (sym
->attr
.implicit_type
)
1439 /* For subroutines or functions that are passed to a BIND(C) procedure,
1440 they're interoperable if they're BIND(C) and their params are all
1442 if (sym
->attr
.flavor
== FL_PROCEDURE
)
1444 if (sym
->attr
.is_bind_c
== 0)
1446 gfc_error_now ("Procedure %qs at %L must have the BIND(C) "
1447 "attribute to be C interoperable", sym
->name
,
1448 &(sym
->declared_at
));
1453 if (sym
->attr
.is_c_interop
== 1)
1454 /* We've already checked this procedure; don't check it again. */
1457 return verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
1462 /* See if we've stored a reference to a procedure that owns sym. */
1463 if (sym
->ns
!= NULL
&& sym
->ns
->proc_name
!= NULL
)
1465 if (sym
->ns
->proc_name
->attr
.is_bind_c
== 1)
1467 is_c_interop
= (gfc_verify_c_interop(&(sym
->ts
)) ? 1 : 0);
1469 if (is_c_interop
!= 1)
1471 /* Make personalized messages to give better feedback. */
1472 if (sym
->ts
.type
== BT_DERIVED
)
1473 gfc_error ("Variable %qs at %L is a dummy argument to the "
1474 "BIND(C) procedure %qs but is not C interoperable "
1475 "because derived type %qs is not C interoperable",
1476 sym
->name
, &(sym
->declared_at
),
1477 sym
->ns
->proc_name
->name
,
1478 sym
->ts
.u
.derived
->name
);
1479 else if (sym
->ts
.type
== BT_CLASS
)
1480 gfc_error ("Variable %qs at %L is a dummy argument to the "
1481 "BIND(C) procedure %qs but is not C interoperable "
1482 "because it is polymorphic",
1483 sym
->name
, &(sym
->declared_at
),
1484 sym
->ns
->proc_name
->name
);
1485 else if (warn_c_binding_type
)
1486 gfc_warning (OPT_Wc_binding_type
,
1487 "Variable %qs at %L is a dummy argument of the "
1488 "BIND(C) procedure %qs but may not be C "
1490 sym
->name
, &(sym
->declared_at
),
1491 sym
->ns
->proc_name
->name
);
1494 /* Character strings are only C interoperable if they have a
1496 if (sym
->ts
.type
== BT_CHARACTER
)
1498 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
1499 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
1500 || mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
1502 if (!gfc_notify_std (GFC_STD_F2018
,
1503 "Character argument %qs at %L "
1504 "must be length 1 because "
1505 "procedure %qs is BIND(C)",
1506 sym
->name
, &sym
->declared_at
,
1507 sym
->ns
->proc_name
->name
))
1512 /* We have to make sure that any param to a bind(c) routine does
1513 not have the allocatable, pointer, or optional attributes,
1514 according to J3/04-007, section 5.1. */
1515 if (sym
->attr
.allocatable
== 1
1516 && !gfc_notify_std (GFC_STD_F2018
, "Variable %qs at %L with "
1517 "ALLOCATABLE attribute in procedure %qs "
1518 "with BIND(C)", sym
->name
,
1519 &(sym
->declared_at
),
1520 sym
->ns
->proc_name
->name
))
1523 if (sym
->attr
.pointer
== 1
1524 && !gfc_notify_std (GFC_STD_F2018
, "Variable %qs at %L with "
1525 "POINTER attribute in procedure %qs "
1526 "with BIND(C)", sym
->name
,
1527 &(sym
->declared_at
),
1528 sym
->ns
->proc_name
->name
))
1531 if ((sym
->attr
.allocatable
|| sym
->attr
.pointer
) && !sym
->as
)
1533 gfc_error ("Scalar variable %qs at %L with POINTER or "
1534 "ALLOCATABLE in procedure %qs with BIND(C) is not yet"
1535 " supported", sym
->name
, &(sym
->declared_at
),
1536 sym
->ns
->proc_name
->name
);
1540 if (sym
->attr
.optional
== 1 && sym
->attr
.value
)
1542 gfc_error ("Variable %qs at %L cannot have both the OPTIONAL "
1543 "and the VALUE attribute because procedure %qs "
1544 "is BIND(C)", sym
->name
, &(sym
->declared_at
),
1545 sym
->ns
->proc_name
->name
);
1548 else if (sym
->attr
.optional
== 1
1549 && !gfc_notify_std (GFC_STD_F2018
, "Variable %qs "
1550 "at %L with OPTIONAL attribute in "
1551 "procedure %qs which is BIND(C)",
1552 sym
->name
, &(sym
->declared_at
),
1553 sym
->ns
->proc_name
->name
))
1556 /* Make sure that if it has the dimension attribute, that it is
1557 either assumed size or explicit shape. Deferred shape is already
1558 covered by the pointer/allocatable attribute. */
1559 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SHAPE
1560 && !gfc_notify_std (GFC_STD_F2018
, "Assumed-shape array %qs "
1561 "at %L as dummy argument to the BIND(C) "
1562 "procedure %qs at %L", sym
->name
,
1563 &(sym
->declared_at
),
1564 sym
->ns
->proc_name
->name
,
1565 &(sym
->ns
->proc_name
->declared_at
)))
1575 /* Function called by variable_decl() that adds a name to the symbol table. */
1578 build_sym (const char *name
, gfc_charlen
*cl
, bool cl_deferred
,
1579 gfc_array_spec
**as
, locus
*var_locus
)
1581 symbol_attribute attr
;
1586 /* Symbols in a submodule are host associated from the parent module or
1587 submodules. Therefore, they can be overridden by declarations in the
1588 submodule scope. Deal with this by attaching the existing symbol to
1589 a new symtree and recycling the old symtree with a new symbol... */
1590 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
1591 if (st
!= NULL
&& gfc_state_stack
->state
== COMP_SUBMODULE
1592 && st
->n
.sym
!= NULL
1593 && st
->n
.sym
->attr
.host_assoc
&& st
->n
.sym
->attr
.used_in_submodule
)
1595 gfc_symtree
*s
= gfc_get_unique_symtree (gfc_current_ns
);
1596 s
->n
.sym
= st
->n
.sym
;
1597 sym
= gfc_new_symbol (name
, gfc_current_ns
);
1602 gfc_set_sym_referenced (sym
);
1604 /* ...Otherwise generate a new symtree and new symbol. */
1605 else if (gfc_get_symbol (name
, NULL
, &sym
))
1608 /* Check if the name has already been defined as a type. The
1609 first letter of the symtree will be in upper case then. Of
1610 course, this is only necessary if the upper case letter is
1611 actually different. */
1613 upper
= TOUPPER(name
[0]);
1614 if (upper
!= name
[0])
1616 char u_name
[GFC_MAX_SYMBOL_LEN
+ 1];
1619 gcc_assert (strlen(name
) <= GFC_MAX_SYMBOL_LEN
);
1620 strcpy (u_name
, name
);
1623 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, u_name
);
1625 /* STRUCTURE types can alias symbol names */
1626 if (st
!= 0 && st
->n
.sym
->attr
.flavor
!= FL_STRUCT
)
1628 gfc_error ("Symbol %qs at %C also declared as a type at %L", name
,
1629 &st
->n
.sym
->declared_at
);
1634 /* Start updating the symbol table. Add basic type attribute if present. */
1635 if (current_ts
.type
!= BT_UNKNOWN
1636 && (sym
->attr
.implicit_type
== 0
1637 || !gfc_compare_types (&sym
->ts
, ¤t_ts
))
1638 && !gfc_add_type (sym
, ¤t_ts
, var_locus
))
1641 if (sym
->ts
.type
== BT_CHARACTER
)
1644 sym
->ts
.deferred
= cl_deferred
;
1647 /* Add dimension attribute if present. */
1648 if (!gfc_set_array_spec (sym
, *as
, var_locus
))
1652 /* Add attribute to symbol. The copy is so that we can reset the
1653 dimension attribute. */
1654 attr
= current_attr
;
1656 attr
.codimension
= 0;
1658 if (!gfc_copy_attr (&sym
->attr
, &attr
, var_locus
))
1661 /* Finish any work that may need to be done for the binding label,
1662 if it's a bind(c). The bind(c) attr is found before the symbol
1663 is made, and before the symbol name (for data decls), so the
1664 current_ts is holding the binding label, or nothing if the
1665 name= attr wasn't given. Therefore, test here if we're dealing
1666 with a bind(c) and make sure the binding label is set correctly. */
1667 if (sym
->attr
.is_bind_c
== 1)
1669 if (!sym
->binding_label
)
1671 /* Set the binding label and verify that if a NAME= was specified
1672 then only one identifier was in the entity-decl-list. */
1673 if (!set_binding_label (&sym
->binding_label
, sym
->name
,
1674 num_idents_on_line
))
1679 /* See if we know we're in a common block, and if it's a bind(c)
1680 common then we need to make sure we're an interoperable type. */
1681 if (sym
->attr
.in_common
== 1)
1683 /* Test the common block object. */
1684 if (sym
->common_block
!= NULL
&& sym
->common_block
->is_bind_c
== 1
1685 && sym
->ts
.is_c_interop
!= 1)
1687 gfc_error_now ("Variable %qs in common block %qs at %C "
1688 "must be declared with a C interoperable "
1689 "kind since common block %qs is BIND(C)",
1690 sym
->name
, sym
->common_block
->name
,
1691 sym
->common_block
->name
);
1696 sym
->attr
.implied_index
= 0;
1698 /* Use the parameter expressions for a parameterized derived type. */
1699 if ((sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
1700 && sym
->ts
.u
.derived
->attr
.pdt_type
&& type_param_spec_list
)
1701 sym
->param_list
= gfc_copy_actual_arglist (type_param_spec_list
);
1703 if (sym
->ts
.type
== BT_CLASS
)
1704 return gfc_build_class_symbol (&sym
->ts
, &sym
->attr
, &sym
->as
);
1710 /* Set character constant to the given length. The constant will be padded or
1711 truncated. If we're inside an array constructor without a typespec, we
1712 additionally check that all elements have the same length; check_len -1
1713 means no checking. */
1716 gfc_set_constant_character_len (gfc_charlen_t len
, gfc_expr
*expr
,
1717 gfc_charlen_t check_len
)
1722 if (expr
->ts
.type
!= BT_CHARACTER
)
1725 if (expr
->expr_type
!= EXPR_CONSTANT
)
1727 gfc_error_now ("CHARACTER length must be a constant at %L", &expr
->where
);
1731 slen
= expr
->value
.character
.length
;
1734 s
= gfc_get_wide_string (len
+ 1);
1735 memcpy (s
, expr
->value
.character
.string
,
1736 MIN (len
, slen
) * sizeof (gfc_char_t
));
1738 gfc_wide_memset (&s
[slen
], ' ', len
- slen
);
1740 if (warn_character_truncation
&& slen
> len
)
1741 gfc_warning_now (OPT_Wcharacter_truncation
,
1742 "CHARACTER expression at %L is being truncated "
1743 "(%ld/%ld)", &expr
->where
,
1744 (long) slen
, (long) len
);
1746 /* Apply the standard by 'hand' otherwise it gets cleared for
1748 if (check_len
!= -1 && slen
!= check_len
1749 && !(gfc_option
.allow_std
& GFC_STD_GNU
))
1750 gfc_error_now ("The CHARACTER elements of the array constructor "
1751 "at %L must have the same length (%ld/%ld)",
1752 &expr
->where
, (long) slen
,
1756 free (expr
->value
.character
.string
);
1757 expr
->value
.character
.string
= s
;
1758 expr
->value
.character
.length
= len
;
1759 /* If explicit representation was given, clear it
1760 as it is no longer needed after padding. */
1761 if (expr
->representation
.length
)
1763 expr
->representation
.length
= 0;
1764 free (expr
->representation
.string
);
1765 expr
->representation
.string
= NULL
;
1771 /* Function to create and update the enumerator history
1772 using the information passed as arguments.
1773 Pointer "max_enum" is also updated, to point to
1774 enum history node containing largest initializer.
1776 SYM points to the symbol node of enumerator.
1777 INIT points to its enumerator value. */
1780 create_enum_history (gfc_symbol
*sym
, gfc_expr
*init
)
1782 enumerator_history
*new_enum_history
;
1783 gcc_assert (sym
!= NULL
&& init
!= NULL
);
1785 new_enum_history
= XCNEW (enumerator_history
);
1787 new_enum_history
->sym
= sym
;
1788 new_enum_history
->initializer
= init
;
1789 new_enum_history
->next
= NULL
;
1791 if (enum_history
== NULL
)
1793 enum_history
= new_enum_history
;
1794 max_enum
= enum_history
;
1798 new_enum_history
->next
= enum_history
;
1799 enum_history
= new_enum_history
;
1801 if (mpz_cmp (max_enum
->initializer
->value
.integer
,
1802 new_enum_history
->initializer
->value
.integer
) < 0)
1803 max_enum
= new_enum_history
;
1808 /* Function to free enum kind history. */
1811 gfc_free_enum_history (void)
1813 enumerator_history
*current
= enum_history
;
1814 enumerator_history
*next
;
1816 while (current
!= NULL
)
1818 next
= current
->next
;
1823 enum_history
= NULL
;
1827 /* Function called by variable_decl() that adds an initialization
1828 expression to a symbol. */
1831 add_init_expr_to_sym (const char *name
, gfc_expr
**initp
, locus
*var_locus
)
1833 symbol_attribute attr
;
1838 if (find_special (name
, &sym
, false))
1843 /* If this symbol is confirming an implicit parameter type,
1844 then an initialization expression is not allowed. */
1845 if (attr
.flavor
== FL_PARAMETER
1846 && sym
->value
!= NULL
1849 gfc_error ("Initializer not allowed for PARAMETER %qs at %C",
1856 /* An initializer is required for PARAMETER declarations. */
1857 if (attr
.flavor
== FL_PARAMETER
)
1859 gfc_error ("PARAMETER at %L is missing an initializer", var_locus
);
1865 /* If a variable appears in a DATA block, it cannot have an
1869 gfc_error ("Variable %qs at %C with an initializer already "
1870 "appears in a DATA statement", sym
->name
);
1874 /* Check if the assignment can happen. This has to be put off
1875 until later for derived type variables and procedure pointers. */
1876 if (!gfc_bt_struct (sym
->ts
.type
) && !gfc_bt_struct (init
->ts
.type
)
1877 && sym
->ts
.type
!= BT_CLASS
&& init
->ts
.type
!= BT_CLASS
1878 && !sym
->attr
.proc_pointer
1879 && !gfc_check_assign_symbol (sym
, NULL
, init
))
1882 if (sym
->ts
.type
== BT_CHARACTER
&& sym
->ts
.u
.cl
1883 && init
->ts
.type
== BT_CHARACTER
)
1885 /* Update symbol character length according initializer. */
1886 if (!gfc_check_assign_symbol (sym
, NULL
, init
))
1889 if (sym
->ts
.u
.cl
->length
== NULL
)
1892 /* If there are multiple CHARACTER variables declared on the
1893 same line, we don't want them to share the same length. */
1894 sym
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
1896 if (sym
->attr
.flavor
== FL_PARAMETER
)
1898 if (init
->expr_type
== EXPR_CONSTANT
)
1900 clen
= init
->value
.character
.length
;
1901 sym
->ts
.u
.cl
->length
1902 = gfc_get_int_expr (gfc_charlen_int_kind
,
1905 else if (init
->expr_type
== EXPR_ARRAY
)
1907 if (init
->ts
.u
.cl
&& init
->ts
.u
.cl
->length
)
1909 const gfc_expr
*length
= init
->ts
.u
.cl
->length
;
1910 if (length
->expr_type
!= EXPR_CONSTANT
)
1912 gfc_error ("Cannot initialize parameter array "
1914 "with variable length elements",
1918 clen
= mpz_get_si (length
->value
.integer
);
1920 else if (init
->value
.constructor
)
1923 c
= gfc_constructor_first (init
->value
.constructor
);
1924 clen
= c
->expr
->value
.character
.length
;
1928 sym
->ts
.u
.cl
->length
1929 = gfc_get_int_expr (gfc_charlen_int_kind
,
1932 else if (init
->ts
.u
.cl
&& init
->ts
.u
.cl
->length
)
1933 sym
->ts
.u
.cl
->length
=
1934 gfc_copy_expr (init
->ts
.u
.cl
->length
);
1937 /* Update initializer character length according symbol. */
1938 else if (sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
1940 if (!gfc_specification_expr (sym
->ts
.u
.cl
->length
))
1943 int k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
,
1945 /* resolve_charlen will complain later on if the length
1946 is too large. Just skeep the initialization in that case. */
1947 if (mpz_cmp (sym
->ts
.u
.cl
->length
->value
.integer
,
1948 gfc_integer_kinds
[k
].huge
) <= 0)
1951 = gfc_mpz_get_hwi (sym
->ts
.u
.cl
->length
->value
.integer
);
1953 if (init
->expr_type
== EXPR_CONSTANT
)
1954 gfc_set_constant_character_len (len
, init
, -1);
1955 else if (init
->expr_type
== EXPR_ARRAY
)
1959 /* Build a new charlen to prevent simplification from
1960 deleting the length before it is resolved. */
1961 init
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
1962 init
->ts
.u
.cl
->length
1963 = gfc_copy_expr (sym
->ts
.u
.cl
->length
);
1965 for (c
= gfc_constructor_first (init
->value
.constructor
);
1966 c
; c
= gfc_constructor_next (c
))
1967 gfc_set_constant_character_len (len
, c
->expr
, -1);
1973 /* If sym is implied-shape, set its upper bounds from init. */
1974 if (sym
->attr
.flavor
== FL_PARAMETER
&& sym
->attr
.dimension
1975 && sym
->as
->type
== AS_IMPLIED_SHAPE
)
1979 if (init
->rank
== 0)
1981 gfc_error ("Can't initialize implied-shape array at %L"
1982 " with scalar", &sym
->declared_at
);
1986 /* The shape may be NULL for EXPR_ARRAY, set it. */
1987 if (init
->shape
== NULL
)
1989 gcc_assert (init
->expr_type
== EXPR_ARRAY
);
1990 init
->shape
= gfc_get_shape (1);
1991 if (!gfc_array_size (init
, &init
->shape
[0]))
1992 gfc_internal_error ("gfc_array_size failed");
1995 for (dim
= 0; dim
< sym
->as
->rank
; ++dim
)
1998 gfc_expr
*e
, *lower
;
2000 lower
= sym
->as
->lower
[dim
];
2002 /* If the lower bound is an array element from another
2003 parameterized array, then it is marked with EXPR_VARIABLE and
2004 is an initialization expression. Try to reduce it. */
2005 if (lower
->expr_type
== EXPR_VARIABLE
)
2006 gfc_reduce_init_expr (lower
);
2008 if (lower
->expr_type
== EXPR_CONSTANT
)
2010 /* All dimensions must be without upper bound. */
2011 gcc_assert (!sym
->as
->upper
[dim
]);
2014 e
= gfc_get_constant_expr (BT_INTEGER
, k
, &sym
->declared_at
);
2015 mpz_add (e
->value
.integer
, lower
->value
.integer
,
2017 mpz_sub_ui (e
->value
.integer
, e
->value
.integer
, 1);
2018 sym
->as
->upper
[dim
] = e
;
2022 gfc_error ("Non-constant lower bound in implied-shape"
2023 " declaration at %L", &lower
->where
);
2028 sym
->as
->type
= AS_EXPLICIT
;
2031 /* Need to check if the expression we initialized this
2032 to was one of the iso_c_binding named constants. If so,
2033 and we're a parameter (constant), let it be iso_c.
2035 integer(c_int), parameter :: my_int = c_int
2036 integer(my_int) :: my_int_2
2037 If we mark my_int as iso_c (since we can see it's value
2038 is equal to one of the named constants), then my_int_2
2039 will be considered C interoperable. */
2040 if (sym
->ts
.type
!= BT_CHARACTER
&& !gfc_bt_struct (sym
->ts
.type
))
2042 sym
->ts
.is_iso_c
|= init
->ts
.is_iso_c
;
2043 sym
->ts
.is_c_interop
|= init
->ts
.is_c_interop
;
2044 /* attr bits needed for module files. */
2045 sym
->attr
.is_iso_c
|= init
->ts
.is_iso_c
;
2046 sym
->attr
.is_c_interop
|= init
->ts
.is_c_interop
;
2047 if (init
->ts
.is_iso_c
)
2048 sym
->ts
.f90_type
= init
->ts
.f90_type
;
2051 /* Add initializer. Make sure we keep the ranks sane. */
2052 if (sym
->attr
.dimension
&& init
->rank
== 0)
2057 if (sym
->attr
.flavor
== FL_PARAMETER
2058 && init
->expr_type
== EXPR_CONSTANT
2059 && spec_size (sym
->as
, &size
)
2060 && mpz_cmp_si (size
, 0) > 0)
2062 array
= gfc_get_array_expr (init
->ts
.type
, init
->ts
.kind
,
2064 for (n
= 0; n
< (int)mpz_get_si (size
); n
++)
2065 gfc_constructor_append_expr (&array
->value
.constructor
,
2068 : gfc_copy_expr (init
),
2071 array
->shape
= gfc_get_shape (sym
->as
->rank
);
2072 for (n
= 0; n
< sym
->as
->rank
; n
++)
2073 spec_dimen_size (sym
->as
, n
, &array
->shape
[n
]);
2078 init
->rank
= sym
->as
->rank
;
2082 if (sym
->attr
.save
== SAVE_NONE
)
2083 sym
->attr
.save
= SAVE_IMPLICIT
;
2091 /* Function called by variable_decl() that adds a name to a structure
2095 build_struct (const char *name
, gfc_charlen
*cl
, gfc_expr
**init
,
2096 gfc_array_spec
**as
)
2101 /* F03:C438/C439. If the current symbol is of the same derived type that we're
2102 constructing, it must have the pointer attribute. */
2103 if ((current_ts
.type
== BT_DERIVED
|| current_ts
.type
== BT_CLASS
)
2104 && current_ts
.u
.derived
== gfc_current_block ()
2105 && current_attr
.pointer
== 0)
2107 if (current_attr
.allocatable
2108 && !gfc_notify_std(GFC_STD_F2008
, "Component at %C "
2109 "must have the POINTER attribute"))
2113 else if (current_attr
.allocatable
== 0)
2115 gfc_error ("Component at %C must have the POINTER attribute");
2121 if (current_ts
.type
== BT_CLASS
2122 && !(current_attr
.pointer
|| current_attr
.allocatable
))
2124 gfc_error ("Component %qs with CLASS at %C must be allocatable "
2125 "or pointer", name
);
2129 if (gfc_current_block ()->attr
.pointer
&& (*as
)->rank
!= 0)
2131 if ((*as
)->type
!= AS_DEFERRED
&& (*as
)->type
!= AS_EXPLICIT
)
2133 gfc_error ("Array component of structure at %C must have explicit "
2134 "or deferred shape");
2139 /* If we are in a nested union/map definition, gfc_add_component will not
2140 properly find repeated components because:
2141 (i) gfc_add_component does a flat search, where components of unions
2142 and maps are implicity chained so nested components may conflict.
2143 (ii) Unions and maps are not linked as components of their parent
2144 structures until after they are parsed.
2145 For (i) we use gfc_find_component which searches recursively, and for (ii)
2146 we search each block directly from the parse stack until we find the top
2149 s
= gfc_state_stack
;
2150 if (s
->state
== COMP_UNION
|| s
->state
== COMP_MAP
)
2152 while (s
->state
== COMP_UNION
|| gfc_comp_struct (s
->state
))
2154 c
= gfc_find_component (s
->sym
, name
, true, true, NULL
);
2157 gfc_error_now ("Component %qs at %C already declared at %L",
2161 /* Break after we've searched the entire chain. */
2162 if (s
->state
== COMP_DERIVED
|| s
->state
== COMP_STRUCTURE
)
2168 if (!gfc_add_component (gfc_current_block(), name
, &c
))
2172 if (c
->ts
.type
== BT_CHARACTER
)
2175 if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_DERIVED
2176 && (c
->ts
.kind
== 0 || c
->ts
.type
== BT_CHARACTER
)
2177 && saved_kind_expr
!= NULL
)
2178 c
->kind_expr
= gfc_copy_expr (saved_kind_expr
);
2180 c
->attr
= current_attr
;
2182 c
->initializer
= *init
;
2189 c
->attr
.codimension
= 1;
2191 c
->attr
.dimension
= 1;
2195 gfc_apply_init (&c
->ts
, &c
->attr
, c
->initializer
);
2197 /* Check array components. */
2198 if (!c
->attr
.dimension
)
2201 if (c
->attr
.pointer
)
2203 if (c
->as
->type
!= AS_DEFERRED
)
2205 gfc_error ("Pointer array component of structure at %C must have a "
2210 else if (c
->attr
.allocatable
)
2212 if (c
->as
->type
!= AS_DEFERRED
)
2214 gfc_error ("Allocatable component of structure at %C must have a "
2221 if (c
->as
->type
!= AS_EXPLICIT
)
2223 gfc_error ("Array component of structure at %C must have an "
2230 if (c
->ts
.type
== BT_CLASS
)
2231 return gfc_build_class_symbol (&c
->ts
, &c
->attr
, &c
->as
);
2233 if (c
->attr
.pdt_kind
|| c
->attr
.pdt_len
)
2236 gfc_find_symbol (c
->name
, gfc_current_block ()->f2k_derived
,
2240 gfc_error ("Type parameter %qs at %C has no corresponding entry "
2241 "in the type parameter name list at %L",
2242 c
->name
, &gfc_current_block ()->declared_at
);
2246 sym
->attr
.pdt_kind
= c
->attr
.pdt_kind
;
2247 sym
->attr
.pdt_len
= c
->attr
.pdt_len
;
2249 sym
->value
= gfc_copy_expr (c
->initializer
);
2250 sym
->attr
.flavor
= FL_VARIABLE
;
2253 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
2254 && c
->ts
.u
.derived
&& c
->ts
.u
.derived
->attr
.pdt_template
2255 && decl_type_param_list
)
2256 c
->param_list
= gfc_copy_actual_arglist (decl_type_param_list
);
2262 /* Match a 'NULL()', and possibly take care of some side effects. */
2265 gfc_match_null (gfc_expr
**result
)
2268 match m
, m2
= MATCH_NO
;
2270 if ((m
= gfc_match (" null ( )")) == MATCH_ERROR
)
2276 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2278 if ((m2
= gfc_match (" null (")) != MATCH_YES
)
2281 old_loc
= gfc_current_locus
;
2282 if ((m2
= gfc_match (" %n ) ", name
)) == MATCH_ERROR
)
2285 && ((m2
= gfc_match (" mold = %n )", name
)) == MATCH_ERROR
))
2289 gfc_current_locus
= old_loc
;
2294 /* The NULL symbol now has to be/become an intrinsic function. */
2295 if (gfc_get_symbol ("null", NULL
, &sym
))
2297 gfc_error ("NULL() initialization at %C is ambiguous");
2301 gfc_intrinsic_symbol (sym
);
2303 if (sym
->attr
.proc
!= PROC_INTRINSIC
2304 && !(sym
->attr
.use_assoc
&& sym
->attr
.intrinsic
)
2305 && (!gfc_add_procedure(&sym
->attr
, PROC_INTRINSIC
, sym
->name
, NULL
)
2306 || !gfc_add_function (&sym
->attr
, sym
->name
, NULL
)))
2309 *result
= gfc_get_null_expr (&gfc_current_locus
);
2311 /* Invalid per F2008, C512. */
2312 if (m2
== MATCH_YES
)
2314 gfc_error ("NULL() initialization at %C may not have MOLD");
2322 /* Match the initialization expr for a data pointer or procedure pointer. */
2325 match_pointer_init (gfc_expr
**init
, int procptr
)
2329 if (gfc_pure (NULL
) && !gfc_comp_struct (gfc_state_stack
->state
))
2331 gfc_error ("Initialization of pointer at %C is not allowed in "
2332 "a PURE procedure");
2335 gfc_unset_implicit_pure (gfc_current_ns
->proc_name
);
2337 /* Match NULL() initialization. */
2338 m
= gfc_match_null (init
);
2342 /* Match non-NULL initialization. */
2343 gfc_matching_ptr_assignment
= !procptr
;
2344 gfc_matching_procptr_assignment
= procptr
;
2345 m
= gfc_match_rvalue (init
);
2346 gfc_matching_ptr_assignment
= 0;
2347 gfc_matching_procptr_assignment
= 0;
2348 if (m
== MATCH_ERROR
)
2350 else if (m
== MATCH_NO
)
2352 gfc_error ("Error in pointer initialization at %C");
2356 if (!procptr
&& !gfc_resolve_expr (*init
))
2359 if (!gfc_notify_std (GFC_STD_F2008
, "non-NULL pointer "
2360 "initialization at %C"))
2368 check_function_name (char *name
)
2370 /* In functions that have a RESULT variable defined, the function name always
2371 refers to function calls. Therefore, the name is not allowed to appear in
2372 specification statements. When checking this, be careful about
2373 'hidden' procedure pointer results ('ppr@'). */
2375 if (gfc_current_state () == COMP_FUNCTION
)
2377 gfc_symbol
*block
= gfc_current_block ();
2378 if (block
&& block
->result
&& block
->result
!= block
2379 && strcmp (block
->result
->name
, "ppr@") != 0
2380 && strcmp (block
->name
, name
) == 0)
2382 gfc_error ("RESULT variable %qs at %L prohibits FUNCTION name %qs at %C "
2383 "from appearing in a specification statement",
2384 block
->result
->name
, &block
->result
->declared_at
, name
);
2393 /* Match a variable name with an optional initializer. When this
2394 subroutine is called, a variable is expected to be parsed next.
2395 Depending on what is happening at the moment, updates either the
2396 symbol table or the current interface. */
2399 variable_decl (int elem
)
2401 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2402 static unsigned int fill_id
= 0;
2403 gfc_expr
*initializer
, *char_len
;
2405 gfc_array_spec
*cp_as
; /* Extra copy for Cray Pointees. */
2417 /* When we get here, we've just matched a list of attributes and
2418 maybe a type and a double colon. The next thing we expect to see
2419 is the name of the symbol. */
2421 /* If we are parsing a structure with legacy support, we allow the symbol
2422 name to be '%FILL' which gives it an anonymous (inaccessible) name. */
2424 gfc_gobble_whitespace ();
2425 if (gfc_peek_ascii_char () == '%')
2427 gfc_next_ascii_char ();
2428 m
= gfc_match ("fill");
2433 m
= gfc_match_name (name
);
2441 if (gfc_current_state () != COMP_STRUCTURE
)
2443 if (flag_dec_structure
)
2444 gfc_error ("%qs not allowed outside STRUCTURE at %C", "%FILL");
2446 gfc_error ("%qs at %C is a DEC extension, enable with "
2447 "%<-fdec-structure%>", "%FILL");
2453 gfc_error ("%qs entity cannot have attributes at %C", "%FILL");
2457 /* %FILL components are given invalid fortran names. */
2458 snprintf (name
, GFC_MAX_SYMBOL_LEN
+ 1, "%%FILL%u", fill_id
++);
2462 var_locus
= gfc_current_locus
;
2464 /* Now we could see the optional array spec. or character length. */
2465 m
= gfc_match_array_spec (&as
, true, true);
2466 if (m
== MATCH_ERROR
)
2470 as
= gfc_copy_array_spec (current_as
);
2472 && !merge_array_spec (current_as
, as
, true))
2478 if (flag_cray_pointer
)
2479 cp_as
= gfc_copy_array_spec (as
);
2481 /* At this point, we know for sure if the symbol is PARAMETER and can thus
2482 determine (and check) whether it can be implied-shape. If it
2483 was parsed as assumed-size, change it because PARAMETERs cannot
2486 An explicit-shape-array cannot appear under several conditions.
2487 That check is done here as well. */
2490 if (as
->type
== AS_IMPLIED_SHAPE
&& current_attr
.flavor
!= FL_PARAMETER
)
2493 gfc_error ("Non-PARAMETER symbol %qs at %L can't be implied-shape",
2498 if (as
->type
== AS_ASSUMED_SIZE
&& as
->rank
== 1
2499 && current_attr
.flavor
== FL_PARAMETER
)
2500 as
->type
= AS_IMPLIED_SHAPE
;
2502 if (as
->type
== AS_IMPLIED_SHAPE
2503 && !gfc_notify_std (GFC_STD_F2008
, "Implied-shape array at %L",
2510 /* F2018:C830 (R816) An explicit-shape-spec whose bounds are not
2511 constant expressions shall appear only in a subprogram, derived
2512 type definition, BLOCK construct, or interface body. */
2513 if (as
->type
== AS_EXPLICIT
2514 && gfc_current_state () != COMP_BLOCK
2515 && gfc_current_state () != COMP_DERIVED
2516 && gfc_current_state () != COMP_FUNCTION
2517 && gfc_current_state () != COMP_INTERFACE
2518 && gfc_current_state () != COMP_SUBROUTINE
)
2521 bool not_constant
= false;
2523 for (int i
= 0; i
< as
->rank
; i
++)
2525 e
= gfc_copy_expr (as
->lower
[i
]);
2526 gfc_resolve_expr (e
);
2527 gfc_simplify_expr (e
, 0);
2528 if (e
&& (e
->expr_type
!= EXPR_CONSTANT
))
2530 not_constant
= true;
2535 e
= gfc_copy_expr (as
->upper
[i
]);
2536 gfc_resolve_expr (e
);
2537 gfc_simplify_expr (e
, 0);
2538 if (e
&& (e
->expr_type
!= EXPR_CONSTANT
))
2540 not_constant
= true;
2548 gfc_error ("Explicit shaped array with nonconstant bounds at %C");
2553 if (as
->type
== AS_EXPLICIT
)
2555 for (int i
= 0; i
< as
->rank
; i
++)
2559 if (e
->expr_type
!= EXPR_CONSTANT
)
2561 n
= gfc_copy_expr (e
);
2562 gfc_simplify_expr (n
, 1);
2563 if (n
->expr_type
== EXPR_CONSTANT
)
2564 gfc_replace_expr (e
, n
);
2569 if (e
->expr_type
!= EXPR_CONSTANT
)
2571 n
= gfc_copy_expr (e
);
2572 gfc_simplify_expr (n
, 1);
2573 if (n
->expr_type
== EXPR_CONSTANT
)
2574 gfc_replace_expr (e
, n
);
2584 cl_deferred
= false;
2586 if (current_ts
.type
== BT_CHARACTER
)
2588 switch (match_char_length (&char_len
, &cl_deferred
, false))
2591 cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
2593 cl
->length
= char_len
;
2596 /* Non-constant lengths need to be copied after the first
2597 element. Also copy assumed lengths. */
2600 && (current_ts
.u
.cl
->length
== NULL
2601 || current_ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
))
2603 cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
2604 cl
->length
= gfc_copy_expr (current_ts
.u
.cl
->length
);
2607 cl
= current_ts
.u
.cl
;
2609 cl_deferred
= current_ts
.deferred
;
2618 /* The dummy arguments and result of the abreviated form of MODULE
2619 PROCEDUREs, used in SUBMODULES should not be redefined. */
2620 if (gfc_current_ns
->proc_name
2621 && gfc_current_ns
->proc_name
->abr_modproc_decl
)
2623 gfc_find_symbol (name
, gfc_current_ns
, 1, &sym
);
2624 if (sym
!= NULL
&& (sym
->attr
.dummy
|| sym
->attr
.result
))
2627 gfc_error ("%qs at %C is a redefinition of the declaration "
2628 "in the corresponding interface for MODULE "
2629 "PROCEDURE %qs", sym
->name
,
2630 gfc_current_ns
->proc_name
->name
);
2635 /* %FILL components may not have initializers. */
2636 if (gfc_str_startswith (name
, "%FILL") && gfc_match_eos () != MATCH_YES
)
2638 gfc_error ("%qs entity cannot have an initializer at %C", "%FILL");
2643 /* If this symbol has already shown up in a Cray Pointer declaration,
2644 and this is not a component declaration,
2645 then we want to set the type & bail out. */
2646 if (flag_cray_pointer
&& !gfc_comp_struct (gfc_current_state ()))
2648 gfc_find_symbol (name
, gfc_current_ns
, 1, &sym
);
2649 if (sym
!= NULL
&& sym
->attr
.cray_pointee
)
2652 if (!gfc_add_type (sym
, ¤t_ts
, &gfc_current_locus
))
2658 /* Check to see if we have an array specification. */
2661 if (sym
->as
!= NULL
)
2663 gfc_error ("Duplicate array spec for Cray pointee at %C");
2664 gfc_free_array_spec (cp_as
);
2670 if (!gfc_set_array_spec (sym
, cp_as
, &var_locus
))
2671 gfc_internal_error ("Couldn't set pointee array spec.");
2673 /* Fix the array spec. */
2674 m
= gfc_mod_pointee_as (sym
->as
);
2675 if (m
== MATCH_ERROR
)
2683 gfc_free_array_spec (cp_as
);
2687 /* Procedure pointer as function result. */
2688 if (gfc_current_state () == COMP_FUNCTION
2689 && strcmp ("ppr@", gfc_current_block ()->name
) == 0
2690 && strcmp (name
, gfc_current_block ()->ns
->proc_name
->name
) == 0)
2691 strcpy (name
, "ppr@");
2693 if (gfc_current_state () == COMP_FUNCTION
2694 && strcmp (name
, gfc_current_block ()->name
) == 0
2695 && gfc_current_block ()->result
2696 && strcmp ("ppr@", gfc_current_block ()->result
->name
) == 0)
2697 strcpy (name
, "ppr@");
2699 /* OK, we've successfully matched the declaration. Now put the
2700 symbol in the current namespace, because it might be used in the
2701 optional initialization expression for this symbol, e.g. this is
2704 integer, parameter :: i = huge(i)
2706 This is only true for parameters or variables of a basic type.
2707 For components of derived types, it is not true, so we don't
2708 create a symbol for those yet. If we fail to create the symbol,
2710 if (!gfc_comp_struct (gfc_current_state ())
2711 && !build_sym (name
, cl
, cl_deferred
, &as
, &var_locus
))
2717 if (!check_function_name (name
))
2723 /* We allow old-style initializations of the form
2724 integer i /2/, j(4) /3*3, 1/
2725 (if no colon has been seen). These are different from data
2726 statements in that initializers are only allowed to apply to the
2727 variable immediately preceding, i.e.
2729 is not allowed. Therefore we have to do some work manually, that
2730 could otherwise be left to the matchers for DATA statements. */
2732 if (!colon_seen
&& gfc_match (" /") == MATCH_YES
)
2734 if (!gfc_notify_std (GFC_STD_GNU
, "Old-style "
2735 "initialization at %C"))
2738 /* Allow old style initializations for components of STRUCTUREs and MAPs
2739 but not components of derived types. */
2740 else if (gfc_current_state () == COMP_DERIVED
)
2742 gfc_error ("Invalid old style initialization for derived type "
2748 /* For structure components, read the initializer as a special
2749 expression and let the rest of this function apply the initializer
2751 else if (gfc_comp_struct (gfc_current_state ()))
2753 m
= match_clist_expr (&initializer
, ¤t_ts
, as
);
2755 gfc_error ("Syntax error in old style initialization of %s at %C",
2761 /* Otherwise we treat the old style initialization just like a
2762 DATA declaration for the current variable. */
2764 return match_old_style_init (name
);
2767 /* The double colon must be present in order to have initializers.
2768 Otherwise the statement is ambiguous with an assignment statement. */
2771 if (gfc_match (" =>") == MATCH_YES
)
2773 if (!current_attr
.pointer
)
2775 gfc_error ("Initialization at %C isn't for a pointer variable");
2780 m
= match_pointer_init (&initializer
, 0);
2784 else if (gfc_match_char ('=') == MATCH_YES
)
2786 if (current_attr
.pointer
)
2788 gfc_error ("Pointer initialization at %C requires %<=>%>, "
2794 m
= gfc_match_init_expr (&initializer
);
2797 gfc_error ("Expected an initialization expression at %C");
2801 if (current_attr
.flavor
!= FL_PARAMETER
&& gfc_pure (NULL
)
2802 && !gfc_comp_struct (gfc_state_stack
->state
))
2804 gfc_error ("Initialization of variable at %C is not allowed in "
2805 "a PURE procedure");
2809 if (current_attr
.flavor
!= FL_PARAMETER
2810 && !gfc_comp_struct (gfc_state_stack
->state
))
2811 gfc_unset_implicit_pure (gfc_current_ns
->proc_name
);
2818 if (initializer
!= NULL
&& current_attr
.allocatable
2819 && gfc_comp_struct (gfc_current_state ()))
2821 gfc_error ("Initialization of allocatable component at %C is not "
2827 if (gfc_current_state () == COMP_DERIVED
2828 && gfc_current_block ()->attr
.pdt_template
)
2831 gfc_find_symbol (name
, gfc_current_block ()->f2k_derived
,
2833 if (!param
&& (current_attr
.pdt_kind
|| current_attr
.pdt_len
))
2835 gfc_error ("The component with KIND or LEN attribute at %C does not "
2836 "not appear in the type parameter list at %L",
2837 &gfc_current_block ()->declared_at
);
2841 else if (param
&& !(current_attr
.pdt_kind
|| current_attr
.pdt_len
))
2843 gfc_error ("The component at %C that appears in the type parameter "
2844 "list at %L has neither the KIND nor LEN attribute",
2845 &gfc_current_block ()->declared_at
);
2849 else if (as
&& (current_attr
.pdt_kind
|| current_attr
.pdt_len
))
2851 gfc_error ("The component at %C which is a type parameter must be "
2856 else if (param
&& initializer
)
2857 param
->value
= gfc_copy_expr (initializer
);
2860 /* Before adding a possible initilizer, do a simple check for compatibility
2861 of lhs and rhs types. Assigning a REAL value to a derived type is not a
2863 if (current_ts
.type
== BT_DERIVED
&& initializer
2864 && (gfc_numeric_ts (&initializer
->ts
)
2865 || initializer
->ts
.type
== BT_LOGICAL
2866 || initializer
->ts
.type
== BT_CHARACTER
))
2868 gfc_error ("Incompatible initialization between a derived type "
2869 "entity and an entity with %qs type at %C",
2870 gfc_typename (&initializer
->ts
));
2876 /* Add the initializer. Note that it is fine if initializer is
2877 NULL here, because we sometimes also need to check if a
2878 declaration *must* have an initialization expression. */
2879 if (!gfc_comp_struct (gfc_current_state ()))
2880 t
= add_init_expr_to_sym (name
, &initializer
, &var_locus
);
2883 if (current_ts
.type
== BT_DERIVED
2884 && !current_attr
.pointer
&& !initializer
)
2885 initializer
= gfc_default_initializer (¤t_ts
);
2886 t
= build_struct (name
, cl
, &initializer
, &as
);
2888 /* If we match a nested structure definition we expect to see the
2889 * body even if the variable declarations blow up, so we need to keep
2890 * the structure declaration around. */
2891 if (gfc_new_block
&& gfc_new_block
->attr
.flavor
== FL_STRUCT
)
2892 gfc_commit_symbol (gfc_new_block
);
2895 m
= (t
) ? MATCH_YES
: MATCH_ERROR
;
2898 /* Free stuff up and return. */
2899 gfc_free_expr (initializer
);
2900 gfc_free_array_spec (as
);
2906 /* Match an extended-f77 "TYPESPEC*bytesize"-style kind specification.
2907 This assumes that the byte size is equal to the kind number for
2908 non-COMPLEX types, and equal to twice the kind number for COMPLEX. */
2911 gfc_match_old_kind_spec (gfc_typespec
*ts
)
2916 if (gfc_match_char ('*') != MATCH_YES
)
2919 m
= gfc_match_small_literal_int (&ts
->kind
, NULL
);
2923 original_kind
= ts
->kind
;
2925 /* Massage the kind numbers for complex types. */
2926 if (ts
->type
== BT_COMPLEX
)
2930 gfc_error ("Old-style type declaration %s*%d not supported at %C",
2931 gfc_basic_typename (ts
->type
), original_kind
);
2938 if (ts
->type
== BT_INTEGER
&& ts
->kind
== 4 && flag_integer4_kind
== 8)
2941 if (ts
->type
== BT_REAL
|| ts
->type
== BT_COMPLEX
)
2945 if (flag_real4_kind
== 8)
2947 if (flag_real4_kind
== 10)
2949 if (flag_real4_kind
== 16)
2955 if (flag_real8_kind
== 4)
2957 if (flag_real8_kind
== 10)
2959 if (flag_real8_kind
== 16)
2964 if (gfc_validate_kind (ts
->type
, ts
->kind
, true) < 0)
2966 gfc_error ("Old-style type declaration %s*%d not supported at %C",
2967 gfc_basic_typename (ts
->type
), original_kind
);
2971 if (!gfc_notify_std (GFC_STD_GNU
,
2972 "Nonstandard type declaration %s*%d at %C",
2973 gfc_basic_typename(ts
->type
), original_kind
))
2980 /* Match a kind specification. Since kinds are generally optional, we
2981 usually return MATCH_NO if something goes wrong. If a "kind="
2982 string is found, then we know we have an error. */
2985 gfc_match_kind_spec (gfc_typespec
*ts
, bool kind_expr_only
)
2995 saved_kind_expr
= NULL
;
2997 where
= loc
= gfc_current_locus
;
3002 if (gfc_match_char ('(') == MATCH_NO
)
3005 /* Also gobbles optional text. */
3006 if (gfc_match (" kind = ") == MATCH_YES
)
3009 loc
= gfc_current_locus
;
3013 n
= gfc_match_init_expr (&e
);
3015 if (gfc_derived_parameter_expr (e
))
3018 saved_kind_expr
= gfc_copy_expr (e
);
3019 goto close_brackets
;
3024 if (gfc_matching_function
)
3026 /* The function kind expression might include use associated or
3027 imported parameters and try again after the specification
3029 if (gfc_match_char (')') != MATCH_YES
)
3031 gfc_error ("Missing right parenthesis at %C");
3037 gfc_undo_symbols ();
3042 /* ....or else, the match is real. */
3044 gfc_error ("Expected initialization expression at %C");
3052 gfc_error ("Expected scalar initialization expression at %C");
3057 if (gfc_extract_int (e
, &ts
->kind
, 1))
3063 /* Before throwing away the expression, let's see if we had a
3064 C interoperable kind (and store the fact). */
3065 if (e
->ts
.is_c_interop
== 1)
3067 /* Mark this as C interoperable if being declared with one
3068 of the named constants from iso_c_binding. */
3069 ts
->is_c_interop
= e
->ts
.is_iso_c
;
3070 ts
->f90_type
= e
->ts
.f90_type
;
3072 ts
->interop_kind
= e
->symtree
->n
.sym
;
3078 /* Ignore errors to this point, if we've gotten here. This means
3079 we ignore the m=MATCH_ERROR from above. */
3080 if (gfc_validate_kind (ts
->type
, ts
->kind
, true) < 0)
3082 gfc_error ("Kind %d not supported for type %s at %C", ts
->kind
,
3083 gfc_basic_typename (ts
->type
));
3084 gfc_current_locus
= where
;
3088 /* Warn if, e.g., c_int is used for a REAL variable, but not
3089 if, e.g., c_double is used for COMPLEX as the standard
3090 explicitly says that the kind type parameter for complex and real
3091 variable is the same, i.e. c_float == c_float_complex. */
3092 if (ts
->f90_type
!= BT_UNKNOWN
&& ts
->f90_type
!= ts
->type
3093 && !((ts
->f90_type
== BT_REAL
&& ts
->type
== BT_COMPLEX
)
3094 || (ts
->f90_type
== BT_COMPLEX
&& ts
->type
== BT_REAL
)))
3095 gfc_warning_now (0, "C kind type parameter is for type %s but type at %L "
3096 "is %s", gfc_basic_typename (ts
->f90_type
), &where
,
3097 gfc_basic_typename (ts
->type
));
3101 gfc_gobble_whitespace ();
3102 if ((c
= gfc_next_ascii_char ()) != ')'
3103 && (ts
->type
!= BT_CHARACTER
|| c
!= ','))
3105 if (ts
->type
== BT_CHARACTER
)
3106 gfc_error ("Missing right parenthesis or comma at %C");
3108 gfc_error ("Missing right parenthesis at %C");
3112 /* All tests passed. */
3115 if(m
== MATCH_ERROR
)
3116 gfc_current_locus
= where
;
3118 if (ts
->type
== BT_INTEGER
&& ts
->kind
== 4 && flag_integer4_kind
== 8)
3121 if (ts
->type
== BT_REAL
|| ts
->type
== BT_COMPLEX
)
3125 if (flag_real4_kind
== 8)
3127 if (flag_real4_kind
== 10)
3129 if (flag_real4_kind
== 16)
3135 if (flag_real8_kind
== 4)
3137 if (flag_real8_kind
== 10)
3139 if (flag_real8_kind
== 16)
3144 /* Return what we know from the test(s). */
3149 gfc_current_locus
= where
;
3155 match_char_kind (int * kind
, int * is_iso_c
)
3164 where
= gfc_current_locus
;
3166 n
= gfc_match_init_expr (&e
);
3168 if (n
!= MATCH_YES
&& gfc_matching_function
)
3170 /* The expression might include use-associated or imported
3171 parameters and try again after the specification
3174 gfc_undo_symbols ();
3179 gfc_error ("Expected initialization expression at %C");
3185 gfc_error ("Expected scalar initialization expression at %C");
3190 if (gfc_derived_parameter_expr (e
))
3192 saved_kind_expr
= e
;
3197 fail
= gfc_extract_int (e
, kind
, 1);
3198 *is_iso_c
= e
->ts
.is_iso_c
;
3207 /* Ignore errors to this point, if we've gotten here. This means
3208 we ignore the m=MATCH_ERROR from above. */
3209 if (gfc_validate_kind (BT_CHARACTER
, *kind
, true) < 0)
3211 gfc_error ("Kind %d is not supported for CHARACTER at %C", *kind
);
3215 /* All tests passed. */
3218 if (m
== MATCH_ERROR
)
3219 gfc_current_locus
= where
;
3221 /* Return what we know from the test(s). */
3226 gfc_current_locus
= where
;
3231 /* Match the various kind/length specifications in a CHARACTER
3232 declaration. We don't return MATCH_NO. */
3235 gfc_match_char_spec (gfc_typespec
*ts
)
3237 int kind
, seen_length
, is_iso_c
;
3249 /* Try the old-style specification first. */
3250 old_char_selector
= 0;
3252 m
= match_char_length (&len
, &deferred
, true);
3256 old_char_selector
= 1;
3261 m
= gfc_match_char ('(');
3264 m
= MATCH_YES
; /* Character without length is a single char. */
3268 /* Try the weird case: ( KIND = <int> [ , LEN = <len-param> ] ). */
3269 if (gfc_match (" kind =") == MATCH_YES
)
3271 m
= match_char_kind (&kind
, &is_iso_c
);
3273 if (m
== MATCH_ERROR
)
3278 if (gfc_match (" , len =") == MATCH_NO
)
3281 m
= char_len_param_value (&len
, &deferred
);
3284 if (m
== MATCH_ERROR
)
3291 /* Try to match "LEN = <len-param>" or "LEN = <len-param>, KIND = <int>". */
3292 if (gfc_match (" len =") == MATCH_YES
)
3294 m
= char_len_param_value (&len
, &deferred
);
3297 if (m
== MATCH_ERROR
)
3301 if (gfc_match_char (')') == MATCH_YES
)
3304 if (gfc_match (" , kind =") != MATCH_YES
)
3307 if (match_char_kind (&kind
, &is_iso_c
) == MATCH_ERROR
)
3313 /* Try to match ( <len-param> ) or ( <len-param> , [ KIND = ] <int> ). */
3314 m
= char_len_param_value (&len
, &deferred
);
3317 if (m
== MATCH_ERROR
)
3321 m
= gfc_match_char (')');
3325 if (gfc_match_char (',') != MATCH_YES
)
3328 gfc_match (" kind ="); /* Gobble optional text. */
3330 m
= match_char_kind (&kind
, &is_iso_c
);
3331 if (m
== MATCH_ERROR
)
3337 /* Require a right-paren at this point. */
3338 m
= gfc_match_char (')');
3343 gfc_error ("Syntax error in CHARACTER declaration at %C");
3345 gfc_free_expr (len
);
3349 /* Deal with character functions after USE and IMPORT statements. */
3350 if (gfc_matching_function
)
3352 gfc_free_expr (len
);
3353 gfc_undo_symbols ();
3359 gfc_free_expr (len
);
3363 /* Do some final massaging of the length values. */
3364 cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
3366 if (seen_length
== 0)
3367 cl
->length
= gfc_get_int_expr (gfc_charlen_int_kind
, NULL
, 1);
3370 /* If gfortran ends up here, then len may be reducible to a constant.
3371 Try to do that here. If it does not reduce, simply assign len to
3372 charlen. A complication occurs with user-defined generic functions,
3373 which are not resolved. Use a private namespace to deal with
3374 generic functions. */
3376 if (len
&& len
->expr_type
!= EXPR_CONSTANT
)
3378 gfc_namespace
*old_ns
;
3381 old_ns
= gfc_current_ns
;
3382 gfc_current_ns
= gfc_get_namespace (NULL
, 0);
3384 e
= gfc_copy_expr (len
);
3385 gfc_reduce_init_expr (e
);
3386 if (e
->expr_type
== EXPR_CONSTANT
)
3388 gfc_replace_expr (len
, e
);
3389 if (mpz_cmp_si (len
->value
.integer
, 0) < 0)
3390 mpz_set_ui (len
->value
.integer
, 0);
3395 gfc_free_namespace (gfc_current_ns
);
3396 gfc_current_ns
= old_ns
;
3403 ts
->kind
= kind
== 0 ? gfc_default_character_kind
: kind
;
3404 ts
->deferred
= deferred
;
3406 /* We have to know if it was a C interoperable kind so we can
3407 do accurate type checking of bind(c) procs, etc. */
3409 /* Mark this as C interoperable if being declared with one
3410 of the named constants from iso_c_binding. */
3411 ts
->is_c_interop
= is_iso_c
;
3412 else if (len
!= NULL
)
3413 /* Here, we might have parsed something such as: character(c_char)
3414 In this case, the parsing code above grabs the c_char when
3415 looking for the length (line 1690, roughly). it's the last
3416 testcase for parsing the kind params of a character variable.
3417 However, it's not actually the length. this seems like it
3419 To see if the user used a C interop kind, test the expr
3420 of the so called length, and see if it's C interoperable. */
3421 ts
->is_c_interop
= len
->ts
.is_iso_c
;
3427 /* Matches a RECORD declaration. */
3430 match_record_decl (char *name
)
3433 old_loc
= gfc_current_locus
;
3436 m
= gfc_match (" record /");
3439 if (!flag_dec_structure
)
3441 gfc_current_locus
= old_loc
;
3442 gfc_error ("RECORD at %C is an extension, enable it with "
3446 m
= gfc_match (" %n/", name
);
3451 gfc_current_locus
= old_loc
;
3452 if (flag_dec_structure
3453 && (gfc_match (" record% ") == MATCH_YES
3454 || gfc_match (" record%t") == MATCH_YES
))
3455 gfc_error ("Structure name expected after RECORD at %C");
3463 /* This function uses the gfc_actual_arglist 'type_param_spec_list' as a source
3464 of expressions to substitute into the possibly parameterized expression
3465 'e'. Using a list is inefficient but should not be too bad since the
3466 number of type parameters is not likely to be large. */
3468 insert_parameter_exprs (gfc_expr
* e
, gfc_symbol
* sym ATTRIBUTE_UNUSED
,
3471 gfc_actual_arglist
*param
;
3474 if (e
->expr_type
!= EXPR_VARIABLE
)
3477 gcc_assert (e
->symtree
);
3478 if (e
->symtree
->n
.sym
->attr
.pdt_kind
3479 || (*f
!= 0 && e
->symtree
->n
.sym
->attr
.pdt_len
))
3481 for (param
= type_param_spec_list
; param
; param
= param
->next
)
3482 if (strcmp (e
->symtree
->n
.sym
->name
, param
->name
) == 0)
3487 copy
= gfc_copy_expr (param
->expr
);
3498 gfc_insert_kind_parameter_exprs (gfc_expr
*e
)
3500 return gfc_traverse_expr (e
, NULL
, &insert_parameter_exprs
, 0);
3505 gfc_insert_parameter_exprs (gfc_expr
*e
, gfc_actual_arglist
*param_list
)
3507 gfc_actual_arglist
*old_param_spec_list
= type_param_spec_list
;
3508 type_param_spec_list
= param_list
;
3509 return gfc_traverse_expr (e
, NULL
, &insert_parameter_exprs
, 1);
3510 type_param_spec_list
= NULL
;
3511 type_param_spec_list
= old_param_spec_list
;
3514 /* Determines the instance of a parameterized derived type to be used by
3515 matching determining the values of the kind parameters and using them
3516 in the name of the instance. If the instance exists, it is used, otherwise
3517 a new derived type is created. */
3519 gfc_get_pdt_instance (gfc_actual_arglist
*param_list
, gfc_symbol
**sym
,
3520 gfc_actual_arglist
**ext_param_list
)
3522 /* The PDT template symbol. */
3523 gfc_symbol
*pdt
= *sym
;
3524 /* The symbol for the parameter in the template f2k_namespace. */
3526 /* The hoped for instance of the PDT. */
3527 gfc_symbol
*instance
;
3528 /* The list of parameters appearing in the PDT declaration. */
3529 gfc_formal_arglist
*type_param_name_list
;
3530 /* Used to store the parameter specification list during recursive calls. */
3531 gfc_actual_arglist
*old_param_spec_list
;
3532 /* Pointers to the parameter specification being used. */
3533 gfc_actual_arglist
*actual_param
;
3534 gfc_actual_arglist
*tail
= NULL
;
3535 /* Used to build up the name of the PDT instance. The prefix uses 4
3536 characters and each KIND parameter 2 more. Allow 8 of the latter. */
3537 char name
[GFC_MAX_SYMBOL_LEN
+ 21];
3539 bool name_seen
= (param_list
== NULL
);
3540 bool assumed_seen
= false;
3541 bool deferred_seen
= false;
3542 bool spec_error
= false;
3544 gfc_expr
*kind_expr
;
3545 gfc_component
*c1
, *c2
;
3548 type_param_spec_list
= NULL
;
3550 type_param_name_list
= pdt
->formal
;
3551 actual_param
= param_list
;
3552 sprintf (name
, "Pdt%s", pdt
->name
);
3554 /* Run through the parameter name list and pick up the actual
3555 parameter values or use the default values in the PDT declaration. */
3556 for (; type_param_name_list
;
3557 type_param_name_list
= type_param_name_list
->next
)
3559 if (actual_param
&& actual_param
->spec_type
!= SPEC_EXPLICIT
)
3561 if (actual_param
->spec_type
== SPEC_ASSUMED
)
3562 spec_error
= deferred_seen
;
3564 spec_error
= assumed_seen
;
3568 gfc_error ("The type parameter spec list at %C cannot contain "
3569 "both ASSUMED and DEFERRED parameters");
3574 if (actual_param
&& actual_param
->name
)
3576 param
= type_param_name_list
->sym
;
3578 if (!param
|| !param
->name
)
3581 c1
= gfc_find_component (pdt
, param
->name
, false, true, NULL
);
3582 /* An error should already have been thrown in resolve.c
3583 (resolve_fl_derived0). */
3584 if (!pdt
->attr
.use_assoc
&& !c1
)
3590 if (!actual_param
&& !(c1
&& c1
->initializer
))
3592 gfc_error ("The type parameter spec list at %C does not contain "
3593 "enough parameter expressions");
3596 else if (!actual_param
&& c1
&& c1
->initializer
)
3597 kind_expr
= gfc_copy_expr (c1
->initializer
);
3598 else if (actual_param
&& actual_param
->spec_type
== SPEC_EXPLICIT
)
3599 kind_expr
= gfc_copy_expr (actual_param
->expr
);
3603 actual_param
= param_list
;
3604 for (;actual_param
; actual_param
= actual_param
->next
)
3605 if (actual_param
->name
3606 && strcmp (actual_param
->name
, param
->name
) == 0)
3608 if (actual_param
&& actual_param
->spec_type
== SPEC_EXPLICIT
)
3609 kind_expr
= gfc_copy_expr (actual_param
->expr
);
3612 if (c1
->initializer
)
3613 kind_expr
= gfc_copy_expr (c1
->initializer
);
3614 else if (!(actual_param
&& param
->attr
.pdt_len
))
3616 gfc_error ("The derived parameter %qs at %C does not "
3617 "have a default value", param
->name
);
3623 /* Store the current parameter expressions in a temporary actual
3624 arglist 'list' so that they can be substituted in the corresponding
3625 expressions in the PDT instance. */
3626 if (type_param_spec_list
== NULL
)
3628 type_param_spec_list
= gfc_get_actual_arglist ();
3629 tail
= type_param_spec_list
;
3633 tail
->next
= gfc_get_actual_arglist ();
3636 tail
->name
= param
->name
;
3640 /* Try simplification even for LEN expressions. */
3641 gfc_resolve_expr (kind_expr
);
3642 gfc_simplify_expr (kind_expr
, 1);
3643 /* Variable expressions seem to default to BT_PROCEDURE.
3644 TODO find out why this is and fix it. */
3645 if (kind_expr
->ts
.type
!= BT_INTEGER
3646 && kind_expr
->ts
.type
!= BT_PROCEDURE
)
3648 gfc_error ("The parameter expression at %C must be of "
3649 "INTEGER type and not %s type",
3650 gfc_basic_typename (kind_expr
->ts
.type
));
3654 tail
->expr
= gfc_copy_expr (kind_expr
);
3658 tail
->spec_type
= actual_param
->spec_type
;
3660 if (!param
->attr
.pdt_kind
)
3662 if (!name_seen
&& actual_param
)
3663 actual_param
= actual_param
->next
;
3666 gfc_free_expr (kind_expr
);
3673 && (actual_param
->spec_type
== SPEC_ASSUMED
3674 || actual_param
->spec_type
== SPEC_DEFERRED
))
3676 gfc_error ("The KIND parameter %qs at %C cannot either be "
3677 "ASSUMED or DEFERRED", param
->name
);
3681 if (!kind_expr
|| !gfc_is_constant_expr (kind_expr
))
3683 gfc_error ("The value for the KIND parameter %qs at %C does not "
3684 "reduce to a constant expression", param
->name
);
3688 gfc_extract_int (kind_expr
, &kind_value
);
3689 sprintf (name
+ strlen (name
), "_%d", kind_value
);
3691 if (!name_seen
&& actual_param
)
3692 actual_param
= actual_param
->next
;
3693 gfc_free_expr (kind_expr
);
3696 if (!name_seen
&& actual_param
)
3698 gfc_error ("The type parameter spec list at %C contains too many "
3699 "parameter expressions");
3703 /* Now we search for the PDT instance 'name'. If it doesn't exist, we
3704 build it, using 'pdt' as a template. */
3705 if (gfc_get_symbol (name
, pdt
->ns
, &instance
))
3707 gfc_error ("Parameterized derived type at %C is ambiguous");
3713 if (instance
->attr
.flavor
== FL_DERIVED
3714 && instance
->attr
.pdt_type
)
3718 *ext_param_list
= type_param_spec_list
;
3720 gfc_commit_symbols ();
3724 /* Start building the new instance of the parameterized type. */
3725 gfc_copy_attr (&instance
->attr
, &pdt
->attr
, &pdt
->declared_at
);
3726 instance
->attr
.pdt_template
= 0;
3727 instance
->attr
.pdt_type
= 1;
3728 instance
->declared_at
= gfc_current_locus
;
3730 /* Add the components, replacing the parameters in all expressions
3731 with the expressions for their values in 'type_param_spec_list'. */
3732 c1
= pdt
->components
;
3733 tail
= type_param_spec_list
;
3734 for (; c1
; c1
= c1
->next
)
3736 gfc_add_component (instance
, c1
->name
, &c2
);
3739 c2
->attr
= c1
->attr
;
3741 /* The order of declaration of the type_specs might not be the
3742 same as that of the components. */
3743 if (c1
->attr
.pdt_kind
|| c1
->attr
.pdt_len
)
3745 for (tail
= type_param_spec_list
; tail
; tail
= tail
->next
)
3746 if (strcmp (c1
->name
, tail
->name
) == 0)
3750 /* Deal with type extension by recursively calling this function
3751 to obtain the instance of the extended type. */
3752 if (gfc_current_state () != COMP_DERIVED
3753 && c1
== pdt
->components
3754 && (c1
->ts
.type
== BT_DERIVED
|| c1
->ts
.type
== BT_CLASS
)
3755 && c1
->ts
.u
.derived
&& c1
->ts
.u
.derived
->attr
.pdt_template
3756 && gfc_get_derived_super_type (*sym
) == c2
->ts
.u
.derived
)
3758 gfc_formal_arglist
*f
;
3760 old_param_spec_list
= type_param_spec_list
;
3762 /* Obtain a spec list appropriate to the extended type..*/
3763 actual_param
= gfc_copy_actual_arglist (type_param_spec_list
);
3764 type_param_spec_list
= actual_param
;
3765 for (f
= c1
->ts
.u
.derived
->formal
; f
&& f
->next
; f
= f
->next
)
3766 actual_param
= actual_param
->next
;
3769 gfc_free_actual_arglist (actual_param
->next
);
3770 actual_param
->next
= NULL
;
3773 /* Now obtain the PDT instance for the extended type. */
3774 c2
->param_list
= type_param_spec_list
;
3775 m
= gfc_get_pdt_instance (type_param_spec_list
, &c2
->ts
.u
.derived
,
3777 type_param_spec_list
= old_param_spec_list
;
3779 c2
->ts
.u
.derived
->refs
++;
3780 gfc_set_sym_referenced (c2
->ts
.u
.derived
);
3782 /* Set extension level. */
3783 if (c2
->ts
.u
.derived
->attr
.extension
== 255)
3785 /* Since the extension field is 8 bit wide, we can only have
3786 up to 255 extension levels. */
3787 gfc_error ("Maximum extension level reached with type %qs at %L",
3788 c2
->ts
.u
.derived
->name
,
3789 &c2
->ts
.u
.derived
->declared_at
);
3792 instance
->attr
.extension
= c2
->ts
.u
.derived
->attr
.extension
+ 1;
3797 /* Set the component kind using the parameterized expression. */
3798 if ((c1
->ts
.kind
== 0 || c1
->ts
.type
== BT_CHARACTER
)
3799 && c1
->kind_expr
!= NULL
)
3801 gfc_expr
*e
= gfc_copy_expr (c1
->kind_expr
);
3802 gfc_insert_kind_parameter_exprs (e
);
3803 gfc_simplify_expr (e
, 1);
3804 gfc_extract_int (e
, &c2
->ts
.kind
);
3806 if (gfc_validate_kind (c2
->ts
.type
, c2
->ts
.kind
, true) < 0)
3808 gfc_error ("Kind %d not supported for type %s at %C",
3809 c2
->ts
.kind
, gfc_basic_typename (c2
->ts
.type
));
3814 /* Similarly, set the string length if parameterized. */
3815 if (c1
->ts
.type
== BT_CHARACTER
3816 && c1
->ts
.u
.cl
->length
3817 && gfc_derived_parameter_expr (c1
->ts
.u
.cl
->length
))
3820 e
= gfc_copy_expr (c1
->ts
.u
.cl
->length
);
3821 gfc_insert_kind_parameter_exprs (e
);
3822 gfc_simplify_expr (e
, 1);
3823 c2
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
3824 c2
->ts
.u
.cl
->length
= e
;
3825 c2
->attr
.pdt_string
= 1;
3828 /* Set up either the KIND/LEN initializer, if constant,
3829 or the parameterized expression. Use the template
3830 initializer if one is not already set in this instance. */
3831 if (c2
->attr
.pdt_kind
|| c2
->attr
.pdt_len
)
3833 if (tail
&& tail
->expr
&& gfc_is_constant_expr (tail
->expr
))
3834 c2
->initializer
= gfc_copy_expr (tail
->expr
);
3835 else if (tail
&& tail
->expr
)
3837 c2
->param_list
= gfc_get_actual_arglist ();
3838 c2
->param_list
->name
= tail
->name
;
3839 c2
->param_list
->expr
= gfc_copy_expr (tail
->expr
);
3840 c2
->param_list
->next
= NULL
;
3843 if (!c2
->initializer
&& c1
->initializer
)
3844 c2
->initializer
= gfc_copy_expr (c1
->initializer
);
3847 /* Copy the array spec. */
3848 c2
->as
= gfc_copy_array_spec (c1
->as
);
3849 if (c1
->ts
.type
== BT_CLASS
)
3850 CLASS_DATA (c2
)->as
= gfc_copy_array_spec (CLASS_DATA (c1
)->as
);
3852 /* Determine if an array spec is parameterized. If so, substitute
3853 in the parameter expressions for the bounds and set the pdt_array
3854 attribute. Notice that this attribute must be unconditionally set
3855 if this is an array of parameterized character length. */
3856 if (c1
->as
&& c1
->as
->type
== AS_EXPLICIT
)
3858 bool pdt_array
= false;
3860 /* Are the bounds of the array parameterized? */
3861 for (i
= 0; i
< c1
->as
->rank
; i
++)
3863 if (gfc_derived_parameter_expr (c1
->as
->lower
[i
]))
3865 if (gfc_derived_parameter_expr (c1
->as
->upper
[i
]))
3869 /* If they are, free the expressions for the bounds and
3870 replace them with the template expressions with substitute
3872 for (i
= 0; pdt_array
&& i
< c1
->as
->rank
; i
++)
3875 e
= gfc_copy_expr (c1
->as
->lower
[i
]);
3876 gfc_insert_kind_parameter_exprs (e
);
3877 gfc_simplify_expr (e
, 1);
3878 gfc_free_expr (c2
->as
->lower
[i
]);
3879 c2
->as
->lower
[i
] = e
;
3880 e
= gfc_copy_expr (c1
->as
->upper
[i
]);
3881 gfc_insert_kind_parameter_exprs (e
);
3882 gfc_simplify_expr (e
, 1);
3883 gfc_free_expr (c2
->as
->upper
[i
]);
3884 c2
->as
->upper
[i
] = e
;
3886 c2
->attr
.pdt_array
= pdt_array
? 1 : c2
->attr
.pdt_string
;
3887 if (c1
->initializer
)
3889 c2
->initializer
= gfc_copy_expr (c1
->initializer
);
3890 gfc_insert_kind_parameter_exprs (c2
->initializer
);
3891 gfc_simplify_expr (c2
->initializer
, 1);
3895 /* Recurse into this function for PDT components. */
3896 if ((c1
->ts
.type
== BT_DERIVED
|| c1
->ts
.type
== BT_CLASS
)
3897 && c1
->ts
.u
.derived
&& c1
->ts
.u
.derived
->attr
.pdt_template
)
3899 gfc_actual_arglist
*params
;
3900 /* The component in the template has a list of specification
3901 expressions derived from its declaration. */
3902 params
= gfc_copy_actual_arglist (c1
->param_list
);
3903 actual_param
= params
;
3904 /* Substitute the template parameters with the expressions
3905 from the specification list. */
3906 for (;actual_param
; actual_param
= actual_param
->next
)
3907 gfc_insert_parameter_exprs (actual_param
->expr
,
3908 type_param_spec_list
);
3910 /* Now obtain the PDT instance for the component. */
3911 old_param_spec_list
= type_param_spec_list
;
3912 m
= gfc_get_pdt_instance (params
, &c2
->ts
.u
.derived
, NULL
);
3913 type_param_spec_list
= old_param_spec_list
;
3915 c2
->param_list
= params
;
3916 if (!(c2
->attr
.pointer
|| c2
->attr
.allocatable
))
3917 c2
->initializer
= gfc_default_initializer (&c2
->ts
);
3919 if (c2
->attr
.allocatable
)
3920 instance
->attr
.alloc_comp
= 1;
3924 gfc_commit_symbol (instance
);
3926 *ext_param_list
= type_param_spec_list
;
3931 gfc_free_actual_arglist (type_param_spec_list
);
3936 /* Matches a declaration-type-spec (F03:R502). If successful, sets the ts
3937 structure to the matched specification. This is necessary for FUNCTION and
3938 IMPLICIT statements.
3940 If implicit_flag is nonzero, then we don't check for the optional
3941 kind specification. Not doing so is needed for matching an IMPLICIT
3942 statement correctly. */
3945 gfc_match_decl_type_spec (gfc_typespec
*ts
, int implicit_flag
)
3947 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3948 gfc_symbol
*sym
, *dt_sym
;
3951 bool seen_deferred_kind
, matched_type
;
3952 const char *dt_name
;
3954 decl_type_param_list
= NULL
;
3956 /* A belt and braces check that the typespec is correctly being treated
3957 as a deferred characteristic association. */
3958 seen_deferred_kind
= (gfc_current_state () == COMP_FUNCTION
)
3959 && (gfc_current_block ()->result
->ts
.kind
== -1)
3960 && (ts
->kind
== -1);
3962 if (seen_deferred_kind
)
3965 /* Clear the current binding label, in case one is given. */
3966 curr_binding_label
= NULL
;
3968 if (gfc_match (" byte") == MATCH_YES
)
3970 if (!gfc_notify_std (GFC_STD_GNU
, "BYTE type at %C"))
3973 if (gfc_validate_kind (BT_INTEGER
, 1, true) < 0)
3975 gfc_error ("BYTE type used at %C "
3976 "is not available on the target machine");
3980 ts
->type
= BT_INTEGER
;
3986 m
= gfc_match (" type (");
3987 matched_type
= (m
== MATCH_YES
);
3990 gfc_gobble_whitespace ();
3991 if (gfc_peek_ascii_char () == '*')
3993 if ((m
= gfc_match ("*)")) != MATCH_YES
)
3995 if (gfc_comp_struct (gfc_current_state ()))
3997 gfc_error ("Assumed type at %C is not allowed for components");
4000 if (!gfc_notify_std (GFC_STD_F2018
, "Assumed type at %C"))
4002 ts
->type
= BT_ASSUMED
;
4006 m
= gfc_match ("%n", name
);
4007 matched_type
= (m
== MATCH_YES
);
4010 if ((matched_type
&& strcmp ("integer", name
) == 0)
4011 || (!matched_type
&& gfc_match (" integer") == MATCH_YES
))
4013 ts
->type
= BT_INTEGER
;
4014 ts
->kind
= gfc_default_integer_kind
;
4018 if ((matched_type
&& strcmp ("character", name
) == 0)
4019 || (!matched_type
&& gfc_match (" character") == MATCH_YES
))
4022 && !gfc_notify_std (GFC_STD_F2008
, "TYPE with "
4023 "intrinsic-type-spec at %C"))
4026 ts
->type
= BT_CHARACTER
;
4027 if (implicit_flag
== 0)
4028 m
= gfc_match_char_spec (ts
);
4032 if (matched_type
&& m
== MATCH_YES
&& gfc_match_char (')') != MATCH_YES
)
4038 if ((matched_type
&& strcmp ("real", name
) == 0)
4039 || (!matched_type
&& gfc_match (" real") == MATCH_YES
))
4042 ts
->kind
= gfc_default_real_kind
;
4047 && (strcmp ("doubleprecision", name
) == 0
4048 || (strcmp ("double", name
) == 0
4049 && gfc_match (" precision") == MATCH_YES
)))
4050 || (!matched_type
&& gfc_match (" double precision") == MATCH_YES
))
4053 && !gfc_notify_std (GFC_STD_F2008
, "TYPE with "
4054 "intrinsic-type-spec at %C"))
4056 if (matched_type
&& gfc_match_char (')') != MATCH_YES
)
4060 ts
->kind
= gfc_default_double_kind
;
4064 if ((matched_type
&& strcmp ("complex", name
) == 0)
4065 || (!matched_type
&& gfc_match (" complex") == MATCH_YES
))
4067 ts
->type
= BT_COMPLEX
;
4068 ts
->kind
= gfc_default_complex_kind
;
4073 && (strcmp ("doublecomplex", name
) == 0
4074 || (strcmp ("double", name
) == 0
4075 && gfc_match (" complex") == MATCH_YES
)))
4076 || (!matched_type
&& gfc_match (" double complex") == MATCH_YES
))
4078 if (!gfc_notify_std (GFC_STD_GNU
, "DOUBLE COMPLEX at %C"))
4082 && !gfc_notify_std (GFC_STD_F2008
, "TYPE with "
4083 "intrinsic-type-spec at %C"))
4086 if (matched_type
&& gfc_match_char (')') != MATCH_YES
)
4089 ts
->type
= BT_COMPLEX
;
4090 ts
->kind
= gfc_default_double_kind
;
4094 if ((matched_type
&& strcmp ("logical", name
) == 0)
4095 || (!matched_type
&& gfc_match (" logical") == MATCH_YES
))
4097 ts
->type
= BT_LOGICAL
;
4098 ts
->kind
= gfc_default_logical_kind
;
4104 m
= gfc_match_actual_arglist (1, &decl_type_param_list
, true);
4105 if (m
== MATCH_ERROR
)
4108 m
= gfc_match_char (')');
4112 m
= match_record_decl (name
);
4114 if (matched_type
|| m
== MATCH_YES
)
4116 ts
->type
= BT_DERIVED
;
4117 /* We accept record/s/ or type(s) where s is a structure, but we
4118 * don't need all the extra derived-type stuff for structures. */
4119 if (gfc_find_symbol (gfc_dt_upper_string (name
), NULL
, 1, &sym
))
4121 gfc_error ("Type name %qs at %C is ambiguous", name
);
4125 if (sym
&& sym
->attr
.flavor
== FL_DERIVED
4126 && sym
->attr
.pdt_template
4127 && gfc_current_state () != COMP_DERIVED
)
4129 m
= gfc_get_pdt_instance (decl_type_param_list
, &sym
, NULL
);
4132 gcc_assert (!sym
->attr
.pdt_template
&& sym
->attr
.pdt_type
);
4133 ts
->u
.derived
= sym
;
4134 strcpy (name
, gfc_dt_lower_string (sym
->name
));
4137 if (sym
&& sym
->attr
.flavor
== FL_STRUCT
)
4139 ts
->u
.derived
= sym
;
4142 /* Actually a derived type. */
4147 /* Match nested STRUCTURE declarations; only valid within another
4148 structure declaration. */
4149 if (flag_dec_structure
4150 && (gfc_current_state () == COMP_STRUCTURE
4151 || gfc_current_state () == COMP_MAP
))
4153 m
= gfc_match (" structure");
4156 m
= gfc_match_structure_decl ();
4159 /* gfc_new_block is updated by match_structure_decl. */
4160 ts
->type
= BT_DERIVED
;
4161 ts
->u
.derived
= gfc_new_block
;
4165 if (m
== MATCH_ERROR
)
4169 /* Match CLASS declarations. */
4170 m
= gfc_match (" class ( * )");
4171 if (m
== MATCH_ERROR
)
4173 else if (m
== MATCH_YES
)
4177 ts
->type
= BT_CLASS
;
4178 gfc_find_symbol ("STAR", gfc_current_ns
, 1, &upe
);
4181 upe
= gfc_new_symbol ("STAR", gfc_current_ns
);
4182 st
= gfc_new_symtree (&gfc_current_ns
->sym_root
, "STAR");
4184 gfc_set_sym_referenced (upe
);
4186 upe
->ts
.type
= BT_VOID
;
4187 upe
->attr
.unlimited_polymorphic
= 1;
4188 /* This is essential to force the construction of
4189 unlimited polymorphic component class containers. */
4190 upe
->attr
.zero_comp
= 1;
4191 if (!gfc_add_flavor (&upe
->attr
, FL_DERIVED
, NULL
,
4192 &gfc_current_locus
))
4197 st
= gfc_get_tbp_symtree (&gfc_current_ns
->sym_root
, "STAR");
4201 ts
->u
.derived
= upe
;
4205 m
= gfc_match (" class (");
4208 m
= gfc_match ("%n", name
);
4214 ts
->type
= BT_CLASS
;
4216 if (!gfc_notify_std (GFC_STD_F2003
, "CLASS statement at %C"))
4219 m
= gfc_match_actual_arglist (1, &decl_type_param_list
, true);
4220 if (m
== MATCH_ERROR
)
4223 m
= gfc_match_char (')');
4228 /* Defer association of the derived type until the end of the
4229 specification block. However, if the derived type can be
4230 found, add it to the typespec. */
4231 if (gfc_matching_function
)
4233 ts
->u
.derived
= NULL
;
4234 if (gfc_current_state () != COMP_INTERFACE
4235 && !gfc_find_symbol (name
, NULL
, 1, &sym
) && sym
)
4237 sym
= gfc_find_dt_in_generic (sym
);
4238 ts
->u
.derived
= sym
;
4243 /* Search for the name but allow the components to be defined later. If
4244 type = -1, this typespec has been seen in a function declaration but
4245 the type could not be accessed at that point. The actual derived type is
4246 stored in a symtree with the first letter of the name capitalized; the
4247 symtree with the all lower-case name contains the associated
4248 generic function. */
4249 dt_name
= gfc_dt_upper_string (name
);
4254 gfc_get_ha_symbol (name
, &sym
);
4255 if (sym
->generic
&& gfc_find_symbol (dt_name
, NULL
, 0, &dt_sym
))
4257 gfc_error ("Type name %qs at %C is ambiguous", name
);
4260 if (sym
->generic
&& !dt_sym
)
4261 dt_sym
= gfc_find_dt_in_generic (sym
);
4263 /* Host associated PDTs can get confused with their constructors
4264 because they ar instantiated in the template's namespace. */
4267 if (gfc_find_symbol (dt_name
, NULL
, 1, &dt_sym
))
4269 gfc_error ("Type name %qs at %C is ambiguous", name
);
4272 if (dt_sym
&& !dt_sym
->attr
.pdt_type
)
4276 else if (ts
->kind
== -1)
4278 int iface
= gfc_state_stack
->previous
->state
!= COMP_INTERFACE
4279 || gfc_current_ns
->has_import_set
;
4280 gfc_find_symbol (name
, NULL
, iface
, &sym
);
4281 if (sym
&& sym
->generic
&& gfc_find_symbol (dt_name
, NULL
, 1, &dt_sym
))
4283 gfc_error ("Type name %qs at %C is ambiguous", name
);
4286 if (sym
&& sym
->generic
&& !dt_sym
)
4287 dt_sym
= gfc_find_dt_in_generic (sym
);
4294 if ((sym
->attr
.flavor
!= FL_UNKNOWN
&& sym
->attr
.flavor
!= FL_STRUCT
4295 && !(sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.generic
))
4296 || sym
->attr
.subroutine
)
4298 gfc_error ("Type name %qs at %C conflicts with previously declared "
4299 "entity at %L, which has the same name", name
,
4304 if (sym
&& sym
->attr
.flavor
== FL_DERIVED
4305 && sym
->attr
.pdt_template
4306 && gfc_current_state () != COMP_DERIVED
)
4308 m
= gfc_get_pdt_instance (decl_type_param_list
, &sym
, NULL
);
4311 gcc_assert (!sym
->attr
.pdt_template
&& sym
->attr
.pdt_type
);
4312 ts
->u
.derived
= sym
;
4313 strcpy (name
, gfc_dt_lower_string (sym
->name
));
4316 gfc_save_symbol_data (sym
);
4317 gfc_set_sym_referenced (sym
);
4318 if (!sym
->attr
.generic
4319 && !gfc_add_generic (&sym
->attr
, sym
->name
, NULL
))
4322 if (!sym
->attr
.function
4323 && !gfc_add_function (&sym
->attr
, sym
->name
, NULL
))
4326 if (dt_sym
&& dt_sym
->attr
.flavor
== FL_DERIVED
4327 && dt_sym
->attr
.pdt_template
4328 && gfc_current_state () != COMP_DERIVED
)
4330 m
= gfc_get_pdt_instance (decl_type_param_list
, &dt_sym
, NULL
);
4333 gcc_assert (!dt_sym
->attr
.pdt_template
&& dt_sym
->attr
.pdt_type
);
4338 gfc_interface
*intr
, *head
;
4340 /* Use upper case to save the actual derived-type symbol. */
4341 gfc_get_symbol (dt_name
, NULL
, &dt_sym
);
4342 dt_sym
->name
= gfc_get_string ("%s", sym
->name
);
4343 head
= sym
->generic
;
4344 intr
= gfc_get_interface ();
4346 intr
->where
= gfc_current_locus
;
4348 sym
->generic
= intr
;
4349 sym
->attr
.if_source
= IFSRC_DECL
;
4352 gfc_save_symbol_data (dt_sym
);
4354 gfc_set_sym_referenced (dt_sym
);
4356 if (dt_sym
->attr
.flavor
!= FL_DERIVED
&& dt_sym
->attr
.flavor
!= FL_STRUCT
4357 && !gfc_add_flavor (&dt_sym
->attr
, FL_DERIVED
, sym
->name
, NULL
))
4360 ts
->u
.derived
= dt_sym
;
4366 && !gfc_notify_std (GFC_STD_F2008
, "TYPE with "
4367 "intrinsic-type-spec at %C"))
4370 /* For all types except double, derived and character, look for an
4371 optional kind specifier. MATCH_NO is actually OK at this point. */
4372 if (implicit_flag
== 1)
4374 if (matched_type
&& gfc_match_char (')') != MATCH_YES
)
4380 if (gfc_current_form
== FORM_FREE
)
4382 c
= gfc_peek_ascii_char ();
4383 if (!gfc_is_whitespace (c
) && c
!= '*' && c
!= '('
4384 && c
!= ':' && c
!= ',')
4386 if (matched_type
&& c
== ')')
4388 gfc_next_ascii_char ();
4395 m
= gfc_match_kind_spec (ts
, false);
4396 if (m
== MATCH_NO
&& ts
->type
!= BT_CHARACTER
)
4398 m
= gfc_match_old_kind_spec (ts
);
4399 if (gfc_validate_kind (ts
->type
, ts
->kind
, true) == -1)
4403 if (matched_type
&& gfc_match_char (')') != MATCH_YES
)
4406 /* Defer association of the KIND expression of function results
4407 until after USE and IMPORT statements. */
4408 if ((gfc_current_state () == COMP_NONE
&& gfc_error_flag_test ())
4409 || gfc_matching_function
)
4413 m
= MATCH_YES
; /* No kind specifier found. */
4419 /* Match an IMPLICIT NONE statement. Actually, this statement is
4420 already matched in parse.c, or we would not end up here in the
4421 first place. So the only thing we need to check, is if there is
4422 trailing garbage. If not, the match is successful. */
4425 gfc_match_implicit_none (void)
4429 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4431 bool external
= false;
4432 locus cur_loc
= gfc_current_locus
;
4434 if (gfc_current_ns
->seen_implicit_none
4435 || gfc_current_ns
->has_implicit_none_export
)
4437 gfc_error ("Duplicate IMPLICIT NONE statement at %C");
4441 gfc_gobble_whitespace ();
4442 c
= gfc_peek_ascii_char ();
4445 (void) gfc_next_ascii_char ();
4446 if (!gfc_notify_std (GFC_STD_F2018
, "IMPORT NONE with spec list at %C"))
4449 gfc_gobble_whitespace ();
4450 if (gfc_peek_ascii_char () == ')')
4452 (void) gfc_next_ascii_char ();
4458 m
= gfc_match (" %n", name
);
4462 if (strcmp (name
, "type") == 0)
4464 else if (strcmp (name
, "external") == 0)
4469 gfc_gobble_whitespace ();
4470 c
= gfc_next_ascii_char ();
4481 if (gfc_match_eos () != MATCH_YES
)
4484 gfc_set_implicit_none (type
, external
, &cur_loc
);
4490 /* Match the letter range(s) of an IMPLICIT statement. */
4493 match_implicit_range (void)
4499 cur_loc
= gfc_current_locus
;
4501 gfc_gobble_whitespace ();
4502 c
= gfc_next_ascii_char ();
4505 gfc_error ("Missing character range in IMPLICIT at %C");
4512 gfc_gobble_whitespace ();
4513 c1
= gfc_next_ascii_char ();
4517 gfc_gobble_whitespace ();
4518 c
= gfc_next_ascii_char ();
4523 inner
= 0; /* Fall through. */
4530 gfc_gobble_whitespace ();
4531 c2
= gfc_next_ascii_char ();
4535 gfc_gobble_whitespace ();
4536 c
= gfc_next_ascii_char ();
4538 if ((c
!= ',') && (c
!= ')'))
4551 gfc_error ("Letters must be in alphabetic order in "
4552 "IMPLICIT statement at %C");
4556 /* See if we can add the newly matched range to the pending
4557 implicits from this IMPLICIT statement. We do not check for
4558 conflicts with whatever earlier IMPLICIT statements may have
4559 set. This is done when we've successfully finished matching
4561 if (!gfc_add_new_implicit_range (c1
, c2
))
4568 gfc_syntax_error (ST_IMPLICIT
);
4570 gfc_current_locus
= cur_loc
;
4575 /* Match an IMPLICIT statement, storing the types for
4576 gfc_set_implicit() if the statement is accepted by the parser.
4577 There is a strange looking, but legal syntactic construction
4578 possible. It looks like:
4580 IMPLICIT INTEGER (a-b) (c-d)
4582 This is legal if "a-b" is a constant expression that happens to
4583 equal one of the legal kinds for integers. The real problem
4584 happens with an implicit specification that looks like:
4586 IMPLICIT INTEGER (a-b)
4588 In this case, a typespec matcher that is "greedy" (as most of the
4589 matchers are) gobbles the character range as a kindspec, leaving
4590 nothing left. We therefore have to go a bit more slowly in the
4591 matching process by inhibiting the kindspec checking during
4592 typespec matching and checking for a kind later. */
4595 gfc_match_implicit (void)
4602 if (gfc_current_ns
->seen_implicit_none
)
4604 gfc_error ("IMPLICIT statement at %C following an IMPLICIT NONE (type) "
4611 /* We don't allow empty implicit statements. */
4612 if (gfc_match_eos () == MATCH_YES
)
4614 gfc_error ("Empty IMPLICIT statement at %C");
4620 /* First cleanup. */
4621 gfc_clear_new_implicit ();
4623 /* A basic type is mandatory here. */
4624 m
= gfc_match_decl_type_spec (&ts
, 1);
4625 if (m
== MATCH_ERROR
)
4630 cur_loc
= gfc_current_locus
;
4631 m
= match_implicit_range ();
4635 /* We may have <TYPE> (<RANGE>). */
4636 gfc_gobble_whitespace ();
4637 c
= gfc_peek_ascii_char ();
4638 if (c
== ',' || c
== '\n' || c
== ';' || c
== '!')
4640 /* Check for CHARACTER with no length parameter. */
4641 if (ts
.type
== BT_CHARACTER
&& !ts
.u
.cl
)
4643 ts
.kind
= gfc_default_character_kind
;
4644 ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
4645 ts
.u
.cl
->length
= gfc_get_int_expr (gfc_charlen_int_kind
,
4649 /* Record the Successful match. */
4650 if (!gfc_merge_new_implicit (&ts
))
4653 c
= gfc_next_ascii_char ();
4654 else if (gfc_match_eos () == MATCH_ERROR
)
4659 gfc_current_locus
= cur_loc
;
4662 /* Discard the (incorrectly) matched range. */
4663 gfc_clear_new_implicit ();
4665 /* Last chance -- check <TYPE> <SELECTOR> (<RANGE>). */
4666 if (ts
.type
== BT_CHARACTER
)
4667 m
= gfc_match_char_spec (&ts
);
4670 m
= gfc_match_kind_spec (&ts
, false);
4673 m
= gfc_match_old_kind_spec (&ts
);
4674 if (m
== MATCH_ERROR
)
4680 if (m
== MATCH_ERROR
)
4683 m
= match_implicit_range ();
4684 if (m
== MATCH_ERROR
)
4689 gfc_gobble_whitespace ();
4690 c
= gfc_next_ascii_char ();
4691 if (c
!= ',' && gfc_match_eos () != MATCH_YES
)
4694 if (!gfc_merge_new_implicit (&ts
))
4702 gfc_syntax_error (ST_IMPLICIT
);
4710 gfc_match_import (void)
4712 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4717 if (gfc_current_ns
->proc_name
== NULL
4718 || gfc_current_ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
4720 gfc_error ("IMPORT statement at %C only permitted in "
4721 "an INTERFACE body");
4725 if (gfc_current_ns
->proc_name
->attr
.module_procedure
)
4727 gfc_error ("F2008: C1210 IMPORT statement at %C is not permitted "
4728 "in a module procedure interface body");
4732 if (!gfc_notify_std (GFC_STD_F2003
, "IMPORT statement at %C"))
4735 if (gfc_match_eos () == MATCH_YES
)
4737 /* All host variables should be imported. */
4738 gfc_current_ns
->has_import_set
= 1;
4742 if (gfc_match (" ::") == MATCH_YES
)
4744 if (gfc_match_eos () == MATCH_YES
)
4746 gfc_error ("Expecting list of named entities at %C");
4754 m
= gfc_match (" %n", name
);
4758 if (gfc_current_ns
->parent
!= NULL
4759 && gfc_find_symbol (name
, gfc_current_ns
->parent
, 1, &sym
))
4761 gfc_error ("Type name %qs at %C is ambiguous", name
);
4764 else if (!sym
&& gfc_current_ns
->proc_name
->ns
->parent
!= NULL
4765 && gfc_find_symbol (name
,
4766 gfc_current_ns
->proc_name
->ns
->parent
,
4769 gfc_error ("Type name %qs at %C is ambiguous", name
);
4775 gfc_error ("Cannot IMPORT %qs from host scoping unit "
4776 "at %C - does not exist.", name
);
4780 if (gfc_find_symtree (gfc_current_ns
->sym_root
, name
))
4782 gfc_warning (0, "%qs is already IMPORTed from host scoping unit "
4787 st
= gfc_new_symtree (&gfc_current_ns
->sym_root
, name
);
4790 sym
->attr
.imported
= 1;
4792 if (sym
->attr
.generic
&& (sym
= gfc_find_dt_in_generic (sym
)))
4794 /* The actual derived type is stored in a symtree with the first
4795 letter of the name capitalized; the symtree with the all
4796 lower-case name contains the associated generic function. */
4797 st
= gfc_new_symtree (&gfc_current_ns
->sym_root
,
4798 gfc_dt_upper_string (name
));
4801 sym
->attr
.imported
= 1;
4814 if (gfc_match_eos () == MATCH_YES
)
4816 if (gfc_match_char (',') != MATCH_YES
)
4823 gfc_error ("Syntax error in IMPORT statement at %C");
4828 /* A minimal implementation of gfc_match without whitespace, escape
4829 characters or variable arguments. Returns true if the next
4830 characters match the TARGET template exactly. */
4833 match_string_p (const char *target
)
4837 for (p
= target
; *p
; p
++)
4838 if ((char) gfc_next_ascii_char () != *p
)
4843 /* Matches an attribute specification including array specs. If
4844 successful, leaves the variables current_attr and current_as
4845 holding the specification. Also sets the colon_seen variable for
4846 later use by matchers associated with initializations.
4848 This subroutine is a little tricky in the sense that we don't know
4849 if we really have an attr-spec until we hit the double colon.
4850 Until that time, we can only return MATCH_NO. This forces us to
4851 check for duplicate specification at this level. */
4854 match_attr_spec (void)
4856 /* Modifiers that can exist in a type statement. */
4858 { GFC_DECL_BEGIN
= 0, DECL_ALLOCATABLE
= GFC_DECL_BEGIN
,
4859 DECL_IN
= INTENT_IN
, DECL_OUT
= INTENT_OUT
, DECL_INOUT
= INTENT_INOUT
,
4860 DECL_DIMENSION
, DECL_EXTERNAL
,
4861 DECL_INTRINSIC
, DECL_OPTIONAL
,
4862 DECL_PARAMETER
, DECL_POINTER
, DECL_PROTECTED
, DECL_PRIVATE
,
4863 DECL_STATIC
, DECL_AUTOMATIC
,
4864 DECL_PUBLIC
, DECL_SAVE
, DECL_TARGET
, DECL_VALUE
, DECL_VOLATILE
,
4865 DECL_IS_BIND_C
, DECL_CODIMENSION
, DECL_ASYNCHRONOUS
, DECL_CONTIGUOUS
,
4866 DECL_LEN
, DECL_KIND
, DECL_NONE
, GFC_DECL_END
/* Sentinel */
4869 /* GFC_DECL_END is the sentinel, index starts at 0. */
4870 #define NUM_DECL GFC_DECL_END
4872 /* Make sure that values from sym_intent are safe to be used here. */
4873 gcc_assert (INTENT_IN
> 0);
4875 locus start
, seen_at
[NUM_DECL
];
4882 gfc_clear_attr (¤t_attr
);
4883 start
= gfc_current_locus
;
4889 /* See if we get all of the keywords up to the final double colon. */
4890 for (d
= GFC_DECL_BEGIN
; d
!= GFC_DECL_END
; d
++)
4898 gfc_gobble_whitespace ();
4900 ch
= gfc_next_ascii_char ();
4903 /* This is the successful exit condition for the loop. */
4904 if (gfc_next_ascii_char () == ':')
4909 gfc_gobble_whitespace ();
4910 switch (gfc_peek_ascii_char ())
4913 gfc_next_ascii_char ();
4914 switch (gfc_next_ascii_char ())
4917 if (match_string_p ("locatable"))
4919 /* Matched "allocatable". */
4920 d
= DECL_ALLOCATABLE
;
4925 if (match_string_p ("ynchronous"))
4927 /* Matched "asynchronous". */
4928 d
= DECL_ASYNCHRONOUS
;
4933 if (match_string_p ("tomatic"))
4935 /* Matched "automatic". */
4943 /* Try and match the bind(c). */
4944 m
= gfc_match_bind_c (NULL
, true);
4947 else if (m
== MATCH_ERROR
)
4952 gfc_next_ascii_char ();
4953 if ('o' != gfc_next_ascii_char ())
4955 switch (gfc_next_ascii_char ())
4958 if (match_string_p ("imension"))
4960 d
= DECL_CODIMENSION
;
4965 if (match_string_p ("tiguous"))
4967 d
= DECL_CONTIGUOUS
;
4974 if (match_string_p ("dimension"))
4979 if (match_string_p ("external"))
4984 if (match_string_p ("int"))
4986 ch
= gfc_next_ascii_char ();
4989 if (match_string_p ("nt"))
4991 /* Matched "intent". */
4992 d
= match_intent_spec ();
4993 if (d
== INTENT_UNKNOWN
)
5002 if (match_string_p ("insic"))
5004 /* Matched "intrinsic". */
5012 if (match_string_p ("kind"))
5017 if (match_string_p ("len"))
5022 if (match_string_p ("optional"))
5027 gfc_next_ascii_char ();
5028 switch (gfc_next_ascii_char ())
5031 if (match_string_p ("rameter"))
5033 /* Matched "parameter". */
5039 if (match_string_p ("inter"))
5041 /* Matched "pointer". */
5047 ch
= gfc_next_ascii_char ();
5050 if (match_string_p ("vate"))
5052 /* Matched "private". */
5058 if (match_string_p ("tected"))
5060 /* Matched "protected". */
5067 if (match_string_p ("blic"))
5069 /* Matched "public". */
5077 gfc_next_ascii_char ();
5078 switch (gfc_next_ascii_char ())
5081 if (match_string_p ("ve"))
5083 /* Matched "save". */
5089 if (match_string_p ("atic"))
5091 /* Matched "static". */
5099 if (match_string_p ("target"))
5104 gfc_next_ascii_char ();
5105 ch
= gfc_next_ascii_char ();
5108 if (match_string_p ("lue"))
5110 /* Matched "value". */
5116 if (match_string_p ("latile"))
5118 /* Matched "volatile". */
5126 /* No double colon and no recognizable decl_type, so assume that
5127 we've been looking at something else the whole time. */
5134 /* Check to make sure any parens are paired up correctly. */
5135 if (gfc_match_parens () == MATCH_ERROR
)
5142 seen_at
[d
] = gfc_current_locus
;
5144 if (d
== DECL_DIMENSION
|| d
== DECL_CODIMENSION
)
5146 gfc_array_spec
*as
= NULL
;
5148 m
= gfc_match_array_spec (&as
, d
== DECL_DIMENSION
,
5149 d
== DECL_CODIMENSION
);
5151 if (current_as
== NULL
)
5153 else if (m
== MATCH_YES
)
5155 if (!merge_array_spec (as
, current_as
, false))
5162 if (d
== DECL_CODIMENSION
)
5163 gfc_error ("Missing codimension specification at %C");
5165 gfc_error ("Missing dimension specification at %C");
5169 if (m
== MATCH_ERROR
)
5174 /* Since we've seen a double colon, we have to be looking at an
5175 attr-spec. This means that we can now issue errors. */
5176 for (d
= GFC_DECL_BEGIN
; d
!= GFC_DECL_END
; d
++)
5181 case DECL_ALLOCATABLE
:
5182 attr
= "ALLOCATABLE";
5184 case DECL_ASYNCHRONOUS
:
5185 attr
= "ASYNCHRONOUS";
5187 case DECL_CODIMENSION
:
5188 attr
= "CODIMENSION";
5190 case DECL_CONTIGUOUS
:
5191 attr
= "CONTIGUOUS";
5193 case DECL_DIMENSION
:
5200 attr
= "INTENT (IN)";
5203 attr
= "INTENT (OUT)";
5206 attr
= "INTENT (IN OUT)";
5208 case DECL_INTRINSIC
:
5220 case DECL_PARAMETER
:
5226 case DECL_PROTECTED
:
5241 case DECL_AUTOMATIC
:
5247 case DECL_IS_BIND_C
:
5257 attr
= NULL
; /* This shouldn't happen. */
5260 gfc_error ("Duplicate %s attribute at %L", attr
, &seen_at
[d
]);
5265 /* Now that we've dealt with duplicate attributes, add the attributes
5266 to the current attribute. */
5267 for (d
= GFC_DECL_BEGIN
; d
!= GFC_DECL_END
; d
++)
5274 if ((d
== DECL_STATIC
|| d
== DECL_AUTOMATIC
)
5275 && !flag_dec_static
)
5277 gfc_error ("%s at %L is a DEC extension, enable with "
5279 d
== DECL_STATIC
? "STATIC" : "AUTOMATIC", &seen_at
[d
]);
5283 /* Allow SAVE with STATIC, but don't complain. */
5284 if (d
== DECL_STATIC
&& seen
[DECL_SAVE
])
5287 if (gfc_current_state () == COMP_DERIVED
5288 && d
!= DECL_DIMENSION
&& d
!= DECL_CODIMENSION
5289 && d
!= DECL_POINTER
&& d
!= DECL_PRIVATE
5290 && d
!= DECL_PUBLIC
&& d
!= DECL_CONTIGUOUS
&& d
!= DECL_NONE
)
5292 if (d
== DECL_ALLOCATABLE
)
5294 if (!gfc_notify_std (GFC_STD_F2003
, "ALLOCATABLE "
5295 "attribute at %C in a TYPE definition"))
5301 else if (d
== DECL_KIND
)
5303 if (!gfc_notify_std (GFC_STD_F2003
, "KIND "
5304 "attribute at %C in a TYPE definition"))
5309 if (current_ts
.type
!= BT_INTEGER
)
5311 gfc_error ("Component with KIND attribute at %C must be "
5316 if (current_ts
.kind
!= gfc_default_integer_kind
)
5318 gfc_error ("Component with KIND attribute at %C must be "
5319 "default integer kind (%d)",
5320 gfc_default_integer_kind
);
5325 else if (d
== DECL_LEN
)
5327 if (!gfc_notify_std (GFC_STD_F2003
, "LEN "
5328 "attribute at %C in a TYPE definition"))
5333 if (current_ts
.type
!= BT_INTEGER
)
5335 gfc_error ("Component with LEN attribute at %C must be "
5340 if (current_ts
.kind
!= gfc_default_integer_kind
)
5342 gfc_error ("Component with LEN attribute at %C must be "
5343 "default integer kind (%d)",
5344 gfc_default_integer_kind
);
5351 gfc_error ("Attribute at %L is not allowed in a TYPE definition",
5358 if ((d
== DECL_PRIVATE
|| d
== DECL_PUBLIC
)
5359 && gfc_current_state () != COMP_MODULE
)
5361 if (d
== DECL_PRIVATE
)
5365 if (gfc_current_state () == COMP_DERIVED
5366 && gfc_state_stack
->previous
5367 && gfc_state_stack
->previous
->state
== COMP_MODULE
)
5369 if (!gfc_notify_std (GFC_STD_F2003
, "Attribute %s "
5370 "at %L in a TYPE definition", attr
,
5379 gfc_error ("%s attribute at %L is not allowed outside of the "
5380 "specification part of a module", attr
, &seen_at
[d
]);
5386 if (gfc_current_state () != COMP_DERIVED
5387 && (d
== DECL_KIND
|| d
== DECL_LEN
))
5389 gfc_error ("Attribute at %L is not allowed outside a TYPE "
5390 "definition", &seen_at
[d
]);
5397 case DECL_ALLOCATABLE
:
5398 t
= gfc_add_allocatable (¤t_attr
, &seen_at
[d
]);
5401 case DECL_ASYNCHRONOUS
:
5402 if (!gfc_notify_std (GFC_STD_F2003
, "ASYNCHRONOUS attribute at %C"))
5405 t
= gfc_add_asynchronous (¤t_attr
, NULL
, &seen_at
[d
]);
5408 case DECL_CODIMENSION
:
5409 t
= gfc_add_codimension (¤t_attr
, NULL
, &seen_at
[d
]);
5412 case DECL_CONTIGUOUS
:
5413 if (!gfc_notify_std (GFC_STD_F2008
, "CONTIGUOUS attribute at %C"))
5416 t
= gfc_add_contiguous (¤t_attr
, NULL
, &seen_at
[d
]);
5419 case DECL_DIMENSION
:
5420 t
= gfc_add_dimension (¤t_attr
, NULL
, &seen_at
[d
]);
5424 t
= gfc_add_external (¤t_attr
, &seen_at
[d
]);
5428 t
= gfc_add_intent (¤t_attr
, INTENT_IN
, &seen_at
[d
]);
5432 t
= gfc_add_intent (¤t_attr
, INTENT_OUT
, &seen_at
[d
]);
5436 t
= gfc_add_intent (¤t_attr
, INTENT_INOUT
, &seen_at
[d
]);
5439 case DECL_INTRINSIC
:
5440 t
= gfc_add_intrinsic (¤t_attr
, &seen_at
[d
]);
5444 t
= gfc_add_optional (¤t_attr
, &seen_at
[d
]);
5448 t
= gfc_add_kind (¤t_attr
, &seen_at
[d
]);
5452 t
= gfc_add_len (¤t_attr
, &seen_at
[d
]);
5455 case DECL_PARAMETER
:
5456 t
= gfc_add_flavor (¤t_attr
, FL_PARAMETER
, NULL
, &seen_at
[d
]);
5460 t
= gfc_add_pointer (¤t_attr
, &seen_at
[d
]);
5463 case DECL_PROTECTED
:
5464 if (gfc_current_state () != COMP_MODULE
5465 || (gfc_current_ns
->proc_name
5466 && gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
))
5468 gfc_error ("PROTECTED at %C only allowed in specification "
5469 "part of a module");
5474 if (!gfc_notify_std (GFC_STD_F2003
, "PROTECTED attribute at %C"))
5477 t
= gfc_add_protected (¤t_attr
, NULL
, &seen_at
[d
]);
5481 t
= gfc_add_access (¤t_attr
, ACCESS_PRIVATE
, NULL
,
5486 t
= gfc_add_access (¤t_attr
, ACCESS_PUBLIC
, NULL
,
5492 t
= gfc_add_save (¤t_attr
, SAVE_EXPLICIT
, NULL
, &seen_at
[d
]);
5495 case DECL_AUTOMATIC
:
5496 t
= gfc_add_automatic (¤t_attr
, NULL
, &seen_at
[d
]);
5500 t
= gfc_add_target (¤t_attr
, &seen_at
[d
]);
5503 case DECL_IS_BIND_C
:
5504 t
= gfc_add_is_bind_c(¤t_attr
, NULL
, &seen_at
[d
], 0);
5508 if (!gfc_notify_std (GFC_STD_F2003
, "VALUE attribute at %C"))
5511 t
= gfc_add_value (¤t_attr
, NULL
, &seen_at
[d
]);
5515 if (!gfc_notify_std (GFC_STD_F2003
, "VOLATILE attribute at %C"))
5518 t
= gfc_add_volatile (¤t_attr
, NULL
, &seen_at
[d
]);
5522 gfc_internal_error ("match_attr_spec(): Bad attribute");
5532 /* Since Fortran 2008 module variables implicitly have the SAVE attribute. */
5533 if ((gfc_current_state () == COMP_MODULE
5534 || gfc_current_state () == COMP_SUBMODULE
)
5535 && !current_attr
.save
5536 && (gfc_option
.allow_std
& GFC_STD_F2008
) != 0)
5537 current_attr
.save
= SAVE_IMPLICIT
;
5543 gfc_current_locus
= start
;
5544 gfc_free_array_spec (current_as
);
5551 /* Set the binding label, dest_label, either with the binding label
5552 stored in the given gfc_typespec, ts, or if none was provided, it
5553 will be the symbol name in all lower case, as required by the draft
5554 (J3/04-007, section 15.4.1). If a binding label was given and
5555 there is more than one argument (num_idents), it is an error. */
5558 set_binding_label (const char **dest_label
, const char *sym_name
,
5561 if (num_idents
> 1 && has_name_equals
)
5563 gfc_error ("Multiple identifiers provided with "
5564 "single NAME= specifier at %C");
5568 if (curr_binding_label
)
5569 /* Binding label given; store in temp holder till have sym. */
5570 *dest_label
= curr_binding_label
;
5573 /* No binding label given, and the NAME= specifier did not exist,
5574 which means there was no NAME="". */
5575 if (sym_name
!= NULL
&& has_name_equals
== 0)
5576 *dest_label
= IDENTIFIER_POINTER (get_identifier (sym_name
));
5583 /* Set the status of the given common block as being BIND(C) or not,
5584 depending on the given parameter, is_bind_c. */
5587 set_com_block_bind_c (gfc_common_head
*com_block
, int is_bind_c
)
5589 com_block
->is_bind_c
= is_bind_c
;
5594 /* Verify that the given gfc_typespec is for a C interoperable type. */
5597 gfc_verify_c_interop (gfc_typespec
*ts
)
5599 if (ts
->type
== BT_DERIVED
&& ts
->u
.derived
!= NULL
)
5600 return (ts
->u
.derived
->ts
.is_c_interop
|| ts
->u
.derived
->attr
.is_bind_c
)
5602 else if (ts
->type
== BT_CLASS
)
5604 else if (ts
->is_c_interop
!= 1 && ts
->type
!= BT_ASSUMED
)
5611 /* Verify that the variables of a given common block, which has been
5612 defined with the attribute specifier bind(c), to be of a C
5613 interoperable type. Errors will be reported here, if
5617 verify_com_block_vars_c_interop (gfc_common_head
*com_block
)
5619 gfc_symbol
*curr_sym
= NULL
;
5622 curr_sym
= com_block
->head
;
5624 /* Make sure we have at least one symbol. */
5625 if (curr_sym
== NULL
)
5628 /* Here we know we have a symbol, so we'll execute this loop
5632 /* The second to last param, 1, says this is in a common block. */
5633 retval
= verify_bind_c_sym (curr_sym
, &(curr_sym
->ts
), 1, com_block
);
5634 curr_sym
= curr_sym
->common_next
;
5635 } while (curr_sym
!= NULL
);
5641 /* Verify that a given BIND(C) symbol is C interoperable. If it is not,
5642 an appropriate error message is reported. */
5645 verify_bind_c_sym (gfc_symbol
*tmp_sym
, gfc_typespec
*ts
,
5646 int is_in_common
, gfc_common_head
*com_block
)
5648 bool bind_c_function
= false;
5651 if (tmp_sym
->attr
.function
&& tmp_sym
->attr
.is_bind_c
)
5652 bind_c_function
= true;
5654 if (tmp_sym
->attr
.function
&& tmp_sym
->result
!= NULL
)
5656 tmp_sym
= tmp_sym
->result
;
5657 /* Make sure it wasn't an implicitly typed result. */
5658 if (tmp_sym
->attr
.implicit_type
&& warn_c_binding_type
)
5660 gfc_warning (OPT_Wc_binding_type
,
5661 "Implicitly declared BIND(C) function %qs at "
5662 "%L may not be C interoperable", tmp_sym
->name
,
5663 &tmp_sym
->declared_at
);
5664 tmp_sym
->ts
.f90_type
= tmp_sym
->ts
.type
;
5665 /* Mark it as C interoperable to prevent duplicate warnings. */
5666 tmp_sym
->ts
.is_c_interop
= 1;
5667 tmp_sym
->attr
.is_c_interop
= 1;
5671 /* Here, we know we have the bind(c) attribute, so if we have
5672 enough type info, then verify that it's a C interop kind.
5673 The info could be in the symbol already, or possibly still in
5674 the given ts (current_ts), so look in both. */
5675 if (tmp_sym
->ts
.type
!= BT_UNKNOWN
|| ts
->type
!= BT_UNKNOWN
)
5677 if (!gfc_verify_c_interop (&(tmp_sym
->ts
)))
5679 /* See if we're dealing with a sym in a common block or not. */
5680 if (is_in_common
== 1 && warn_c_binding_type
)
5682 gfc_warning (OPT_Wc_binding_type
,
5683 "Variable %qs in common block %qs at %L "
5684 "may not be a C interoperable "
5685 "kind though common block %qs is BIND(C)",
5686 tmp_sym
->name
, com_block
->name
,
5687 &(tmp_sym
->declared_at
), com_block
->name
);
5691 if (tmp_sym
->ts
.type
== BT_DERIVED
|| ts
->type
== BT_DERIVED
)
5692 gfc_error ("Type declaration %qs at %L is not C "
5693 "interoperable but it is BIND(C)",
5694 tmp_sym
->name
, &(tmp_sym
->declared_at
));
5695 else if (warn_c_binding_type
)
5696 gfc_warning (OPT_Wc_binding_type
, "Variable %qs at %L "
5697 "may not be a C interoperable "
5698 "kind but it is BIND(C)",
5699 tmp_sym
->name
, &(tmp_sym
->declared_at
));
5703 /* Variables declared w/in a common block can't be bind(c)
5704 since there's no way for C to see these variables, so there's
5705 semantically no reason for the attribute. */
5706 if (is_in_common
== 1 && tmp_sym
->attr
.is_bind_c
== 1)
5708 gfc_error ("Variable %qs in common block %qs at "
5709 "%L cannot be declared with BIND(C) "
5710 "since it is not a global",
5711 tmp_sym
->name
, com_block
->name
,
5712 &(tmp_sym
->declared_at
));
5716 /* Scalar variables that are bind(c) cannot have the pointer
5717 or allocatable attributes. */
5718 if (tmp_sym
->attr
.is_bind_c
== 1)
5720 if (tmp_sym
->attr
.pointer
== 1)
5722 gfc_error ("Variable %qs at %L cannot have both the "
5723 "POINTER and BIND(C) attributes",
5724 tmp_sym
->name
, &(tmp_sym
->declared_at
));
5728 if (tmp_sym
->attr
.allocatable
== 1)
5730 gfc_error ("Variable %qs at %L cannot have both the "
5731 "ALLOCATABLE and BIND(C) attributes",
5732 tmp_sym
->name
, &(tmp_sym
->declared_at
));
5738 /* If it is a BIND(C) function, make sure the return value is a
5739 scalar value. The previous tests in this function made sure
5740 the type is interoperable. */
5741 if (bind_c_function
&& tmp_sym
->as
!= NULL
)
5742 gfc_error ("Return type of BIND(C) function %qs at %L cannot "
5743 "be an array", tmp_sym
->name
, &(tmp_sym
->declared_at
));
5745 /* BIND(C) functions cannot return a character string. */
5746 if (bind_c_function
&& tmp_sym
->ts
.type
== BT_CHARACTER
)
5747 if (tmp_sym
->ts
.u
.cl
== NULL
|| tmp_sym
->ts
.u
.cl
->length
== NULL
5748 || tmp_sym
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
5749 || mpz_cmp_si (tmp_sym
->ts
.u
.cl
->length
->value
.integer
, 1) != 0)
5750 gfc_error ("Return type of BIND(C) function %qs of character "
5751 "type at %L must have length 1", tmp_sym
->name
,
5752 &(tmp_sym
->declared_at
));
5755 /* See if the symbol has been marked as private. If it has, make sure
5756 there is no binding label and warn the user if there is one. */
5757 if (tmp_sym
->attr
.access
== ACCESS_PRIVATE
5758 && tmp_sym
->binding_label
)
5759 /* Use gfc_warning_now because we won't say that the symbol fails
5760 just because of this. */
5761 gfc_warning_now (0, "Symbol %qs at %L is marked PRIVATE but has been "
5762 "given the binding label %qs", tmp_sym
->name
,
5763 &(tmp_sym
->declared_at
), tmp_sym
->binding_label
);
5769 /* Set the appropriate fields for a symbol that's been declared as
5770 BIND(C) (the is_bind_c flag and the binding label), and verify that
5771 the type is C interoperable. Errors are reported by the functions
5772 used to set/test these fields. */
5775 set_verify_bind_c_sym (gfc_symbol
*tmp_sym
, int num_idents
)
5779 /* TODO: Do we need to make sure the vars aren't marked private? */
5781 /* Set the is_bind_c bit in symbol_attribute. */
5782 gfc_add_is_bind_c (&(tmp_sym
->attr
), tmp_sym
->name
, &gfc_current_locus
, 0);
5784 if (!set_binding_label (&tmp_sym
->binding_label
, tmp_sym
->name
, num_idents
))
5791 /* Set the fields marking the given common block as BIND(C), including
5792 a binding label, and report any errors encountered. */
5795 set_verify_bind_c_com_block (gfc_common_head
*com_block
, int num_idents
)
5799 /* destLabel, common name, typespec (which may have binding label). */
5800 if (!set_binding_label (&com_block
->binding_label
, com_block
->name
,
5804 /* Set the given common block (com_block) to being bind(c) (1). */
5805 set_com_block_bind_c (com_block
, 1);
5811 /* Retrieve the list of one or more identifiers that the given bind(c)
5812 attribute applies to. */
5815 get_bind_c_idents (void)
5817 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
5819 gfc_symbol
*tmp_sym
= NULL
;
5821 gfc_common_head
*com_block
= NULL
;
5823 if (gfc_match_name (name
) == MATCH_YES
)
5825 found_id
= MATCH_YES
;
5826 gfc_get_ha_symbol (name
, &tmp_sym
);
5828 else if (match_common_name (name
) == MATCH_YES
)
5830 found_id
= MATCH_YES
;
5831 com_block
= gfc_get_common (name
, 0);
5835 gfc_error ("Need either entity or common block name for "
5836 "attribute specification statement at %C");
5840 /* Save the current identifier and look for more. */
5843 /* Increment the number of identifiers found for this spec stmt. */
5846 /* Make sure we have a sym or com block, and verify that it can
5847 be bind(c). Set the appropriate field(s) and look for more
5849 if (tmp_sym
!= NULL
|| com_block
!= NULL
)
5851 if (tmp_sym
!= NULL
)
5853 if (!set_verify_bind_c_sym (tmp_sym
, num_idents
))
5858 if (!set_verify_bind_c_com_block (com_block
, num_idents
))
5862 /* Look to see if we have another identifier. */
5864 if (gfc_match_eos () == MATCH_YES
)
5865 found_id
= MATCH_NO
;
5866 else if (gfc_match_char (',') != MATCH_YES
)
5867 found_id
= MATCH_NO
;
5868 else if (gfc_match_name (name
) == MATCH_YES
)
5870 found_id
= MATCH_YES
;
5871 gfc_get_ha_symbol (name
, &tmp_sym
);
5873 else if (match_common_name (name
) == MATCH_YES
)
5875 found_id
= MATCH_YES
;
5876 com_block
= gfc_get_common (name
, 0);
5880 gfc_error ("Missing entity or common block name for "
5881 "attribute specification statement at %C");
5887 gfc_internal_error ("Missing symbol");
5889 } while (found_id
== MATCH_YES
);
5891 /* if we get here we were successful */
5896 /* Try and match a BIND(C) attribute specification statement. */
5899 gfc_match_bind_c_stmt (void)
5901 match found_match
= MATCH_NO
;
5906 /* This may not be necessary. */
5908 /* Clear the temporary binding label holder. */
5909 curr_binding_label
= NULL
;
5911 /* Look for the bind(c). */
5912 found_match
= gfc_match_bind_c (NULL
, true);
5914 if (found_match
== MATCH_YES
)
5916 if (!gfc_notify_std (GFC_STD_F2003
, "BIND(C) statement at %C"))
5919 /* Look for the :: now, but it is not required. */
5922 /* Get the identifier(s) that needs to be updated. This may need to
5923 change to hand the flag(s) for the attr specified so all identifiers
5924 found can have all appropriate parts updated (assuming that the same
5925 spec stmt can have multiple attrs, such as both bind(c) and
5927 if (!get_bind_c_idents ())
5928 /* Error message should have printed already. */
5936 /* Match a data declaration statement. */
5939 gfc_match_data_decl (void)
5945 type_param_spec_list
= NULL
;
5946 decl_type_param_list
= NULL
;
5948 num_idents_on_line
= 0;
5950 m
= gfc_match_decl_type_spec (¤t_ts
, 0);
5954 if ((current_ts
.type
== BT_DERIVED
|| current_ts
.type
== BT_CLASS
)
5955 && !gfc_comp_struct (gfc_current_state ()))
5957 sym
= gfc_use_derived (current_ts
.u
.derived
);
5965 current_ts
.u
.derived
= sym
;
5968 m
= match_attr_spec ();
5969 if (m
== MATCH_ERROR
)
5975 if (current_ts
.type
== BT_CLASS
5976 && current_ts
.u
.derived
->attr
.unlimited_polymorphic
)
5979 if ((current_ts
.type
== BT_DERIVED
|| current_ts
.type
== BT_CLASS
)
5980 && current_ts
.u
.derived
->components
== NULL
5981 && !current_ts
.u
.derived
->attr
.zero_comp
)
5984 if (current_attr
.pointer
&& gfc_comp_struct (gfc_current_state ()))
5987 if (current_attr
.allocatable
&& gfc_current_state () == COMP_DERIVED
)
5990 gfc_find_symbol (current_ts
.u
.derived
->name
,
5991 current_ts
.u
.derived
->ns
, 1, &sym
);
5993 /* Any symbol that we find had better be a type definition
5994 which has its components defined, or be a structure definition
5995 actively being parsed. */
5996 if (sym
!= NULL
&& gfc_fl_struct (sym
->attr
.flavor
)
5997 && (current_ts
.u
.derived
->components
!= NULL
5998 || current_ts
.u
.derived
->attr
.zero_comp
5999 || current_ts
.u
.derived
== gfc_new_block
))
6002 gfc_error ("Derived type at %C has not been previously defined "
6003 "and so cannot appear in a derived type definition");
6009 /* If we have an old-style character declaration, and no new-style
6010 attribute specifications, then there a comma is optional between
6011 the type specification and the variable list. */
6012 if (m
== MATCH_NO
&& current_ts
.type
== BT_CHARACTER
&& old_char_selector
)
6013 gfc_match_char (',');
6015 /* Give the types/attributes to symbols that follow. Give the element
6016 a number so that repeat character length expressions can be copied. */
6020 num_idents_on_line
++;
6021 m
= variable_decl (elem
++);
6022 if (m
== MATCH_ERROR
)
6027 if (gfc_match_eos () == MATCH_YES
)
6029 if (gfc_match_char (',') != MATCH_YES
)
6033 if (!gfc_error_flag_test ())
6035 /* An anonymous structure declaration is unambiguous; if we matched one
6036 according to gfc_match_structure_decl, we need to return MATCH_YES
6037 here to avoid confusing the remaining matchers, even if there was an
6038 error during variable_decl. We must flush any such errors. Note this
6039 causes the parser to gracefully continue parsing the remaining input
6040 as a structure body, which likely follows. */
6041 if (current_ts
.type
== BT_DERIVED
&& current_ts
.u
.derived
6042 && gfc_fl_struct (current_ts
.u
.derived
->attr
.flavor
))
6044 gfc_error_now ("Syntax error in anonymous structure declaration"
6046 /* Skip the bad variable_decl and line up for the start of the
6048 gfc_error_recovery ();
6053 gfc_error ("Syntax error in data declaration at %C");
6058 gfc_free_data_all (gfc_current_ns
);
6061 if (saved_kind_expr
)
6062 gfc_free_expr (saved_kind_expr
);
6063 if (type_param_spec_list
)
6064 gfc_free_actual_arglist (type_param_spec_list
);
6065 if (decl_type_param_list
)
6066 gfc_free_actual_arglist (decl_type_param_list
);
6067 saved_kind_expr
= NULL
;
6068 gfc_free_array_spec (current_as
);
6074 /* Match a prefix associated with a function or subroutine
6075 declaration. If the typespec pointer is nonnull, then a typespec
6076 can be matched. Note that if nothing matches, MATCH_YES is
6077 returned (the null string was matched). */
6080 gfc_match_prefix (gfc_typespec
*ts
)
6086 gfc_clear_attr (¤t_attr
);
6088 seen_impure
= false;
6090 gcc_assert (!gfc_matching_prefix
);
6091 gfc_matching_prefix
= true;
6095 found_prefix
= false;
6097 /* MODULE is a prefix like PURE, ELEMENTAL, etc., having a
6098 corresponding attribute seems natural and distinguishes these
6099 procedures from procedure types of PROC_MODULE, which these are
6101 if (gfc_match ("module% ") == MATCH_YES
)
6103 if (!gfc_notify_std (GFC_STD_F2008
, "MODULE prefix at %C"))
6106 current_attr
.module_procedure
= 1;
6107 found_prefix
= true;
6110 if (!seen_type
&& ts
!= NULL
6111 && gfc_match_decl_type_spec (ts
, 0) == MATCH_YES
6112 && gfc_match_space () == MATCH_YES
)
6116 found_prefix
= true;
6119 if (gfc_match ("elemental% ") == MATCH_YES
)
6121 if (!gfc_add_elemental (¤t_attr
, NULL
))
6124 found_prefix
= true;
6127 if (gfc_match ("pure% ") == MATCH_YES
)
6129 if (!gfc_add_pure (¤t_attr
, NULL
))
6132 found_prefix
= true;
6135 if (gfc_match ("recursive% ") == MATCH_YES
)
6137 if (!gfc_add_recursive (¤t_attr
, NULL
))
6140 found_prefix
= true;
6143 /* IMPURE is a somewhat special case, as it needs not set an actual
6144 attribute but rather only prevents ELEMENTAL routines from being
6145 automatically PURE. */
6146 if (gfc_match ("impure% ") == MATCH_YES
)
6148 if (!gfc_notify_std (GFC_STD_F2008
, "IMPURE procedure at %C"))
6152 found_prefix
= true;
6155 while (found_prefix
);
6157 /* IMPURE and PURE must not both appear, of course. */
6158 if (seen_impure
&& current_attr
.pure
)
6160 gfc_error ("PURE and IMPURE must not appear both at %C");
6164 /* If IMPURE it not seen but the procedure is ELEMENTAL, mark it as PURE. */
6165 if (!seen_impure
&& current_attr
.elemental
&& !current_attr
.pure
)
6167 if (!gfc_add_pure (¤t_attr
, NULL
))
6171 /* At this point, the next item is not a prefix. */
6172 gcc_assert (gfc_matching_prefix
);
6174 gfc_matching_prefix
= false;
6178 gcc_assert (gfc_matching_prefix
);
6179 gfc_matching_prefix
= false;
6184 /* Copy attributes matched by gfc_match_prefix() to attributes on a symbol. */
6187 copy_prefix (symbol_attribute
*dest
, locus
*where
)
6189 if (dest
->module_procedure
)
6191 if (current_attr
.elemental
)
6192 dest
->elemental
= 1;
6194 if (current_attr
.pure
)
6197 if (current_attr
.recursive
)
6198 dest
->recursive
= 1;
6200 /* Module procedures are unusual in that the 'dest' is copied from
6201 the interface declaration. However, this is an oportunity to
6202 check that the submodule declaration is compliant with the
6204 if (dest
->elemental
&& !current_attr
.elemental
)
6206 gfc_error ("ELEMENTAL prefix in MODULE PROCEDURE interface is "
6207 "missing at %L", where
);
6211 if (dest
->pure
&& !current_attr
.pure
)
6213 gfc_error ("PURE prefix in MODULE PROCEDURE interface is "
6214 "missing at %L", where
);
6218 if (dest
->recursive
&& !current_attr
.recursive
)
6220 gfc_error ("RECURSIVE prefix in MODULE PROCEDURE interface is "
6221 "missing at %L", where
);
6228 if (current_attr
.elemental
&& !gfc_add_elemental (dest
, where
))
6231 if (current_attr
.pure
&& !gfc_add_pure (dest
, where
))
6234 if (current_attr
.recursive
&& !gfc_add_recursive (dest
, where
))
6241 /* Match a formal argument list or, if typeparam is true, a
6242 type_param_name_list. */
6245 gfc_match_formal_arglist (gfc_symbol
*progname
, int st_flag
,
6246 int null_flag
, bool typeparam
)
6248 gfc_formal_arglist
*head
, *tail
, *p
, *q
;
6249 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
6252 gfc_formal_arglist
*formal
= NULL
;
6256 /* Keep the interface formal argument list and null it so that the
6257 matching for the new declaration can be done. The numbers and
6258 names of the arguments are checked here. The interface formal
6259 arguments are retained in formal_arglist and the characteristics
6260 are compared in resolve.c(resolve_fl_procedure). See the remark
6261 in get_proc_name about the eventual need to copy the formal_arglist
6262 and populate the formal namespace of the interface symbol. */
6263 if (progname
->attr
.module_procedure
6264 && progname
->attr
.host_assoc
)
6266 formal
= progname
->formal
;
6267 progname
->formal
= NULL
;
6270 if (gfc_match_char ('(') != MATCH_YES
)
6277 if (gfc_match_char (')') == MATCH_YES
)
6282 if (gfc_match_char ('*') == MATCH_YES
)
6285 if (!typeparam
&& !gfc_notify_std (GFC_STD_F95_OBS
,
6286 "Alternate-return argument at %C"))
6292 gfc_error_now ("A parameter name is required at %C");
6296 m
= gfc_match_name (name
);
6300 gfc_error_now ("A parameter name is required at %C");
6304 if (!typeparam
&& gfc_get_symbol (name
, NULL
, &sym
))
6307 && gfc_get_symbol (name
, progname
->f2k_derived
, &sym
))
6311 p
= gfc_get_formal_arglist ();
6323 /* We don't add the VARIABLE flavor because the name could be a
6324 dummy procedure. We don't apply these attributes to formal
6325 arguments of statement functions. */
6326 if (sym
!= NULL
&& !st_flag
6327 && (!gfc_add_dummy(&sym
->attr
, sym
->name
, NULL
)
6328 || !gfc_missing_attr (&sym
->attr
, NULL
)))
6334 /* The name of a program unit can be in a different namespace,
6335 so check for it explicitly. After the statement is accepted,
6336 the name is checked for especially in gfc_get_symbol(). */
6337 if (gfc_new_block
!= NULL
&& sym
!= NULL
&& !typeparam
6338 && strcmp (sym
->name
, gfc_new_block
->name
) == 0)
6340 gfc_error ("Name %qs at %C is the name of the procedure",
6346 if (gfc_match_char (')') == MATCH_YES
)
6349 m
= gfc_match_char (',');
6353 gfc_error_now ("Expected parameter list in type declaration "
6356 gfc_error ("Unexpected junk in formal argument list at %C");
6362 /* Check for duplicate symbols in the formal argument list. */
6365 for (p
= head
; p
->next
; p
= p
->next
)
6370 for (q
= p
->next
; q
; q
= q
->next
)
6371 if (p
->sym
== q
->sym
)
6374 gfc_error_now ("Duplicate name %qs in parameter "
6375 "list at %C", p
->sym
->name
);
6377 gfc_error ("Duplicate symbol %qs in formal argument "
6378 "list at %C", p
->sym
->name
);
6386 if (!gfc_add_explicit_interface (progname
, IFSRC_DECL
, head
, NULL
))
6392 /* gfc_error_now used in following and return with MATCH_YES because
6393 doing otherwise results in a cascade of extraneous errors and in
6394 some cases an ICE in symbol.c(gfc_release_symbol). */
6395 if (progname
->attr
.module_procedure
&& progname
->attr
.host_assoc
)
6397 bool arg_count_mismatch
= false;
6399 if (!formal
&& head
)
6400 arg_count_mismatch
= true;
6402 /* Abbreviated module procedure declaration is not meant to have any
6403 formal arguments! */
6404 if (!progname
->abr_modproc_decl
&& formal
&& !head
)
6405 arg_count_mismatch
= true;
6407 for (p
= formal
, q
= head
; p
&& q
; p
= p
->next
, q
= q
->next
)
6409 if ((p
->next
!= NULL
&& q
->next
== NULL
)
6410 || (p
->next
== NULL
&& q
->next
!= NULL
))
6411 arg_count_mismatch
= true;
6412 else if ((p
->sym
== NULL
&& q
->sym
== NULL
)
6413 || strcmp (p
->sym
->name
, q
->sym
->name
) == 0)
6416 gfc_error_now ("Mismatch in MODULE PROCEDURE formal "
6417 "argument names (%s/%s) at %C",
6418 p
->sym
->name
, q
->sym
->name
);
6421 if (arg_count_mismatch
)
6422 gfc_error_now ("Mismatch in number of MODULE PROCEDURE "
6423 "formal arguments at %C");
6429 gfc_free_formal_arglist (head
);
6434 /* Match a RESULT specification following a function declaration or
6435 ENTRY statement. Also matches the end-of-statement. */
6438 match_result (gfc_symbol
*function
, gfc_symbol
**result
)
6440 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
6444 if (gfc_match (" result (") != MATCH_YES
)
6447 m
= gfc_match_name (name
);
6451 /* Get the right paren, and that's it because there could be the
6452 bind(c) attribute after the result clause. */
6453 if (gfc_match_char (')') != MATCH_YES
)
6455 /* TODO: should report the missing right paren here. */
6459 if (strcmp (function
->name
, name
) == 0)
6461 gfc_error ("RESULT variable at %C must be different than function name");
6465 if (gfc_get_symbol (name
, NULL
, &r
))
6468 if (!gfc_add_result (&r
->attr
, r
->name
, NULL
))
6477 /* Match a function suffix, which could be a combination of a result
6478 clause and BIND(C), either one, or neither. The draft does not
6479 require them to come in a specific order. */
6482 gfc_match_suffix (gfc_symbol
*sym
, gfc_symbol
**result
)
6484 match is_bind_c
; /* Found bind(c). */
6485 match is_result
; /* Found result clause. */
6486 match found_match
; /* Status of whether we've found a good match. */
6487 char peek_char
; /* Character we're going to peek at. */
6488 bool allow_binding_name
;
6490 /* Initialize to having found nothing. */
6491 found_match
= MATCH_NO
;
6492 is_bind_c
= MATCH_NO
;
6493 is_result
= MATCH_NO
;
6495 /* Get the next char to narrow between result and bind(c). */
6496 gfc_gobble_whitespace ();
6497 peek_char
= gfc_peek_ascii_char ();
6499 /* C binding names are not allowed for internal procedures. */
6500 if (gfc_current_state () == COMP_CONTAINS
6501 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6502 allow_binding_name
= false;
6504 allow_binding_name
= true;
6509 /* Look for result clause. */
6510 is_result
= match_result (sym
, result
);
6511 if (is_result
== MATCH_YES
)
6513 /* Now see if there is a bind(c) after it. */
6514 is_bind_c
= gfc_match_bind_c (sym
, allow_binding_name
);
6515 /* We've found the result clause and possibly bind(c). */
6516 found_match
= MATCH_YES
;
6519 /* This should only be MATCH_ERROR. */
6520 found_match
= is_result
;
6523 /* Look for bind(c) first. */
6524 is_bind_c
= gfc_match_bind_c (sym
, allow_binding_name
);
6525 if (is_bind_c
== MATCH_YES
)
6527 /* Now see if a result clause followed it. */
6528 is_result
= match_result (sym
, result
);
6529 found_match
= MATCH_YES
;
6533 /* Should only be a MATCH_ERROR if we get here after seeing 'b'. */
6534 found_match
= MATCH_ERROR
;
6538 gfc_error ("Unexpected junk after function declaration at %C");
6539 found_match
= MATCH_ERROR
;
6543 if (is_bind_c
== MATCH_YES
)
6545 /* Fortran 2008 draft allows BIND(C) for internal procedures. */
6546 if (gfc_current_state () == COMP_CONTAINS
6547 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
6548 && !gfc_notify_std (GFC_STD_F2008
, "BIND(C) attribute "
6549 "at %L may not be specified for an internal "
6550 "procedure", &gfc_current_locus
))
6553 if (!gfc_add_is_bind_c (&(sym
->attr
), sym
->name
, &gfc_current_locus
, 1))
6561 /* Procedure pointer return value without RESULT statement:
6562 Add "hidden" result variable named "ppr@". */
6565 add_hidden_procptr_result (gfc_symbol
*sym
)
6569 if (gfc_notification_std (GFC_STD_F2003
) == ERROR
)
6572 /* First usage case: PROCEDURE and EXTERNAL statements. */
6573 case1
= gfc_current_state () == COMP_FUNCTION
&& gfc_current_block ()
6574 && strcmp (gfc_current_block ()->name
, sym
->name
) == 0
6575 && sym
->attr
.external
;
6576 /* Second usage case: INTERFACE statements. */
6577 case2
= gfc_current_state () == COMP_INTERFACE
&& gfc_state_stack
->previous
6578 && gfc_state_stack
->previous
->state
== COMP_FUNCTION
6579 && strcmp (gfc_state_stack
->previous
->sym
->name
, sym
->name
) == 0;
6585 gfc_get_sym_tree ("ppr@", gfc_current_ns
, &stree
, false);
6589 gfc_get_sym_tree ("ppr@", gfc_current_ns
->parent
, &stree
, false);
6590 st2
= gfc_new_symtree (&gfc_current_ns
->sym_root
, "ppr@");
6591 st2
->n
.sym
= stree
->n
.sym
;
6592 stree
->n
.sym
->refs
++;
6594 sym
->result
= stree
->n
.sym
;
6596 sym
->result
->attr
.proc_pointer
= sym
->attr
.proc_pointer
;
6597 sym
->result
->attr
.pointer
= sym
->attr
.pointer
;
6598 sym
->result
->attr
.external
= sym
->attr
.external
;
6599 sym
->result
->attr
.referenced
= sym
->attr
.referenced
;
6600 sym
->result
->ts
= sym
->ts
;
6601 sym
->attr
.proc_pointer
= 0;
6602 sym
->attr
.pointer
= 0;
6603 sym
->attr
.external
= 0;
6604 if (sym
->result
->attr
.external
&& sym
->result
->attr
.pointer
)
6606 sym
->result
->attr
.pointer
= 0;
6607 sym
->result
->attr
.proc_pointer
= 1;
6610 return gfc_add_result (&sym
->result
->attr
, sym
->result
->name
, NULL
);
6612 /* POINTER after PROCEDURE/EXTERNAL/INTERFACE statement. */
6613 else if (sym
->attr
.function
&& !sym
->attr
.external
&& sym
->attr
.pointer
6614 && sym
->result
&& sym
->result
!= sym
&& sym
->result
->attr
.external
6615 && sym
== gfc_current_ns
->proc_name
6616 && sym
== sym
->result
->ns
->proc_name
6617 && strcmp ("ppr@", sym
->result
->name
) == 0)
6619 sym
->result
->attr
.proc_pointer
= 1;
6620 sym
->attr
.pointer
= 0;
6628 /* Match the interface for a PROCEDURE declaration,
6629 including brackets (R1212). */
6632 match_procedure_interface (gfc_symbol
**proc_if
)
6636 locus old_loc
, entry_loc
;
6637 gfc_namespace
*old_ns
= gfc_current_ns
;
6638 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
6640 old_loc
= entry_loc
= gfc_current_locus
;
6641 gfc_clear_ts (¤t_ts
);
6643 if (gfc_match (" (") != MATCH_YES
)
6645 gfc_current_locus
= entry_loc
;
6649 /* Get the type spec. for the procedure interface. */
6650 old_loc
= gfc_current_locus
;
6651 m
= gfc_match_decl_type_spec (¤t_ts
, 0);
6652 gfc_gobble_whitespace ();
6653 if (m
== MATCH_YES
|| (m
== MATCH_NO
&& gfc_peek_ascii_char () == ')'))
6656 if (m
== MATCH_ERROR
)
6659 /* Procedure interface is itself a procedure. */
6660 gfc_current_locus
= old_loc
;
6661 m
= gfc_match_name (name
);
6663 /* First look to see if it is already accessible in the current
6664 namespace because it is use associated or contained. */
6666 if (gfc_find_sym_tree (name
, NULL
, 0, &st
))
6669 /* If it is still not found, then try the parent namespace, if it
6670 exists and create the symbol there if it is still not found. */
6671 if (gfc_current_ns
->parent
)
6672 gfc_current_ns
= gfc_current_ns
->parent
;
6673 if (st
== NULL
&& gfc_get_ha_sym_tree (name
, &st
))
6676 gfc_current_ns
= old_ns
;
6677 *proc_if
= st
->n
.sym
;
6682 /* Resolve interface if possible. That way, attr.procedure is only set
6683 if it is declared by a later procedure-declaration-stmt, which is
6684 invalid per F08:C1216 (cf. resolve_procedure_interface). */
6685 while ((*proc_if
)->ts
.interface
6686 && *proc_if
!= (*proc_if
)->ts
.interface
)
6687 *proc_if
= (*proc_if
)->ts
.interface
;
6689 if ((*proc_if
)->attr
.flavor
== FL_UNKNOWN
6690 && (*proc_if
)->ts
.type
== BT_UNKNOWN
6691 && !gfc_add_flavor (&(*proc_if
)->attr
, FL_PROCEDURE
,
6692 (*proc_if
)->name
, NULL
))
6697 if (gfc_match (" )") != MATCH_YES
)
6699 gfc_current_locus
= entry_loc
;
6707 /* Match a PROCEDURE declaration (R1211). */
6710 match_procedure_decl (void)
6713 gfc_symbol
*sym
, *proc_if
= NULL
;
6715 gfc_expr
*initializer
= NULL
;
6717 /* Parse interface (with brackets). */
6718 m
= match_procedure_interface (&proc_if
);
6722 /* Parse attributes (with colons). */
6723 m
= match_attr_spec();
6724 if (m
== MATCH_ERROR
)
6727 if (proc_if
&& proc_if
->attr
.is_bind_c
&& !current_attr
.is_bind_c
)
6729 current_attr
.is_bind_c
= 1;
6730 has_name_equals
= 0;
6731 curr_binding_label
= NULL
;
6734 /* Get procedure symbols. */
6737 m
= gfc_match_symbol (&sym
, 0);
6740 else if (m
== MATCH_ERROR
)
6743 /* Add current_attr to the symbol attributes. */
6744 if (!gfc_copy_attr (&sym
->attr
, ¤t_attr
, NULL
))
6747 if (sym
->attr
.is_bind_c
)
6749 /* Check for C1218. */
6750 if (!proc_if
|| !proc_if
->attr
.is_bind_c
)
6752 gfc_error ("BIND(C) attribute at %C requires "
6753 "an interface with BIND(C)");
6756 /* Check for C1217. */
6757 if (has_name_equals
&& sym
->attr
.pointer
)
6759 gfc_error ("BIND(C) procedure with NAME may not have "
6760 "POINTER attribute at %C");
6763 if (has_name_equals
&& sym
->attr
.dummy
)
6765 gfc_error ("Dummy procedure at %C may not have "
6766 "BIND(C) attribute with NAME");
6769 /* Set binding label for BIND(C). */
6770 if (!set_binding_label (&sym
->binding_label
, sym
->name
, num
))
6774 if (!gfc_add_external (&sym
->attr
, NULL
))
6777 if (add_hidden_procptr_result (sym
))
6780 if (!gfc_add_proc (&sym
->attr
, sym
->name
, NULL
))
6783 /* Set interface. */
6784 if (proc_if
!= NULL
)
6786 if (sym
->ts
.type
!= BT_UNKNOWN
)
6788 gfc_error ("Procedure %qs at %L already has basic type of %s",
6789 sym
->name
, &gfc_current_locus
,
6790 gfc_basic_typename (sym
->ts
.type
));
6793 sym
->ts
.interface
= proc_if
;
6794 sym
->attr
.untyped
= 1;
6795 sym
->attr
.if_source
= IFSRC_IFBODY
;
6797 else if (current_ts
.type
!= BT_UNKNOWN
)
6799 if (!gfc_add_type (sym
, ¤t_ts
, &gfc_current_locus
))
6801 sym
->ts
.interface
= gfc_new_symbol ("", gfc_current_ns
);
6802 sym
->ts
.interface
->ts
= current_ts
;
6803 sym
->ts
.interface
->attr
.flavor
= FL_PROCEDURE
;
6804 sym
->ts
.interface
->attr
.function
= 1;
6805 sym
->attr
.function
= 1;
6806 sym
->attr
.if_source
= IFSRC_UNKNOWN
;
6809 if (gfc_match (" =>") == MATCH_YES
)
6811 if (!current_attr
.pointer
)
6813 gfc_error ("Initialization at %C isn't for a pointer variable");
6818 m
= match_pointer_init (&initializer
, 1);
6822 if (!add_init_expr_to_sym (sym
->name
, &initializer
, &gfc_current_locus
))
6827 if (gfc_match_eos () == MATCH_YES
)
6829 if (gfc_match_char (',') != MATCH_YES
)
6834 gfc_error ("Syntax error in PROCEDURE statement at %C");
6838 /* Free stuff up and return. */
6839 gfc_free_expr (initializer
);
6845 match_binding_attributes (gfc_typebound_proc
* ba
, bool generic
, bool ppc
);
6848 /* Match a procedure pointer component declaration (R445). */
6851 match_ppc_decl (void)
6854 gfc_symbol
*proc_if
= NULL
;
6858 gfc_expr
*initializer
= NULL
;
6859 gfc_typebound_proc
* tb
;
6860 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
6862 /* Parse interface (with brackets). */
6863 m
= match_procedure_interface (&proc_if
);
6867 /* Parse attributes. */
6868 tb
= XCNEW (gfc_typebound_proc
);
6869 tb
->where
= gfc_current_locus
;
6870 m
= match_binding_attributes (tb
, false, true);
6871 if (m
== MATCH_ERROR
)
6874 gfc_clear_attr (¤t_attr
);
6875 current_attr
.procedure
= 1;
6876 current_attr
.proc_pointer
= 1;
6877 current_attr
.access
= tb
->access
;
6878 current_attr
.flavor
= FL_PROCEDURE
;
6880 /* Match the colons (required). */
6881 if (gfc_match (" ::") != MATCH_YES
)
6883 gfc_error ("Expected %<::%> after binding-attributes at %C");
6887 /* Check for C450. */
6888 if (!tb
->nopass
&& proc_if
== NULL
)
6890 gfc_error("NOPASS or explicit interface required at %C");
6894 if (!gfc_notify_std (GFC_STD_F2003
, "Procedure pointer component at %C"))
6897 /* Match PPC names. */
6901 m
= gfc_match_name (name
);
6904 else if (m
== MATCH_ERROR
)
6907 if (!gfc_add_component (gfc_current_block(), name
, &c
))
6910 /* Add current_attr to the symbol attributes. */
6911 if (!gfc_copy_attr (&c
->attr
, ¤t_attr
, NULL
))
6914 if (!gfc_add_external (&c
->attr
, NULL
))
6917 if (!gfc_add_proc (&c
->attr
, name
, NULL
))
6924 c
->tb
= XCNEW (gfc_typebound_proc
);
6925 c
->tb
->where
= gfc_current_locus
;
6929 /* Set interface. */
6930 if (proc_if
!= NULL
)
6932 c
->ts
.interface
= proc_if
;
6933 c
->attr
.untyped
= 1;
6934 c
->attr
.if_source
= IFSRC_IFBODY
;
6936 else if (ts
.type
!= BT_UNKNOWN
)
6939 c
->ts
.interface
= gfc_new_symbol ("", gfc_current_ns
);
6940 c
->ts
.interface
->result
= c
->ts
.interface
;
6941 c
->ts
.interface
->ts
= ts
;
6942 c
->ts
.interface
->attr
.flavor
= FL_PROCEDURE
;
6943 c
->ts
.interface
->attr
.function
= 1;
6944 c
->attr
.function
= 1;
6945 c
->attr
.if_source
= IFSRC_UNKNOWN
;
6948 if (gfc_match (" =>") == MATCH_YES
)
6950 m
= match_pointer_init (&initializer
, 1);
6953 gfc_free_expr (initializer
);
6956 c
->initializer
= initializer
;
6959 if (gfc_match_eos () == MATCH_YES
)
6961 if (gfc_match_char (',') != MATCH_YES
)
6966 gfc_error ("Syntax error in procedure pointer component at %C");
6971 /* Match a PROCEDURE declaration inside an interface (R1206). */
6974 match_procedure_in_interface (void)
6978 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
6981 if (current_interface
.type
== INTERFACE_NAMELESS
6982 || current_interface
.type
== INTERFACE_ABSTRACT
)
6984 gfc_error ("PROCEDURE at %C must be in a generic interface");
6988 /* Check if the F2008 optional double colon appears. */
6989 gfc_gobble_whitespace ();
6990 old_locus
= gfc_current_locus
;
6991 if (gfc_match ("::") == MATCH_YES
)
6993 if (!gfc_notify_std (GFC_STD_F2008
, "double colon in "
6994 "MODULE PROCEDURE statement at %L", &old_locus
))
6998 gfc_current_locus
= old_locus
;
7002 m
= gfc_match_name (name
);
7005 else if (m
== MATCH_ERROR
)
7007 if (gfc_get_symbol (name
, gfc_current_ns
->parent
, &sym
))
7010 if (!gfc_add_interface (sym
))
7013 if (gfc_match_eos () == MATCH_YES
)
7015 if (gfc_match_char (',') != MATCH_YES
)
7022 gfc_error ("Syntax error in PROCEDURE statement at %C");
7027 /* General matcher for PROCEDURE declarations. */
7029 static match
match_procedure_in_type (void);
7032 gfc_match_procedure (void)
7036 switch (gfc_current_state ())
7041 case COMP_SUBMODULE
:
7042 case COMP_SUBROUTINE
:
7045 m
= match_procedure_decl ();
7047 case COMP_INTERFACE
:
7048 m
= match_procedure_in_interface ();
7051 m
= match_ppc_decl ();
7053 case COMP_DERIVED_CONTAINS
:
7054 m
= match_procedure_in_type ();
7063 if (!gfc_notify_std (GFC_STD_F2003
, "PROCEDURE statement at %C"))
7070 /* Warn if a matched procedure has the same name as an intrinsic; this is
7071 simply a wrapper around gfc_warn_intrinsic_shadow that interprets the current
7072 parser-state-stack to find out whether we're in a module. */
7075 do_warn_intrinsic_shadow (const gfc_symbol
* sym
, bool func
)
7079 in_module
= (gfc_state_stack
->previous
7080 && (gfc_state_stack
->previous
->state
== COMP_MODULE
7081 || gfc_state_stack
->previous
->state
== COMP_SUBMODULE
));
7083 gfc_warn_intrinsic_shadow (sym
, in_module
, func
);
7087 /* Match a function declaration. */
7090 gfc_match_function_decl (void)
7092 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
7093 gfc_symbol
*sym
, *result
;
7097 match found_match
; /* Status returned by match func. */
7099 if (gfc_current_state () != COMP_NONE
7100 && gfc_current_state () != COMP_INTERFACE
7101 && gfc_current_state () != COMP_CONTAINS
)
7104 gfc_clear_ts (¤t_ts
);
7106 old_loc
= gfc_current_locus
;
7108 m
= gfc_match_prefix (¤t_ts
);
7111 gfc_current_locus
= old_loc
;
7115 if (gfc_match ("function% %n", name
) != MATCH_YES
)
7117 gfc_current_locus
= old_loc
;
7121 if (get_proc_name (name
, &sym
, false))
7124 if (add_hidden_procptr_result (sym
))
7127 if (current_attr
.module_procedure
)
7128 sym
->attr
.module_procedure
= 1;
7130 gfc_new_block
= sym
;
7132 m
= gfc_match_formal_arglist (sym
, 0, 0);
7135 gfc_error ("Expected formal argument list in function "
7136 "definition at %C");
7140 else if (m
== MATCH_ERROR
)
7145 /* According to the draft, the bind(c) and result clause can
7146 come in either order after the formal_arg_list (i.e., either
7147 can be first, both can exist together or by themselves or neither
7148 one). Therefore, the match_result can't match the end of the
7149 string, and check for the bind(c) or result clause in either order. */
7150 found_match
= gfc_match_eos ();
7152 /* Make sure that it isn't already declared as BIND(C). If it is, it
7153 must have been marked BIND(C) with a BIND(C) attribute and that is
7154 not allowed for procedures. */
7155 if (sym
->attr
.is_bind_c
== 1)
7157 sym
->attr
.is_bind_c
= 0;
7158 if (sym
->old_symbol
!= NULL
)
7159 gfc_error_now ("BIND(C) attribute at %L can only be used for "
7160 "variables or common blocks",
7161 &(sym
->old_symbol
->declared_at
));
7163 gfc_error_now ("BIND(C) attribute at %L can only be used for "
7164 "variables or common blocks", &gfc_current_locus
);
7167 if (found_match
!= MATCH_YES
)
7169 /* If we haven't found the end-of-statement, look for a suffix. */
7170 suffix_match
= gfc_match_suffix (sym
, &result
);
7171 if (suffix_match
== MATCH_YES
)
7172 /* Need to get the eos now. */
7173 found_match
= gfc_match_eos ();
7175 found_match
= suffix_match
;
7178 if(found_match
!= MATCH_YES
)
7182 /* Make changes to the symbol. */
7185 if (!gfc_add_function (&sym
->attr
, sym
->name
, NULL
))
7188 if (!gfc_missing_attr (&sym
->attr
, NULL
))
7191 if (!copy_prefix (&sym
->attr
, &sym
->declared_at
))
7193 if(!sym
->attr
.module_procedure
)
7199 /* Delay matching the function characteristics until after the
7200 specification block by signalling kind=-1. */
7201 sym
->declared_at
= old_loc
;
7202 if (current_ts
.type
!= BT_UNKNOWN
)
7203 current_ts
.kind
= -1;
7205 current_ts
.kind
= 0;
7209 if (current_ts
.type
!= BT_UNKNOWN
7210 && !gfc_add_type (sym
, ¤t_ts
, &gfc_current_locus
))
7216 if (current_ts
.type
!= BT_UNKNOWN
7217 && !gfc_add_type (result
, ¤t_ts
, &gfc_current_locus
))
7219 sym
->result
= result
;
7222 /* Warn if this procedure has the same name as an intrinsic. */
7223 do_warn_intrinsic_shadow (sym
, true);
7229 gfc_current_locus
= old_loc
;
7234 /* This is mostly a copy of parse.c(add_global_procedure) but modified to
7235 pass the name of the entry, rather than the gfc_current_block name, and
7236 to return false upon finding an existing global entry. */
7239 add_global_entry (const char *name
, const char *binding_label
, bool sub
,
7243 enum gfc_symbol_type type
;
7245 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
7247 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
7248 name is a global identifier. */
7249 if (!binding_label
|| gfc_notification_std (GFC_STD_F2008
))
7251 s
= gfc_get_gsymbol (name
);
7253 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= type
))
7255 gfc_global_used (s
, where
);
7264 s
->ns
= gfc_current_ns
;
7268 /* Don't add the symbol multiple times. */
7270 && (!gfc_notification_std (GFC_STD_F2008
)
7271 || strcmp (name
, binding_label
) != 0))
7273 s
= gfc_get_gsymbol (binding_label
);
7275 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= type
))
7277 gfc_global_used (s
, where
);
7284 s
->binding_label
= binding_label
;
7287 s
->ns
= gfc_current_ns
;
7295 /* Match an ENTRY statement. */
7298 gfc_match_entry (void)
7303 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
7304 gfc_compile_state state
;
7308 bool module_procedure
;
7312 m
= gfc_match_name (name
);
7316 if (!gfc_notify_std (GFC_STD_F2008_OBS
, "ENTRY statement at %C"))
7319 state
= gfc_current_state ();
7320 if (state
!= COMP_SUBROUTINE
&& state
!= COMP_FUNCTION
)
7325 gfc_error ("ENTRY statement at %C cannot appear within a PROGRAM");
7328 gfc_error ("ENTRY statement at %C cannot appear within a MODULE");
7330 case COMP_SUBMODULE
:
7331 gfc_error ("ENTRY statement at %C cannot appear within a SUBMODULE");
7333 case COMP_BLOCK_DATA
:
7334 gfc_error ("ENTRY statement at %C cannot appear within "
7337 case COMP_INTERFACE
:
7338 gfc_error ("ENTRY statement at %C cannot appear within "
7341 case COMP_STRUCTURE
:
7342 gfc_error ("ENTRY statement at %C cannot appear within "
7343 "a STRUCTURE block");
7346 gfc_error ("ENTRY statement at %C cannot appear within "
7347 "a DERIVED TYPE block");
7350 gfc_error ("ENTRY statement at %C cannot appear within "
7351 "an IF-THEN block");
7354 case COMP_DO_CONCURRENT
:
7355 gfc_error ("ENTRY statement at %C cannot appear within "
7359 gfc_error ("ENTRY statement at %C cannot appear within "
7363 gfc_error ("ENTRY statement at %C cannot appear within "
7367 gfc_error ("ENTRY statement at %C cannot appear within "
7371 gfc_error ("ENTRY statement at %C cannot appear within "
7372 "a contained subprogram");
7375 gfc_error ("Unexpected ENTRY statement at %C");
7380 if ((state
== COMP_SUBROUTINE
|| state
== COMP_FUNCTION
)
7381 && gfc_state_stack
->previous
->state
== COMP_INTERFACE
)
7383 gfc_error ("ENTRY statement at %C cannot appear within an INTERFACE");
7387 module_procedure
= gfc_current_ns
->parent
!= NULL
7388 && gfc_current_ns
->parent
->proc_name
7389 && gfc_current_ns
->parent
->proc_name
->attr
.flavor
7392 if (gfc_current_ns
->parent
!= NULL
7393 && gfc_current_ns
->parent
->proc_name
7394 && !module_procedure
)
7396 gfc_error("ENTRY statement at %C cannot appear in a "
7397 "contained procedure");
7401 /* Module function entries need special care in get_proc_name
7402 because previous references within the function will have
7403 created symbols attached to the current namespace. */
7404 if (get_proc_name (name
, &entry
,
7405 gfc_current_ns
->parent
!= NULL
7406 && module_procedure
))
7409 proc
= gfc_current_block ();
7411 /* Make sure that it isn't already declared as BIND(C). If it is, it
7412 must have been marked BIND(C) with a BIND(C) attribute and that is
7413 not allowed for procedures. */
7414 if (entry
->attr
.is_bind_c
== 1)
7416 entry
->attr
.is_bind_c
= 0;
7417 if (entry
->old_symbol
!= NULL
)
7418 gfc_error_now ("BIND(C) attribute at %L can only be used for "
7419 "variables or common blocks",
7420 &(entry
->old_symbol
->declared_at
));
7422 gfc_error_now ("BIND(C) attribute at %L can only be used for "
7423 "variables or common blocks", &gfc_current_locus
);
7426 /* Check what next non-whitespace character is so we can tell if there
7427 is the required parens if we have a BIND(C). */
7428 old_loc
= gfc_current_locus
;
7429 gfc_gobble_whitespace ();
7430 peek_char
= gfc_peek_ascii_char ();
7432 if (state
== COMP_SUBROUTINE
)
7434 m
= gfc_match_formal_arglist (entry
, 0, 1);
7438 /* Call gfc_match_bind_c with allow_binding_name = true as ENTRY can
7439 never be an internal procedure. */
7440 is_bind_c
= gfc_match_bind_c (entry
, true);
7441 if (is_bind_c
== MATCH_ERROR
)
7443 if (is_bind_c
== MATCH_YES
)
7445 if (peek_char
!= '(')
7447 gfc_error ("Missing required parentheses before BIND(C) at %C");
7451 if (!gfc_add_is_bind_c (&(entry
->attr
), entry
->name
,
7452 &(entry
->declared_at
), 1))
7457 if (!gfc_current_ns
->parent
7458 && !add_global_entry (name
, entry
->binding_label
, true,
7462 /* An entry in a subroutine. */
7463 if (!gfc_add_entry (&entry
->attr
, entry
->name
, NULL
)
7464 || !gfc_add_subroutine (&entry
->attr
, entry
->name
, NULL
))
7469 /* An entry in a function.
7470 We need to take special care because writing
7475 ENTRY f() RESULT (r)
7477 ENTRY f RESULT (r). */
7478 if (gfc_match_eos () == MATCH_YES
)
7480 gfc_current_locus
= old_loc
;
7481 /* Match the empty argument list, and add the interface to
7483 m
= gfc_match_formal_arglist (entry
, 0, 1);
7486 m
= gfc_match_formal_arglist (entry
, 0, 0);
7493 if (gfc_match_eos () == MATCH_YES
)
7495 if (!gfc_add_entry (&entry
->attr
, entry
->name
, NULL
)
7496 || !gfc_add_function (&entry
->attr
, entry
->name
, NULL
))
7499 entry
->result
= entry
;
7503 m
= gfc_match_suffix (entry
, &result
);
7505 gfc_syntax_error (ST_ENTRY
);
7511 if (!gfc_add_result (&result
->attr
, result
->name
, NULL
)
7512 || !gfc_add_entry (&entry
->attr
, result
->name
, NULL
)
7513 || !gfc_add_function (&entry
->attr
, result
->name
, NULL
))
7515 entry
->result
= result
;
7519 if (!gfc_add_entry (&entry
->attr
, entry
->name
, NULL
)
7520 || !gfc_add_function (&entry
->attr
, entry
->name
, NULL
))
7522 entry
->result
= entry
;
7526 if (!gfc_current_ns
->parent
7527 && !add_global_entry (name
, entry
->binding_label
, false,
7532 if (gfc_match_eos () != MATCH_YES
)
7534 gfc_syntax_error (ST_ENTRY
);
7538 /* F2018:C1546 An elemental procedure shall not have the BIND attribute. */
7539 if (proc
->attr
.elemental
&& entry
->attr
.is_bind_c
)
7541 gfc_error ("ENTRY statement at %L with BIND(C) prohibited in an "
7542 "elemental procedure", &entry
->declared_at
);
7546 entry
->attr
.recursive
= proc
->attr
.recursive
;
7547 entry
->attr
.elemental
= proc
->attr
.elemental
;
7548 entry
->attr
.pure
= proc
->attr
.pure
;
7550 el
= gfc_get_entry_list ();
7552 el
->next
= gfc_current_ns
->entries
;
7553 gfc_current_ns
->entries
= el
;
7555 el
->id
= el
->next
->id
+ 1;
7559 new_st
.op
= EXEC_ENTRY
;
7560 new_st
.ext
.entry
= el
;
7566 /* Match a subroutine statement, including optional prefixes. */
7569 gfc_match_subroutine (void)
7571 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
7576 bool allow_binding_name
;
7579 if (gfc_current_state () != COMP_NONE
7580 && gfc_current_state () != COMP_INTERFACE
7581 && gfc_current_state () != COMP_CONTAINS
)
7584 m
= gfc_match_prefix (NULL
);
7588 m
= gfc_match ("subroutine% %n", name
);
7592 if (get_proc_name (name
, &sym
, false))
7595 /* Set declared_at as it might point to, e.g., a PUBLIC statement, if
7596 the symbol existed before. */
7597 sym
->declared_at
= gfc_current_locus
;
7599 if (current_attr
.module_procedure
)
7600 sym
->attr
.module_procedure
= 1;
7602 if (add_hidden_procptr_result (sym
))
7605 gfc_new_block
= sym
;
7607 /* Check what next non-whitespace character is so we can tell if there
7608 is the required parens if we have a BIND(C). */
7609 gfc_gobble_whitespace ();
7610 peek_char
= gfc_peek_ascii_char ();
7612 if (!gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
))
7615 if (gfc_match_formal_arglist (sym
, 0, 1) != MATCH_YES
)
7618 /* Make sure that it isn't already declared as BIND(C). If it is, it
7619 must have been marked BIND(C) with a BIND(C) attribute and that is
7620 not allowed for procedures. */
7621 if (sym
->attr
.is_bind_c
== 1)
7623 sym
->attr
.is_bind_c
= 0;
7624 if (sym
->old_symbol
!= NULL
)
7625 gfc_error_now ("BIND(C) attribute at %L can only be used for "
7626 "variables or common blocks",
7627 &(sym
->old_symbol
->declared_at
));
7629 gfc_error_now ("BIND(C) attribute at %L can only be used for "
7630 "variables or common blocks", &gfc_current_locus
);
7633 /* C binding names are not allowed for internal procedures. */
7634 if (gfc_current_state () == COMP_CONTAINS
7635 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
7636 allow_binding_name
= false;
7638 allow_binding_name
= true;
7640 /* Here, we are just checking if it has the bind(c) attribute, and if
7641 so, then we need to make sure it's all correct. If it doesn't,
7642 we still need to continue matching the rest of the subroutine line. */
7643 gfc_gobble_whitespace ();
7644 loc
= gfc_current_locus
;
7645 is_bind_c
= gfc_match_bind_c (sym
, allow_binding_name
);
7646 if (is_bind_c
== MATCH_ERROR
)
7648 /* There was an attempt at the bind(c), but it was wrong. An
7649 error message should have been printed w/in the gfc_match_bind_c
7650 so here we'll just return the MATCH_ERROR. */
7654 if (is_bind_c
== MATCH_YES
)
7656 gfc_formal_arglist
*arg
;
7658 /* The following is allowed in the Fortran 2008 draft. */
7659 if (gfc_current_state () == COMP_CONTAINS
7660 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
7661 && !gfc_notify_std (GFC_STD_F2008
, "BIND(C) attribute "
7662 "at %L may not be specified for an internal "
7663 "procedure", &gfc_current_locus
))
7666 if (peek_char
!= '(')
7668 gfc_error ("Missing required parentheses before BIND(C) at %C");
7672 /* Scan the dummy arguments for an alternate return. */
7673 for (arg
= sym
->formal
; arg
; arg
= arg
->next
)
7676 gfc_error ("Alternate return dummy argument cannot appear in a "
7677 "SUBROUTINE with the BIND(C) attribute at %L", &loc
);
7681 if (!gfc_add_is_bind_c (&(sym
->attr
), sym
->name
, &(sym
->declared_at
), 1))
7685 if (gfc_match_eos () != MATCH_YES
)
7687 gfc_syntax_error (ST_SUBROUTINE
);
7691 if (!copy_prefix (&sym
->attr
, &sym
->declared_at
))
7693 if(!sym
->attr
.module_procedure
)
7699 /* Warn if it has the same name as an intrinsic. */
7700 do_warn_intrinsic_shadow (sym
, false);
7706 /* Check that the NAME identifier in a BIND attribute or statement
7707 is conform to C identifier rules. */
7710 check_bind_name_identifier (char **name
)
7712 char *n
= *name
, *p
;
7714 /* Remove leading spaces. */
7718 /* On an empty string, free memory and set name to NULL. */
7726 /* Remove trailing spaces. */
7727 p
= n
+ strlen(n
) - 1;
7731 /* Insert the identifier into the symbol table. */
7736 /* Now check that identifier is valid under C rules. */
7739 gfc_error ("Invalid C identifier in NAME= specifier at %C");
7744 if (!(ISALNUM (*p
) || *p
== '_' || *p
== '$'))
7746 gfc_error ("Invalid C identifier in NAME= specifier at %C");
7754 /* Match a BIND(C) specifier, with the optional 'name=' specifier if
7755 given, and set the binding label in either the given symbol (if not
7756 NULL), or in the current_ts. The symbol may be NULL because we may
7757 encounter the BIND(C) before the declaration itself. Return
7758 MATCH_NO if what we're looking at isn't a BIND(C) specifier,
7759 MATCH_ERROR if it is a BIND(C) clause but an error was encountered,
7760 or MATCH_YES if the specifier was correct and the binding label and
7761 bind(c) fields were set correctly for the given symbol or the
7762 current_ts. If allow_binding_name is false, no binding name may be
7766 gfc_match_bind_c (gfc_symbol
*sym
, bool allow_binding_name
)
7768 char *binding_label
= NULL
;
7771 /* Initialize the flag that specifies whether we encountered a NAME=
7772 specifier or not. */
7773 has_name_equals
= 0;
7775 /* This much we have to be able to match, in this order, if
7776 there is a bind(c) label. */
7777 if (gfc_match (" bind ( c ") != MATCH_YES
)
7780 /* Now see if there is a binding label, or if we've reached the
7781 end of the bind(c) attribute without one. */
7782 if (gfc_match_char (',') == MATCH_YES
)
7784 if (gfc_match (" name = ") != MATCH_YES
)
7786 gfc_error ("Syntax error in NAME= specifier for binding label "
7788 /* should give an error message here */
7792 has_name_equals
= 1;
7794 if (gfc_match_init_expr (&e
) != MATCH_YES
)
7800 if (!gfc_simplify_expr(e
, 0))
7802 gfc_error ("NAME= specifier at %C should be a constant expression");
7807 if (e
->expr_type
!= EXPR_CONSTANT
|| e
->ts
.type
!= BT_CHARACTER
7808 || e
->ts
.kind
!= gfc_default_character_kind
|| e
->rank
!= 0)
7810 gfc_error ("NAME= specifier at %C should be a scalar of "
7811 "default character kind");
7816 // Get a C string from the Fortran string constant
7817 binding_label
= gfc_widechar_to_char (e
->value
.character
.string
,
7818 e
->value
.character
.length
);
7821 // Check that it is valid (old gfc_match_name_C)
7822 if (check_bind_name_identifier (&binding_label
) != MATCH_YES
)
7826 /* Get the required right paren. */
7827 if (gfc_match_char (')') != MATCH_YES
)
7829 gfc_error ("Missing closing paren for binding label at %C");
7833 if (has_name_equals
&& !allow_binding_name
)
7835 gfc_error ("No binding name is allowed in BIND(C) at %C");
7839 if (has_name_equals
&& sym
!= NULL
&& sym
->attr
.dummy
)
7841 gfc_error ("For dummy procedure %s, no binding name is "
7842 "allowed in BIND(C) at %C", sym
->name
);
7847 /* Save the binding label to the symbol. If sym is null, we're
7848 probably matching the typespec attributes of a declaration and
7849 haven't gotten the name yet, and therefore, no symbol yet. */
7853 sym
->binding_label
= binding_label
;
7855 curr_binding_label
= binding_label
;
7857 else if (allow_binding_name
)
7859 /* No binding label, but if symbol isn't null, we
7860 can set the label for it here.
7861 If name="" or allow_binding_name is false, no C binding name is
7863 if (sym
!= NULL
&& sym
->name
!= NULL
&& has_name_equals
== 0)
7864 sym
->binding_label
= IDENTIFIER_POINTER (get_identifier (sym
->name
));
7867 if (has_name_equals
&& gfc_current_state () == COMP_INTERFACE
7868 && current_interface
.type
== INTERFACE_ABSTRACT
)
7870 gfc_error ("NAME not allowed on BIND(C) for ABSTRACT INTERFACE at %C");
7878 /* Return nonzero if we're currently compiling a contained procedure. */
7881 contained_procedure (void)
7883 gfc_state_data
*s
= gfc_state_stack
;
7885 if ((s
->state
== COMP_SUBROUTINE
|| s
->state
== COMP_FUNCTION
)
7886 && s
->previous
!= NULL
&& s
->previous
->state
== COMP_CONTAINS
)
7892 /* Set the kind of each enumerator. The kind is selected such that it is
7893 interoperable with the corresponding C enumeration type, making
7894 sure that -fshort-enums is honored. */
7899 enumerator_history
*current_history
= NULL
;
7903 if (max_enum
== NULL
|| enum_history
== NULL
)
7906 if (!flag_short_enums
)
7912 kind
= gfc_integer_kinds
[i
++].kind
;
7914 while (kind
< gfc_c_int_kind
7915 && gfc_check_integer_range (max_enum
->initializer
->value
.integer
,
7918 current_history
= enum_history
;
7919 while (current_history
!= NULL
)
7921 current_history
->sym
->ts
.kind
= kind
;
7922 current_history
= current_history
->next
;
7927 /* Match any of the various end-block statements. Returns the type of
7928 END to the caller. The END INTERFACE, END IF, END DO, END SELECT
7929 and END BLOCK statements cannot be replaced by a single END statement. */
7932 gfc_match_end (gfc_statement
*st
)
7934 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
7935 gfc_compile_state state
;
7937 const char *block_name
;
7941 gfc_namespace
*parent_ns
, *ns
, *prev_ns
;
7942 gfc_namespace
**nsp
;
7943 bool abreviated_modproc_decl
= false;
7944 bool got_matching_end
= false;
7946 old_loc
= gfc_current_locus
;
7947 if (gfc_match ("end") != MATCH_YES
)
7950 state
= gfc_current_state ();
7951 block_name
= gfc_current_block () == NULL
7952 ? NULL
: gfc_current_block ()->name
;
7956 case COMP_ASSOCIATE
:
7958 if (gfc_str_startswith (block_name
, "block@"))
7963 case COMP_DERIVED_CONTAINS
:
7964 state
= gfc_state_stack
->previous
->state
;
7965 block_name
= gfc_state_stack
->previous
->sym
== NULL
7966 ? NULL
: gfc_state_stack
->previous
->sym
->name
;
7967 abreviated_modproc_decl
= gfc_state_stack
->previous
->sym
7968 && gfc_state_stack
->previous
->sym
->abr_modproc_decl
;
7975 if (!abreviated_modproc_decl
)
7976 abreviated_modproc_decl
= gfc_current_block ()
7977 && gfc_current_block ()->abr_modproc_decl
;
7983 *st
= ST_END_PROGRAM
;
7984 target
= " program";
7988 case COMP_SUBROUTINE
:
7989 *st
= ST_END_SUBROUTINE
;
7990 if (!abreviated_modproc_decl
)
7991 target
= " subroutine";
7993 target
= " procedure";
7994 eos_ok
= !contained_procedure ();
7998 *st
= ST_END_FUNCTION
;
7999 if (!abreviated_modproc_decl
)
8000 target
= " function";
8002 target
= " procedure";
8003 eos_ok
= !contained_procedure ();
8006 case COMP_BLOCK_DATA
:
8007 *st
= ST_END_BLOCK_DATA
;
8008 target
= " block data";
8013 *st
= ST_END_MODULE
;
8018 case COMP_SUBMODULE
:
8019 *st
= ST_END_SUBMODULE
;
8020 target
= " submodule";
8024 case COMP_INTERFACE
:
8025 *st
= ST_END_INTERFACE
;
8026 target
= " interface";
8042 case COMP_STRUCTURE
:
8043 *st
= ST_END_STRUCTURE
;
8044 target
= " structure";
8049 case COMP_DERIVED_CONTAINS
:
8055 case COMP_ASSOCIATE
:
8056 *st
= ST_END_ASSOCIATE
;
8057 target
= " associate";
8074 case COMP_DO_CONCURRENT
:
8081 *st
= ST_END_CRITICAL
;
8082 target
= " critical";
8087 case COMP_SELECT_TYPE
:
8088 *st
= ST_END_SELECT
;
8094 *st
= ST_END_FORALL
;
8109 last_initializer
= NULL
;
8111 gfc_free_enum_history ();
8115 gfc_error ("Unexpected END statement at %C");
8119 old_loc
= gfc_current_locus
;
8120 if (gfc_match_eos () == MATCH_YES
)
8122 if (!eos_ok
&& (*st
== ST_END_SUBROUTINE
|| *st
== ST_END_FUNCTION
))
8124 if (!gfc_notify_std (GFC_STD_F2008
, "END statement "
8125 "instead of %s statement at %L",
8126 abreviated_modproc_decl
? "END PROCEDURE"
8127 : gfc_ascii_statement(*st
), &old_loc
))
8132 /* We would have required END [something]. */
8133 gfc_error ("%s statement expected at %L",
8134 gfc_ascii_statement (*st
), &old_loc
);
8141 /* Verify that we've got the sort of end-block that we're expecting. */
8142 if (gfc_match (target
) != MATCH_YES
)
8144 gfc_error ("Expecting %s statement at %L", abreviated_modproc_decl
8145 ? "END PROCEDURE" : gfc_ascii_statement(*st
), &old_loc
);
8149 got_matching_end
= true;
8151 old_loc
= gfc_current_locus
;
8152 /* If we're at the end, make sure a block name wasn't required. */
8153 if (gfc_match_eos () == MATCH_YES
)
8156 if (*st
!= ST_ENDDO
&& *st
!= ST_ENDIF
&& *st
!= ST_END_SELECT
8157 && *st
!= ST_END_FORALL
&& *st
!= ST_END_WHERE
&& *st
!= ST_END_BLOCK
8158 && *st
!= ST_END_ASSOCIATE
&& *st
!= ST_END_CRITICAL
)
8164 gfc_error ("Expected block name of %qs in %s statement at %L",
8165 block_name
, gfc_ascii_statement (*st
), &old_loc
);
8170 /* END INTERFACE has a special handler for its several possible endings. */
8171 if (*st
== ST_END_INTERFACE
)
8172 return gfc_match_end_interface ();
8174 /* We haven't hit the end of statement, so what is left must be an
8176 m
= gfc_match_space ();
8178 m
= gfc_match_name (name
);
8181 gfc_error ("Expected terminating name at %C");
8185 if (block_name
== NULL
)
8188 /* We have to pick out the declared submodule name from the composite
8189 required by F2008:11.2.3 para 2, which ends in the declared name. */
8190 if (state
== COMP_SUBMODULE
)
8191 block_name
= strchr (block_name
, '.') + 1;
8193 if (strcmp (name
, block_name
) != 0 && strcmp (block_name
, "ppr@") != 0)
8195 gfc_error ("Expected label %qs for %s statement at %C", block_name
,
8196 gfc_ascii_statement (*st
));
8199 /* Procedure pointer as function result. */
8200 else if (strcmp (block_name
, "ppr@") == 0
8201 && strcmp (name
, gfc_current_block ()->ns
->proc_name
->name
) != 0)
8203 gfc_error ("Expected label %qs for %s statement at %C",
8204 gfc_current_block ()->ns
->proc_name
->name
,
8205 gfc_ascii_statement (*st
));
8209 if (gfc_match_eos () == MATCH_YES
)
8213 gfc_syntax_error (*st
);
8216 gfc_current_locus
= old_loc
;
8218 /* If we are missing an END BLOCK, we created a half-ready namespace.
8219 Remove it from the parent namespace's sibling list. */
8221 while (state
== COMP_BLOCK
&& !got_matching_end
)
8223 parent_ns
= gfc_current_ns
->parent
;
8225 nsp
= &(gfc_state_stack
->previous
->tail
->ext
.block
.ns
);
8231 if (ns
== gfc_current_ns
)
8233 if (prev_ns
== NULL
)
8236 prev_ns
->sibling
= ns
->sibling
;
8242 gfc_free_namespace (gfc_current_ns
);
8243 gfc_current_ns
= parent_ns
;
8244 gfc_state_stack
= gfc_state_stack
->previous
;
8245 state
= gfc_current_state ();
8253 /***************** Attribute declaration statements ****************/
8255 /* Set the attribute of a single variable. */
8260 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
8263 /* Workaround -Wmaybe-uninitialized false positive during
8264 profiledbootstrap by initializing them. */
8265 gfc_symbol
*sym
= NULL
;
8271 m
= gfc_match_name (name
);
8275 if (find_special (name
, &sym
, false))
8278 if (!check_function_name (name
))
8284 var_locus
= gfc_current_locus
;
8286 /* Deal with possible array specification for certain attributes. */
8287 if (current_attr
.dimension
8288 || current_attr
.codimension
8289 || current_attr
.allocatable
8290 || current_attr
.pointer
8291 || current_attr
.target
)
8293 m
= gfc_match_array_spec (&as
, !current_attr
.codimension
,
8294 !current_attr
.dimension
8295 && !current_attr
.pointer
8296 && !current_attr
.target
);
8297 if (m
== MATCH_ERROR
)
8300 if (current_attr
.dimension
&& m
== MATCH_NO
)
8302 gfc_error ("Missing array specification at %L in DIMENSION "
8303 "statement", &var_locus
);
8308 if (current_attr
.dimension
&& sym
->value
)
8310 gfc_error ("Dimensions specified for %s at %L after its "
8311 "initialization", sym
->name
, &var_locus
);
8316 if (current_attr
.codimension
&& m
== MATCH_NO
)
8318 gfc_error ("Missing array specification at %L in CODIMENSION "
8319 "statement", &var_locus
);
8324 if ((current_attr
.allocatable
|| current_attr
.pointer
)
8325 && (m
== MATCH_YES
) && (as
->type
!= AS_DEFERRED
))
8327 gfc_error ("Array specification must be deferred at %L", &var_locus
);
8333 /* Update symbol table. DIMENSION attribute is set in
8334 gfc_set_array_spec(). For CLASS variables, this must be applied
8335 to the first component, or '_data' field. */
8336 if (sym
->ts
.type
== BT_CLASS
&& sym
->ts
.u
.derived
->attr
.is_class
)
8338 if (!gfc_copy_attr (&CLASS_DATA(sym
)->attr
, ¤t_attr
, &var_locus
))
8346 if (current_attr
.dimension
== 0 && current_attr
.codimension
== 0
8347 && !gfc_copy_attr (&sym
->attr
, ¤t_attr
, &var_locus
))
8354 if (sym
->ts
.type
== BT_CLASS
8355 && !gfc_build_class_symbol (&sym
->ts
, &sym
->attr
, &sym
->as
))
8361 if (!gfc_set_array_spec (sym
, as
, &var_locus
))
8367 if (sym
->attr
.cray_pointee
&& sym
->as
!= NULL
)
8369 /* Fix the array spec. */
8370 m
= gfc_mod_pointee_as (sym
->as
);
8371 if (m
== MATCH_ERROR
)
8375 if (!gfc_add_attribute (&sym
->attr
, &var_locus
))
8381 if ((current_attr
.external
|| current_attr
.intrinsic
)
8382 && sym
->attr
.flavor
!= FL_PROCEDURE
8383 && !gfc_add_flavor (&sym
->attr
, FL_PROCEDURE
, sym
->name
, NULL
))
8389 add_hidden_procptr_result (sym
);
8394 gfc_free_array_spec (as
);
8399 /* Generic attribute declaration subroutine. Used for attributes that
8400 just have a list of names. */
8407 /* Gobble the optional double colon, by simply ignoring the result
8417 if (gfc_match_eos () == MATCH_YES
)
8423 if (gfc_match_char (',') != MATCH_YES
)
8425 gfc_error ("Unexpected character in variable list at %C");
8435 /* This routine matches Cray Pointer declarations of the form:
8436 pointer ( <pointer>, <pointee> )
8438 pointer ( <pointer1>, <pointee1> ), ( <pointer2>, <pointee2> ), ...
8439 The pointer, if already declared, should be an integer. Otherwise, we
8440 set it as BT_INTEGER with kind gfc_index_integer_kind. The pointee may
8441 be either a scalar, or an array declaration. No space is allocated for
8442 the pointee. For the statement
8443 pointer (ipt, ar(10))
8444 any subsequent uses of ar will be translated (in C-notation) as
8445 ar(i) => ((<type> *) ipt)(i)
8446 After gimplification, pointee variable will disappear in the code. */
8449 cray_pointer_decl (void)
8452 gfc_array_spec
*as
= NULL
;
8453 gfc_symbol
*cptr
; /* Pointer symbol. */
8454 gfc_symbol
*cpte
; /* Pointee symbol. */
8460 if (gfc_match_char ('(') != MATCH_YES
)
8462 gfc_error ("Expected %<(%> at %C");
8466 /* Match pointer. */
8467 var_locus
= gfc_current_locus
;
8468 gfc_clear_attr (¤t_attr
);
8469 gfc_add_cray_pointer (¤t_attr
, &var_locus
);
8470 current_ts
.type
= BT_INTEGER
;
8471 current_ts
.kind
= gfc_index_integer_kind
;
8473 m
= gfc_match_symbol (&cptr
, 0);
8476 gfc_error ("Expected variable name at %C");
8480 if (!gfc_add_cray_pointer (&cptr
->attr
, &var_locus
))
8483 gfc_set_sym_referenced (cptr
);
8485 if (cptr
->ts
.type
== BT_UNKNOWN
) /* Override the type, if necessary. */
8487 cptr
->ts
.type
= BT_INTEGER
;
8488 cptr
->ts
.kind
= gfc_index_integer_kind
;
8490 else if (cptr
->ts
.type
!= BT_INTEGER
)
8492 gfc_error ("Cray pointer at %C must be an integer");
8495 else if (cptr
->ts
.kind
< gfc_index_integer_kind
)
8496 gfc_warning (0, "Cray pointer at %C has %d bytes of precision;"
8497 " memory addresses require %d bytes",
8498 cptr
->ts
.kind
, gfc_index_integer_kind
);
8500 if (gfc_match_char (',') != MATCH_YES
)
8502 gfc_error ("Expected \",\" at %C");
8506 /* Match Pointee. */
8507 var_locus
= gfc_current_locus
;
8508 gfc_clear_attr (¤t_attr
);
8509 gfc_add_cray_pointee (¤t_attr
, &var_locus
);
8510 current_ts
.type
= BT_UNKNOWN
;
8511 current_ts
.kind
= 0;
8513 m
= gfc_match_symbol (&cpte
, 0);
8516 gfc_error ("Expected variable name at %C");
8520 /* Check for an optional array spec. */
8521 m
= gfc_match_array_spec (&as
, true, false);
8522 if (m
== MATCH_ERROR
)
8524 gfc_free_array_spec (as
);
8527 else if (m
== MATCH_NO
)
8529 gfc_free_array_spec (as
);
8533 if (!gfc_add_cray_pointee (&cpte
->attr
, &var_locus
))
8536 gfc_set_sym_referenced (cpte
);
8538 if (cpte
->as
== NULL
)
8540 if (!gfc_set_array_spec (cpte
, as
, &var_locus
))
8541 gfc_internal_error ("Couldn't set Cray pointee array spec.");
8543 else if (as
!= NULL
)
8545 gfc_error ("Duplicate array spec for Cray pointee at %C");
8546 gfc_free_array_spec (as
);
8552 if (cpte
->as
!= NULL
)
8554 /* Fix array spec. */
8555 m
= gfc_mod_pointee_as (cpte
->as
);
8556 if (m
== MATCH_ERROR
)
8560 /* Point the Pointee at the Pointer. */
8561 cpte
->cp_pointer
= cptr
;
8563 if (gfc_match_char (')') != MATCH_YES
)
8565 gfc_error ("Expected \")\" at %C");
8568 m
= gfc_match_char (',');
8570 done
= true; /* Stop searching for more declarations. */
8574 if (m
== MATCH_ERROR
/* Failed when trying to find ',' above. */
8575 || gfc_match_eos () != MATCH_YES
)
8577 gfc_error ("Expected %<,%> or end of statement at %C");
8585 gfc_match_external (void)
8588 gfc_clear_attr (¤t_attr
);
8589 current_attr
.external
= 1;
8591 return attr_decl ();
8596 gfc_match_intent (void)
8600 /* This is not allowed within a BLOCK construct! */
8601 if (gfc_current_state () == COMP_BLOCK
)
8603 gfc_error ("INTENT is not allowed inside of BLOCK at %C");
8607 intent
= match_intent_spec ();
8608 if (intent
== INTENT_UNKNOWN
)
8611 gfc_clear_attr (¤t_attr
);
8612 current_attr
.intent
= intent
;
8614 return attr_decl ();
8619 gfc_match_intrinsic (void)
8622 gfc_clear_attr (¤t_attr
);
8623 current_attr
.intrinsic
= 1;
8625 return attr_decl ();
8630 gfc_match_optional (void)
8632 /* This is not allowed within a BLOCK construct! */
8633 if (gfc_current_state () == COMP_BLOCK
)
8635 gfc_error ("OPTIONAL is not allowed inside of BLOCK at %C");
8639 gfc_clear_attr (¤t_attr
);
8640 current_attr
.optional
= 1;
8642 return attr_decl ();
8647 gfc_match_pointer (void)
8649 gfc_gobble_whitespace ();
8650 if (gfc_peek_ascii_char () == '(')
8652 if (!flag_cray_pointer
)
8654 gfc_error ("Cray pointer declaration at %C requires -fcray-pointer "
8658 return cray_pointer_decl ();
8662 gfc_clear_attr (¤t_attr
);
8663 current_attr
.pointer
= 1;
8665 return attr_decl ();
8671 gfc_match_allocatable (void)
8673 gfc_clear_attr (¤t_attr
);
8674 current_attr
.allocatable
= 1;
8676 return attr_decl ();
8681 gfc_match_codimension (void)
8683 gfc_clear_attr (¤t_attr
);
8684 current_attr
.codimension
= 1;
8686 return attr_decl ();
8691 gfc_match_contiguous (void)
8693 if (!gfc_notify_std (GFC_STD_F2008
, "CONTIGUOUS statement at %C"))
8696 gfc_clear_attr (¤t_attr
);
8697 current_attr
.contiguous
= 1;
8699 return attr_decl ();
8704 gfc_match_dimension (void)
8706 gfc_clear_attr (¤t_attr
);
8707 current_attr
.dimension
= 1;
8709 return attr_decl ();
8714 gfc_match_target (void)
8716 gfc_clear_attr (¤t_attr
);
8717 current_attr
.target
= 1;
8719 return attr_decl ();
8723 /* Match the list of entities being specified in a PUBLIC or PRIVATE
8727 access_attr_decl (gfc_statement st
)
8729 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
8730 interface_type type
;
8732 gfc_symbol
*sym
, *dt_sym
;
8733 gfc_intrinsic_op op
;
8736 if (gfc_match (" ::") == MATCH_NO
&& gfc_match_space () == MATCH_NO
)
8741 m
= gfc_match_generic_spec (&type
, name
, &op
);
8744 if (m
== MATCH_ERROR
)
8749 case INTERFACE_NAMELESS
:
8750 case INTERFACE_ABSTRACT
:
8753 case INTERFACE_GENERIC
:
8754 case INTERFACE_DTIO
:
8756 if (gfc_get_symbol (name
, NULL
, &sym
))
8759 if (type
== INTERFACE_DTIO
8760 && gfc_current_ns
->proc_name
8761 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
8762 && sym
->attr
.flavor
== FL_UNKNOWN
)
8763 sym
->attr
.flavor
= FL_PROCEDURE
;
8765 if (!gfc_add_access (&sym
->attr
,
8767 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
,
8771 if (sym
->attr
.generic
&& (dt_sym
= gfc_find_dt_in_generic (sym
))
8772 && !gfc_add_access (&dt_sym
->attr
,
8774 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
,
8780 case INTERFACE_INTRINSIC_OP
:
8781 if (gfc_current_ns
->operator_access
[op
] == ACCESS_UNKNOWN
)
8783 gfc_intrinsic_op other_op
;
8785 gfc_current_ns
->operator_access
[op
] =
8786 (st
== ST_PUBLIC
) ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
8788 /* Handle the case if there is another op with the same
8789 function, for INTRINSIC_EQ vs. INTRINSIC_EQ_OS and so on. */
8790 other_op
= gfc_equivalent_op (op
);
8792 if (other_op
!= INTRINSIC_NONE
)
8793 gfc_current_ns
->operator_access
[other_op
] =
8794 (st
== ST_PUBLIC
) ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
8799 gfc_error ("Access specification of the %s operator at %C has "
8800 "already been specified", gfc_op2string (op
));
8806 case INTERFACE_USER_OP
:
8807 uop
= gfc_get_uop (name
);
8809 if (uop
->access
== ACCESS_UNKNOWN
)
8811 uop
->access
= (st
== ST_PUBLIC
)
8812 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
8816 gfc_error ("Access specification of the .%s. operator at %C "
8817 "has already been specified", sym
->name
);
8824 if (gfc_match_char (',') == MATCH_NO
)
8828 if (gfc_match_eos () != MATCH_YES
)
8833 gfc_syntax_error (st
);
8841 gfc_match_protected (void)
8846 if (!gfc_current_ns
->proc_name
8847 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
8849 gfc_error ("PROTECTED at %C only allowed in specification "
8850 "part of a module");
8855 if (!gfc_notify_std (GFC_STD_F2003
, "PROTECTED statement at %C"))
8858 if (gfc_match (" ::") == MATCH_NO
&& gfc_match_space () == MATCH_NO
)
8863 if (gfc_match_eos () == MATCH_YES
)
8868 m
= gfc_match_symbol (&sym
, 0);
8872 if (!gfc_add_protected (&sym
->attr
, sym
->name
, &gfc_current_locus
))
8884 if (gfc_match_eos () == MATCH_YES
)
8886 if (gfc_match_char (',') != MATCH_YES
)
8893 gfc_error ("Syntax error in PROTECTED statement at %C");
8898 /* The PRIVATE statement is a bit weird in that it can be an attribute
8899 declaration, but also works as a standalone statement inside of a
8900 type declaration or a module. */
8903 gfc_match_private (gfc_statement
*st
)
8906 if (gfc_match ("private") != MATCH_YES
)
8909 if (gfc_current_state () != COMP_MODULE
8910 && !(gfc_current_state () == COMP_DERIVED
8911 && gfc_state_stack
->previous
8912 && gfc_state_stack
->previous
->state
== COMP_MODULE
)
8913 && !(gfc_current_state () == COMP_DERIVED_CONTAINS
8914 && gfc_state_stack
->previous
&& gfc_state_stack
->previous
->previous
8915 && gfc_state_stack
->previous
->previous
->state
== COMP_MODULE
))
8917 gfc_error ("PRIVATE statement at %C is only allowed in the "
8918 "specification part of a module");
8922 if (gfc_current_state () == COMP_DERIVED
)
8924 if (gfc_match_eos () == MATCH_YES
)
8930 gfc_syntax_error (ST_PRIVATE
);
8934 if (gfc_match_eos () == MATCH_YES
)
8941 return access_attr_decl (ST_PRIVATE
);
8946 gfc_match_public (gfc_statement
*st
)
8949 if (gfc_match ("public") != MATCH_YES
)
8952 if (gfc_current_state () != COMP_MODULE
)
8954 gfc_error ("PUBLIC statement at %C is only allowed in the "
8955 "specification part of a module");
8959 if (gfc_match_eos () == MATCH_YES
)
8966 return access_attr_decl (ST_PUBLIC
);
8970 /* Workhorse for gfc_match_parameter. */
8980 m
= gfc_match_symbol (&sym
, 0);
8982 gfc_error ("Expected variable name at %C in PARAMETER statement");
8987 if (gfc_match_char ('=') == MATCH_NO
)
8989 gfc_error ("Expected = sign in PARAMETER statement at %C");
8993 m
= gfc_match_init_expr (&init
);
8995 gfc_error ("Expected expression at %C in PARAMETER statement");
8999 if (sym
->ts
.type
== BT_UNKNOWN
9000 && !gfc_set_default_type (sym
, 1, NULL
))
9006 if (!gfc_check_assign_symbol (sym
, NULL
, init
)
9007 || !gfc_add_flavor (&sym
->attr
, FL_PARAMETER
, sym
->name
, NULL
))
9015 gfc_error ("Initializing already initialized variable at %C");
9020 t
= add_init_expr_to_sym (sym
->name
, &init
, &gfc_current_locus
);
9021 return (t
) ? MATCH_YES
: MATCH_ERROR
;
9024 gfc_free_expr (init
);
9029 /* Match a parameter statement, with the weird syntax that these have. */
9032 gfc_match_parameter (void)
9034 const char *term
= " )%t";
9037 if (gfc_match_char ('(') == MATCH_NO
)
9039 /* With legacy PARAMETER statements, don't expect a terminating ')'. */
9040 if (!gfc_notify_std (GFC_STD_LEGACY
, "PARAMETER without '()' at %C"))
9051 if (gfc_match (term
) == MATCH_YES
)
9054 if (gfc_match_char (',') != MATCH_YES
)
9056 gfc_error ("Unexpected characters in PARAMETER statement at %C");
9067 gfc_match_automatic (void)
9071 bool seen_symbol
= false;
9073 if (!flag_dec_static
)
9075 gfc_error ("%s at %C is a DEC extension, enable with "
9086 m
= gfc_match_symbol (&sym
, 0);
9096 if (!gfc_add_automatic (&sym
->attr
, sym
->name
, &gfc_current_locus
))
9102 if (gfc_match_eos () == MATCH_YES
)
9104 if (gfc_match_char (',') != MATCH_YES
)
9110 gfc_error ("Expected entity-list in AUTOMATIC statement at %C");
9117 gfc_error ("Syntax error in AUTOMATIC statement at %C");
9123 gfc_match_static (void)
9127 bool seen_symbol
= false;
9129 if (!flag_dec_static
)
9131 gfc_error ("%s at %C is a DEC extension, enable with "
9141 m
= gfc_match_symbol (&sym
, 0);
9151 if (!gfc_add_save (&sym
->attr
, SAVE_EXPLICIT
, sym
->name
,
9152 &gfc_current_locus
))
9158 if (gfc_match_eos () == MATCH_YES
)
9160 if (gfc_match_char (',') != MATCH_YES
)
9166 gfc_error ("Expected entity-list in STATIC statement at %C");
9173 gfc_error ("Syntax error in STATIC statement at %C");
9178 /* Save statements have a special syntax. */
9181 gfc_match_save (void)
9183 char n
[GFC_MAX_SYMBOL_LEN
+1];
9188 if (gfc_match_eos () == MATCH_YES
)
9190 if (gfc_current_ns
->seen_save
)
9192 if (!gfc_notify_std (GFC_STD_LEGACY
, "Blanket SAVE statement at %C "
9193 "follows previous SAVE statement"))
9197 gfc_current_ns
->save_all
= gfc_current_ns
->seen_save
= 1;
9201 if (gfc_current_ns
->save_all
)
9203 if (!gfc_notify_std (GFC_STD_LEGACY
, "SAVE statement at %C follows "
9204 "blanket SAVE statement"))
9212 m
= gfc_match_symbol (&sym
, 0);
9216 if (!gfc_add_save (&sym
->attr
, SAVE_EXPLICIT
, sym
->name
,
9217 &gfc_current_locus
))
9228 m
= gfc_match (" / %n /", &n
);
9229 if (m
== MATCH_ERROR
)
9234 c
= gfc_get_common (n
, 0);
9237 gfc_current_ns
->seen_save
= 1;
9240 if (gfc_match_eos () == MATCH_YES
)
9242 if (gfc_match_char (',') != MATCH_YES
)
9249 gfc_error ("Syntax error in SAVE statement at %C");
9255 gfc_match_value (void)
9260 /* This is not allowed within a BLOCK construct! */
9261 if (gfc_current_state () == COMP_BLOCK
)
9263 gfc_error ("VALUE is not allowed inside of BLOCK at %C");
9267 if (!gfc_notify_std (GFC_STD_F2003
, "VALUE statement at %C"))
9270 if (gfc_match (" ::") == MATCH_NO
&& gfc_match_space () == MATCH_NO
)
9275 if (gfc_match_eos () == MATCH_YES
)
9280 m
= gfc_match_symbol (&sym
, 0);
9284 if (!gfc_add_value (&sym
->attr
, sym
->name
, &gfc_current_locus
))
9296 if (gfc_match_eos () == MATCH_YES
)
9298 if (gfc_match_char (',') != MATCH_YES
)
9305 gfc_error ("Syntax error in VALUE statement at %C");
9311 gfc_match_volatile (void)
9317 if (!gfc_notify_std (GFC_STD_F2003
, "VOLATILE statement at %C"))
9320 if (gfc_match (" ::") == MATCH_NO
&& gfc_match_space () == MATCH_NO
)
9325 if (gfc_match_eos () == MATCH_YES
)
9330 /* VOLATILE is special because it can be added to host-associated
9331 symbols locally. Except for coarrays. */
9332 m
= gfc_match_symbol (&sym
, 1);
9336 name
= XCNEWVAR (char, strlen (sym
->name
) + 1);
9337 strcpy (name
, sym
->name
);
9338 if (!check_function_name (name
))
9340 /* F2008, C560+C561. VOLATILE for host-/use-associated variable or
9341 for variable in a BLOCK which is defined outside of the BLOCK. */
9342 if (sym
->ns
!= gfc_current_ns
&& sym
->attr
.codimension
)
9344 gfc_error ("Specifying VOLATILE for coarray variable %qs at "
9345 "%C, which is use-/host-associated", sym
->name
);
9348 if (!gfc_add_volatile (&sym
->attr
, sym
->name
, &gfc_current_locus
))
9360 if (gfc_match_eos () == MATCH_YES
)
9362 if (gfc_match_char (',') != MATCH_YES
)
9369 gfc_error ("Syntax error in VOLATILE statement at %C");
9375 gfc_match_asynchronous (void)
9381 if (!gfc_notify_std (GFC_STD_F2003
, "ASYNCHRONOUS statement at %C"))
9384 if (gfc_match (" ::") == MATCH_NO
&& gfc_match_space () == MATCH_NO
)
9389 if (gfc_match_eos () == MATCH_YES
)
9394 /* ASYNCHRONOUS is special because it can be added to host-associated
9396 m
= gfc_match_symbol (&sym
, 1);
9400 name
= XCNEWVAR (char, strlen (sym
->name
) + 1);
9401 strcpy (name
, sym
->name
);
9402 if (!check_function_name (name
))
9404 if (!gfc_add_asynchronous (&sym
->attr
, sym
->name
, &gfc_current_locus
))
9416 if (gfc_match_eos () == MATCH_YES
)
9418 if (gfc_match_char (',') != MATCH_YES
)
9425 gfc_error ("Syntax error in ASYNCHRONOUS statement at %C");
9430 /* Match a module procedure statement in a submodule. */
9433 gfc_match_submod_proc (void)
9435 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
9436 gfc_symbol
*sym
, *fsym
;
9438 gfc_formal_arglist
*formal
, *head
, *tail
;
9440 if (gfc_current_state () != COMP_CONTAINS
9441 || !(gfc_state_stack
->previous
9442 && (gfc_state_stack
->previous
->state
== COMP_SUBMODULE
9443 || gfc_state_stack
->previous
->state
== COMP_MODULE
)))
9446 m
= gfc_match (" module% procedure% %n", name
);
9450 if (!gfc_notify_std (GFC_STD_F2008
, "MODULE PROCEDURE declaration "
9454 if (get_proc_name (name
, &sym
, false))
9457 /* Make sure that the result field is appropriately filled, even though
9458 the result symbol will be replaced later on. */
9459 if (sym
->tlink
&& sym
->tlink
->attr
.function
)
9461 if (sym
->tlink
->result
9462 && sym
->tlink
->result
!= sym
->tlink
)
9463 sym
->result
= sym
->tlink
->result
;
9468 /* Set declared_at as it might point to, e.g., a PUBLIC statement, if
9469 the symbol existed before. */
9470 sym
->declared_at
= gfc_current_locus
;
9472 if (!sym
->attr
.module_procedure
)
9475 /* Signal match_end to expect "end procedure". */
9476 sym
->abr_modproc_decl
= 1;
9478 /* Change from IFSRC_IFBODY coming from the interface declaration. */
9479 sym
->attr
.if_source
= IFSRC_DECL
;
9481 gfc_new_block
= sym
;
9483 /* Make a new formal arglist with the symbols in the procedure
9486 for (formal
= sym
->formal
; formal
&& formal
->sym
; formal
= formal
->next
)
9488 if (formal
== sym
->formal
)
9489 head
= tail
= gfc_get_formal_arglist ();
9492 tail
->next
= gfc_get_formal_arglist ();
9496 if (gfc_copy_dummy_sym (&fsym
, formal
->sym
, 0))
9500 gfc_set_sym_referenced (fsym
);
9503 /* The dummy symbols get cleaned up, when the formal_namespace of the
9504 interface declaration is cleared. This allows us to add the
9505 explicit interface as is done for other type of procedure. */
9506 if (!gfc_add_explicit_interface (sym
, IFSRC_DECL
, head
,
9507 &gfc_current_locus
))
9510 if (gfc_match_eos () != MATCH_YES
)
9512 gfc_syntax_error (ST_MODULE_PROC
);
9519 gfc_free_formal_arglist (head
);
9524 /* Match a module procedure statement. Note that we have to modify
9525 symbols in the parent's namespace because the current one was there
9526 to receive symbols that are in an interface's formal argument list. */
9529 gfc_match_modproc (void)
9531 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
9535 gfc_namespace
*module_ns
;
9536 gfc_interface
*old_interface_head
, *interface
;
9538 if (gfc_state_stack
->state
!= COMP_INTERFACE
9539 || gfc_state_stack
->previous
== NULL
9540 || current_interface
.type
== INTERFACE_NAMELESS
9541 || current_interface
.type
== INTERFACE_ABSTRACT
)
9543 gfc_error ("MODULE PROCEDURE at %C must be in a generic module "
9548 module_ns
= gfc_current_ns
->parent
;
9549 for (; module_ns
; module_ns
= module_ns
->parent
)
9550 if (module_ns
->proc_name
->attr
.flavor
== FL_MODULE
9551 || module_ns
->proc_name
->attr
.flavor
== FL_PROGRAM
9552 || (module_ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
9553 && !module_ns
->proc_name
->attr
.contained
))
9556 if (module_ns
== NULL
)
9559 /* Store the current state of the interface. We will need it if we
9560 end up with a syntax error and need to recover. */
9561 old_interface_head
= gfc_current_interface_head ();
9563 /* Check if the F2008 optional double colon appears. */
9564 gfc_gobble_whitespace ();
9565 old_locus
= gfc_current_locus
;
9566 if (gfc_match ("::") == MATCH_YES
)
9568 if (!gfc_notify_std (GFC_STD_F2008
, "double colon in "
9569 "MODULE PROCEDURE statement at %L", &old_locus
))
9573 gfc_current_locus
= old_locus
;
9578 old_locus
= gfc_current_locus
;
9580 m
= gfc_match_name (name
);
9586 /* Check for syntax error before starting to add symbols to the
9587 current namespace. */
9588 if (gfc_match_eos () == MATCH_YES
)
9591 if (!last
&& gfc_match_char (',') != MATCH_YES
)
9594 /* Now we're sure the syntax is valid, we process this item
9596 if (gfc_get_symbol (name
, module_ns
, &sym
))
9599 if (sym
->attr
.intrinsic
)
9601 gfc_error ("Intrinsic procedure at %L cannot be a MODULE "
9602 "PROCEDURE", &old_locus
);
9606 if (sym
->attr
.proc
!= PROC_MODULE
9607 && !gfc_add_procedure (&sym
->attr
, PROC_MODULE
, sym
->name
, NULL
))
9610 if (!gfc_add_interface (sym
))
9613 sym
->attr
.mod_proc
= 1;
9614 sym
->declared_at
= old_locus
;
9623 /* Restore the previous state of the interface. */
9624 interface
= gfc_current_interface_head ();
9625 gfc_set_current_interface_head (old_interface_head
);
9627 /* Free the new interfaces. */
9628 while (interface
!= old_interface_head
)
9630 gfc_interface
*i
= interface
->next
;
9635 /* And issue a syntax error. */
9636 gfc_syntax_error (ST_MODULE_PROC
);
9641 /* Check a derived type that is being extended. */
9644 check_extended_derived_type (char *name
)
9646 gfc_symbol
*extended
;
9648 if (gfc_find_symbol (name
, gfc_current_ns
, 1, &extended
))
9650 gfc_error ("Ambiguous symbol in TYPE definition at %C");
9654 extended
= gfc_find_dt_in_generic (extended
);
9659 gfc_error ("Symbol %qs at %C has not been previously defined", name
);
9663 if (extended
->attr
.flavor
!= FL_DERIVED
)
9665 gfc_error ("%qs in EXTENDS expression at %C is not a "
9666 "derived type", name
);
9670 if (extended
->attr
.is_bind_c
)
9672 gfc_error ("%qs cannot be extended at %C because it "
9673 "is BIND(C)", extended
->name
);
9677 if (extended
->attr
.sequence
)
9679 gfc_error ("%qs cannot be extended at %C because it "
9680 "is a SEQUENCE type", extended
->name
);
9688 /* Match the optional attribute specifiers for a type declaration.
9689 Return MATCH_ERROR if an error is encountered in one of the handled
9690 attributes (public, private, bind(c)), MATCH_NO if what's found is
9691 not a handled attribute, and MATCH_YES otherwise. TODO: More error
9692 checking on attribute conflicts needs to be done. */
9695 gfc_get_type_attr_spec (symbol_attribute
*attr
, char *name
)
9697 /* See if the derived type is marked as private. */
9698 if (gfc_match (" , private") == MATCH_YES
)
9700 if (gfc_current_state () != COMP_MODULE
)
9702 gfc_error ("Derived type at %C can only be PRIVATE in the "
9703 "specification part of a module");
9707 if (!gfc_add_access (attr
, ACCESS_PRIVATE
, NULL
, NULL
))
9710 else if (gfc_match (" , public") == MATCH_YES
)
9712 if (gfc_current_state () != COMP_MODULE
)
9714 gfc_error ("Derived type at %C can only be PUBLIC in the "
9715 "specification part of a module");
9719 if (!gfc_add_access (attr
, ACCESS_PUBLIC
, NULL
, NULL
))
9722 else if (gfc_match (" , bind ( c )") == MATCH_YES
)
9724 /* If the type is defined to be bind(c) it then needs to make
9725 sure that all fields are interoperable. This will
9726 need to be a semantic check on the finished derived type.
9727 See 15.2.3 (lines 9-12) of F2003 draft. */
9728 if (!gfc_add_is_bind_c (attr
, NULL
, &gfc_current_locus
, 0))
9731 /* TODO: attr conflicts need to be checked, probably in symbol.c. */
9733 else if (gfc_match (" , abstract") == MATCH_YES
)
9735 if (!gfc_notify_std (GFC_STD_F2003
, "ABSTRACT type at %C"))
9738 if (!gfc_add_abstract (attr
, &gfc_current_locus
))
9741 else if (name
&& gfc_match (" , extends ( %n )", name
) == MATCH_YES
)
9743 if (!gfc_add_extension (attr
, &gfc_current_locus
))
9749 /* If we get here, something matched. */
9754 /* Common function for type declaration blocks similar to derived types, such
9755 as STRUCTURES and MAPs. Unlike derived types, a structure type
9756 does NOT have a generic symbol matching the name given by the user.
9757 STRUCTUREs can share names with variables and PARAMETERs so we must allow
9758 for the creation of an independent symbol.
9759 Other parameters are a message to prefix errors with, the name of the new
9760 type to be created, and the flavor to add to the resulting symbol. */
9763 get_struct_decl (const char *name
, sym_flavor fl
, locus
*decl
,
9764 gfc_symbol
**result
)
9769 gcc_assert (name
[0] == (char) TOUPPER (name
[0]));
9774 where
= gfc_current_locus
;
9776 if (gfc_get_symbol (name
, NULL
, &sym
))
9781 gfc_internal_error ("Failed to create structure type '%s' at %C", name
);
9785 if (sym
->components
!= NULL
|| sym
->attr
.zero_comp
)
9787 gfc_error ("Type definition of %qs at %C was already defined at %L",
9788 sym
->name
, &sym
->declared_at
);
9792 sym
->declared_at
= where
;
9794 if (sym
->attr
.flavor
!= fl
9795 && !gfc_add_flavor (&sym
->attr
, fl
, sym
->name
, NULL
))
9798 if (!sym
->hash_value
)
9799 /* Set the hash for the compound name for this type. */
9800 sym
->hash_value
= gfc_hash_value (sym
);
9802 /* Normally the type is expected to have been completely parsed by the time
9803 a field declaration with this type is seen. For unions, maps, and nested
9804 structure declarations, we need to indicate that it is okay that we
9805 haven't seen any components yet. This will be updated after the structure
9807 sym
->attr
.zero_comp
= 0;
9809 /* Structures always act like derived-types with the SEQUENCE attribute */
9810 gfc_add_sequence (&sym
->attr
, sym
->name
, NULL
);
9812 if (result
) *result
= sym
;
9818 /* Match the opening of a MAP block. Like a struct within a union in C;
9819 behaves identical to STRUCTURE blocks. */
9822 gfc_match_map (void)
9824 /* Counter used to give unique internal names to map structures. */
9825 static unsigned int gfc_map_id
= 0;
9826 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
9830 old_loc
= gfc_current_locus
;
9832 if (gfc_match_eos () != MATCH_YES
)
9834 gfc_error ("Junk after MAP statement at %C");
9835 gfc_current_locus
= old_loc
;
9839 /* Map blocks are anonymous so we make up unique names for the symbol table
9840 which are invalid Fortran identifiers. */
9841 snprintf (name
, GFC_MAX_SYMBOL_LEN
+ 1, "MM$%u", gfc_map_id
++);
9843 if (!get_struct_decl (name
, FL_STRUCT
, &old_loc
, &sym
))
9846 gfc_new_block
= sym
;
9852 /* Match the opening of a UNION block. */
9855 gfc_match_union (void)
9857 /* Counter used to give unique internal names to union types. */
9858 static unsigned int gfc_union_id
= 0;
9859 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
9863 old_loc
= gfc_current_locus
;
9865 if (gfc_match_eos () != MATCH_YES
)
9867 gfc_error ("Junk after UNION statement at %C");
9868 gfc_current_locus
= old_loc
;
9872 /* Unions are anonymous so we make up unique names for the symbol table
9873 which are invalid Fortran identifiers. */
9874 snprintf (name
, GFC_MAX_SYMBOL_LEN
+ 1, "UU$%u", gfc_union_id
++);
9876 if (!get_struct_decl (name
, FL_UNION
, &old_loc
, &sym
))
9879 gfc_new_block
= sym
;
9885 /* Match the beginning of a STRUCTURE declaration. This is similar to
9886 matching the beginning of a derived type declaration with a few
9887 twists. The resulting type symbol has no access control or other
9888 interesting attributes. */
9891 gfc_match_structure_decl (void)
9893 /* Counter used to give unique internal names to anonymous structures. */
9894 static unsigned int gfc_structure_id
= 0;
9895 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
9900 if (!flag_dec_structure
)
9902 gfc_error ("%s at %C is a DEC extension, enable with "
9903 "%<-fdec-structure%>",
9910 m
= gfc_match (" /%n/", name
);
9913 /* Non-nested structure declarations require a structure name. */
9914 if (!gfc_comp_struct (gfc_current_state ()))
9916 gfc_error ("Structure name expected in non-nested structure "
9917 "declaration at %C");
9920 /* This is an anonymous structure; make up a unique name for it
9921 (upper-case letters never make it to symbol names from the source).
9922 The important thing is initializing the type variable
9923 and setting gfc_new_symbol, which is immediately used by
9924 parse_structure () and variable_decl () to add components of
9926 snprintf (name
, GFC_MAX_SYMBOL_LEN
+ 1, "SS$%u", gfc_structure_id
++);
9929 where
= gfc_current_locus
;
9930 /* No field list allowed after non-nested structure declaration. */
9931 if (!gfc_comp_struct (gfc_current_state ())
9932 && gfc_match_eos () != MATCH_YES
)
9934 gfc_error ("Junk after non-nested STRUCTURE statement at %C");
9938 /* Make sure the name is not the name of an intrinsic type. */
9939 if (gfc_is_intrinsic_typename (name
))
9941 gfc_error ("Structure name %qs at %C cannot be the same as an"
9942 " intrinsic type", name
);
9946 /* Store the actual type symbol for the structure with an upper-case first
9947 letter (an invalid Fortran identifier). */
9949 if (!get_struct_decl (gfc_dt_upper_string (name
), FL_STRUCT
, &where
, &sym
))
9952 gfc_new_block
= sym
;
9957 /* This function does some work to determine which matcher should be used to
9958 * match a statement beginning with "TYPE". This is used to disambiguate TYPE
9959 * as an alias for PRINT from derived type declarations, TYPE IS statements,
9960 * and [parameterized] derived type declarations. */
9963 gfc_match_type (gfc_statement
*st
)
9965 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
9969 /* Requires -fdec. */
9973 m
= gfc_match ("type");
9976 /* If we already have an error in the buffer, it is probably from failing to
9977 * match a derived type data declaration. Let it happen. */
9978 else if (gfc_error_flag_test ())
9981 old_loc
= gfc_current_locus
;
9984 /* If we see an attribute list before anything else it's definitely a derived
9985 * type declaration. */
9986 if (gfc_match (" ,") == MATCH_YES
|| gfc_match (" ::") == MATCH_YES
)
9989 /* By now "TYPE" has already been matched. If we do not see a name, this may
9990 * be something like "TYPE *" or "TYPE <fmt>". */
9991 m
= gfc_match_name (name
);
9994 /* Let print match if it can, otherwise throw an error from
9995 * gfc_match_derived_decl. */
9996 gfc_current_locus
= old_loc
;
9997 if (gfc_match_print () == MATCH_YES
)
10005 /* Check for EOS. */
10006 if (gfc_match_eos () == MATCH_YES
)
10008 /* By now we have "TYPE <name> <EOS>". Check first if the name is an
10009 * intrinsic typename - if so let gfc_match_derived_decl dump an error.
10010 * Otherwise if gfc_match_derived_decl fails it's probably an existing
10011 * symbol which can be printed. */
10012 gfc_current_locus
= old_loc
;
10013 m
= gfc_match_derived_decl ();
10014 if (gfc_is_intrinsic_typename (name
) || m
== MATCH_YES
)
10016 *st
= ST_DERIVED_DECL
;
10022 /* Here we have "TYPE <name>". Check for <TYPE IS (> or a PDT declaration
10023 like <type name(parameter)>. */
10024 gfc_gobble_whitespace ();
10025 bool paren
= gfc_peek_ascii_char () == '(';
10028 if (strcmp ("is", name
) == 0)
10035 /* Treat TYPE... like PRINT... */
10036 gfc_current_locus
= old_loc
;
10038 return gfc_match_print ();
10041 gfc_current_locus
= old_loc
;
10042 *st
= ST_DERIVED_DECL
;
10043 return gfc_match_derived_decl ();
10046 gfc_current_locus
= old_loc
;
10048 return gfc_match_type_is ();
10052 /* Match the beginning of a derived type declaration. If a type name
10053 was the result of a function, then it is possible to have a symbol
10054 already to be known as a derived type yet have no components. */
10057 gfc_match_derived_decl (void)
10059 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
10060 char parent
[GFC_MAX_SYMBOL_LEN
+ 1];
10061 symbol_attribute attr
;
10062 gfc_symbol
*sym
, *gensym
;
10063 gfc_symbol
*extended
;
10065 match is_type_attr_spec
= MATCH_NO
;
10066 bool seen_attr
= false;
10067 gfc_interface
*intr
= NULL
, *head
;
10068 bool parameterized_type
= false;
10069 bool seen_colons
= false;
10071 if (gfc_comp_struct (gfc_current_state ()))
10076 gfc_clear_attr (&attr
);
10081 is_type_attr_spec
= gfc_get_type_attr_spec (&attr
, parent
);
10082 if (is_type_attr_spec
== MATCH_ERROR
)
10083 return MATCH_ERROR
;
10084 if (is_type_attr_spec
== MATCH_YES
)
10086 } while (is_type_attr_spec
== MATCH_YES
);
10088 /* Deal with derived type extensions. The extension attribute has
10089 been added to 'attr' but now the parent type must be found and
10092 extended
= check_extended_derived_type (parent
);
10094 if (parent
[0] && !extended
)
10095 return MATCH_ERROR
;
10097 m
= gfc_match (" ::");
10098 if (m
== MATCH_YES
)
10100 seen_colons
= true;
10102 else if (seen_attr
)
10104 gfc_error ("Expected :: in TYPE definition at %C");
10105 return MATCH_ERROR
;
10108 m
= gfc_match (" %n ", name
);
10109 if (m
!= MATCH_YES
)
10112 /* Make sure that we don't identify TYPE IS (...) as a parameterized
10113 derived type named 'is'.
10114 TODO Expand the check, when 'name' = "is" by matching " (tname) "
10115 and checking if this is a(n intrinsic) typename. his picks up
10116 misplaced TYPE IS statements such as in select_type_1.f03. */
10117 if (gfc_peek_ascii_char () == '(')
10119 if (gfc_current_state () == COMP_SELECT_TYPE
10120 || (!seen_colons
&& !strcmp (name
, "is")))
10122 parameterized_type
= true;
10125 m
= gfc_match_eos ();
10126 if (m
!= MATCH_YES
&& !parameterized_type
)
10129 /* Make sure the name is not the name of an intrinsic type. */
10130 if (gfc_is_intrinsic_typename (name
))
10132 gfc_error ("Type name %qs at %C cannot be the same as an intrinsic "
10134 return MATCH_ERROR
;
10137 if (gfc_get_symbol (name
, NULL
, &gensym
))
10138 return MATCH_ERROR
;
10140 if (!gensym
->attr
.generic
&& gensym
->ts
.type
!= BT_UNKNOWN
)
10142 if (gensym
->ts
.u
.derived
)
10143 gfc_error ("Derived type name %qs at %C already has a basic type "
10144 "of %s", gensym
->name
, gfc_typename (&gensym
->ts
));
10146 gfc_error ("Derived type name %qs at %C already has a basic type",
10148 return MATCH_ERROR
;
10151 if (!gensym
->attr
.generic
10152 && !gfc_add_generic (&gensym
->attr
, gensym
->name
, NULL
))
10153 return MATCH_ERROR
;
10155 if (!gensym
->attr
.function
10156 && !gfc_add_function (&gensym
->attr
, gensym
->name
, NULL
))
10157 return MATCH_ERROR
;
10159 sym
= gfc_find_dt_in_generic (gensym
);
10161 if (sym
&& (sym
->components
!= NULL
|| sym
->attr
.zero_comp
))
10163 gfc_error ("Derived type definition of %qs at %C has already been "
10164 "defined", sym
->name
);
10165 return MATCH_ERROR
;
10170 /* Use upper case to save the actual derived-type symbol. */
10171 gfc_get_symbol (gfc_dt_upper_string (gensym
->name
), NULL
, &sym
);
10172 sym
->name
= gfc_get_string ("%s", gensym
->name
);
10173 head
= gensym
->generic
;
10174 intr
= gfc_get_interface ();
10176 intr
->where
= gfc_current_locus
;
10177 intr
->sym
->declared_at
= gfc_current_locus
;
10179 gensym
->generic
= intr
;
10180 gensym
->attr
.if_source
= IFSRC_DECL
;
10183 /* The symbol may already have the derived attribute without the
10184 components. The ways this can happen is via a function
10185 definition, an INTRINSIC statement or a subtype in another
10186 derived type that is a pointer. The first part of the AND clause
10187 is true if the symbol is not the return value of a function. */
10188 if (sym
->attr
.flavor
!= FL_DERIVED
10189 && !gfc_add_flavor (&sym
->attr
, FL_DERIVED
, sym
->name
, NULL
))
10190 return MATCH_ERROR
;
10192 if (attr
.access
!= ACCESS_UNKNOWN
10193 && !gfc_add_access (&sym
->attr
, attr
.access
, sym
->name
, NULL
))
10194 return MATCH_ERROR
;
10195 else if (sym
->attr
.access
== ACCESS_UNKNOWN
10196 && gensym
->attr
.access
!= ACCESS_UNKNOWN
10197 && !gfc_add_access (&sym
->attr
, gensym
->attr
.access
,
10199 return MATCH_ERROR
;
10201 if (sym
->attr
.access
!= ACCESS_UNKNOWN
10202 && gensym
->attr
.access
== ACCESS_UNKNOWN
)
10203 gensym
->attr
.access
= sym
->attr
.access
;
10205 /* See if the derived type was labeled as bind(c). */
10206 if (attr
.is_bind_c
!= 0)
10207 sym
->attr
.is_bind_c
= attr
.is_bind_c
;
10209 /* Construct the f2k_derived namespace if it is not yet there. */
10210 if (!sym
->f2k_derived
)
10211 sym
->f2k_derived
= gfc_get_namespace (NULL
, 0);
10213 if (parameterized_type
)
10215 /* Ignore error or mismatches by going to the end of the statement
10216 in order to avoid the component declarations causing problems. */
10217 m
= gfc_match_formal_arglist (sym
, 0, 0, true);
10218 if (m
!= MATCH_YES
)
10219 gfc_error_recovery ();
10220 m
= gfc_match_eos ();
10221 if (m
!= MATCH_YES
)
10223 gfc_error_recovery ();
10224 gfc_error_now ("Garbage after PARAMETERIZED TYPE declaration at %C");
10226 sym
->attr
.pdt_template
= 1;
10229 if (extended
&& !sym
->components
)
10232 gfc_formal_arglist
*f
, *g
, *h
;
10234 /* Add the extended derived type as the first component. */
10235 gfc_add_component (sym
, parent
, &p
);
10237 gfc_set_sym_referenced (extended
);
10239 p
->ts
.type
= BT_DERIVED
;
10240 p
->ts
.u
.derived
= extended
;
10241 p
->initializer
= gfc_default_initializer (&p
->ts
);
10243 /* Set extension level. */
10244 if (extended
->attr
.extension
== 255)
10246 /* Since the extension field is 8 bit wide, we can only have
10247 up to 255 extension levels. */
10248 gfc_error ("Maximum extension level reached with type %qs at %L",
10249 extended
->name
, &extended
->declared_at
);
10250 return MATCH_ERROR
;
10252 sym
->attr
.extension
= extended
->attr
.extension
+ 1;
10254 /* Provide the links between the extended type and its extension. */
10255 if (!extended
->f2k_derived
)
10256 extended
->f2k_derived
= gfc_get_namespace (NULL
, 0);
10258 /* Copy the extended type-param-name-list from the extended type,
10259 append those of the extension and add the whole lot to the
10261 if (extended
->attr
.pdt_template
)
10264 sym
->attr
.pdt_template
= 1;
10265 for (f
= extended
->formal
; f
; f
= f
->next
)
10267 if (f
== extended
->formal
)
10269 g
= gfc_get_formal_arglist ();
10274 g
->next
= gfc_get_formal_arglist ();
10279 g
->next
= sym
->formal
;
10284 if (!sym
->hash_value
)
10285 /* Set the hash for the compound name for this type. */
10286 sym
->hash_value
= gfc_hash_value (sym
);
10288 /* Take over the ABSTRACT attribute. */
10289 sym
->attr
.abstract
= attr
.abstract
;
10291 gfc_new_block
= sym
;
10297 /* Cray Pointees can be declared as:
10298 pointer (ipt, a (n,m,...,*)) */
10301 gfc_mod_pointee_as (gfc_array_spec
*as
)
10303 as
->cray_pointee
= true; /* This will be useful to know later. */
10304 if (as
->type
== AS_ASSUMED_SIZE
)
10305 as
->cp_was_assumed
= true;
10306 else if (as
->type
== AS_ASSUMED_SHAPE
)
10308 gfc_error ("Cray Pointee at %C cannot be assumed shape array");
10309 return MATCH_ERROR
;
10315 /* Match the enum definition statement, here we are trying to match
10316 the first line of enum definition statement.
10317 Returns MATCH_YES if match is found. */
10320 gfc_match_enum (void)
10324 m
= gfc_match_eos ();
10325 if (m
!= MATCH_YES
)
10328 if (!gfc_notify_std (GFC_STD_F2003
, "ENUM and ENUMERATOR at %C"))
10329 return MATCH_ERROR
;
10335 /* Returns an initializer whose value is one higher than the value of the
10336 LAST_INITIALIZER argument. If the argument is NULL, the
10337 initializers value will be set to zero. The initializer's kind
10338 will be set to gfc_c_int_kind.
10340 If -fshort-enums is given, the appropriate kind will be selected
10341 later after all enumerators have been parsed. A warning is issued
10342 here if an initializer exceeds gfc_c_int_kind. */
10345 enum_initializer (gfc_expr
*last_initializer
, locus where
)
10348 result
= gfc_get_constant_expr (BT_INTEGER
, gfc_c_int_kind
, &where
);
10350 mpz_init (result
->value
.integer
);
10352 if (last_initializer
!= NULL
)
10354 mpz_add_ui (result
->value
.integer
, last_initializer
->value
.integer
, 1);
10355 result
->where
= last_initializer
->where
;
10357 if (gfc_check_integer_range (result
->value
.integer
,
10358 gfc_c_int_kind
) != ARITH_OK
)
10360 gfc_error ("Enumerator exceeds the C integer type at %C");
10366 /* Control comes here, if it's the very first enumerator and no
10367 initializer has been given. It will be initialized to zero. */
10368 mpz_set_si (result
->value
.integer
, 0);
10375 /* Match a variable name with an optional initializer. When this
10376 subroutine is called, a variable is expected to be parsed next.
10377 Depending on what is happening at the moment, updates either the
10378 symbol table or the current interface. */
10381 enumerator_decl (void)
10383 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
10384 gfc_expr
*initializer
;
10385 gfc_array_spec
*as
= NULL
;
10392 initializer
= NULL
;
10393 old_locus
= gfc_current_locus
;
10395 /* When we get here, we've just matched a list of attributes and
10396 maybe a type and a double colon. The next thing we expect to see
10397 is the name of the symbol. */
10398 m
= gfc_match_name (name
);
10399 if (m
!= MATCH_YES
)
10402 var_locus
= gfc_current_locus
;
10404 /* OK, we've successfully matched the declaration. Now put the
10405 symbol in the current namespace. If we fail to create the symbol,
10407 if (!build_sym (name
, NULL
, false, &as
, &var_locus
))
10413 /* The double colon must be present in order to have initializers.
10414 Otherwise the statement is ambiguous with an assignment statement. */
10417 if (gfc_match_char ('=') == MATCH_YES
)
10419 m
= gfc_match_init_expr (&initializer
);
10422 gfc_error ("Expected an initialization expression at %C");
10426 if (m
!= MATCH_YES
)
10431 /* If we do not have an initializer, the initialization value of the
10432 previous enumerator (stored in last_initializer) is incremented
10433 by 1 and is used to initialize the current enumerator. */
10434 if (initializer
== NULL
)
10435 initializer
= enum_initializer (last_initializer
, old_locus
);
10437 if (initializer
== NULL
|| initializer
->ts
.type
!= BT_INTEGER
)
10439 gfc_error ("ENUMERATOR %L not initialized with integer expression",
10445 /* Store this current initializer, for the next enumerator variable
10446 to be parsed. add_init_expr_to_sym() zeros initializer, so we
10447 use last_initializer below. */
10448 last_initializer
= initializer
;
10449 t
= add_init_expr_to_sym (name
, &initializer
, &var_locus
);
10451 /* Maintain enumerator history. */
10452 gfc_find_symbol (name
, NULL
, 0, &sym
);
10453 create_enum_history (sym
, last_initializer
);
10455 return (t
) ? MATCH_YES
: MATCH_ERROR
;
10458 /* Free stuff up and return. */
10459 gfc_free_expr (initializer
);
10465 /* Match the enumerator definition statement. */
10468 gfc_match_enumerator_def (void)
10473 gfc_clear_ts (¤t_ts
);
10475 m
= gfc_match (" enumerator");
10476 if (m
!= MATCH_YES
)
10479 m
= gfc_match (" :: ");
10480 if (m
== MATCH_ERROR
)
10483 colon_seen
= (m
== MATCH_YES
);
10485 if (gfc_current_state () != COMP_ENUM
)
10487 gfc_error ("ENUM definition statement expected before %C");
10488 gfc_free_enum_history ();
10489 return MATCH_ERROR
;
10492 (¤t_ts
)->type
= BT_INTEGER
;
10493 (¤t_ts
)->kind
= gfc_c_int_kind
;
10495 gfc_clear_attr (¤t_attr
);
10496 t
= gfc_add_flavor (¤t_attr
, FL_PARAMETER
, NULL
, NULL
);
10505 m
= enumerator_decl ();
10506 if (m
== MATCH_ERROR
)
10508 gfc_free_enum_history ();
10514 if (gfc_match_eos () == MATCH_YES
)
10516 if (gfc_match_char (',') != MATCH_YES
)
10520 if (gfc_current_state () == COMP_ENUM
)
10522 gfc_free_enum_history ();
10523 gfc_error ("Syntax error in ENUMERATOR definition at %C");
10528 gfc_free_array_spec (current_as
);
10535 /* Match binding attributes. */
10538 match_binding_attributes (gfc_typebound_proc
* ba
, bool generic
, bool ppc
)
10540 bool found_passing
= false;
10541 bool seen_ptr
= false;
10542 match m
= MATCH_YES
;
10544 /* Initialize to defaults. Do so even before the MATCH_NO check so that in
10545 this case the defaults are in there. */
10546 ba
->access
= ACCESS_UNKNOWN
;
10547 ba
->pass_arg
= NULL
;
10548 ba
->pass_arg_num
= 0;
10550 ba
->non_overridable
= 0;
10554 /* If we find a comma, we believe there are binding attributes. */
10555 m
= gfc_match_char (',');
10561 /* Access specifier. */
10563 m
= gfc_match (" public");
10564 if (m
== MATCH_ERROR
)
10566 if (m
== MATCH_YES
)
10568 if (ba
->access
!= ACCESS_UNKNOWN
)
10570 gfc_error ("Duplicate access-specifier at %C");
10574 ba
->access
= ACCESS_PUBLIC
;
10578 m
= gfc_match (" private");
10579 if (m
== MATCH_ERROR
)
10581 if (m
== MATCH_YES
)
10583 if (ba
->access
!= ACCESS_UNKNOWN
)
10585 gfc_error ("Duplicate access-specifier at %C");
10589 ba
->access
= ACCESS_PRIVATE
;
10593 /* If inside GENERIC, the following is not allowed. */
10598 m
= gfc_match (" nopass");
10599 if (m
== MATCH_ERROR
)
10601 if (m
== MATCH_YES
)
10605 gfc_error ("Binding attributes already specify passing,"
10606 " illegal NOPASS at %C");
10610 found_passing
= true;
10615 /* PASS possibly including argument. */
10616 m
= gfc_match (" pass");
10617 if (m
== MATCH_ERROR
)
10619 if (m
== MATCH_YES
)
10621 char arg
[GFC_MAX_SYMBOL_LEN
+ 1];
10625 gfc_error ("Binding attributes already specify passing,"
10626 " illegal PASS at %C");
10630 m
= gfc_match (" ( %n )", arg
);
10631 if (m
== MATCH_ERROR
)
10633 if (m
== MATCH_YES
)
10634 ba
->pass_arg
= gfc_get_string ("%s", arg
);
10635 gcc_assert ((m
== MATCH_YES
) == (ba
->pass_arg
!= NULL
));
10637 found_passing
= true;
10644 /* POINTER flag. */
10645 m
= gfc_match (" pointer");
10646 if (m
== MATCH_ERROR
)
10648 if (m
== MATCH_YES
)
10652 gfc_error ("Duplicate POINTER attribute at %C");
10662 /* NON_OVERRIDABLE flag. */
10663 m
= gfc_match (" non_overridable");
10664 if (m
== MATCH_ERROR
)
10666 if (m
== MATCH_YES
)
10668 if (ba
->non_overridable
)
10670 gfc_error ("Duplicate NON_OVERRIDABLE at %C");
10674 ba
->non_overridable
= 1;
10678 /* DEFERRED flag. */
10679 m
= gfc_match (" deferred");
10680 if (m
== MATCH_ERROR
)
10682 if (m
== MATCH_YES
)
10686 gfc_error ("Duplicate DEFERRED at %C");
10697 /* Nothing matching found. */
10699 gfc_error ("Expected access-specifier at %C");
10701 gfc_error ("Expected binding attribute at %C");
10704 while (gfc_match_char (',') == MATCH_YES
);
10706 /* NON_OVERRIDABLE and DEFERRED exclude themselves. */
10707 if (ba
->non_overridable
&& ba
->deferred
)
10709 gfc_error ("NON_OVERRIDABLE and DEFERRED can't both appear at %C");
10716 if (ba
->access
== ACCESS_UNKNOWN
)
10717 ba
->access
= ppc
? gfc_current_block()->component_access
10718 : gfc_typebound_default_access
;
10720 if (ppc
&& !seen_ptr
)
10722 gfc_error ("POINTER attribute is required for procedure pointer component"
10730 return MATCH_ERROR
;
10734 /* Match a PROCEDURE specific binding inside a derived type. */
10737 match_procedure_in_type (void)
10739 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
10740 char target_buf
[GFC_MAX_SYMBOL_LEN
+ 1];
10741 char* target
= NULL
, *ifc
= NULL
;
10742 gfc_typebound_proc tb
;
10746 gfc_symtree
* stree
;
10751 /* Check current state. */
10752 gcc_assert (gfc_state_stack
->state
== COMP_DERIVED_CONTAINS
);
10753 block
= gfc_state_stack
->previous
->sym
;
10754 gcc_assert (block
);
10756 /* Try to match PROCEDURE(interface). */
10757 if (gfc_match (" (") == MATCH_YES
)
10759 m
= gfc_match_name (target_buf
);
10760 if (m
== MATCH_ERROR
)
10762 if (m
!= MATCH_YES
)
10764 gfc_error ("Interface-name expected after %<(%> at %C");
10765 return MATCH_ERROR
;
10768 if (gfc_match (" )") != MATCH_YES
)
10770 gfc_error ("%<)%> expected at %C");
10771 return MATCH_ERROR
;
10777 /* Construct the data structure. */
10778 memset (&tb
, 0, sizeof (tb
));
10779 tb
.where
= gfc_current_locus
;
10781 /* Match binding attributes. */
10782 m
= match_binding_attributes (&tb
, false, false);
10783 if (m
== MATCH_ERROR
)
10785 seen_attrs
= (m
== MATCH_YES
);
10787 /* Check that attribute DEFERRED is given if an interface is specified. */
10788 if (tb
.deferred
&& !ifc
)
10790 gfc_error ("Interface must be specified for DEFERRED binding at %C");
10791 return MATCH_ERROR
;
10793 if (ifc
&& !tb
.deferred
)
10795 gfc_error ("PROCEDURE(interface) at %C should be declared DEFERRED");
10796 return MATCH_ERROR
;
10799 /* Match the colons. */
10800 m
= gfc_match (" ::");
10801 if (m
== MATCH_ERROR
)
10803 seen_colons
= (m
== MATCH_YES
);
10804 if (seen_attrs
&& !seen_colons
)
10806 gfc_error ("Expected %<::%> after binding-attributes at %C");
10807 return MATCH_ERROR
;
10810 /* Match the binding names. */
10813 m
= gfc_match_name (name
);
10814 if (m
== MATCH_ERROR
)
10818 gfc_error ("Expected binding name at %C");
10819 return MATCH_ERROR
;
10822 if (num
>1 && !gfc_notify_std (GFC_STD_F2008
, "PROCEDURE list at %C"))
10823 return MATCH_ERROR
;
10825 /* Try to match the '=> target', if it's there. */
10827 m
= gfc_match (" =>");
10828 if (m
== MATCH_ERROR
)
10830 if (m
== MATCH_YES
)
10834 gfc_error ("%<=> target%> is invalid for DEFERRED binding at %C");
10835 return MATCH_ERROR
;
10840 gfc_error ("%<::%> needed in PROCEDURE binding with explicit target"
10842 return MATCH_ERROR
;
10845 m
= gfc_match_name (target_buf
);
10846 if (m
== MATCH_ERROR
)
10850 gfc_error ("Expected binding target after %<=>%> at %C");
10851 return MATCH_ERROR
;
10853 target
= target_buf
;
10856 /* If no target was found, it has the same name as the binding. */
10860 /* Get the namespace to insert the symbols into. */
10861 ns
= block
->f2k_derived
;
10864 /* If the binding is DEFERRED, check that the containing type is ABSTRACT. */
10865 if (tb
.deferred
&& !block
->attr
.abstract
)
10867 gfc_error ("Type %qs containing DEFERRED binding at %C "
10868 "is not ABSTRACT", block
->name
);
10869 return MATCH_ERROR
;
10872 /* See if we already have a binding with this name in the symtree which
10873 would be an error. If a GENERIC already targeted this binding, it may
10874 be already there but then typebound is still NULL. */
10875 stree
= gfc_find_symtree (ns
->tb_sym_root
, name
);
10876 if (stree
&& stree
->n
.tb
)
10878 gfc_error ("There is already a procedure with binding name %qs for "
10879 "the derived type %qs at %C", name
, block
->name
);
10880 return MATCH_ERROR
;
10883 /* Insert it and set attributes. */
10887 stree
= gfc_new_symtree (&ns
->tb_sym_root
, name
);
10888 gcc_assert (stree
);
10890 stree
->n
.tb
= gfc_get_typebound_proc (&tb
);
10892 if (gfc_get_sym_tree (target
, gfc_current_ns
, &stree
->n
.tb
->u
.specific
,
10894 return MATCH_ERROR
;
10895 gfc_set_sym_referenced (stree
->n
.tb
->u
.specific
->n
.sym
);
10896 gfc_add_flavor(&stree
->n
.tb
->u
.specific
->n
.sym
->attr
, FL_PROCEDURE
,
10897 target
, &stree
->n
.tb
->u
.specific
->n
.sym
->declared_at
);
10899 if (gfc_match_eos () == MATCH_YES
)
10901 if (gfc_match_char (',') != MATCH_YES
)
10906 gfc_error ("Syntax error in PROCEDURE statement at %C");
10907 return MATCH_ERROR
;
10911 /* Match a GENERIC procedure binding inside a derived type. */
10914 gfc_match_generic (void)
10916 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
10917 char bind_name
[GFC_MAX_SYMBOL_LEN
+ 16]; /* Allow space for OPERATOR(...). */
10919 gfc_typebound_proc tbattr
; /* Used for match_binding_attributes. */
10920 gfc_typebound_proc
* tb
;
10922 interface_type op_type
;
10923 gfc_intrinsic_op op
;
10926 /* Check current state. */
10927 if (gfc_current_state () == COMP_DERIVED
)
10929 gfc_error ("GENERIC at %C must be inside a derived-type CONTAINS");
10930 return MATCH_ERROR
;
10932 if (gfc_current_state () != COMP_DERIVED_CONTAINS
)
10934 block
= gfc_state_stack
->previous
->sym
;
10935 ns
= block
->f2k_derived
;
10936 gcc_assert (block
&& ns
);
10938 memset (&tbattr
, 0, sizeof (tbattr
));
10939 tbattr
.where
= gfc_current_locus
;
10941 /* See if we get an access-specifier. */
10942 m
= match_binding_attributes (&tbattr
, true, false);
10943 if (m
== MATCH_ERROR
)
10946 /* Now the colons, those are required. */
10947 if (gfc_match (" ::") != MATCH_YES
)
10949 gfc_error ("Expected %<::%> at %C");
10953 /* Match the binding name; depending on type (operator / generic) format
10954 it for future error messages into bind_name. */
10956 m
= gfc_match_generic_spec (&op_type
, name
, &op
);
10957 if (m
== MATCH_ERROR
)
10958 return MATCH_ERROR
;
10961 gfc_error ("Expected generic name or operator descriptor at %C");
10967 case INTERFACE_GENERIC
:
10968 case INTERFACE_DTIO
:
10969 snprintf (bind_name
, sizeof (bind_name
), "%s", name
);
10972 case INTERFACE_USER_OP
:
10973 snprintf (bind_name
, sizeof (bind_name
), "OPERATOR(.%s.)", name
);
10976 case INTERFACE_INTRINSIC_OP
:
10977 snprintf (bind_name
, sizeof (bind_name
), "OPERATOR(%s)",
10978 gfc_op2string (op
));
10981 case INTERFACE_NAMELESS
:
10982 gfc_error ("Malformed GENERIC statement at %C");
10987 gcc_unreachable ();
10990 /* Match the required =>. */
10991 if (gfc_match (" =>") != MATCH_YES
)
10993 gfc_error ("Expected %<=>%> at %C");
10997 /* Try to find existing GENERIC binding with this name / for this operator;
10998 if there is something, check that it is another GENERIC and then extend
10999 it rather than building a new node. Otherwise, create it and put it
11000 at the right position. */
11004 case INTERFACE_DTIO
:
11005 case INTERFACE_USER_OP
:
11006 case INTERFACE_GENERIC
:
11008 const bool is_op
= (op_type
== INTERFACE_USER_OP
);
11011 st
= gfc_find_symtree (is_op
? ns
->tb_uop_root
: ns
->tb_sym_root
, name
);
11012 tb
= st
? st
->n
.tb
: NULL
;
11016 case INTERFACE_INTRINSIC_OP
:
11017 tb
= ns
->tb_op
[op
];
11021 gcc_unreachable ();
11026 if (!tb
->is_generic
)
11028 gcc_assert (op_type
== INTERFACE_GENERIC
);
11029 gfc_error ("There's already a non-generic procedure with binding name"
11030 " %qs for the derived type %qs at %C",
11031 bind_name
, block
->name
);
11035 if (tb
->access
!= tbattr
.access
)
11037 gfc_error ("Binding at %C must have the same access as already"
11038 " defined binding %qs", bind_name
);
11044 tb
= gfc_get_typebound_proc (NULL
);
11045 tb
->where
= gfc_current_locus
;
11046 tb
->access
= tbattr
.access
;
11047 tb
->is_generic
= 1;
11048 tb
->u
.generic
= NULL
;
11052 case INTERFACE_DTIO
:
11053 case INTERFACE_GENERIC
:
11054 case INTERFACE_USER_OP
:
11056 const bool is_op
= (op_type
== INTERFACE_USER_OP
);
11057 gfc_symtree
* st
= gfc_get_tbp_symtree (is_op
? &ns
->tb_uop_root
:
11058 &ns
->tb_sym_root
, name
);
11065 case INTERFACE_INTRINSIC_OP
:
11066 ns
->tb_op
[op
] = tb
;
11070 gcc_unreachable ();
11074 /* Now, match all following names as specific targets. */
11077 gfc_symtree
* target_st
;
11078 gfc_tbp_generic
* target
;
11080 m
= gfc_match_name (name
);
11081 if (m
== MATCH_ERROR
)
11085 gfc_error ("Expected specific binding name at %C");
11089 target_st
= gfc_get_tbp_symtree (&ns
->tb_sym_root
, name
);
11091 /* See if this is a duplicate specification. */
11092 for (target
= tb
->u
.generic
; target
; target
= target
->next
)
11093 if (target_st
== target
->specific_st
)
11095 gfc_error ("%qs already defined as specific binding for the"
11096 " generic %qs at %C", name
, bind_name
);
11100 target
= gfc_get_tbp_generic ();
11101 target
->specific_st
= target_st
;
11102 target
->specific
= NULL
;
11103 target
->next
= tb
->u
.generic
;
11104 target
->is_operator
= ((op_type
== INTERFACE_USER_OP
)
11105 || (op_type
== INTERFACE_INTRINSIC_OP
));
11106 tb
->u
.generic
= target
;
11108 while (gfc_match (" ,") == MATCH_YES
);
11110 /* Here should be the end. */
11111 if (gfc_match_eos () != MATCH_YES
)
11113 gfc_error ("Junk after GENERIC binding at %C");
11120 return MATCH_ERROR
;
11124 /* Match a FINAL declaration inside a derived type. */
11127 gfc_match_final_decl (void)
11129 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
11132 gfc_namespace
* module_ns
;
11136 if (gfc_current_form
== FORM_FREE
)
11138 char c
= gfc_peek_ascii_char ();
11139 if (!gfc_is_whitespace (c
) && c
!= ':')
11143 if (gfc_state_stack
->state
!= COMP_DERIVED_CONTAINS
)
11145 if (gfc_current_form
== FORM_FIXED
)
11148 gfc_error ("FINAL declaration at %C must be inside a derived type "
11149 "CONTAINS section");
11150 return MATCH_ERROR
;
11153 block
= gfc_state_stack
->previous
->sym
;
11154 gcc_assert (block
);
11156 if (!gfc_state_stack
->previous
|| !gfc_state_stack
->previous
->previous
11157 || gfc_state_stack
->previous
->previous
->state
!= COMP_MODULE
)
11159 gfc_error ("Derived type declaration with FINAL at %C must be in the"
11160 " specification part of a MODULE");
11161 return MATCH_ERROR
;
11164 module_ns
= gfc_current_ns
;
11165 gcc_assert (module_ns
);
11166 gcc_assert (module_ns
->proc_name
->attr
.flavor
== FL_MODULE
);
11168 /* Match optional ::, don't care about MATCH_YES or MATCH_NO. */
11169 if (gfc_match (" ::") == MATCH_ERROR
)
11170 return MATCH_ERROR
;
11172 /* Match the sequence of procedure names. */
11179 if (first
&& gfc_match_eos () == MATCH_YES
)
11181 gfc_error ("Empty FINAL at %C");
11182 return MATCH_ERROR
;
11185 m
= gfc_match_name (name
);
11188 gfc_error ("Expected module procedure name at %C");
11189 return MATCH_ERROR
;
11191 else if (m
!= MATCH_YES
)
11192 return MATCH_ERROR
;
11194 if (gfc_match_eos () == MATCH_YES
)
11196 if (!last
&& gfc_match_char (',') != MATCH_YES
)
11198 gfc_error ("Expected %<,%> at %C");
11199 return MATCH_ERROR
;
11202 if (gfc_get_symbol (name
, module_ns
, &sym
))
11204 gfc_error ("Unknown procedure name %qs at %C", name
);
11205 return MATCH_ERROR
;
11208 /* Mark the symbol as module procedure. */
11209 if (sym
->attr
.proc
!= PROC_MODULE
11210 && !gfc_add_procedure (&sym
->attr
, PROC_MODULE
, sym
->name
, NULL
))
11211 return MATCH_ERROR
;
11213 /* Check if we already have this symbol in the list, this is an error. */
11214 for (f
= block
->f2k_derived
->finalizers
; f
; f
= f
->next
)
11215 if (f
->proc_sym
== sym
)
11217 gfc_error ("%qs at %C is already defined as FINAL procedure",
11219 return MATCH_ERROR
;
11222 /* Add this symbol to the list of finalizers. */
11223 gcc_assert (block
->f2k_derived
);
11225 f
= XCNEW (gfc_finalizer
);
11227 f
->proc_tree
= NULL
;
11228 f
->where
= gfc_current_locus
;
11229 f
->next
= block
->f2k_derived
->finalizers
;
11230 block
->f2k_derived
->finalizers
= f
;
11240 const ext_attr_t ext_attr_list
[] = {
11241 { "dllimport", EXT_ATTR_DLLIMPORT
, "dllimport" },
11242 { "dllexport", EXT_ATTR_DLLEXPORT
, "dllexport" },
11243 { "cdecl", EXT_ATTR_CDECL
, "cdecl" },
11244 { "stdcall", EXT_ATTR_STDCALL
, "stdcall" },
11245 { "fastcall", EXT_ATTR_FASTCALL
, "fastcall" },
11246 { "no_arg_check", EXT_ATTR_NO_ARG_CHECK
, NULL
},
11247 { NULL
, EXT_ATTR_LAST
, NULL
}
11250 /* Match a !GCC$ ATTRIBUTES statement of the form:
11251 !GCC$ ATTRIBUTES attribute-list :: var-name [, var-name] ...
11252 When we come here, we have already matched the !GCC$ ATTRIBUTES string.
11254 TODO: We should support all GCC attributes using the same syntax for
11255 the attribute list, i.e. the list in C
11256 __attributes(( attribute-list ))
11258 !GCC$ ATTRIBUTES attribute-list ::
11259 Cf. c-parser.c's c_parser_attributes; the data can then directly be
11262 As there is absolutely no risk of confusion, we should never return
11265 gfc_match_gcc_attributes (void)
11267 symbol_attribute attr
;
11268 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
11273 gfc_clear_attr (&attr
);
11278 if (gfc_match_name (name
) != MATCH_YES
)
11279 return MATCH_ERROR
;
11281 for (id
= 0; id
< EXT_ATTR_LAST
; id
++)
11282 if (strcmp (name
, ext_attr_list
[id
].name
) == 0)
11285 if (id
== EXT_ATTR_LAST
)
11287 gfc_error ("Unknown attribute in !GCC$ ATTRIBUTES statement at %C");
11288 return MATCH_ERROR
;
11291 if (!gfc_add_ext_attribute (&attr
, (ext_attr_id_t
)id
, &gfc_current_locus
))
11292 return MATCH_ERROR
;
11294 gfc_gobble_whitespace ();
11295 ch
= gfc_next_ascii_char ();
11298 /* This is the successful exit condition for the loop. */
11299 if (gfc_next_ascii_char () == ':')
11309 if (gfc_match_eos () == MATCH_YES
)
11314 m
= gfc_match_name (name
);
11315 if (m
!= MATCH_YES
)
11318 if (find_special (name
, &sym
, true))
11319 return MATCH_ERROR
;
11321 sym
->attr
.ext_attr
|= attr
.ext_attr
;
11323 if (gfc_match_eos () == MATCH_YES
)
11326 if (gfc_match_char (',') != MATCH_YES
)
11333 gfc_error ("Syntax error in !GCC$ ATTRIBUTES statement at %C");
11334 return MATCH_ERROR
;
11338 /* Match a !GCC$ UNROLL statement of the form:
11341 The parameter n is the number of times we are supposed to unroll.
11343 When we come here, we have already matched the !GCC$ UNROLL string. */
11345 gfc_match_gcc_unroll (void)
11349 if (gfc_match_small_int (&value
) == MATCH_YES
)
11351 if (value
< 0 || value
> USHRT_MAX
)
11353 gfc_error ("%<GCC unroll%> directive requires a"
11354 " non-negative integral constant"
11355 " less than or equal to %u at %C",
11358 return MATCH_ERROR
;
11360 if (gfc_match_eos () == MATCH_YES
)
11362 directive_unroll
= value
== 0 ? 1 : value
;
11367 gfc_error ("Syntax error in !GCC$ UNROLL directive at %C");
11368 return MATCH_ERROR
;
11371 /* Match a !GCC$ builtin (b) attributes simd flags if('target') form:
11373 The parameter b is name of a middle-end built-in.
11374 FLAGS is optional and must be one of:
11378 IF('target') is optional and TARGET is a name of a multilib ABI.
11380 When we come here, we have already matched the !GCC$ builtin string. */
11383 gfc_match_gcc_builtin (void)
11385 char builtin
[GFC_MAX_SYMBOL_LEN
+ 1];
11386 char target
[GFC_MAX_SYMBOL_LEN
+ 1];
11388 if (gfc_match (" ( %n ) attributes simd", builtin
) != MATCH_YES
)
11389 return MATCH_ERROR
;
11391 gfc_simd_clause clause
= SIMD_NONE
;
11392 if (gfc_match (" ( notinbranch ) ") == MATCH_YES
)
11393 clause
= SIMD_NOTINBRANCH
;
11394 else if (gfc_match (" ( inbranch ) ") == MATCH_YES
)
11395 clause
= SIMD_INBRANCH
;
11397 if (gfc_match (" if ( '%n' ) ", target
) == MATCH_YES
)
11399 const char *abi
= targetm
.get_multilib_abi_name ();
11400 if (abi
== NULL
|| strcmp (abi
, target
) != 0)
11404 if (gfc_vectorized_builtins
== NULL
)
11405 gfc_vectorized_builtins
= new hash_map
<nofree_string_hash
, int> ();
11407 char *r
= XNEWVEC (char, strlen (builtin
) + 32);
11408 sprintf (r
, "__builtin_%s", builtin
);
11411 int &value
= gfc_vectorized_builtins
->get_or_insert (r
, &existed
);