Branch data Line data Source code
1 : : /* Declaration statement matcher
2 : : Copyright (C) 2002-2025 Free Software Foundation, Inc.
3 : : Contributed by Andy Vaught
4 : :
5 : : This file is part of GCC.
6 : :
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
10 : : version.
11 : :
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
15 : : for more details.
16 : :
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/>. */
20 : :
21 : : #include "config.h"
22 : : #include "system.h"
23 : : #include "coretypes.h"
24 : : #include "options.h"
25 : : #include "tree.h"
26 : : #include "gfortran.h"
27 : : #include "stringpool.h"
28 : : #include "match.h"
29 : : #include "parse.h"
30 : : #include "constructor.h"
31 : : #include "target.h"
32 : :
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)
38 : :
39 : :
40 : : static bool set_binding_label (const char **, const char *, int);
41 : :
42 : :
43 : : /* This flag is set if an old-style length selector is matched
44 : : during a type-declaration statement. */
45 : :
46 : : static int old_char_selector;
47 : :
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. */
52 : :
53 : : static gfc_typespec current_ts;
54 : :
55 : : static symbol_attribute current_attr;
56 : : static gfc_array_spec *current_as;
57 : : static int colon_seen;
58 : : static int attr_seen;
59 : :
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;
68 : :
69 : : /* Initializer of the previous enumerator. */
70 : :
71 : : static gfc_expr *last_initializer;
72 : :
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. */
76 : :
77 : : typedef struct enumerator_history
78 : : {
79 : : gfc_symbol *sym;
80 : : gfc_expr *initializer;
81 : : struct enumerator_history *next;
82 : : }
83 : : enumerator_history;
84 : :
85 : : /* Header of enum history chain. */
86 : :
87 : : static enumerator_history *enum_history = NULL;
88 : :
89 : : /* Pointer of enum history node containing largest initializer. */
90 : :
91 : : static enumerator_history *max_enum = NULL;
92 : :
93 : : /* gfc_new_block points to the symbol of a newly matched block. */
94 : :
95 : : gfc_symbol *gfc_new_block;
96 : :
97 : : bool gfc_matching_function;
98 : :
99 : : /* Set upon parsing a !GCC$ unroll n directive for use in the next loop. */
100 : : int directive_unroll = -1;
101 : :
102 : : /* Set upon parsing supported !GCC$ pragmas for use in the next loop. */
103 : : bool directive_ivdep = false;
104 : : bool directive_vector = false;
105 : : bool directive_novector = false;
106 : :
107 : : /* Map of middle-end built-ins that should be vectorized. */
108 : : hash_map<nofree_string_hash, int> *gfc_vectorized_builtins;
109 : :
110 : : /* If a kind expression of a component of a parameterized derived type is
111 : : parameterized, temporarily store the expression here. */
112 : : static gfc_expr *saved_kind_expr = NULL;
113 : :
114 : : /* Used to store the parameter list arising in a PDT declaration and
115 : : in the typespec of a PDT variable or component. */
116 : : static gfc_actual_arglist *decl_type_param_list;
117 : : static gfc_actual_arglist *type_param_spec_list;
118 : :
119 : : /********************* DATA statement subroutines *********************/
120 : :
121 : : static bool in_match_data = false;
122 : :
123 : : bool
124 : 8061 : gfc_in_match_data (void)
125 : : {
126 : 8061 : return in_match_data;
127 : : }
128 : :
129 : : static void
130 : 4798 : set_in_match_data (bool set_value)
131 : : {
132 : 4798 : in_match_data = set_value;
133 : 2399 : }
134 : :
135 : : /* Free a gfc_data_variable structure and everything beneath it. */
136 : :
137 : : static void
138 : 5620 : free_variable (gfc_data_variable *p)
139 : : {
140 : 5620 : gfc_data_variable *q;
141 : :
142 : 8687 : for (; p; p = q)
143 : : {
144 : 3067 : q = p->next;
145 : 3067 : gfc_free_expr (p->expr);
146 : 3067 : gfc_free_iterator (&p->iter, 0);
147 : 3067 : free_variable (p->list);
148 : 3067 : free (p);
149 : : }
150 : 5620 : }
151 : :
152 : :
153 : : /* Free a gfc_data_value structure and everything beneath it. */
154 : :
155 : : static void
156 : 2553 : free_value (gfc_data_value *p)
157 : : {
158 : 2553 : gfc_data_value *q;
159 : :
160 : 10839 : for (; p; p = q)
161 : : {
162 : 8286 : q = p->next;
163 : 8286 : mpz_clear (p->repeat);
164 : 8286 : gfc_free_expr (p->expr);
165 : 8286 : free (p);
166 : : }
167 : 2553 : }
168 : :
169 : :
170 : : /* Free a list of gfc_data structures. */
171 : :
172 : : void
173 : 492936 : gfc_free_data (gfc_data *p)
174 : : {
175 : 492936 : gfc_data *q;
176 : :
177 : 495489 : for (; p; p = q)
178 : : {
179 : 2553 : q = p->next;
180 : 2553 : free_variable (p->var);
181 : 2553 : free_value (p->value);
182 : 2553 : free (p);
183 : : }
184 : 492936 : }
185 : :
186 : :
187 : : /* Free all data in a namespace. */
188 : :
189 : : static void
190 : 38 : gfc_free_data_all (gfc_namespace *ns)
191 : : {
192 : 38 : gfc_data *d;
193 : :
194 : 44 : for (;ns->data;)
195 : : {
196 : 6 : d = ns->data->next;
197 : 6 : free (ns->data);
198 : 6 : ns->data = d;
199 : : }
200 : 38 : }
201 : :
202 : : /* Reject data parsed since the last restore point was marked. */
203 : :
204 : : void
205 : 8094581 : gfc_reject_data (gfc_namespace *ns)
206 : : {
207 : 8094581 : gfc_data *d;
208 : :
209 : 8094583 : while (ns->data && ns->data != ns->old_data)
210 : : {
211 : 2 : d = ns->data->next;
212 : 2 : free (ns->data);
213 : 2 : ns->data = d;
214 : : }
215 : 8094581 : }
216 : :
217 : : static match var_element (gfc_data_variable *);
218 : :
219 : : /* Match a list of variables terminated by an iterator and a right
220 : : parenthesis. */
221 : :
222 : : static match
223 : 153 : var_list (gfc_data_variable *parent)
224 : : {
225 : 153 : gfc_data_variable *tail, var;
226 : 153 : match m;
227 : :
228 : 153 : m = var_element (&var);
229 : 153 : if (m == MATCH_ERROR)
230 : : return MATCH_ERROR;
231 : 153 : if (m == MATCH_NO)
232 : 0 : goto syntax;
233 : :
234 : 153 : tail = gfc_get_data_variable ();
235 : 153 : *tail = var;
236 : :
237 : 153 : parent->list = tail;
238 : :
239 : 155 : for (;;)
240 : : {
241 : 154 : if (gfc_match_char (',') != MATCH_YES)
242 : 0 : goto syntax;
243 : :
244 : 154 : m = gfc_match_iterator (&parent->iter, 1);
245 : 154 : if (m == MATCH_YES)
246 : : break;
247 : 1 : if (m == MATCH_ERROR)
248 : : return MATCH_ERROR;
249 : :
250 : 1 : m = var_element (&var);
251 : 1 : if (m == MATCH_ERROR)
252 : : return MATCH_ERROR;
253 : 1 : if (m == MATCH_NO)
254 : 0 : goto syntax;
255 : :
256 : 1 : tail->next = gfc_get_data_variable ();
257 : 1 : tail = tail->next;
258 : :
259 : 1 : *tail = var;
260 : : }
261 : :
262 : 153 : if (gfc_match_char (')') != MATCH_YES)
263 : 0 : goto syntax;
264 : : return MATCH_YES;
265 : :
266 : 0 : syntax:
267 : 0 : gfc_syntax_error (ST_DATA);
268 : 0 : return MATCH_ERROR;
269 : : }
270 : :
271 : :
272 : : /* Match a single element in a data variable list, which can be a
273 : : variable-iterator list. */
274 : :
275 : : static match
276 : 3025 : var_element (gfc_data_variable *new_var)
277 : : {
278 : 3025 : match m;
279 : 3025 : gfc_symbol *sym;
280 : :
281 : 3025 : memset (new_var, 0, sizeof (gfc_data_variable));
282 : :
283 : 3025 : if (gfc_match_char ('(') == MATCH_YES)
284 : 153 : return var_list (new_var);
285 : :
286 : 2872 : m = gfc_match_variable (&new_var->expr, 0);
287 : 2872 : if (m != MATCH_YES)
288 : : return m;
289 : :
290 : 2868 : if (new_var->expr->expr_type == EXPR_CONSTANT
291 : 2 : && new_var->expr->symtree == NULL)
292 : : {
293 : 2 : gfc_error ("Inquiry parameter cannot appear in a "
294 : : "data-stmt-object-list at %C");
295 : 2 : return MATCH_ERROR;
296 : : }
297 : :
298 : 2866 : sym = new_var->expr->symtree->n.sym;
299 : :
300 : : /* Symbol should already have an associated type. */
301 : 2866 : if (!gfc_check_symbol_typed (sym, gfc_current_ns, false, gfc_current_locus))
302 : : return MATCH_ERROR;
303 : :
304 : 2865 : if (!sym->attr.function && gfc_current_ns->parent
305 : 148 : && gfc_current_ns->parent == sym->ns)
306 : : {
307 : 1 : gfc_error ("Host associated variable %qs may not be in the DATA "
308 : : "statement at %C", sym->name);
309 : 1 : return MATCH_ERROR;
310 : : }
311 : :
312 : 2864 : if (gfc_current_state () != COMP_BLOCK_DATA
313 : 2728 : && sym->attr.in_common
314 : 2893 : && !gfc_notify_std (GFC_STD_GNU, "initialization of "
315 : : "common block variable %qs in DATA statement at %C",
316 : : sym->name))
317 : : return MATCH_ERROR;
318 : :
319 : 2862 : if (!gfc_add_data (&sym->attr, sym->name, &new_var->expr->where))
320 : : return MATCH_ERROR;
321 : :
322 : : return MATCH_YES;
323 : : }
324 : :
325 : :
326 : : /* Match the top-level list of data variables. */
327 : :
328 : : static match
329 : 2496 : top_var_list (gfc_data *d)
330 : : {
331 : 2496 : gfc_data_variable var, *tail, *new_var;
332 : 2496 : match m;
333 : :
334 : 2496 : tail = NULL;
335 : :
336 : 2871 : for (;;)
337 : : {
338 : 2871 : m = var_element (&var);
339 : 2871 : if (m == MATCH_NO)
340 : 0 : goto syntax;
341 : 2871 : if (m == MATCH_ERROR)
342 : : return MATCH_ERROR;
343 : :
344 : 2856 : new_var = gfc_get_data_variable ();
345 : 2856 : *new_var = var;
346 : 2856 : if (new_var->expr)
347 : 2731 : new_var->expr->where = gfc_current_locus;
348 : :
349 : 2856 : if (tail == NULL)
350 : 2481 : d->var = new_var;
351 : : else
352 : 375 : tail->next = new_var;
353 : :
354 : 2856 : tail = new_var;
355 : :
356 : 2856 : if (gfc_match_char ('/') == MATCH_YES)
357 : : break;
358 : 378 : if (gfc_match_char (',') != MATCH_YES)
359 : 3 : goto syntax;
360 : : }
361 : :
362 : : return MATCH_YES;
363 : :
364 : 3 : syntax:
365 : 3 : gfc_syntax_error (ST_DATA);
366 : 3 : gfc_free_data_all (gfc_current_ns);
367 : 3 : return MATCH_ERROR;
368 : : }
369 : :
370 : :
371 : : static match
372 : 8687 : match_data_constant (gfc_expr **result)
373 : : {
374 : 8687 : char name[GFC_MAX_SYMBOL_LEN + 1];
375 : 8687 : gfc_symbol *sym, *dt_sym = NULL;
376 : 8687 : gfc_expr *expr;
377 : 8687 : match m;
378 : 8687 : locus old_loc;
379 : 8687 : gfc_symtree *symtree;
380 : :
381 : 8687 : m = gfc_match_literal_constant (&expr, 1);
382 : 8687 : if (m == MATCH_YES)
383 : : {
384 : 8342 : *result = expr;
385 : 8342 : return MATCH_YES;
386 : : }
387 : :
388 : 345 : if (m == MATCH_ERROR)
389 : : return MATCH_ERROR;
390 : :
391 : 337 : m = gfc_match_null (result);
392 : 337 : if (m != MATCH_NO)
393 : : return m;
394 : :
395 : 329 : old_loc = gfc_current_locus;
396 : :
397 : : /* Should this be a structure component, try to match it
398 : : before matching a name. */
399 : 329 : m = gfc_match_rvalue (result);
400 : 329 : if (m == MATCH_ERROR)
401 : : return m;
402 : :
403 : 329 : if (m == MATCH_YES && (*result)->expr_type == EXPR_STRUCTURE)
404 : : {
405 : 4 : if (!gfc_simplify_expr (*result, 0))
406 : 0 : m = MATCH_ERROR;
407 : 4 : return m;
408 : : }
409 : 319 : else if (m == MATCH_YES)
410 : : {
411 : : /* If a parameter inquiry ends up here, symtree is NULL but **result
412 : : contains the right constant expression. Check here. */
413 : 319 : if ((*result)->symtree == NULL
414 : 37 : && (*result)->expr_type == EXPR_CONSTANT
415 : 37 : && ((*result)->ts.type == BT_INTEGER
416 : 1 : || (*result)->ts.type == BT_REAL))
417 : : return m;
418 : :
419 : : /* F2018:R845 data-stmt-constant is initial-data-target.
420 : : A data-stmt-constant shall be ... initial-data-target if and
421 : : only if the corresponding data-stmt-object has the POINTER
422 : : attribute. ... If data-stmt-constant is initial-data-target
423 : : the corresponding data statement object shall be
424 : : data-pointer-initialization compatible (7.5.4.6) with the initial
425 : : data target; the data statement object is initially associated
426 : : with the target. */
427 : 283 : if ((*result)->symtree
428 : 282 : && (*result)->symtree->n.sym->attr.save
429 : 218 : && (*result)->symtree->n.sym->attr.target)
430 : : return m;
431 : 250 : gfc_free_expr (*result);
432 : : }
433 : :
434 : 256 : gfc_current_locus = old_loc;
435 : :
436 : 256 : m = gfc_match_name (name);
437 : 256 : if (m != MATCH_YES)
438 : : return m;
439 : :
440 : 250 : if (gfc_find_sym_tree (name, NULL, 1, &symtree))
441 : : return MATCH_ERROR;
442 : :
443 : 250 : sym = symtree->n.sym;
444 : :
445 : 250 : if (sym && sym->attr.generic)
446 : 60 : dt_sym = gfc_find_dt_in_generic (sym);
447 : :
448 : 60 : if (sym == NULL
449 : 250 : || (sym->attr.flavor != FL_PARAMETER
450 : 65 : && (!dt_sym || !gfc_fl_struct (dt_sym->attr.flavor))))
451 : : {
452 : 5 : gfc_error ("Symbol %qs must be a PARAMETER in DATA statement at %C",
453 : : name);
454 : 5 : *result = NULL;
455 : 5 : return MATCH_ERROR;
456 : : }
457 : 245 : else if (dt_sym && gfc_fl_struct (dt_sym->attr.flavor))
458 : 60 : return gfc_match_structure_constructor (dt_sym, symtree, result);
459 : :
460 : : /* Check to see if the value is an initialization array expression. */
461 : 185 : if (sym->value->expr_type == EXPR_ARRAY)
462 : : {
463 : 67 : gfc_current_locus = old_loc;
464 : :
465 : 67 : m = gfc_match_init_expr (result);
466 : 67 : if (m == MATCH_ERROR)
467 : : return m;
468 : :
469 : 66 : if (m == MATCH_YES)
470 : : {
471 : 66 : if (!gfc_simplify_expr (*result, 0))
472 : 0 : m = MATCH_ERROR;
473 : :
474 : 66 : if ((*result)->expr_type == EXPR_CONSTANT)
475 : : return m;
476 : : else
477 : : {
478 : 2 : gfc_error ("Invalid initializer %s in Data statement at %C", name);
479 : 2 : return MATCH_ERROR;
480 : : }
481 : : }
482 : : }
483 : :
484 : 118 : *result = gfc_copy_expr (sym->value);
485 : 118 : return MATCH_YES;
486 : : }
487 : :
488 : :
489 : : /* Match a list of values in a DATA statement. The leading '/' has
490 : : already been seen at this point. */
491 : :
492 : : static match
493 : 2539 : top_val_list (gfc_data *data)
494 : : {
495 : 2539 : gfc_data_value *new_val, *tail;
496 : 2539 : gfc_expr *expr;
497 : 2539 : match m;
498 : :
499 : 2539 : tail = NULL;
500 : :
501 : 8323 : for (;;)
502 : : {
503 : 8323 : m = match_data_constant (&expr);
504 : 8323 : if (m == MATCH_NO)
505 : 3 : goto syntax;
506 : 8320 : if (m == MATCH_ERROR)
507 : : return MATCH_ERROR;
508 : :
509 : 8298 : new_val = gfc_get_data_value ();
510 : 8298 : mpz_init (new_val->repeat);
511 : :
512 : 8298 : if (tail == NULL)
513 : 2514 : data->value = new_val;
514 : : else
515 : 5784 : tail->next = new_val;
516 : :
517 : 8298 : tail = new_val;
518 : :
519 : 8298 : if (expr->ts.type != BT_INTEGER || gfc_match_char ('*') != MATCH_YES)
520 : : {
521 : 8093 : tail->expr = expr;
522 : 8093 : mpz_set_ui (tail->repeat, 1);
523 : : }
524 : : else
525 : : {
526 : 205 : mpz_set (tail->repeat, expr->value.integer);
527 : 205 : gfc_free_expr (expr);
528 : :
529 : 205 : m = match_data_constant (&tail->expr);
530 : 205 : if (m == MATCH_NO)
531 : 0 : goto syntax;
532 : 205 : if (m == MATCH_ERROR)
533 : : return MATCH_ERROR;
534 : : }
535 : :
536 : 8294 : if (gfc_match_char ('/') == MATCH_YES)
537 : : break;
538 : 5785 : if (gfc_match_char (',') == MATCH_NO)
539 : 1 : goto syntax;
540 : : }
541 : :
542 : : return MATCH_YES;
543 : :
544 : 4 : syntax:
545 : 4 : gfc_syntax_error (ST_DATA);
546 : 4 : gfc_free_data_all (gfc_current_ns);
547 : 4 : return MATCH_ERROR;
548 : : }
549 : :
550 : :
551 : : /* Matches an old style initialization. */
552 : :
553 : : static match
554 : 70 : match_old_style_init (const char *name)
555 : : {
556 : 70 : match m;
557 : 70 : gfc_symtree *st;
558 : 70 : gfc_symbol *sym;
559 : 70 : gfc_data *newdata, *nd;
560 : :
561 : : /* Set up data structure to hold initializers. */
562 : 70 : gfc_find_sym_tree (name, NULL, 0, &st);
563 : 70 : sym = st->n.sym;
564 : :
565 : 70 : newdata = gfc_get_data ();
566 : 70 : newdata->var = gfc_get_data_variable ();
567 : 70 : newdata->var->expr = gfc_get_variable_expr (st);
568 : 70 : newdata->var->expr->where = sym->declared_at;
569 : 70 : newdata->where = gfc_current_locus;
570 : :
571 : : /* Match initial value list. This also eats the terminal '/'. */
572 : 70 : m = top_val_list (newdata);
573 : 70 : if (m != MATCH_YES)
574 : : {
575 : 1 : free (newdata);
576 : 1 : return m;
577 : : }
578 : :
579 : : /* Check that a BOZ did not creep into an old-style initialization. */
580 : 137 : for (nd = newdata; nd; nd = nd->next)
581 : : {
582 : 69 : if (nd->value->expr->ts.type == BT_BOZ
583 : 69 : && gfc_invalid_boz (G_("BOZ at %L cannot appear in an old-style "
584 : : "initialization"), &nd->value->expr->where))
585 : : return MATCH_ERROR;
586 : :
587 : 68 : if (nd->var->expr->ts.type != BT_INTEGER
588 : 27 : && nd->var->expr->ts.type != BT_REAL
589 : 21 : && nd->value->expr->ts.type == BT_BOZ)
590 : : {
591 : 0 : gfc_error (G_("BOZ literal constant near %L cannot be assigned to "
592 : : "a %qs variable in an old-style initialization"),
593 : 0 : &nd->value->expr->where,
594 : : gfc_typename (&nd->value->expr->ts));
595 : 0 : return MATCH_ERROR;
596 : : }
597 : : }
598 : :
599 : 68 : if (gfc_pure (NULL))
600 : : {
601 : 1 : gfc_error ("Initialization at %C is not allowed in a PURE procedure");
602 : 1 : free (newdata);
603 : 1 : return MATCH_ERROR;
604 : : }
605 : 67 : gfc_unset_implicit_pure (gfc_current_ns->proc_name);
606 : :
607 : : /* Mark the variable as having appeared in a data statement. */
608 : 67 : if (!gfc_add_data (&sym->attr, sym->name, &sym->declared_at))
609 : : {
610 : 2 : free (newdata);
611 : 2 : return MATCH_ERROR;
612 : : }
613 : :
614 : : /* Chain in namespace list of DATA initializers. */
615 : 65 : newdata->next = gfc_current_ns->data;
616 : 65 : gfc_current_ns->data = newdata;
617 : :
618 : 65 : return m;
619 : : }
620 : :
621 : :
622 : : /* Match the stuff following a DATA statement. If ERROR_FLAG is set,
623 : : we are matching a DATA statement and are therefore issuing an error
624 : : if we encounter something unexpected, if not, we're trying to match
625 : : an old-style initialization expression of the form INTEGER I /2/. */
626 : :
627 : : match
628 : 2401 : gfc_match_data (void)
629 : : {
630 : 2401 : gfc_data *new_data;
631 : 2401 : gfc_expr *e;
632 : 2401 : gfc_ref *ref;
633 : 2401 : match m;
634 : 2401 : char c;
635 : :
636 : : /* DATA has been matched. In free form source code, the next character
637 : : needs to be whitespace or '(' from an implied do-loop. Check that
638 : : here. */
639 : 2401 : c = gfc_peek_ascii_char ();
640 : 2401 : if (gfc_current_form == FORM_FREE && !gfc_is_whitespace (c) && c != '(')
641 : : return MATCH_NO;
642 : :
643 : : /* Before parsing the rest of a DATA statement, check F2008:c1206. */
644 : 2400 : if ((gfc_current_state () == COMP_FUNCTION
645 : 2400 : || gfc_current_state () == COMP_SUBROUTINE)
646 : 1153 : && gfc_state_stack->previous->state == COMP_INTERFACE)
647 : : {
648 : 1 : gfc_error ("DATA statement at %C cannot appear within an INTERFACE");
649 : 1 : return MATCH_ERROR;
650 : : }
651 : :
652 : 2399 : set_in_match_data (true);
653 : :
654 : 2593 : for (;;)
655 : : {
656 : 2496 : new_data = gfc_get_data ();
657 : 2496 : new_data->where = gfc_current_locus;
658 : :
659 : 2496 : m = top_var_list (new_data);
660 : 2496 : if (m != MATCH_YES)
661 : 18 : goto cleanup;
662 : :
663 : 2478 : if (new_data->var->iter.var
664 : 116 : && new_data->var->iter.var->ts.type == BT_INTEGER
665 : 73 : && new_data->var->iter.var->symtree->n.sym->attr.implied_index == 1
666 : 67 : && new_data->var->list
667 : 67 : && new_data->var->list->expr
668 : 54 : && new_data->var->list->expr->ts.type == BT_CHARACTER
669 : 3 : && new_data->var->list->expr->ref
670 : 3 : && new_data->var->list->expr->ref->type == REF_SUBSTRING)
671 : : {
672 : 1 : gfc_error ("Invalid substring in data-implied-do at %L in DATA "
673 : : "statement", &new_data->var->list->expr->where);
674 : 1 : goto cleanup;
675 : : }
676 : :
677 : : /* Check for an entity with an allocatable component, which is not
678 : : allowed. */
679 : 2477 : e = new_data->var->expr;
680 : 2477 : if (e)
681 : : {
682 : 2362 : bool invalid;
683 : :
684 : 2362 : invalid = false;
685 : 3581 : for (ref = e->ref; ref; ref = ref->next)
686 : 1219 : if ((ref->type == REF_COMPONENT
687 : 139 : && ref->u.c.component->attr.allocatable)
688 : 1217 : || (ref->type == REF_ARRAY
689 : 1030 : && e->symtree->n.sym->attr.pointer != 1
690 : 1027 : && ref->u.ar.as && ref->u.ar.as->type == AS_DEFERRED))
691 : 1219 : invalid = true;
692 : :
693 : 2362 : if (invalid)
694 : : {
695 : 2 : gfc_error ("Allocatable component or deferred-shaped array "
696 : : "near %C in DATA statement");
697 : 2 : goto cleanup;
698 : : }
699 : :
700 : : /* F2008:C567 (R536) A data-i-do-object or a variable that appears
701 : : as a data-stmt-object shall not be an object designator in which
702 : : a pointer appears other than as the entire rightmost part-ref. */
703 : 2360 : if (!e->ref && e->ts.type == BT_DERIVED
704 : 43 : && e->symtree->n.sym->attr.pointer)
705 : 4 : goto partref;
706 : :
707 : 2356 : ref = e->ref;
708 : 2356 : if (e->symtree->n.sym->ts.type == BT_DERIVED
709 : 124 : && e->symtree->n.sym->attr.pointer
710 : 1 : && ref->type == REF_COMPONENT)
711 : 1 : goto partref;
712 : :
713 : 3566 : for (; ref; ref = ref->next)
714 : 1212 : if (ref->type == REF_COMPONENT
715 : 134 : && ref->u.c.component->attr.pointer
716 : 27 : && ref->next)
717 : 1 : goto partref;
718 : : }
719 : :
720 : 2469 : m = top_val_list (new_data);
721 : 2469 : if (m != MATCH_YES)
722 : 29 : goto cleanup;
723 : :
724 : 2440 : new_data->next = gfc_current_ns->data;
725 : 2440 : gfc_current_ns->data = new_data;
726 : :
727 : : /* A BOZ literal constant cannot appear in a structure constructor.
728 : : Check for that here for a data statement value. */
729 : 2440 : if (new_data->value->expr->ts.type == BT_DERIVED
730 : 37 : && new_data->value->expr->value.constructor)
731 : : {
732 : 35 : gfc_constructor *c;
733 : 35 : c = gfc_constructor_first (new_data->value->expr->value.constructor);
734 : 106 : for (; c; c = gfc_constructor_next (c))
735 : 36 : if (c->expr && c->expr->ts.type == BT_BOZ)
736 : : {
737 : 0 : gfc_error ("BOZ literal constant at %L cannot appear in a "
738 : : "structure constructor", &c->expr->where);
739 : 0 : return MATCH_ERROR;
740 : : }
741 : : }
742 : :
743 : 2440 : if (gfc_match_eos () == MATCH_YES)
744 : : break;
745 : :
746 : 97 : gfc_match_char (','); /* Optional comma */
747 : 97 : }
748 : :
749 : 2343 : set_in_match_data (false);
750 : :
751 : 2343 : if (gfc_pure (NULL))
752 : : {
753 : 0 : gfc_error ("DATA statement at %C is not allowed in a PURE procedure");
754 : 0 : return MATCH_ERROR;
755 : : }
756 : 2343 : gfc_unset_implicit_pure (gfc_current_ns->proc_name);
757 : :
758 : 2343 : return MATCH_YES;
759 : :
760 : 6 : partref:
761 : :
762 : 6 : gfc_error ("part-ref with pointer attribute near %L is not "
763 : : "rightmost part-ref of data-stmt-object",
764 : : &e->where);
765 : :
766 : 56 : cleanup:
767 : 56 : set_in_match_data (false);
768 : 56 : gfc_free_data (new_data);
769 : 56 : return MATCH_ERROR;
770 : : }
771 : :
772 : :
773 : : /************************ Declaration statements *********************/
774 : :
775 : :
776 : : /* Like gfc_match_init_expr, but matches a 'clist' (old-style initialization
777 : : list). The difference here is the expression is a list of constants
778 : : and is surrounded by '/'.
779 : : The typespec ts must match the typespec of the variable which the
780 : : clist is initializing.
781 : : The arrayspec tells whether this should match a list of constants
782 : : corresponding to array elements or a scalar (as == NULL). */
783 : :
784 : : static match
785 : 74 : match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as)
786 : : {
787 : 74 : gfc_constructor_base array_head = NULL;
788 : 74 : gfc_expr *expr = NULL;
789 : 74 : match m = MATCH_ERROR;
790 : 74 : locus where;
791 : 74 : mpz_t repeat, cons_size, as_size;
792 : 74 : bool scalar;
793 : 74 : int cmp;
794 : :
795 : 74 : gcc_assert (ts);
796 : :
797 : : /* We have already matched '/' - now look for a constant list, as with
798 : : top_val_list from decl.cc, but append the result to an array. */
799 : 74 : if (gfc_match ("/") == MATCH_YES)
800 : : {
801 : 1 : gfc_error ("Empty old style initializer list at %C");
802 : 1 : return MATCH_ERROR;
803 : : }
804 : :
805 : 73 : where = gfc_current_locus;
806 : 73 : scalar = !as || !as->rank;
807 : :
808 : 42 : if (!scalar && !spec_size (as, &as_size))
809 : : {
810 : 2 : gfc_error ("Array in initializer list at %L must have an explicit shape",
811 : 1 : as->type == AS_EXPLICIT ? &as->upper[0]->where : &where);
812 : : /* Nothing to cleanup yet. */
813 : 1 : return MATCH_ERROR;
814 : : }
815 : :
816 : 72 : mpz_init_set_ui (repeat, 0);
817 : :
818 : 143 : for (;;)
819 : : {
820 : 143 : m = match_data_constant (&expr);
821 : 143 : if (m != MATCH_YES)
822 : 3 : expr = NULL; /* match_data_constant may set expr to garbage */
823 : 3 : if (m == MATCH_NO)
824 : 2 : goto syntax;
825 : 141 : if (m == MATCH_ERROR)
826 : 1 : goto cleanup;
827 : :
828 : : /* Found r in repeat spec r*c; look for the constant to repeat. */
829 : 140 : if ( gfc_match_char ('*') == MATCH_YES)
830 : : {
831 : 18 : if (scalar)
832 : : {
833 : 1 : gfc_error ("Repeat spec invalid in scalar initializer at %C");
834 : 1 : goto cleanup;
835 : : }
836 : 17 : if (expr->ts.type != BT_INTEGER)
837 : : {
838 : 1 : gfc_error ("Repeat spec must be an integer at %C");
839 : 1 : goto cleanup;
840 : : }
841 : 16 : mpz_set (repeat, expr->value.integer);
842 : 16 : gfc_free_expr (expr);
843 : 16 : expr = NULL;
844 : :
845 : 16 : m = match_data_constant (&expr);
846 : 16 : if (m == MATCH_NO)
847 : : {
848 : 1 : m = MATCH_ERROR;
849 : 1 : gfc_error ("Expected data constant after repeat spec at %C");
850 : : }
851 : 16 : if (m != MATCH_YES)
852 : 1 : goto cleanup;
853 : : }
854 : : /* No repeat spec, we matched the data constant itself. */
855 : : else
856 : 122 : mpz_set_ui (repeat, 1);
857 : :
858 : 137 : if (!scalar)
859 : : {
860 : : /* Add the constant initializer as many times as repeated. */
861 : 251 : for (; mpz_cmp_ui (repeat, 0) > 0; mpz_sub_ui (repeat, repeat, 1))
862 : : {
863 : : /* Make sure types of elements match */
864 : 144 : if(ts && !gfc_compare_types (&expr->ts, ts)
865 : 12 : && !gfc_convert_type (expr, ts, 1))
866 : 0 : goto cleanup;
867 : :
868 : 144 : gfc_constructor_append_expr (&array_head,
869 : : gfc_copy_expr (expr), &gfc_current_locus);
870 : : }
871 : :
872 : 107 : gfc_free_expr (expr);
873 : 107 : expr = NULL;
874 : : }
875 : :
876 : : /* For scalar initializers quit after one element. */
877 : : else
878 : : {
879 : 30 : if(gfc_match_char ('/') != MATCH_YES)
880 : : {
881 : 1 : gfc_error ("End of scalar initializer expected at %C");
882 : 1 : goto cleanup;
883 : : }
884 : : break;
885 : : }
886 : :
887 : 107 : if (gfc_match_char ('/') == MATCH_YES)
888 : : break;
889 : 72 : if (gfc_match_char (',') == MATCH_NO)
890 : 1 : goto syntax;
891 : : }
892 : :
893 : : /* If we break early from here out, we encountered an error. */
894 : 64 : m = MATCH_ERROR;
895 : :
896 : : /* Set up expr as an array constructor. */
897 : 64 : if (!scalar)
898 : : {
899 : 35 : expr = gfc_get_array_expr (ts->type, ts->kind, &where);
900 : 35 : expr->ts = *ts;
901 : 35 : expr->value.constructor = array_head;
902 : :
903 : : /* Validate sizes. We built expr ourselves, so cons_size will be
904 : : constant (we fail above for non-constant expressions).
905 : : We still need to verify that the sizes match. */
906 : 35 : gcc_assert (gfc_array_size (expr, &cons_size));
907 : 35 : cmp = mpz_cmp (cons_size, as_size);
908 : 35 : if (cmp < 0)
909 : 2 : gfc_error ("Not enough elements in array initializer at %C");
910 : 33 : else if (cmp > 0)
911 : 3 : gfc_error ("Too many elements in array initializer at %C");
912 : 35 : mpz_clear (cons_size);
913 : 35 : if (cmp)
914 : 5 : goto cleanup;
915 : :
916 : : /* Set the rank/shape to match the LHS as auto-reshape is implied. */
917 : 30 : expr->rank = as->rank;
918 : 30 : expr->corank = as->corank;
919 : 30 : expr->shape = gfc_get_shape (as->rank);
920 : 66 : for (int i = 0; i < as->rank; ++i)
921 : 36 : spec_dimen_size (as, i, &expr->shape[i]);
922 : : }
923 : :
924 : : /* Make sure scalar types match. */
925 : 29 : else if (!gfc_compare_types (&expr->ts, ts)
926 : 29 : && !gfc_convert_type (expr, ts, 1))
927 : 2 : goto cleanup;
928 : :
929 : 57 : if (expr->ts.u.cl)
930 : 1 : expr->ts.u.cl->length_from_typespec = 1;
931 : :
932 : 57 : *result = expr;
933 : 57 : m = MATCH_YES;
934 : 57 : goto done;
935 : :
936 : 3 : syntax:
937 : 3 : m = MATCH_ERROR;
938 : 3 : gfc_error ("Syntax error in old style initializer list at %C");
939 : :
940 : 15 : cleanup:
941 : 15 : if (expr)
942 : 10 : expr->value.constructor = NULL;
943 : 15 : gfc_free_expr (expr);
944 : 15 : gfc_constructor_free (array_head);
945 : :
946 : 72 : done:
947 : 72 : mpz_clear (repeat);
948 : 72 : if (!scalar)
949 : 41 : mpz_clear (as_size);
950 : : return m;
951 : : }
952 : :
953 : :
954 : : /* Auxiliary function to merge DIMENSION and CODIMENSION array specs. */
955 : :
956 : : static bool
957 : 88 : merge_array_spec (gfc_array_spec *from, gfc_array_spec *to, bool copy)
958 : : {
959 : 88 : if ((from->type == AS_ASSUMED_RANK && to->corank)
960 : 86 : || (to->type == AS_ASSUMED_RANK && from->corank))
961 : : {
962 : 5 : gfc_error ("The assumed-rank array at %C shall not have a codimension");
963 : 5 : return false;
964 : : }
965 : :
966 : 83 : if (to->rank == 0 && from->rank > 0)
967 : : {
968 : 36 : to->rank = from->rank;
969 : 36 : to->type = from->type;
970 : 36 : to->cray_pointee = from->cray_pointee;
971 : 36 : to->cp_was_assumed = from->cp_was_assumed;
972 : :
973 : 110 : for (int i = to->corank - 1; i >= 0; i--)
974 : : {
975 : : /* Do not exceed the limits on lower[] and upper[]. gfortran
976 : : cleans up elsewhere. */
977 : 74 : int j = from->rank + i;
978 : 74 : if (j >= GFC_MAX_DIMENSIONS)
979 : : break;
980 : :
981 : 74 : to->lower[j] = to->lower[i];
982 : 74 : to->upper[j] = to->upper[i];
983 : : }
984 : 85 : for (int i = 0; i < from->rank; i++)
985 : : {
986 : 49 : if (copy)
987 : : {
988 : 33 : to->lower[i] = gfc_copy_expr (from->lower[i]);
989 : 33 : to->upper[i] = gfc_copy_expr (from->upper[i]);
990 : : }
991 : : else
992 : : {
993 : 16 : to->lower[i] = from->lower[i];
994 : 16 : to->upper[i] = from->upper[i];
995 : : }
996 : : }
997 : : }
998 : 47 : else if (to->corank == 0 && from->corank > 0)
999 : : {
1000 : 22 : to->corank = from->corank;
1001 : 22 : to->cotype = from->cotype;
1002 : :
1003 : 75 : for (int i = 0; i < from->corank; i++)
1004 : : {
1005 : : /* Do not exceed the limits on lower[] and upper[]. gfortran
1006 : : cleans up elsewhere. */
1007 : 54 : int k = from->rank + i;
1008 : 54 : int j = to->rank + i;
1009 : 54 : if (j >= GFC_MAX_DIMENSIONS)
1010 : : break;
1011 : :
1012 : 53 : if (copy)
1013 : : {
1014 : 24 : to->lower[j] = gfc_copy_expr (from->lower[k]);
1015 : 24 : to->upper[j] = gfc_copy_expr (from->upper[k]);
1016 : : }
1017 : : else
1018 : : {
1019 : 29 : to->lower[j] = from->lower[k];
1020 : 29 : to->upper[j] = from->upper[k];
1021 : : }
1022 : : }
1023 : : }
1024 : :
1025 : 83 : if (to->rank + to->corank > GFC_MAX_DIMENSIONS)
1026 : : {
1027 : 1 : gfc_error ("Sum of array rank %d and corank %d at %C exceeds maximum "
1028 : : "allowed dimensions of %d",
1029 : : to->rank, to->corank, GFC_MAX_DIMENSIONS);
1030 : 1 : to->corank = GFC_MAX_DIMENSIONS - to->rank;
1031 : 1 : return false;
1032 : : }
1033 : : return true;
1034 : : }
1035 : :
1036 : :
1037 : : /* Match an intent specification. Since this can only happen after an
1038 : : INTENT word, a legal intent-spec must follow. */
1039 : :
1040 : : static sym_intent
1041 : 26031 : match_intent_spec (void)
1042 : : {
1043 : :
1044 : 26031 : if (gfc_match (" ( in out )") == MATCH_YES)
1045 : : return INTENT_INOUT;
1046 : 23137 : if (gfc_match (" ( in )") == MATCH_YES)
1047 : : return INTENT_IN;
1048 : 3510 : if (gfc_match (" ( out )") == MATCH_YES)
1049 : : return INTENT_OUT;
1050 : :
1051 : 2 : gfc_error ("Bad INTENT specification at %C");
1052 : 2 : return INTENT_UNKNOWN;
1053 : : }
1054 : :
1055 : :
1056 : : /* Matches a character length specification, which is either a
1057 : : specification expression, '*', or ':'. */
1058 : :
1059 : : static match
1060 : 25660 : char_len_param_value (gfc_expr **expr, bool *deferred)
1061 : : {
1062 : 25660 : match m;
1063 : 25660 : gfc_expr *p;
1064 : :
1065 : 25660 : *expr = NULL;
1066 : 25660 : *deferred = false;
1067 : :
1068 : 25660 : if (gfc_match_char ('*') == MATCH_YES)
1069 : : return MATCH_YES;
1070 : :
1071 : 19278 : if (gfc_match_char (':') == MATCH_YES)
1072 : : {
1073 : 3135 : if (!gfc_notify_std (GFC_STD_F2003, "deferred type parameter at %C"))
1074 : : return MATCH_ERROR;
1075 : :
1076 : 3133 : *deferred = true;
1077 : :
1078 : 3133 : return MATCH_YES;
1079 : : }
1080 : :
1081 : 16143 : m = gfc_match_expr (expr);
1082 : :
1083 : 16143 : if (m == MATCH_NO || m == MATCH_ERROR)
1084 : : return m;
1085 : :
1086 : 16138 : if (!gfc_expr_check_typed (*expr, gfc_current_ns, false))
1087 : : return MATCH_ERROR;
1088 : :
1089 : : /* Try to simplify the expression to catch things like CHARACTER(([1])). */
1090 : 16132 : p = gfc_copy_expr (*expr);
1091 : 16132 : if (gfc_is_constant_expr (p) && gfc_simplify_expr (p, 1))
1092 : 13617 : gfc_replace_expr (*expr, p);
1093 : : else
1094 : 2515 : gfc_free_expr (p);
1095 : :
1096 : 16132 : if ((*expr)->expr_type == EXPR_FUNCTION)
1097 : : {
1098 : 1012 : if ((*expr)->ts.type == BT_INTEGER
1099 : 1011 : || ((*expr)->ts.type == BT_UNKNOWN
1100 : 1011 : && strcmp((*expr)->symtree->name, "null") != 0))
1101 : : return MATCH_YES;
1102 : :
1103 : 2 : goto syntax;
1104 : : }
1105 : 15120 : else if ((*expr)->expr_type == EXPR_CONSTANT)
1106 : : {
1107 : : /* F2008, 4.4.3.1: The length is a type parameter; its kind is
1108 : : processor dependent and its value is greater than or equal to zero.
1109 : : F2008, 4.4.3.2: If the character length parameter value evaluates
1110 : : to a negative value, the length of character entities declared
1111 : : is zero. */
1112 : :
1113 : 13564 : if ((*expr)->ts.type == BT_INTEGER)
1114 : : {
1115 : 13546 : if (mpz_cmp_si ((*expr)->value.integer, 0) < 0)
1116 : 4 : mpz_set_si ((*expr)->value.integer, 0);
1117 : : }
1118 : : else
1119 : 18 : goto syntax;
1120 : : }
1121 : 1556 : else if ((*expr)->expr_type == EXPR_ARRAY)
1122 : 8 : goto syntax;
1123 : 1548 : else if ((*expr)->expr_type == EXPR_VARIABLE)
1124 : : {
1125 : 1159 : bool t;
1126 : 1159 : gfc_expr *e;
1127 : :
1128 : 1159 : e = gfc_copy_expr (*expr);
1129 : :
1130 : : /* This catches the invalid code "[character(m(2:3)) :: 'x', 'y']",
1131 : : which causes an ICE if gfc_reduce_init_expr() is called. */
1132 : 1159 : if (e->ref && e->ref->type == REF_ARRAY
1133 : 8 : && e->ref->u.ar.type == AR_UNKNOWN
1134 : 7 : && e->ref->u.ar.dimen_type[0] == DIMEN_RANGE)
1135 : 2 : goto syntax;
1136 : :
1137 : 1157 : t = gfc_reduce_init_expr (e);
1138 : :
1139 : 1157 : if (!t && e->ts.type == BT_UNKNOWN
1140 : 7 : && e->symtree->n.sym->attr.untyped == 1
1141 : 7 : && (flag_implicit_none
1142 : 5 : || e->symtree->n.sym->ns->seen_implicit_none == 1
1143 : 1 : || e->symtree->n.sym->ns->parent->seen_implicit_none == 1))
1144 : : {
1145 : 7 : gfc_free_expr (e);
1146 : 7 : goto syntax;
1147 : : }
1148 : :
1149 : 1150 : if ((e->ref && e->ref->type == REF_ARRAY
1150 : 4 : && e->ref->u.ar.type != AR_ELEMENT)
1151 : 1149 : || (!e->ref && e->expr_type == EXPR_ARRAY))
1152 : : {
1153 : 2 : gfc_free_expr (e);
1154 : 2 : goto syntax;
1155 : : }
1156 : :
1157 : 1148 : gfc_free_expr (e);
1158 : : }
1159 : :
1160 : 15083 : if (gfc_seen_div0)
1161 : 52 : m = MATCH_ERROR;
1162 : :
1163 : : return m;
1164 : :
1165 : 39 : syntax:
1166 : 39 : gfc_error ("Scalar INTEGER expression expected at %L", &(*expr)->where);
1167 : 39 : return MATCH_ERROR;
1168 : : }
1169 : :
1170 : :
1171 : : /* A character length is a '*' followed by a literal integer or a
1172 : : char_len_param_value in parenthesis. */
1173 : :
1174 : : static match
1175 : 59412 : match_char_length (gfc_expr **expr, bool *deferred, bool obsolescent_check)
1176 : : {
1177 : 59412 : int length;
1178 : 59412 : match m;
1179 : :
1180 : 59412 : *deferred = false;
1181 : 59412 : m = gfc_match_char ('*');
1182 : 59412 : if (m != MATCH_YES)
1183 : : return m;
1184 : :
1185 : 2653 : m = gfc_match_small_literal_int (&length, NULL);
1186 : 2653 : if (m == MATCH_ERROR)
1187 : : return m;
1188 : :
1189 : 2653 : if (m == MATCH_YES)
1190 : : {
1191 : 2137 : if (obsolescent_check
1192 : 2137 : && !gfc_notify_std (GFC_STD_F95_OBS, "Old-style character length at %C"))
1193 : : return MATCH_ERROR;
1194 : 2137 : *expr = gfc_get_int_expr (gfc_charlen_int_kind, NULL, length);
1195 : 2137 : return m;
1196 : : }
1197 : :
1198 : 516 : if (gfc_match_char ('(') == MATCH_NO)
1199 : 0 : goto syntax;
1200 : :
1201 : 516 : m = char_len_param_value (expr, deferred);
1202 : 516 : if (m != MATCH_YES && gfc_matching_function)
1203 : : {
1204 : 0 : gfc_undo_symbols ();
1205 : 0 : m = MATCH_YES;
1206 : : }
1207 : :
1208 : 1 : if (m == MATCH_ERROR)
1209 : : return m;
1210 : 515 : if (m == MATCH_NO)
1211 : 0 : goto syntax;
1212 : :
1213 : 515 : if (gfc_match_char (')') == MATCH_NO)
1214 : : {
1215 : 0 : gfc_free_expr (*expr);
1216 : 0 : *expr = NULL;
1217 : 0 : goto syntax;
1218 : : }
1219 : :
1220 : : return MATCH_YES;
1221 : :
1222 : 0 : syntax:
1223 : 0 : gfc_error ("Syntax error in character length specification at %C");
1224 : 0 : return MATCH_ERROR;
1225 : : }
1226 : :
1227 : :
1228 : : /* Special subroutine for finding a symbol. Check if the name is found
1229 : : in the current name space. If not, and we're compiling a function or
1230 : : subroutine and the parent compilation unit is an interface, then check
1231 : : to see if the name we've been given is the name of the interface
1232 : : (located in another namespace). */
1233 : :
1234 : : static int
1235 : 267612 : find_special (const char *name, gfc_symbol **result, bool allow_subroutine)
1236 : : {
1237 : 267612 : gfc_state_data *s;
1238 : 267612 : gfc_symtree *st;
1239 : 267612 : int i;
1240 : :
1241 : 267612 : i = gfc_get_sym_tree (name, NULL, &st, allow_subroutine);
1242 : 267612 : if (i == 0)
1243 : : {
1244 : 267612 : *result = st ? st->n.sym : NULL;
1245 : 267612 : goto end;
1246 : : }
1247 : :
1248 : 0 : if (gfc_current_state () != COMP_SUBROUTINE
1249 : 0 : && gfc_current_state () != COMP_FUNCTION)
1250 : 0 : goto end;
1251 : :
1252 : 0 : s = gfc_state_stack->previous;
1253 : 0 : if (s == NULL)
1254 : 0 : goto end;
1255 : :
1256 : 0 : if (s->state != COMP_INTERFACE)
1257 : 0 : goto end;
1258 : 0 : if (s->sym == NULL)
1259 : 0 : goto end; /* Nameless interface. */
1260 : :
1261 : 0 : if (strcmp (name, s->sym->name) == 0)
1262 : : {
1263 : 0 : *result = s->sym;
1264 : 0 : return 0;
1265 : : }
1266 : :
1267 : 0 : end:
1268 : : return i;
1269 : : }
1270 : :
1271 : :
1272 : : /* Special subroutine for getting a symbol node associated with a
1273 : : procedure name, used in SUBROUTINE and FUNCTION statements. The
1274 : : symbol is created in the parent using with symtree node in the
1275 : : child unit pointing to the symbol. If the current namespace has no
1276 : : parent, then the symbol is just created in the current unit. */
1277 : :
1278 : : static int
1279 : 59681 : get_proc_name (const char *name, gfc_symbol **result, bool module_fcn_entry)
1280 : : {
1281 : 59681 : gfc_symtree *st;
1282 : 59681 : gfc_symbol *sym;
1283 : 59681 : int rc = 0;
1284 : :
1285 : : /* Module functions have to be left in their own namespace because
1286 : : they have potentially (almost certainly!) already been referenced.
1287 : : In this sense, they are rather like external functions. This is
1288 : : fixed up in resolve.cc(resolve_entries), where the symbol name-
1289 : : space is set to point to the master function, so that the fake
1290 : : result mechanism can work. */
1291 : 59681 : if (module_fcn_entry)
1292 : : {
1293 : : /* Present if entry is declared to be a module procedure. */
1294 : 259 : rc = gfc_find_symbol (name, gfc_current_ns->parent, 0, result);
1295 : :
1296 : 259 : if (*result == NULL)
1297 : 216 : rc = gfc_get_symbol (name, NULL, result);
1298 : 86 : else if (!gfc_get_symbol (name, NULL, &sym) && sym
1299 : 43 : && (*result)->ts.type == BT_UNKNOWN
1300 : 86 : && sym->attr.flavor == FL_UNKNOWN)
1301 : : /* Pick up the typespec for the entry, if declared in the function
1302 : : body. Note that this symbol is FL_UNKNOWN because it will
1303 : : only have appeared in a type declaration. The local symtree
1304 : : is set to point to the module symbol and a unique symtree
1305 : : to the local version. This latter ensures a correct clearing
1306 : : of the symbols. */
1307 : : {
1308 : : /* If the ENTRY proceeds its specification, we need to ensure
1309 : : that this does not raise a "has no IMPLICIT type" error. */
1310 : 43 : if (sym->ts.type == BT_UNKNOWN)
1311 : 23 : sym->attr.untyped = 1;
1312 : :
1313 : 43 : (*result)->ts = sym->ts;
1314 : :
1315 : : /* Put the symbol in the procedure namespace so that, should
1316 : : the ENTRY precede its specification, the specification
1317 : : can be applied. */
1318 : 43 : (*result)->ns = gfc_current_ns;
1319 : :
1320 : 43 : gfc_find_sym_tree (name, gfc_current_ns, 0, &st);
1321 : 43 : st->n.sym = *result;
1322 : 43 : st = gfc_get_unique_symtree (gfc_current_ns);
1323 : 43 : sym->refs++;
1324 : 43 : st->n.sym = sym;
1325 : : }
1326 : : }
1327 : : else
1328 : 59422 : rc = gfc_get_symbol (name, gfc_current_ns->parent, result);
1329 : :
1330 : 59681 : if (rc)
1331 : : return rc;
1332 : :
1333 : 59680 : sym = *result;
1334 : 59680 : if (sym->attr.proc == PROC_ST_FUNCTION)
1335 : : return rc;
1336 : :
1337 : 59680 : if (sym->attr.module_procedure && sym->attr.if_source == IFSRC_IFBODY)
1338 : : {
1339 : : /* Create a partially populated interface symbol to carry the
1340 : : characteristics of the procedure and the result. */
1341 : 366 : sym->tlink = gfc_new_symbol (name, sym->ns);
1342 : 366 : gfc_add_type (sym->tlink, &(sym->ts), &gfc_current_locus);
1343 : 366 : gfc_copy_attr (&sym->tlink->attr, &sym->attr, NULL);
1344 : 366 : if (sym->attr.dimension)
1345 : 15 : sym->tlink->as = gfc_copy_array_spec (sym->as);
1346 : :
1347 : : /* Ideally, at this point, a copy would be made of the formal
1348 : : arguments and their namespace. However, this does not appear
1349 : : to be necessary, albeit at the expense of not being able to
1350 : : use gfc_compare_interfaces directly. */
1351 : :
1352 : 366 : if (sym->result && sym->result != sym)
1353 : : {
1354 : 60 : sym->tlink->result = sym->result;
1355 : 60 : sym->result = NULL;
1356 : : }
1357 : 306 : else if (sym->result)
1358 : : {
1359 : 62 : sym->tlink->result = sym->tlink;
1360 : : }
1361 : : }
1362 : 59314 : else if (sym && !sym->gfc_new
1363 : 22961 : && gfc_current_state () != COMP_INTERFACE)
1364 : : {
1365 : : /* Trap another encompassed procedure with the same name. All
1366 : : these conditions are necessary to avoid picking up an entry
1367 : : whose name clashes with that of the encompassing procedure;
1368 : : this is handled using gsymbols to register unique, globally
1369 : : accessible names. */
1370 : 22034 : if (sym->attr.flavor != 0
1371 : 20092 : && sym->attr.proc != 0
1372 : 2077 : && (sym->attr.subroutine || sym->attr.function || sym->attr.entry)
1373 : 6 : && sym->attr.if_source != IFSRC_UNKNOWN)
1374 : : {
1375 : 6 : gfc_error_now ("Procedure %qs at %C is already defined at %L",
1376 : : name, &sym->declared_at);
1377 : 6 : return true;
1378 : : }
1379 : 22028 : if (sym->attr.flavor != 0
1380 : 20086 : && sym->attr.entry && sym->attr.if_source != IFSRC_UNKNOWN)
1381 : : {
1382 : 1 : gfc_error_now ("Procedure %qs at %C is already defined at %L",
1383 : : name, &sym->declared_at);
1384 : 1 : return true;
1385 : : }
1386 : :
1387 : 22027 : if (sym->attr.external && sym->attr.procedure
1388 : 2 : && gfc_current_state () == COMP_CONTAINS)
1389 : : {
1390 : 1 : gfc_error_now ("Contained procedure %qs at %C clashes with "
1391 : : "procedure defined at %L",
1392 : : name, &sym->declared_at);
1393 : 1 : return true;
1394 : : }
1395 : :
1396 : : /* Trap a procedure with a name the same as interface in the
1397 : : encompassing scope. */
1398 : 22026 : if (sym->attr.generic != 0
1399 : 59 : && (sym->attr.subroutine || sym->attr.function)
1400 : 1 : && !sym->attr.mod_proc)
1401 : : {
1402 : 1 : gfc_error_now ("Name %qs at %C is already defined"
1403 : : " as a generic interface at %L",
1404 : : name, &sym->declared_at);
1405 : 1 : return true;
1406 : : }
1407 : :
1408 : : /* Trap declarations of attributes in encompassing scope. The
1409 : : signature for this is that ts.kind is nonzero for no-CLASS
1410 : : entity. For a CLASS entity, ts.kind is zero. */
1411 : 22025 : if ((sym->ts.kind != 0
1412 : 21684 : || sym->ts.type == BT_CLASS
1413 : 21683 : || sym->ts.type == BT_DERIVED)
1414 : 365 : && !sym->attr.implicit_type
1415 : 364 : && sym->attr.proc == 0
1416 : 346 : && gfc_current_ns->parent != NULL
1417 : 137 : && sym->attr.access == 0
1418 : 135 : && !module_fcn_entry)
1419 : : {
1420 : 5 : gfc_error_now ("Procedure %qs at %C has an explicit interface "
1421 : : "from a previous declaration", name);
1422 : 5 : return true;
1423 : : }
1424 : : }
1425 : :
1426 : : /* C1246 (R1225) MODULE shall appear only in the function-stmt or
1427 : : subroutine-stmt of a module subprogram or of a nonabstract interface
1428 : : body that is declared in the scoping unit of a module or submodule. */
1429 : 59666 : if (sym->attr.external
1430 : 79 : && (sym->attr.subroutine || sym->attr.function)
1431 : 78 : && sym->attr.if_source == IFSRC_IFBODY
1432 : 78 : && !current_attr.module_procedure
1433 : 3 : && sym->attr.proc == PROC_MODULE
1434 : 3 : && gfc_state_stack->state == COMP_CONTAINS)
1435 : : {
1436 : 1 : gfc_error_now ("Procedure %qs defined in interface body at %L "
1437 : : "clashes with internal procedure defined at %C",
1438 : : name, &sym->declared_at);
1439 : 1 : return true;
1440 : : }
1441 : :
1442 : 59665 : if (sym && !sym->gfc_new
1443 : 23312 : && sym->attr.flavor != FL_UNKNOWN
1444 : 21027 : && sym->attr.referenced == 0 && sym->attr.subroutine == 1
1445 : 213 : && gfc_state_stack->state == COMP_CONTAINS
1446 : 208 : && gfc_state_stack->previous->state == COMP_SUBROUTINE)
1447 : : {
1448 : 1 : gfc_error_now ("Procedure %qs at %C is already defined at %L",
1449 : : name, &sym->declared_at);
1450 : 1 : return true;
1451 : : }
1452 : :
1453 : 59664 : if (gfc_current_ns->parent == NULL || *result == NULL)
1454 : : return rc;
1455 : :
1456 : : /* Module function entries will already have a symtree in
1457 : : the current namespace but will need one at module level. */
1458 : 48013 : if (module_fcn_entry)
1459 : : {
1460 : : /* Present if entry is declared to be a module procedure. */
1461 : 257 : rc = gfc_find_sym_tree (name, gfc_current_ns->parent, 0, &st);
1462 : 257 : if (st == NULL)
1463 : 216 : st = gfc_new_symtree (&gfc_current_ns->parent->sym_root, name);
1464 : : }
1465 : : else
1466 : 47756 : st = gfc_new_symtree (&gfc_current_ns->sym_root, name);
1467 : :
1468 : 48013 : st->n.sym = sym;
1469 : 48013 : sym->refs++;
1470 : :
1471 : : /* See if the procedure should be a module procedure. */
1472 : :
1473 : 48013 : if (((sym->ns->proc_name != NULL
1474 : 48013 : && sym->ns->proc_name->attr.flavor == FL_MODULE
1475 : 19684 : && sym->attr.proc != PROC_MODULE)
1476 : 48013 : || (module_fcn_entry && sym->attr.proc != PROC_MODULE))
1477 : 65283 : && !gfc_add_procedure (&sym->attr, PROC_MODULE, sym->name, NULL))
1478 : : rc = 2;
1479 : :
1480 : : return rc;
1481 : : }
1482 : :
1483 : :
1484 : : /* Verify that the given symbol representing a parameter is C
1485 : : interoperable, by checking to see if it was marked as such after
1486 : : its declaration. If the given symbol is not interoperable, a
1487 : : warning is reported, thus removing the need to return the status to
1488 : : the calling function. The standard does not require the user use
1489 : : one of the iso_c_binding named constants to declare an
1490 : : interoperable parameter, but we can't be sure if the param is C
1491 : : interop or not if the user doesn't. For example, integer(4) may be
1492 : : legal Fortran, but doesn't have meaning in C. It may interop with
1493 : : a number of the C types, which causes a problem because the
1494 : : compiler can't know which one. This code is almost certainly not
1495 : : portable, and the user will get what they deserve if the C type
1496 : : across platforms isn't always interoperable with integer(4). If
1497 : : the user had used something like integer(c_int) or integer(c_long),
1498 : : the compiler could have automatically handled the varying sizes
1499 : : across platforms. */
1500 : :
1501 : : bool
1502 : 14642 : gfc_verify_c_interop_param (gfc_symbol *sym)
1503 : : {
1504 : 14642 : int is_c_interop = 0;
1505 : 14642 : bool retval = true;
1506 : :
1507 : : /* We check implicitly typed variables in symbol.cc:gfc_set_default_type().
1508 : : Don't repeat the checks here. */
1509 : 14642 : if (sym->attr.implicit_type)
1510 : : return true;
1511 : :
1512 : : /* For subroutines or functions that are passed to a BIND(C) procedure,
1513 : : they're interoperable if they're BIND(C) and their params are all
1514 : : interoperable. */
1515 : 14642 : if (sym->attr.flavor == FL_PROCEDURE)
1516 : : {
1517 : 4 : if (sym->attr.is_bind_c == 0)
1518 : : {
1519 : 0 : gfc_error_now ("Procedure %qs at %L must have the BIND(C) "
1520 : : "attribute to be C interoperable", sym->name,
1521 : : &(sym->declared_at));
1522 : 0 : return false;
1523 : : }
1524 : : else
1525 : : {
1526 : 4 : if (sym->attr.is_c_interop == 1)
1527 : : /* We've already checked this procedure; don't check it again. */
1528 : : return true;
1529 : : else
1530 : 4 : return verify_bind_c_sym (sym, &(sym->ts), sym->attr.in_common,
1531 : 4 : sym->common_block);
1532 : : }
1533 : : }
1534 : :
1535 : : /* See if we've stored a reference to a procedure that owns sym. */
1536 : 14638 : if (sym->ns != NULL && sym->ns->proc_name != NULL)
1537 : : {
1538 : 14638 : if (sym->ns->proc_name->attr.is_bind_c == 1)
1539 : : {
1540 : 14599 : is_c_interop = (gfc_verify_c_interop(&(sym->ts)) ? 1 : 0);
1541 : :
1542 : 3375 : if (is_c_interop != 1)
1543 : : {
1544 : : /* Make personalized messages to give better feedback. */
1545 : 3375 : if (sym->ts.type == BT_DERIVED)
1546 : 1 : gfc_error ("Variable %qs at %L is a dummy argument to the "
1547 : : "BIND(C) procedure %qs but is not C interoperable "
1548 : : "because derived type %qs is not C interoperable",
1549 : : sym->name, &(sym->declared_at),
1550 : 1 : sym->ns->proc_name->name,
1551 : 1 : sym->ts.u.derived->name);
1552 : 3374 : else if (sym->ts.type == BT_CLASS)
1553 : 6 : gfc_error ("Variable %qs at %L is a dummy argument to the "
1554 : : "BIND(C) procedure %qs but is not C interoperable "
1555 : : "because it is polymorphic",
1556 : : sym->name, &(sym->declared_at),
1557 : 6 : sym->ns->proc_name->name);
1558 : 3368 : else if (warn_c_binding_type)
1559 : 23 : gfc_warning (OPT_Wc_binding_type,
1560 : : "Variable %qs at %L is a dummy argument of the "
1561 : : "BIND(C) procedure %qs but may not be C "
1562 : : "interoperable",
1563 : : sym->name, &(sym->declared_at),
1564 : 23 : sym->ns->proc_name->name);
1565 : : }
1566 : :
1567 : : /* Per F2018, 18.3.6 (5), pointer + contiguous is not permitted. */
1568 : 14599 : if (sym->attr.pointer && sym->attr.contiguous)
1569 : 2 : gfc_error ("Dummy argument %qs at %L may not be a pointer with "
1570 : : "CONTIGUOUS attribute as procedure %qs is BIND(C)",
1571 : 2 : sym->name, &sym->declared_at, sym->ns->proc_name->name);
1572 : :
1573 : : /* Per F2018, C1557, pointer/allocatable dummies to a bind(c)
1574 : : procedure that are default-initialized are not permitted. */
1575 : 14599 : if ((sym->attr.pointer || sym->attr.allocatable)
1576 : 1029 : && sym->ts.type == BT_DERIVED
1577 : 14969 : && gfc_has_default_initializer (sym->ts.u.derived))
1578 : : {
1579 : 8 : gfc_error ("Default-initialized dummy argument %qs with %s "
1580 : : "attribute at %L is not permitted in BIND(C) "
1581 : : "procedure %qs", sym->name,
1582 : 4 : (sym->attr.pointer ? "POINTER" : "ALLOCATABLE"),
1583 : 4 : &sym->declared_at, sym->ns->proc_name->name);
1584 : 4 : retval = false;
1585 : : }
1586 : :
1587 : : /* Character strings are only C interoperable if they have a
1588 : : length of 1. However, as an argument they are also interoperable
1589 : : when passed as descriptor (which requires len=: or len=*). */
1590 : 14599 : if (sym->ts.type == BT_CHARACTER)
1591 : : {
1592 : 2333 : gfc_charlen *cl = sym->ts.u.cl;
1593 : :
1594 : 2333 : if (sym->attr.allocatable || sym->attr.pointer)
1595 : : {
1596 : : /* F2018, 18.3.6 (6). */
1597 : 193 : if (!sym->ts.deferred)
1598 : : {
1599 : 64 : if (sym->attr.allocatable)
1600 : 32 : gfc_error ("Allocatable character dummy argument %qs "
1601 : : "at %L must have deferred length as "
1602 : : "procedure %qs is BIND(C)", sym->name,
1603 : 32 : &sym->declared_at, sym->ns->proc_name->name);
1604 : : else
1605 : 32 : gfc_error ("Pointer character dummy argument %qs at %L "
1606 : : "must have deferred length as procedure %qs "
1607 : : "is BIND(C)", sym->name, &sym->declared_at,
1608 : 32 : sym->ns->proc_name->name);
1609 : : retval = false;
1610 : : }
1611 : 129 : else if (!gfc_notify_std (GFC_STD_F2018,
1612 : : "Deferred-length character dummy "
1613 : : "argument %qs at %L of procedure "
1614 : : "%qs with BIND(C) attribute",
1615 : : sym->name, &sym->declared_at,
1616 : 129 : sym->ns->proc_name->name))
1617 : 102 : retval = false;
1618 : : }
1619 : 2140 : else if (sym->attr.value
1620 : 351 : && (!cl || !cl->length
1621 : 351 : || cl->length->expr_type != EXPR_CONSTANT
1622 : 351 : || mpz_cmp_si (cl->length->value.integer, 1) != 0))
1623 : : {
1624 : 1 : gfc_error ("Character dummy argument %qs at %L must be "
1625 : : "of length 1 as it has the VALUE attribute",
1626 : : sym->name, &sym->declared_at);
1627 : 1 : retval = false;
1628 : : }
1629 : 2139 : else if (!cl || !cl->length)
1630 : : {
1631 : : /* Assumed length; F2018, 18.3.6 (5)(2).
1632 : : Uses the CFI array descriptor - also for scalars and
1633 : : explicit-size/assumed-size arrays. */
1634 : 956 : if (!gfc_notify_std (GFC_STD_F2018,
1635 : : "Assumed-length character dummy argument "
1636 : : "%qs at %L of procedure %qs with BIND(C) "
1637 : : "attribute", sym->name, &sym->declared_at,
1638 : 956 : sym->ns->proc_name->name))
1639 : 102 : retval = false;
1640 : : }
1641 : 1183 : else if (cl->length->expr_type != EXPR_CONSTANT
1642 : 869 : || mpz_cmp_si (cl->length->value.integer, 1) != 0)
1643 : : {
1644 : : /* F2018, 18.3.6, (5), item 4. */
1645 : 653 : if (!sym->attr.dimension
1646 : 645 : || sym->as->type == AS_ASSUMED_SIZE
1647 : 639 : || sym->as->type == AS_EXPLICIT)
1648 : : {
1649 : 20 : gfc_error ("Character dummy argument %qs at %L must be "
1650 : : "of constant length of one or assumed length, "
1651 : : "unless it has assumed shape or assumed rank, "
1652 : : "as procedure %qs has the BIND(C) attribute",
1653 : : sym->name, &sym->declared_at,
1654 : 20 : sym->ns->proc_name->name);
1655 : 20 : retval = false;
1656 : : }
1657 : : /* else: valid only since F2018 - and an assumed-shape/rank
1658 : : array; however, gfc_notify_std is already called when
1659 : : those array types are used. Thus, silently accept F200x. */
1660 : : }
1661 : : }
1662 : :
1663 : : /* We have to make sure that any param to a bind(c) routine does
1664 : : not have the allocatable, pointer, or optional attributes,
1665 : : according to J3/04-007, section 5.1. */
1666 : 14599 : if (sym->attr.allocatable == 1
1667 : 14995 : && !gfc_notify_std (GFC_STD_F2018, "Variable %qs at %L with "
1668 : : "ALLOCATABLE attribute in procedure %qs "
1669 : : "with BIND(C)", sym->name,
1670 : : &(sym->declared_at),
1671 : 396 : sym->ns->proc_name->name))
1672 : : retval = false;
1673 : :
1674 : 14599 : if (sym->attr.pointer == 1
1675 : 15232 : && !gfc_notify_std (GFC_STD_F2018, "Variable %qs at %L with "
1676 : : "POINTER attribute in procedure %qs "
1677 : : "with BIND(C)", sym->name,
1678 : : &(sym->declared_at),
1679 : 633 : sym->ns->proc_name->name))
1680 : : retval = false;
1681 : :
1682 : 14599 : if (sym->attr.optional == 1 && sym->attr.value)
1683 : : {
1684 : 9 : gfc_error ("Variable %qs at %L cannot have both the OPTIONAL "
1685 : : "and the VALUE attribute because procedure %qs "
1686 : : "is BIND(C)", sym->name, &(sym->declared_at),
1687 : 9 : sym->ns->proc_name->name);
1688 : 9 : retval = false;
1689 : : }
1690 : 14590 : else if (sym->attr.optional == 1
1691 : 15479 : && !gfc_notify_std (GFC_STD_F2018, "Variable %qs "
1692 : : "at %L with OPTIONAL attribute in "
1693 : : "procedure %qs which is BIND(C)",
1694 : : sym->name, &(sym->declared_at),
1695 : 889 : sym->ns->proc_name->name))
1696 : : retval = false;
1697 : :
1698 : : /* Make sure that if it has the dimension attribute, that it is
1699 : : either assumed size or explicit shape. Deferred shape is already
1700 : : covered by the pointer/allocatable attribute. */
1701 : 4907 : if (sym->as != NULL && sym->as->type == AS_ASSUMED_SHAPE
1702 : 15926 : && !gfc_notify_std (GFC_STD_F2018, "Assumed-shape array %qs "
1703 : : "at %L as dummy argument to the BIND(C) "
1704 : : "procedure %qs at %L", sym->name,
1705 : : &(sym->declared_at),
1706 : : sym->ns->proc_name->name,
1707 : 1327 : &(sym->ns->proc_name->declared_at)))
1708 : : retval = false;
1709 : : }
1710 : : }
1711 : :
1712 : : return retval;
1713 : : }
1714 : :
1715 : :
1716 : :
1717 : : /* Function called by variable_decl() that adds a name to the symbol table. */
1718 : :
1719 : : static bool
1720 : 247447 : build_sym (const char *name, int elem, gfc_charlen *cl, bool cl_deferred,
1721 : : gfc_array_spec **as, locus *var_locus)
1722 : : {
1723 : 247447 : symbol_attribute attr;
1724 : 247447 : gfc_symbol *sym;
1725 : 247447 : int upper;
1726 : 247447 : gfc_symtree *st;
1727 : :
1728 : : /* Symbols in a submodule are host associated from the parent module or
1729 : : submodules. Therefore, they can be overridden by declarations in the
1730 : : submodule scope. Deal with this by attaching the existing symbol to
1731 : : a new symtree and recycling the old symtree with a new symbol... */
1732 : 247447 : st = gfc_find_symtree (gfc_current_ns->sym_root, name);
1733 : 247447 : if (st != NULL && gfc_state_stack->state == COMP_SUBMODULE
1734 : 12 : && st->n.sym != NULL
1735 : 12 : && st->n.sym->attr.host_assoc && st->n.sym->attr.used_in_submodule)
1736 : : {
1737 : 12 : gfc_symtree *s = gfc_get_unique_symtree (gfc_current_ns);
1738 : 12 : s->n.sym = st->n.sym;
1739 : 12 : sym = gfc_new_symbol (name, gfc_current_ns, var_locus);
1740 : :
1741 : 12 : st->n.sym = sym;
1742 : 12 : sym->refs++;
1743 : 12 : gfc_set_sym_referenced (sym);
1744 : 12 : }
1745 : : /* ...Otherwise generate a new symtree and new symbol. */
1746 : 247435 : else if (gfc_get_symbol (name, NULL, &sym, var_locus))
1747 : : return false;
1748 : :
1749 : : /* Check if the name has already been defined as a type. The
1750 : : first letter of the symtree will be in upper case then. Of
1751 : : course, this is only necessary if the upper case letter is
1752 : : actually different. */
1753 : :
1754 : 247447 : upper = TOUPPER(name[0]);
1755 : 247447 : if (upper != name[0])
1756 : : {
1757 : 246809 : char u_name[GFC_MAX_SYMBOL_LEN + 1];
1758 : 246809 : gfc_symtree *st;
1759 : :
1760 : 246809 : gcc_assert (strlen(name) <= GFC_MAX_SYMBOL_LEN);
1761 : 246809 : strcpy (u_name, name);
1762 : 246809 : u_name[0] = upper;
1763 : :
1764 : 246809 : st = gfc_find_symtree (gfc_current_ns->sym_root, u_name);
1765 : :
1766 : : /* STRUCTURE types can alias symbol names */
1767 : 246809 : if (st != 0 && st->n.sym->attr.flavor != FL_STRUCT)
1768 : : {
1769 : 1 : gfc_error ("Symbol %qs at %C also declared as a type at %L", name,
1770 : : &st->n.sym->declared_at);
1771 : 1 : return false;
1772 : : }
1773 : : }
1774 : :
1775 : : /* Start updating the symbol table. Add basic type attribute if present. */
1776 : 247446 : if (current_ts.type != BT_UNKNOWN
1777 : 247446 : && (sym->attr.implicit_type == 0
1778 : 185 : || !gfc_compare_types (&sym->ts, ¤t_ts))
1779 : 494711 : && !gfc_add_type (sym, ¤t_ts, var_locus))
1780 : : return false;
1781 : :
1782 : 247420 : if (sym->ts.type == BT_CHARACTER)
1783 : : {
1784 : 27792 : if (elem > 1)
1785 : 3932 : sym->ts.u.cl = gfc_new_charlen (sym->ns, cl);
1786 : : else
1787 : 23860 : sym->ts.u.cl = cl;
1788 : 27792 : sym->ts.deferred = cl_deferred;
1789 : : }
1790 : :
1791 : : /* Add dimension attribute if present. */
1792 : 247420 : if (!gfc_set_array_spec (sym, *as, var_locus))
1793 : : return false;
1794 : 247418 : *as = NULL;
1795 : :
1796 : : /* Add attribute to symbol. The copy is so that we can reset the
1797 : : dimension attribute. */
1798 : 247418 : attr = current_attr;
1799 : 247418 : attr.dimension = 0;
1800 : 247418 : attr.codimension = 0;
1801 : :
1802 : 247418 : if (!gfc_copy_attr (&sym->attr, &attr, var_locus))
1803 : : return false;
1804 : :
1805 : : /* Finish any work that may need to be done for the binding label,
1806 : : if it's a bind(c). The bind(c) attr is found before the symbol
1807 : : is made, and before the symbol name (for data decls), so the
1808 : : current_ts is holding the binding label, or nothing if the
1809 : : name= attr wasn't given. Therefore, test here if we're dealing
1810 : : with a bind(c) and make sure the binding label is set correctly. */
1811 : 247404 : if (sym->attr.is_bind_c == 1)
1812 : : {
1813 : 1189 : if (!sym->binding_label)
1814 : : {
1815 : : /* Set the binding label and verify that if a NAME= was specified
1816 : : then only one identifier was in the entity-decl-list. */
1817 : 136 : if (!set_binding_label (&sym->binding_label, sym->name,
1818 : : num_idents_on_line))
1819 : : return false;
1820 : : }
1821 : : }
1822 : :
1823 : : /* See if we know we're in a common block, and if it's a bind(c)
1824 : : common then we need to make sure we're an interoperable type. */
1825 : 247402 : if (sym->attr.in_common == 1)
1826 : : {
1827 : : /* Test the common block object. */
1828 : 613 : if (sym->common_block != NULL && sym->common_block->is_bind_c == 1
1829 : 6 : && sym->ts.is_c_interop != 1)
1830 : : {
1831 : 0 : gfc_error_now ("Variable %qs in common block %qs at %C "
1832 : : "must be declared with a C interoperable "
1833 : : "kind since common block %qs is BIND(C)",
1834 : : sym->name, sym->common_block->name,
1835 : 0 : sym->common_block->name);
1836 : 0 : gfc_clear_error ();
1837 : : }
1838 : : }
1839 : :
1840 : 247402 : sym->attr.implied_index = 0;
1841 : :
1842 : : /* Use the parameter expressions for a parameterized derived type. */
1843 : 247402 : if ((sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS)
1844 : 33789 : && sym->ts.u.derived->attr.pdt_type && type_param_spec_list)
1845 : 433 : sym->param_list = gfc_copy_actual_arglist (type_param_spec_list);
1846 : :
1847 : 247402 : if (sym->ts.type == BT_CLASS)
1848 : 10394 : return gfc_build_class_symbol (&sym->ts, &sym->attr, &sym->as);
1849 : :
1850 : : return true;
1851 : : }
1852 : :
1853 : :
1854 : : /* Set character constant to the given length. The constant will be padded or
1855 : : truncated. If we're inside an array constructor without a typespec, we
1856 : : additionally check that all elements have the same length; check_len -1
1857 : : means no checking. */
1858 : :
1859 : : void
1860 : 12606 : gfc_set_constant_character_len (gfc_charlen_t len, gfc_expr *expr,
1861 : : gfc_charlen_t check_len)
1862 : : {
1863 : 12606 : gfc_char_t *s;
1864 : 12606 : gfc_charlen_t slen;
1865 : :
1866 : 12606 : if (expr->ts.type != BT_CHARACTER)
1867 : : return;
1868 : :
1869 : 12605 : if (expr->expr_type != EXPR_CONSTANT)
1870 : : {
1871 : 1 : gfc_error_now ("CHARACTER length must be a constant at %L", &expr->where);
1872 : 1 : return;
1873 : : }
1874 : :
1875 : 12604 : slen = expr->value.character.length;
1876 : 12604 : if (len != slen)
1877 : : {
1878 : 1544 : s = gfc_get_wide_string (len + 1);
1879 : 1544 : memcpy (s, expr->value.character.string,
1880 : 1544 : MIN (len, slen) * sizeof (gfc_char_t));
1881 : 1544 : if (len > slen)
1882 : 1375 : gfc_wide_memset (&s[slen], ' ', len - slen);
1883 : :
1884 : 1544 : if (warn_character_truncation && slen > len)
1885 : 1 : gfc_warning_now (OPT_Wcharacter_truncation,
1886 : : "CHARACTER expression at %L is being truncated "
1887 : : "(%ld/%ld)", &expr->where,
1888 : : (long) slen, (long) len);
1889 : :
1890 : : /* Apply the standard by 'hand' otherwise it gets cleared for
1891 : : initializers. */
1892 : 1544 : if (check_len != -1 && slen != check_len)
1893 : : {
1894 : 3 : if (!(gfc_option.allow_std & GFC_STD_GNU))
1895 : 0 : gfc_error_now ("The CHARACTER elements of the array constructor "
1896 : : "at %L must have the same length (%ld/%ld)",
1897 : : &expr->where, (long) slen,
1898 : : (long) check_len);
1899 : : else
1900 : 3 : gfc_notify_std (GFC_STD_LEGACY,
1901 : : "The CHARACTER elements of the array constructor "
1902 : : "at %L must have the same length (%ld/%ld)",
1903 : : &expr->where, (long) slen,
1904 : : (long) check_len);
1905 : : }
1906 : :
1907 : 1544 : s[len] = '\0';
1908 : 1544 : free (expr->value.character.string);
1909 : 1544 : expr->value.character.string = s;
1910 : 1544 : expr->value.character.length = len;
1911 : : /* If explicit representation was given, clear it
1912 : : as it is no longer needed after padding. */
1913 : 1544 : if (expr->representation.length)
1914 : : {
1915 : 45 : expr->representation.length = 0;
1916 : 45 : free (expr->representation.string);
1917 : 45 : expr->representation.string = NULL;
1918 : : }
1919 : : }
1920 : : }
1921 : :
1922 : :
1923 : : /* Function to create and update the enumerator history
1924 : : using the information passed as arguments.
1925 : : Pointer "max_enum" is also updated, to point to
1926 : : enum history node containing largest initializer.
1927 : :
1928 : : SYM points to the symbol node of enumerator.
1929 : : INIT points to its enumerator value. */
1930 : :
1931 : : static void
1932 : 543 : create_enum_history (gfc_symbol *sym, gfc_expr *init)
1933 : : {
1934 : 543 : enumerator_history *new_enum_history;
1935 : 543 : gcc_assert (sym != NULL && init != NULL);
1936 : :
1937 : 543 : new_enum_history = XCNEW (enumerator_history);
1938 : :
1939 : 543 : new_enum_history->sym = sym;
1940 : 543 : new_enum_history->initializer = init;
1941 : 543 : new_enum_history->next = NULL;
1942 : :
1943 : 543 : if (enum_history == NULL)
1944 : : {
1945 : 160 : enum_history = new_enum_history;
1946 : 160 : max_enum = enum_history;
1947 : : }
1948 : : else
1949 : : {
1950 : 383 : new_enum_history->next = enum_history;
1951 : 383 : enum_history = new_enum_history;
1952 : :
1953 : 383 : if (mpz_cmp (max_enum->initializer->value.integer,
1954 : 383 : new_enum_history->initializer->value.integer) < 0)
1955 : 381 : max_enum = new_enum_history;
1956 : : }
1957 : 543 : }
1958 : :
1959 : :
1960 : : /* Function to free enum kind history. */
1961 : :
1962 : : void
1963 : 175 : gfc_free_enum_history (void)
1964 : : {
1965 : 175 : enumerator_history *current = enum_history;
1966 : 175 : enumerator_history *next;
1967 : :
1968 : 718 : while (current != NULL)
1969 : : {
1970 : 543 : next = current->next;
1971 : 543 : free (current);
1972 : 543 : current = next;
1973 : : }
1974 : 175 : max_enum = NULL;
1975 : 175 : enum_history = NULL;
1976 : 175 : }
1977 : :
1978 : :
1979 : : /* Function to fix initializer character length if the length of the
1980 : : symbol or component is constant. */
1981 : :
1982 : : static bool
1983 : 2554 : fix_initializer_charlen (gfc_typespec *ts, gfc_expr *init)
1984 : : {
1985 : 2554 : if (!gfc_specification_expr (ts->u.cl->length))
1986 : : return false;
1987 : :
1988 : 2554 : int k = gfc_validate_kind (BT_INTEGER, gfc_charlen_int_kind, false);
1989 : :
1990 : : /* resolve_charlen will complain later on if the length
1991 : : is too large. Just skip the initialization in that case. */
1992 : 2554 : if (mpz_cmp (ts->u.cl->length->value.integer,
1993 : 2554 : gfc_integer_kinds[k].huge) <= 0)
1994 : : {
1995 : 2553 : HOST_WIDE_INT len
1996 : 2553 : = gfc_mpz_get_hwi (ts->u.cl->length->value.integer);
1997 : :
1998 : 2553 : if (init->expr_type == EXPR_CONSTANT)
1999 : 1857 : gfc_set_constant_character_len (len, init, -1);
2000 : 696 : else if (init->expr_type == EXPR_ARRAY)
2001 : : {
2002 : 695 : gfc_constructor *cons;
2003 : :
2004 : : /* Build a new charlen to prevent simplification from
2005 : : deleting the length before it is resolved. */
2006 : 695 : init->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
2007 : 695 : init->ts.u.cl->length = gfc_copy_expr (ts->u.cl->length);
2008 : 695 : cons = gfc_constructor_first (init->value.constructor);
2009 : 4683 : for (; cons; cons = gfc_constructor_next (cons))
2010 : 3293 : gfc_set_constant_character_len (len, cons->expr, -1);
2011 : : }
2012 : : }
2013 : :
2014 : : return true;
2015 : : }
2016 : :
2017 : :
2018 : : /* Function called by variable_decl() that adds an initialization
2019 : : expression to a symbol. */
2020 : :
2021 : : static bool
2022 : 254732 : add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
2023 : : {
2024 : 254732 : symbol_attribute attr;
2025 : 254732 : gfc_symbol *sym;
2026 : 254732 : gfc_expr *init;
2027 : :
2028 : 254732 : init = *initp;
2029 : 254732 : if (find_special (name, &sym, false))
2030 : : return false;
2031 : :
2032 : 254732 : attr = sym->attr;
2033 : :
2034 : : /* If this symbol is confirming an implicit parameter type,
2035 : : then an initialization expression is not allowed. */
2036 : 254732 : if (attr.flavor == FL_PARAMETER && sym->value != NULL)
2037 : : {
2038 : 1 : if (*initp != NULL)
2039 : : {
2040 : 0 : gfc_error ("Initializer not allowed for PARAMETER %qs at %C",
2041 : : sym->name);
2042 : 0 : return false;
2043 : : }
2044 : : else
2045 : : return true;
2046 : : }
2047 : :
2048 : 254731 : if (init == NULL)
2049 : : {
2050 : : /* An initializer is required for PARAMETER declarations. */
2051 : 224073 : if (attr.flavor == FL_PARAMETER)
2052 : : {
2053 : 1 : gfc_error ("PARAMETER at %L is missing an initializer", var_locus);
2054 : 1 : return false;
2055 : : }
2056 : : }
2057 : : else
2058 : : {
2059 : : /* If a variable appears in a DATA block, it cannot have an
2060 : : initializer. */
2061 : 30658 : if (sym->attr.data)
2062 : : {
2063 : 0 : gfc_error ("Variable %qs at %C with an initializer already "
2064 : : "appears in a DATA statement", sym->name);
2065 : 0 : return false;
2066 : : }
2067 : :
2068 : : /* Check if the assignment can happen. This has to be put off
2069 : : until later for derived type variables and procedure pointers. */
2070 : 29613 : if (!gfc_bt_struct (sym->ts.type) && !gfc_bt_struct (init->ts.type)
2071 : 29590 : && sym->ts.type != BT_CLASS && init->ts.type != BT_CLASS
2072 : 29540 : && !sym->attr.proc_pointer
2073 : 60114 : && !gfc_check_assign_symbol (sym, NULL, init))
2074 : : return false;
2075 : :
2076 : 30627 : if (sym->ts.type == BT_CHARACTER && sym->ts.u.cl
2077 : 3172 : && init->ts.type == BT_CHARACTER)
2078 : : {
2079 : : /* Update symbol character length according initializer. */
2080 : 3062 : if (!gfc_check_assign_symbol (sym, NULL, init))
2081 : : return false;
2082 : :
2083 : 3062 : if (sym->ts.u.cl->length == NULL)
2084 : : {
2085 : 823 : gfc_charlen_t clen;
2086 : : /* If there are multiple CHARACTER variables declared on the
2087 : : same line, we don't want them to share the same length. */
2088 : 823 : sym->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
2089 : :
2090 : 823 : if (sym->attr.flavor == FL_PARAMETER)
2091 : : {
2092 : 814 : if (init->expr_type == EXPR_CONSTANT)
2093 : : {
2094 : 539 : clen = init->value.character.length;
2095 : 539 : sym->ts.u.cl->length
2096 : 539 : = gfc_get_int_expr (gfc_charlen_int_kind,
2097 : : NULL, clen);
2098 : : }
2099 : 275 : else if (init->expr_type == EXPR_ARRAY)
2100 : : {
2101 : 275 : if (init->ts.u.cl && init->ts.u.cl->length)
2102 : : {
2103 : 263 : const gfc_expr *length = init->ts.u.cl->length;
2104 : 263 : if (length->expr_type != EXPR_CONSTANT)
2105 : : {
2106 : 1 : gfc_error ("Cannot initialize parameter array "
2107 : : "at %L "
2108 : : "with variable length elements",
2109 : : &sym->declared_at);
2110 : 1 : return false;
2111 : : }
2112 : 262 : clen = mpz_get_si (length->value.integer);
2113 : 262 : }
2114 : 12 : else if (init->value.constructor)
2115 : : {
2116 : 12 : gfc_constructor *c;
2117 : 12 : c = gfc_constructor_first (init->value.constructor);
2118 : 12 : clen = c->expr->value.character.length;
2119 : : }
2120 : : else
2121 : 0 : gcc_unreachable ();
2122 : 274 : sym->ts.u.cl->length
2123 : 274 : = gfc_get_int_expr (gfc_charlen_int_kind,
2124 : : NULL, clen);
2125 : : }
2126 : 0 : else if (init->ts.u.cl && init->ts.u.cl->length)
2127 : 0 : sym->ts.u.cl->length =
2128 : 0 : gfc_copy_expr (init->ts.u.cl->length);
2129 : : }
2130 : : }
2131 : : /* Update initializer character length according to symbol. */
2132 : 2239 : else if (sym->ts.u.cl->length->expr_type == EXPR_CONSTANT
2133 : 2239 : && !fix_initializer_charlen (&sym->ts, init))
2134 : : return false;
2135 : : }
2136 : :
2137 : 30626 : if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension && sym->as
2138 : 3589 : && sym->as->rank && init->rank && init->rank != sym->as->rank)
2139 : : {
2140 : 3 : gfc_error ("Rank mismatch of array at %L and its initializer "
2141 : : "(%d/%d)", &sym->declared_at, sym->as->rank, init->rank);
2142 : 3 : return false;
2143 : : }
2144 : :
2145 : : /* If sym is implied-shape, set its upper bounds from init. */
2146 : 30623 : if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension
2147 : 3586 : && sym->as->type == AS_IMPLIED_SHAPE)
2148 : : {
2149 : 908 : int dim;
2150 : :
2151 : 908 : if (init->rank == 0)
2152 : : {
2153 : 1 : gfc_error ("Cannot initialize implied-shape array at %L"
2154 : : " with scalar", &sym->declared_at);
2155 : 1 : return false;
2156 : : }
2157 : :
2158 : : /* The shape may be NULL for EXPR_ARRAY, set it. */
2159 : 907 : if (init->shape == NULL)
2160 : : {
2161 : 5 : if (init->expr_type != EXPR_ARRAY)
2162 : : {
2163 : 2 : gfc_error ("Bad shape of initializer at %L", &init->where);
2164 : 2 : return false;
2165 : : }
2166 : :
2167 : 3 : init->shape = gfc_get_shape (1);
2168 : 3 : if (!gfc_array_size (init, &init->shape[0]))
2169 : : {
2170 : 1 : gfc_error ("Cannot determine shape of initializer at %L",
2171 : : &init->where);
2172 : 1 : free (init->shape);
2173 : 1 : init->shape = NULL;
2174 : 1 : return false;
2175 : : }
2176 : : }
2177 : :
2178 : 1897 : for (dim = 0; dim < sym->as->rank; ++dim)
2179 : : {
2180 : 994 : int k;
2181 : 994 : gfc_expr *e, *lower;
2182 : :
2183 : 994 : lower = sym->as->lower[dim];
2184 : :
2185 : : /* If the lower bound is an array element from another
2186 : : parameterized array, then it is marked with EXPR_VARIABLE and
2187 : : is an initialization expression. Try to reduce it. */
2188 : 994 : if (lower->expr_type == EXPR_VARIABLE)
2189 : 7 : gfc_reduce_init_expr (lower);
2190 : :
2191 : 994 : if (lower->expr_type == EXPR_CONSTANT)
2192 : : {
2193 : : /* All dimensions must be without upper bound. */
2194 : 993 : gcc_assert (!sym->as->upper[dim]);
2195 : :
2196 : 993 : k = lower->ts.kind;
2197 : 993 : e = gfc_get_constant_expr (BT_INTEGER, k, &sym->declared_at);
2198 : 993 : mpz_add (e->value.integer, lower->value.integer,
2199 : 993 : init->shape[dim]);
2200 : 993 : mpz_sub_ui (e->value.integer, e->value.integer, 1);
2201 : 993 : sym->as->upper[dim] = e;
2202 : : }
2203 : : else
2204 : : {
2205 : 1 : gfc_error ("Non-constant lower bound in implied-shape"
2206 : : " declaration at %L", &lower->where);
2207 : 1 : return false;
2208 : : }
2209 : : }
2210 : :
2211 : 903 : sym->as->type = AS_EXPLICIT;
2212 : : }
2213 : :
2214 : : /* Ensure that explicit bounds are simplified. */
2215 : 30618 : if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension
2216 : 3581 : && sym->as->type == AS_EXPLICIT)
2217 : : {
2218 : 7974 : for (int dim = 0; dim < sym->as->rank; ++dim)
2219 : : {
2220 : 4405 : gfc_expr *e;
2221 : :
2222 : 4405 : e = sym->as->lower[dim];
2223 : 4405 : if (e->expr_type != EXPR_CONSTANT)
2224 : 12 : gfc_reduce_init_expr (e);
2225 : :
2226 : 4405 : e = sym->as->upper[dim];
2227 : 4405 : if (e->expr_type != EXPR_CONSTANT)
2228 : 96 : gfc_reduce_init_expr (e);
2229 : : }
2230 : : }
2231 : :
2232 : : /* Need to check if the expression we initialized this
2233 : : to was one of the iso_c_binding named constants. If so,
2234 : : and we're a parameter (constant), let it be iso_c.
2235 : : For example:
2236 : : integer(c_int), parameter :: my_int = c_int
2237 : : integer(my_int) :: my_int_2
2238 : : If we mark my_int as iso_c (since we can see it's value
2239 : : is equal to one of the named constants), then my_int_2
2240 : : will be considered C interoperable. */
2241 : 30618 : if (sym->ts.type != BT_CHARACTER && !gfc_bt_struct (sym->ts.type))
2242 : : {
2243 : 26405 : sym->ts.is_iso_c |= init->ts.is_iso_c;
2244 : 26405 : sym->ts.is_c_interop |= init->ts.is_c_interop;
2245 : : /* attr bits needed for module files. */
2246 : 26405 : sym->attr.is_iso_c |= init->ts.is_iso_c;
2247 : 26405 : sym->attr.is_c_interop |= init->ts.is_c_interop;
2248 : 26405 : if (init->ts.is_iso_c)
2249 : 108 : sym->ts.f90_type = init->ts.f90_type;
2250 : : }
2251 : :
2252 : : /* Catch the case: type(t), parameter :: x = z'1'. */
2253 : 30618 : if (sym->ts.type == BT_DERIVED && init->ts.type == BT_BOZ)
2254 : : {
2255 : 1 : gfc_error ("Entity %qs at %L is incompatible with a BOZ "
2256 : : "literal constant", name, &sym->declared_at);
2257 : 1 : return false;
2258 : : }
2259 : :
2260 : : /* Add initializer. Make sure we keep the ranks sane. */
2261 : 30617 : if (sym->attr.dimension && init->rank == 0)
2262 : : {
2263 : 1175 : mpz_t size;
2264 : 1175 : gfc_expr *array;
2265 : 1175 : int n;
2266 : 1175 : if (sym->attr.flavor == FL_PARAMETER
2267 : 438 : && gfc_is_constant_expr (init)
2268 : 438 : && (init->expr_type == EXPR_CONSTANT
2269 : 31 : || init->expr_type == EXPR_STRUCTURE)
2270 : 1613 : && spec_size (sym->as, &size))
2271 : : {
2272 : 434 : array = gfc_get_array_expr (init->ts.type, init->ts.kind,
2273 : : &init->where);
2274 : 434 : if (init->ts.type == BT_DERIVED)
2275 : 31 : array->ts.u.derived = init->ts.u.derived;
2276 : 67549 : for (n = 0; n < (int)mpz_get_si (size); n++)
2277 : 133937 : gfc_constructor_append_expr (&array->value.constructor,
2278 : : n == 0
2279 : : ? init
2280 : 66822 : : gfc_copy_expr (init),
2281 : : &init->where);
2282 : :
2283 : 434 : array->shape = gfc_get_shape (sym->as->rank);
2284 : 994 : for (n = 0; n < sym->as->rank; n++)
2285 : 560 : spec_dimen_size (sym->as, n, &array->shape[n]);
2286 : :
2287 : 434 : init = array;
2288 : 434 : mpz_clear (size);
2289 : : }
2290 : 1175 : init->rank = sym->as->rank;
2291 : 1175 : init->corank = sym->as->corank;
2292 : : }
2293 : :
2294 : 30617 : sym->value = init;
2295 : 30617 : if (sym->attr.save == SAVE_NONE)
2296 : 26334 : sym->attr.save = SAVE_IMPLICIT;
2297 : 30617 : *initp = NULL;
2298 : : }
2299 : :
2300 : : return true;
2301 : : }
2302 : :
2303 : :
2304 : : /* Function called by variable_decl() that adds a name to a structure
2305 : : being built. */
2306 : :
2307 : : static bool
2308 : 16434 : build_struct (const char *name, gfc_charlen *cl, gfc_expr **init,
2309 : : gfc_array_spec **as)
2310 : : {
2311 : 16434 : gfc_state_data *s;
2312 : 16434 : gfc_component *c;
2313 : :
2314 : : /* F03:C438/C439. If the current symbol is of the same derived type that we're
2315 : : constructing, it must have the pointer attribute. */
2316 : 16434 : if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS)
2317 : 3031 : && current_ts.u.derived == gfc_current_block ()
2318 : 226 : && current_attr.pointer == 0)
2319 : : {
2320 : 66 : if (current_attr.allocatable
2321 : 66 : && !gfc_notify_std(GFC_STD_F2008, "Component at %C "
2322 : : "must have the POINTER attribute"))
2323 : : {
2324 : : return false;
2325 : : }
2326 : 65 : else if (current_attr.allocatable == 0)
2327 : : {
2328 : 0 : gfc_error ("Component at %C must have the POINTER attribute");
2329 : 0 : return false;
2330 : : }
2331 : : }
2332 : :
2333 : : /* F03:C437. */
2334 : 16433 : if (current_ts.type == BT_CLASS
2335 : 787 : && !(current_attr.pointer || current_attr.allocatable))
2336 : : {
2337 : 5 : gfc_error ("Component %qs with CLASS at %C must be allocatable "
2338 : : "or pointer", name);
2339 : 5 : return false;
2340 : : }
2341 : :
2342 : 16428 : if (gfc_current_block ()->attr.pointer && (*as)->rank != 0)
2343 : : {
2344 : 0 : if ((*as)->type != AS_DEFERRED && (*as)->type != AS_EXPLICIT)
2345 : : {
2346 : 0 : gfc_error ("Array component of structure at %C must have explicit "
2347 : : "or deferred shape");
2348 : 0 : return false;
2349 : : }
2350 : : }
2351 : :
2352 : : /* If we are in a nested union/map definition, gfc_add_component will not
2353 : : properly find repeated components because:
2354 : : (i) gfc_add_component does a flat search, where components of unions
2355 : : and maps are implicity chained so nested components may conflict.
2356 : : (ii) Unions and maps are not linked as components of their parent
2357 : : structures until after they are parsed.
2358 : : For (i) we use gfc_find_component which searches recursively, and for (ii)
2359 : : we search each block directly from the parse stack until we find the top
2360 : : level structure. */
2361 : :
2362 : 16428 : s = gfc_state_stack;
2363 : 16428 : if (s->state == COMP_UNION || s->state == COMP_MAP)
2364 : : {
2365 : 1434 : while (s->state == COMP_UNION || gfc_comp_struct (s->state))
2366 : : {
2367 : 1434 : c = gfc_find_component (s->sym, name, true, true, NULL);
2368 : 1434 : if (c != NULL)
2369 : : {
2370 : 0 : gfc_error_now ("Component %qs at %C already declared at %L",
2371 : : name, &c->loc);
2372 : 0 : return false;
2373 : : }
2374 : : /* Break after we've searched the entire chain. */
2375 : 1434 : if (s->state == COMP_DERIVED || s->state == COMP_STRUCTURE)
2376 : : break;
2377 : 1000 : s = s->previous;
2378 : : }
2379 : : }
2380 : :
2381 : 16428 : if (!gfc_add_component (gfc_current_block(), name, &c))
2382 : : return false;
2383 : :
2384 : 16422 : c->ts = current_ts;
2385 : 16422 : if (c->ts.type == BT_CHARACTER)
2386 : 1866 : c->ts.u.cl = cl;
2387 : :
2388 : 16422 : if (c->ts.type != BT_CLASS && c->ts.type != BT_DERIVED
2389 : 13397 : && (c->ts.kind == 0 || c->ts.type == BT_CHARACTER)
2390 : 1943 : && saved_kind_expr != NULL)
2391 : 91 : c->kind_expr = gfc_copy_expr (saved_kind_expr);
2392 : :
2393 : 16422 : c->attr = current_attr;
2394 : :
2395 : 16422 : c->initializer = *init;
2396 : 16422 : *init = NULL;
2397 : :
2398 : : /* Update initializer character length according to component. */
2399 : 1866 : if (c->ts.type == BT_CHARACTER && c->ts.u.cl->length
2400 : 1484 : && c->ts.u.cl->length->expr_type == EXPR_CONSTANT
2401 : 1438 : && c->initializer && c->initializer->ts.type == BT_CHARACTER
2402 : 16740 : && !fix_initializer_charlen (&c->ts, c->initializer))
2403 : : return false;
2404 : :
2405 : 16422 : c->as = *as;
2406 : 16422 : if (c->as != NULL)
2407 : : {
2408 : 4137 : if (c->as->corank)
2409 : 93 : c->attr.codimension = 1;
2410 : 4137 : if (c->as->rank)
2411 : 4068 : c->attr.dimension = 1;
2412 : : }
2413 : 16422 : *as = NULL;
2414 : :
2415 : 16422 : gfc_apply_init (&c->ts, &c->attr, c->initializer);
2416 : :
2417 : : /* Check array components. */
2418 : 16422 : if (!c->attr.dimension)
2419 : 12354 : goto scalar;
2420 : :
2421 : 4068 : if (c->attr.pointer)
2422 : : {
2423 : 659 : if (c->as->type != AS_DEFERRED)
2424 : : {
2425 : 5 : gfc_error ("Pointer array component of structure at %C must have a "
2426 : : "deferred shape");
2427 : 5 : return false;
2428 : : }
2429 : : }
2430 : 3409 : else if (c->attr.allocatable)
2431 : : {
2432 : 1939 : const char *err = G_("Allocatable component of structure at %C must have "
2433 : : "a deferred shape");
2434 : 1939 : if (c->as->type != AS_DEFERRED)
2435 : : {
2436 : 14 : if (c->ts.type == BT_CLASS || c->ts.type == BT_DERIVED)
2437 : : {
2438 : : /* Issue an immediate error and allow this component to pass for
2439 : : the sake of clean error recovery. Set the error flag for the
2440 : : containing derived type so that finalizers are not built. */
2441 : 4 : gfc_error_now (err);
2442 : 4 : s->sym->error = 1;
2443 : 4 : c->as->type = AS_DEFERRED;
2444 : : }
2445 : : else
2446 : : {
2447 : 10 : gfc_error (err);
2448 : 10 : return false;
2449 : : }
2450 : : }
2451 : : }
2452 : : else
2453 : : {
2454 : 1470 : if (c->as->type != AS_EXPLICIT)
2455 : : {
2456 : 7 : gfc_error ("Array component of structure at %C must have an "
2457 : : "explicit shape");
2458 : 7 : return false;
2459 : : }
2460 : : }
2461 : :
2462 : 1463 : scalar:
2463 : 16400 : if (c->ts.type == BT_CLASS)
2464 : 779 : return gfc_build_class_symbol (&c->ts, &c->attr, &c->as);
2465 : :
2466 : 15621 : if (c->attr.pdt_kind || c->attr.pdt_len)
2467 : : {
2468 : 310 : gfc_symbol *sym;
2469 : 310 : gfc_find_symbol (c->name, gfc_current_block ()->f2k_derived,
2470 : : 0, &sym);
2471 : 310 : if (sym == NULL)
2472 : : {
2473 : 0 : gfc_error ("Type parameter %qs at %C has no corresponding entry "
2474 : : "in the type parameter name list at %L",
2475 : 0 : c->name, &gfc_current_block ()->declared_at);
2476 : 0 : return false;
2477 : : }
2478 : 310 : sym->ts = c->ts;
2479 : 310 : sym->attr.pdt_kind = c->attr.pdt_kind;
2480 : 310 : sym->attr.pdt_len = c->attr.pdt_len;
2481 : 310 : if (c->initializer)
2482 : 104 : sym->value = gfc_copy_expr (c->initializer);
2483 : 310 : sym->attr.flavor = FL_VARIABLE;
2484 : : }
2485 : :
2486 : 15621 : if ((c->ts.type == BT_DERIVED || c->ts.type == BT_CLASS)
2487 : 2243 : && c->ts.u.derived && c->ts.u.derived->attr.pdt_template
2488 : 39 : && decl_type_param_list)
2489 : 39 : c->param_list = gfc_copy_actual_arglist (decl_type_param_list);
2490 : :
2491 : : return true;
2492 : : }
2493 : :
2494 : :
2495 : : /* Match a 'NULL()', and possibly take care of some side effects. */
2496 : :
2497 : : match
2498 : 1578 : gfc_match_null (gfc_expr **result)
2499 : : {
2500 : 1578 : gfc_symbol *sym;
2501 : 1578 : match m, m2 = MATCH_NO;
2502 : :
2503 : 1578 : if ((m = gfc_match (" null ( )")) == MATCH_ERROR)
2504 : : return MATCH_ERROR;
2505 : :
2506 : 1578 : if (m == MATCH_NO)
2507 : : {
2508 : 503 : locus old_loc;
2509 : 503 : char name[GFC_MAX_SYMBOL_LEN + 1];
2510 : :
2511 : 503 : if ((m2 = gfc_match (" null (")) != MATCH_YES)
2512 : 497 : return m2;
2513 : :
2514 : 6 : old_loc = gfc_current_locus;
2515 : 6 : if ((m2 = gfc_match (" %n ) ", name)) == MATCH_ERROR)
2516 : : return MATCH_ERROR;
2517 : 6 : if (m2 != MATCH_YES
2518 : 6 : && ((m2 = gfc_match (" mold = %n )", name)) == MATCH_ERROR))
2519 : : return MATCH_ERROR;
2520 : 6 : if (m2 == MATCH_NO)
2521 : : {
2522 : 0 : gfc_current_locus = old_loc;
2523 : 0 : return MATCH_NO;
2524 : : }
2525 : : }
2526 : :
2527 : : /* The NULL symbol now has to be/become an intrinsic function. */
2528 : 1081 : if (gfc_get_symbol ("null", NULL, &sym))
2529 : : {
2530 : 0 : gfc_error ("NULL() initialization at %C is ambiguous");
2531 : 0 : return MATCH_ERROR;
2532 : : }
2533 : :
2534 : 1081 : gfc_intrinsic_symbol (sym);
2535 : :
2536 : 1081 : if (sym->attr.proc != PROC_INTRINSIC
2537 : 782 : && !(sym->attr.use_assoc && sym->attr.intrinsic)
2538 : 1862 : && (!gfc_add_procedure(&sym->attr, PROC_INTRINSIC, sym->name, NULL)
2539 : 781 : || !gfc_add_function (&sym->attr, sym->name, NULL)))
2540 : 0 : return MATCH_ERROR;
2541 : :
2542 : 1081 : *result = gfc_get_null_expr (&gfc_current_locus);
2543 : :
2544 : : /* Invalid per F2008, C512. */
2545 : 1081 : if (m2 == MATCH_YES)
2546 : : {
2547 : 6 : gfc_error ("NULL() initialization at %C may not have MOLD");
2548 : 6 : return MATCH_ERROR;
2549 : : }
2550 : :
2551 : : return MATCH_YES;
2552 : : }
2553 : :
2554 : :
2555 : : /* Match the initialization expr for a data pointer or procedure pointer. */
2556 : :
2557 : : static match
2558 : 1242 : match_pointer_init (gfc_expr **init, int procptr)
2559 : : {
2560 : 1242 : match m;
2561 : :
2562 : 1242 : if (gfc_pure (NULL) && !gfc_comp_struct (gfc_state_stack->state))
2563 : : {
2564 : 1 : gfc_error ("Initialization of pointer at %C is not allowed in "
2565 : : "a PURE procedure");
2566 : 1 : return MATCH_ERROR;
2567 : : }
2568 : 1241 : gfc_unset_implicit_pure (gfc_current_ns->proc_name);
2569 : :
2570 : : /* Match NULL() initialization. */
2571 : 1241 : m = gfc_match_null (init);
2572 : 1241 : if (m != MATCH_NO)
2573 : : return m;
2574 : :
2575 : : /* Match non-NULL initialization. */
2576 : 168 : gfc_matching_ptr_assignment = !procptr;
2577 : 168 : gfc_matching_procptr_assignment = procptr;
2578 : 168 : m = gfc_match_rvalue (init);
2579 : 168 : gfc_matching_ptr_assignment = 0;
2580 : 168 : gfc_matching_procptr_assignment = 0;
2581 : 168 : if (m == MATCH_ERROR)
2582 : : return MATCH_ERROR;
2583 : 167 : else if (m == MATCH_NO)
2584 : : {
2585 : 2 : gfc_error ("Error in pointer initialization at %C");
2586 : 2 : return MATCH_ERROR;
2587 : : }
2588 : :
2589 : 165 : if (!procptr && !gfc_resolve_expr (*init))
2590 : : return MATCH_ERROR;
2591 : :
2592 : 164 : if (!gfc_notify_std (GFC_STD_F2008, "non-NULL pointer "
2593 : : "initialization at %C"))
2594 : : return MATCH_ERROR;
2595 : :
2596 : : return MATCH_YES;
2597 : : }
2598 : :
2599 : :
2600 : : static bool
2601 : 273588 : check_function_name (char *name)
2602 : : {
2603 : : /* In functions that have a RESULT variable defined, the function name always
2604 : : refers to function calls. Therefore, the name is not allowed to appear in
2605 : : specification statements. When checking this, be careful about
2606 : : 'hidden' procedure pointer results ('ppr@'). */
2607 : :
2608 : 273588 : if (gfc_current_state () == COMP_FUNCTION)
2609 : : {
2610 : 43604 : gfc_symbol *block = gfc_current_block ();
2611 : 43604 : if (block && block->result && block->result != block
2612 : 14489 : && strcmp (block->result->name, "ppr@") != 0
2613 : 14430 : && strcmp (block->name, name) == 0)
2614 : : {
2615 : 9 : gfc_error ("RESULT variable %qs at %L prohibits FUNCTION name %qs at %C "
2616 : : "from appearing in a specification statement",
2617 : : block->result->name, &block->result->declared_at, name);
2618 : 9 : return false;
2619 : : }
2620 : : }
2621 : :
2622 : : return true;
2623 : : }
2624 : :
2625 : :
2626 : : /* Match a variable name with an optional initializer. When this
2627 : : subroutine is called, a variable is expected to be parsed next.
2628 : : Depending on what is happening at the moment, updates either the
2629 : : symbol table or the current interface. */
2630 : :
2631 : : static match
2632 : 263563 : variable_decl (int elem)
2633 : : {
2634 : 263563 : char name[GFC_MAX_SYMBOL_LEN + 1];
2635 : 263563 : static unsigned int fill_id = 0;
2636 : 263563 : gfc_expr *initializer, *char_len;
2637 : 263563 : gfc_array_spec *as;
2638 : 263563 : gfc_array_spec *cp_as; /* Extra copy for Cray Pointees. */
2639 : 263563 : gfc_charlen *cl;
2640 : 263563 : bool cl_deferred;
2641 : 263563 : locus var_locus;
2642 : 263563 : match m;
2643 : 263563 : bool t;
2644 : 263563 : gfc_symbol *sym;
2645 : 263563 : char c;
2646 : :
2647 : 263563 : initializer = NULL;
2648 : 263563 : as = NULL;
2649 : 263563 : cp_as = NULL;
2650 : :
2651 : : /* When we get here, we've just matched a list of attributes and
2652 : : maybe a type and a double colon. The next thing we expect to see
2653 : : is the name of the symbol. */
2654 : :
2655 : : /* If we are parsing a structure with legacy support, we allow the symbol
2656 : : name to be '%FILL' which gives it an anonymous (inaccessible) name. */
2657 : 263563 : m = MATCH_NO;
2658 : 263563 : gfc_gobble_whitespace ();
2659 : 263563 : var_locus = gfc_current_locus;
2660 : 263563 : c = gfc_peek_ascii_char ();
2661 : 263563 : if (c == '%')
2662 : : {
2663 : 12 : gfc_next_ascii_char (); /* Burn % character. */
2664 : 12 : m = gfc_match ("fill");
2665 : 12 : if (m == MATCH_YES)
2666 : : {
2667 : 11 : if (gfc_current_state () != COMP_STRUCTURE)
2668 : : {
2669 : 2 : if (flag_dec_structure)
2670 : 1 : gfc_error ("%qs not allowed outside STRUCTURE at %C", "%FILL");
2671 : : else
2672 : 1 : gfc_error ("%qs at %C is a DEC extension, enable with "
2673 : : "%<-fdec-structure%>", "%FILL");
2674 : 2 : m = MATCH_ERROR;
2675 : 2 : goto cleanup;
2676 : : }
2677 : :
2678 : 9 : if (attr_seen)
2679 : : {
2680 : 1 : gfc_error ("%qs entity cannot have attributes at %C", "%FILL");
2681 : 1 : m = MATCH_ERROR;
2682 : 1 : goto cleanup;
2683 : : }
2684 : :
2685 : : /* %FILL components are given invalid fortran names. */
2686 : 8 : snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "%%FILL%u", fill_id++);
2687 : : }
2688 : : else
2689 : : {
2690 : 1 : gfc_error ("Invalid character %qc in variable name at %C", c);
2691 : 1 : return MATCH_ERROR;
2692 : : }
2693 : : }
2694 : : else
2695 : : {
2696 : 263551 : m = gfc_match_name (name);
2697 : 263550 : if (m != MATCH_YES)
2698 : 10 : goto cleanup;
2699 : : }
2700 : :
2701 : : /* Now we could see the optional array spec. or character length. */
2702 : 263548 : m = gfc_match_array_spec (&as, true, true);
2703 : 263547 : if (m == MATCH_ERROR)
2704 : 56 : goto cleanup;
2705 : :
2706 : 263491 : if (m == MATCH_NO)
2707 : 205792 : as = gfc_copy_array_spec (current_as);
2708 : 57699 : else if (current_as
2709 : 57699 : && !merge_array_spec (current_as, as, true))
2710 : : {
2711 : 4 : m = MATCH_ERROR;
2712 : 4 : goto cleanup;
2713 : : }
2714 : :
2715 : 263487 : var_locus = gfc_get_location_range (NULL, 0, &var_locus, 1,
2716 : : &gfc_current_locus);
2717 : 263487 : if (flag_cray_pointer)
2718 : 3063 : cp_as = gfc_copy_array_spec (as);
2719 : :
2720 : : /* At this point, we know for sure if the symbol is PARAMETER and can thus
2721 : : determine (and check) whether it can be implied-shape. If it
2722 : : was parsed as assumed-size, change it because PARAMETERs cannot
2723 : : be assumed-size.
2724 : :
2725 : : An explicit-shape-array cannot appear under several conditions.
2726 : : That check is done here as well. */
2727 : 263487 : if (as)
2728 : : {
2729 : 79183 : if (as->type == AS_IMPLIED_SHAPE && current_attr.flavor != FL_PARAMETER)
2730 : : {
2731 : 2 : m = MATCH_ERROR;
2732 : 2 : gfc_error ("Non-PARAMETER symbol %qs at %L cannot be implied-shape",
2733 : : name, &var_locus);
2734 : 2 : goto cleanup;
2735 : : }
2736 : :
2737 : 79181 : if (as->type == AS_ASSUMED_SIZE && as->rank == 1
2738 : 5971 : && current_attr.flavor == FL_PARAMETER)
2739 : 872 : as->type = AS_IMPLIED_SHAPE;
2740 : :
2741 : 79181 : if (as->type == AS_IMPLIED_SHAPE
2742 : 79181 : && !gfc_notify_std (GFC_STD_F2008, "Implied-shape array at %L",
2743 : : &var_locus))
2744 : : {
2745 : 1 : m = MATCH_ERROR;
2746 : 1 : goto cleanup;
2747 : : }
2748 : :
2749 : 79180 : gfc_seen_div0 = false;
2750 : :
2751 : : /* F2018:C830 (R816) An explicit-shape-spec whose bounds are not
2752 : : constant expressions shall appear only in a subprogram, derived
2753 : : type definition, BLOCK construct, or interface body. */
2754 : 79180 : if (as->type == AS_EXPLICIT
2755 : 40179 : && gfc_current_state () != COMP_BLOCK
2756 : : && gfc_current_state () != COMP_DERIVED
2757 : : && gfc_current_state () != COMP_FUNCTION
2758 : : && gfc_current_state () != COMP_INTERFACE
2759 : : && gfc_current_state () != COMP_SUBROUTINE)
2760 : : {
2761 : : gfc_expr *e;
2762 : 48087 : bool not_constant = false;
2763 : :
2764 : 48087 : for (int i = 0; i < as->rank; i++)
2765 : : {
2766 : 27416 : e = gfc_copy_expr (as->lower[i]);
2767 : 27416 : if (!gfc_resolve_expr (e) && gfc_seen_div0)
2768 : : {
2769 : 0 : m = MATCH_ERROR;
2770 : 0 : goto cleanup;
2771 : : }
2772 : :
2773 : 27416 : gfc_simplify_expr (e, 0);
2774 : 27416 : if (e && (e->expr_type != EXPR_CONSTANT))
2775 : : {
2776 : : not_constant = true;
2777 : : break;
2778 : : }
2779 : 27416 : gfc_free_expr (e);
2780 : :
2781 : 27416 : e = gfc_copy_expr (as->upper[i]);
2782 : 27416 : if (!gfc_resolve_expr (e) && gfc_seen_div0)
2783 : : {
2784 : 4 : m = MATCH_ERROR;
2785 : 4 : goto cleanup;
2786 : : }
2787 : :
2788 : 27412 : gfc_simplify_expr (e, 0);
2789 : 27412 : if (e && (e->expr_type != EXPR_CONSTANT))
2790 : : {
2791 : : not_constant = true;
2792 : : break;
2793 : : }
2794 : 27399 : gfc_free_expr (e);
2795 : : }
2796 : :
2797 : 20684 : if (not_constant && e->ts.type != BT_INTEGER)
2798 : : {
2799 : 4 : gfc_error ("Explicit array shape at %C must be constant of "
2800 : : "INTEGER type and not %s type",
2801 : : gfc_basic_typename (e->ts.type));
2802 : 4 : m = MATCH_ERROR;
2803 : 4 : goto cleanup;
2804 : : }
2805 : 9 : if (not_constant)
2806 : : {
2807 : 9 : gfc_error ("Explicit shaped array with nonconstant bounds at %C");
2808 : 9 : m = MATCH_ERROR;
2809 : 9 : goto cleanup;
2810 : : }
2811 : : }
2812 : 79163 : if (as->type == AS_EXPLICIT)
2813 : : {
2814 : 96138 : for (int i = 0; i < as->rank; i++)
2815 : : {
2816 : 55976 : gfc_expr *e, *n;
2817 : 55976 : e = as->lower[i];
2818 : 55976 : if (e->expr_type != EXPR_CONSTANT)
2819 : : {
2820 : 430 : n = gfc_copy_expr (e);
2821 : 430 : if (!gfc_simplify_expr (n, 1) && gfc_seen_div0)
2822 : : {
2823 : 0 : m = MATCH_ERROR;
2824 : 0 : goto cleanup;
2825 : : }
2826 : :
2827 : 430 : if (n->expr_type == EXPR_CONSTANT)
2828 : 22 : gfc_replace_expr (e, n);
2829 : : else
2830 : 408 : gfc_free_expr (n);
2831 : : }
2832 : 55976 : e = as->upper[i];
2833 : 55976 : if (e->expr_type != EXPR_CONSTANT)
2834 : : {
2835 : 6422 : n = gfc_copy_expr (e);
2836 : 6422 : if (!gfc_simplify_expr (n, 1) && gfc_seen_div0)
2837 : : {
2838 : 0 : m = MATCH_ERROR;
2839 : 0 : goto cleanup;
2840 : : }
2841 : :
2842 : 6422 : if (n->expr_type == EXPR_CONSTANT)
2843 : 45 : gfc_replace_expr (e, n);
2844 : : else
2845 : 6377 : gfc_free_expr (n);
2846 : : }
2847 : : /* For an explicit-shape spec with constant bounds, ensure
2848 : : that the effective upper bound is not lower than the
2849 : : respective lower bound minus one. Otherwise adjust it so
2850 : : that the extent is trivially derived to be zero. */
2851 : 55976 : if (as->lower[i]->expr_type == EXPR_CONSTANT
2852 : 55568 : && as->upper[i]->expr_type == EXPR_CONSTANT
2853 : 49593 : && as->lower[i]->ts.type == BT_INTEGER
2854 : 49593 : && as->upper[i]->ts.type == BT_INTEGER
2855 : 49588 : && mpz_cmp (as->upper[i]->value.integer,
2856 : 49588 : as->lower[i]->value.integer) < 0)
2857 : 1205 : mpz_sub_ui (as->upper[i]->value.integer,
2858 : : as->lower[i]->value.integer, 1);
2859 : : }
2860 : : }
2861 : : }
2862 : :
2863 : 263467 : char_len = NULL;
2864 : 263467 : cl = NULL;
2865 : 263467 : cl_deferred = false;
2866 : :
2867 : 263467 : if (current_ts.type == BT_CHARACTER)
2868 : : {
2869 : 29698 : switch (match_char_length (&char_len, &cl_deferred, false))
2870 : : {
2871 : 435 : case MATCH_YES:
2872 : 435 : cl = gfc_new_charlen (gfc_current_ns, NULL);
2873 : :
2874 : 435 : cl->length = char_len;
2875 : 435 : break;
2876 : :
2877 : : /* Non-constant lengths need to be copied after the first
2878 : : element. Also copy assumed lengths. */
2879 : 29262 : case MATCH_NO:
2880 : 29262 : if (elem > 1
2881 : 3697 : && (current_ts.u.cl->length == NULL
2882 : 2546 : || current_ts.u.cl->length->expr_type != EXPR_CONSTANT))
2883 : : {
2884 : 1206 : cl = gfc_new_charlen (gfc_current_ns, NULL);
2885 : 1206 : cl->length = gfc_copy_expr (current_ts.u.cl->length);
2886 : : }
2887 : : else
2888 : 28056 : cl = current_ts.u.cl;
2889 : :
2890 : 29262 : cl_deferred = current_ts.deferred;
2891 : :
2892 : 29262 : break;
2893 : :
2894 : 1 : case MATCH_ERROR:
2895 : 1 : goto cleanup;
2896 : : }
2897 : : }
2898 : :
2899 : : /* The dummy arguments and result of the abbreviated form of MODULE
2900 : : PROCEDUREs, used in SUBMODULES should not be redefined. */
2901 : 263466 : if (gfc_current_ns->proc_name
2902 : 259064 : && gfc_current_ns->proc_name->abr_modproc_decl)
2903 : : {
2904 : 44 : gfc_find_symbol (name, gfc_current_ns, 1, &sym);
2905 : 44 : if (sym != NULL && (sym->attr.dummy || sym->attr.result))
2906 : : {
2907 : 2 : m = MATCH_ERROR;
2908 : 2 : gfc_error ("%qs at %L is a redefinition of the declaration "
2909 : : "in the corresponding interface for MODULE "
2910 : : "PROCEDURE %qs", sym->name, &var_locus,
2911 : 2 : gfc_current_ns->proc_name->name);
2912 : 2 : goto cleanup;
2913 : : }
2914 : : }
2915 : :
2916 : : /* %FILL components may not have initializers. */
2917 : 263464 : if (startswith (name, "%FILL") && gfc_match_eos () != MATCH_YES)
2918 : : {
2919 : 1 : gfc_error ("%qs entity cannot have an initializer at %L", "%FILL",
2920 : : &var_locus);
2921 : 1 : m = MATCH_ERROR;
2922 : 1 : goto cleanup;
2923 : : }
2924 : :
2925 : : /* If this symbol has already shown up in a Cray Pointer declaration,
2926 : : and this is not a component declaration,
2927 : : then we want to set the type & bail out. */
2928 : 263463 : if (flag_cray_pointer && !gfc_comp_struct (gfc_current_state ()))
2929 : : {
2930 : 2959 : gfc_find_symbol (name, gfc_current_ns, 0, &sym);
2931 : 2959 : if (sym != NULL && sym->attr.cray_pointee)
2932 : : {
2933 : 101 : m = MATCH_YES;
2934 : 101 : if (!gfc_add_type (sym, ¤t_ts, &gfc_current_locus))
2935 : : {
2936 : 1 : m = MATCH_ERROR;
2937 : 1 : goto cleanup;
2938 : : }
2939 : :
2940 : : /* Check to see if we have an array specification. */
2941 : 100 : if (cp_as != NULL)
2942 : : {
2943 : 49 : if (sym->as != NULL)
2944 : : {
2945 : 1 : gfc_error ("Duplicate array spec for Cray pointee at %L", &var_locus);
2946 : 1 : gfc_free_array_spec (cp_as);
2947 : 1 : m = MATCH_ERROR;
2948 : 1 : goto cleanup;
2949 : : }
2950 : : else
2951 : : {
2952 : 48 : if (!gfc_set_array_spec (sym, cp_as, &var_locus))
2953 : 0 : gfc_internal_error ("Cannot set pointee array spec.");
2954 : :
2955 : : /* Fix the array spec. */
2956 : 48 : m = gfc_mod_pointee_as (sym->as);
2957 : 48 : if (m == MATCH_ERROR)
2958 : 0 : goto cleanup;
2959 : : }
2960 : : }
2961 : 99 : goto cleanup;
2962 : : }
2963 : : else
2964 : : {
2965 : 2858 : gfc_free_array_spec (cp_as);
2966 : : }
2967 : : }
2968 : :
2969 : : /* Procedure pointer as function result. */
2970 : 263362 : if (gfc_current_state () == COMP_FUNCTION
2971 : 42251 : && strcmp ("ppr@", gfc_current_block ()->name) == 0
2972 : 25 : && strcmp (name, gfc_current_block ()->ns->proc_name->name) == 0)
2973 : 7 : strcpy (name, "ppr@");
2974 : :
2975 : 263362 : if (gfc_current_state () == COMP_FUNCTION
2976 : 42251 : && strcmp (name, gfc_current_block ()->name) == 0
2977 : 7198 : && gfc_current_block ()->result
2978 : 7198 : && strcmp ("ppr@", gfc_current_block ()->result->name) == 0)
2979 : 16 : strcpy (name, "ppr@");
2980 : :
2981 : : /* OK, we've successfully matched the declaration. Now put the
2982 : : symbol in the current namespace, because it might be used in the
2983 : : optional initialization expression for this symbol, e.g. this is
2984 : : perfectly legal:
2985 : :
2986 : : integer, parameter :: i = huge(i)
2987 : :
2988 : : This is only true for parameters or variables of a basic type.
2989 : : For components of derived types, it is not true, so we don't
2990 : : create a symbol for those yet. If we fail to create the symbol,
2991 : : bail out. */
2992 : 263362 : if (!gfc_comp_struct (gfc_current_state ())
2993 : 246899 : && !build_sym (name, elem, cl, cl_deferred, &as, &var_locus))
2994 : : {
2995 : 45 : m = MATCH_ERROR;
2996 : 45 : goto cleanup;
2997 : : }
2998 : :
2999 : 263317 : if (!check_function_name (name))
3000 : : {
3001 : 0 : m = MATCH_ERROR;
3002 : 0 : goto cleanup;
3003 : : }
3004 : :
3005 : : /* We allow old-style initializations of the form
3006 : : integer i /2/, j(4) /3*3, 1/
3007 : : (if no colon has been seen). These are different from data
3008 : : statements in that initializers are only allowed to apply to the
3009 : : variable immediately preceding, i.e.
3010 : : integer i, j /1, 2/
3011 : : is not allowed. Therefore we have to do some work manually, that
3012 : : could otherwise be left to the matchers for DATA statements. */
3013 : :
3014 : 263317 : if (!colon_seen && gfc_match (" /") == MATCH_YES)
3015 : : {
3016 : 146 : if (!gfc_notify_std (GFC_STD_GNU, "Old-style "
3017 : : "initialization at %C"))
3018 : : return MATCH_ERROR;
3019 : :
3020 : : /* Allow old style initializations for components of STRUCTUREs and MAPs
3021 : : but not components of derived types. */
3022 : 146 : else if (gfc_current_state () == COMP_DERIVED)
3023 : : {
3024 : 2 : gfc_error ("Invalid old style initialization for derived type "
3025 : : "component at %C");
3026 : 2 : m = MATCH_ERROR;
3027 : 2 : goto cleanup;
3028 : : }
3029 : :
3030 : : /* For structure components, read the initializer as a special
3031 : : expression and let the rest of this function apply the initializer
3032 : : as usual. */
3033 : 144 : else if (gfc_comp_struct (gfc_current_state ()))
3034 : : {
3035 : 74 : m = match_clist_expr (&initializer, ¤t_ts, as);
3036 : 74 : if (m == MATCH_NO)
3037 : : gfc_error ("Syntax error in old style initialization of %s at %C",
3038 : : name);
3039 : 74 : if (m != MATCH_YES)
3040 : 14 : goto cleanup;
3041 : : }
3042 : :
3043 : : /* Otherwise we treat the old style initialization just like a
3044 : : DATA declaration for the current variable. */
3045 : : else
3046 : 70 : return match_old_style_init (name);
3047 : : }
3048 : :
3049 : : /* The double colon must be present in order to have initializers.
3050 : : Otherwise the statement is ambiguous with an assignment statement. */
3051 : 263231 : if (colon_seen)
3052 : : {
3053 : 219709 : if (gfc_match (" =>") == MATCH_YES)
3054 : : {
3055 : 1097 : if (!current_attr.pointer)
3056 : : {
3057 : 0 : gfc_error ("Initialization at %C isn't for a pointer variable");
3058 : 0 : m = MATCH_ERROR;
3059 : 0 : goto cleanup;
3060 : : }
3061 : :
3062 : 1097 : m = match_pointer_init (&initializer, 0);
3063 : 1097 : if (m != MATCH_YES)
3064 : 10 : goto cleanup;
3065 : :
3066 : : /* The target of a pointer initialization must have the SAVE
3067 : : attribute. A variable in PROGRAM, MODULE, or SUBMODULE scope
3068 : : is implicit SAVEd. Explicitly, set the SAVE_IMPLICIT value. */
3069 : 1087 : if (initializer->expr_type == EXPR_VARIABLE
3070 : 126 : && initializer->symtree->n.sym->attr.save == SAVE_NONE
3071 : 25 : && (gfc_current_state () == COMP_PROGRAM
3072 : : || gfc_current_state () == COMP_MODULE
3073 : 25 : || gfc_current_state () == COMP_SUBMODULE))
3074 : 11 : initializer->symtree->n.sym->attr.save = SAVE_IMPLICIT;
3075 : : }
3076 : 218612 : else if (gfc_match_char ('=') == MATCH_YES)
3077 : : {
3078 : 24417 : if (current_attr.pointer)
3079 : : {
3080 : 0 : gfc_error ("Pointer initialization at %C requires %<=>%>, "
3081 : : "not %<=%>");
3082 : 0 : m = MATCH_ERROR;
3083 : 0 : goto cleanup;
3084 : : }
3085 : :
3086 : 24417 : m = gfc_match_init_expr (&initializer);
3087 : 24417 : if (m == MATCH_NO)
3088 : : {
3089 : 0 : gfc_error ("Expected an initialization expression at %C");
3090 : 0 : m = MATCH_ERROR;
3091 : : }
3092 : :
3093 : 9124 : if (current_attr.flavor != FL_PARAMETER && gfc_pure (NULL)
3094 : 24419 : && !gfc_comp_struct (gfc_state_stack->state))
3095 : : {
3096 : 1 : gfc_error ("Initialization of variable at %C is not allowed in "
3097 : : "a PURE procedure");
3098 : 1 : m = MATCH_ERROR;
3099 : : }
3100 : :
3101 : 24417 : if (current_attr.flavor != FL_PARAMETER
3102 : 9124 : && !gfc_comp_struct (gfc_state_stack->state))
3103 : 6884 : gfc_unset_implicit_pure (gfc_current_ns->proc_name);
3104 : :
3105 : 24417 : if (m != MATCH_YES)
3106 : 149 : goto cleanup;
3107 : : }
3108 : : }
3109 : :
3110 : 263072 : if (initializer != NULL && current_attr.allocatable
3111 : 3 : && gfc_comp_struct (gfc_current_state ()))
3112 : : {
3113 : 2 : gfc_error ("Initialization of allocatable component at %C is not "
3114 : : "allowed");
3115 : 2 : m = MATCH_ERROR;
3116 : 2 : goto cleanup;
3117 : : }
3118 : :
3119 : 263070 : if (gfc_current_state () == COMP_DERIVED
3120 : 15421 : && initializer && initializer->ts.type == BT_HOLLERITH)
3121 : : {
3122 : 1 : gfc_error ("Initialization of structure component with a HOLLERITH "
3123 : : "constant at %L is not allowed", &initializer->where);
3124 : 1 : m = MATCH_ERROR;
3125 : 1 : goto cleanup;
3126 : : }
3127 : :
3128 : 263069 : if (gfc_current_state () == COMP_DERIVED
3129 : 15420 : && gfc_current_block ()->attr.pdt_template)
3130 : : {
3131 : 529 : gfc_symbol *param;
3132 : 529 : gfc_find_symbol (name, gfc_current_block ()->f2k_derived,
3133 : : 0, ¶m);
3134 : 529 : if (!param && (current_attr.pdt_kind || current_attr.pdt_len))
3135 : : {
3136 : 1 : gfc_error ("The component with KIND or LEN attribute at %C does not "
3137 : : "not appear in the type parameter list at %L",
3138 : 1 : &gfc_current_block ()->declared_at);
3139 : 1 : m = MATCH_ERROR;
3140 : 4 : goto cleanup;
3141 : : }
3142 : 528 : else if (param && !(current_attr.pdt_kind || current_attr.pdt_len))
3143 : : {
3144 : 1 : gfc_error ("The component at %C that appears in the type parameter "
3145 : : "list at %L has neither the KIND nor LEN attribute",
3146 : 1 : &gfc_current_block ()->declared_at);
3147 : 1 : m = MATCH_ERROR;
3148 : 1 : goto cleanup;
3149 : : }
3150 : 527 : else if (as && (current_attr.pdt_kind || current_attr.pdt_len))
3151 : : {
3152 : 1 : gfc_error ("The component at %C which is a type parameter must be "
3153 : : "a scalar");
3154 : 1 : m = MATCH_ERROR;
3155 : 1 : goto cleanup;
3156 : : }
3157 : 526 : else if (param && initializer)
3158 : : {
3159 : 105 : if (initializer->ts.type == BT_BOZ)
3160 : : {
3161 : 1 : gfc_error ("BOZ literal constant at %L cannot appear as an "
3162 : : "initializer", &initializer->where);
3163 : 1 : m = MATCH_ERROR;
3164 : 1 : goto cleanup;
3165 : : }
3166 : 104 : param->value = gfc_copy_expr (initializer);
3167 : : }
3168 : : }
3169 : :
3170 : : /* Before adding a possible initializer, do a simple check for compatibility
3171 : : of lhs and rhs types. Assigning a REAL value to a derived type is not a
3172 : : good thing. */
3173 : 25621 : if (current_ts.type == BT_DERIVED && initializer
3174 : 264359 : && (gfc_numeric_ts (&initializer->ts)
3175 : 1292 : || initializer->ts.type == BT_LOGICAL
3176 : 1292 : || initializer->ts.type == BT_CHARACTER))
3177 : : {
3178 : 2 : gfc_error ("Incompatible initialization between a derived type "
3179 : : "entity and an entity with %qs type at %C",
3180 : : gfc_typename (initializer));
3181 : 2 : m = MATCH_ERROR;
3182 : 2 : goto cleanup;
3183 : : }
3184 : :
3185 : :
3186 : : /* Add the initializer. Note that it is fine if initializer is
3187 : : NULL here, because we sometimes also need to check if a
3188 : : declaration *must* have an initialization expression. */
3189 : 263063 : if (!gfc_comp_struct (gfc_current_state ()))
3190 : 246629 : t = add_init_expr_to_sym (name, &initializer, &var_locus);
3191 : : else
3192 : : {
3193 : 16434 : if (current_ts.type == BT_DERIVED
3194 : 2243 : && !current_attr.pointer && !initializer)
3195 : 1706 : initializer = gfc_default_initializer (¤t_ts);
3196 : 16434 : t = build_struct (name, cl, &initializer, &as);
3197 : :
3198 : : /* If we match a nested structure definition we expect to see the
3199 : : * body even if the variable declarations blow up, so we need to keep
3200 : : * the structure declaration around. */
3201 : 16434 : if (gfc_new_block && gfc_new_block->attr.flavor == FL_STRUCT)
3202 : 34 : gfc_commit_symbol (gfc_new_block);
3203 : : }
3204 : :
3205 : 263063 : m = (t) ? MATCH_YES : MATCH_ERROR;
3206 : :
3207 : 263490 : cleanup:
3208 : : /* Free stuff up and return. */
3209 : 263490 : gfc_seen_div0 = false;
3210 : 263490 : gfc_free_expr (initializer);
3211 : 263490 : gfc_free_array_spec (as);
3212 : :
3213 : 263490 : return m;
3214 : : }
3215 : :
3216 : :
3217 : : /* Match an extended-f77 "TYPESPEC*bytesize"-style kind specification.
3218 : : This assumes that the byte size is equal to the kind number for
3219 : : non-COMPLEX types, and equal to twice the kind number for COMPLEX. */
3220 : :
3221 : : static match
3222 : 102926 : gfc_match_old_kind_spec (gfc_typespec *ts)
3223 : : {
3224 : 102926 : match m;
3225 : 102926 : int original_kind;
3226 : :
3227 : 102926 : if (gfc_match_char ('*') != MATCH_YES)
3228 : : return MATCH_NO;
3229 : :
3230 : 1136 : m = gfc_match_small_literal_int (&ts->kind, NULL);
3231 : 1136 : if (m != MATCH_YES)
3232 : : return MATCH_ERROR;
3233 : :
3234 : 1136 : original_kind = ts->kind;
3235 : :
3236 : : /* Massage the kind numbers for complex types. */
3237 : 1136 : if (ts->type == BT_COMPLEX)
3238 : : {
3239 : 79 : if (ts->kind % 2)
3240 : : {
3241 : 0 : gfc_error ("Old-style type declaration %s*%d not supported at %C",
3242 : : gfc_basic_typename (ts->type), original_kind);
3243 : 0 : return MATCH_ERROR;
3244 : : }
3245 : 79 : ts->kind /= 2;
3246 : :
3247 : : }
3248 : :
3249 : 1136 : if (ts->type == BT_INTEGER && ts->kind == 4 && flag_integer4_kind == 8)
3250 : 0 : ts->kind = 8;
3251 : :
3252 : 1136 : if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
3253 : : {
3254 : 844 : if (ts->kind == 4)
3255 : : {
3256 : 212 : if (flag_real4_kind == 8)
3257 : 24 : ts->kind = 8;
3258 : 212 : if (flag_real4_kind == 10)
3259 : 24 : ts->kind = 10;
3260 : 212 : if (flag_real4_kind == 16)
3261 : 24 : ts->kind = 16;
3262 : : }
3263 : 632 : else if (ts->kind == 8)
3264 : : {
3265 : 627 : if (flag_real8_kind == 4)
3266 : 24 : ts->kind = 4;
3267 : 627 : if (flag_real8_kind == 10)
3268 : 24 : ts->kind = 10;
3269 : 627 : if (flag_real8_kind == 16)
3270 : 24 : ts->kind = 16;
3271 : : }
3272 : : }
3273 : :
3274 : 1136 : if (gfc_validate_kind (ts->type, ts->kind, true) < 0)
3275 : : {
3276 : 8 : gfc_error ("Old-style type declaration %s*%d not supported at %C",
3277 : : gfc_basic_typename (ts->type), original_kind);
3278 : 8 : return MATCH_ERROR;
3279 : : }
3280 : :
3281 : 1128 : if (!gfc_notify_std (GFC_STD_GNU,
3282 : : "Nonstandard type declaration %s*%d at %C",
3283 : : gfc_basic_typename(ts->type), original_kind))
3284 : : return MATCH_ERROR;
3285 : :
3286 : : return MATCH_YES;
3287 : : }
3288 : :
3289 : :
3290 : : /* Match a kind specification. Since kinds are generally optional, we
3291 : : usually return MATCH_NO if something goes wrong. If a "kind="
3292 : : string is found, then we know we have an error. */
3293 : :
3294 : : match
3295 : 149929 : gfc_match_kind_spec (gfc_typespec *ts, bool kind_expr_only)
3296 : : {
3297 : 149929 : locus where, loc;
3298 : 149929 : gfc_expr *e;
3299 : 149929 : match m, n;
3300 : 149929 : char c;
3301 : :
3302 : 149929 : m = MATCH_NO;
3303 : 149929 : n = MATCH_YES;
3304 : 149929 : e = NULL;
3305 : 149929 : saved_kind_expr = NULL;
3306 : :
3307 : 149929 : where = loc = gfc_current_locus;
3308 : :
3309 : 149929 : if (kind_expr_only)
3310 : 0 : goto kind_expr;
3311 : :
3312 : 149929 : if (gfc_match_char ('(') == MATCH_NO)
3313 : : return MATCH_NO;
3314 : :
3315 : : /* Also gobbles optional text. */
3316 : 45694 : if (gfc_match (" kind = ") == MATCH_YES)
3317 : 45694 : m = MATCH_ERROR;
3318 : :
3319 : 45694 : loc = gfc_current_locus;
3320 : :
3321 : 45694 : kind_expr:
3322 : :
3323 : 45694 : n = gfc_match_init_expr (&e);
3324 : :
3325 : 45694 : if (gfc_derived_parameter_expr (e))
3326 : : {
3327 : 77 : ts->kind = 0;
3328 : 77 : saved_kind_expr = gfc_copy_expr (e);
3329 : 77 : goto close_brackets;
3330 : : }
3331 : :
3332 : 45617 : if (n != MATCH_YES)
3333 : : {
3334 : 345 : if (gfc_matching_function)
3335 : : {
3336 : : /* The function kind expression might include use associated or
3337 : : imported parameters and try again after the specification
3338 : : expressions..... */
3339 : 317 : if (gfc_match_char (')') != MATCH_YES)
3340 : : {
3341 : 1 : gfc_error ("Missing right parenthesis at %C");
3342 : 1 : m = MATCH_ERROR;
3343 : 1 : goto no_match;
3344 : : }
3345 : :
3346 : 316 : gfc_free_expr (e);
3347 : 316 : gfc_undo_symbols ();
3348 : 316 : return MATCH_YES;
3349 : : }
3350 : : else
3351 : : {
3352 : : /* ....or else, the match is real. */
3353 : 28 : if (n == MATCH_NO)
3354 : 0 : gfc_error ("Expected initialization expression at %C");
3355 : 28 : if (n != MATCH_YES)
3356 : 28 : return MATCH_ERROR;
3357 : : }
3358 : : }
3359 : :
3360 : 45272 : if (e->rank != 0)
3361 : : {
3362 : 0 : gfc_error ("Expected scalar initialization expression at %C");
3363 : 0 : m = MATCH_ERROR;
3364 : 0 : goto no_match;
3365 : : }
3366 : :
3367 : 45272 : if (gfc_extract_int (e, &ts->kind, 1))
3368 : : {
3369 : 0 : m = MATCH_ERROR;
3370 : 0 : goto no_match;
3371 : : }
3372 : :
3373 : : /* Before throwing away the expression, let's see if we had a
3374 : : C interoperable kind (and store the fact). */
3375 : 45272 : if (e->ts.is_c_interop == 1)
3376 : : {
3377 : : /* Mark this as C interoperable if being declared with one
3378 : : of the named constants from iso_c_binding. */
3379 : 16883 : ts->is_c_interop = e->ts.is_iso_c;
3380 : 16883 : ts->f90_type = e->ts.f90_type;
3381 : 16883 : if (e->symtree)
3382 : 16882 : ts->interop_kind = e->symtree->n.sym;
3383 : : }
3384 : :
3385 : 45272 : gfc_free_expr (e);
3386 : 45272 : e = NULL;
3387 : :
3388 : : /* Ignore errors to this point, if we've gotten here. This means
3389 : : we ignore the m=MATCH_ERROR from above. */
3390 : 45272 : if (gfc_validate_kind (ts->type, ts->kind, true) < 0)
3391 : : {
3392 : 7 : gfc_error ("Kind %d not supported for type %s at %C", ts->kind,
3393 : : gfc_basic_typename (ts->type));
3394 : 7 : gfc_current_locus = where;
3395 : 7 : return MATCH_ERROR;
3396 : : }
3397 : :
3398 : : /* Warn if, e.g., c_int is used for a REAL variable, but not
3399 : : if, e.g., c_double is used for COMPLEX as the standard
3400 : : explicitly says that the kind type parameter for complex and real
3401 : : variable is the same, i.e. c_float == c_float_complex. */
3402 : 45265 : if (ts->f90_type != BT_UNKNOWN && ts->f90_type != ts->type
3403 : 17 : && !((ts->f90_type == BT_REAL && ts->type == BT_COMPLEX)
3404 : 1 : || (ts->f90_type == BT_COMPLEX && ts->type == BT_REAL)))
3405 : 13 : gfc_warning_now (0, "C kind type parameter is for type %s but type at %L "
3406 : : "is %s", gfc_basic_typename (ts->f90_type), &where,
3407 : : gfc_basic_typename (ts->type));
3408 : :
3409 : 45252 : close_brackets:
3410 : :
3411 : 45342 : gfc_gobble_whitespace ();
3412 : 45342 : if ((c = gfc_next_ascii_char ()) != ')'
3413 : 45342 : && (ts->type != BT_CHARACTER || c != ','))
3414 : : {
3415 : 0 : if (ts->type == BT_CHARACTER)
3416 : 0 : gfc_error ("Missing right parenthesis or comma at %C");
3417 : : else
3418 : 0 : gfc_error ("Missing right parenthesis at %C");
3419 : 0 : m = MATCH_ERROR;
3420 : 0 : goto no_match;
3421 : : }
3422 : : else
3423 : : /* All tests passed. */
3424 : 45342 : m = MATCH_YES;
3425 : :
3426 : 45342 : if(m == MATCH_ERROR)
3427 : : gfc_current_locus = where;
3428 : :
3429 : 45342 : if (ts->type == BT_INTEGER && ts->kind == 4 && flag_integer4_kind == 8)
3430 : 0 : ts->kind = 8;
3431 : :
3432 : 45342 : if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
3433 : : {
3434 : 13380 : if (ts->kind == 4)
3435 : : {
3436 : 4359 : if (flag_real4_kind == 8)
3437 : 54 : ts->kind = 8;
3438 : 4359 : if (flag_real4_kind == 10)
3439 : 54 : ts->kind = 10;
3440 : 4359 : if (flag_real4_kind == 16)
3441 : 54 : ts->kind = 16;
3442 : : }
3443 : 9021 : else if (ts->kind == 8)
3444 : : {
3445 : 6108 : if (flag_real8_kind == 4)
3446 : 48 : ts->kind = 4;
3447 : 6108 : if (flag_real8_kind == 10)
3448 : 48 : ts->kind = 10;
3449 : 6108 : if (flag_real8_kind == 16)
3450 : 48 : ts->kind = 16;
3451 : : }
3452 : : }
3453 : :
3454 : : /* Return what we know from the test(s). */
3455 : : return m;
3456 : :
3457 : 1 : no_match:
3458 : 1 : gfc_free_expr (e);
3459 : 1 : gfc_current_locus = where;
3460 : 1 : return m;
3461 : : }
3462 : :
3463 : :
3464 : : static match
3465 : 4477 : match_char_kind (int * kind, int * is_iso_c)
3466 : : {
3467 : 4477 : locus where;
3468 : 4477 : gfc_expr *e;
3469 : 4477 : match m, n;
3470 : 4477 : bool fail;
3471 : :
3472 : 4477 : m = MATCH_NO;
3473 : 4477 : e = NULL;
3474 : 4477 : where = gfc_current_locus;
3475 : :
3476 : 4477 : n = gfc_match_init_expr (&e);
3477 : :
3478 : 4477 : if (n != MATCH_YES && gfc_matching_function)
3479 : : {
3480 : : /* The expression might include use-associated or imported
3481 : : parameters and try again after the specification
3482 : : expressions. */
3483 : 7 : gfc_free_expr (e);
3484 : 7 : gfc_undo_symbols ();
3485 : 7 : return MATCH_YES;
3486 : : }
3487 : :
3488 : 7 : if (n == MATCH_NO)
3489 : 2 : gfc_error ("Expected initialization expression at %C");
3490 : 4470 : if (n != MATCH_YES)
3491 : : return MATCH_ERROR;
3492 : :
3493 : 4463 : if (e->rank != 0)
3494 : : {
3495 : 0 : gfc_error ("Expected scalar initialization expression at %C");
3496 : 0 : m = MATCH_ERROR;
3497 : 0 : goto no_match;
3498 : : }
3499 : :
3500 : 4463 : if (gfc_derived_parameter_expr (e))
3501 : : {
3502 : 14 : saved_kind_expr = e;
3503 : 14 : *kind = 0;
3504 : 14 : return MATCH_YES;
3505 : : }
3506 : :
3507 : 4449 : fail = gfc_extract_int (e, kind, 1);
3508 : 4449 : *is_iso_c = e->ts.is_iso_c;
3509 : 4449 : if (fail)
3510 : : {
3511 : 0 : m = MATCH_ERROR;
3512 : 0 : goto no_match;
3513 : : }
3514 : :
3515 : 4449 : gfc_free_expr (e);
3516 : :
3517 : : /* Ignore errors to this point, if we've gotten here. This means
3518 : : we ignore the m=MATCH_ERROR from above. */
3519 : 4449 : if (gfc_validate_kind (BT_CHARACTER, *kind, true) < 0)
3520 : : {
3521 : 14 : gfc_error ("Kind %d is not supported for CHARACTER at %C", *kind);
3522 : 14 : m = MATCH_ERROR;
3523 : : }
3524 : : else
3525 : : /* All tests passed. */
3526 : : m = MATCH_YES;
3527 : :
3528 : 14 : if (m == MATCH_ERROR)
3529 : 14 : gfc_current_locus = where;
3530 : :
3531 : : /* Return what we know from the test(s). */
3532 : : return m;
3533 : :
3534 : 0 : no_match:
3535 : 0 : gfc_free_expr (e);
3536 : 0 : gfc_current_locus = where;
3537 : 0 : return m;
3538 : : }
3539 : :
3540 : :
3541 : : /* Match the various kind/length specifications in a CHARACTER
3542 : : declaration. We don't return MATCH_NO. */
3543 : :
3544 : : match
3545 : 29714 : gfc_match_char_spec (gfc_typespec *ts)
3546 : : {
3547 : 29714 : int kind, seen_length, is_iso_c;
3548 : 29714 : gfc_charlen *cl;
3549 : 29714 : gfc_expr *len;
3550 : 29714 : match m;
3551 : 29714 : bool deferred;
3552 : :
3553 : 29714 : len = NULL;
3554 : 29714 : seen_length = 0;
3555 : 29714 : kind = 0;
3556 : 29714 : is_iso_c = 0;
3557 : 29714 : deferred = false;
3558 : :
3559 : : /* Try the old-style specification first. */
3560 : 29714 : old_char_selector = 0;
3561 : :
3562 : 29714 : m = match_char_length (&len, &deferred, true);
3563 : 29714 : if (m != MATCH_NO)
3564 : : {
3565 : 2217 : if (m == MATCH_YES)
3566 : 2217 : old_char_selector = 1;
3567 : 2217 : seen_length = 1;
3568 : 2217 : goto done;
3569 : : }
3570 : :
3571 : 27497 : m = gfc_match_char ('(');
3572 : 27497 : if (m != MATCH_YES)
3573 : : {
3574 : 1823 : m = MATCH_YES; /* Character without length is a single char. */
3575 : 1823 : goto done;
3576 : : }
3577 : :
3578 : : /* Try the weird case: ( KIND = <int> [ , LEN = <len-param> ] ). */
3579 : 25674 : if (gfc_match (" kind =") == MATCH_YES)
3580 : : {
3581 : 3144 : m = match_char_kind (&kind, &is_iso_c);
3582 : :
3583 : 3144 : if (m == MATCH_ERROR)
3584 : 16 : goto done;
3585 : 3128 : if (m == MATCH_NO)
3586 : : goto syntax;
3587 : :
3588 : 3128 : if (gfc_match (" , len =") == MATCH_NO)
3589 : 514 : goto rparen;
3590 : :
3591 : 2614 : m = char_len_param_value (&len, &deferred);
3592 : 2614 : if (m == MATCH_NO)
3593 : 0 : goto syntax;
3594 : 2614 : if (m == MATCH_ERROR)
3595 : 2 : goto done;
3596 : 2612 : seen_length = 1;
3597 : :
3598 : 2612 : goto rparen;
3599 : : }
3600 : :
3601 : : /* Try to match "LEN = <len-param>" or "LEN = <len-param>, KIND = <int>". */
3602 : 22530 : if (gfc_match (" len =") == MATCH_YES)
3603 : : {
3604 : 13400 : m = char_len_param_value (&len, &deferred);
3605 : 13400 : if (m == MATCH_NO)
3606 : 2 : goto syntax;
3607 : 13398 : if (m == MATCH_ERROR)
3608 : 8 : goto done;
3609 : 13390 : seen_length = 1;
3610 : :
3611 : 13390 : if (gfc_match_char (')') == MATCH_YES)
3612 : 12199 : goto done;
3613 : :
3614 : 1191 : if (gfc_match (" , kind =") != MATCH_YES)
3615 : 0 : goto syntax;
3616 : :
3617 : 1191 : if (match_char_kind (&kind, &is_iso_c) == MATCH_ERROR)
3618 : 2 : goto done;
3619 : :
3620 : 1189 : goto rparen;
3621 : : }
3622 : :
3623 : : /* Try to match ( <len-param> ) or ( <len-param> , [ KIND = ] <int> ). */
3624 : 9130 : m = char_len_param_value (&len, &deferred);
3625 : 9130 : if (m == MATCH_NO)
3626 : 0 : goto syntax;
3627 : 9130 : if (m == MATCH_ERROR)
3628 : 44 : goto done;
3629 : 9086 : seen_length = 1;
3630 : :
3631 : 9086 : m = gfc_match_char (')');
3632 : 9086 : if (m == MATCH_YES)
3633 : 8942 : goto done;
3634 : :
3635 : 144 : if (gfc_match_char (',') != MATCH_YES)
3636 : 2 : goto syntax;
3637 : :
3638 : 142 : gfc_match (" kind ="); /* Gobble optional text. */
3639 : :
3640 : 142 : m = match_char_kind (&kind, &is_iso_c);
3641 : 142 : if (m == MATCH_ERROR)
3642 : 3 : goto done;
3643 : : if (m == MATCH_NO)
3644 : : goto syntax;
3645 : :
3646 : 4454 : rparen:
3647 : : /* Require a right-paren at this point. */
3648 : 4454 : m = gfc_match_char (')');
3649 : 4454 : if (m == MATCH_YES)
3650 : 4454 : goto done;
3651 : :
3652 : 0 : syntax:
3653 : 4 : gfc_error ("Syntax error in CHARACTER declaration at %C");
3654 : 4 : m = MATCH_ERROR;
3655 : 4 : gfc_free_expr (len);
3656 : 4 : return m;
3657 : :
3658 : 29710 : done:
3659 : : /* Deal with character functions after USE and IMPORT statements. */
3660 : 29710 : if (gfc_matching_function)
3661 : : {
3662 : 1393 : gfc_free_expr (len);
3663 : 1393 : gfc_undo_symbols ();
3664 : 1393 : return MATCH_YES;
3665 : : }
3666 : :
3667 : 28317 : if (m != MATCH_YES)
3668 : : {
3669 : 65 : gfc_free_expr (len);
3670 : 65 : return m;
3671 : : }
3672 : :
3673 : : /* Do some final massaging of the length values. */
3674 : 28252 : cl = gfc_new_charlen (gfc_current_ns, NULL);
3675 : :
3676 : 28252 : if (seen_length == 0)
3677 : 2285 : cl->length = gfc_get_int_expr (gfc_charlen_int_kind, NULL, 1);
3678 : : else
3679 : : {
3680 : : /* If gfortran ends up here, then len may be reducible to a constant.
3681 : : Try to do that here. If it does not reduce, simply assign len to
3682 : : charlen. A complication occurs with user-defined generic functions,
3683 : : which are not resolved. Use a private namespace to deal with
3684 : : generic functions. */
3685 : :
3686 : 25967 : if (len && len->expr_type != EXPR_CONSTANT)
3687 : : {
3688 : 2509 : gfc_namespace *old_ns;
3689 : 2509 : gfc_expr *e;
3690 : :
3691 : 2509 : old_ns = gfc_current_ns;
3692 : 2509 : gfc_current_ns = gfc_get_namespace (NULL, 0);
3693 : :
3694 : 2509 : e = gfc_copy_expr (len);
3695 : 2509 : gfc_push_suppress_errors ();
3696 : 2509 : gfc_reduce_init_expr (e);
3697 : 2509 : gfc_pop_suppress_errors ();
3698 : 2509 : if (e->expr_type == EXPR_CONSTANT)
3699 : : {
3700 : 292 : gfc_replace_expr (len, e);
3701 : 292 : if (mpz_cmp_si (len->value.integer, 0) < 0)
3702 : 7 : mpz_set_ui (len->value.integer, 0);
3703 : : }
3704 : : else
3705 : 2217 : gfc_free_expr (e);
3706 : :
3707 : 2509 : gfc_free_namespace (gfc_current_ns);
3708 : 2509 : gfc_current_ns = old_ns;
3709 : : }
3710 : :
3711 : 25967 : cl->length = len;
3712 : : }
3713 : :
3714 : 28252 : ts->u.cl = cl;
3715 : 28252 : ts->kind = kind == 0 ? gfc_default_character_kind : kind;
3716 : 28252 : ts->deferred = deferred;
3717 : :
3718 : : /* We have to know if it was a C interoperable kind so we can
3719 : : do accurate type checking of bind(c) procs, etc. */
3720 : 28252 : if (kind != 0)
3721 : : /* Mark this as C interoperable if being declared with one
3722 : : of the named constants from iso_c_binding. */
3723 : 4372 : ts->is_c_interop = is_iso_c;
3724 : 23880 : else if (len != NULL)
3725 : : /* Here, we might have parsed something such as: character(c_char)
3726 : : In this case, the parsing code above grabs the c_char when
3727 : : looking for the length (line 1690, roughly). it's the last
3728 : : testcase for parsing the kind params of a character variable.
3729 : : However, it's not actually the length. this seems like it
3730 : : could be an error.
3731 : : To see if the user used a C interop kind, test the expr
3732 : : of the so called length, and see if it's C interoperable. */
3733 : 15094 : ts->is_c_interop = len->ts.is_iso_c;
3734 : :
3735 : : return MATCH_YES;
3736 : : }
3737 : :
3738 : :
3739 : : /* Matches a RECORD declaration. */
3740 : :
3741 : : static match
3742 : 906368 : match_record_decl (char *name)
3743 : : {
3744 : 906368 : locus old_loc;
3745 : 906368 : old_loc = gfc_current_locus;
3746 : 906368 : match m;
3747 : :
3748 : 906368 : m = gfc_match (" record /");
3749 : 906368 : if (m == MATCH_YES)
3750 : : {
3751 : 353 : if (!flag_dec_structure)
3752 : : {
3753 : 6 : gfc_current_locus = old_loc;
3754 : 6 : gfc_error ("RECORD at %C is an extension, enable it with "
3755 : : "%<-fdec-structure%>");
3756 : 6 : return MATCH_ERROR;
3757 : : }
3758 : 347 : m = gfc_match (" %n/", name);
3759 : 347 : if (m == MATCH_YES)
3760 : : return MATCH_YES;
3761 : : }
3762 : :
3763 : 906018 : gfc_current_locus = old_loc;
3764 : 906018 : if (flag_dec_structure
3765 : 906018 : && (gfc_match (" record% ") == MATCH_YES
3766 : 8026 : || gfc_match (" record%t") == MATCH_YES))
3767 : 6 : gfc_error ("Structure name expected after RECORD at %C");
3768 : 906018 : if (m == MATCH_NO)
3769 : : return MATCH_NO;
3770 : :
3771 : : return MATCH_ERROR;
3772 : : }
3773 : :
3774 : :
3775 : : /* This function uses the gfc_actual_arglist 'type_param_spec_list' as a source
3776 : : of expressions to substitute into the possibly parameterized expression
3777 : : 'e'. Using a list is inefficient but should not be too bad since the
3778 : : number of type parameters is not likely to be large. */
3779 : : static bool
3780 : 1592 : insert_parameter_exprs (gfc_expr* e, gfc_symbol* sym ATTRIBUTE_UNUSED,
3781 : : int* f)
3782 : : {
3783 : 1592 : gfc_actual_arglist *param;
3784 : 1592 : gfc_expr *copy;
3785 : :
3786 : 1592 : if (e->expr_type != EXPR_VARIABLE)
3787 : : return false;
3788 : :
3789 : 799 : gcc_assert (e->symtree);
3790 : 799 : if (e->symtree->n.sym->attr.pdt_kind
3791 : 656 : || (*f != 0 && e->symtree->n.sym->attr.pdt_len))
3792 : : {
3793 : 812 : for (param = type_param_spec_list; param; param = param->next)
3794 : 812 : if (strcmp (e->symtree->n.sym->name, param->name) == 0)
3795 : : break;
3796 : :
3797 : 502 : if (param)
3798 : : {
3799 : 502 : copy = gfc_copy_expr (param->expr);
3800 : 502 : *e = *copy;
3801 : 502 : free (copy);
3802 : : }
3803 : : }
3804 : :
3805 : : return false;
3806 : : }
3807 : :
3808 : :
3809 : : static bool
3810 : 585 : gfc_insert_kind_parameter_exprs (gfc_expr *e)
3811 : : {
3812 : 585 : return gfc_traverse_expr (e, NULL, &insert_parameter_exprs, 0);
3813 : : }
3814 : :
3815 : :
3816 : : bool
3817 : 646 : gfc_insert_parameter_exprs (gfc_expr *e, gfc_actual_arglist *param_list)
3818 : : {
3819 : 646 : gfc_actual_arglist *old_param_spec_list = type_param_spec_list;
3820 : 646 : type_param_spec_list = param_list;
3821 : 646 : bool res = gfc_traverse_expr (e, NULL, &insert_parameter_exprs, 1);
3822 : 646 : type_param_spec_list = old_param_spec_list;
3823 : 646 : return res;
3824 : : }
3825 : :
3826 : : /* Determines the instance of a parameterized derived type to be used by
3827 : : matching determining the values of the kind parameters and using them
3828 : : in the name of the instance. If the instance exists, it is used, otherwise
3829 : : a new derived type is created. */
3830 : : match
3831 : 565 : gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym,
3832 : : gfc_actual_arglist **ext_param_list)
3833 : : {
3834 : : /* The PDT template symbol. */
3835 : 565 : gfc_symbol *pdt = *sym;
3836 : : /* The symbol for the parameter in the template f2k_namespace. */
3837 : 565 : gfc_symbol *param;
3838 : : /* The hoped for instance of the PDT. */
3839 : 565 : gfc_symbol *instance;
3840 : : /* The list of parameters appearing in the PDT declaration. */
3841 : 565 : gfc_formal_arglist *type_param_name_list;
3842 : : /* Used to store the parameter specification list during recursive calls. */
3843 : 565 : gfc_actual_arglist *old_param_spec_list;
3844 : : /* Pointers to the parameter specification being used. */
3845 : 565 : gfc_actual_arglist *actual_param;
3846 : 565 : gfc_actual_arglist *tail = NULL;
3847 : : /* Used to build up the name of the PDT instance. The prefix uses 4
3848 : : characters and each KIND parameter 2 more. Allow 8 of the latter. */
3849 : 565 : char name[GFC_MAX_SYMBOL_LEN + 21];
3850 : :
3851 : 565 : bool name_seen = (param_list == NULL);
3852 : 565 : bool assumed_seen = false;
3853 : 565 : bool deferred_seen = false;
3854 : 565 : bool spec_error = false;
3855 : 565 : int kind_value, i;
3856 : 565 : gfc_expr *kind_expr;
3857 : 565 : gfc_component *c1, *c2;
3858 : 565 : match m;
3859 : :
3860 : 565 : type_param_spec_list = NULL;
3861 : :
3862 : 565 : type_param_name_list = pdt->formal;
3863 : 565 : actual_param = param_list;
3864 : 565 : sprintf (name, "Pdt%s", pdt->name);
3865 : :
3866 : : /* Run through the parameter name list and pick up the actual
3867 : : parameter values or use the default values in the PDT declaration. */
3868 : 1559 : for (; type_param_name_list;
3869 : 994 : type_param_name_list = type_param_name_list->next)
3870 : : {
3871 : 1006 : if (actual_param && actual_param->spec_type != SPEC_EXPLICIT)
3872 : : {
3873 : 929 : if (actual_param->spec_type == SPEC_ASSUMED)
3874 : : spec_error = deferred_seen;
3875 : : else
3876 : 929 : spec_error = assumed_seen;
3877 : :
3878 : 929 : if (spec_error)
3879 : : {
3880 : : gfc_error ("The type parameter spec list at %C cannot contain "
3881 : : "both ASSUMED and DEFERRED parameters");
3882 : : goto error_return;
3883 : : }
3884 : : }
3885 : :
3886 : 929 : if (actual_param && actual_param->name)
3887 : 1006 : name_seen = true;
3888 : 1006 : param = type_param_name_list->sym;
3889 : :
3890 : 1006 : if (!param || !param->name)
3891 : 1 : continue;
3892 : :
3893 : 1005 : c1 = gfc_find_component (pdt, param->name, false, true, NULL);
3894 : : /* An error should already have been thrown in resolve.cc
3895 : : (resolve_fl_derived0). */
3896 : 1005 : if (!pdt->attr.use_assoc && !c1)
3897 : 3 : goto error_return;
3898 : :
3899 : 1002 : kind_expr = NULL;
3900 : 1002 : if (!name_seen)
3901 : : {
3902 : 617 : if (!actual_param && !(c1 && c1->initializer))
3903 : : {
3904 : 1 : gfc_error ("The type parameter spec list at %C does not contain "
3905 : : "enough parameter expressions");
3906 : 1 : goto error_return;
3907 : : }
3908 : 616 : else if (!actual_param && c1 && c1->initializer)
3909 : 1 : kind_expr = gfc_copy_expr (c1->initializer);
3910 : 615 : else if (actual_param && actual_param->spec_type == SPEC_EXPLICIT)
3911 : 462 : kind_expr = gfc_copy_expr (actual_param->expr);
3912 : : }
3913 : : else
3914 : : {
3915 : : actual_param = param_list;
3916 : 526 : for (;actual_param; actual_param = actual_param->next)
3917 : 446 : if (actual_param->name
3918 : 444 : && strcmp (actual_param->name, param->name) == 0)
3919 : : break;
3920 : 385 : if (actual_param && actual_param->spec_type == SPEC_EXPLICIT)
3921 : 245 : kind_expr = gfc_copy_expr (actual_param->expr);
3922 : : else
3923 : : {
3924 : 140 : if (c1->initializer)
3925 : 111 : kind_expr = gfc_copy_expr (c1->initializer);
3926 : 29 : else if (!(actual_param && param->attr.pdt_len))
3927 : : {
3928 : 0 : gfc_error ("The derived parameter %qs at %C does not "
3929 : : "have a default value", param->name);
3930 : 0 : goto error_return;
3931 : : }
3932 : : }
3933 : : }
3934 : :
3935 : : /* Store the current parameter expressions in a temporary actual
3936 : : arglist 'list' so that they can be substituted in the corresponding
3937 : : expressions in the PDT instance. */
3938 : 1001 : if (type_param_spec_list == NULL)
3939 : : {
3940 : 563 : type_param_spec_list = gfc_get_actual_arglist ();
3941 : 563 : tail = type_param_spec_list;
3942 : : }
3943 : : else
3944 : : {
3945 : 438 : tail->next = gfc_get_actual_arglist ();
3946 : 438 : tail = tail->next;
3947 : : }
3948 : 1001 : tail->name = param->name;
3949 : :
3950 : 1001 : if (kind_expr)
3951 : : {
3952 : : /* Try simplification even for LEN expressions. */
3953 : 819 : bool ok;
3954 : 819 : gfc_resolve_expr (kind_expr);
3955 : 819 : ok = gfc_simplify_expr (kind_expr, 1);
3956 : : /* Variable expressions seem to default to BT_PROCEDURE.
3957 : : TODO find out why this is and fix it. */
3958 : 819 : if (kind_expr->ts.type != BT_INTEGER
3959 : 27 : && kind_expr->ts.type != BT_PROCEDURE)
3960 : : {
3961 : 3 : gfc_error ("The parameter expression at %C must be of "
3962 : : "INTEGER type and not %s type",
3963 : : gfc_basic_typename (kind_expr->ts.type));
3964 : 3 : goto error_return;
3965 : : }
3966 : 816 : if (kind_expr->ts.type == BT_INTEGER && !ok)
3967 : : {
3968 : 2 : gfc_error ("The parameter expression at %C does not "
3969 : : "simplify to an INTEGER constant");
3970 : 2 : goto error_return;
3971 : : }
3972 : :
3973 : 814 : tail->expr = gfc_copy_expr (kind_expr);
3974 : : }
3975 : :
3976 : 996 : if (actual_param)
3977 : 915 : tail->spec_type = actual_param->spec_type;
3978 : :
3979 : 996 : if (!param->attr.pdt_kind)
3980 : : {
3981 : 529 : if (!name_seen && actual_param)
3982 : 348 : actual_param = actual_param->next;
3983 : 529 : if (kind_expr)
3984 : : {
3985 : 349 : gfc_free_expr (kind_expr);
3986 : 349 : kind_expr = NULL;
3987 : : }
3988 : 529 : continue;
3989 : : }
3990 : :
3991 : 467 : if (actual_param
3992 : 410 : && (actual_param->spec_type == SPEC_ASSUMED
3993 : 410 : || actual_param->spec_type == SPEC_DEFERRED))
3994 : : {
3995 : 2 : gfc_error ("The KIND parameter %qs at %C cannot either be "
3996 : : "ASSUMED or DEFERRED", param->name);
3997 : 2 : goto error_return;
3998 : : }
3999 : :
4000 : 465 : if (!kind_expr || !gfc_is_constant_expr (kind_expr))
4001 : : {
4002 : 1 : gfc_error ("The value for the KIND parameter %qs at %C does not "
4003 : : "reduce to a constant expression", param->name);
4004 : 1 : goto error_return;
4005 : : }
4006 : :
4007 : 464 : gfc_extract_int (kind_expr, &kind_value);
4008 : 464 : sprintf (name + strlen (name), "_%d", kind_value);
4009 : :
4010 : 464 : if (!name_seen && actual_param)
4011 : 259 : actual_param = actual_param->next;
4012 : 464 : gfc_free_expr (kind_expr);
4013 : : }
4014 : :
4015 : 553 : if (!name_seen && actual_param)
4016 : : {
4017 : 1 : gfc_error ("The type parameter spec list at %C contains too many "
4018 : : "parameter expressions");
4019 : 1 : goto error_return;
4020 : : }
4021 : :
4022 : : /* Now we search for the PDT instance 'name'. If it doesn't exist, we
4023 : : build it, using 'pdt' as a template. */
4024 : 552 : if (gfc_get_symbol (name, pdt->ns, &instance))
4025 : : {
4026 : 0 : gfc_error ("Parameterized derived type at %C is ambiguous");
4027 : 0 : goto error_return;
4028 : : }
4029 : :
4030 : 552 : m = MATCH_YES;
4031 : :
4032 : 552 : if (instance->attr.flavor == FL_DERIVED
4033 : 552 : && instance->attr.pdt_type)
4034 : : {
4035 : 325 : instance->refs++;
4036 : 325 : if (ext_param_list)
4037 : 62 : *ext_param_list = type_param_spec_list;
4038 : 325 : *sym = instance;
4039 : 325 : gfc_commit_symbols ();
4040 : 325 : return m;
4041 : : }
4042 : :
4043 : : /* Start building the new instance of the parameterized type. */
4044 : 227 : gfc_copy_attr (&instance->attr, &pdt->attr, &pdt->declared_at);
4045 : 227 : instance->attr.pdt_template = 0;
4046 : 227 : instance->attr.pdt_type = 1;
4047 : 227 : instance->declared_at = gfc_current_locus;
4048 : :
4049 : : /* Add the components, replacing the parameters in all expressions
4050 : : with the expressions for their values in 'type_param_spec_list'. */
4051 : 227 : c1 = pdt->components;
4052 : 227 : tail = type_param_spec_list;
4053 : 918 : for (; c1; c1 = c1->next)
4054 : : {
4055 : 692 : gfc_add_component (instance, c1->name, &c2);
4056 : :
4057 : 692 : c2->ts = c1->ts;
4058 : 692 : c2->attr = c1->attr;
4059 : :
4060 : : /* The order of declaration of the type_specs might not be the
4061 : : same as that of the components. */
4062 : 692 : if (c1->attr.pdt_kind || c1->attr.pdt_len)
4063 : : {
4064 : 605 : for (tail = type_param_spec_list; tail; tail = tail->next)
4065 : 605 : if (strcmp (c1->name, tail->name) == 0)
4066 : : break;
4067 : : }
4068 : :
4069 : : /* Deal with type extension by recursively calling this function
4070 : : to obtain the instance of the extended type. */
4071 : 692 : if (gfc_current_state () != COMP_DERIVED
4072 : 692 : && c1 == pdt->components
4073 : 227 : && (c1->ts.type == BT_DERIVED || c1->ts.type == BT_CLASS)
4074 : 29 : && c1->ts.u.derived && c1->ts.u.derived->attr.pdt_template
4075 : 721 : && gfc_get_derived_super_type (*sym) == c2->ts.u.derived)
4076 : : {
4077 : 29 : gfc_formal_arglist *f;
4078 : :
4079 : 29 : old_param_spec_list = type_param_spec_list;
4080 : :
4081 : : /* Obtain a spec list appropriate to the extended type..*/
4082 : 29 : actual_param = gfc_copy_actual_arglist (type_param_spec_list);
4083 : 29 : type_param_spec_list = actual_param;
4084 : 67 : for (f = c1->ts.u.derived->formal; f && f->next; f = f->next)
4085 : 38 : actual_param = actual_param->next;
4086 : 29 : if (actual_param)
4087 : : {
4088 : 29 : gfc_free_actual_arglist (actual_param->next);
4089 : 29 : actual_param->next = NULL;
4090 : : }
4091 : :
4092 : : /* Now obtain the PDT instance for the extended type. */
4093 : 29 : c2->param_list = type_param_spec_list;
4094 : 29 : m = gfc_get_pdt_instance (type_param_spec_list, &c2->ts.u.derived,
4095 : : NULL);
4096 : 29 : type_param_spec_list = old_param_spec_list;
4097 : :
4098 : 29 : c2->ts.u.derived->refs++;
4099 : 29 : gfc_set_sym_referenced (c2->ts.u.derived);
4100 : :
4101 : : /* Set extension level. */
4102 : 29 : if (c2->ts.u.derived->attr.extension == 255)
4103 : : {
4104 : : /* Since the extension field is 8 bit wide, we can only have
4105 : : up to 255 extension levels. */
4106 : 0 : gfc_error ("Maximum extension level reached with type %qs at %L",
4107 : : c2->ts.u.derived->name,
4108 : : &c2->ts.u.derived->declared_at);
4109 : 0 : goto error_return;
4110 : : }
4111 : 29 : instance->attr.extension = c2->ts.u.derived->attr.extension + 1;
4112 : :
4113 : 29 : continue;
4114 : 29 : }
4115 : :
4116 : : /* Addressing PR82943, this will fix the issue where a function or
4117 : : subroutine is declared as not a member of the PDT instance.
4118 : : The reason for this is because the PDT instance did not have access
4119 : : to its template's f2k_derived namespace in order to find the
4120 : : typebound procedures.
4121 : :
4122 : : The number of references to the PDT template's f2k_derived will
4123 : : ensure that f2k_derived is properly freed later on. */
4124 : :
4125 : 663 : if (!instance->f2k_derived && pdt->f2k_derived)
4126 : : {
4127 : 226 : instance->f2k_derived = pdt->f2k_derived;
4128 : 226 : instance->f2k_derived->refs++;
4129 : : }
4130 : :
4131 : : /* Set the component kind using the parameterized expression. */
4132 : 663 : if ((c1->ts.kind == 0 || c1->ts.type == BT_CHARACTER)
4133 : 211 : && c1->kind_expr != NULL)
4134 : : {
4135 : 130 : gfc_expr *e = gfc_copy_expr (c1->kind_expr);
4136 : 130 : gfc_insert_kind_parameter_exprs (e);
4137 : 130 : gfc_simplify_expr (e, 1);
4138 : 130 : gfc_extract_int (e, &c2->ts.kind);
4139 : 130 : gfc_free_expr (e);
4140 : 130 : if (gfc_validate_kind (c2->ts.type, c2->ts.kind, true) < 0)
4141 : : {
4142 : 1 : gfc_error ("Kind %d not supported for type %s at %C",
4143 : : c2->ts.kind, gfc_basic_typename (c2->ts.type));
4144 : 1 : goto error_return;
4145 : : }
4146 : : }
4147 : :
4148 : : /* Similarly, set the string length if parameterized. */
4149 : 662 : if (c1->ts.type == BT_CHARACTER
4150 : 67 : && c1->ts.u.cl->length
4151 : 729 : && gfc_derived_parameter_expr (c1->ts.u.cl->length))
4152 : : {
4153 : 67 : gfc_expr *e;
4154 : 67 : e = gfc_copy_expr (c1->ts.u.cl->length);
4155 : 67 : gfc_insert_kind_parameter_exprs (e);
4156 : 67 : gfc_simplify_expr (e, 1);
4157 : 67 : c2->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
4158 : 67 : c2->ts.u.cl->length = e;
4159 : 67 : c2->attr.pdt_string = 1;
4160 : : }
4161 : :
4162 : : /* Set up either the KIND/LEN initializer, if constant,
4163 : : or the parameterized expression. Use the template
4164 : : initializer if one is not already set in this instance. */
4165 : 662 : if (c2->attr.pdt_kind || c2->attr.pdt_len)
4166 : : {
4167 : 370 : if (tail && tail->expr && gfc_is_constant_expr (tail->expr))
4168 : 301 : c2->initializer = gfc_copy_expr (tail->expr);
4169 : 69 : else if (tail && tail->expr)
4170 : : {
4171 : 4 : c2->param_list = gfc_get_actual_arglist ();
4172 : 4 : c2->param_list->name = tail->name;
4173 : 4 : c2->param_list->expr = gfc_copy_expr (tail->expr);
4174 : 4 : c2->param_list->next = NULL;
4175 : : }
4176 : :
4177 : 370 : if (!c2->initializer && c1->initializer)
4178 : 17 : c2->initializer = gfc_copy_expr (c1->initializer);
4179 : : }
4180 : :
4181 : : /* Copy the array spec. */
4182 : 662 : c2->as = gfc_copy_array_spec (c1->as);
4183 : 662 : if (c1->ts.type == BT_CLASS)
4184 : 0 : CLASS_DATA (c2)->as = gfc_copy_array_spec (CLASS_DATA (c1)->as);
4185 : :
4186 : : /* Determine if an array spec is parameterized. If so, substitute
4187 : : in the parameter expressions for the bounds and set the pdt_array
4188 : : attribute. Notice that this attribute must be unconditionally set
4189 : : if this is an array of parameterized character length. */
4190 : 662 : if (c1->as && c1->as->type == AS_EXPLICIT)
4191 : : {
4192 : : bool pdt_array = false;
4193 : :
4194 : : /* Are the bounds of the array parameterized? */
4195 : 327 : for (i = 0; i < c1->as->rank; i++)
4196 : : {
4197 : 202 : if (gfc_derived_parameter_expr (c1->as->lower[i]))
4198 : 0 : pdt_array = true;
4199 : 202 : if (gfc_derived_parameter_expr (c1->as->upper[i]))
4200 : 188 : pdt_array = true;
4201 : : }
4202 : :
4203 : : /* If they are, free the expressions for the bounds and
4204 : : replace them with the template expressions with substitute
4205 : : values. */
4206 : 313 : for (i = 0; pdt_array && i < c1->as->rank; i++)
4207 : : {
4208 : 188 : gfc_expr *e;
4209 : 188 : e = gfc_copy_expr (c1->as->lower[i]);
4210 : 188 : gfc_insert_kind_parameter_exprs (e);
4211 : 188 : gfc_simplify_expr (e, 1);
4212 : 188 : gfc_free_expr (c2->as->lower[i]);
4213 : 188 : c2->as->lower[i] = e;
4214 : 188 : e = gfc_copy_expr (c1->as->upper[i]);
4215 : 188 : gfc_insert_kind_parameter_exprs (e);
4216 : 188 : gfc_simplify_expr (e, 1);
4217 : 188 : gfc_free_expr (c2->as->upper[i]);
4218 : 188 : c2->as->upper[i] = e;
4219 : : }
4220 : 125 : c2->attr.pdt_array = pdt_array ? 1 : c2->attr.pdt_string;
4221 : 125 : if (c1->initializer)
4222 : : {
4223 : 12 : c2->initializer = gfc_copy_expr (c1->initializer);
4224 : 12 : gfc_insert_kind_parameter_exprs (c2->initializer);
4225 : 12 : gfc_simplify_expr (c2->initializer, 1);
4226 : : }
4227 : : }
4228 : :
4229 : : /* Recurse into this function for PDT components. */
4230 : 662 : if ((c1->ts.type == BT_DERIVED || c1->ts.type == BT_CLASS)
4231 : 39 : && c1->ts.u.derived && c1->ts.u.derived->attr.pdt_template)
4232 : : {
4233 : 39 : gfc_actual_arglist *params;
4234 : : /* The component in the template has a list of specification
4235 : : expressions derived from its declaration. */
4236 : 39 : params = gfc_copy_actual_arglist (c1->param_list);
4237 : 39 : actual_param = params;
4238 : : /* Substitute the template parameters with the expressions
4239 : : from the specification list. */
4240 : 118 : for (;actual_param; actual_param = actual_param->next)
4241 : 40 : gfc_insert_parameter_exprs (actual_param->expr,
4242 : : type_param_spec_list);
4243 : :
4244 : : /* Now obtain the PDT instance for the component. */
4245 : 39 : old_param_spec_list = type_param_spec_list;
4246 : 39 : m = gfc_get_pdt_instance (params, &c2->ts.u.derived, NULL);
4247 : 39 : type_param_spec_list = old_param_spec_list;
4248 : :
4249 : 39 : c2->param_list = params;
4250 : 39 : if (!(c2->attr.pointer || c2->attr.allocatable))
4251 : 26 : c2->initializer = gfc_default_initializer (&c2->ts);
4252 : :
4253 : 39 : if (c2->attr.allocatable)
4254 : 7 : instance->attr.alloc_comp = 1;
4255 : : }
4256 : : }
4257 : :
4258 : 226 : gfc_commit_symbol (instance);
4259 : 226 : if (ext_param_list)
4260 : 7 : *ext_param_list = type_param_spec_list;
4261 : 226 : *sym = instance;
4262 : 226 : return m;
4263 : :
4264 : 14 : error_return:
4265 : 14 : gfc_free_actual_arglist (type_param_spec_list);
4266 : 14 : return MATCH_ERROR;
4267 : : }
4268 : :
4269 : :
4270 : : /* Match a legacy nonstandard BYTE type-spec. */
4271 : :
4272 : : static match
4273 : 1113558 : match_byte_typespec (gfc_typespec *ts)
4274 : : {
4275 : 1113558 : if (gfc_match (" byte") == MATCH_YES)
4276 : : {
4277 : 33 : if (!gfc_notify_std (GFC_STD_GNU, "BYTE type at %C"))
4278 : : return MATCH_ERROR;
4279 : :
4280 : 31 : if (gfc_current_form == FORM_FREE)
4281 : : {
4282 : 19 : char c = gfc_peek_ascii_char ();
4283 : 19 : if (!gfc_is_whitespace (c) && c != ',')
4284 : : return MATCH_NO;
4285 : : }
4286 : :
4287 : 29 : if (gfc_validate_kind (BT_INTEGER, 1, true) < 0)
4288 : : {
4289 : 0 : gfc_error ("BYTE type used at %C "
4290 : : "is not available on the target machine");
4291 : 0 : return MATCH_ERROR;
4292 : : }
4293 : :
4294 : 29 : ts->type = BT_INTEGER;
4295 : 29 : ts->kind = 1;
4296 : 29 : return MATCH_YES;
4297 : : }
4298 : : return MATCH_NO;
4299 : : }
4300 : :
4301 : :
4302 : : /* Matches a declaration-type-spec (F03:R502). If successful, sets the ts
4303 : : structure to the matched specification. This is necessary for FUNCTION and
4304 : : IMPLICIT statements.
4305 : :
4306 : : If implicit_flag is nonzero, then we don't check for the optional
4307 : : kind specification. Not doing so is needed for matching an IMPLICIT
4308 : : statement correctly. */
4309 : :
4310 : : match
4311 : 1113558 : gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag)
4312 : : {
4313 : : /* Provide sufficient space to hold "pdtsymbol". */
4314 : 1113558 : char *name = XALLOCAVEC (char, GFC_MAX_SYMBOL_LEN + 1);
4315 : 1113558 : gfc_symbol *sym, *dt_sym;
4316 : 1113558 : match m;
4317 : 1113558 : char c;
4318 : 1113558 : bool seen_deferred_kind, matched_type;
4319 : 1113558 : const char *dt_name;
4320 : :
4321 : 1113558 : decl_type_param_list = NULL;
4322 : :
4323 : : /* A belt and braces check that the typespec is correctly being treated
4324 : : as a deferred characteristic association. */
4325 : 2227116 : seen_deferred_kind = (gfc_current_state () == COMP_FUNCTION)
4326 : 77382 : && (gfc_current_block ()->result->ts.kind == -1)
4327 : 1124984 : && (ts->kind == -1);
4328 : 1113558 : gfc_clear_ts (ts);
4329 : 1113558 : if (seen_deferred_kind)
4330 : 9261 : ts->kind = -1;
4331 : :
4332 : : /* Clear the current binding label, in case one is given. */
4333 : 1113558 : curr_binding_label = NULL;
4334 : :
4335 : : /* Match BYTE type-spec. */
4336 : 1113558 : m = match_byte_typespec (ts);
4337 : 1113558 : if (m != MATCH_NO)
4338 : : return m;
4339 : :
4340 : 1113527 : m = gfc_match (" type (");
4341 : 1113527 : matched_type = (m == MATCH_YES);
4342 : 1113527 : if (matched_type)
4343 : : {
4344 : 27931 : gfc_gobble_whitespace ();
4345 : 27931 : if (gfc_peek_ascii_char () == '*')
4346 : : {
4347 : 4741 : if ((m = gfc_match ("* ) ")) != MATCH_YES)
4348 : : return m;
4349 : 4741 : if (gfc_comp_struct (gfc_current_state ()))
4350 : : {
4351 : 2 : gfc_error ("Assumed type at %C is not allowed for components");
4352 : 2 : return MATCH_ERROR;
4353 : : }
4354 : 4739 : if (!gfc_notify_std (GFC_STD_F2018, "Assumed type at %C"))
4355 : : return MATCH_ERROR;
4356 : 4737 : ts->type = BT_ASSUMED;
4357 : 4737 : return MATCH_YES;
4358 : : }
4359 : :
4360 : 23190 : m = gfc_match ("%n", name);
4361 : 23190 : matched_type = (m == MATCH_YES);
4362 : : }
4363 : :
4364 : 23190 : if ((matched_type && strcmp ("integer", name) == 0)
4365 : 1108786 : || (!matched_type && gfc_match (" integer") == MATCH_YES))
4366 : : {
4367 : 103923 : ts->type = BT_INTEGER;
4368 : 103923 : ts->kind = gfc_default_integer_kind;
4369 : 103923 : goto get_kind;
4370 : : }
4371 : :
4372 : 1004863 : if (flag_unsigned)
4373 : : {
4374 : 0 : if ((matched_type && strcmp ("unsigned", name) == 0)
4375 : 22281 : || (!matched_type && gfc_match (" unsigned") == MATCH_YES))
4376 : : {
4377 : 996 : ts->type = BT_UNSIGNED;
4378 : 996 : ts->kind = gfc_default_integer_kind;
4379 : 996 : goto get_kind;
4380 : : }
4381 : : }
4382 : :
4383 : 23184 : if ((matched_type && strcmp ("character", name) == 0)
4384 : 1003867 : || (!matched_type && gfc_match (" character") == MATCH_YES))
4385 : : {
4386 : 27839 : if (matched_type
4387 : 27839 : && !gfc_notify_std (GFC_STD_F2008, "TYPE with "
4388 : : "intrinsic-type-spec at %C"))
4389 : : return MATCH_ERROR;
4390 : :
4391 : 27838 : ts->type = BT_CHARACTER;
4392 : 27838 : if (implicit_flag == 0)
4393 : 27732 : m = gfc_match_char_spec (ts);
4394 : : else
4395 : : m = MATCH_YES;
4396 : :
4397 : 27838 : if (matched_type && m == MATCH_YES && gfc_match_char (')') != MATCH_YES)
4398 : : {
4399 : 1 : gfc_error ("Malformed type-spec at %C");
4400 : 1 : return MATCH_ERROR;
4401 : : }
4402 : :
4403 : 27837 : return m;
4404 : : }
4405 : :
4406 : 23180 : if ((matched_type && strcmp ("real", name) == 0)
4407 : 976028 : || (!matched_type && gfc_match (" real") == MATCH_YES))
4408 : : {
4409 : 28774 : ts->type = BT_REAL;
4410 : 28774 : ts->kind = gfc_default_real_kind;
4411 : 28774 : goto get_kind;
4412 : : }
4413 : :
4414 : 947254 : if ((matched_type
4415 : 23177 : && (strcmp ("doubleprecision", name) == 0
4416 : 23176 : || (strcmp ("double", name) == 0
4417 : 5 : && gfc_match (" precision") == MATCH_YES)))
4418 : 947254 : || (!matched_type && gfc_match (" double precision") == MATCH_YES))
4419 : : {
4420 : 2543 : if (matched_type
4421 : 2543 : && !gfc_notify_std (GFC_STD_F2008, "TYPE with "
4422 : : "intrinsic-type-spec at %C"))
4423 : : return MATCH_ERROR;
4424 : :
4425 : 2542 : if (matched_type && gfc_match_char (')') != MATCH_YES)
4426 : : {
4427 : 2 : gfc_error ("Malformed type-spec at %C");
4428 : 2 : return MATCH_ERROR;
4429 : : }
4430 : :
4431 : 2540 : ts->type = BT_REAL;
4432 : 2540 : ts->kind = gfc_default_double_kind;
4433 : 2540 : return MATCH_YES;
4434 : : }
4435 : :
4436 : 23173 : if ((matched_type && strcmp ("complex", name) == 0)
4437 : 944711 : || (!matched_type && gfc_match (" complex") == MATCH_YES))
4438 : : {
4439 : 3857 : ts->type = BT_COMPLEX;
4440 : 3857 : ts->kind = gfc_default_complex_kind;
4441 : 3857 : goto get_kind;
4442 : : }
4443 : :
4444 : 940854 : if ((matched_type
4445 : 23173 : && (strcmp ("doublecomplex", name) == 0
4446 : 23172 : || (strcmp ("double", name) == 0
4447 : 2 : && gfc_match (" complex") == MATCH_YES)))
4448 : 940854 : || (!matched_type && gfc_match (" double complex") == MATCH_YES))
4449 : : {
4450 : 204 : if (!gfc_notify_std (GFC_STD_GNU, "DOUBLE COMPLEX at %C"))
4451 : : return MATCH_ERROR;
4452 : :
4453 : 203 : if (matched_type
4454 : 203 : && !gfc_notify_std (GFC_STD_F2008, "TYPE with "
4455 : : "intrinsic-type-spec at %C"))
4456 : : return MATCH_ERROR;
4457 : :
4458 : 203 : if (matched_type && gfc_match_char (')') != MATCH_YES)
4459 : : {
4460 : 2 : gfc_error ("Malformed type-spec at %C");
4461 : 2 : return MATCH_ERROR;
4462 : : }
4463 : :
4464 : 201 : ts->type = BT_COMPLEX;
4465 : 201 : ts->kind = gfc_default_double_kind;
4466 : 201 : return MATCH_YES;
4467 : : }
4468 : :
4469 : 23170 : if ((matched_type && strcmp ("logical", name) == 0)
4470 : 940650 : || (!matched_type && gfc_match (" logical") == MATCH_YES))
4471 : : {
4472 : 11115 : ts->type = BT_LOGICAL;
4473 : 11115 : ts->kind = gfc_default_logical_kind;
4474 : 11115 : goto get_kind;
4475 : : }
4476 : :
4477 : 929535 : if (matched_type)
4478 : : {
4479 : 23167 : m = gfc_match_actual_arglist (1, &decl_type_param_list, true);
4480 : 23167 : if (m == MATCH_ERROR)
4481 : : return m;
4482 : :
4483 : 23167 : gfc_gobble_whitespace ();
4484 : 23167 : if (gfc_peek_ascii_char () != ')')
4485 : : {
4486 : 1 : gfc_error ("Malformed type-spec at %C");
4487 : 1 : return MATCH_ERROR;
4488 : : }
4489 : 23166 : m = gfc_match_char (')'); /* Burn closing ')'. */
4490 : : }
4491 : :
4492 : 929534 : if (m != MATCH_YES)
4493 : 906368 : m = match_record_decl (name);
4494 : :
4495 : 929534 : if (matched_type || m == MATCH_YES)
4496 : : {
4497 : 23510 : ts->type = BT_DERIVED;
4498 : : /* We accept record/s/ or type(s) where s is a structure, but we
4499 : : * don't need all the extra derived-type stuff for structures. */
4500 : 23510 : if (gfc_find_symbol (gfc_dt_upper_string (name), NULL, 1, &sym))
4501 : : {
4502 : 1 : gfc_error ("Type name %qs at %C is ambiguous", name);
4503 : 1 : return MATCH_ERROR;
4504 : : }
4505 : :
4506 : 23509 : if (sym && sym->attr.flavor == FL_DERIVED
4507 : 23117 : && sym->attr.pdt_template
4508 : 406 : && gfc_current_state () != COMP_DERIVED)
4509 : : {
4510 : 367 : m = gfc_get_pdt_instance (decl_type_param_list, &sym, NULL);
4511 : 367 : if (m != MATCH_YES)
4512 : : return m;
4513 : 354 : gcc_assert (!sym->attr.pdt_template && sym->attr.pdt_type);
4514 : 354 : ts->u.derived = sym;
4515 : 354 : const char* lower = gfc_dt_lower_string (sym->name);
4516 : 354 : size_t len = strlen (lower);
4517 : : /* Reallocate with sufficient size. */
4518 : 354 : if (len > GFC_MAX_SYMBOL_LEN)
4519 : 2 : name = XALLOCAVEC (char, len + 1);
4520 : 354 : memcpy (name, lower, len);
4521 : 354 : name[len] = '\0';
4522 : : }
4523 : :
4524 : 23496 : if (sym && sym->attr.flavor == FL_STRUCT)
4525 : : {
4526 : 361 : ts->u.derived = sym;
4527 : 361 : return MATCH_YES;
4528 : : }
4529 : : /* Actually a derived type. */
4530 : : }
4531 : :
4532 : : else
4533 : : {
4534 : : /* Match nested STRUCTURE declarations; only valid within another
4535 : : structure declaration. */
4536 : 906024 : if (flag_dec_structure
4537 : 8032 : && (gfc_current_state () == COMP_STRUCTURE
4538 : 7570 : || gfc_current_state () == COMP_MAP))
4539 : : {
4540 : 732 : m = gfc_match (" structure");
4541 : 732 : if (m == MATCH_YES)
4542 : : {
4543 : 27 : m = gfc_match_structure_decl ();
4544 : 27 : if (m == MATCH_YES)
4545 : : {
4546 : : /* gfc_new_block is updated by match_structure_decl. */
4547 : 26 : ts->type = BT_DERIVED;
4548 : 26 : ts->u.derived = gfc_new_block;
4549 : 26 : return MATCH_YES;
4550 : : }
4551 : : }
4552 : 706 : if (m == MATCH_ERROR)
4553 : : return MATCH_ERROR;
4554 : : }
4555 : :
4556 : : /* Match CLASS declarations. */
4557 : 905997 : m = gfc_match (" class ( * )");
4558 : 905997 : if (m == MATCH_ERROR)
4559 : : return MATCH_ERROR;
4560 : 905997 : else if (m == MATCH_YES)
4561 : : {
4562 : 1775 : gfc_symbol *upe;
4563 : 1775 : gfc_symtree *st;
4564 : 1775 : ts->type = BT_CLASS;
4565 : 1775 : gfc_find_symbol ("STAR", gfc_current_ns, 1, &upe);
4566 : 1775 : if (upe == NULL)
4567 : : {
4568 : 1087 : upe = gfc_new_symbol ("STAR", gfc_current_ns);
4569 : 1087 : st = gfc_new_symtree (&gfc_current_ns->sym_root, "STAR");
4570 : 1087 : st->n.sym = upe;
4571 : 1087 : gfc_set_sym_referenced (upe);
4572 : 1087 : upe->refs++;
4573 : 1087 : upe->ts.type = BT_VOID;
4574 : 1087 : upe->attr.unlimited_polymorphic = 1;
4575 : : /* This is essential to force the construction of
4576 : : unlimited polymorphic component class containers. */
4577 : 1087 : upe->attr.zero_comp = 1;
4578 : 1087 : if (!gfc_add_flavor (&upe->attr, FL_DERIVED, NULL,
4579 : : &gfc_current_locus))
4580 : : return MATCH_ERROR;
4581 : : }
4582 : : else
4583 : : {
4584 : 688 : st = gfc_get_tbp_symtree (&gfc_current_ns->sym_root, "STAR");
4585 : 688 : st->n.sym = upe;
4586 : 688 : upe->refs++;
4587 : : }
4588 : 1775 : ts->u.derived = upe;
4589 : 1775 : return m;
4590 : : }
4591 : :
4592 : 904222 : m = gfc_match (" class (");
4593 : :
4594 : 904222 : if (m == MATCH_YES)
4595 : 8466 : m = gfc_match ("%n", name);
4596 : : else
4597 : : return m;
4598 : :
4599 : 8466 : if (m != MATCH_YES)
4600 : : return m;
4601 : 8466 : ts->type = BT_CLASS;
4602 : :
4603 : 8466 : if (!gfc_notify_std (GFC_STD_F2003, "CLASS statement at %C"))
4604 : : return MATCH_ERROR;
4605 : :
4606 : 8465 : m = gfc_match_actual_arglist (1, &decl_type_param_list, true);
4607 : 8465 : if (m == MATCH_ERROR)
4608 : : return m;
4609 : :
4610 : 8465 : m = gfc_match_char (')');
4611 : 8465 : if (m != MATCH_YES)
4612 : : return m;
4613 : : }
4614 : :
4615 : : /* Defer association of the derived type until the end of the
4616 : : specification block. However, if the derived type can be
4617 : : found, add it to the typespec. */
4618 : 31600 : if (gfc_matching_function)
4619 : : {
4620 : 1014 : ts->u.derived = NULL;
4621 : 1014 : if (gfc_current_state () != COMP_INTERFACE
4622 : 1014 : && !gfc_find_symbol (name, NULL, 1, &sym) && sym)
4623 : : {
4624 : 499 : sym = gfc_find_dt_in_generic (sym);
4625 : 499 : ts->u.derived = sym;
4626 : : }
4627 : 1014 : return MATCH_YES;
4628 : : }
4629 : :
4630 : : /* Search for the name but allow the components to be defined later. If
4631 : : type = -1, this typespec has been seen in a function declaration but
4632 : : the type could not be accessed at that point. The actual derived type is
4633 : : stored in a symtree with the first letter of the name capitalized; the
4634 : : symtree with the all lower-case name contains the associated
4635 : : generic function. */
4636 : 30586 : dt_name = gfc_dt_upper_string (name);
4637 : 30586 : sym = NULL;
4638 : 30586 : dt_sym = NULL;
4639 : 30586 : if (ts->kind != -1)
4640 : : {
4641 : 29411 : gfc_get_ha_symbol (name, &sym);
4642 : 29411 : if (sym->generic && gfc_find_symbol (dt_name, NULL, 0, &dt_sym))
4643 : : {
4644 : 0 : gfc_error ("Type name %qs at %C is ambiguous", name);
4645 : 0 : return MATCH_ERROR;
4646 : : }
4647 : 29411 : if (sym->generic && !dt_sym)
4648 : 12387 : dt_sym = gfc_find_dt_in_generic (sym);
4649 : :
4650 : : /* Host associated PDTs can get confused with their constructors
4651 : : because they ar instantiated in the template's namespace. */
4652 : 29411 : if (!dt_sym)
4653 : : {
4654 : 473 : if (gfc_find_symbol (dt_name, NULL, 1, &dt_sym))
4655 : : {
4656 : 0 : gfc_error ("Type name %qs at %C is ambiguous", name);
4657 : 0 : return MATCH_ERROR;
4658 : : }
4659 : 473 : if (dt_sym && !dt_sym->attr.pdt_type)
4660 : 0 : dt_sym = NULL;
4661 : : }
4662 : : }
4663 : 1175 : else if (ts->kind == -1)
4664 : : {
4665 : 2350 : int iface = gfc_state_stack->previous->state != COMP_INTERFACE
4666 : 1175 : || gfc_current_ns->has_import_set;
4667 : 1175 : gfc_find_symbol (name, NULL, iface, &sym);
4668 : 1175 : if (sym && sym->generic && gfc_find_symbol (dt_name, NULL, 1, &dt_sym))
4669 : : {
4670 : 0 : gfc_error ("Type name %qs at %C is ambiguous", name);
4671 : 0 : return MATCH_ERROR;
4672 : : }
4673 : 1175 : if (sym && sym->generic && !dt_sym)
4674 : 0 : dt_sym = gfc_find_dt_in_generic (sym);
4675 : :
4676 : 1175 : ts->kind = 0;
4677 : 1175 : if (sym == NULL)
4678 : : return MATCH_NO;
4679 : : }
4680 : :
4681 : 30577 : if ((sym->attr.flavor != FL_UNKNOWN && sym->attr.flavor != FL_STRUCT
4682 : 30226 : && !(sym->attr.flavor == FL_PROCEDURE && sym->attr.generic))
4683 : 30575 : || sym->attr.subroutine)
4684 : : {
4685 : 2 : gfc_error ("Type name %qs at %C conflicts with previously declared "
4686 : : "entity at %L, which has the same name", name,
4687 : : &sym->declared_at);
4688 : 2 : return MATCH_ERROR;
4689 : : }
4690 : :
4691 : 30575 : if (sym && sym->attr.flavor == FL_DERIVED
4692 : 30575 : && sym->attr.pdt_template
4693 : 0 : && gfc_current_state () != COMP_DERIVED)
4694 : : {
4695 : 0 : m = gfc_get_pdt_instance (decl_type_param_list, &sym, NULL);
4696 : 0 : if (m != MATCH_YES)
4697 : : return m;
4698 : 0 : gcc_assert (!sym->attr.pdt_template && sym->attr.pdt_type);
4699 : 0 : ts->u.derived = sym;
4700 : 0 : strcpy (name, gfc_dt_lower_string (sym->name));
4701 : : }
4702 : :
4703 : 30575 : gfc_save_symbol_data (sym);
4704 : 30575 : gfc_set_sym_referenced (sym);
4705 : 30575 : if (!sym->attr.generic
4706 : 30575 : && !gfc_add_generic (&sym->attr, sym->name, NULL))
4707 : : return MATCH_ERROR;
4708 : :
4709 : 30575 : if (!sym->attr.function
4710 : 30575 : && !gfc_add_function (&sym->attr, sym->name, NULL))
4711 : : return MATCH_ERROR;
4712 : :
4713 : 30575 : if (dt_sym && dt_sym->attr.flavor == FL_DERIVED
4714 : 30455 : && dt_sym->attr.pdt_template
4715 : 81 : && gfc_current_state () != COMP_DERIVED)
4716 : : {
4717 : 42 : m = gfc_get_pdt_instance (decl_type_param_list, &dt_sym, NULL);
4718 : 42 : if (m != MATCH_YES)
4719 : : return m;
4720 : 42 : gcc_assert (!dt_sym->attr.pdt_template && dt_sym->attr.pdt_type);
4721 : : }
4722 : :
4723 : 30575 : if (!dt_sym)
4724 : : {
4725 : 120 : gfc_interface *intr, *head;
4726 : :
4727 : : /* Use upper case to save the actual derived-type symbol. */
4728 : 120 : gfc_get_symbol (dt_name, NULL, &dt_sym);
4729 : 120 : dt_sym->name = gfc_get_string ("%s", sym->name);
4730 : 120 : head = sym->generic;
4731 : 120 : intr = gfc_get_interface ();
4732 : 120 : intr->sym = dt_sym;
4733 : 120 : intr->where = gfc_current_locus;
4734 : 120 : intr->next = head;
4735 : 120 : sym->generic = intr;
4736 : 120 : sym->attr.if_source = IFSRC_DECL;
4737 : : }
4738 : : else
4739 : 30455 : gfc_save_symbol_data (dt_sym);
4740 : :
4741 : 30575 : gfc_set_sym_referenced (dt_sym);
4742 : :
4743 : 120 : if (dt_sym->attr.flavor != FL_DERIVED && dt_sym->attr.flavor != FL_STRUCT
4744 : 30695 : && !gfc_add_flavor (&dt_sym->attr, FL_DERIVED, sym->name, NULL))
4745 : : return MATCH_ERROR;
4746 : :
4747 : 30575 : ts->u.derived = dt_sym;
4748 : :
4749 : 30575 : return MATCH_YES;
4750 : :
4751 : 148665 : get_kind:
4752 : 148665 : if (matched_type
4753 : 148665 : && !gfc_notify_std (GFC_STD_F2008, "TYPE with "
4754 : : "intrinsic-type-spec at %C"))
4755 : : return MATCH_ERROR;
4756 : :
4757 : : /* For all types except double, derived and character, look for an
4758 : : optional kind specifier. MATCH_NO is actually OK at this point. */
4759 : 148662 : if (implicit_flag == 1)
4760 : : {
4761 : 223 : if (matched_type && gfc_match_char (')') != MATCH_YES)
4762 : : return MATCH_ERROR;
4763 : :
4764 : 223 : return MATCH_YES;
4765 : : }
4766 : :
4767 : 148439 : if (gfc_current_form == FORM_FREE)
4768 : : {
4769 : 135467 : c = gfc_peek_ascii_char ();
4770 : 135467 : if (!gfc_is_whitespace (c) && c != '*' && c != '('
4771 : 67218 : && c != ':' && c != ',')
4772 : : {
4773 : 166 : if (matched_type && c == ')')
4774 : : {
4775 : 3 : gfc_next_ascii_char ();
4776 : 3 : return MATCH_YES;
4777 : : }
4778 : 163 : gfc_error ("Malformed type-spec at %C");
4779 : 163 : return MATCH_NO;
4780 : : }
4781 : : }
4782 : :
4783 : 148273 : m = gfc_match_kind_spec (ts, false);
4784 : 148273 : if (m == MATCH_ERROR)
4785 : : return MATCH_ERROR;
4786 : :
4787 : 148237 : if (m == MATCH_NO && ts->type != BT_CHARACTER)
4788 : : {
4789 : 102886 : m = gfc_match_old_kind_spec (ts);
4790 : 102886 : if (gfc_validate_kind (ts->type, ts->kind, true) == -1)
4791 : : return MATCH_ERROR;
4792 : : }
4793 : :
4794 : 148229 : if (matched_type && gfc_match_char (')') != MATCH_YES)
4795 : : {
4796 : 0 : gfc_error ("Malformed type-spec at %C");
4797 : 0 : return MATCH_ERROR;
4798 : : }
4799 : :
4800 : : /* Defer association of the KIND expression of function results
4801 : : until after USE and IMPORT statements. */
4802 : 4397 : if ((gfc_current_state () == COMP_NONE && gfc_error_flag_test ())
4803 : 152599 : || gfc_matching_function)
4804 : 6931 : return MATCH_YES;
4805 : :
4806 : 141298 : if (m == MATCH_NO)
4807 : 143045 : m = MATCH_YES; /* No kind specifier found. */
4808 : :
4809 : : return m;
4810 : : }
4811 : :
4812 : :
4813 : : /* Match an IMPLICIT NONE statement. Actually, this statement is
4814 : : already matched in parse.cc, or we would not end up here in the
4815 : : first place. So the only thing we need to check, is if there is
4816 : : trailing garbage. If not, the match is successful. */
4817 : :
4818 : : match
4819 : 22337 : gfc_match_implicit_none (void)
4820 : : {
4821 : 22337 : char c;
4822 : 22337 : match m;
4823 : 22337 : char name[GFC_MAX_SYMBOL_LEN + 1];
4824 : 22337 : bool type = false;
4825 : 22337 : bool external = false;
4826 : 22337 : locus cur_loc = gfc_current_locus;
4827 : :
4828 : 22337 : if (gfc_current_ns->seen_implicit_none
4829 : 22335 : || gfc_current_ns->has_implicit_none_export)
4830 : : {
4831 : 4 : gfc_error ("Duplicate IMPLICIT NONE statement at %C");
4832 : 4 : return MATCH_ERROR;
4833 : : }
4834 : :
4835 : 22333 : gfc_gobble_whitespace ();
4836 : 22333 : c = gfc_peek_ascii_char ();
4837 : 22333 : if (c == '(')
4838 : : {
4839 : 1027 : (void) gfc_next_ascii_char ();
4840 : 1027 : if (!gfc_notify_std (GFC_STD_F2018, "IMPLICIT NONE with spec list at %C"))
4841 : : return MATCH_ERROR;
4842 : :
4843 : 1026 : gfc_gobble_whitespace ();
4844 : 1026 : if (gfc_peek_ascii_char () == ')')
4845 : : {
4846 : 1 : (void) gfc_next_ascii_char ();
4847 : 1 : type = true;
4848 : : }
4849 : : else
4850 : 3055 : for(;;)
4851 : : {
4852 : 2040 : m = gfc_match (" %n", name);
4853 : 2040 : if (m != MATCH_YES)
4854 : : return MATCH_ERROR;
4855 : :
4856 : 2040 : if (strcmp (name, "type") == 0)
4857 : : type = true;
4858 : 1025 : else if (strcmp (name, "external") == 0)
4859 : : external = true;
4860 : : else
4861 : : return MATCH_ERROR;
4862 : :
4863 : 2040 : gfc_gobble_whitespace ();
4864 : 2040 : c = gfc_next_ascii_char ();
4865 : 2040 : if (c == ',')
4866 : 1015 : continue;
4867 : 1025 : if (c == ')')
4868 : : break;
4869 : : return MATCH_ERROR;
4870 : : }
4871 : : }
4872 : : else
4873 : : type = true;
4874 : :
4875 : 22332 : if (gfc_match_eos () != MATCH_YES)
4876 : : return MATCH_ERROR;
4877 : :
4878 : 22332 : gfc_set_implicit_none (type, external, &cur_loc);
4879 : :
4880 : 22332 : return MATCH_YES;
4881 : : }
4882 : :
4883 : :
4884 : : /* Match the letter range(s) of an IMPLICIT statement. */
4885 : :
4886 : : static match
4887 : 600 : match_implicit_range (void)
4888 : : {
4889 : 600 : char c, c1, c2;
4890 : 600 : int inner;
4891 : 600 : locus cur_loc;
4892 : :
4893 : 600 : cur_loc = gfc_current_locus;
4894 : :
4895 : 600 : gfc_gobble_whitespace ();
4896 : 600 : c = gfc_next_ascii_char ();
4897 : 600 : if (c != '(')
4898 : : {
4899 : 59 : gfc_error ("Missing character range in IMPLICIT at %C");
4900 : 59 : goto bad;
4901 : : }
4902 : :
4903 : : inner = 1;
4904 : 1195 : while (inner)
4905 : : {
4906 : 722 : gfc_gobble_whitespace ();
4907 : 722 : c1 = gfc_next_ascii_char ();
4908 : 722 : if (!ISALPHA (c1))
4909 : 33 : goto bad;
4910 : :
4911 : 689 : gfc_gobble_whitespace ();
4912 : 689 : c = gfc_next_ascii_char ();
4913 : :
4914 : 689 : switch (c)
4915 : : {
4916 : 201 : case ')':
4917 : 201 : inner = 0; /* Fall through. */
4918 : :
4919 : : case ',':
4920 : : c2 = c1;
4921 : : break;
4922 : :
4923 : 439 : case '-':
4924 : 439 : gfc_gobble_whitespace ();
4925 : 439 : c2 = gfc_next_ascii_char ();
4926 : 439 : if (!ISALPHA (c2))
4927 : 0 : goto bad;
4928 : :
4929 : 439 : gfc_gobble_whitespace ();
4930 : 439 : c = gfc_next_ascii_char ();
4931 : :
4932 : 439 : if ((c != ',') && (c != ')'))
4933 : 0 : goto bad;
4934 : 439 : if (c == ')')
4935 : 272 : inner = 0;
4936 : :
4937 : : break;
4938 : :
4939 : 35 : default:
4940 : 35 : goto bad;
4941 : : }
4942 : :
4943 : 654 : if (c1 > c2)
4944 : : {
4945 : 0 : gfc_error ("Letters must be in alphabetic order in "
4946 : : "IMPLICIT statement at %C");
4947 : 0 : goto bad;
4948 : : }
4949 : :
4950 : : /* See if we can add the newly matched range to the pending
4951 : : implicits from this IMPLICIT statement. We do not check for
4952 : : conflicts with whatever earlier IMPLICIT statements may have
4953 : : set. This is done when we've successfully finished matching
4954 : : the current one. */
4955 : 654 : if (!gfc_add_new_implicit_range (c1, c2))
4956 : 0 : goto bad;
4957 : : }
4958 : :
4959 : : return MATCH_YES;
4960 : :
4961 : 127 : bad:
4962 : 127 : gfc_syntax_error (ST_IMPLICIT);
4963 : :
4964 : 127 : gfc_current_locus = cur_loc;
4965 : 127 : return MATCH_ERROR;
4966 : : }
4967 : :
4968 : :
4969 : : /* Match an IMPLICIT statement, storing the types for
4970 : : gfc_set_implicit() if the statement is accepted by the parser.
4971 : : There is a strange looking, but legal syntactic construction
4972 : : possible. It looks like:
4973 : :
4974 : : IMPLICIT INTEGER (a-b) (c-d)
4975 : :
4976 : : This is legal if "a-b" is a constant expression that happens to
4977 : : equal one of the legal kinds for integers. The real problem
4978 : : happens with an implicit specification that looks like:
4979 : :
4980 : : IMPLICIT INTEGER (a-b)
4981 : :
4982 : : In this case, a typespec matcher that is "greedy" (as most of the
4983 : : matchers are) gobbles the character range as a kindspec, leaving
4984 : : nothing left. We therefore have to go a bit more slowly in the
4985 : : matching process by inhibiting the kindspec checking during
4986 : : typespec matching and checking for a kind later. */
4987 : :
4988 : : match
4989 : 22763 : gfc_match_implicit (void)
4990 : : {
4991 : 22763 : gfc_typespec ts;
4992 : 22763 : locus cur_loc;
4993 : 22763 : char c;
4994 : 22763 : match m;
4995 : :
4996 : 22763 : if (gfc_current_ns->seen_implicit_none)
4997 : : {
4998 : 4 : gfc_error ("IMPLICIT statement at %C following an IMPLICIT NONE (type) "
4999 : : "statement");
5000 : 4 : return MATCH_ERROR;
5001 : : }
5002 : :
5003 : 22759 : gfc_clear_ts (&ts);
5004 : :
5005 : : /* We don't allow empty implicit statements. */
5006 : 22759 : if (gfc_match_eos () == MATCH_YES)
5007 : : {
5008 : 0 : gfc_error ("Empty IMPLICIT statement at %C");
5009 : 0 : return MATCH_ERROR;
5010 : : }
5011 : :
5012 : 22788 : do
5013 : : {
5014 : : /* First cleanup. */
5015 : 22788 : gfc_clear_new_implicit ();
5016 : :
5017 : : /* A basic type is mandatory here. */
5018 : 22788 : m = gfc_match_decl_type_spec (&ts, 1);
5019 : 22788 : if (m == MATCH_ERROR)
5020 : 0 : goto error;
5021 : 22788 : if (m == MATCH_NO)
5022 : 22335 : goto syntax;
5023 : :
5024 : 453 : cur_loc = gfc_current_locus;
5025 : 453 : m = match_implicit_range ();
5026 : :
5027 : 453 : if (m == MATCH_YES)
5028 : : {
5029 : : /* We may have <TYPE> (<RANGE>). */
5030 : 326 : gfc_gobble_whitespace ();
5031 : 326 : c = gfc_peek_ascii_char ();
5032 : 326 : if (c == ',' || c == '\n' || c == ';' || c == '!')
5033 : : {
5034 : : /* Check for CHARACTER with no length parameter. */
5035 : 299 : if (ts.type == BT_CHARACTER && !ts.u.cl)
5036 : : {
5037 : 32 : ts.kind = gfc_default_character_kind;
5038 : 32 : ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
5039 : 32 : ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind,
5040 : : NULL, 1);
5041 : : }
5042 : :
5043 : : /* Record the Successful match. */
5044 : 299 : if (!gfc_merge_new_implicit (&ts))
5045 : : return MATCH_ERROR;
5046 : 297 : if (c == ',')
5047 : 28 : c = gfc_next_ascii_char ();
5048 : 269 : else if (gfc_match_eos () == MATCH_ERROR)
5049 : 0 : goto error;
5050 : 297 : continue;
5051 : : }
5052 : :
5053 : 27 : gfc_current_locus = cur_loc;
5054 : : }
5055 : :
5056 : : /* Discard the (incorrectly) matched range. */
5057 : 154 : gfc_clear_new_implicit ();
5058 : :
5059 : : /* Last chance -- check <TYPE> <SELECTOR> (<RANGE>). */
5060 : 154 : if (ts.type == BT_CHARACTER)
5061 : 74 : m = gfc_match_char_spec (&ts);
5062 : 80 : else if (gfc_numeric_ts(&ts) || ts.type == BT_LOGICAL)
5063 : : {
5064 : 76 : m = gfc_match_kind_spec (&ts, false);
5065 : 76 : if (m == MATCH_NO)
5066 : : {
5067 : 40 : m = gfc_match_old_kind_spec (&ts);
5068 : 40 : if (m == MATCH_ERROR)
5069 : 0 : goto error;
5070 : 40 : if (m == MATCH_NO)
5071 : 0 : goto syntax;
5072 : : }
5073 : : }
5074 : 154 : if (m == MATCH_ERROR)
5075 : 7 : goto error;
5076 : :
5077 : 147 : m = match_implicit_range ();
5078 : 147 : if (m == MATCH_ERROR)
5079 : 0 : goto error;
5080 : 147 : if (m == MATCH_NO)
5081 : : goto syntax;
5082 : :
5083 : 147 : gfc_gobble_whitespace ();
5084 : 147 : c = gfc_next_ascii_char ();
5085 : 147 : if (c != ',' && gfc_match_eos () != MATCH_YES)
5086 : 0 : goto syntax;
5087 : :
5088 : 147 : if (!gfc_merge_new_implicit (&ts))
5089 : : return MATCH_ERROR;
5090 : : }
5091 : 444 : while (c == ',');
5092 : :
5093 : : return MATCH_YES;
5094 : :
5095 : 22335 : syntax:
5096 : 22335 : gfc_syntax_error (ST_IMPLICIT);
5097 : :
5098 : : error:
5099 : : return MATCH_ERROR;
5100 : : }
5101 : :
5102 : :
5103 : : match
5104 : 3139 : gfc_match_import (void)
5105 : : {
5106 : 3139 : char name[GFC_MAX_SYMBOL_LEN + 1];
5107 : 3139 : match m;
5108 : 3139 : gfc_symbol *sym;
5109 : 3139 : gfc_symtree *st;
5110 : :
5111 : 3139 : if (gfc_current_ns->proc_name == NULL
5112 : 3138 : || gfc_current_ns->proc_name->attr.if_source != IFSRC_IFBODY)
5113 : : {
5114 : 3 : gfc_error ("IMPORT statement at %C only permitted in "
5115 : : "an INTERFACE body");
5116 : 3 : return MATCH_ERROR;
5117 : : }
5118 : :
5119 : 3136 : if (gfc_current_ns->proc_name->attr.module_procedure)
5120 : : {
5121 : 1 : gfc_error ("F2008: C1210 IMPORT statement at %C is not permitted "
5122 : : "in a module procedure interface body");
5123 : 1 : return MATCH_ERROR;
5124 : : }
5125 : :
5126 : 3135 : if (!gfc_notify_std (GFC_STD_F2003, "IMPORT statement at %C"))
5127 : : return MATCH_ERROR;
5128 : :
5129 : 3131 : if (gfc_match_eos () == MATCH_YES)
5130 : : {
5131 : : /* All host variables should be imported. */
5132 : 214 : gfc_current_ns->has_import_set = 1;
5133 : 214 : return MATCH_YES;
5134 : : }
5135 : :
5136 : 2917 : if (gfc_match (" ::") == MATCH_YES)
5137 : : {
5138 : 827 : if (gfc_match_eos () == MATCH_YES)
5139 : : {
5140 : 1 : gfc_error ("Expecting list of named entities at %C");
5141 : 1 : return MATCH_ERROR;
5142 : : }
5143 : : }
5144 : :
5145 : 3591 : for(;;)
5146 : : {
5147 : 3591 : sym = NULL;
5148 : 3591 : m = gfc_match (" %n", name);
5149 : 3591 : switch (m)
5150 : : {
5151 : 3591 : case MATCH_YES:
5152 : 3591 : if (gfc_current_ns->parent != NULL
5153 : 3591 : && gfc_find_symbol (name, gfc_current_ns->parent, 1, &sym))
5154 : : {
5155 : 0 : gfc_error ("Type name %qs at %C is ambiguous", name);
5156 : 0 : return MATCH_ERROR;
5157 : : }
5158 : 1 : else if (!sym && gfc_current_ns->proc_name->ns->parent != NULL
5159 : 3591 : && gfc_find_symbol (name,
5160 : : gfc_current_ns->proc_name->ns->parent,
5161 : : 1, &sym))
5162 : : {
5163 : 0 : gfc_error ("Type name %qs at %C is ambiguous", name);
5164 : 0 : return MATCH_ERROR;
5165 : : }
5166 : :
5167 : 3591 : if (sym == NULL)
5168 : : {
5169 : 1 : gfc_error ("Cannot IMPORT %qs from host scoping unit "
5170 : : "at %C - does not exist.", name);
5171 : 1 : return MATCH_ERROR;
5172 : : }
5173 : :
5174 : 3590 : if (gfc_find_symtree (gfc_current_ns->sym_root, name))
5175 : : {
5176 : 6 : gfc_warning (0, "%qs is already IMPORTed from host scoping unit "
5177 : : "at %C", name);
5178 : 6 : goto next_item;
5179 : : }
5180 : :
5181 : 3584 : st = gfc_new_symtree (&gfc_current_ns->sym_root, name);
5182 : 3584 : st->n.sym = sym;
5183 : 3584 : sym->refs++;
5184 : 3584 : sym->attr.imported = 1;
5185 : :
5186 : 3584 : if (sym->attr.generic && (sym = gfc_find_dt_in_generic (sym)))
5187 : : {
5188 : : /* The actual derived type is stored in a symtree with the first
5189 : : letter of the name capitalized; the symtree with the all
5190 : : lower-case name contains the associated generic function. */
5191 : 593 : st = gfc_new_symtree (&gfc_current_ns->sym_root,
5192 : : gfc_dt_upper_string (name));
5193 : 593 : st->n.sym = sym;
5194 : 593 : sym->refs++;
5195 : 593 : sym->attr.imported = 1;
5196 : : }
5197 : :
5198 : 3584 : goto next_item;
5199 : :
5200 : : case MATCH_NO:
5201 : : break;
5202 : :
5203 : : case MATCH_ERROR:
5204 : : return MATCH_ERROR;
5205 : : }
5206 : :
5207 : 3590 : next_item:
5208 : 3590 : if (gfc_match_eos () == MATCH_YES)
5209 : : break;
5210 : 675 : if (gfc_match_char (',') != MATCH_YES)
5211 : 0 : goto syntax;
5212 : : }
5213 : :
5214 : : return MATCH_YES;
5215 : :
5216 : 0 : syntax:
5217 : 0 : gfc_error ("Syntax error in IMPORT statement at %C");
5218 : 0 : return MATCH_ERROR;
5219 : : }
5220 : :
5221 : :
5222 : : /* A minimal implementation of gfc_match without whitespace, escape
5223 : : characters or variable arguments. Returns true if the next
5224 : : characters match the TARGET template exactly. */
5225 : :
5226 : : static bool
5227 : 136425 : match_string_p (const char *target)
5228 : : {
5229 : 136425 : const char *p;
5230 : :
5231 : 862352 : for (p = target; *p; p++)
5232 : 725928 : if ((char) gfc_next_ascii_char () != *p)
5233 : : return false;
5234 : : return true;
5235 : : }
5236 : :
5237 : : /* Matches an attribute specification including array specs. If
5238 : : successful, leaves the variables current_attr and current_as
5239 : : holding the specification. Also sets the colon_seen variable for
5240 : : later use by matchers associated with initializations.
5241 : :
5242 : : This subroutine is a little tricky in the sense that we don't know
5243 : : if we really have an attr-spec until we hit the double colon.
5244 : : Until that time, we can only return MATCH_NO. This forces us to
5245 : : check for duplicate specification at this level. */
5246 : :
5247 : : static match
5248 : 202088 : match_attr_spec (void)
5249 : : {
5250 : : /* Modifiers that can exist in a type statement. */
5251 : 202088 : enum
5252 : : { GFC_DECL_BEGIN = 0, DECL_ALLOCATABLE = GFC_DECL_BEGIN,
5253 : : DECL_IN = INTENT_IN, DECL_OUT = INTENT_OUT, DECL_INOUT = INTENT_INOUT,
5254 : : DECL_DIMENSION, DECL_EXTERNAL,
5255 : : DECL_INTRINSIC, DECL_OPTIONAL,
5256 : : DECL_PARAMETER, DECL_POINTER, DECL_PROTECTED, DECL_PRIVATE,
5257 : : DECL_STATIC, DECL_AUTOMATIC,
5258 : : DECL_PUBLIC, DECL_SAVE, DECL_TARGET, DECL_VALUE, DECL_VOLATILE,
5259 : : DECL_IS_BIND_C, DECL_CODIMENSION, DECL_ASYNCHRONOUS, DECL_CONTIGUOUS,
5260 : : DECL_LEN, DECL_KIND, DECL_NONE, GFC_DECL_END /* Sentinel */
5261 : : };
5262 : :
5263 : : /* GFC_DECL_END is the sentinel, index starts at 0. */
5264 : : #define NUM_DECL GFC_DECL_END
5265 : :
5266 : : /* Make sure that values from sym_intent are safe to be used here. */
5267 : 202088 : gcc_assert (INTENT_IN > 0);
5268 : :
5269 : 202088 : locus start, seen_at[NUM_DECL];
5270 : 202088 : int seen[NUM_DECL];
5271 : 202088 : unsigned int d;
5272 : 202088 : const char *attr;
5273 : 202088 : match m;
5274 : 202088 : bool t;
5275 : :
5276 : 202088 : gfc_clear_attr (¤t_attr);
5277 : 202088 : start = gfc_current_locus;
5278 : :
5279 : 202088 : current_as = NULL;
5280 : 202088 : colon_seen = 0;
5281 : 202088 : attr_seen = 0;
5282 : :
5283 : : /* See if we get all of the keywords up to the final double colon. */
5284 : 5456376 : for (d = GFC_DECL_BEGIN; d != GFC_DECL_END; d++)
5285 : 5254288 : seen[d] = 0;
5286 : :
5287 : 312832 : for (;;)
5288 : : {
5289 : 312832 : char ch;
5290 : :
5291 : 312832 : d = DECL_NONE;
5292 : 312832 : gfc_gobble_whitespace ();
5293 : :
5294 : 312832 : ch = gfc_next_ascii_char ();
5295 : 312832 : if (ch == ':')
5296 : : {
5297 : : /* This is the successful exit condition for the loop. */
5298 : 170729 : if (gfc_next_ascii_char () == ':')
5299 : : break;
5300 : : }
5301 : 142103 : else if (ch == ',')
5302 : : {
5303 : 110756 : gfc_gobble_whitespace ();
5304 : 110756 : switch (gfc_peek_ascii_char ())
5305 : : {
5306 : 17173 : case 'a':
5307 : 17173 : gfc_next_ascii_char ();
5308 : 17173 : switch (gfc_next_ascii_char ())
5309 : : {
5310 : 17108 : case 'l':
5311 : 17108 : if (match_string_p ("locatable"))
5312 : : {
5313 : : /* Matched "allocatable". */
5314 : : d = DECL_ALLOCATABLE;
5315 : : }
5316 : : break;
5317 : :
5318 : 24 : case 's':
5319 : 24 : if (match_string_p ("ynchronous"))
5320 : : {
5321 : : /* Matched "asynchronous". */
5322 : : d = DECL_ASYNCHRONOUS;
5323 : : }
5324 : : break;
5325 : :
5326 : 41 : case 'u':
5327 : 41 : if (match_string_p ("tomatic"))
5328 : : {
5329 : : /* Matched "automatic". */
5330 : : d = DECL_AUTOMATIC;
5331 : : }
5332 : : break;
5333 : : }
5334 : : break;
5335 : :
5336 : 162 : case 'b':
5337 : : /* Try and match the bind(c). */
5338 : 162 : m = gfc_match_bind_c (NULL, true);
5339 : 162 : if (m == MATCH_YES)
5340 : : d = DECL_IS_BIND_C;
5341 : 0 : else if (m == MATCH_ERROR)
5342 : 0 : goto cleanup;
5343 : : break;
5344 : :
5345 : 1932 : case 'c':
5346 : 1932 : gfc_next_ascii_char ();
5347 : 1932 : if ('o' != gfc_next_ascii_char ())
5348 : : break;
5349 : 1931 : switch (gfc_next_ascii_char ())
5350 : : {
5351 : 46 : case 'd':
5352 : 46 : if (match_string_p ("imension"))
5353 : : {
5354 : : d = DECL_CODIMENSION;
5355 : : break;
5356 : : }
5357 : : /* FALLTHRU */
5358 : 1885 : case 'n':
5359 : 1885 : if (match_string_p ("tiguous"))
5360 : : {
5361 : : d = DECL_CONTIGUOUS;
5362 : : break;
5363 : : }
5364 : : }
5365 : : break;
5366 : :
5367 : 18559 : case 'd':
5368 : 18559 : if (match_string_p ("dimension"))
5369 : : d = DECL_DIMENSION;
5370 : : break;
5371 : :
5372 : 176 : case 'e':
5373 : 176 : if (match_string_p ("external"))
5374 : : d = DECL_EXTERNAL;
5375 : : break;
5376 : :
5377 : 25832 : case 'i':
5378 : 25832 : if (match_string_p ("int"))
5379 : : {
5380 : 25832 : ch = gfc_next_ascii_char ();
5381 : 25832 : if (ch == 'e')
5382 : : {
5383 : 25826 : if (match_string_p ("nt"))
5384 : : {
5385 : : /* Matched "intent". */
5386 : 25825 : d = match_intent_spec ();
5387 : 25825 : if (d == INTENT_UNKNOWN)
5388 : : {
5389 : 2 : m = MATCH_ERROR;
5390 : 2 : goto cleanup;
5391 : : }
5392 : : }
5393 : : }
5394 : 6 : else if (ch == 'r')
5395 : : {
5396 : 6 : if (match_string_p ("insic"))
5397 : : {
5398 : : /* Matched "intrinsic". */
5399 : : d = DECL_INTRINSIC;
5400 : : }
5401 : : }
5402 : : }
5403 : : break;
5404 : :
5405 : 136 : case 'k':
5406 : 136 : if (match_string_p ("kind"))
5407 : : d = DECL_KIND;
5408 : : break;
5409 : :
5410 : 179 : case 'l':
5411 : 179 : if (match_string_p ("len"))
5412 : : d = DECL_LEN;
5413 : : break;
5414 : :
5415 : 4953 : case 'o':
5416 : 4953 : if (match_string_p ("optional"))
5417 : : d = DECL_OPTIONAL;
5418 : : break;
5419 : :
5420 : 25986 : case 'p':
5421 : 25986 : gfc_next_ascii_char ();
5422 : 25986 : switch (gfc_next_ascii_char ())
5423 : : {
5424 : 13597 : case 'a':
5425 : 13597 : if (match_string_p ("rameter"))
5426 : : {
5427 : : /* Matched "parameter". */
5428 : : d = DECL_PARAMETER;
5429 : : }
5430 : : break;
5431 : :
5432 : 11873 : case 'o':
5433 : 11873 : if (match_string_p ("inter"))
5434 : : {
5435 : : /* Matched "pointer". */
5436 : : d = DECL_POINTER;
5437 : : }
5438 : : break;
5439 : :
5440 : 265 : case 'r':
5441 : 265 : ch = gfc_next_ascii_char ();
5442 : 265 : if (ch == 'i')
5443 : : {
5444 : 214 : if (match_string_p ("vate"))
5445 : : {
5446 : : /* Matched "private". */
5447 : : d = DECL_PRIVATE;
5448 : : }
5449 : : }
5450 : 51 : else if (ch == 'o')
5451 : : {
5452 : 51 : if (match_string_p ("tected"))
5453 : : {
5454 : : /* Matched "protected". */
5455 : : d = DECL_PROTECTED;
5456 : : }
5457 : : }
5458 : : break;
5459 : :
5460 : 251 : case 'u':
5461 : 251 : if (match_string_p ("blic"))
5462 : : {
5463 : : /* Matched "public". */
5464 : : d = DECL_PUBLIC;
5465 : : }
5466 : : break;
5467 : : }
5468 : : break;
5469 : :
5470 : 1137 : case 's':
5471 : 1137 : gfc_next_ascii_char ();
5472 : 1137 : switch (gfc_next_ascii_char ())
5473 : : {
5474 : 1124 : case 'a':
5475 : 1124 : if (match_string_p ("ve"))
5476 : : {
5477 : : /* Matched "save". */
5478 : : d = DECL_SAVE;
5479 : : }
5480 : : break;
5481 : :
5482 : 13 : case 't':
5483 : 13 : if (match_string_p ("atic"))
5484 : : {
5485 : : /* Matched "static". */
5486 : : d = DECL_STATIC;
5487 : : }
5488 : : break;
5489 : : }
5490 : : break;
5491 : :
5492 : 5147 : case 't':
5493 : 5147 : if (match_string_p ("target"))
5494 : : d = DECL_TARGET;
5495 : : break;
5496 : :
5497 : 9384 : case 'v':
5498 : 9384 : gfc_next_ascii_char ();
5499 : 9384 : ch = gfc_next_ascii_char ();
5500 : 9384 : if (ch == 'a')
5501 : : {
5502 : 8884 : if (match_string_p ("lue"))
5503 : : {
5504 : : /* Matched "value". */
5505 : : d = DECL_VALUE;
5506 : : }
5507 : : }
5508 : 500 : else if (ch == 'o')
5509 : : {
5510 : 500 : if (match_string_p ("latile"))
5511 : : {
5512 : : /* Matched "volatile". */
5513 : : d = DECL_VOLATILE;
5514 : : }
5515 : : }
5516 : : break;
5517 : : }
5518 : : }
5519 : :
5520 : : /* No double colon and no recognizable decl_type, so assume that
5521 : : we've been looking at something else the whole time. */
5522 : : if (d == DECL_NONE)
5523 : : {
5524 : 31350 : m = MATCH_NO;
5525 : 31350 : goto cleanup;
5526 : : }
5527 : :
5528 : : /* Check to make sure any parens are paired up correctly. */
5529 : 110752 : if (gfc_match_parens () == MATCH_ERROR)
5530 : : {
5531 : 1 : m = MATCH_ERROR;
5532 : 1 : goto cleanup;
5533 : : }
5534 : :
5535 : 110751 : seen[d]++;
5536 : 110751 : seen_at[d] = gfc_current_locus;
5537 : :
5538 : 110751 : if (d == DECL_DIMENSION || d == DECL_CODIMENSION)
5539 : : {
5540 : 18604 : gfc_array_spec *as = NULL;
5541 : :
5542 : 18604 : m = gfc_match_array_spec (&as, d == DECL_DIMENSION,
5543 : : d == DECL_CODIMENSION);
5544 : :
5545 : 18604 : if (current_as == NULL)
5546 : 18586 : current_as = as;
5547 : 18 : else if (m == MATCH_YES)
5548 : : {
5549 : 18 : if (!merge_array_spec (as, current_as, false))
5550 : 2 : m = MATCH_ERROR;
5551 : 18 : free (as);
5552 : : }
5553 : :
5554 : 18604 : if (m == MATCH_NO)
5555 : : {
5556 : 0 : if (d == DECL_CODIMENSION)
5557 : 0 : gfc_error ("Missing codimension specification at %C");
5558 : : else
5559 : 0 : gfc_error ("Missing dimension specification at %C");
5560 : : m = MATCH_ERROR;
5561 : : }
5562 : :
5563 : 18604 : if (m == MATCH_ERROR)
5564 : 7 : goto cleanup;
5565 : : }
5566 : : }
5567 : :
5568 : : /* Since we've seen a double colon, we have to be looking at an
5569 : : attr-spec. This means that we can now issue errors. */
5570 : 4609635 : for (d = GFC_DECL_BEGIN; d != GFC_DECL_END; d++)
5571 : 4438909 : if (seen[d] > 1)
5572 : : {
5573 : 2 : switch (d)
5574 : : {
5575 : : case DECL_ALLOCATABLE:
5576 : : attr = "ALLOCATABLE";
5577 : : break;
5578 : 0 : case DECL_ASYNCHRONOUS:
5579 : 0 : attr = "ASYNCHRONOUS";
5580 : 0 : break;
5581 : 0 : case DECL_CODIMENSION:
5582 : 0 : attr = "CODIMENSION";
5583 : 0 : break;
5584 : 0 : case DECL_CONTIGUOUS:
5585 : 0 : attr = "CONTIGUOUS";
5586 : 0 : break;
5587 : 0 : case DECL_DIMENSION:
5588 : 0 : attr = "DIMENSION";
5589 : 0 : break;
5590 : 0 : case DECL_EXTERNAL:
5591 : 0 : attr = "EXTERNAL";
5592 : 0 : break;
5593 : 0 : case DECL_IN:
5594 : 0 : attr = "INTENT (IN)";
5595 : 0 : break;
5596 : 0 : case DECL_OUT:
5597 : 0 : attr = "INTENT (OUT)";
5598 : 0 : break;
5599 : 0 : case DECL_INOUT:
5600 : 0 : attr = "INTENT (IN OUT)";
5601 : 0 : break;
5602 : 0 : case DECL_INTRINSIC:
5603 : 0 : attr = "INTRINSIC";
5604 : 0 : break;
5605 : 0 : case DECL_OPTIONAL:
5606 : 0 : attr = "OPTIONAL";
5607 : 0 : break;
5608 : 0 : case DECL_KIND:
5609 : 0 : attr = "KIND";
5610 : 0 : break;
5611 : 0 : case DECL_LEN:
5612 : 0 : attr = "LEN";
5613 : 0 : break;
5614 : 0 : case DECL_PARAMETER:
5615 : 0 : attr = "PARAMETER";
5616 : 0 : break;
5617 : 0 : case DECL_POINTER:
5618 : 0 : attr = "POINTER";
5619 : 0 : break;
5620 : 0 : case DECL_PROTECTED:
5621 : 0 : attr = "PROTECTED";
5622 : 0 : break;
5623 : 0 : case DECL_PRIVATE:
5624 : 0 : attr = "PRIVATE";
5625 : 0 : break;
5626 : 0 : case DECL_PUBLIC:
5627 : 0 : attr = "PUBLIC";
5628 : 0 : break;
5629 : 0 : case DECL_SAVE:
5630 : 0 : attr = "SAVE";
5631 : 0 : break;
5632 : 0 : case DECL_STATIC:
5633 : 0 : attr = "STATIC";
5634 : 0 : break;
5635 : 1 : case DECL_AUTOMATIC:
5636 : 1 : attr = "AUTOMATIC";
5637 : 1 : break;
5638 : 0 : case DECL_TARGET:
5639 : 0 : attr = "TARGET";
5640 : 0 : break;
5641 : 0 : case DECL_IS_BIND_C:
5642 : 0 : attr = "IS_BIND_C";
5643 : 0 : break;
5644 : 0 : case DECL_VALUE:
5645 : 0 : attr = "VALUE";
5646 : 0 : break;
5647 : 1 : case DECL_VOLATILE:
5648 : 1 : attr = "VOLATILE";
5649 : 1 : break;
5650 : 0 : default:
5651 : 0 : attr = NULL; /* This shouldn't happen. */
5652 : : }
5653 : :
5654 : 2 : gfc_error ("Duplicate %s attribute at %L", attr, &seen_at[d]);
5655 : 2 : m = MATCH_ERROR;
5656 : 2 : goto cleanup;
5657 : : }
5658 : :
5659 : : /* Now that we've dealt with duplicate attributes, add the attributes
5660 : : to the current attribute. */
5661 : 4608815 : for (d = GFC_DECL_BEGIN; d != GFC_DECL_END; d++)
5662 : : {
5663 : 4438162 : if (seen[d] == 0)
5664 : 4327427 : continue;
5665 : : else
5666 : 110735 : attr_seen = 1;
5667 : :
5668 : 110735 : if ((d == DECL_STATIC || d == DECL_AUTOMATIC)
5669 : 52 : && !flag_dec_static)
5670 : : {
5671 : 3 : gfc_error ("%s at %L is a DEC extension, enable with "
5672 : : "%<-fdec-static%>",
5673 : : d == DECL_STATIC ? "STATIC" : "AUTOMATIC", &seen_at[d]);
5674 : 2 : m = MATCH_ERROR;
5675 : 2 : goto cleanup;
5676 : : }
5677 : : /* Allow SAVE with STATIC, but don't complain. */
5678 : 50 : if (d == DECL_STATIC && seen[DECL_SAVE])
5679 : 0 : continue;
5680 : :
5681 : 110733 : if (gfc_comp_struct (gfc_current_state ())
5682 : 5904 : && d != DECL_DIMENSION && d != DECL_CODIMENSION
5683 : 4971 : && d != DECL_POINTER && d != DECL_PRIVATE
5684 : 3385 : && d != DECL_PUBLIC && d != DECL_CONTIGUOUS && d != DECL_NONE)
5685 : : {
5686 : 3330 : bool is_derived = gfc_current_state () == COMP_DERIVED;
5687 : 3330 : if (d == DECL_ALLOCATABLE)
5688 : : {
5689 : 3002 : if (!gfc_notify_std (GFC_STD_F2003, is_derived
5690 : : ? G_("ALLOCATABLE attribute at %C in a "
5691 : : "TYPE definition")
5692 : : : G_("ALLOCATABLE attribute at %C in a "
5693 : : "STRUCTURE definition")))
5694 : : {
5695 : 2 : m = MATCH_ERROR;
5696 : 2 : goto cleanup;
5697 : : }
5698 : : }
5699 : 328 : else if (d == DECL_KIND)
5700 : : {
5701 : 134 : if (!gfc_notify_std (GFC_STD_F2003, is_derived
5702 : : ? G_("KIND attribute at %C in a "
5703 : : "TYPE definition")
5704 : : : G_("KIND attribute at %C in a "
5705 : : "STRUCTURE definition")))
5706 : : {
5707 : 1 : m = MATCH_ERROR;
5708 : 1 : goto cleanup;
5709 : : }
5710 : 133 : if (current_ts.type != BT_INTEGER)
5711 : : {
5712 : 2 : gfc_error ("Component with KIND attribute at %C must be "
5713 : : "INTEGER");
5714 : 2 : m = MATCH_ERROR;
5715 : 2 : goto cleanup;
5716 : : }
5717 : : }
5718 : 194 : else if (d == DECL_LEN)
5719 : : {
5720 : 178 : if (!gfc_notify_std (GFC_STD_F2003, is_derived
5721 : : ? G_("LEN attribute at %C in a "
5722 : : "TYPE definition")
5723 : : : G_("LEN attribute at %C in a "
5724 : : "STRUCTURE definition")))
5725 : : {
5726 : 0 : m = MATCH_ERROR;
5727 : 0 : goto cleanup;
5728 : : }
5729 : 178 : if (current_ts.type != BT_INTEGER)
5730 : : {
5731 : 1 : gfc_error ("Component with LEN attribute at %C must be "
5732 : : "INTEGER");
5733 : 1 : m = MATCH_ERROR;
5734 : 1 : goto cleanup;
5735 : : }
5736 : : }
5737 : : else
5738 : : {
5739 : 32 : gfc_error (is_derived ? G_("Attribute at %L is not allowed in a "
5740 : : "TYPE definition")
5741 : : : G_("Attribute at %L is not allowed in a "
5742 : : "STRUCTURE definition"), &seen_at[d]);
5743 : 16 : m = MATCH_ERROR;
5744 : 16 : goto cleanup;
5745 : : }
5746 : : }
5747 : :
5748 : 110711 : if ((d == DECL_PRIVATE || d == DECL_PUBLIC)
5749 : 465 : && gfc_current_state () != COMP_MODULE)
5750 : : {
5751 : 144 : if (d == DECL_PRIVATE)
5752 : : attr = "PRIVATE";
5753 : : else
5754 : 42 : attr = "PUBLIC";
5755 : 144 : if (gfc_current_state () == COMP_DERIVED
5756 : 138 : && gfc_state_stack->previous
5757 : 138 : && gfc_state_stack->previous->state == COMP_MODULE)
5758 : : {
5759 : 135 : if (!gfc_notify_std (GFC_STD_F2003, "Attribute %s "
5760 : : "at %L in a TYPE definition", attr,
5761 : : &seen_at[d]))
5762 : : {
5763 : 2 : m = MATCH_ERROR;
5764 : 2 : goto cleanup;
5765 : : }
5766 : : }
5767 : : else
5768 : : {
5769 : 9 : gfc_error ("%s attribute at %L is not allowed outside of the "
5770 : : "specification part of a module", attr, &seen_at[d]);
5771 : 9 : m = MATCH_ERROR;
5772 : 9 : goto cleanup;
5773 : : }
5774 : : }
5775 : :
5776 : 110700 : if (gfc_current_state () != COMP_DERIVED
5777 : 104827 : && (d == DECL_KIND || d == DECL_LEN))
5778 : : {
5779 : 3 : gfc_error ("Attribute at %L is not allowed outside a TYPE "
5780 : : "definition", &seen_at[d]);
5781 : 3 : m = MATCH_ERROR;
5782 : 3 : goto cleanup;
5783 : : }
5784 : :
5785 : 110697 : switch (d)
5786 : : {
5787 : 17106 : case DECL_ALLOCATABLE:
5788 : 17106 : t = gfc_add_allocatable (¤t_attr, &seen_at[d]);
5789 : 17106 : break;
5790 : :
5791 : 23 : case DECL_ASYNCHRONOUS:
5792 : 23 : if (!gfc_notify_std (GFC_STD_F2003, "ASYNCHRONOUS attribute at %C"))
5793 : : t = false;
5794 : : else
5795 : 23 : t = gfc_add_asynchronous (¤t_attr, NULL, &seen_at[d]);
5796 : : break;
5797 : :
5798 : 44 : case DECL_CODIMENSION:
5799 : 44 : t = gfc_add_codimension (¤t_attr, NULL, &seen_at[d]);
5800 : 44 : break;
5801 : :
5802 : 1885 : case DECL_CONTIGUOUS:
5803 : 1885 : if (!gfc_notify_std (GFC_STD_F2008, "CONTIGUOUS attribute at %C"))
5804 : : t = false;
5805 : : else
5806 : 1884 : t = gfc_add_contiguous (¤t_attr, NULL, &seen_at[d]);
5807 : : break;
5808 : :
5809 : 18551 : case DECL_DIMENSION:
5810 : 18551 : t = gfc_add_dimension (¤t_attr, NULL, &seen_at[d]);
5811 : 18551 : break;
5812 : :
5813 : 175 : case DECL_EXTERNAL:
5814 : 175 : t = gfc_add_external (¤t_attr, &seen_at[d]);
5815 : 175 : break;
5816 : :
5817 : 19455 : case DECL_IN:
5818 : 19455 : t = gfc_add_intent (¤t_attr, INTENT_IN, &seen_at[d]);
5819 : 19455 : break;
5820 : :
5821 : 3504 : case DECL_OUT:
5822 : 3504 : t = gfc_add_intent (¤t_attr, INTENT_OUT, &seen_at[d]);
5823 : 3504 : break;
5824 : :
5825 : 2860 : case DECL_INOUT:
5826 : 2860 : t = gfc_add_intent (¤t_attr, INTENT_INOUT, &seen_at[d]);
5827 : 2860 : break;
5828 : :
5829 : 5 : case DECL_INTRINSIC:
5830 : 5 : t = gfc_add_intrinsic (¤t_attr, &seen_at[d]);
5831 : 5 : break;
5832 : :
5833 : 4952 : case DECL_OPTIONAL:
5834 : 4952 : t = gfc_add_optional (¤t_attr, &seen_at[d]);
5835 : 4952 : break;
5836 : :
5837 : 131 : case DECL_KIND:
5838 : 131 : t = gfc_add_kind (¤t_attr, &seen_at[d]);
5839 : 131 : break;
5840 : :
5841 : 177 : case DECL_LEN:
5842 : 177 : t = gfc_add_len (¤t_attr, &seen_at[d]);
5843 : 177 : break;
5844 : :
5845 : 13596 : case DECL_PARAMETER:
5846 : 13596 : t = gfc_add_flavor (¤t_attr, FL_PARAMETER, NULL, &seen_at[d]);
5847 : 13596 : break;
5848 : :
5849 : 11872 : case DECL_POINTER:
5850 : 11872 : t = gfc_add_pointer (¤t_attr, &seen_at[d]);
5851 : 11872 : break;
5852 : :
5853 : 50 : case DECL_PROTECTED:
5854 : 50 : if (gfc_current_state () != COMP_MODULE
5855 : 48 : || (gfc_current_ns->proc_name
5856 : 48 : && gfc_current_ns->proc_name->attr.flavor != FL_MODULE))
5857 : : {
5858 : 2 : gfc_error ("PROTECTED at %C only allowed in specification "
5859 : : "part of a module");
5860 : 2 : t = false;
5861 : 2 : break;
5862 : : }
5863 : :
5864 : 48 : if (!gfc_notify_std (GFC_STD_F2003, "PROTECTED attribute at %C"))
5865 : : t = false;
5866 : : else
5867 : 44 : t = gfc_add_protected (¤t_attr, NULL, &seen_at[d]);
5868 : : break;
5869 : :
5870 : 211 : case DECL_PRIVATE:
5871 : 211 : t = gfc_add_access (¤t_attr, ACCESS_PRIVATE, NULL,
5872 : : &seen_at[d]);
5873 : 211 : break;
5874 : :
5875 : 243 : case DECL_PUBLIC:
5876 : 243 : t = gfc_add_access (¤t_attr, ACCESS_PUBLIC, NULL,
5877 : : &seen_at[d]);
5878 : 243 : break;
5879 : :
5880 : 1134 : case DECL_STATIC:
5881 : 1134 : case DECL_SAVE:
5882 : 1134 : t = gfc_add_save (¤t_attr, SAVE_EXPLICIT, NULL, &seen_at[d]);
5883 : 1134 : break;
5884 : :
5885 : 37 : case DECL_AUTOMATIC:
5886 : 37 : t = gfc_add_automatic (¤t_attr, NULL, &seen_at[d]);
5887 : 37 : break;
5888 : :
5889 : 5145 : case DECL_TARGET:
5890 : 5145 : t = gfc_add_target (¤t_attr, &seen_at[d]);
5891 : 5145 : break;
5892 : :
5893 : 161 : case DECL_IS_BIND_C:
5894 : 161 : t = gfc_add_is_bind_c(¤t_attr, NULL, &seen_at[d], 0);
5895 : 161 : break;
5896 : :
5897 : 8883 : case DECL_VALUE:
5898 : 8883 : if (!gfc_notify_std (GFC_STD_F2003, "VALUE attribute at %C"))
5899 : : t = false;
5900 : : else
5901 : 8883 : t = gfc_add_value (¤t_attr, NULL, &seen_at[d]);
5902 : : break;
5903 : :
5904 : 497 : case DECL_VOLATILE:
5905 : 497 : if (!gfc_notify_std (GFC_STD_F2003, "VOLATILE attribute at %C"))
5906 : : t = false;
5907 : : else
5908 : 496 : t = gfc_add_volatile (¤t_attr, NULL, &seen_at[d]);
5909 : : break;
5910 : :
5911 : 0 : default:
5912 : 0 : gfc_internal_error ("match_attr_spec(): Bad attribute");
5913 : : }
5914 : :
5915 : 110691 : if (!t)
5916 : : {
5917 : 35 : m = MATCH_ERROR;
5918 : 35 : goto cleanup;
5919 : : }
5920 : : }
5921 : :
5922 : : /* Since Fortran 2008 module variables implicitly have the SAVE attribute. */
5923 : 170653 : if ((gfc_current_state () == COMP_MODULE
5924 : 170653 : || gfc_current_state () == COMP_SUBMODULE)
5925 : 5408 : && !current_attr.save
5926 : 5226 : && (gfc_option.allow_std & GFC_STD_F2008) != 0)
5927 : 5133 : current_attr.save = SAVE_IMPLICIT;
5928 : :
5929 : 170653 : colon_seen = 1;
5930 : 170653 : return MATCH_YES;
5931 : :
5932 : 31435 : cleanup:
5933 : 31435 : gfc_current_locus = start;
5934 : 31435 : gfc_free_array_spec (current_as);
5935 : 31435 : current_as = NULL;
5936 : 31435 : attr_seen = 0;
5937 : 31435 : return m;
5938 : : }
5939 : :
5940 : :
5941 : : /* Set the binding label, dest_label, either with the binding label
5942 : : stored in the given gfc_typespec, ts, or if none was provided, it
5943 : : will be the symbol name in all lower case, as required by the draft
5944 : : (J3/04-007, section 15.4.1). If a binding label was given and
5945 : : there is more than one argument (num_idents), it is an error. */
5946 : :
5947 : : static bool
5948 : 309 : set_binding_label (const char **dest_label, const char *sym_name,
5949 : : int num_idents)
5950 : : {
5951 : 309 : if (num_idents > 1 && has_name_equals)
5952 : : {
5953 : 4 : gfc_error ("Multiple identifiers provided with "
5954 : : "single NAME= specifier at %C");
5955 : 4 : return false;
5956 : : }
5957 : :
5958 : 305 : if (curr_binding_label)
5959 : : /* Binding label given; store in temp holder till have sym. */
5960 : 106 : *dest_label = curr_binding_label;
5961 : : else
5962 : : {
5963 : : /* No binding label given, and the NAME= specifier did not exist,
5964 : : which means there was no NAME="". */
5965 : 199 : if (sym_name != NULL && has_name_equals == 0)
5966 : 169 : *dest_label = IDENTIFIER_POINTER (get_identifier (sym_name));
5967 : : }
5968 : :
5969 : : return true;
5970 : : }
5971 : :
5972 : :
5973 : : /* Set the status of the given common block as being BIND(C) or not,
5974 : : depending on the given parameter, is_bind_c. */
5975 : :
5976 : : static void
5977 : 76 : set_com_block_bind_c (gfc_common_head *com_block, int is_bind_c)
5978 : : {
5979 : 76 : com_block->is_bind_c = is_bind_c;
5980 : 76 : return;
5981 : : }
5982 : :
5983 : :
5984 : : /* Verify that the given gfc_typespec is for a C interoperable type. */
5985 : :
5986 : : bool
5987 : 18064 : gfc_verify_c_interop (gfc_typespec *ts)
5988 : : {
5989 : 18064 : if (ts->type == BT_DERIVED && ts->u.derived != NULL)
5990 : 3757 : return (ts->u.derived->ts.is_c_interop || ts->u.derived->attr.is_bind_c)
5991 : 7495 : ? true : false;
5992 : 14315 : else if (ts->type == BT_CLASS)
5993 : : return false;
5994 : 14307 : else if (ts->is_c_interop != 1 && ts->type != BT_ASSUMED)
5995 : 3560 : return false;
5996 : :
5997 : : return true;
5998 : : }
5999 : :
6000 : :
6001 : : /* Verify that the variables of a given common block, which has been
6002 : : defined with the attribute specifier bind(c), to be of a C
6003 : : interoperable type. Errors will be reported here, if
6004 : : encountered. */
6005 : :
6006 : : bool
6007 : 1 : verify_com_block_vars_c_interop (gfc_common_head *com_block)
6008 : : {
6009 : 1 : gfc_symbol *curr_sym = NULL;
6010 : 1 : bool retval = true;
6011 : :
6012 : 1 : curr_sym = com_block->head;
6013 : :
6014 : : /* Make sure we have at least one symbol. */
6015 : 1 : if (curr_sym == NULL)
6016 : : return retval;
6017 : :
6018 : : /* Here we know we have a symbol, so we'll execute this loop
6019 : : at least once. */
6020 : 1 : do
6021 : : {
6022 : : /* The second to last param, 1, says this is in a common block. */
6023 : 1 : retval = verify_bind_c_sym (curr_sym, &(curr_sym->ts), 1, com_block);
6024 : 1 : curr_sym = curr_sym->common_next;
6025 : 1 : } while (curr_sym != NULL);
6026 : :
6027 : : return retval;
6028 : : }
6029 : :
6030 : :
6031 : : /* Verify that a given BIND(C) symbol is C interoperable. If it is not,
6032 : : an appropriate error message is reported. */
6033 : :
6034 : : bool
6035 : 6052 : verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts,
6036 : : int is_in_common, gfc_common_head *com_block)
6037 : : {
6038 : 6052 : bool bind_c_function = false;
6039 : 6052 : bool retval = true;
6040 : :
6041 : 6052 : if (tmp_sym->attr.function && tmp_sym->attr.is_bind_c)
6042 : 2470 : bind_c_function = true;
6043 : :
6044 : 6052 : if (tmp_sym->attr.function && tmp_sym->result != NULL)
6045 : : {
6046 : 2470 : tmp_sym = tmp_sym->result;
6047 : : /* Make sure it wasn't an implicitly typed result. */
6048 : 2470 : if (tmp_sym->attr.implicit_type && warn_c_binding_type)
6049 : : {
6050 : 1 : gfc_warning (OPT_Wc_binding_type,
6051 : : "Implicitly declared BIND(C) function %qs at "
6052 : : "%L may not be C interoperable", tmp_sym->name,
6053 : : &tmp_sym->declared_at);
6054 : 1 : tmp_sym->ts.f90_type = tmp_sym->ts.type;
6055 : : /* Mark it as C interoperable to prevent duplicate warnings. */
6056 : 1 : tmp_sym->ts.is_c_interop = 1;
6057 : 1 : tmp_sym->attr.is_c_interop = 1;
6058 : : }
6059 : : }
6060 : :
6061 : : /* Here, we know we have the bind(c) attribute, so if we have
6062 : : enough type info, then verify that it's a C interop kind.
6063 : : The info could be in the symbol already, or possibly still in
6064 : : the given ts (current_ts), so look in both. */
6065 : 6052 : if (tmp_sym->ts.type != BT_UNKNOWN || ts->type != BT_UNKNOWN)
6066 : : {
6067 : 2628 : if (!gfc_verify_c_interop (&(tmp_sym->ts)))
6068 : : {
6069 : : /* See if we're dealing with a sym in a common block or not. */
6070 : 162 : if (is_in_common == 1 && warn_c_binding_type)
6071 : : {
6072 : 0 : gfc_warning (OPT_Wc_binding_type,
6073 : : "Variable %qs in common block %qs at %L "
6074 : : "may not be a C interoperable "
6075 : : "kind though common block %qs is BIND(C)",
6076 : : tmp_sym->name, com_block->name,
6077 : 0 : &(tmp_sym->declared_at), com_block->name);
6078 : : }
6079 : : else
6080 : : {
6081 : 162 : if (tmp_sym->ts.type == BT_DERIVED || ts->type == BT_DERIVED
6082 : 160 : || tmp_sym->ts.type == BT_CLASS || ts->type == BT_CLASS)
6083 : : {
6084 : 3 : gfc_error ("Type declaration %qs at %L is not C "
6085 : : "interoperable but it is BIND(C)",
6086 : : tmp_sym->name, &(tmp_sym->declared_at));
6087 : 3 : retval = false;
6088 : : }
6089 : 159 : else if (warn_c_binding_type)
6090 : 3 : gfc_warning (OPT_Wc_binding_type, "Variable %qs at %L "
6091 : : "may not be a C interoperable "
6092 : : "kind but it is BIND(C)",
6093 : : tmp_sym->name, &(tmp_sym->declared_at));
6094 : : }
6095 : : }
6096 : :
6097 : : /* Variables declared w/in a common block can't be bind(c)
6098 : : since there's no way for C to see these variables, so there's
6099 : : semantically no reason for the attribute. */
6100 : 2628 : if (is_in_common == 1 && tmp_sym->attr.is_bind_c == 1)
6101 : : {
6102 : 1 : gfc_error ("Variable %qs in common block %qs at "
6103 : : "%L cannot be declared with BIND(C) "
6104 : : "since it is not a global",
6105 : 1 : tmp_sym->name, com_block->name,
6106 : : &(tmp_sym->declared_at));
6107 : 1 : retval = false;
6108 : : }
6109 : :
6110 : : /* Scalar variables that are bind(c) cannot have the pointer
6111 : : or allocatable attributes. */
6112 : 2628 : if (tmp_sym->attr.is_bind_c == 1)
6113 : : {
6114 : 2109 : if (tmp_sym->attr.pointer == 1)
6115 : : {
6116 : 1 : gfc_error ("Variable %qs at %L cannot have both the "
6117 : : "POINTER and BIND(C) attributes",
6118 : : tmp_sym->name, &(tmp_sym->declared_at));
6119 : 1 : retval = false;
6120 : : }
6121 : :
6122 : 2109 : if (tmp_sym->attr.allocatable == 1)
6123 : : {
6124 : 0 : gfc_error ("Variable %qs at %L cannot have both the "
6125 : : "ALLOCATABLE and BIND(C) attributes",
6126 : : tmp_sym->name, &(tmp_sym->declared_at));
6127 : 0 : retval = false;
6128 : : }
6129 : :
6130 : : }
6131 : :
6132 : : /* If it is a BIND(C) function, make sure the return value is a
6133 : : scalar value. The previous tests in this function made sure
6134 : : the type is interoperable. */
6135 : 2628 : if (bind_c_function && tmp_sym->as != NULL)
6136 : 2 : gfc_error ("Return type of BIND(C) function %qs at %L cannot "
6137 : : "be an array", tmp_sym->name, &(tmp_sym->declared_at));
6138 : :
6139 : : /* BIND(C) functions cannot return a character string. */
6140 : 2470 : if (bind_c_function && tmp_sym->ts.type == BT_CHARACTER)
6141 : 68 : if (!gfc_length_one_character_type_p (&tmp_sym->ts))
6142 : 4 : gfc_error ("Return type of BIND(C) function %qs of character "
6143 : : "type at %L must have length 1", tmp_sym->name,
6144 : : &(tmp_sym->declared_at));
6145 : : }
6146 : :
6147 : : /* See if the symbol has been marked as private. If it has, make sure
6148 : : there is no binding label and warn the user if there is one. */
6149 : 6052 : if (tmp_sym->attr.access == ACCESS_PRIVATE
6150 : 10 : && tmp_sym->binding_label)
6151 : : /* Use gfc_warning_now because we won't say that the symbol fails
6152 : : just because of this. */
6153 : 7 : gfc_warning_now (0, "Symbol %qs at %L is marked PRIVATE but has been "
6154 : : "given the binding label %qs", tmp_sym->name,
6155 : : &(tmp_sym->declared_at), tmp_sym->binding_label);
6156 : :
6157 : 6052 : return retval;
6158 : : }
6159 : :
6160 : :
6161 : : /* Set the appropriate fields for a symbol that's been declared as
6162 : : BIND(C) (the is_bind_c flag and the binding label), and verify that
6163 : : the type is C interoperable. Errors are reported by the functions
6164 : : used to set/test these fields. */
6165 : :
6166 : : static bool
6167 : 47 : set_verify_bind_c_sym (gfc_symbol *tmp_sym, int num_idents)
6168 : : {
6169 : 47 : bool retval = true;
6170 : :
6171 : : /* TODO: Do we need to make sure the vars aren't marked private? */
6172 : :
6173 : : /* Set the is_bind_c bit in symbol_attribute. */
6174 : 47 : gfc_add_is_bind_c (&(tmp_sym->attr), tmp_sym->name, &gfc_current_locus, 0);
6175 : :
6176 : 47 : if (!set_binding_label (&tmp_sym->binding_label, tmp_sym->name, num_idents))
6177 : : return false;
6178 : :
6179 : : return retval;
6180 : : }
6181 : :
6182 : :
6183 : : /* Set the fields marking the given common block as BIND(C), including
6184 : : a binding label, and report any errors encountered. */
6185 : :
6186 : : static bool
6187 : 76 : set_verify_bind_c_com_block (gfc_common_head *com_block, int num_idents)
6188 : : {
6189 : 76 : bool retval = true;
6190 : :
6191 : : /* destLabel, common name, typespec (which may have binding label). */
6192 : 76 : if (!set_binding_label (&com_block->binding_label, com_block->name,
6193 : : num_idents))
6194 : : return false;
6195 : :
6196 : : /* Set the given common block (com_block) to being bind(c) (1). */
6197 : 76 : set_com_block_bind_c (com_block, 1);
6198 : :
6199 : 76 : return retval;
6200 : : }
6201 : :
6202 : :
6203 : : /* Retrieve the list of one or more identifiers that the given bind(c)
6204 : : attribute applies to. */
6205 : :
6206 : : static bool
6207 : 102 : get_bind_c_idents (void)
6208 : : {
6209 : 102 : char name[GFC_MAX_SYMBOL_LEN + 1];
6210 : 102 : int num_idents = 0;
6211 : 102 : gfc_symbol *tmp_sym = NULL;
6212 : 102 : match found_id;
6213 : 102 : gfc_common_head *com_block = NULL;
6214 : :
6215 : 102 : if (gfc_match_name (name) == MATCH_YES)
6216 : : {
6217 : 38 : found_id = MATCH_YES;
6218 : 38 : gfc_get_ha_symbol (name, &tmp_sym);
6219 : : }
6220 : 64 : else if (gfc_match_common_name (name) == MATCH_YES)
6221 : : {
6222 : 64 : found_id = MATCH_YES;
6223 : 64 : com_block = gfc_get_common (name, 0);
6224 : : }
6225 : : else
6226 : : {
6227 : 0 : gfc_error ("Need either entity or common block name for "
6228 : : "attribute specification statement at %C");
6229 : 0 : return false;
6230 : : }
6231 : :
6232 : : /* Save the current identifier and look for more. */
6233 : 123 : do
6234 : : {
6235 : : /* Increment the number of identifiers found for this spec stmt. */
6236 : 123 : num_idents++;
6237 : :
6238 : : /* Make sure we have a sym or com block, and verify that it can
6239 : : be bind(c). Set the appropriate field(s) and look for more
6240 : : identifiers. */
6241 : 123 : if (tmp_sym != NULL || com_block != NULL)
6242 : : {
6243 : 123 : if (tmp_sym != NULL)
6244 : : {
6245 : 47 : if (!set_verify_bind_c_sym (tmp_sym, num_idents))
6246 : : return false;
6247 : : }
6248 : : else
6249 : : {
6250 : 76 : if (!set_verify_bind_c_com_block (com_block, num_idents))
6251 : : return false;
6252 : : }
6253 : :
6254 : : /* Look to see if we have another identifier. */
6255 : 122 : tmp_sym = NULL;
6256 : 122 : if (gfc_match_eos () == MATCH_YES)
6257 : : found_id = MATCH_NO;
6258 : 21 : else if (gfc_match_char (',') != MATCH_YES)
6259 : : found_id = MATCH_NO;
6260 : 21 : else if (gfc_match_name (name) == MATCH_YES)
6261 : : {
6262 : 9 : found_id = MATCH_YES;
6263 : 9 : gfc_get_ha_symbol (name, &tmp_sym);
6264 : : }
6265 : 12 : else if (gfc_match_common_name (name) == MATCH_YES)
6266 : : {
6267 : 12 : found_id = MATCH_YES;
6268 : 12 : com_block = gfc_get_common (name, 0);
6269 : : }
6270 : : else
6271 : : {
6272 : 0 : gfc_error ("Missing entity or common block name for "
6273 : : "attribute specification statement at %C");
6274 : 0 : return false;
6275 : : }
6276 : : }
6277 : : else
6278 : : {
6279 : 0 : gfc_internal_error ("Missing symbol");
6280 : : }
6281 : 122 : } while (found_id == MATCH_YES);
6282 : :
6283 : : /* if we get here we were successful */
6284 : : return true;
6285 : : }
6286 : :
6287 : :
6288 : : /* Try and match a BIND(C) attribute specification statement. */
6289 : :
6290 : : match
6291 : 140 : gfc_match_bind_c_stmt (void)
6292 : : {
6293 : 140 : match found_match = MATCH_NO;
6294 : 140 : gfc_typespec *ts;
6295 : :
6296 : 140 : ts = ¤t_ts;
6297 : :
6298 : : /* This may not be necessary. */
6299 : 140 : gfc_clear_ts (ts);
6300 : : /* Clear the temporary binding label holder. */
6301 : 140 : curr_binding_label = NULL;
6302 : :
6303 : : /* Look for the bind(c). */
6304 : 140 : found_match = gfc_match_bind_c (NULL, true);
6305 : :
6306 : 140 : if (found_match == MATCH_YES)
6307 : : {
6308 : 103 : if (!gfc_notify_std (GFC_STD_F2003, "BIND(C) statement at %C"))
6309 : : return MATCH_ERROR;
6310 : :
6311 : : /* Look for the :: now, but it is not required. */
6312 : 102 : gfc_match (" :: ");
6313 : :
6314 : : /* Get the identifier(s) that needs to be updated. This may need to
6315 : : change to hand the flag(s) for the attr specified so all identifiers
6316 : : found can have all appropriate parts updated (assuming that the same
6317 : : spec stmt can have multiple attrs, such as both bind(c) and
6318 : : allocatable...). */
6319 : 102 : if (!get_bind_c_idents ())
6320 : : /* Error message should have printed already. */
6321 : : return MATCH_ERROR;
6322 : : }
6323 : :
6324 : : return found_match;
6325 : : }
6326 : :
6327 : :
6328 : : /* Match a data declaration statement. */
6329 : :
6330 : : match
6331 : 963136 : gfc_match_data_decl (void)
6332 : : {
6333 : 963136 : gfc_symbol *sym;
6334 : 963136 : match m;
6335 : 963136 : int elem;
6336 : :
6337 : 963136 : type_param_spec_list = NULL;
6338 : 963136 : decl_type_param_list = NULL;
6339 : :
6340 : 963136 : num_idents_on_line = 0;
6341 : :
6342 : 963136 : m = gfc_match_decl_type_spec (¤t_ts, 0);
6343 : 963136 : if (m != MATCH_YES)
6344 : : return m;
6345 : :
6346 : 201006 : if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS)
6347 : 31682 : && !gfc_comp_struct (gfc_current_state ()))
6348 : : {
6349 : 28703 : sym = gfc_use_derived (current_ts.u.derived);
6350 : :
6351 : 28703 : if (sym == NULL)
6352 : : {
6353 : 15 : m = MATCH_ERROR;
6354 : 15 : goto cleanup;
6355 : : }
6356 : :
6357 : 28688 : current_ts.u.derived = sym;
6358 : : }
6359 : :
6360 : 200991 : m = match_attr_spec ();
6361 : 200991 : if (m == MATCH_ERROR)
6362 : : {
6363 : 84 : m = MATCH_NO;
6364 : 84 : goto cleanup;
6365 : : }
6366 : :
6367 : : /* F2018:C708. */
6368 : 200907 : if (current_ts.type == BT_CLASS && current_attr.flavor == FL_PARAMETER)
6369 : : {
6370 : 6 : gfc_error ("CLASS entity at %C cannot have the PARAMETER attribute");
6371 : 6 : m = MATCH_ERROR;
6372 : 6 : goto cleanup;
6373 : : }
6374 : :
6375 : 200901 : if (current_ts.type == BT_CLASS
6376 : 10167 : && current_ts.u.derived->attr.unlimited_polymorphic)
6377 : 1747 : goto ok;
6378 : :
6379 : 199154 : if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS)
6380 : 29913 : && current_ts.u.derived->components == NULL
6381 : 2636 : && !current_ts.u.derived->attr.zero_comp)
6382 : : {
6383 : :
6384 : 200 : if (current_attr.pointer && gfc_comp_struct (gfc_current_state ()))
6385 : 135 : goto ok;
6386 : :
6387 : 65 : if (current_attr.allocatable && gfc_current_state () == COMP_DERIVED)
6388 : 38 : goto ok;
6389 : :
6390 : 27 : gfc_find_symbol (current_ts.u.derived->name,
6391 : : current_ts.u.derived->ns, 1, &sym);
6392 : :
6393 : : /* Any symbol that we find had better be a type definition
6394 : : which has its components defined, or be a structure definition
6395 : : actively being parsed. */
6396 : 27 : if (sym != NULL && gfc_fl_struct (sym->attr.flavor)
6397 : 26 : && (current_ts.u.derived->components != NULL
6398 : 26 : || current_ts.u.derived->attr.zero_comp
6399 : 26 : || current_ts.u.derived == gfc_new_block))
6400 : 26 : goto ok;
6401 : :
6402 : 1 : gfc_error ("Derived type at %C has not been previously defined "
6403 : : "and so cannot appear in a derived type definition");
6404 : 1 : m = MATCH_ERROR;
6405 : 1 : goto cleanup;
6406 : : }
6407 : :
6408 : 198954 : ok:
6409 : : /* If we have an old-style character declaration, and no new-style
6410 : : attribute specifications, then there a comma is optional between
6411 : : the type specification and the variable list. */
6412 : 200900 : if (m == MATCH_NO && current_ts.type == BT_CHARACTER && old_char_selector)
6413 : 1407 : gfc_match_char (',');
6414 : :
6415 : : /* Give the types/attributes to symbols that follow. Give the element
6416 : : a number so that repeat character length expressions can be copied. */
6417 : : elem = 1;
6418 : 263563 : for (;;)
6419 : : {
6420 : 263563 : num_idents_on_line++;
6421 : 263563 : m = variable_decl (elem++);
6422 : 263561 : if (m == MATCH_ERROR)
6423 : 398 : goto cleanup;
6424 : 263163 : if (m == MATCH_NO)
6425 : : break;
6426 : :
6427 : 263152 : if (gfc_match_eos () == MATCH_YES)
6428 : 200468 : goto cleanup;
6429 : 62684 : if (gfc_match_char (',') != MATCH_YES)
6430 : : break;
6431 : : }
6432 : :
6433 : 32 : if (!gfc_error_flag_test ())
6434 : : {
6435 : : /* An anonymous structure declaration is unambiguous; if we matched one
6436 : : according to gfc_match_structure_decl, we need to return MATCH_YES
6437 : : here to avoid confusing the remaining matchers, even if there was an
6438 : : error during variable_decl. We must flush any such errors. Note this
6439 : : causes the parser to gracefully continue parsing the remaining input
6440 : : as a structure body, which likely follows. */
6441 : 8 : if (current_ts.type == BT_DERIVED && current_ts.u.derived
6442 : 1 : && gfc_fl_struct (current_ts.u.derived->attr.flavor))
6443 : : {
6444 : 1 : gfc_error_now ("Syntax error in anonymous structure declaration"
6445 : : " at %C");
6446 : : /* Skip the bad variable_decl and line up for the start of the
6447 : : structure body. */
6448 : 1 : gfc_error_recovery ();
6449 : 1 : m = MATCH_YES;
6450 : 1 : goto cleanup;
6451 : : }
6452 : :
6453 : 7 : gfc_error ("Syntax error in data declaration at %C");
6454 : : }
6455 : :
6456 : 31 : m = MATCH_ERROR;
6457 : :
6458 : 31 : gfc_free_data_all (gfc_current_ns);
6459 : :
6460 : 201004 : cleanup:
6461 : 201004 : if (saved_kind_expr)
6462 : 91 : gfc_free_expr (saved_kind_expr);
6463 : 201004 : if (type_param_spec_list)
6464 : 396 : gfc_free_actual_arglist (type_param_spec_list);
6465 : 201004 : if (decl_type_param_list)
6466 : 423 : gfc_free_actual_arglist (decl_type_param_list);
6467 : 201004 : saved_kind_expr = NULL;
6468 : 201004 : gfc_free_array_spec (current_as);
6469 : 201004 : current_as = NULL;
6470 : 201004 : return m;
6471 : : }
6472 : :
6473 : : static bool
6474 : 22296 : in_module_or_interface(void)
6475 : : {
6476 : 22296 : if (gfc_current_state () == COMP_MODULE
6477 : 22296 : || gfc_current_state () == COMP_SUBMODULE
6478 : 22296 : || gfc_current_state () == COMP_INTERFACE)
6479 : : return true;
6480 : :
6481 : 18881 : if (gfc_state_stack->state == COMP_CONTAINS
6482 : 18213 : || gfc_state_stack->state == COMP_FUNCTION
6483 : 18134 : || gfc_state_stack->state == COMP_SUBROUTINE)
6484 : : {
6485 : 747 : gfc_state_data *p;
6486 : 782 : for (p = gfc_state_stack->previous; p ; p = p->previous)
6487 : : {
6488 : 778 : if (p->state == COMP_MODULE || p->state == COMP_SUBMODULE
6489 : 91 : || p->state == COMP_INTERFACE)
6490 : : return true;
6491 : : }
6492 : : }
6493 : : return false;
6494 : : }
6495 : :
6496 : : /* Match a prefix associated with a function or subroutine
6497 : : declaration. If the typespec pointer is nonnull, then a typespec
6498 : : can be matched. Note that if nothing matches, MATCH_YES is
6499 : : returned (the null string was matched). */
6500 : :
6501 : : match
6502 : 225254 : gfc_match_prefix (gfc_typespec *ts)
6503 : : {
6504 : 225254 : bool seen_type;
6505 : 225254 : bool seen_impure;
6506 : 225254 : bool found_prefix;
6507 : :
6508 : 225254 : gfc_clear_attr (¤t_attr);
6509 : 225254 : seen_type = false;
6510 : 225254 : seen_impure = false;
6511 : :
6512 : 225254 : gcc_assert (!gfc_matching_prefix);
6513 : 225254 : gfc_matching_prefix = true;
6514 : :
6515 : 234425 : do
6516 : : {
6517 : 252867 : found_prefix = false;
6518 : :
6519 : : /* MODULE is a prefix like PURE, ELEMENTAL, etc., having a
6520 : : corresponding attribute seems natural and distinguishes these
6521 : : procedures from procedure types of PROC_MODULE, which these are
6522 : : as well. */
6523 : 252867 : if (gfc_match ("module% ") == MATCH_YES)
6524 : : {
6525 : 22575 : if (!gfc_notify_std (GFC_STD_F2008, "MODULE prefix at %C"))
6526 : 279 : goto error;
6527 : :
6528 : 22296 : if (!in_module_or_interface ())
6529 : : {
6530 : 18138 : gfc_error ("MODULE prefix at %C found outside of a module, "
6531 : : "submodule, or interface");
6532 : 18138 : goto error;
6533 : : }
6534 : :
6535 : 4158 : current_attr.module_procedure = 1;
6536 : 4158 : found_prefix = true;
6537 : : }
6538 : :
6539 : 234450 : if (!seen_type && ts != NULL)
6540 : : {
6541 : 126125 : match m;
6542 : 126125 : m = gfc_match_decl_type_spec (ts, 0);
6543 : 126125 : if (m == MATCH_ERROR)
6544 : 15 : goto error;
6545 : 126110 : if (m == MATCH_YES && gfc_match_space () == MATCH_YES)
6546 : : {
6547 : : seen_type = true;
6548 : : found_prefix = true;
6549 : : }
6550 : : }
6551 : :
6552 : 234435 : if (gfc_match ("elemental% ") == MATCH_YES)
6553 : : {
6554 : 5067 : if (!gfc_add_elemental (¤t_attr, NULL))
6555 : 2 : goto error;
6556 : :
6557 : : found_prefix = true;
6558 : : }
6559 : :
6560 : 234433 : if (gfc_match ("pure% ") == MATCH_YES)
6561 : : {
6562 : 2261 : if (!gfc_add_pure (¤t_attr, NULL))
6563 : 2 : goto error;
6564 : :
6565 : : found_prefix = true;
6566 : : }
6567 : :
6568 : 234431 : if (gfc_match ("recursive% ") == MATCH_YES)
6569 : : {
6570 : 447 : if (!gfc_add_recursive (¤t_attr, NULL))
6571 : 2 : goto error;
6572 : :
6573 : : found_prefix = true;
6574 : : }
6575 : :
6576 : : /* IMPURE is a somewhat special case, as it needs not set an actual
6577 : : attribute but rather only prevents ELEMENTAL routines from being
6578 : : automatically PURE. */
6579 : 234429 : if (gfc_match ("impure% ") == MATCH_YES)
6580 : : {
6581 : 615 : if (!gfc_notify_std (GFC_STD_F2008, "IMPURE procedure at %C"))
6582 : 4 : goto error;
6583 : :
6584 : : seen_impure = true;
6585 : : found_prefix = true;
6586 : : }
6587 : : }
6588 : : while (found_prefix);
6589 : :
6590 : : /* IMPURE and PURE must not both appear, of course. */
6591 : 206812 : if (seen_impure && current_attr.pure)
6592 : : {
6593 : 4 : gfc_error ("PURE and IMPURE must not appear both at %C");
6594 : 4 : goto error;
6595 : : }
6596 : :
6597 : : /* If IMPURE it not seen but the procedure is ELEMENTAL, mark it as PURE. */
6598 : 206201 : if (!seen_impure && current_attr.elemental && !current_attr.pure)
6599 : : {
6600 : 4450 : if (!gfc_add_pure (¤t_attr, NULL))
6601 : 0 : goto error;
6602 : : }
6603 : :
6604 : : /* At this point, the next item is not a prefix. */
6605 : 206808 : gcc_assert (gfc_matching_prefix);
6606 : :
6607 : 206808 : gfc_matching_prefix = false;
6608 : 206808 : return MATCH_YES;
6609 : :
6610 : 18446 : error:
6611 : 18446 : gcc_assert (gfc_matching_prefix);
6612 : 18446 : gfc_matching_prefix = false;
6613 : 18446 : return MATCH_ERROR;
6614 : : }
6615 : :
6616 : :
6617 : : /* Copy attributes matched by gfc_match_prefix() to attributes on a symbol. */
6618 : :
6619 : : static bool
6620 : 58667 : copy_prefix (symbol_attribute *dest, locus *where)
6621 : : {
6622 : 58667 : if (dest->module_procedure)
6623 : : {
6624 : 568 : if (current_attr.elemental)
6625 : 4 : dest->elemental = 1;
6626 : :
6627 : 568 : if (current_attr.pure)
6628 : 13 : dest->pure = 1;
6629 : :
6630 : 568 : if (current_attr.recursive)
6631 : 8 : dest->recursive = 1;
6632 : :
6633 : : /* Module procedures are unusual in that the 'dest' is copied from
6634 : : the interface declaration. However, this is an oportunity to
6635 : : check that the submodule declaration is compliant with the
6636 : : interface. */
6637 : 568 : if (dest->elemental && !current_attr.elemental)
6638 : : {
6639 : 1 : gfc_error ("ELEMENTAL prefix in MODULE PROCEDURE interface is "
6640 : : "missing at %L", where);
6641 : 1 : return false;
6642 : : }
6643 : :
6644 : 567 : if (dest->pure && !current_attr.pure)
6645 : : {
6646 : 1 : gfc_error ("PURE prefix in MODULE PROCEDURE interface is "
6647 : : "missing at %L", where);
6648 : 1 : return false;
6649 : : }
6650 : :
6651 : 566 : if (dest->recursive && !current_attr.recursive)
6652 : : {
6653 : 1 : gfc_error ("RECURSIVE prefix in MODULE PROCEDURE interface is "
6654 : : "missing at %L", where);
6655 : 1 : return false;
6656 : : }
6657 : :
6658 : : return true;
6659 : : }
6660 : :
6661 : 58099 : if (current_attr.elemental && !gfc_add_elemental (dest, where))
6662 : : return false;
6663 : :
6664 : 58097 : if (current_attr.pure && !gfc_add_pure (dest, where))
6665 : : return false;
6666 : :
6667 : 58097 : if (current_attr.recursive && !gfc_add_recursive (dest, where))
6668 : : return false;
6669 : :
6670 : : return true;
6671 : : }
6672 : :
6673 : :
6674 : : /* Match a formal argument list or, if typeparam is true, a
6675 : : type_param_name_list. */
6676 : :
6677 : : match
6678 : 451029 : gfc_match_formal_arglist (gfc_symbol *progname, int st_flag,
6679 : : int null_flag, bool typeparam)
6680 : : {
6681 : 451029 : gfc_formal_arglist *head, *tail, *p, *q;
6682 : 451029 : char name[GFC_MAX_SYMBOL_LEN + 1];
6683 : 451029 : gfc_symbol *sym;
6684 : 451029 : match m;
6685 : 451029 : gfc_formal_arglist *formal = NULL;
6686 : :
6687 : 451029 : head = tail = NULL;
6688 : :
6689 : : /* Keep the interface formal argument list and null it so that the
6690 : : matching for the new declaration can be done. The numbers and
6691 : : names of the arguments are checked here. The interface formal
6692 : : arguments are retained in formal_arglist and the characteristics
6693 : : are compared in resolve.cc(resolve_fl_procedure). See the remark
6694 : : in get_proc_name about the eventual need to copy the formal_arglist
6695 : : and populate the formal namespace of the interface symbol. */
6696 : 451029 : if (progname->attr.module_procedure
6697 : 572 : && progname->attr.host_assoc)
6698 : : {
6699 : 163 : formal = progname->formal;
6700 : 163 : progname->formal = NULL;
6701 : : }
6702 : :
6703 : 451029 : if (gfc_match_char ('(') != MATCH_YES)
6704 : : {
6705 : 268009 : if (null_flag)
6706 : 6069 : goto ok;
6707 : : return MATCH_NO;
6708 : : }
6709 : :
6710 : 183020 : if (gfc_match_char (')') == MATCH_YES)
6711 : : {
6712 : 9973 : if (typeparam)
6713 : : {
6714 : 1 : gfc_error_now ("A type parameter list is required at %C");
6715 : 1 : m = MATCH_ERROR;
6716 : 1 : goto cleanup;
6717 : : }
6718 : : else
6719 : 9972 : goto ok;
6720 : : }
6721 : :
6722 : 231101 : for (;;)
6723 : : {
6724 : 231101 : gfc_gobble_whitespace ();
6725 : 231101 : if (gfc_match_char ('*') == MATCH_YES)
6726 : : {
6727 : 9196 : sym = NULL;
6728 : 9196 : if (!typeparam && !gfc_notify_std (GFC_STD_F95_OBS,
6729 : : "Alternate-return argument at %C"))
6730 : : {
6731 : 1 : m = MATCH_ERROR;
6732 : 1 : goto cleanup;
6733 : : }
6734 : 9195 : else if (typeparam)
6735 : 2 : gfc_error_now ("A parameter name is required at %C");
6736 : : }
6737 : : else
6738 : : {
6739 : 221905 : locus loc = gfc_current_locus;
6740 : 221905 : m = gfc_match_name (name);
6741 : 221905 : if (m != MATCH_YES)
6742 : : {
6743 : 15643 : if(typeparam)
6744 : 1 : gfc_error_now ("A parameter name is required at %C");
6745 : 15647 : goto cleanup;
6746 : : }
6747 : 206262 : loc = gfc_get_location_range (NULL, 0, &loc, 1, &gfc_current_locus);
6748 : :
6749 : 206262 : if (!typeparam && gfc_get_symbol (name, NULL, &sym, &loc))
6750 : 4 : goto cleanup;
6751 : 206258 : else if (typeparam
6752 : 206258 : && gfc_get_symbol (name, progname->f2k_derived, &sym, &loc))
6753 : 0 : goto cleanup;
6754 : : }
6755 : :
6756 : 215453 : p = gfc_get_formal_arglist ();
6757 : :
6758 : 215453 : if (head == NULL)
6759 : : head = tail = p;
6760 : : else
6761 : : {
6762 : 57356 : tail->next = p;
6763 : 57356 : tail = p;
6764 : : }
6765 : :
6766 : 215453 : tail->sym = sym;
6767 : :
6768 : : /* We don't add the VARIABLE flavor because the name could be a
6769 : : dummy procedure. We don't apply these attributes to formal
6770 : : arguments of statement functions. */
6771 : 206258 : if (sym != NULL && !st_flag
6772 : 309270 : && (!gfc_add_dummy(&sym->attr, sym->name, NULL)
6773 : 93817 : || !gfc_missing_attr (&sym->attr, NULL)))
6774 : : {
6775 : 0 : m = MATCH_ERROR;
6776 : 0 : goto cleanup;
6777 : : }
6778 : :
6779 : : /* The name of a program unit can be in a different namespace,
6780 : : so check for it explicitly. After the statement is accepted,
6781 : : the name is checked for especially in gfc_get_symbol(). */
6782 : 215453 : if (gfc_new_block != NULL && sym != NULL && !typeparam
6783 : 92852 : && strcmp (sym->name, gfc_new_block->name) == 0)
6784 : : {
6785 : 0 : gfc_error ("Name %qs at %C is the name of the procedure",
6786 : : sym->name);
6787 : 0 : m = MATCH_ERROR;
6788 : 0 : goto cleanup;
6789 : : }
6790 : :
6791 : 215453 : if (gfc_match_char (')') == MATCH_YES)
6792 : 112450 : goto ok;
6793 : :
6794 : 103003 : m = gfc_match_char (',');
6795 : 103003 : if (m != MATCH_YES)
6796 : : {
6797 : 44949 : if (typeparam)
6798 : 1 : gfc_error_now ("Expected parameter list in type declaration "
6799 : : "at %C");
6800 : : else
6801 : 44948 : gfc_error ("Unexpected junk in formal argument list at %C");
6802 : 44949 : goto cleanup;
6803 : : }
6804 : : }
6805 : :
6806 : 128491 : ok:
6807 : : /* Check for duplicate symbols in the formal argument list. */
6808 : 128491 : if (head != NULL)
6809 : : {
6810 : 168254 : for (p = head; p->next; p = p->next)
6811 : : {
6812 : 55852 : if (p->sym == NULL)
6813 : 325 : continue;
6814 : :
6815 : 225918 : for (q = p->next; q; q = q->next)
6816 : 170439 : if (p->sym == q->sym)
6817 : : {
6818 : 48 : if (typeparam)
6819 : 1 : gfc_error_now ("Duplicate name %qs in parameter "
6820 : : "list at %C", p->sym->name);
6821 : : else
6822 : 47 : gfc_error ("Duplicate symbol %qs in formal argument "
6823 : : "list at %C", p->sym->name);
6824 : :
6825 : 48 : m = MATCH_ERROR;
6826 : 48 : goto cleanup;
6827 : : }
6828 : : }
6829 : : }
6830 : :
6831 : 128443 : if (!gfc_add_explicit_interface (progname, IFSRC_DECL, head, NULL))
6832 : : {
6833 : 0 : m = MATCH_ERROR;
6834 : 0 : goto cleanup;
6835 : : }
6836 : :
6837 : : /* gfc_error_now used in following and return with MATCH_YES because
6838 : : doing otherwise results in a cascade of extraneous errors and in
6839 : : some cases an ICE in symbol.cc(gfc_release_symbol). */
6840 : 128443 : if (progname->attr.module_procedure && progname->attr.host_assoc)
6841 : : {
6842 : 162 : bool arg_count_mismatch = false;
6843 : :
6844 : 162 : if (!formal && head)
6845 : : arg_count_mismatch = true;
6846 : :
6847 : : /* Abbreviated module procedure declaration is not meant to have any
6848 : : formal arguments! */
6849 : 162 : if (!progname->abr_modproc_decl && formal && !head)
6850 : 1 : arg_count_mismatch = true;
6851 : :
6852 : 308 : for (p = formal, q = head; p && q; p = p->next, q = q->next)
6853 : : {
6854 : 146 : if ((p->next != NULL && q->next == NULL)
6855 : 145 : || (p->next == NULL && q->next != NULL))
6856 : : arg_count_mismatch = true;
6857 : 144 : else if ((p->sym == NULL && q->sym == NULL)
6858 : 144 : || (p->sym && q->sym
6859 : 142 : && strcmp (p->sym->name, q->sym->name) == 0))
6860 : 140 : continue;
6861 : : else
6862 : : {
6863 : 4 : if (q->sym == NULL)
6864 : 1 : gfc_error_now ("MODULE PROCEDURE formal argument %qs "
6865 : : "conflicts with alternate return at %C",
6866 : : p->sym->name);
6867 : 3 : else if (p->sym == NULL)
6868 : 1 : gfc_error_now ("MODULE PROCEDURE formal argument is "
6869 : : "alternate return and conflicts with "
6870 : : "%qs in the separate declaration at %C",
6871 : : q->sym->name);
6872 : : else
6873 : 2 : gfc_error_now ("Mismatch in MODULE PROCEDURE formal "
6874 : : "argument names (%s/%s) at %C",
6875 : : p->sym->name, q->sym->name);
6876 : : }
6877 : : }
6878 : :
6879 : 162 : if (arg_count_mismatch)
6880 : 4 : gfc_error_now ("Mismatch in number of MODULE PROCEDURE "
6881 : : "formal arguments at %C");
6882 : : }
6883 : :
6884 : : return MATCH_YES;
6885 : :
6886 : 60646 : cleanup:
6887 : 60646 : gfc_free_formal_arglist (head);
6888 : 60646 : return m;
6889 : : }
6890 : :
6891 : :
6892 : : /* Match a RESULT specification following a function declaration or
6893 : : ENTRY statement. Also matches the end-of-statement. */
6894 : :
6895 : : static match
6896 : 7549 : match_result (gfc_symbol *function, gfc_symbol **result)
6897 : : {
6898 : 7549 : char name[GFC_MAX_SYMBOL_LEN + 1];
6899 : 7549 : gfc_symbol *r;
6900 : 7549 : match m;
6901 : :
6902 : 7549 : if (gfc_match (" result (") != MATCH_YES)
6903 : : return MATCH_NO;
6904 : :
6905 : 5617 : m = gfc_match_name (name);
6906 : 5617 : if (m != MATCH_YES)
6907 : : return m;
6908 : :
6909 : : /* Get the right paren, and that's it because there could be the
6910 : : bind(c) attribute after the result clause. */
6911 : 5617 : if (gfc_match_char (')') != MATCH_YES)
6912 : : {
6913 : : /* TODO: should report the missing right paren here. */
6914 : : return MATCH_ERROR;
6915 : : }
6916 : :
6917 : 5617 : if (strcmp (function->name, name) == 0)
6918 : : {
6919 : 1 : gfc_error ("RESULT variable at %C must be different than function name");
6920 : 1 : return MATCH_ERROR;
6921 : : }
6922 : :
6923 : 5616 : if (gfc_get_symbol (name, NULL, &r))
6924 : : return MATCH_ERROR;
6925 : :
6926 : 5616 : if (!gfc_add_result (&r->attr, r->name, NULL))
6927 : : return MATCH_ERROR;
6928 : :
6929 : 5616 : *result = r;
6930 : :
6931 : 5616 : return MATCH_YES;
6932 : : }
6933 : :
6934 : :
6935 : : /* Match a function suffix, which could be a combination of a result
6936 : : clause and BIND(C), either one, or neither. The draft does not
6937 : : require them to come in a specific order. */
6938 : :
6939 : : static match
6940 : 7553 : gfc_match_suffix (gfc_symbol *sym, gfc_symbol **result)
6941 : : {
6942 : 7553 : match is_bind_c; /* Found bind(c). */
6943 : 7553 : match is_result; /* Found result clause. */
6944 : 7553 : match found_match; /* Status of whether we've found a good match. */
6945 : 7553 : char peek_char; /* Character we're going to peek at. */
6946 : 7553 : bool allow_binding_name;
6947 : :
6948 : : /* Initialize to having found nothing. */
6949 : 7553 : found_match = MATCH_NO;
6950 : 7553 : is_bind_c = MATCH_NO;
6951 : 7553 : is_result = MATCH_NO;
6952 : :
6953 : : /* Get the next char to narrow between result and bind(c). */
6954 : 7553 : gfc_gobble_whitespace ();
6955 : 7553 : peek_char = gfc_peek_ascii_char ();
6956 : :
6957 : : /* C binding names are not allowed for internal procedures. */
6958 : 7553 : if (gfc_current_state () == COMP_CONTAINS
6959 : 4453 : && sym->ns->proc_name->attr.flavor != FL_MODULE)
6960 : : allow_binding_name = false;
6961 : : else
6962 : 5946 : allow_binding_name = true;
6963 : :
6964 : 7553 : switch (peek_char)
6965 : : {
6966 : 5247 : case 'r':
6967 : : /* Look for result clause. */
6968 : 5247 : is_result = match_result (sym, result);
6969 : 5247 : if (is_result == MATCH_YES)
6970 : : {
6971 : : /* Now see if there is a bind(c) after it. */
6972 : 5246 : is_bind_c = gfc_match_bind_c (sym, allow_binding_name);
6973 : : /* We've found the result clause and possibly bind(c). */
6974 : 5246 : found_match = MATCH_YES;
6975 : : }
6976 : : else
6977 : : /* This should only be MATCH_ERROR. */
6978 : : found_match = is_result;
6979 : : break;
6980 : 2306 : case 'b':
6981 : : /* Look for bind(c) first. */
6982 : 2306 : is_bind_c = gfc_match_bind_c (sym, allow_binding_name);
6983 : 2306 : if (is_bind_c == MATCH_YES)
6984 : : {
6985 : : /* Now see if a result clause followed it. */
6986 : 2302 : is_result = match_result (sym, result);
6987 : 2302 : found_match = MATCH_YES;
6988 : : }
6989 : : else
6990 : : {
6991 : : /* Should only be a MATCH_ERROR if we get here after seeing 'b'. */
6992 : : found_match = MATCH_ERROR;
6993 : : }
6994 : : break;
6995 : 0 : default:
6996 : 0 : gfc_error ("Unexpected junk after function declaration at %C");
6997 : 0 : found_match = MATCH_ERROR;
6998 : 0 : break;
6999 : : }
7000 : :
7001 : 7548 : if (is_bind_c == MATCH_YES)
7002 : : {
7003 : : /* Fortran 2008 draft allows BIND(C) for internal procedures. */
7004 : 2451 : if (gfc_current_state () == COMP_CONTAINS
7005 : 416 : && sym->ns->proc_name->attr.flavor != FL_MODULE
7006 : 2463 : && !gfc_notify_std (GFC_STD_F2008, "BIND(C) attribute "
7007 : : "at %L may not be specified for an internal "
7008 : : "procedure", &gfc_current_locus))
7009 : : return MATCH_ERROR;
7010 : :
7011 : 2448 : if (!gfc_add_is_bind_c (&(sym->attr), sym->name, &gfc_current_locus, 1))
7012 : : return MATCH_ERROR;
7013 : : }
7014 : :
7015 : : return found_match;
7016 : : }
7017 : :
7018 : :
7019 : : /* Procedure pointer return value without RESULT statement:
7020 : : Add "hidden" result variable named "ppr@". */
7021 : :
7022 : : static bool
7023 : 70033 : add_hidden_procptr_result (gfc_symbol *sym)
7024 : : {
7025 : 70033 : bool case1,case2;
7026 : :
7027 : 70033 : if (gfc_notification_std (GFC_STD_F2003) == ERROR)
7028 : : return false;
7029 : :
7030 : : /* First usage case: PROCEDURE and EXTERNAL statements. */
7031 : 1498 : case1 = gfc_current_state () == COMP_FUNCTION && gfc_current_block ()
7032 : 1498 : && strcmp (gfc_current_block ()->name, sym->name) == 0
7033 : 70411 : && sym->attr.external;
7034 : : /* Second usage case: INTERFACE statements. */
7035 : 12724 : case2 = gfc_current_state () == COMP_INTERFACE && gfc_state_stack->previous
7036 : 12724 : && gfc_state_stack->previous->state == COMP_FUNCTION
7037 : 70075 : && strcmp (gfc_state_stack->previous->sym->name, sym->name) == 0;
7038 : :
7039 : 69848 : if (case1 || case2)
7040 : : {
7041 : 123 : gfc_symtree *stree;
7042 : 123 : if (case1)
7043 : 93 : gfc_get_sym_tree ("ppr@", gfc_current_ns, &stree, false);
7044 : : else
7045 : : {
7046 : 30 : gfc_symtree *st2;
7047 : 30 : gfc_get_sym_tree ("ppr@", gfc_current_ns->parent, &stree, false);
7048 : 30 : st2 = gfc_new_symtree (&gfc_current_ns->sym_root, "ppr@");
7049 : 30 : st2->n.sym = stree->n.sym;
7050 : 30 : stree->n.sym->refs++;
7051 : : }
7052 : 123 : sym->result = stree->n.sym;
7053 : :
7054 : 123 : sym->result->attr.proc_pointer = sym->attr.proc_pointer;
7055 : 123 : sym->result->attr.pointer = sym->attr.pointer;
7056 : 123 : sym->result->attr.external = sym->attr.external;
7057 : 123 : sym->result->attr.referenced = sym->attr.referenced;
7058 : 123 : sym->result->ts = sym->ts;
7059 : 123 : sym->attr.proc_pointer = 0;
7060 : 123 : sym->attr.pointer = 0;
7061 : 123 : sym->attr.external = 0;
7062 : 123 : if (sym->result->attr.external && sym->result->attr.pointer)
7063 : : {
7064 : 4 : sym->result->attr.pointer = 0;
7065 : 4 : sym->result->attr.proc_pointer = 1;
7066 : : }
7067 : :
7068 : 123 : return gfc_add_result (&sym->result->attr, sym->result->name, NULL);
7069 : : }
7070 : : /* POINTER after PROCEDURE/EXTERNAL/INTERFACE statement. */
7071 : 69755 : else if (sym->attr.function && !sym->attr.external && sym->attr.pointer
7072 : 399 : && sym->result && sym->result != sym && sym->result->attr.external
7073 : 28 : && sym == gfc_current_ns->proc_name
7074 : 28 : && sym == sym->result->ns->proc_name
7075 : 28 : && strcmp ("ppr@", sym->result->name) == 0)
7076 : : {
7077 : 28 : sym->result->attr.proc_pointer = 1;
7078 : 28 : sym->attr.pointer = 0;
7079 : 28 : return true;
7080 : : }
7081 : : else
7082 : : return false;
7083 : : }
7084 : :
7085 : :
7086 : : /* Match the interface for a PROCEDURE declaration,
7087 : : including brackets (R1212). */
7088 : :
7089 : : static match
7090 : 1510 : match_procedure_interface (gfc_symbol **proc_if)
7091 : : {
7092 : 1510 : match m;
7093 : 1510 : gfc_symtree *st;
7094 : 1510 : locus old_loc, entry_loc;
7095 : 1510 : gfc_namespace *old_ns = gfc_current_ns;
7096 : 1510 : char name[GFC_MAX_SYMBOL_LEN + 1];
7097 : :
7098 : 1510 : old_loc = entry_loc = gfc_current_locus;
7099 : 1510 : gfc_clear_ts (¤t_ts);
7100 : :
7101 : 1510 : if (gfc_match (" (") != MATCH_YES)
7102 : : {
7103 : 1 : gfc_current_locus = entry_loc;
7104 : 1 : return MATCH_NO;
7105 : : }
7106 : :
7107 : : /* Get the type spec. for the procedure interface. */
7108 : 1509 : old_loc = gfc_current_locus;
7109 : 1509 : m = gfc_match_decl_type_spec (¤t_ts, 0);
7110 : 1509 : gfc_gobble_whitespace ();
7111 : 1509 : if (m == MATCH_YES || (m == MATCH_NO && gfc_peek_ascii_char () == ')'))
7112 : 384 : goto got_ts;
7113 : :
7114 : 1125 : if (m == MATCH_ERROR)
7115 : : return m;
7116 : :
7117 : : /* Procedure interface is itself a procedure. */
7118 : 1125 : gfc_current_locus = old_loc;
7119 : 1125 : m = gfc_match_name (name);
7120 : :
7121 : : /* First look to see if it is already accessible in the current
7122 : : namespace because it is use associated or contained. */
7123 : 1125 : st = NULL;
7124 : 1125 : if (gfc_find_sym_tree (name, NULL, 0, &st))
7125 : : return MATCH_ERROR;
7126 : :
7127 : : /* If it is still not found, then try the parent namespace, if it
7128 : : exists and create the symbol there if it is still not found. */
7129 : 1125 : if (gfc_current_ns->parent)
7130 : 368 : gfc_current_ns = gfc_current_ns->parent;
7131 : 1125 : if (st == NULL && gfc_get_ha_sym_tree (name, &st))
7132 : : return MATCH_ERROR;
7133 : :
7134 : 1125 : gfc_current_ns = old_ns;
7135 : 1125 : *proc_if = st->n.sym;
7136 : :
7137 : 1125 : if (*proc_if)
7138 : : {
7139 : 1125 : (*proc_if)->refs++;
7140 : : /* Resolve interface if possible. That way, attr.procedure is only set
7141 : : if it is declared by a later procedure-declaration-stmt, which is
7142 : : invalid per F08:C1216 (cf. resolve_procedure_interface). */
7143 : 1125 : while ((*proc_if)->ts.interface
7144 : 1132 : && *proc_if != (*proc_if)->ts.interface)
7145 : 7 : *proc_if = (*proc_if)->ts.interface;
7146 : :
7147 : 1125 : if ((*proc_if)->attr.flavor == FL_UNKNOWN
7148 : 387 : && (*proc_if)->ts.type == BT_UNKNOWN
7149 : 1512 : && !gfc_add_flavor (&(*proc_if)->attr, FL_PROCEDURE,
7150 : : (*proc_if)->name, NULL))
7151 : : return MATCH_ERROR;
7152 : : }
7153 : :
7154 : 0 : got_ts:
7155 : 1509 : if (gfc_match (" )") != MATCH_YES)
7156 : : {
7157 : 0 : gfc_current_locus = entry_loc;
7158 : 0 : return MATCH_NO;
7159 : : }
7160 : :
7161 : : return MATCH_YES;
7162 : : }
7163 : :
7164 : :
7165 : : /* Match a PROCEDURE declaration (R1211). */
7166 : :
7167 : : static match
7168 : 1097 : match_procedure_decl (void)
7169 : : {
7170 : 1097 : match m;
7171 : 1097 : gfc_symbol *sym, *proc_if = NULL;
7172 : 1097 : int num;
7173 : 1097 : gfc_expr *initializer = NULL;
7174 : :
7175 : : /* Parse interface (with brackets). */
7176 : 1097 : m = match_procedure_interface (&proc_if);
7177 : 1097 : if (m != MATCH_YES)
7178 : : return m;
7179 : :
7180 : : /* Parse attributes (with colons). */
7181 : 1097 : m = match_attr_spec();
7182 : 1097 : if (m == MATCH_ERROR)
7183 : : return MATCH_ERROR;
7184 : :
7185 : 1096 : if (proc_if && proc_if->attr.is_bind_c && !current_attr.is_bind_c)
7186 : : {
7187 : 17 : current_attr.is_bind_c = 1;
7188 : 17 : has_name_equals = 0;
7189 : 17 : curr_binding_label = NULL;
7190 : : }
7191 : :
7192 : : /* Get procedure symbols. */
7193 : 79 : for(num=1;;num++)
7194 : : {
7195 : 1175 : m = gfc_match_symbol (&sym, 0);
7196 : 1175 : if (m == MATCH_NO)
7197 : 1 : goto syntax;
7198 : 1174 : else if (m == MATCH_ERROR)
7199 : : return m;
7200 : :
7201 : : /* Add current_attr to the symbol attributes. */
7202 : 1174 : if (!gfc_copy_attr (&sym->attr, ¤t_attr, NULL))
7203 : : return MATCH_ERROR;
7204 : :
7205 : 1172 : if (sym->attr.is_bind_c)
7206 : : {
7207 : : /* Check for C1218. */
7208 : 53 : if (!proc_if || !proc_if->attr.is_bind_c)
7209 : : {
7210 : 1 : gfc_error ("BIND(C) attribute at %C requires "
7211 : : "an interface with BIND(C)");
7212 : 1 : return MATCH_ERROR;
7213 : : }
7214 : : /* Check for C1217. */
7215 : 52 : if (has_name_equals && sym->attr.pointer)
7216 : : {
7217 : 1 : gfc_error ("BIND(C) procedure with NAME may not have "
7218 : : "POINTER attribute at %C");
7219 : 1 : return MATCH_ERROR;
7220 : : }
7221 : 51 : if (has_name_equals && sym->attr.dummy)
7222 : : {
7223 : 1 : gfc_error ("Dummy procedure at %C may not have "
7224 : : "BIND(C) attribute with NAME");
7225 : 1 : return MATCH_ERROR;
7226 : : }
7227 : : /* Set binding label for BIND(C). */
7228 : 50 : if (!set_binding_label (&sym->binding_label, sym->name, num))
7229 : : return MATCH_ERROR;
7230 : : }
7231 : :
7232 : 1168 : if (!gfc_add_external (&sym->attr, NULL))
7233 : : return MATCH_ERROR;
7234 : :
7235 : 1164 : if (add_hidden_procptr_result (sym))
7236 : 66 : sym = sym->result;
7237 : :
7238 : 1164 : if (!gfc_add_proc (&sym->attr, sym->name, NULL))
7239 : : return MATCH_ERROR;
7240 : :
7241 : : /* Set interface. */
7242 : 1163 : if (proc_if != NULL)
7243 : : {
7244 : 824 : if (sym->ts.type != BT_UNKNOWN)
7245 : : {
7246 : 1 : gfc_error ("Procedure %qs at %L already has basic type of %s",
7247 : : sym->name, &gfc_current_locus,
7248 : : gfc_basic_typename (sym->ts.type));
7249 : 1 : return MATCH_ERROR;
7250 : : }
7251 : 823 : sym->ts.interface = proc_if;
7252 : 823 : sym->attr.untyped = 1;
7253 : 823 : sym->attr.if_source = IFSRC_IFBODY;
7254 : : }
7255 : 339 : else if (current_ts.type != BT_UNKNOWN)
7256 : : {
7257 : 199 : if (!gfc_add_type (sym, ¤t_ts, &gfc_current_locus))
7258 : : return MATCH_ERROR;
7259 : 198 : sym->ts.interface = gfc_new_symbol ("", gfc_current_ns);
7260 : 198 : sym->ts.interface->ts = current_ts;
7261 : 198 : sym->ts.interface->attr.flavor = FL_PROCEDURE;
7262 : 198 : sym->ts.interface->attr.function = 1;
7263 : 198 : sym->attr.function = 1;
7264 : 198 : sym->attr.if_source = IFSRC_UNKNOWN;
7265 : : }
7266 : :
7267 : 1161 : if (gfc_match (" =>") == MATCH_YES)
7268 : : {
7269 : 85 : if (!current_attr.pointer)
7270 : : {
7271 : 0 : gfc_error ("Initialization at %C isn't for a pointer variable");
7272 : 0 : m = MATCH_ERROR;
7273 : 0 : goto cleanup;
7274 : : }
7275 : :
7276 : 85 : m = match_pointer_init (&initializer, 1);
7277 : 85 : if (m != MATCH_YES)
7278 : 1 : goto cleanup;
7279 : :
7280 : 84 : if (!add_init_expr_to_sym (sym->name, &initializer, &gfc_current_locus))
7281 : 0 : goto cleanup;
7282 : :
7283 : : }
7284 : :
7285 : 1160 : if (gfc_match_eos () == MATCH_YES)
7286 : : return MATCH_YES;
7287 : 79 : if (gfc_match_char (',') != MATCH_YES)
7288 : 0 : goto syntax;
7289 : : }
7290 : :
7291 : 1 : syntax:
7292 : 1 : gfc_error ("Syntax error in PROCEDURE statement at %C");
7293 : 1 : return MATCH_ERROR;
7294 : :
7295 : 1 : cleanup:
7296 : : /* Free stuff up and return. */
7297 : 1 : gfc_free_expr (initializer);
7298 : 1 : return m;
7299 : : }
7300 : :
7301 : :
7302 : : static match
7303 : : match_binding_attributes (gfc_typebound_proc* ba, bool generic, bool ppc);
7304 : :
7305 : :
7306 : : /* Match a procedure pointer component declaration (R445). */
7307 : :
7308 : : static match
7309 : 413 : match_ppc_decl (void)
7310 : : {
7311 : 413 : match m;
7312 : 413 : gfc_symbol *proc_if = NULL;
7313 : 413 : gfc_typespec ts;
7314 : 413 : int num;
7315 : 413 : gfc_component *c;
7316 : 413 : gfc_expr *initializer = NULL;
7317 : 413 : gfc_typebound_proc* tb;
7318 : 413 : char name[GFC_MAX_SYMBOL_LEN + 1];
7319 : :
7320 : : /* Parse interface (with brackets). */
7321 : 413 : m = match_procedure_interface (&proc_if);
7322 : 413 : if (m != MATCH_YES)
7323 : 1 : goto syntax;
7324 : :
7325 : : /* Parse attributes. */
7326 : 412 : tb = XCNEW (gfc_typebound_proc);
7327 : 412 : tb->where = gfc_current_locus;
7328 : 412 : m = match_binding_attributes (tb, false, true);
7329 : 412 : if (m == MATCH_ERROR)
7330 : : return m;
7331 : :
7332 : 409 : gfc_clear_attr (¤t_attr);
7333 : 409 : current_attr.procedure = 1;
7334 : 409 : current_attr.proc_pointer = 1;
7335 : 409 : current_attr.access = tb->access;
7336 : 409 : current_attr.flavor = FL_PROCEDURE;
7337 : :
7338 : : /* Match the colons (required). */
7339 : 409 : if (gfc_match (" ::") != MATCH_YES)
7340 : : {
7341 : 1 : gfc_error ("Expected %<::%> after binding-attributes at %C");
7342 : 1 : return MATCH_ERROR;
7343 : : }
7344 : :
7345 : : /* Check for C450. */
7346 : 408 : if (!tb->nopass && proc_if == NULL)
7347 : : {
7348 : 2 : gfc_error("NOPASS or explicit interface required at %C");
7349 : 2 : return MATCH_ERROR;
7350 : : }
7351 : :
7352 : 406 : if (!gfc_notify_std (GFC_STD_F2003, "Procedure pointer component at %C"))
7353 : : return MATCH_ERROR;
7354 : :
7355 : : /* Match PPC names. */
7356 : 405 : ts = current_ts;
7357 : 405 : for(num=1;;num++)
7358 : : {
7359 : 406 : m = gfc_match_name (name);
7360 : 406 : if (m == MATCH_NO)
7361 : 0 : goto syntax;
7362 : 406 : else if (m == MATCH_ERROR)
7363 : : return m;
7364 : :
7365 : 406 : if (!gfc_add_component (gfc_current_block(), name, &c))
7366 : : return MATCH_ERROR;
7367 : :
7368 : : /* Add current_attr to the symbol attributes. */
7369 : 406 : if (!gfc_copy_attr (&c->attr, ¤t_attr, NULL))
7370 : : return MATCH_ERROR;
7371 : :
7372 : 406 : if (!gfc_add_external (&c->attr, NULL))
7373 : : return MATCH_ERROR;
7374 : :
7375 : 406 : if (!gfc_add_proc (&c->attr, name, NULL))
7376 : : return MATCH_ERROR;
7377 : :
7378 : 406 : if (num == 1)
7379 : 405 : c->tb = tb;
7380 : : else
7381 : : {
7382 : 1 : c->tb = XCNEW (gfc_typebound_proc);
7383 : 1 : c->tb->where = gfc_current_locus;
7384 : 1 : *c->tb = *tb;
7385 : : }
7386 : :
7387 : : /* Set interface. */
7388 : 406 : if (proc_if != NULL)
7389 : : {
7390 : 346 : c->ts.interface = proc_if;
7391 : 346 : c->attr.untyped = 1;
7392 : 346 : c->attr.if_source = IFSRC_IFBODY;
7393 : : }
7394 : 60 : else if (ts.type != BT_UNKNOWN)
7395 : : {
7396 : 23 : c->ts = ts;
7397 : 23 : c->ts.interface = gfc_new_symbol ("", gfc_current_ns);
7398 : 23 : c->ts.interface->result = c->ts.interface;
7399 : 23 : c->ts.interface->ts = ts;
7400 : 23 : c->ts.interface->attr.flavor = FL_PROCEDURE;
7401 : 23 : c->ts.interface->attr.function = 1;
7402 : 23 : c->attr.function = 1;
7403 : 23 : c->attr.if_source = IFSRC_UNKNOWN;
7404 : : }
7405 : :
7406 : 406 : if (gfc_match (" =>") == MATCH_YES)
7407 : : {
7408 : 60 : m = match_pointer_init (&initializer, 1);
7409 : 60 : if (m != MATCH_YES)
7410 : : {
7411 : 0 : gfc_free_expr (initializer);
7412 : 0 : return m;
7413 : : }
7414 : 60 : c->initializer = initializer;
7415 : : }
7416 : :
7417 : 406 : if (gfc_match_eos () == MATCH_YES)
7418 : : return MATCH_YES;
7419 : 1 : if (gfc_match_char (',') != MATCH_YES)
7420 : 0 : goto syntax;
7421 : : }
7422 : :
7423 : 1 : syntax:
7424 : 1 : gfc_error ("Syntax error in procedure pointer component at %C");
7425 : 1 : return MATCH_ERROR;
7426 : : }
7427 : :
7428 : :
7429 : : /* Match a PROCEDURE declaration inside an interface (R1206). */
7430 : :
7431 : : static match
7432 : 1534 : match_procedure_in_interface (void)
7433 : : {
7434 : 1534 : match m;
7435 : 1534 : gfc_symbol *sym;
7436 : 1534 : char name[GFC_MAX_SYMBOL_LEN + 1];
7437 : 1534 : locus old_locus;
7438 : :
7439 : 1534 : if (current_interface.type == INTERFACE_NAMELESS
7440 : 1534 : || current_interface.type == INTERFACE_ABSTRACT)
7441 : : {
7442 : 1 : gfc_error ("PROCEDURE at %C must be in a generic interface");
7443 : 1 : return MATCH_ERROR;
7444 : : }
7445 : :
7446 : : /* Check if the F2008 optional double colon appears. */
7447 : 1533 : gfc_gobble_whitespace ();
7448 : 1533 : old_locus = gfc_current_locus;
7449 : 1533 : if (gfc_match ("::") == MATCH_YES)
7450 : : {
7451 : 848 : if (!gfc_notify_std (GFC_STD_F2008, "double colon in "
7452 : : "MODULE PROCEDURE statement at %L", &old_locus))
7453 : : return MATCH_ERROR;
7454 : : }
7455 : : else
7456 : 685 : gfc_current_locus = old_locus;
7457 : :
7458 : 2187 : for(;;)
7459 : : {
7460 : 2187 : m = gfc_match_name (name);
7461 : 2187 : if (m == MATCH_NO)
7462 : 0 : goto syntax;
7463 : 2187 : else if (m == MATCH_ERROR)
7464 : : return m;
7465 : 2187 : if (gfc_get_symbol (name, gfc_current_ns->parent, &sym))
7466 : : return MATCH_ERROR;
7467 : :
7468 : 2187 : if (!gfc_add_interface (sym))
7469 : : return MATCH_ERROR;
7470 : :
7471 : 2186 : if (gfc_match_eos () == MATCH_YES)
7472 : : break;
7473 : 655 : if (gfc_match_char (',') != MATCH_YES)
7474 : 0 : goto syntax;
7475 : : }
7476 : :
7477 : : return MATCH_YES;
7478 : :
7479 : 0 : syntax:
7480 : 0 : gfc_error ("Syntax error in PROCEDURE statement at %C");
7481 : 0 : return MATCH_ERROR;
7482 : : }
7483 : :
7484 : :
7485 : : /* General matcher for PROCEDURE declarations. */
7486 : :
7487 : : static match match_procedure_in_type (void);
7488 : :
7489 : : match
7490 : 6098 : gfc_match_procedure (void)
7491 : : {
7492 : 6098 : match m;
7493 : :
7494 : 6098 : switch (gfc_current_state ())
7495 : : {
7496 : 1097 : case COMP_NONE:
7497 : 1097 : case COMP_PROGRAM:
7498 : 1097 : case COMP_MODULE:
7499 : 1097 : case COMP_SUBMODULE:
7500 : 1097 : case COMP_SUBROUTINE:
7501 : 1097 : case COMP_FUNCTION:
7502 : 1097 : case COMP_BLOCK:
7503 : 1097 : m = match_procedure_decl ();
7504 : 1097 : break;
7505 : 1534 : case COMP_INTERFACE:
7506 : 1534 : m = match_procedure_in_interface ();
7507 : 1534 : break;
7508 : 413 : case COMP_DERIVED:
7509 : 413 : m = match_ppc_decl ();
7510 : 413 : break;
7511 : 3054 : case COMP_DERIVED_CONTAINS:
7512 : 3054 : m = match_procedure_in_type ();
7513 : 3054 : break;
7514 : : default:
7515 : : return MATCH_NO;
7516 : : }
7517 : :
7518 : 6098 : if (m != MATCH_YES)
7519 : : return m;
7520 : :
7521 : 6042 : if (!gfc_notify_std (GFC_STD_F2003, "PROCEDURE statement at %C"))
7522 : 4 : return MATCH_ERROR;
7523 : :
7524 : : return m;
7525 : : }
7526 : :
7527 : :
7528 : : /* Warn if a matched procedure has the same name as an intrinsic; this is
7529 : : simply a wrapper around gfc_warn_intrinsic_shadow that interprets the current
7530 : : parser-state-stack to find out whether we're in a module. */
7531 : :
7532 : : static void
7533 : 58664 : do_warn_intrinsic_shadow (const gfc_symbol* sym, bool func)
7534 : : {
7535 : 58664 : bool in_module;
7536 : :
7537 : 117328 : in_module = (gfc_state_stack->previous
7538 : 58664 : && (gfc_state_stack->previous->state == COMP_MODULE
7539 : 47526 : || gfc_state_stack->previous->state == COMP_SUBMODULE));
7540 : :
7541 : 58664 : gfc_warn_intrinsic_shadow (sym, in_module, func);
7542 : 58664 : }
7543 : :
7544 : :
7545 : : /* Match a function declaration. */
7546 : :
7547 : : match
7548 : 119903 : gfc_match_function_decl (void)
7549 : : {
7550 : 119903 : char name[GFC_MAX_SYMBOL_LEN + 1];
7551 : 119903 : gfc_symbol *sym, *result;
7552 : 119903 : locus old_loc;
7553 : 119903 : match m;
7554 : 119903 : match suffix_match;
7555 : 119903 : match found_match; /* Status returned by match func. */
7556 : :
7557 : 119903 : if (gfc_current_state () != COMP_NONE
7558 : 74511 : && gfc_current_state () != COMP_INTERFACE
7559 : 49283 : && gfc_current_state () != COMP_CONTAINS)
7560 : : return MATCH_NO;
7561 : :
7562 : 119903 : gfc_clear_ts (¤t_ts);
7563 : :
7564 : 119903 : old_loc = gfc_current_locus;
7565 : :
7566 : 119903 : m = gfc_match_prefix (¤t_ts);
7567 : 119903 : if (m != MATCH_YES)
7568 : : {
7569 : 9225 : gfc_current_locus = old_loc;
7570 : 9225 : return m;
7571 : : }
7572 : :
7573 : 110678 : if (gfc_match ("function% %n", name) != MATCH_YES)
7574 : : {
7575 : 92393 : gfc_current_locus = old_loc;
7576 : 92393 : return MATCH_NO;
7577 : : }
7578 : :
7579 : 18285 : if (get_proc_name (name, &sym, false))
7580 : : return MATCH_ERROR;
7581 : :
7582 : 18280 : if (add_hidden_procptr_result (sym))
7583 : 20 : sym = sym->result;
7584 : :
7585 : 18280 : if (current_attr.module_procedure)
7586 : 200 : sym->attr.module_procedure = 1;
7587 : :
7588 : 18280 : gfc_new_block = sym;
7589 : :
7590 : 18280 : m = gfc_match_formal_arglist (sym, 0, 0);
7591 : 18280 : if (m == MATCH_NO)
7592 : : {
7593 : 6 : gfc_error ("Expected formal argument list in function "
7594 : : "definition at %C");
7595 : 6 : m = MATCH_ERROR;
7596 : 6 : goto cleanup;
7597 : : }
7598 : 18274 : else if (m == MATCH_ERROR)
7599 : 0 : goto cleanup;
7600 : :
7601 : 18274 : result = NULL;
7602 : :
7603 : : /* According to the draft, the bind(c) and result clause can
7604 : : come in either order after the formal_arg_list (i.e., either
7605 : : can be first, both can exist together or by themselves or neither
7606 : : one). Therefore, the match_result can't match the end of the
7607 : : string, and check for the bind(c) or result clause in either order. */
7608 : 18274 : found_match = gfc_match_eos ();
7609 : :
7610 : : /* Make sure that it isn't already declared as BIND(C). If it is, it
7611 : : must have been marked BIND(C) with a BIND(C) attribute and that is
7612 : : not allowed for procedures. */
7613 : 18274 : if (sym->attr.is_bind_c == 1)
7614 : : {
7615 : 3 : sym->attr.is_bind_c = 0;
7616 : :
7617 : 3 : if (gfc_state_stack->previous
7618 : 3 : && gfc_state_stack->previous->state != COMP_SUBMODULE)
7619 : : {
7620 : 1 : locus loc;
7621 : 1 : loc = sym->old_symbol != NULL
7622 : 1 : ? sym->old_symbol->declared_at : gfc_current_locus;
7623 : 1 : gfc_error_now ("BIND(C) attribute at %L can only be used for "
7624 : : "variables or common blocks", &loc);
7625 : : }
7626 : : }
7627 : :
7628 : 18274 : if (found_match != MATCH_YES)
7629 : : {
7630 : : /* If we haven't found the end-of-statement, look for a suffix. */
7631 : 7322 : suffix_match = gfc_match_suffix (sym, &result);
7632 : 7322 : if (suffix_match == MATCH_YES)
7633 : : /* Need to get the eos now. */
7634 : 7314 : found_match = gfc_match_eos ();
7635 : : else
7636 : : found_match = suffix_match;
7637 : : }
7638 : :
7639 : : /* F2018 C1550 (R1526) If MODULE appears in the prefix of a module
7640 : : subprogram and a binding label is specified, it shall be the
7641 : : same as the binding label specified in the corresponding module
7642 : : procedure interface body. */
7643 : 18274 : if (sym->attr.is_bind_c && sym->attr.module_procedure && sym->old_symbol
7644 : 3 : && strcmp (sym->name, sym->old_symbol->name) == 0
7645 : 3 : && sym->binding_label && sym->old_symbol->binding_label
7646 : 2 : && strcmp (sym->binding_label, sym->old_symbol->binding_label) != 0)
7647 : : {
7648 : 1 : const char *null = "NULL", *s1, *s2;
7649 : 1 : s1 = sym->binding_label;
7650 : 1 : if (!s1) s1 = null;
7651 : 1 : s2 = sym->old_symbol->binding_label;
7652 : 1 : if (!s2) s2 = null;
7653 : 1 : gfc_error ("Mismatch in BIND(C) names (%qs/%qs) at %C", s1, s2);
7654 : 1 : sym->refs++; /* Needed to avoid an ICE in gfc_release_symbol */
7655 : 1 : return MATCH_ERROR;
7656 : : }
7657 : :
7658 : 18273 : if(found_match != MATCH_YES)
7659 : : m = MATCH_ERROR;
7660 : : else
7661 : : {
7662 : : /* Make changes to the symbol. */
7663 : 18265 : m = MATCH_ERROR;
7664 : :
7665 : 18265 : if (!gfc_add_function (&sym->attr, sym->name, NULL))
7666 : 0 : goto cleanup;
7667 : :
7668 : 18265 : if (!gfc_missing_attr (&sym->attr, NULL))
7669 : 0 : goto cleanup;
7670 : :
7671 : 18265 : if (!copy_prefix (&sym->attr, &sym->declared_at))
7672 : : {
7673 : 1 : if(!sym->attr.module_procedure)
7674 : 1 : goto cleanup;
7675 : : else
7676 : 0 : gfc_error_check ();
7677 : : }
7678 : :
7679 : : /* Delay matching the function characteristics until after the
7680 : : specification block by signalling kind=-1. */
7681 : 18264 : sym->declared_at = old_loc;
7682 : 18264 : if (current_ts.type != BT_UNKNOWN)
7683 : 6596 : current_ts.kind = -1;
7684 : : else
7685 : 11668 : current_ts.kind = 0;
7686 : :
7687 : 18264 : if (result == NULL)
7688 : : {
7689 : 12860 : if (current_ts.type != BT_UNKNOWN
7690 : 12860 : && !gfc_add_type (sym, ¤t_ts, &gfc_current_locus))
7691 : 1 : goto cleanup;
7692 : 12859 : sym->result = sym;
7693 : : }
7694 : : else
7695 : : {
7696 : 5404 : if (current_ts.type != BT_UNKNOWN
7697 : 5404 : && !gfc_add_type (result, ¤t_ts, &gfc_current_locus))
7698 : 0 : goto cleanup;
7699 : 5404 : sym->result = result;
7700 : : }
7701 : :
7702 : : /* Warn if this procedure has the same name as an intrinsic. */
7703 : 18263 : do_warn_intrinsic_shadow (sym, true);
7704 : :
7705 : 18263 : return MATCH_YES;
7706 : : }
7707 : :
7708 : 16 : cleanup:
7709 : 16 : gfc_current_locus = old_loc;
7710 : 16 : return m;
7711 : : }
7712 : :
7713 : :
7714 : : /* This is mostly a copy of parse.cc(add_global_procedure) but modified to
7715 : : pass the name of the entry, rather than the gfc_current_block name, and
7716 : : to return false upon finding an existing global entry. */
7717 : :
7718 : : static bool
7719 : 504 : add_global_entry (const char *name, const char *binding_label, bool sub,
7720 : : locus *where)
7721 : : {
7722 : 504 : gfc_gsymbol *s;
7723 : 504 : enum gfc_symbol_type type;
7724 : :
7725 : 504 : type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION;
7726 : :
7727 : : /* Only in Fortran 2003: For procedures with a binding label also the Fortran
7728 : : name is a global identifier. */
7729 : 504 : if (!binding_label || gfc_notification_std (GFC_STD_F2008))
7730 : : {
7731 : 499 : s = gfc_get_gsymbol (name, false);
7732 : :
7733 : 499 : if (s->defined || (s->type != GSYM_UNKNOWN && s->type != type))
7734 : : {
7735 : 2 : gfc_global_used (s, where);
7736 : 2 : return false;
7737 : : }
7738 : : else
7739 : : {
7740 : 497 : s->type = type;
7741 : 497 : s->sym_name = name;
7742 : 497 : s->where = *where;
7743 : 497 : s->defined = 1;
7744 : 497 : s->ns = gfc_current_ns;
7745 : : }
7746 : : }
7747 : :
7748 : : /* Don't add the symbol multiple times. */
7749 : 502 : if (binding_label
7750 : 502 : && (!gfc_notification_std (GFC_STD_F2008)
7751 : 0 : || strcmp (name, binding_label) != 0))
7752 : : {
7753 : 5 : s = gfc_get_gsymbol (binding_label, true);
7754 : :
7755 : 5 : if (s->defined || (s->type != GSYM_UNKNOWN && s->type != type))
7756 : : {
7757 : 1 : gfc_global_used (s, where);
7758 : 1 : return false;
7759 : : }
7760 : : else
7761 : : {
7762 : 4 : s->type = type;
7763 : 4 : s->sym_name = name;
7764 : 4 : s->binding_label = binding_label;
7765 : 4 : s->where = *where;
7766 : 4 : s->defined = 1;
7767 : 4 : s->ns = gfc_current_ns;
7768 : : }
7769 : : }
7770 : :
7771 : : return true;
7772 : : }
7773 : :
7774 : :
7775 : : /* Match an ENTRY statement. */
7776 : :
7777 : : match
7778 : 769 : gfc_match_entry (void)
7779 : : {
7780 : 769 : gfc_symbol *proc;
7781 : 769 : gfc_symbol *result;
7782 : 769 : gfc_symbol *entry;
7783 : 769 : char name[GFC_MAX_SYMBOL_LEN + 1];
7784 : 769 : gfc_compile_state state;
7785 : 769 : match m;
7786 : 769 : gfc_entry_list *el;
7787 : 769 : locus old_loc;
7788 : 769 : bool module_procedure;
7789 : 769 : char peek_char;
7790 : 769 : match is_bind_c;
7791 : :
7792 : 769 : m = gfc_match_name (name);
7793 : 769 : if (m != MATCH_YES)
7794 : : return m;
7795 : :
7796 : 769 : if (!gfc_notify_std (GFC_STD_F2008_OBS, "ENTRY statement at %C"))
7797 : : return MATCH_ERROR;
7798 : :
7799 : 769 : state = gfc_current_state ();
7800 : 769 : if (state != COMP_SUBROUTINE && state != COMP_FUNCTION)
7801 : : {
7802 : 3 : switch (state)
7803 : : {
7804 : 0 : case COMP_PROGRAM:
7805 : 0 : gfc_error ("ENTRY statement at %C cannot appear within a PROGRAM");
7806 : 0 : break;
7807 : 0 : case COMP_MODULE:
7808 : 0 : gfc_error ("ENTRY statement at %C cannot appear within a MODULE");
7809 : 0 : break;
7810 : 0 : case COMP_SUBMODULE:
7811 : 0 : gfc_error ("ENTRY statement at %C cannot appear within a SUBMODULE");
7812 : 0 : break;
7813 : 0 : case COMP_BLOCK_DATA:
7814 : 0 : gfc_error ("ENTRY statement at %C cannot appear within "
7815 : : "a BLOCK DATA");
7816 : 0 : break;
7817 : 0 : case COMP_INTERFACE:
7818 : 0 : gfc_error ("ENTRY statement at %C cannot appear within "
7819 : : "an INTERFACE");
7820 : 0 : break;
7821 : 1 : case COMP_STRUCTURE:
7822 : 1 : gfc_error ("ENTRY statement at %C cannot appear within "
7823 : : "a STRUCTURE block");
7824 : 1 : break;
7825 : 0 : case COMP_DERIVED:
7826 : 0 : gfc_error ("ENTRY statement at %C cannot appear within "
7827 : : "a DERIVED TYPE block");
7828 : 0 : break;
7829 : 0 : case COMP_IF:
7830 : 0 : gfc_error ("ENTRY statement at %C cannot appear within "
7831 : : "an IF-THEN block");
7832 : 0 : break;
7833 : 0 : case COMP_DO:
7834 : 0 : case COMP_DO_CONCURRENT:
7835 : 0 : gfc_error ("ENTRY statement at %C cannot appear within "
7836 : : "a DO block");
7837 : 0 : break;
7838 : 0 : case COMP_SELECT:
7839 : 0 : gfc_error ("ENTRY statement at %C cannot appear within "
7840 : : "a SELECT block");
7841 : 0 : break;
7842 : 0 : case COMP_FORALL:
7843 : 0 : gfc_error ("ENTRY statement at %C cannot appear within "
7844 : : "a FORALL block");
7845 : 0 : break;
7846 : 0 : case COMP_WHERE:
7847 : 0 : gfc_error ("ENTRY statement at %C cannot appear within "
7848 : : "a WHERE block");
7849 : 0 : break;
7850 : 0 : case COMP_CONTAINS:
7851 : 0 : gfc_error ("ENTRY statement at %C cannot appear within "
7852 : : "a contained subprogram");
7853 : 0 : break;
7854 : 2 : default:
7855 : 2 : gfc_error ("Unexpected ENTRY statement at %C");
7856 : : }
7857 : 3 : return MATCH_ERROR;
7858 : : }
7859 : :
7860 : 766 : if ((state == COMP_SUBROUTINE || state == COMP_FUNCTION)
7861 : 766 : && gfc_state_stack->previous->state == COMP_INTERFACE)
7862 : : {
7863 : 1 : gfc_error ("ENTRY statement at %C cannot appear within an INTERFACE");
7864 : 1 : return MATCH_ERROR;
7865 : : }
7866 : :
7867 : 1530 : module_procedure = gfc_current_ns->parent != NULL
7868 : 259 : && gfc_current_ns->parent->proc_name
7869 : 765 : && gfc_current_ns->parent->proc_name->attr.flavor
7870 : 259 : == FL_MODULE;
7871 : :
7872 : 765 : if (gfc_current_ns->parent != NULL
7873 : 259 : && gfc_current_ns->parent->proc_name
7874 : 259 : && !module_procedure)
7875 : : {
7876 : 0 : gfc_error("ENTRY statement at %C cannot appear in a "
7877 : : "contained procedure");
7878 : 0 : return MATCH_ERROR;
7879 : : }
7880 : :
7881 : : /* Module function entries need special care in get_proc_name
7882 : : because previous references within the function will have
7883 : : created symbols attached to the current namespace. */
7884 : 765 : if (get_proc_name (name, &entry,
7885 : : gfc_current_ns->parent != NULL
7886 : 765 : && module_procedure))
7887 : : return MATCH_ERROR;
7888 : :
7889 : 763 : proc = gfc_current_block ();
7890 : :
7891 : : /* Make sure that it isn't already declared as BIND(C). If it is, it
7892 : : must have been marked BIND(C) with a BIND(C) attribute and that is
7893 : : not allowed for procedures. */
7894 : 763 : if (entry->attr.is_bind_c == 1)
7895 : : {
7896 : 0 : locus loc;
7897 : :
7898 : 0 : entry->attr.is_bind_c = 0;
7899 : :
7900 : 0 : loc = entry->old_symbol != NULL
7901 : 0 : ? entry->old_symbol->declared_at : gfc_current_locus;
7902 : 0 : gfc_error_now ("BIND(C) attribute at %L can only be used for "
7903 : : "variables or common blocks", &loc);
7904 : : }
7905 : :
7906 : : /* Check what next non-whitespace character is so we can tell if there
7907 : : is the required parens if we have a BIND(C). */
7908 : 763 : old_loc = gfc_current_locus;
7909 : 763 : gfc_gobble_whitespace ();
7910 : 763 : peek_char = gfc_peek_ascii_char ();
7911 : :
7912 : 763 : if (state == COMP_SUBROUTINE)
7913 : : {
7914 : 134 : m = gfc_match_formal_arglist (entry, 0, 1);
7915 : 134 : if (m != MATCH_YES)
7916 : : return MATCH_ERROR;
7917 : :
7918 : : /* Call gfc_match_bind_c with allow_binding_name = true as ENTRY can
7919 : : never be an internal procedure. */
7920 : 134 : is_bind_c = gfc_match_bind_c (entry, true);
7921 : 134 : if (is_bind_c == MATCH_ERROR)
7922 : : return MATCH_ERROR;
7923 : 134 : if (is_bind_c == MATCH_YES)
7924 : : {
7925 : 22 : if (peek_char != '(')
7926 : : {
7927 : 0 : gfc_error ("Missing required parentheses before BIND(C) at %C");
7928 : 0 : return MATCH_ERROR;
7929 : : }
7930 : :
7931 : 22 : if (!gfc_add_is_bind_c (&(entry->attr), entry->name,
7932 : 22 : &(entry->declared_at), 1))
7933 : : return MATCH_ERROR;
7934 : :
7935 : : }
7936 : :
7937 : 134 : if (!gfc_current_ns->parent
7938 : 134 : && !add_global_entry (name, entry->binding_label, true,
7939 : : &old_loc))
7940 : : return MATCH_ERROR;
7941 : :
7942 : : /* An entry in a subroutine. */
7943 : 131 : if (!gfc_add_entry (&entry->attr, entry->name, NULL)
7944 : 131 : || !gfc_add_subroutine (&entry->attr, entry->name, NULL))
7945 : 3 : return MATCH_ERROR;
7946 : : }
7947 : : else
7948 : : {
7949 : : /* An entry in a function.
7950 : : We need to take special care because writing
7951 : : ENTRY f()
7952 : : as
7953 : : ENTRY f
7954 : : is allowed, whereas
7955 : : ENTRY f() RESULT (r)
7956 : : can't be written as
7957 : : ENTRY f RESULT (r). */
7958 : 629 : if (gfc_match_eos () == MATCH_YES)
7959 : : {
7960 : 24 : gfc_current_locus = old_loc;
7961 : : /* Match the empty argument list, and add the interface to
7962 : : the symbol. */
7963 : 24 : m = gfc_match_formal_arglist (entry, 0, 1);
7964 : : }
7965 : : else
7966 : 605 : m = gfc_match_formal_arglist (entry, 0, 0);
7967 : :
7968 : 629 : if (m != MATCH_YES)
7969 : : return MATCH_ERROR;
7970 : :
7971 : 628 : result = NULL;
7972 : :
7973 : 628 : if (gfc_match_eos () == MATCH_YES)
7974 : : {
7975 : 397 : if (!gfc_add_entry (&entry->attr, entry->name, NULL)
7976 : 397 : || !gfc_add_function (&entry->attr, entry->name, NULL))
7977 : 2 : return MATCH_ERROR;
7978 : :
7979 : 395 : entry->result = entry;
7980 : : }
7981 : : else
7982 : : {
7983 : 231 : m = gfc_match_suffix (entry, &result);
7984 : 231 : if (m == MATCH_NO)
7985 : 0 : gfc_syntax_error (ST_ENTRY);
7986 : 231 : if (m != MATCH_YES)
7987 : : return MATCH_ERROR;
7988 : :
7989 : 231 : if (result)
7990 : : {
7991 : 212 : if (!gfc_add_result (&result->attr, result->name, NULL)
7992 : 212 : || !gfc_add_entry (&entry->attr, result->name, NULL)
7993 : 424 : || !gfc_add_function (&entry->attr, result->name, NULL))
7994 : 0 : return MATCH_ERROR;
7995 : 212 : entry->result = result;
7996 : : }
7997 : : else
7998 : : {
7999 : 19 : if (!gfc_add_entry (&entry->attr, entry->name, NULL)
8000 : 19 : || !gfc_add_function (&entry->attr, entry->name, NULL))
8001 : 0 : return MATCH_ERROR;
8002 : 19 : entry->result = entry;
8003 : : }
8004 : : }
8005 : :
8006 : 626 : if (!gfc_current_ns->parent
8007 : 626 : && !add_global_entry (name, entry->binding_label, false,
8008 : : &old_loc))
8009 : : return MATCH_ERROR;
8010 : : }
8011 : :
8012 : 754 : if (gfc_match_eos () != MATCH_YES)
8013 : : {
8014 : 0 : gfc_syntax_error (ST_ENTRY);
8015 : 0 : return MATCH_ERROR;
8016 : : }
8017 : :
8018 : : /* F2018:C1546 An elemental procedure shall not have the BIND attribute. */
8019 : 754 : if (proc->attr.elemental && entry->attr.is_bind_c)
8020 : : {
8021 : 2 : gfc_error ("ENTRY statement at %L with BIND(C) prohibited in an "
8022 : : "elemental procedure", &entry->declared_at);
8023 : 2 : return MATCH_ERROR;
8024 : : }
8025 : :
8026 : 752 : entry->attr.recursive = proc->attr.recursive;
8027 : 752 : entry->attr.elemental = proc->attr.elemental;
8028 : 752 : entry->attr.pure = proc->attr.pure;
8029 : :
8030 : 752 : el = gfc_get_entry_list ();
8031 : 752 : el->sym = entry;
8032 : 752 : el->next = gfc_current_ns->entries;
8033 : 752 : gfc_current_ns->entries = el;
8034 : 752 : if (el->next)
8035 : 84 : el->id = el->next->id + 1;
8036 : : else
8037 : 668 : el->id = 1;
8038 : :
8039 : 752 : new_st.op = EXEC_ENTRY;
8040 : 752 : new_st.ext.entry = el;
8041 : :
8042 : 752 : return MATCH_YES;
8043 : : }
8044 : :
8045 : :
8046 : : /* Match a subroutine statement, including optional prefixes. */
8047 : :
8048 : : match
8049 : 761188 : gfc_match_subroutine (void)
8050 : : {
8051 : 761188 : char name[GFC_MAX_SYMBOL_LEN + 1];
8052 : 761188 : gfc_symbol *sym;
8053 : 761188 : match m;
8054 : 761188 : match is_bind_c;
8055 : 761188 : char peek_char;
8056 : 761188 : bool allow_binding_name;
8057 : 761188 : locus loc;
8058 : :
8059 : 761188 : if (gfc_current_state () != COMP_NONE
8060 : 721478 : && gfc_current_state () != COMP_INTERFACE
8061 : 701824 : && gfc_current_state () != COMP_CONTAINS)
8062 : : return MATCH_NO;
8063 : :
8064 : 98757 : m = gfc_match_prefix (NULL);
8065 : 98757 : if (m != MATCH_YES)
8066 : : return m;
8067 : :
8068 : 89542 : loc = gfc_current_locus;
8069 : 89542 : m = gfc_match ("subroutine% %n", name);
8070 : 89542 : if (m != MATCH_YES)
8071 : : return m;
8072 : :
8073 : 40437 : if (get_proc_name (name, &sym, false))
8074 : : return MATCH_ERROR;
8075 : :
8076 : : /* Set declared_at as it might point to, e.g., a PUBLIC statement, if
8077 : : the symbol existed before. */
8078 : 40426 : sym->declared_at = gfc_get_location_range (NULL, 0, &loc, 1,
8079 : : &gfc_current_locus);
8080 : :
8081 : 40426 : if (current_attr.module_procedure)
8082 : 361 : sym->attr.module_procedure = 1;
8083 : :
8084 : 40426 : if (add_hidden_procptr_result (sym))
8085 : 9 : sym = sym->result;
8086 : :
8087 : 40426 : gfc_new_block = sym;
8088 : :
8089 : : /* Check what next non-whitespace character is so we can tell if there
8090 : : is the required parens if we have a BIND(C). */
8091 : 40426 : gfc_gobble_whitespace ();
8092 : 40426 : peek_char = gfc_peek_ascii_char ();
8093 : :
8094 : 40426 : if (!gfc_add_subroutine (&sym->attr, sym->name, NULL))
8095 : : return MATCH_ERROR;
8096 : :
8097 : 40423 : if (gfc_match_formal_arglist (sym, 0, 1) != MATCH_YES)
8098 : : return MATCH_ERROR;
8099 : :
8100 : : /* Make sure that it isn't already declared as BIND(C). If it is, it
8101 : : must have been marked BIND(C) with a BIND(C) attribute and that is
8102 : : not allowed for procedures. */
8103 : 40423 : if (sym->attr.is_bind_c == 1)
8104 : : {
8105 : 4 : sym->attr.is_bind_c = 0;
8106 : :
8107 : 4 : if (gfc_state_stack->previous
8108 : 4 : && gfc_state_stack->previous->state != COMP_SUBMODULE)
8109 : : {
8110 : 2 : locus loc;
8111 : 2 : loc = sym->old_symbol != NULL
8112 : 2 : ? sym->old_symbol->declared_at : gfc_current_locus;
8113 : 2 : gfc_error_now ("BIND(C) attribute at %L can only be used for "
8114 : : "variables or common blocks", &loc);
8115 : : }
8116 : : }
8117 : :
8118 : : /* C binding names are not allowed for internal procedures. */
8119 : 40423 : if (gfc_current_state () == COMP_CONTAINS
8120 : 24938 : && sym->ns->proc_name->attr.flavor != FL_MODULE)
8121 : : allow_binding_name = false;
8122 : : else
8123 : 26061 : allow_binding_name = true;
8124 : :
8125 : : /* Here, we are just checking if it has the bind(c) attribute, and if
8126 : : so, then we need to make sure it's all correct. If it doesn't,
8127 : : we still need to continue matching the rest of the subroutine line. */
8128 : 40423 : gfc_gobble_whitespace ();
8129 : 40423 : loc = gfc_current_locus;
8130 : 40423 : is_bind_c = gfc_match_bind_c (sym, allow_binding_name);
8131 : 40423 : if (is_bind_c == MATCH_ERROR)
8132 : : {
8133 : : /* There was an attempt at the bind(c), but it was wrong. An
8134 : : error message should have been printed w/in the gfc_match_bind_c
8135 : : so here we'll just return the MATCH_ERROR. */
8136 : : return MATCH_ERROR;
8137 : : }
8138 : :
8139 : 40410 : if (is_bind_c == MATCH_YES)
8140 : : {
8141 : 3387 : gfc_formal_arglist *arg;
8142 : :
8143 : : /* The following is allowed in the Fortran 2008 draft. */
8144 : 3387 : if (gfc_current_state () == COMP_CONTAINS
8145 : 1292 : && sym->ns->proc_name->attr.flavor != FL_MODULE
8146 : 3797 : && !gfc_notify_std (GFC_STD_F2008, "BIND(C) attribute "
8147 : : "at %L may not be specified for an internal "
8148 : : "procedure", &gfc_current_locus))
8149 : : return MATCH_ERROR;
8150 : :
8151 : 3384 : if (peek_char != '(')
8152 : : {
8153 : 1 : gfc_error ("Missing required parentheses before BIND(C) at %C");
8154 : 1 : return MATCH_ERROR;
8155 : : }
8156 : :
8157 : : /* F2018 C1550 (R1526) If MODULE appears in the prefix of a module
8158 : : subprogram and a binding label is specified, it shall be the
8159 : : same as the binding label specified in the corresponding module
8160 : : procedure interface body. */
8161 : 3383 : if (sym->attr.module_procedure && sym->old_symbol
8162 : 3 : && strcmp (sym->name, sym->old_symbol->name) == 0
8163 : 3 : && sym->binding_label && sym->old_symbol->binding_label
8164 : 2 : && strcmp (sym->binding_label, sym->old_symbol->binding_label) != 0)
8165 : : {
8166 : 1 : const char *null = "NULL", *s1, *s2;
8167 : 1 : s1 = sym->binding_label;
8168 : 1 : if (!s1) s1 = null;
8169 : 1 : s2 = sym->old_symbol->binding_label;
8170 : 1 : if (!s2) s2 = null;
8171 : 1 : gfc_error ("Mismatch in BIND(C) names (%qs/%qs) at %C", s1, s2);
8172 : 1 : sym->refs++; /* Needed to avoid an ICE in gfc_release_symbol */
8173 : 1 : return MATCH_ERROR;
8174 : : }
8175 : :
8176 : : /* Scan the dummy arguments for an alternate return. */
8177 : 10495 : for (arg = sym->formal; arg; arg = arg->next)
8178 : 7114 : if (!arg->sym)
8179 : : {
8180 : 1 : gfc_error ("Alternate return dummy argument cannot appear in a "
8181 : : "SUBROUTINE with the BIND(C) attribute at %L", &loc);
8182 : 1 : return MATCH_ERROR;
8183 : : }
8184 : :
8185 : 3381 : if (!gfc_add_is_bind_c (&(sym->attr), sym->name, &(sym->declared_at), 1))
8186 : : return MATCH_ERROR;
8187 : : }
8188 : :
8189 : 40403 : if (gfc_match_eos () != MATCH_YES)
8190 : : {
8191 : 1 : gfc_syntax_error (ST_SUBROUTINE);
8192 : 1 : return MATCH_ERROR;
8193 : : }
8194 : :
8195 : 40402 : if (!copy_prefix (&sym->attr, &sym->declared_at))
8196 : : {
8197 : 4 : if(!sym->attr.module_procedure)
8198 : : return MATCH_ERROR;
8199 : : else
8200 : 3 : gfc_error_check ();
8201 : : }
8202 : :
8203 : : /* Warn if it has the same name as an intrinsic. */
8204 : 40401 : do_warn_intrinsic_shadow (sym, false);
8205 : :
8206 : 40401 : return MATCH_YES;
8207 : : }
8208 : :
8209 : :
8210 : : /* Check that the NAME identifier in a BIND attribute or statement
8211 : : is conform to C identifier rules. */
8212 : :
8213 : : match
8214 : 1152 : check_bind_name_identifier (char **name)
8215 : : {
8216 : 1152 : char *n = *name, *p;
8217 : :
8218 : : /* Remove leading spaces. */
8219 : 1178 : while (*n == ' ')
8220 : 26 : n++;
8221 : :
8222 : : /* On an empty string, free memory and set name to NULL. */
8223 : 1152 : if (*n == '\0')
8224 : : {
8225 : 42 : free (*name);
8226 : 42 : *name = NULL;
8227 : 42 : return MATCH_YES;
8228 : : }
8229 : :
8230 : : /* Remove trailing spaces. */
8231 : 1110 : p = n + strlen(n) - 1;
8232 : 1126 : while (*p == ' ')
8233 : 16 : *(p--) = '\0';
8234 : :
8235 : : /* Insert the identifier into the symbol table. */
8236 : 1110 : p = xstrdup (n);
8237 : 1110 : free (*name);
8238 : 1110 : *name = p;
8239 : :
8240 : : /* Now check that identifier is valid under C rules. */
8241 : 1110 : if (ISDIGIT (*p))
8242 : : {
8243 : 2 : gfc_error ("Invalid C identifier in NAME= specifier at %C");
8244 : 2 : return MATCH_ERROR;
8245 : : }
8246 : :
8247 : 12118 : for (; *p; p++)
8248 : 11013 : if (!(ISALNUM (*p) || *p == '_' || *p == '$'))
8249 : : {
8250 : 3 : gfc_error ("Invalid C identifier in NAME= specifier at %C");
8251 : 3 : return MATCH_ERROR;
8252 : : }
8253 : :
8254 : : return MATCH_YES;
8255 : : }
8256 : :
8257 : :
8258 : : /* Match a BIND(C) specifier, with the optional 'name=' specifier if
8259 : : given, and set the binding label in either the given symbol (if not
8260 : : NULL), or in the current_ts. The symbol may be NULL because we may
8261 : : encounter the BIND(C) before the declaration itself. Return
8262 : : MATCH_NO if what we're looking at isn't a BIND(C) specifier,
8263 : : MATCH_ERROR if it is a BIND(C) clause but an error was encountered,
8264 : : or MATCH_YES if the specifier was correct and the binding label and
8265 : : bind(c) fields were set correctly for the given symbol or the
8266 : : current_ts. If allow_binding_name is false, no binding name may be
8267 : : given. */
8268 : :
8269 : : match
8270 : 48411 : gfc_match_bind_c (gfc_symbol *sym, bool allow_binding_name)
8271 : : {
8272 : 48411 : char *binding_label = NULL;
8273 : 48411 : gfc_expr *e = NULL;
8274 : :
8275 : : /* Initialize the flag that specifies whether we encountered a NAME=
8276 : : specifier or not. */
8277 : 48411 : has_name_equals = 0;
8278 : :
8279 : : /* This much we have to be able to match, in this order, if
8280 : : there is a bind(c) label. */
8281 : 48411 : if (gfc_match (" bind ( c ") != MATCH_YES)
8282 : : return MATCH_NO;
8283 : :
8284 : : /* Now see if there is a binding label, or if we've reached the
8285 : : end of the bind(c) attribute without one. */
8286 : 6147 : if (gfc_match_char (',') == MATCH_YES)
8287 : : {
8288 : 1159 : if (gfc_match (" name = ") != MATCH_YES)
8289 : : {
8290 : 1 : gfc_error ("Syntax error in NAME= specifier for binding label "
8291 : : "at %C");
8292 : : /* should give an error message here */
8293 : 1 : return MATCH_ERROR;
8294 : : }
8295 : :
8296 : 1158 : has_name_equals = 1;
8297 : :
8298 : 1158 : if (gfc_match_init_expr (&e) != MATCH_YES)
8299 : : {
8300 : 2 : gfc_free_expr (e);
8301 : 2 : return MATCH_ERROR;
8302 : : }
8303 : :
8304 : 1156 : if (!gfc_simplify_expr(e, 0))
8305 : : {
8306 : 0 : gfc_error ("NAME= specifier at %C should be a constant expression");
8307 : 0 : gfc_free_expr (e);
8308 : 0 : return MATCH_ERROR;
8309 : : }
8310 : :
8311 : 1156 : if (e->expr_type != EXPR_CONSTANT || e->ts.type != BT_CHARACTER
8312 : 1153 : || e->ts.kind != gfc_default_character_kind || e->rank != 0)
8313 : : {
8314 : 4 : gfc_error ("NAME= specifier at %C should be a scalar of "
8315 : : "default character kind");
8316 : 4 : gfc_free_expr(e);
8317 : 4 : return MATCH_ERROR;
8318 : : }
8319 : :
8320 : : // Get a C string from the Fortran string constant
8321 : 2304 : binding_label = gfc_widechar_to_char (e->value.character.string,
8322 : 1152 : e->value.character.length);
8323 : 1152 : gfc_free_expr(e);
8324 : :
8325 : : // Check that it is valid (old gfc_match_name_C)
8326 : 1152 : if (check_bind_name_identifier (&binding_label) != MATCH_YES)
8327 : : return MATCH_ERROR;
8328 : : }
8329 : :
8330 : : /* Get the required right paren. */
8331 : 6135 : if (gfc_match_char (')') != MATCH_YES)
8332 : : {
8333 : 1 : gfc_error ("Missing closing paren for binding label at %C");
8334 : 1 : return MATCH_ERROR;
8335 : : }
8336 : :
8337 : 6134 : if (has_name_equals && !allow_binding_name)
8338 : : {
8339 : 6 : gfc_error ("No binding name is allowed in BIND(C) at %C");
8340 : 6 : return MATCH_ERROR;
8341 : : }
8342 : :
8343 : 6128 : if (has_name_equals && sym != NULL && sym->attr.dummy)
8344 : : {
8345 : 2 : gfc_error ("For dummy procedure %s, no binding name is "
8346 : : "allowed in BIND(C) at %C", sym->name);
8347 : 2 : return MATCH_ERROR;
8348 : : }
8349 : :
8350 : :
8351 : : /* Save the binding label to the symbol. If sym is null, we're
8352 : : probably matching the typespec attributes of a declaration and
8353 : : haven't gotten the name yet, and therefore, no symbol yet. */
8354 : 6126 : if (binding_label)
8355 : : {
8356 : 1098 : if (sym != NULL)
8357 : 990 : sym->binding_label = binding_label;
8358 : : else
8359 : 108 : curr_binding_label = binding_label;
8360 : : }
8361 : 5028 : else if (allow_binding_name)
8362 : : {
8363 : : /* No binding label, but if symbol isn't null, we
8364 : : can set the label for it here.
8365 : : If name="" or allow_binding_name is false, no C binding name is
8366 : : created. */
8367 : 4606 : if (sym != NULL && sym->name != NULL && has_name_equals == 0)
8368 : 4439 : sym->binding_label = IDENTIFIER_POINTER (get_identifier (sym->name));
8369 : : }
8370 : :
8371 : 6126 : if (has_name_equals && gfc_current_state () == COMP_INTERFACE
8372 : 709 : && current_interface.type == INTERFACE_ABSTRACT)
8373 : : {
8374 : 1 : gfc_error ("NAME not allowed on BIND(C) for ABSTRACT INTERFACE at %C");
8375 : 1 : return MATCH_ERROR;
8376 : : }
8377 : :
8378 : : return MATCH_YES;
8379 : : }
8380 : :
8381 : :
8382 : : /* Return nonzero if we're currently compiling a contained procedure. */
8383 : :
8384 : : static int
8385 : 58909 : contained_procedure (void)
8386 : : {
8387 : 58909 : gfc_state_data *s = gfc_state_stack;
8388 : :
8389 : 58909 : if ((s->state == COMP_SUBROUTINE || s->state == COMP_FUNCTION)
8390 : 58064 : && s->previous != NULL && s->previous->state == COMP_CONTAINS)
8391 : 34687 : return 1;
8392 : :
8393 : : return 0;
8394 : : }
8395 : :
8396 : : /* Set the kind of each enumerator. The kind is selected such that it is
8397 : : interoperable with the corresponding C enumeration type, making
8398 : : sure that -fshort-enums is honored. */
8399 : :
8400 : : static void
8401 : 158 : set_enum_kind(void)
8402 : : {
8403 : 158 : enumerator_history *current_history = NULL;
8404 : 158 : int kind;
8405 : 158 : int i;
8406 : :
8407 : 158 : if (max_enum == NULL || enum_history == NULL)
8408 : : return;
8409 : :
8410 : 150 : if (!flag_short_enums)
8411 : : return;
8412 : :
8413 : : i = 0;
8414 : 48 : do
8415 : : {
8416 : 48 : kind = gfc_integer_kinds[i++].kind;
8417 : : }
8418 : 48 : while (kind < gfc_c_int_kind
8419 : 72 : && gfc_check_integer_range (max_enum->initializer->value.integer,
8420 : : kind) != ARITH_OK);
8421 : :
8422 : 24 : current_history = enum_history;
8423 : 96 : while (current_history != NULL)
8424 : : {
8425 : 72 : current_history->sym->ts.kind = kind;
8426 : 72 : current_history = current_history->next;
8427 : : }
8428 : : }
8429 : :
8430 : :
8431 : : /* Match any of the various end-block statements. Returns the type of
8432 : : END to the caller. The END INTERFACE, END IF, END DO, END SELECT
8433 : : and END BLOCK statements cannot be replaced by a single END statement. */
8434 : :
8435 : : match
8436 : 174348 : gfc_match_end (gfc_statement *st)
8437 : : {
8438 : 174348 : char name[GFC_MAX_SYMBOL_LEN + 1];
8439 : 174348 : gfc_compile_state state;
8440 : 174348 : locus old_loc;
8441 : 174348 : const char *block_name;
8442 : 174348 : const char *target;
8443 : 174348 : int eos_ok;
8444 : 174348 : match m;
8445 : 174348 : gfc_namespace *parent_ns, *ns, *prev_ns;
8446 : 174348 : gfc_namespace **nsp;
8447 : 174348 : bool abbreviated_modproc_decl = false;
8448 : 174348 : bool got_matching_end = false;
8449 : :
8450 : 174348 : old_loc = gfc_current_locus;
8451 : 174348 : if (gfc_match ("end") != MATCH_YES)
8452 : : return MATCH_NO;
8453 : :
8454 : 169359 : state = gfc_current_state ();
8455 : 338718 : block_name = gfc_current_block () == NULL
8456 : 169359 : ? NULL : gfc_current_block ()->name;
8457 : :
8458 : 169359 : switch (state)
8459 : : {
8460 : 2542 : case COMP_ASSOCIATE:
8461 : 2542 : case COMP_BLOCK:
8462 : 2542 : if (startswith (block_name, "block@"))
8463 : : block_name = NULL;
8464 : : break;
8465 : :
8466 : 16356 : case COMP_CONTAINS:
8467 : 16356 : case COMP_DERIVED_CONTAINS:
8468 : 16356 : case COMP_OMP_BEGIN_METADIRECTIVE:
8469 : 16356 : state = gfc_state_stack->previous->state;
8470 : 32712 : block_name = gfc_state_stack->previous->sym == NULL
8471 : 16356 : ? NULL : gfc_state_stack->previous->sym->name;
8472 : 16356 : abbreviated_modproc_decl = gfc_state_stack->previous->sym
8473 : 16356 : && gfc_state_stack->previous->sym->abr_modproc_decl;
8474 : : break;
8475 : :
8476 : : case COMP_OMP_METADIRECTIVE:
8477 : : {
8478 : : /* Metadirectives can be nested, so we need to drill down to the
8479 : : first state that is not COMP_OMP_METADIRECTIVE. */
8480 : : gfc_state_data *state_data = gfc_state_stack;
8481 : :
8482 : 71 : do
8483 : : {
8484 : 71 : state_data = state_data->previous;
8485 : 71 : state = state_data->state;
8486 : 142 : block_name = (state_data->sym == NULL
8487 : 71 : ? NULL : state_data->sym->name);
8488 : 142 : abbreviated_modproc_decl = (state_data->sym
8489 : 71 : && state_data->sym->abr_modproc_decl);
8490 : : }
8491 : 71 : while (state == COMP_OMP_METADIRECTIVE);
8492 : :
8493 : 69 : if (block_name && startswith (block_name, "block@"))
8494 : : block_name = NULL;
8495 : : }
8496 : : break;
8497 : :
8498 : : default:
8499 : : break;
8500 : : }
8501 : :
8502 : 69 : if (!abbreviated_modproc_decl)
8503 : 169358 : abbreviated_modproc_decl = gfc_current_block ()
8504 : 169358 : && gfc_current_block ()->abr_modproc_decl;
8505 : :
8506 : 169359 : switch (state)
8507 : : {
8508 : 26737 : case COMP_NONE:
8509 : 26737 : case COMP_PROGRAM:
8510 : 26737 : *st = ST_END_PROGRAM;
8511 : 26737 : target = " program";
8512 : 26737 : eos_ok = 1;
8513 : 26737 : break;
8514 : :
8515 : 40571 : case COMP_SUBROUTINE:
8516 : 40571 : *st = ST_END_SUBROUTINE;
8517 : 40571 : if (!abbreviated_modproc_decl)
8518 : : target = " subroutine";
8519 : : else
8520 : 133 : target = " procedure";
8521 : 40571 : eos_ok = !contained_procedure ();
8522 : 40571 : break;
8523 : :
8524 : 18338 : case COMP_FUNCTION:
8525 : 18338 : *st = ST_END_FUNCTION;
8526 : 18338 : if (!abbreviated_modproc_decl)
8527 : : target = " function";
8528 : : else
8529 : 59 : target = " procedure";
8530 : 18338 : eos_ok = !contained_procedure ();
8531 : 18338 : break;
8532 : :
8533 : 84 : case COMP_BLOCK_DATA:
8534 : 84 : *st = ST_END_BLOCK_DATA;
8535 : 84 : target = " block data";
8536 : 84 : eos_ok = 1;
8537 : 84 : break;
8538 : :
8539 : 9206 : case COMP_MODULE:
8540 : 9206 : *st = ST_END_MODULE;
8541 : 9206 : target = " module";
8542 : 9206 : eos_ok = 1;
8543 : 9206 : break;
8544 : :
8545 : 205 : case COMP_SUBMODULE:
8546 : 205 : *st = ST_END_SUBMODULE;
8547 : 205 : target = " submodule";
8548 : 205 : eos_ok = 1;
8549 : 205 : break;
8550 : :
8551 : 9547 : case COMP_INTERFACE:
8552 : 9547 : *st = ST_END_INTERFACE;
8553 : 9547 : target = " interface";
8554 : 9547 : eos_ok = 0;
8555 : 9547 : break;
8556 : :
8557 : 257 : case COMP_MAP:
8558 : 257 : *st = ST_END_MAP;
8559 : 257 : target = " map";
8560 : 257 : eos_ok = 0;
8561 : 257 : break;
8562 : :
8563 : 132 : case COMP_UNION:
8564 : 132 : *st = ST_END_UNION;
8565 : 132 : target = " union";
8566 : 132 : eos_ok = 0;
8567 : 132 : break;
8568 : :
8569 : 313 : case COMP_STRUCTURE:
8570 : 313 : *st = ST_END_STRUCTURE;
8571 : 313 : target = " structure";
8572 : 313 : eos_ok = 0;
8573 : 313 : break;
8574 : :
8575 : 11855 : case COMP_DERIVED:
8576 : 11855 : case COMP_DERIVED_CONTAINS:
8577 : 11855 : *st = ST_END_TYPE;
8578 : 11855 : target = " type";
8579 : 11855 : eos_ok = 0;
8580 : 11855 : break;
8581 : :
8582 : 1294 : case COMP_ASSOCIATE:
8583 : 1294 : *st = ST_END_ASSOCIATE;
8584 : 1294 : target = " associate";
8585 : 1294 : eos_ok = 0;
8586 : 1294 : break;
8587 : :
8588 : 1278 : case COMP_BLOCK:
8589 : 1278 : case COMP_OMP_STRICTLY_STRUCTURED_BLOCK:
8590 : 1278 : *st = ST_END_BLOCK;
8591 : 1278 : target = " block";
8592 : 1278 : eos_ok = 0;
8593 : 1278 : break;
8594 : :
8595 : 14141 : case COMP_IF:
8596 : 14141 : *st = ST_ENDIF;
8597 : 14141 : target = " if";
8598 : 14141 : eos_ok = 0;
8599 : 14141 : break;
8600 : :
8601 : 29901 : case COMP_DO:
8602 : 29901 : case COMP_DO_CONCURRENT:
8603 : 29901 : *st = ST_ENDDO;
8604 : 29901 : target = " do";
8605 : 29901 : eos_ok = 0;
8606 : 29901 : break;
8607 : :
8608 : 35 : case COMP_CRITICAL:
8609 : 35 : *st = ST_END_CRITICAL;
8610 : 35 : target = " critical";
8611 : 35 : eos_ok = 0;
8612 : 35 : break;
8613 : :
8614 : 4419 : case COMP_SELECT:
8615 : 4419 : case COMP_SELECT_TYPE:
8616 : 4419 : case COMP_SELECT_RANK:
8617 : 4419 : *st = ST_END_SELECT;
8618 : 4419 : target = " select";
8619 : 4419 : eos_ok = 0;
8620 : 4419 : break;
8621 : :
8622 : 506 : case COMP_FORALL:
8623 : 506 : *st = ST_END_FORALL;
8624 : 506 : target = " forall";
8625 : 506 : eos_ok = 0;
8626 : 506 : break;
8627 : :
8628 : 373 : case COMP_WHERE:
8629 : 373 : *st = ST_END_WHERE;
8630 : 373 : target = " where";
8631 : 373 : eos_ok = 0;
8632 : 373 : break;
8633 : :
8634 : 158 : case COMP_ENUM:
8635 : 158 : *st = ST_END_ENUM;
8636 : 158 : target = " enum";
8637 : 158 : eos_ok = 0;
8638 : 158 : last_initializer = NULL;
8639 : 158 : set_enum_kind ();
8640 : 158 : gfc_free_enum_history ();
8641 : 158 : break;
8642 : :
8643 : 0 : case COMP_OMP_BEGIN_METADIRECTIVE:
8644 : 0 : *st = ST_OMP_END_METADIRECTIVE;
8645 : 0 : target = " metadirective";
8646 : 0 : eos_ok = 0;
8647 : 0 : break;
8648 : :
8649 : 9 : default:
8650 : 9 : gfc_error ("Unexpected END statement at %C");
8651 : 9 : goto cleanup;
8652 : : }
8653 : :
8654 : 169350 : old_loc = gfc_current_locus;
8655 : 169350 : if (gfc_match_eos () == MATCH_YES)
8656 : : {
8657 : 19430 : if (!eos_ok && (*st == ST_END_SUBROUTINE || *st == ST_END_FUNCTION))
8658 : : {
8659 : 7493 : if (!gfc_notify_std (GFC_STD_F2008, "END statement "
8660 : : "instead of %s statement at %L",
8661 : : abbreviated_modproc_decl ? "END PROCEDURE"
8662 : 3746 : : gfc_ascii_statement(*st), &old_loc))
8663 : 4 : goto cleanup;
8664 : : }
8665 : 7 : else if (!eos_ok)
8666 : : {
8667 : : /* We would have required END [something]. */
8668 : 7 : gfc_error ("%s statement expected at %L",
8669 : : gfc_ascii_statement (*st), &old_loc);
8670 : 7 : goto cleanup;
8671 : : }
8672 : :
8673 : 19419 : return MATCH_YES;
8674 : : }
8675 : :
8676 : : /* Verify that we've got the sort of end-block that we're expecting. */
8677 : 149920 : if (gfc_match (target) != MATCH_YES)
8678 : : {
8679 : 303 : gfc_error ("Expecting %s statement at %L", abbreviated_modproc_decl
8680 : 151 : ? "END PROCEDURE" : gfc_ascii_statement(*st), &old_loc);
8681 : 152 : goto cleanup;
8682 : : }
8683 : : else
8684 : 149768 : got_matching_end = true;
8685 : :
8686 : 149768 : old_loc = gfc_current_locus;
8687 : : /* If we're at the end, make sure a block name wasn't required. */
8688 : 149768 : if (gfc_match_eos () == MATCH_YES)
8689 : : {
8690 : :
8691 : 98623 : if (*st != ST_ENDDO && *st != ST_ENDIF && *st != ST_END_SELECT
8692 : : && *st != ST_END_FORALL && *st != ST_END_WHERE && *st != ST_END_BLOCK
8693 : : && *st != ST_END_ASSOCIATE && *st != ST_END_CRITICAL)
8694 : : return MATCH_YES;
8695 : :
8696 : 51465 : if (!block_name)
8697 : : return MATCH_YES;
8698 : :
8699 : 7 : gfc_error ("Expected block name of %qs in %s statement at %L",
8700 : : block_name, gfc_ascii_statement (*st), &old_loc);
8701 : :
8702 : 7 : return MATCH_ERROR;
8703 : : }
8704 : :
8705 : : /* END INTERFACE has a special handler for its several possible endings. */
8706 : 51145 : if (*st == ST_END_INTERFACE)
8707 : 562 : return gfc_match_end_interface ();
8708 : :
8709 : : /* We haven't hit the end of statement, so what is left must be an
8710 : : end-name. */
8711 : 50583 : m = gfc_match_space ();
8712 : 50583 : if (m == MATCH_YES)
8713 : 50583 : m = gfc_match_name (name);
8714 : :
8715 : 50583 : if (m == MATCH_NO)
8716 : 0 : gfc_error ("Expected terminating name at %C");
8717 : 50583 : if (m != MATCH_YES)
8718 : 0 : goto cleanup;
8719 : :
8720 : 50583 : if (block_name == NULL)
8721 : 15 : goto syntax;
8722 : :
8723 : : /* We have to pick out the declared submodule name from the composite
8724 : : required by F2008:11.2.3 para 2, which ends in the declared name. */
8725 : 50568 : if (state == COMP_SUBMODULE)
8726 : 113 : block_name = strchr (block_name, '.') + 1;
8727 : :
8728 : 50568 : if (strcmp (name, block_name) != 0 && strcmp (block_name, "ppr@") != 0)
8729 : : {
8730 : 8 : gfc_error ("Expected label %qs for %s statement at %C", block_name,
8731 : : gfc_ascii_statement (*st));
8732 : 8 : goto cleanup;
8733 : : }
8734 : : /* Procedure pointer as function result. */
8735 : 50560 : else if (strcmp (block_name, "ppr@") == 0
8736 : 21 : && strcmp (name, gfc_current_block ()->ns->proc_name->name) != 0)
8737 : : {
8738 : 0 : gfc_error ("Expected label %qs for %s statement at %C",
8739 : 0 : gfc_current_block ()->ns->proc_name->name,
8740 : : gfc_ascii_statement (*st));
8741 : 0 : goto cleanup;
8742 : : }
8743 : :
8744 : 50560 : if (gfc_match_eos () == MATCH_YES)
8745 : : return MATCH_YES;
8746 : :
8747 : 0 : syntax:
8748 : 15 : gfc_syntax_error (*st);
8749 : :
8750 : 195 : cleanup:
8751 : 195 : gfc_current_locus = old_loc;
8752 : :
8753 : : /* If we are missing an END BLOCK, we created a half-ready namespace.
8754 : : Remove it from the parent namespace's sibling list. */
8755 : :
8756 : 203 : while (state == COMP_BLOCK && !got_matching_end)
8757 : : {
8758 : 8 : parent_ns = gfc_current_ns->parent;
8759 : :
8760 : 8 : nsp = &(gfc_state_stack->previous->tail->ext.block.ns);
8761 : :
8762 : 8 : prev_ns = NULL;
8763 : 8 : ns = *nsp;
8764 : 16 : while (ns)
8765 : : {
8766 : 8 : if (ns == gfc_current_ns)
8767 : : {
8768 : 8 : if (prev_ns == NULL)
8769 : 8 : *nsp = NULL;
8770 : : else
8771 : 0 : prev_ns->sibling = ns->sibling;
8772 : : }
8773 : 8 : prev_ns = ns;
8774 : 8 : ns = ns->sibling;
8775 : : }
8776 : :
8777 : 8 : gfc_free_namespace (gfc_current_ns);
8778 : 8 : gfc_current_ns = parent_ns;
8779 : 8 : gfc_state_stack = gfc_state_stack->previous;
8780 : 8 : state = gfc_current_state ();
8781 : : }
8782 : :
8783 : : return MATCH_ERROR;
8784 : : }
8785 : :
8786 : :
8787 : :
8788 : : /***************** Attribute declaration statements ****************/
8789 : :
8790 : : /* Set the attribute of a single variable. */
8791 : :
8792 : : static match
8793 : 10213 : attr_decl1 (void)
8794 : : {
8795 : 10213 : char name[GFC_MAX_SYMBOL_LEN + 1];
8796 : 10213 : gfc_array_spec *as;
8797 : :
8798 : : /* Workaround -Wmaybe-uninitialized false positive during
8799 : : profiledbootstrap by initializing them. */
8800 : 10213 : gfc_symbol *sym = NULL;
8801 : 10213 : locus var_locus;
8802 : 10213 : match m;
8803 : :
8804 : 10213 : as = NULL;
8805 : :
8806 : 10213 : m = gfc_match_name (name);
8807 : 10213 : if (m != MATCH_YES)
8808 : 0 : goto cleanup;
8809 : :
8810 : 10213 : if (find_special (name, &sym, false))
8811 : : return MATCH_ERROR;
8812 : :
8813 : 10213 : if (!check_function_name (name))
8814 : : {
8815 : 7 : m = MATCH_ERROR;
8816 : 7 : goto cleanup;
8817 : : }
8818 : :
8819 : 10206 : var_locus = gfc_current_locus;
8820 : :
8821 : : /* Deal with possible array specification for certain attributes. */
8822 : 10206 : if (current_attr.dimension
8823 : : || current_attr.codimension
8824 : : || current_attr.allocatable
8825 : : || current_attr.pointer
8826 : 10206 : || current_attr.target)
8827 : : {
8828 : 5896 : m = gfc_match_array_spec (&as, !current_attr.codimension,
8829 : : !current_attr.dimension
8830 : : && !current_attr.pointer
8831 : 2948 : && !current_attr.target);
8832 : 2948 : if (m == MATCH_ERROR)
8833 : 2 : goto cleanup;
8834 : :
8835 : 2946 : if (current_attr.dimension && m == MATCH_NO)
8836 : : {
8837 : 0 : gfc_error ("Missing array specification at %L in DIMENSION "
8838 : : "statement", &var_locus);
8839 : 0 : m = MATCH_ERROR;
8840 : 0 : goto cleanup;
8841 : : }
8842 : :
8843 : 2946 : if (current_attr.dimension && sym->value)
8844 : : {
8845 : 1 : gfc_error ("Dimensions specified for %s at %L after its "
8846 : : "initialization", sym->name, &var_locus);
8847 : 1 : m = MATCH_ERROR;
8848 : 1 : goto cleanup;
8849 : : }
8850 : :
8851 : 2945 : if (current_attr.codimension && m == MATCH_NO)
8852 : : {
8853 : 0 : gfc_error ("Missing array specification at %L in CODIMENSION "
8854 : : "statement", &var_locus);
8855 : 0 : m = MATCH_ERROR;
8856 : 0 : goto cleanup;
8857 : : }
8858 : :
8859 : 2945 : if ((current_attr.allocatable || current_attr.pointer)
8860 : 1128 : && (m == MATCH_YES) && (as->type != AS_DEFERRED))
8861 : : {
8862 : 0 : gfc_error ("Array specification must be deferred at %L", &var_locus);
8863 : 0 : m = MATCH_ERROR;
8864 : 0 : goto cleanup;
8865 : : }
8866 : : }
8867 : :
8868 : 10203 : if (sym->ts.type == BT_CLASS
8869 : 200 : && sym->ts.u.derived
8870 : 200 : && sym->ts.u.derived->attr.is_class)
8871 : : {
8872 : 177 : sym->attr.pointer = CLASS_DATA(sym)->attr.class_pointer;
8873 : 177 : sym->attr.allocatable = CLASS_DATA(sym)->attr.allocatable;
8874 : 177 : sym->attr.dimension = CLASS_DATA(sym)->attr.dimension;
8875 : 177 : sym->attr.codimension = CLASS_DATA(sym)->attr.codimension;
8876 : 177 : if (CLASS_DATA (sym)->as)
8877 : 123 : sym->as = gfc_copy_array_spec (CLASS_DATA (sym)->as);
8878 : : }
8879 : 10203 : if (current_attr.dimension == 0 && current_attr.codimension == 0
8880 : 10203 : && !gfc_copy_attr (&sym->attr, ¤t_attr, &var_locus))
8881 : : {
8882 : 22 : m = MATCH_ERROR;
8883 : 22 : goto cleanup;
8884 : : }
8885 : 10181 : if (!gfc_set_array_spec (sym, as, &var_locus))
8886 : : {
8887 : 18 : m = MATCH_ERROR;
8888 : 18 : goto cleanup;
8889 : : }
8890 : :
8891 : 10163 : if (sym->attr.cray_pointee && sym->as != NULL)
8892 : : {
8893 : : /* Fix the array spec. */
8894 : 2 : m = gfc_mod_pointee_as (sym->as);
8895 : 2 : if (m == MATCH_ERROR)
8896 : 0 : goto cleanup;
8897 : : }
8898 : :
8899 : 10163 : if (!gfc_add_attribute (&sym->attr, &var_locus))
8900 : : {
8901 : 0 : m = MATCH_ERROR;
8902 : 0 : goto cleanup;
8903 : : }
8904 : :
8905 : 10163 : if ((current_attr.external || current_attr.intrinsic)
8906 : 6101 : && sym->attr.flavor != FL_PROCEDURE
8907 : 16232 : && !gfc_add_flavor (&sym->attr, FL_PROCEDURE, sym->name, NULL))
8908 : : {
8909 : 0 : m = MATCH_ERROR;
8910 : 0 : goto cleanup;
8911 : : }
8912 : :
8913 : 10163 : if (sym->ts.type == BT_CLASS && sym->ts.u.derived->attr.is_class
8914 : 169 : && !as && !current_attr.pointer && !current_attr.allocatable
8915 : 151 : && !current_attr.external)
8916 : : {
8917 : 136 : sym->attr.pointer = 0;
8918 : 136 : sym->attr.allocatable = 0;
8919 : 136 : sym->attr.dimension = 0;
8920 : 136 : sym->attr.codimension = 0;
8921 : 136 : gfc_free_array_spec (sym->as);
8922 : 136 : sym->as = NULL;
8923 : : }
8924 : 10027 : else if (sym->ts.type == BT_CLASS
8925 : 10027 : && !gfc_build_class_symbol (&sym->ts, &sym->attr, &sym->as))
8926 : : {
8927 : 0 : m = MATCH_ERROR;
8928 : 0 : goto cleanup;
8929 : : }
8930 : :
8931 : 10163 : add_hidden_procptr_result (sym);
8932 : :
8933 : 10163 : return MATCH_YES;
8934 : :
8935 : 50 : cleanup:
8936 : 50 : gfc_free_array_spec (as);
8937 : 50 : return m;
8938 : : }
8939 : :
8940 : :
8941 : : /* Generic attribute declaration subroutine. Used for attributes that
8942 : : just have a list of names. */
8943 : :
8944 : : static match
8945 : 6553 : attr_decl (void)
8946 : : {
8947 : 6553 : match m;
8948 : :
8949 : : /* Gobble the optional double colon, by simply ignoring the result
8950 : : of gfc_match(). */
8951 : 6553 : gfc_match (" ::");
8952 : :
8953 : 10213 : for (;;)
8954 : : {
8955 : 10213 : m = attr_decl1 ();
8956 : 10213 : if (m != MATCH_YES)
8957 : : break;
8958 : :
8959 : 10163 : if (gfc_match_eos () == MATCH_YES)
8960 : : {
8961 : : m = MATCH_YES;
8962 : : break;
8963 : : }
8964 : :
8965 : 3660 : if (gfc_match_char (',') != MATCH_YES)
8966 : : {
8967 : 0 : gfc_error ("Unexpected character in variable list at %C");
8968 : 0 : m = MATCH_ERROR;
8969 : 0 : break;
8970 : : }
8971 : : }
8972 : :
8973 : 6553 : return m;
8974 : : }
8975 : :
8976 : :
8977 : : /* This routine matches Cray Pointer declarations of the form:
8978 : : pointer ( <pointer>, <pointee> )
8979 : : or
8980 : : pointer ( <pointer1>, <pointee1> ), ( <pointer2>, <pointee2> ), ...
8981 : : The pointer, if already declared, should be an integer. Otherwise, we
8982 : : set it as BT_INTEGER with kind gfc_index_integer_kind. The pointee may
8983 : : be either a scalar, or an array declaration. No space is allocated for
8984 : : the pointee. For the statement
8985 : : pointer (ipt, ar(10))
8986 : : any subsequent uses of ar will be translated (in C-notation) as
8987 : : ar(i) => ((<type> *) ipt)(i)
8988 : : After gimplification, pointee variable will disappear in the code. */
8989 : :
8990 : : static match
8991 : 334 : cray_pointer_decl (void)
8992 : : {
8993 : 334 : match m;
8994 : 334 : gfc_array_spec *as = NULL;
8995 : 334 : gfc_symbol *cptr; /* Pointer symbol. */
8996 : 334 : gfc_symbol *cpte; /* Pointee symbol. */
8997 : 334 : locus var_locus;
8998 : 334 : bool done = false;
8999 : :
9000 : 334 : while (!done)
9001 : : {
9002 : 347 : if (gfc_match_char ('(') != MATCH_YES)
9003 : : {
9004 : 1 : gfc_error ("Expected %<(%> at %C");
9005 : 1 : return MATCH_ERROR;
9006 : : }
9007 : :
9008 : : /* Match pointer. */
9009 : 346 : var_locus = gfc_current_locus;
9010 : 346 : gfc_clear_attr (¤t_attr);
9011 : 346 : gfc_add_cray_pointer (¤t_attr, &var_locus);
9012 : 346 : current_ts.type = BT_INTEGER;
9013 : 346 : current_ts.kind = gfc_index_integer_kind;
9014 : :
9015 : 346 : m = gfc_match_symbol (&cptr, 0);
9016 : 346 : if (m != MATCH_YES)
9017 : : {
9018 : 2 : gfc_error ("Expected variable name at %C");
9019 : 2 : return m;
9020 : : }
9021 : :
9022 : 344 : if (!gfc_add_cray_pointer (&cptr->attr, &var_locus))
9023 : : return MATCH_ERROR;
9024 : :
9025 : 341 : gfc_set_sym_referenced (cptr);
9026 : :
9027 : 341 : if (cptr->ts.type == BT_UNKNOWN) /* Override the type, if necessary. */
9028 : : {
9029 : 327 : cptr->ts.type = BT_INTEGER;
9030 : 327 : cptr->ts.kind = gfc_index_integer_kind;
9031 : : }
9032 : 14 : else if (cptr->ts.type != BT_INTEGER)
9033 : : {
9034 : 1 : gfc_error ("Cray pointer at %C must be an integer");
9035 : 1 : return MATCH_ERROR;
9036 : : }
9037 : 13 : else if (cptr->ts.kind < gfc_index_integer_kind)
9038 : 0 : gfc_warning (0, "Cray pointer at %C has %d bytes of precision;"
9039 : : " memory addresses require %d bytes",
9040 : : cptr->ts.kind, gfc_index_integer_kind);
9041 : :
9042 : 340 : if (gfc_match_char (',') != MATCH_YES)
9043 : : {
9044 : 2 : gfc_error ("Expected \",\" at %C");
9045 : 2 : return MATCH_ERROR;
9046 : : }
9047 : :
9048 : : /* Match Pointee. */
9049 : 338 : var_locus = gfc_current_locus;
9050 : 338 : gfc_clear_attr (¤t_attr);
9051 : 338 : gfc_add_cray_pointee (¤t_attr, &var_locus);
9052 : 338 : current_ts.type = BT_UNKNOWN;
9053 : 338 : current_ts.kind = 0;
9054 : :
9055 : 338 : m = gfc_match_symbol (&cpte, 0);
9056 : 338 : if (m != MATCH_YES)
9057 : : {
9058 : 2 : gfc_error ("Expected variable name at %C");
9059 : 2 : return m;
9060 : : }
9061 : :
9062 : : /* Check for an optional array spec. */
9063 : 336 : m = gfc_match_array_spec (&as, true, false);
9064 : 336 : if (m == MATCH_ERROR)
9065 : : {
9066 : 0 : gfc_free_array_spec (as);
9067 : 0 : return m;
9068 : : }
9069 : 336 : else if (m == MATCH_NO)
9070 : : {
9071 : 226 : gfc_free_array_spec (as);
9072 : 226 : as = NULL;
9073 : : }
9074 : :
9075 : 336 : if (!gfc_add_cray_pointee (&cpte->attr, &var_locus))
9076 : : return MATCH_ERROR;
9077 : :
9078 : 329 : gfc_set_sym_referenced (cpte);
9079 : :
9080 : 329 : if (cpte->as == NULL)
9081 : : {
9082 : 247 : if (!gfc_set_array_spec (cpte, as, &var_locus))
9083 : 0 : gfc_internal_error ("Cannot set Cray pointee array spec.");
9084 : : }
9085 : 82 : else if (as != NULL)
9086 : : {
9087 : 1 : gfc_error ("Duplicate array spec for Cray pointee at %C");
9088 : 1 : gfc_free_array_spec (as);
9089 : 1 : return MATCH_ERROR;
9090 : : }
9091 : :
9092 : 328 : as = NULL;
9093 : :
9094 : 328 : if (cpte->as != NULL)
9095 : : {
9096 : : /* Fix array spec. */
9097 : 190 : m = gfc_mod_pointee_as (cpte->as);
9098 : 190 : if (m == MATCH_ERROR)
9099 : : return m;
9100 : : }
9101 : :
9102 : : /* Point the Pointee at the Pointer. */
9103 : 328 : cpte->cp_pointer = cptr;
9104 : :
9105 : 328 : if (gfc_match_char (')') != MATCH_YES)
9106 : : {
9107 : 2 : gfc_error ("Expected \")\" at %C");
9108 : 2 : return MATCH_ERROR;
9109 : : }
9110 : 326 : m = gfc_match_char (',');
9111 : 326 : if (m != MATCH_YES)
9112 : 313 : done = true; /* Stop searching for more declarations. */
9113 : :
9114 : : }
9115 : :
9116 : 313 : if (m == MATCH_ERROR /* Failed when trying to find ',' above. */
9117 : 313 : || gfc_match_eos () != MATCH_YES)
9118 : : {
9119 : 0 : gfc_error ("Expected %<,%> or end of statement at %C");
9120 : 0 : return MATCH_ERROR;
9121 : : }
9122 : : return MATCH_YES;
9123 : : }
9124 : :
9125 : :
9126 : : match
9127 : 3112 : gfc_match_external (void)
9128 : : {
9129 : :
9130 : 3112 : gfc_clear_attr (¤t_attr);
9131 : 3112 : current_attr.external = 1;
9132 : :
9133 : 3112 : return attr_decl ();
9134 : : }
9135 : :
9136 : :
9137 : : match
9138 : 208 : gfc_match_intent (void)
9139 : : {
9140 : 208 : sym_intent intent;
9141 : :
9142 : : /* This is not allowed within a BLOCK construct! */
9143 : 208 : if (gfc_current_state () == COMP_BLOCK)
9144 : : {
9145 : 2 : gfc_error ("INTENT is not allowed inside of BLOCK at %C");
9146 : 2 : return MATCH_ERROR;
9147 : : }
9148 : :
9149 : 206 : intent = match_intent_spec ();
9150 : 206 : if (intent == INTENT_UNKNOWN)
9151 : : return MATCH_ERROR;
9152 : :
9153 : 206 : gfc_clear_attr (¤t_attr);
9154 : 206 : current_attr.intent = intent;
9155 : :
9156 : 206 : return attr_decl ();
9157 : : }
9158 : :
9159 : :
9160 : : match
9161 : 1449 : gfc_match_intrinsic (void)
9162 : : {
9163 : :
9164 : 1449 : gfc_clear_attr (¤t_attr);
9165 : 1449 : current_attr.intrinsic = 1;
9166 : :
9167 : 1449 : return attr_decl ();
9168 : : }
9169 : :
9170 : :
9171 : : match
9172 : 220 : gfc_match_optional (void)
9173 : : {
9174 : : /* This is not allowed within a BLOCK construct! */
9175 : 220 : if (gfc_current_state () == COMP_BLOCK)
9176 : : {
9177 : 2 : gfc_error ("OPTIONAL is not allowed inside of BLOCK at %C");
9178 : 2 : return MATCH_ERROR;
9179 : : }
9180 : :
9181 : 218 : gfc_clear_attr (¤t_attr);
9182 : 218 : current_attr.optional = 1;
9183 : :
9184 : 218 : return attr_decl ();
9185 : : }
9186 : :
9187 : :
9188 : : match
9189 : 903 : gfc_match_pointer (void)
9190 : : {
9191 : 903 : gfc_gobble_whitespace ();
9192 : 903 : if (gfc_peek_ascii_char () == '(')
9193 : : {
9194 : 335 : if (!flag_cray_pointer)
9195 : : {
9196 : 1 : gfc_error ("Cray pointer declaration at %C requires "
9197 : : "%<-fcray-pointer%> flag");
9198 : 1 : return MATCH_ERROR;
9199 : : }
9200 : 334 : return cray_pointer_decl ();
9201 : : }
9202 : : else
9203 : : {
9204 : 568 : gfc_clear_attr (¤t_attr);
9205 : 568 : current_attr.pointer = 1;
9206 : :
9207 : 568 : return attr_decl ();
9208 : : }
9209 : : }
9210 : :
9211 : :
9212 : : match
9213 : 155 : gfc_match_allocatable (void)
9214 : : {
9215 : 155 : gfc_clear_attr (¤t_attr);
9216 : 155 : current_attr.allocatable = 1;
9217 : :
9218 : 155 : return attr_decl ();
9219 : : }
9220 : :
9221 : :
9222 : : match
9223 : 22 : gfc_match_codimension (void)
9224 : : {
9225 : 22 : gfc_clear_attr (¤t_attr);
9226 : 22 : current_attr.codimension = 1;
9227 : :
9228 : 22 : return attr_decl ();
9229 : : }
9230 : :
9231 : :
9232 : : match
9233 : 80 : gfc_match_contiguous (void)
9234 : : {
9235 : 80 : if (!gfc_notify_std (GFC_STD_F2008, "CONTIGUOUS statement at %C"))
9236 : : return MATCH_ERROR;
9237 : :
9238 : 79 : gfc_clear_attr (¤t_attr);
9239 : 79 : current_attr.contiguous = 1;
9240 : :
9241 : 79 : return attr_decl ();
9242 : : }
9243 : :
9244 : :
9245 : : match
9246 : 645 : gfc_match_dimension (void)
9247 : : {
9248 : 645 : gfc_clear_attr (¤t_attr);
9249 : 645 : current_attr.dimension = 1;
9250 : :
9251 : 645 : return attr_decl ();
9252 : : }
9253 : :
9254 : :
9255 : : match
9256 : 99 : gfc_match_target (void)
9257 : : {
9258 : 99 : gfc_clear_attr (¤t_attr);
9259 : 99 : current_attr.target = 1;
9260 : :
9261 : 99 : return attr_decl ();
9262 : : }
9263 : :
9264 : :
9265 : : /* Match the list of entities being specified in a PUBLIC or PRIVATE
9266 : : statement. */
9267 : :
9268 : : static match
9269 : 1590 : access_attr_decl (gfc_statement st)
9270 : : {
9271 : 1590 : char name[GFC_MAX_SYMBOL_LEN + 1];
9272 : 1590 : interface_type type;
9273 : 1590 : gfc_user_op *uop;
9274 : 1590 : gfc_symbol *sym, *dt_sym;
9275 : 1590 : gfc_intrinsic_op op;
9276 : 1590 : match m;
9277 : 1590 : gfc_access access = (st == ST_PUBLIC) ? ACCESS_PUBLIC : ACCESS_PRIVATE;
9278 : :
9279 : 1590 : if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO)
9280 : 0 : goto done;
9281 : :
9282 : 2660 : for (;;)
9283 : : {
9284 : 2660 : m = gfc_match_generic_spec (&type, name, &op);
9285 : 2660 : if (m == MATCH_NO)
9286 : 0 : goto syntax;
9287 : 2660 : if (m == MATCH_ERROR)
9288 : 0 : goto done;
9289 : :
9290 : 2660 : switch (type)
9291 : : {
9292 : 0 : case INTERFACE_NAMELESS:
9293 : 0 : case INTERFACE_ABSTRACT:
9294 : 0 : goto syntax;
9295 : :
9296 : 2592 : case INTERFACE_GENERIC:
9297 : 2592 : case INTERFACE_DTIO:
9298 : :
9299 : 2592 : if (gfc_get_symbol (name, NULL, &sym))
9300 : 0 : goto done;
9301 : :
9302 : 2592 : if (type == INTERFACE_DTIO
9303 : 20 : && gfc_current_ns->proc_name
9304 : 20 : && gfc_current_ns->proc_name->attr.flavor == FL_MODULE
9305 : 20 : && sym->attr.flavor == FL_UNKNOWN)
9306 : 2 : sym->attr.flavor = FL_PROCEDURE;
9307 : :
9308 : 2592 : if (!gfc_add_access (&sym->attr, access, sym->name, NULL))
9309 : 4 : goto done;
9310 : :
9311 : 316 : if (sym->attr.generic && (dt_sym = gfc_find_dt_in_generic (sym))
9312 : 2638 : && !gfc_add_access (&dt_sym->attr, access, sym->name, NULL))
9313 : 0 : goto done;
9314 : :
9315 : : break;
9316 : :
9317 : 64 : case INTERFACE_INTRINSIC_OP:
9318 : 64 : if (gfc_current_ns->operator_access[op] == ACCESS_UNKNOWN)
9319 : : {
9320 : 64 : gfc_intrinsic_op other_op;
9321 : :
9322 : 64 : gfc_current_ns->operator_access[op] = access;
9323 : :
9324 : : /* Handle the case if there is another op with the same
9325 : : function, for INTRINSIC_EQ vs. INTRINSIC_EQ_OS and so on. */
9326 : 64 : other_op = gfc_equivalent_op (op);
9327 : :
9328 : 64 : if (other_op != INTRINSIC_NONE)
9329 : 21 : gfc_current_ns->operator_access[other_op] = access;
9330 : : }
9331 : : else
9332 : : {
9333 : 0 : gfc_error ("Access specification of the %s operator at %C has "
9334 : : "already been specified", gfc_op2string (op));
9335 : 0 : goto done;
9336 : : }
9337 : :
9338 : : break;
9339 : :
9340 : 4 : case INTERFACE_USER_OP:
9341 : 4 : uop = gfc_get_uop (name);
9342 : :
9343 : 4 : if (uop->access == ACCESS_UNKNOWN)
9344 : : {
9345 : 3 : uop->access = access;
9346 : : }
9347 : : else
9348 : : {
9349 : 1 : gfc_error ("Access specification of the .%s. operator at %C "
9350 : : "has already been specified", uop->name);
9351 : 1 : goto done;
9352 : : }
9353 : :
9354 : 3 : break;
9355 : : }
9356 : :
9357 : 2655 : if (gfc_match_char (',') == MATCH_NO)
9358 : : break;
9359 : : }
9360 : :
9361 : 1585 : if (gfc_match_eos () != MATCH_YES)
9362 : 0 : goto syntax;
9363 : : return MATCH_YES;
9364 : :
9365 : 0 : syntax:
9366 : 0 : gfc_syntax_error (st);
9367 : :
9368 : : done:
9369 : : return MATCH_ERROR;
9370 : : }
9371 : :
9372 : :
9373 : : match
9374 : 23 : gfc_match_protected (void)
9375 : : {
9376 : 23 : gfc_symbol *sym;
9377 : 23 : match m;
9378 : 23 : char c;
9379 : :
9380 : : /* PROTECTED has already been seen, but must be followed by whitespace
9381 : : or ::. */
9382 : 23 : c = gfc_peek_ascii_char ();
9383 : 23 : if (!gfc_is_whitespace (c) && c != ':')
9384 : : return MATCH_NO;
9385 : :
9386 : 22 : if (!gfc_current_ns->proc_name
9387 : 20 : || gfc_current_ns->proc_name->attr.flavor != FL_MODULE)
9388 : : {
9389 : 3 : gfc_error ("PROTECTED at %C only allowed in specification "
9390 : : "part of a module");
9391 : 3 : return MATCH_ERROR;
9392 : :
9393 : : }
9394 : :
9395 : 19 : gfc_match (" ::");
9396 : :
9397 : 19 : if (!gfc_notify_std (GFC_STD_F2003, "PROTECTED statement at %C"))
9398 : : return MATCH_ERROR;
9399 : :
9400 : : /* PROTECTED has an entity-list. */
9401 : 18 : if (gfc_match_eos () == MATCH_YES)
9402 : 0 : goto syntax;
9403 : :
9404 : 26 : for(;;)
9405 : : {
9406 : 26 : m = gfc_match_symbol (&sym, 0);
9407 : 26 : switch (m)
9408 : : {
9409 : 26 : case MATCH_YES:
9410 : 26 : if (!gfc_add_protected (&sym->attr, sym->name, &gfc_current_locus))
9411 : : return MATCH_ERROR;
9412 : 25 : goto next_item;
9413 : :
9414 : : case MATCH_NO:
9415 : : break;
9416 : :
9417 : : case MATCH_ERROR:
9418 : : return MATCH_ERROR;
9419 : : }
9420 : :
9421 : 25 : next_item:
9422 : 25 : if (gfc_match_eos () == MATCH_YES)
9423 : : break;
9424 : 8 : if (gfc_match_char (',') != MATCH_YES)
9425 : 0 : goto syntax;
9426 : : }
9427 : :
9428 : : return MATCH_YES;
9429 : :
9430 : 0 : syntax:
9431 : 0 : gfc_error ("Syntax error in PROTECTED statement at %C");
9432 : 0 : return MATCH_ERROR;
9433 : : }
9434 : :
9435 : :
9436 : : /* The PRIVATE statement is a bit weird in that it can be an attribute
9437 : : declaration, but also works as a standalone statement inside of a
9438 : : type declaration or a module. */
9439 : :
9440 : : match
9441 : 27589 : gfc_match_private (gfc_statement *st)
9442 : : {
9443 : 27589 : gfc_state_data *prev;
9444 : :
9445 : 27589 : if (gfc_match ("private") != MATCH_YES)
9446 : : return MATCH_NO;
9447 : :
9448 : : /* Try matching PRIVATE without an access-list. */
9449 : 1472 : if (gfc_match_eos () == MATCH_YES)
9450 : : {
9451 : 1187 : prev = gfc_state_stack->previous;
9452 : 1187 : if (gfc_current_state () != COMP_MODULE
9453 : 352 : && !(gfc_current_state () == COMP_DERIVED
9454 : 319 : && prev && prev->state == COMP_MODULE)
9455 : 34 : && !(gfc_current_state () == COMP_DERIVED_CONTAINS
9456 : 32 : && prev->previous && prev->previous->state == COMP_MODULE))
9457 : : {
9458 : 2 : gfc_error ("PRIVATE statement at %C is only allowed in the "
9459 : : "specification part of a module");
9460 : 2 : return MATCH_ERROR;
9461 : : }
9462 : :
9463 : 1185 : *st = ST_PRIVATE;
9464 : 1185 : return MATCH_YES;
9465 : : }
9466 : :
9467 : : /* At this point in free-form source code, PRIVATE must be followed
9468 : : by whitespace or ::. */
9469 : 285 : if (gfc_current_form == FORM_FREE)
9470 : : {
9471 : 283 : char c = gfc_peek_ascii_char ();
9472 : 283 : if (!gfc_is_whitespace (c) && c != ':')
9473 : : return MATCH_NO;
9474 : : }
9475 : :
9476 : 284 : prev = gfc_state_stack->previous;
9477 : 284 : if (gfc_current_state () != COMP_MODULE
9478 : 1 : && !(gfc_current_state () == COMP_DERIVED
9479 : 0 : && prev && prev->state == COMP_MODULE)
9480 : 1 : && !(gfc_current_state () == COMP_DERIVED_CONTAINS
9481 : 0 : && prev->previous && prev->previous->state == COMP_MODULE))
9482 : : {
9483 : 1 : gfc_error ("PRIVATE statement at %C is only allowed in the "
9484 : : "specification part of a module");
9485 : 1 : return MATCH_ERROR;
9486 : : }
9487 : :
9488 : 283 : *st = ST_ATTR_DECL;
9489 : 283 : return access_attr_decl (ST_PRIVATE);
9490 : : }
9491 : :
9492 : :
9493 : : match
9494 : 1686 : gfc_match_public (gfc_statement *st)
9495 : : {
9496 : 1686 : if (gfc_match ("public") != MATCH_YES)
9497 : : return MATCH_NO;
9498 : :
9499 : : /* Try matching PUBLIC without an access-list. */
9500 : 1347 : if (gfc_match_eos () == MATCH_YES)
9501 : : {
9502 : 38 : if (gfc_current_state () != COMP_MODULE)
9503 : : {
9504 : 2 : gfc_error ("PUBLIC statement at %C is only allowed in the "
9505 : : "specification part of a module");
9506 : 2 : return MATCH_ERROR;
9507 : : }
9508 : :
9509 : 36 : *st = ST_PUBLIC;
9510 : 36 : return MATCH_YES;
9511 : : }
9512 : :
9513 : : /* At this point in free-form source code, PUBLIC must be followed
9514 : : by whitespace or ::. */
9515 : 1309 : if (gfc_current_form == FORM_FREE)
9516 : : {
9517 : 1307 : char c = gfc_peek_ascii_char ();
9518 : 1307 : if (!gfc_is_whitespace (c) && c != ':')
9519 : : return MATCH_NO;
9520 : : }
9521 : :
9522 : 1308 : if (gfc_current_state () != COMP_MODULE)
9523 : : {
9524 : 1 : gfc_error ("PUBLIC statement at %C is only allowed in the "
9525 : : "specification part of a module");
9526 : 1 : return MATCH_ERROR;
9527 : : }
9528 : :
9529 : 1307 : *st = ST_ATTR_DECL;
9530 : 1307 : return access_attr_decl (ST_PUBLIC);
9531 : : }
9532 : :
9533 : :
9534 : : /* Workhorse for gfc_match_parameter. */
9535 : :
9536 : : static match
9537 : 7480 : do_parm (void)
9538 : : {
9539 : 7480 : gfc_symbol *sym;
9540 : 7480 : gfc_expr *init;
9541 : 7480 : match m;
9542 : 7480 : bool t;
9543 : :
9544 : 7480 : m = gfc_match_symbol (&sym, 0);
9545 : 7480 : if (m == MATCH_NO)
9546 : 0 : gfc_error ("Expected variable name at %C in PARAMETER statement");
9547 : :
9548 : 7480 : if (m != MATCH_YES)
9549 : : return m;
9550 : :
9551 : 7480 : if (gfc_match_char ('=') == MATCH_NO)
9552 : : {
9553 : 0 : gfc_error ("Expected = sign in PARAMETER statement at %C");
9554 : 0 : return MATCH_ERROR;
9555 : : }
9556 : :
9557 : 7480 : m = gfc_match_init_expr (&init);
9558 : 7480 : if (m == MATCH_NO)
9559 : 0 : gfc_error ("Expected expression at %C in PARAMETER statement");
9560 : 7480 : if (m != MATCH_YES)
9561 : : return m;
9562 : :
9563 : 7479 : if (sym->ts.type == BT_UNKNOWN
9564 : 7479 : && !gfc_set_default_type (sym, 1, NULL))
9565 : : {
9566 : 1 : m = MATCH_ERROR;
9567 : 1 : goto cleanup;
9568 : : }
9569 : :
9570 : 7478 : if (!gfc_check_assign_symbol (sym, NULL, init)
9571 : 7478 : || !gfc_add_flavor (&sym->attr, FL_PARAMETER, sym->name, NULL))
9572 : : {
9573 : 1 : m = MATCH_ERROR;
9574 : 1 : goto cleanup;
9575 : : }
9576 : :
9577 : 7477 : if (sym->value)
9578 : : {
9579 : 1 : gfc_error ("Initializing already initialized variable at %C");
9580 : 1 : m = MATCH_ERROR;
9581 : 1 : goto cleanup;
9582 : : }
9583 : :
9584 : 7476 : t = add_init_expr_to_sym (sym->name, &init, &gfc_current_locus);
9585 : 7476 : return (t) ? MATCH_YES : MATCH_ERROR;
9586 : :
9587 : 3 : cleanup:
9588 : 3 : gfc_free_expr (init);
9589 : 3 : return m;
9590 : : }
9591 : :
9592 : :
9593 : : /* Match a parameter statement, with the weird syntax that these have. */
9594 : :
9595 : : match
9596 : 6770 : gfc_match_parameter (void)
9597 : : {
9598 : 6770 : const char *term = " )%t";
9599 : 6770 : match m;
9600 : :
9601 : 6770 : if (gfc_match_char ('(') == MATCH_NO)
9602 : : {
9603 : : /* With legacy PARAMETER statements, don't expect a terminating ')'. */
9604 : 28 : if (!gfc_notify_std (GFC_STD_LEGACY, "PARAMETER without '()' at %C"))
9605 : : return MATCH_NO;
9606 : 6769 : term = " %t";
9607 : : }
9608 : :
9609 : 7480 : for (;;)
9610 : : {
9611 : 7480 : m = do_parm ();
9612 : 7480 : if (m != MATCH_YES)
9613 : : break;
9614 : :
9615 : 7476 : if (gfc_match (term) == MATCH_YES)
9616 : : break;
9617 : :
9618 : 711 : if (gfc_match_char (',') != MATCH_YES)
9619 : : {
9620 : 0 : gfc_error ("Unexpected characters in PARAMETER statement at %C");
9621 : 0 : m = MATCH_ERROR;
9622 : 0 : break;
9623 : : }
9624 : : }
9625 : :
9626 : : return m;
9627 : : }
9628 : :
9629 : :
9630 : : match
9631 : 8 : gfc_match_automatic (void)
9632 : : {
9633 : 8 : gfc_symbol *sym;
9634 : 8 : match m;
9635 : 8 : bool seen_symbol = false;
9636 : :
9637 : 8 : if (!flag_dec_static)
9638 : : {
9639 : 2 : gfc_error ("%s at %C is a DEC extension, enable with "
9640 : : "%<-fdec-static%>",
9641 : : "AUTOMATIC"
9642 : : );
9643 : 2 : return MATCH_ERROR;
9644 : : }
9645 : :
9646 : 6 : gfc_match (" ::");
9647 : :
9648 : 6 : for (;;)
9649 : : {
9650 : 6 : m = gfc_match_symbol (&sym, 0);
9651 : 6 : switch (m)
9652 : : {
9653 : : case MATCH_NO:
9654 : : break;
9655 : :
9656 : : case MATCH_ERROR:
9657 : : return MATCH_ERROR;
9658 : :
9659 : 4 : case MATCH_YES:
9660 : 4 : if (!gfc_add_automatic (&sym->attr, sym->name, &gfc_current_locus))
9661 : : return MATCH_ERROR;
9662 : : seen_symbol = true;
9663 : : break;
9664 : : }
9665 : :
9666 : 4 : if (gfc_match_eos () == MATCH_YES)
9667 : : break;
9668 : 0 : if (gfc_match_char (',') != MATCH_YES)
9669 : 0 : goto syntax;
9670 : : }
9671 : :
9672 : 4 : if (!seen_symbol)
9673 : : {
9674 : 2 : gfc_error ("Expected entity-list in AUTOMATIC statement at %C");
9675 : 2 : return MATCH_ERROR;
9676 : : }
9677 : :
9678 : : return MATCH_YES;
9679 : :
9680 : 0 : syntax:
9681 : 0 : gfc_error ("Syntax error in AUTOMATIC statement at %C");
9682 : 0 : return MATCH_ERROR;
9683 : : }
9684 : :
9685 : :
9686 : : match
9687 : 7 : gfc_match_static (void)
9688 : : {
9689 : 7 : gfc_symbol *sym;
9690 : 7 : match m;
9691 : 7 : bool seen_symbol = false;
9692 : :
9693 : 7 : if (!flag_dec_static)
9694 : : {
9695 : 2 : gfc_error ("%s at %C is a DEC extension, enable with "
9696 : : "%<-fdec-static%>",
9697 : : "STATIC");
9698 : 2 : return MATCH_ERROR;
9699 : : }
9700 : :
9701 : 5 : gfc_match (" ::");
9702 : :
9703 : 5 : for (;;)
9704 : : {
9705 : 5 : m = gfc_match_symbol (&sym, 0);
9706 : 5 : switch (m)
9707 : : {
9708 : : case MATCH_NO:
9709 : : break;
9710 : :
9711 : : case MATCH_ERROR:
9712 : : return MATCH_ERROR;
9713 : :
9714 : 3 : case MATCH_YES:
9715 : 3 : if (!gfc_add_save (&sym->attr, SAVE_EXPLICIT, sym->name,
9716 : : &gfc_current_locus))
9717 : : return MATCH_ERROR;
9718 : : seen_symbol = true;
9719 : : break;
9720 : : }
9721 : :
9722 : 3 : if (gfc_match_eos () == MATCH_YES)
9723 : : break;
9724 : 0 : if (gfc_match_char (',') != MATCH_YES)
9725 : 0 : goto syntax;
9726 : : }
9727 : :
9728 : 3 : if (!seen_symbol)
9729 : : {
9730 : 2 : gfc_error ("Expected entity-list in STATIC statement at %C");
9731 : 2 : return MATCH_ERROR;
9732 : : }
9733 : :
9734 : : return MATCH_YES;
9735 : :
9736 : 0 : syntax:
9737 : 0 : gfc_error ("Syntax error in STATIC statement at %C");
9738 : 0 : return MATCH_ERROR;
9739 : : }
9740 : :
9741 : :
9742 : : /* Save statements have a special syntax. */
9743 : :
9744 : : match
9745 : 270 : gfc_match_save (void)
9746 : : {
9747 : 270 : char n[GFC_MAX_SYMBOL_LEN+1];
9748 : 270 : gfc_common_head *c;
9749 : 270 : gfc_symbol *sym;
9750 : 270 : match m;
9751 : :
9752 : 270 : if (gfc_match_eos () == MATCH_YES)
9753 : : {
9754 : 149 : if (gfc_current_ns->seen_save)
9755 : : {
9756 : 7 : if (!gfc_notify_std (GFC_STD_LEGACY, "Blanket SAVE statement at %C "
9757 : : "follows previous SAVE statement"))
9758 : : return MATCH_ERROR;
9759 : : }
9760 : :
9761 : 148 : gfc_current_ns->save_all = gfc_current_ns->seen_save = 1;
9762 : 148 : return MATCH_YES;
9763 : : }
9764 : :
9765 : 121 : if (gfc_current_ns->save_all)
9766 : : {
9767 : 7 : if (!gfc_notify_std (GFC_STD_LEGACY, "SAVE statement at %C follows "
9768 : : "blanket SAVE statement"))
9769 : : return MATCH_ERROR;
9770 : : }
9771 : :
9772 : 120 : gfc_match (" ::");
9773 : :
9774 : 180 : for (;;)
9775 : : {
9776 : 180 : m = gfc_match_symbol (&sym, 0);
9777 : 180 : switch (m)
9778 : : {
9779 : 178 : case MATCH_YES:
9780 : 178 : if (!gfc_add_save (&sym->attr, SAVE_EXPLICIT, sym->name,
9781 : : &gfc_current_locus))
9782 : : return MATCH_ERROR;
9783 : 176 : goto next_item;
9784 : :
9785 : : case MATCH_NO:
9786 : : break;
9787 : :
9788 : : case MATCH_ERROR:
9789 : : return MATCH_ERROR;
9790 : : }
9791 : :
9792 : 2 : m = gfc_match (" / %n /", &n);
9793 : 2 : if (m == MATCH_ERROR)
9794 : : return MATCH_ERROR;
9795 : 2 : if (m == MATCH_NO)
9796 : 0 : goto syntax;
9797 : :
9798 : : /* F2023:C1108: A SAVE statement in a BLOCK construct shall contain a
9799 : : saved-entity-list that does not specify a common-block-name. */
9800 : 2 : if (gfc_current_state () == COMP_BLOCK)
9801 : : {
9802 : 1 : gfc_error ("SAVE of COMMON block %qs at %C is not allowed "
9803 : : "in a BLOCK construct", n);
9804 : 1 : return MATCH_ERROR;
9805 : : }
9806 : :
9807 : 1 : c = gfc_get_common (n, 0);
9808 : 1 : c->saved = 1;
9809 : :
9810 : 1 : gfc_current_ns->seen_save = 1;
9811 : :
9812 : 177 : next_item:
9813 : 177 : if (gfc_match_eos () == MATCH_YES)
9814 : : break;
9815 : 60 : if (gfc_match_char (',') != MATCH_YES)
9816 : 0 : goto syntax;
9817 : : }
9818 : :
9819 : : return MATCH_YES;
9820 : :
9821 : 0 : syntax:
9822 : 0 : if (gfc_current_ns->seen_save)
9823 : : {
9824 : 0 : gfc_error ("Syntax error in SAVE statement at %C");
9825 : 0 : return MATCH_ERROR;
9826 : : }
9827 : : else
9828 : : return MATCH_NO;
9829 : : }
9830 : :
9831 : :
9832 : : match
9833 : 93 : gfc_match_value (void)
9834 : : {
9835 : 93 : gfc_symbol *sym;
9836 : 93 : match m;
9837 : :
9838 : : /* This is not allowed within a BLOCK construct! */
9839 : 93 : if (gfc_current_state () == COMP_BLOCK)
9840 : : {
9841 : 2 : gfc_error ("VALUE is not allowed inside of BLOCK at %C");
9842 : 2 : return MATCH_ERROR;
9843 : : }
9844 : :
9845 : 91 : if (!gfc_notify_std (GFC_STD_F2003, "VALUE statement at %C"))
9846 : : return MATCH_ERROR;
9847 : :
9848 : 90 : if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO)
9849 : : {
9850 : : return MATCH_ERROR;
9851 : : }
9852 : :
9853 : 90 : if (gfc_match_eos () == MATCH_YES)
9854 : 0 : goto syntax;
9855 : :
9856 : 116 : for(;;)
9857 : : {
9858 : 116 : m = gfc_match_symbol (&sym, 0);
9859 : 116 : switch (m)
9860 : : {
9861 : 116 : case MATCH_YES:
9862 : 116 : if (!gfc_add_value (&sym->attr, sym->name, &gfc_current_locus))
9863 : : return MATCH_ERROR;
9864 : 109 : goto next_item;
9865 : :
9866 : : case MATCH_NO:
9867 : : break;
9868 : :
9869 : : case MATCH_ERROR:
9870 : : return MATCH_ERROR;
9871 : : }
9872 : :
9873 : 109 : next_item:
9874 : 109 : if (gfc_match_eos () == MATCH_YES)
9875 : : break;
9876 : 26 : if (gfc_match_char (',') != MATCH_YES)
9877 : 0 : goto syntax;
9878 : : }
9879 : :
9880 : : return MATCH_YES;
9881 : :
9882 : 0 : syntax:
9883 : 0 : gfc_error ("Syntax error in VALUE statement at %C");
9884 : 0 : return MATCH_ERROR;
9885 : : }
9886 : :
9887 : :
9888 : : match
9889 : 45 : gfc_match_volatile (void)
9890 : : {
9891 : 45 : gfc_symbol *sym;
9892 : 45 : char *name;
9893 : 45 : match m;
9894 : :
9895 : 45 : if (!gfc_notify_std (GFC_STD_F2003, "VOLATILE statement at %C"))
9896 : : return MATCH_ERROR;
9897 : :
9898 : 44 : if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO)
9899 : : {
9900 : : return MATCH_ERROR;
9901 : : }
9902 : :
9903 : 44 : if (gfc_match_eos () == MATCH_YES)
9904 : 1 : goto syntax;
9905 : :
9906 : 48 : for(;;)
9907 : : {
9908 : : /* VOLATILE is special because it can be added to host-associated
9909 : : symbols locally. Except for coarrays. */
9910 : 48 : m = gfc_match_symbol (&sym, 1);
9911 : 48 : switch (m)
9912 : : {
9913 : 48 : case MATCH_YES:
9914 : 48 : name = XCNEWVAR (char, strlen (sym->name) + 1);
9915 : 48 : strcpy (name, sym->name);
9916 : 48 : if (!check_function_name (name))
9917 : : return MATCH_ERROR;
9918 : : /* F2008, C560+C561. VOLATILE for host-/use-associated variable or
9919 : : for variable in a BLOCK which is defined outside of the BLOCK. */
9920 : 47 : if (sym->ns != gfc_current_ns && sym->attr.codimension)
9921 : : {
9922 : 2 : gfc_error ("Specifying VOLATILE for coarray variable %qs at "
9923 : : "%C, which is use-/host-associated", sym->name);
9924 : 2 : return MATCH_ERROR;
9925 : : }
9926 : 45 : if (!gfc_add_volatile (&sym->attr, sym->name, &gfc_current_locus))
9927 : : return MATCH_ERROR;
9928 : 42 : goto next_item;
9929 : :
9930 : : case MATCH_NO:
9931 : : break;
9932 : :
9933 : : case MATCH_ERROR:
9934 : : return MATCH_ERROR;
9935 : : }
9936 : :
9937 : 42 : next_item:
9938 : 42 : if (gfc_match_eos () == MATCH_YES)
9939 : : break;
9940 : 5 : if (gfc_match_char (',') != MATCH_YES)
9941 : 0 : goto syntax;
9942 : : }
9943 : :
9944 : : return MATCH_YES;
9945 : :
9946 : 1 : syntax:
9947 : 1 : gfc_error ("Syntax error in VOLATILE statement at %C");
9948 : 1 : return MATCH_ERROR;
9949 : : }
9950 : :
9951 : :
9952 : : match
9953 : 11 : gfc_match_asynchronous (void)
9954 : : {
9955 : 11 : gfc_symbol *sym;
9956 : 11 : char *name;
9957 : 11 : match m;
9958 : :
9959 : 11 : if (!gfc_notify_std (GFC_STD_F2003, "ASYNCHRONOUS statement at %C"))
9960 : : return MATCH_ERROR;
9961 : :
9962 : 10 : if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO)
9963 : : {
9964 : : return MATCH_ERROR;
9965 : : }
9966 : :
9967 : 10 : if (gfc_match_eos () == MATCH_YES)
9968 : 0 : goto syntax;
9969 : :
9970 : 10 : for(;;)
9971 : : {
9972 : : /* ASYNCHRONOUS is special because it can be added to host-associated
9973 : : symbols locally. */
9974 : 10 : m = gfc_match_symbol (&sym, 1);
9975 : 10 : switch (m)
9976 : : {
9977 : 10 : case MATCH_YES:
9978 : 10 : name = XCNEWVAR (char, strlen (sym->name) + 1);
9979 : 10 : strcpy (name, sym->name);
9980 : 10 : if (!check_function_name (name))
9981 : : return MATCH_ERROR;
9982 : 9 : if (!gfc_add_asynchronous (&sym->attr, sym->name, &gfc_current_locus))
9983 : : return MATCH_ERROR;
9984 : 7 : goto next_item;
9985 : :
9986 : : case MATCH_NO:
9987 : : break;
9988 : :
9989 : : case MATCH_ERROR:
9990 : : return MATCH_ERROR;
9991 : : }
9992 : :
9993 : 7 : next_item:
9994 : 7 : if (gfc_match_eos () == MATCH_YES)
9995 : : break;
9996 : 0 : if (gfc_match_char (',') != MATCH_YES)
9997 : 0 : goto syntax;
9998 : : }
9999 : :
10000 : : return MATCH_YES;
10001 : :
10002 : 0 : syntax:
10003 : 0 : gfc_error ("Syntax error in ASYNCHRONOUS statement at %C");
10004 : 0 : return MATCH_ERROR;
10005 : : }
10006 : :
10007 : :
10008 : : /* Match a module procedure statement in a submodule. */
10009 : :
10010 : : match
10011 : 720787 : gfc_match_submod_proc (void)
10012 : : {
10013 : 720787 : char name[GFC_MAX_SYMBOL_LEN + 1];
10014 : 720787 : gfc_symbol *sym, *fsym;
10015 : 720787 : match m;
10016 : 720787 : gfc_formal_arglist *formal, *head, *tail;
10017 : :
10018 : 720787 : if (gfc_current_state () != COMP_CONTAINS
10019 : 14470 : || !(gfc_state_stack->previous
10020 : 14470 : && (gfc_state_stack->previous->state == COMP_SUBMODULE
10021 : 14470 : || gfc_state_stack->previous->state == COMP_MODULE)))
10022 : : return MATCH_NO;
10023 : :
10024 : 7175 : m = gfc_match (" module% procedure% %n", name);
10025 : 7175 : if (m != MATCH_YES)
10026 : : return m;
10027 : :
10028 : 194 : if (!gfc_notify_std (GFC_STD_F2008, "MODULE PROCEDURE declaration "
10029 : : "at %C"))
10030 : : return MATCH_ERROR;
10031 : :
10032 : 194 : if (get_proc_name (name, &sym, false))
10033 : : return MATCH_ERROR;
10034 : :
10035 : : /* Make sure that the result field is appropriately filled. */
10036 : 194 : if (sym->tlink && sym->tlink->attr.function)
10037 : : {
10038 : 59 : if (sym->tlink->result && sym->tlink->result != sym->tlink)
10039 : : {
10040 : 28 : sym->result = sym->tlink->result;
10041 : 28 : if (!sym->result->attr.use_assoc)
10042 : : {
10043 : 13 : gfc_symtree *st = gfc_new_symtree (&gfc_current_ns->sym_root,
10044 : : sym->result->name);
10045 : 13 : st->n.sym = sym->result;
10046 : 13 : sym->result->refs++;
10047 : : }
10048 : : }
10049 : : else
10050 : 31 : sym->result = sym;
10051 : : }
10052 : :
10053 : : /* Set declared_at as it might point to, e.g., a PUBLIC statement, if
10054 : : the symbol existed before. */
10055 : 194 : sym->declared_at = gfc_current_locus;
10056 : :
10057 : 194 : if (!sym->attr.module_procedure)
10058 : : return MATCH_ERROR;
10059 : :
10060 : : /* Signal match_end to expect "end procedure". */
10061 : 192 : sym->abr_modproc_decl = 1;
10062 : :
10063 : : /* Change from IFSRC_IFBODY coming from the interface declaration. */
10064 : 192 : sym->attr.if_source = IFSRC_DECL;
10065 : :
10066 : 192 : gfc_new_block = sym;
10067 : :
10068 : : /* Make a new formal arglist with the symbols in the procedure
10069 : : namespace. */
10070 : 192 : head = tail = NULL;
10071 : 437 : for (formal = sym->formal; formal && formal->sym; formal = formal->next)
10072 : : {
10073 : 245 : if (formal == sym->formal)
10074 : 167 : head = tail = gfc_get_formal_arglist ();
10075 : : else
10076 : : {
10077 : 78 : tail->next = gfc_get_formal_arglist ();
10078 : 78 : tail = tail->next;
10079 : : }
10080 : :
10081 : 245 : if (gfc_copy_dummy_sym (&fsym, formal->sym, 0))
10082 : 0 : goto cleanup;
10083 : :
10084 : 245 : tail->sym = fsym;
10085 : 245 : gfc_set_sym_referenced (fsym);
10086 : : }
10087 : :
10088 : : /* The dummy symbols get cleaned up, when the formal_namespace of the
10089 : : interface declaration is cleared. This allows us to add the
10090 : : explicit interface as is done for other type of procedure. */
10091 : 192 : if (!gfc_add_explicit_interface (sym, IFSRC_DECL, head,
10092 : : &gfc_current_locus))
10093 : : return MATCH_ERROR;
10094 : :
10095 : 192 : if (gfc_match_eos () != MATCH_YES)
10096 : : {
10097 : : /* Unset st->n.sym. Note: in reject_statement (), the symbol changes are
10098 : : undone, such that the st->n.sym->formal points to the original symbol;
10099 : : if now this namespace is finalized, the formal namespace is freed,
10100 : : but it might be still needed in the parent namespace. */
10101 : 1 : gfc_symtree *st = gfc_find_symtree (gfc_current_ns->sym_root, sym->name);
10102 : 1 : st->n.sym = NULL;
10103 : 1 : gfc_free_symbol (sym->tlink);
10104 : 1 : sym->tlink = NULL;
10105 : 1 : sym->refs--;
10106 : 1 : gfc_syntax_error (ST_MODULE_PROC);
10107 : 1 : return MATCH_ERROR;
10108 : : }
10109 : :
10110 : : return MATCH_YES;
10111 : :
10112 : 0 : cleanup:
10113 : 0 : gfc_free_formal_arglist (head);
10114 : 0 : return MATCH_ERROR;
10115 : : }
10116 : :
10117 : :
10118 : : /* Match a module procedure statement. Note that we have to modify
10119 : : symbols in the parent's namespace because the current one was there
10120 : : to receive symbols that are in an interface's formal argument list. */
10121 : :
10122 : : match
10123 : 1409 : gfc_match_modproc (void)
10124 : : {
10125 : 1409 : char name[GFC_MAX_SYMBOL_LEN + 1];
10126 : 1409 : gfc_symbol *sym;
10127 : 1409 : match m;
10128 : 1409 : locus old_locus;
10129 : 1409 : gfc_namespace *module_ns;
10130 : 1409 : gfc_interface *old_interface_head, *interface;
10131 : :
10132 : 1409 : if (gfc_state_stack->previous == NULL
10133 : 1407 : || (gfc_state_stack->state != COMP_INTERFACE
10134 : 4 : && (gfc_state_stack->state != COMP_CONTAINS
10135 : 4 : || gfc_state_stack->previous->state != COMP_INTERFACE))
10136 : 1403 : || current_interface.type == INTERFACE_NAMELESS
10137 : 1403 : || current_interface.type == INTERFACE_ABSTRACT)
10138 : : {
10139 : 7 : gfc_error ("MODULE PROCEDURE at %C must be in a generic module "
10140 : : "interface");
10141 : 7 : return MATCH_ERROR;
10142 : : }
10143 : :
10144 : 1402 : module_ns = gfc_current_ns->parent;
10145 : 1408 : for (; module_ns; module_ns = module_ns->parent)
10146 : 1408 : if (module_ns->proc_name->attr.flavor == FL_MODULE
10147 : 29 : || module_ns->proc_name->attr.flavor == FL_PROGRAM
10148 : 12 : || (module_ns->proc_name->attr.flavor == FL_PROCEDURE
10149 : 12 : && !module_ns->proc_name->attr.contained))
10150 : : break;
10151 : :
10152 : 1402 : if (module_ns == NULL)
10153 : : return MATCH_ERROR;
10154 : :
10155 : : /* Store the current state of the interface. We will need it if we
10156 : : end up with a syntax error and need to recover. */
10157 : 1402 : old_interface_head = gfc_current_interface_head ();
10158 : :
10159 : : /* Check if the F2008 optional double colon appears. */
10160 : 1402 : gfc_gobble_whitespace ();
10161 : 1402 : old_locus = gfc_current_locus;
10162 : 1402 : if (gfc_match ("::") == MATCH_YES)
10163 : : {
10164 : 25 : if (!gfc_notify_std (GFC_STD_F2008, "double colon in "
10165 : : "MODULE PROCEDURE statement at %L", &old_locus))
10166 : : return MATCH_ERROR;
10167 : : }
10168 : : else
10169 : 1377 : gfc_current_locus = old_locus;
10170 : :
10171 : 1753 : for (;;)
10172 : : {
10173 : 1753 : bool last = false;
10174 : 1753 : old_locus = gfc_current_locus;
10175 : :
10176 : 1753 : m = gfc_match_name (name);
10177 : 1753 : if (m == MATCH_NO)
10178 : 1 : goto syntax;
10179 : 1752 : if (m != MATCH_YES)
10180 : : return MATCH_ERROR;
10181 : :
10182 : : /* Check for syntax error before starting to add symbols to the
10183 : : current namespace. */
10184 : 1752 : if (gfc_match_eos () == MATCH_YES)
10185 : : last = true;
10186 : :
10187 : 356 : if (!last && gfc_match_char (',') != MATCH_YES)
10188 : 2 : goto syntax;
10189 : :
10190 : : /* Now we're sure the syntax is valid, we process this item
10191 : : further. */
10192 : 1750 : if (gfc_get_symbol (name, module_ns, &sym))
10193 : : return MATCH_ERROR;
10194 : :
10195 : 1750 : if (sym->attr.intrinsic)
10196 : : {
10197 : 1 : gfc_error ("Intrinsic procedure at %L cannot be a MODULE "
10198 : : "PROCEDURE", &old_locus);
10199 : 1 : return MATCH_ERROR;
10200 : : }
10201 : :
10202 : 1749 : if (sym->attr.proc != PROC_MODULE
10203 : 1749 : && !gfc_add_procedure (&sym->attr, PROC_MODULE, sym->name, NULL))
10204 : : return MATCH_ERROR;
10205 : :
10206 : 1746 : if (!gfc_add_interface (sym))
10207 : : return MATCH_ERROR;
10208 : :
10209 : 1743 : sym->attr.mod_proc = 1;
10210 : 1743 : sym->declared_at = old_locus;
10211 : :
10212 : 1743 : if (last)
10213 : : break;
10214 : : }
10215 : :
10216 : : return MATCH_YES;
10217 : :
10218 : 3 : syntax:
10219 : : /* Restore the previous state of the interface. */
10220 : 3 : interface = gfc_current_interface_head ();
10221 : 3 : gfc_set_current_interface_head (old_interface_head);
10222 : :
10223 : : /* Free the new interfaces. */
10224 : 10 : while (interface != old_interface_head)
10225 : : {
10226 : 4 : gfc_interface *i = interface->next;
10227 : 4 : free (interface);
10228 : 4 : interface = i;
10229 : : }
10230 : :
10231 : : /* And issue a syntax error. */
10232 : 3 : gfc_syntax_error (ST_MODULE_PROC);
10233 : 3 : return MATCH_ERROR;
10234 : : }
10235 : :
10236 : :
10237 : : /* Check a derived type that is being extended. */
10238 : :
10239 : : static gfc_symbol*
10240 : 1428 : check_extended_derived_type (char *name)
10241 : : {
10242 : 1428 : gfc_symbol *extended;
10243 : :
10244 : 1428 : if (gfc_find_symbol (name, gfc_current_ns, 1, &extended))
10245 : : {
10246 : 0 : gfc_error ("Ambiguous symbol in TYPE definition at %C");
10247 : 0 : return NULL;
10248 : : }
10249 : :
10250 : 1428 : extended = gfc_find_dt_in_generic (extended);
10251 : :
10252 : : /* F08:C428. */
10253 : 1428 : if (!extended)
10254 : : {
10255 : 2 : gfc_error ("Symbol %qs at %C has not been previously defined", name);
10256 : 2 : return NULL;
10257 : : }
10258 : :
10259 : 1426 : if (extended->attr.flavor != FL_DERIVED)
10260 : : {
10261 : 0 : gfc_error ("%qs in EXTENDS expression at %C is not a "
10262 : : "derived type", name);
10263 : 0 : return NULL;
10264 : : }
10265 : :
10266 : 1426 : if (extended->attr.is_bind_c)
10267 : : {
10268 : 1 : gfc_error ("%qs cannot be extended at %C because it "
10269 : : "is BIND(C)", extended->name);
10270 : 1 : return NULL;
10271 : : }
10272 : :
10273 : 1425 : if (extended->attr.sequence)
10274 : : {
10275 : 1 : gfc_error ("%qs cannot be extended at %C because it "
10276 : : "is a SEQUENCE type", extended->name);
10277 : 1 : return NULL;
10278 : : }
10279 : :
10280 : : return extended;
10281 : : }
10282 : :
10283 : :
10284 : : /* Match the optional attribute specifiers for a type declaration.
10285 : : Return MATCH_ERROR if an error is encountered in one of the handled
10286 : : attributes (public, private, bind(c)), MATCH_NO if what's found is
10287 : : not a handled attribute, and MATCH_YES otherwise. TODO: More error
10288 : : checking on attribute conflicts needs to be done. */
10289 : :
10290 : : static match
10291 : 17972 : gfc_get_type_attr_spec (symbol_attribute *attr, char *name)
10292 : : {
10293 : : /* See if the derived type is marked as private. */
10294 : 17972 : if (gfc_match (" , private") == MATCH_YES)
10295 : : {
10296 : 15 : if (gfc_current_state () != COMP_MODULE)
10297 : : {
10298 : 1 : gfc_error ("Derived type at %C can only be PRIVATE in the "
10299 : : "specification part of a module");
10300 : 1 : return MATCH_ERROR;
10301 : : }
10302 : :
10303 : 14 : if (!gfc_add_access (attr, ACCESS_PRIVATE, NULL, NULL))
10304 : : return MATCH_ERROR;
10305 : : }
10306 : 17957 : else if (gfc_match (" , public") == MATCH_YES)
10307 : : {
10308 : 537 : if (gfc_current_state () != COMP_MODULE)
10309 : : {
10310 : 0 : gfc_error ("Derived type at %C can only be PUBLIC in the "
10311 : : "specification part of a module");
10312 : 0 : return MATCH_ERROR;
10313 : : }
10314 : :
10315 : 537 : if (!gfc_add_access (attr, ACCESS_PUBLIC, NULL, NULL))
10316 : : return MATCH_ERROR;
10317 : : }
10318 : 17420 : else if (gfc_match (" , bind ( c )") == MATCH_YES)
10319 : : {
10320 : : /* If the type is defined to be bind(c) it then needs to make
10321 : : sure that all fields are interoperable. This will
10322 : : need to be a semantic check on the finished derived type.
10323 : : See 15.2.3 (lines 9-12) of F2003 draft. */
10324 : 407 : if (!gfc_add_is_bind_c (attr, NULL, &gfc_current_locus, 0))
10325 : : return MATCH_ERROR;
10326 : :
10327 : : /* TODO: attr conflicts need to be checked, probably in symbol.cc. */
10328 : : }
10329 : 17013 : else if (gfc_match (" , abstract") == MATCH_YES)
10330 : : {
10331 : 319 : if (!gfc_notify_std (GFC_STD_F2003, "ABSTRACT type at %C"))
10332 : : return MATCH_ERROR;
10333 : :
10334 : 318 : if (!gfc_add_abstract (attr, &gfc_current_locus))
10335 : : return MATCH_ERROR;
10336 : : }
10337 : 16694 : else if (name && gfc_match (" , extends ( %n )", name) == MATCH_YES)
10338 : : {
10339 : 1429 : if (!gfc_add_extension (attr, &gfc_current_locus))
10340 : : return MATCH_ERROR;
10341 : : }
10342 : : else
10343 : 15265 : return MATCH_NO;
10344 : :
10345 : : /* If we get here, something matched. */
10346 : : return MATCH_YES;
10347 : : }
10348 : :
10349 : :
10350 : : /* Common function for type declaration blocks similar to derived types, such
10351 : : as STRUCTURES and MAPs. Unlike derived types, a structure type
10352 : : does NOT have a generic symbol matching the name given by the user.
10353 : : STRUCTUREs can share names with variables and PARAMETERs so we must allow
10354 : : for the creation of an independent symbol.
10355 : : Other parameters are a message to prefix errors with, the name of the new
10356 : : type to be created, and the flavor to add to the resulting symbol. */
10357 : :
10358 : : static bool
10359 : 717 : get_struct_decl (const char *name, sym_flavor fl, locus *decl,
10360 : : gfc_symbol **result)
10361 : : {
10362 : 717 : gfc_symbol *sym;
10363 : 717 : locus where;
10364 : :
10365 : 717 : gcc_assert (name[0] == (char) TOUPPER (name[0]));
10366 : :
10367 : 717 : if (decl)
10368 : 717 : where = *decl;
10369 : : else
10370 : 0 : where = gfc_current_locus;
10371 : :
10372 : 717 : if (gfc_get_symbol (name, NULL, &sym))
10373 : : return false;
10374 : :
10375 : 717 : if (!sym)
10376 : : {
10377 : 0 : gfc_internal_error ("Failed to create structure type '%s' at %C", name);
10378 : : return false;
10379 : : }
10380 : :
10381 : 717 : if (sym->components != NULL || sym->attr.zero_comp)
10382 : : {
10383 : 3 : gfc_error ("Type definition of %qs at %C was already defined at %L",
10384 : : sym->name, &sym->declared_at);
10385 : 3 : return false;
10386 : : }
10387 : :
10388 : 714 : sym->declared_at = where;
10389 : :
10390 : 714 : if (sym->attr.flavor != fl
10391 : 714 : && !gfc_add_flavor (&sym->attr, fl, sym->name, NULL))
10392 : : return false;
10393 : :
10394 : 714 : if (!sym->hash_value)
10395 : : /* Set the hash for the compound name for this type. */
10396 : 713 : sym->hash_value = gfc_hash_value (sym);
10397 : :
10398 : : /* Normally the type is expected to have been completely parsed by the time
10399 : : a field declaration with this type is seen. For unions, maps, and nested
10400 : : structure declarations, we need to indicate that it is okay that we
10401 : : haven't seen any components yet. This will be updated after the structure
10402 : : is fully parsed. */
10403 : 714 : sym->attr.zero_comp = 0;
10404 : :
10405 : : /* Structures always act like derived-types with the SEQUENCE attribute */
10406 : 714 : gfc_add_sequence (&sym->attr, sym->name, NULL);
10407 : :
10408 : 714 : if (result) *result = sym;
10409 : :
10410 : : return true;
10411 : : }
10412 : :
10413 : :
10414 : : /* Match the opening of a MAP block. Like a struct within a union in C;
10415 : : behaves identical to STRUCTURE blocks. */
10416 : :
10417 : : match
10418 : 259 : gfc_match_map (void)
10419 : : {
10420 : : /* Counter used to give unique internal names to map structures. */
10421 : 259 : static unsigned int gfc_map_id = 0;
10422 : 259 : char name[GFC_MAX_SYMBOL_LEN + 1];
10423 : 259 : gfc_symbol *sym;
10424 : 259 : locus old_loc;
10425 : :
10426 : 259 : old_loc = gfc_current_locus;
10427 : :
10428 : 259 : if (gfc_match_eos () != MATCH_YES)
10429 : : {
10430 : 1 : gfc_error ("Junk after MAP statement at %C");
10431 : 1 : gfc_current_locus = old_loc;
10432 : 1 : return MATCH_ERROR;
10433 : : }
10434 : :
10435 : : /* Map blocks are anonymous so we make up unique names for the symbol table
10436 : : which are invalid Fortran identifiers. */
10437 : 258 : snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "MM$%u", gfc_map_id++);
10438 : :
10439 : 258 : if (!get_struct_decl (name, FL_STRUCT, &old_loc, &sym))
10440 : : return MATCH_ERROR;
10441 : :
10442 : 258 : gfc_new_block = sym;
10443 : :
10444 : 258 : return MATCH_YES;
10445 : : }
10446 : :
10447 : :
10448 : : /* Match the opening of a UNION block. */
10449 : :
10450 : : match
10451 : 133 : gfc_match_union (void)
10452 : : {
10453 : : /* Counter used to give unique internal names to union types. */
10454 : 133 : static unsigned int gfc_union_id = 0;
10455 : 133 : char name[GFC_MAX_SYMBOL_LEN + 1];
10456 : 133 : gfc_symbol *sym;
10457 : 133 : locus old_loc;
10458 : :
10459 : 133 : old_loc = gfc_current_locus;
10460 : :
10461 : 133 : if (gfc_match_eos () != MATCH_YES)
10462 : : {
10463 : 1 : gfc_error ("Junk after UNION statement at %C");
10464 : 1 : gfc_current_locus = old_loc;
10465 : 1 : return MATCH_ERROR;
10466 : : }
10467 : :
10468 : : /* Unions are anonymous so we make up unique names for the symbol table
10469 : : which are invalid Fortran identifiers. */
10470 : 132 : snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "UU$%u", gfc_union_id++);
10471 : :
10472 : 132 : if (!get_struct_decl (name, FL_UNION, &old_loc, &sym))
10473 : : return MATCH_ERROR;
10474 : :
10475 : 132 : gfc_new_block = sym;
10476 : :
10477 : 132 : return MATCH_YES;
10478 : : }
10479 : :
10480 : :
10481 : : /* Match the beginning of a STRUCTURE declaration. This is similar to
10482 : : matching the beginning of a derived type declaration with a few
10483 : : twists. The resulting type symbol has no access control or other
10484 : : interesting attributes. */
10485 : :
10486 : : match
10487 : 336 : gfc_match_structure_decl (void)
10488 : : {
10489 : : /* Counter used to give unique internal names to anonymous structures. */
10490 : 336 : static unsigned int gfc_structure_id = 0;
10491 : 336 : char name[GFC_MAX_SYMBOL_LEN + 1];
10492 : 336 : gfc_symbol *sym;
10493 : 336 : match m;
10494 : 336 : locus where;
10495 : :
10496 : 336 : if (!flag_dec_structure)
10497 : : {
10498 : 3 : gfc_error ("%s at %C is a DEC extension, enable with "
10499 : : "%<-fdec-structure%>",
10500 : : "STRUCTURE");
10501 : 3 : return MATCH_ERROR;
10502 : : }
10503 : :
10504 : 333 : name[0] = '\0';
10505 : :
10506 : 333 : m = gfc_match (" /%n/", name);
10507 : 333 : if (m != MATCH_YES)
10508 : : {
10509 : : /* Non-nested structure declarations require a structure name. */
10510 : 24 : if (!gfc_comp_struct (gfc_current_state ()))
10511 : : {
10512 : 4 : gfc_error ("Structure name expected in non-nested structure "
10513 : : "declaration at %C");
10514 : 4 : return MATCH_ERROR;
10515 : : }
10516 : : /* This is an anonymous structure; make up a unique name for it
10517 : : (upper-case letters never make it to symbol names from the source).
10518 : : The important thing is initializing the type variable
10519 : : and setting gfc_new_symbol, which is immediately used by
10520 : : parse_structure () and variable_decl () to add components of
10521 : : this type. */
10522 : 20 : snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "SS$%u", gfc_structure_id++);
10523 : : }
10524 : :
10525 : 329 : where = gfc_current_locus;
10526 : : /* No field list allowed after non-nested structure declaration. */
10527 : 329 : if (!gfc_comp_struct (gfc_current_state ())
10528 : 296 : && gfc_match_eos () != MATCH_YES)
10529 : : {
10530 : 1 : gfc_error ("Junk after non-nested STRUCTURE statement at %C");
10531 : 1 : return MATCH_ERROR;
10532 : : }
10533 : :
10534 : : /* Make sure the name is not the name of an intrinsic type. */
10535 : 328 : if (gfc_is_intrinsic_typename (name))
10536 : : {
10537 : 1 : gfc_error ("Structure name %qs at %C cannot be the same as an"
10538 : : " intrinsic type", name);
10539 : 1 : return MATCH_ERROR;
10540 : : }
10541 : :
10542 : : /* Store the actual type symbol for the structure with an upper-case first
10543 : : letter (an invalid Fortran identifier). */
10544 : :
10545 : 327 : if (!get_struct_decl (gfc_dt_upper_string (name), FL_STRUCT, &where, &sym))
10546 : : return MATCH_ERROR;
10547 : :
10548 : 324 : gfc_new_block = sym;
10549 : 324 : return MATCH_YES;
10550 : : }
10551 : :
10552 : :
10553 : : /* This function does some work to determine which matcher should be used to
10554 : : * match a statement beginning with "TYPE". This is used to disambiguate TYPE
10555 : : * as an alias for PRINT from derived type declarations, TYPE IS statements,
10556 : : * and [parameterized] derived type declarations. */
10557 : :
10558 : : match
10559 : 498937 : gfc_match_type (gfc_statement *st)
10560 : : {
10561 : 498937 : char name[GFC_MAX_SYMBOL_LEN + 1];
10562 : 498937 : match m;
10563 : 498937 : locus old_loc;
10564 : :
10565 : : /* Requires -fdec. */
10566 : 498937 : if (!flag_dec)
10567 : : return MATCH_NO;
10568 : :
10569 : 2483 : m = gfc_match ("type");
10570 : 2483 : if (m != MATCH_YES)
10571 : : return m;
10572 : : /* If we already have an error in the buffer, it is probably from failing to
10573 : : * match a derived type data declaration. Let it happen. */
10574 : 20 : else if (gfc_error_flag_test ())
10575 : : return MATCH_NO;
10576 : :
10577 : 20 : old_loc = gfc_current_locus;
10578 : 20 : *st = ST_NONE;
10579 : :
10580 : : /* If we see an attribute list before anything else it's definitely a derived
10581 : : * type declaration. */
10582 : 20 : if (gfc_match (" ,") == MATCH_YES || gfc_match (" ::") == MATCH_YES)
10583 : 8 : goto derived;
10584 : :
10585 : : /* By now "TYPE" has already been matched. If we do not see a name, this may
10586 : : * be something like "TYPE *" or "TYPE <fmt>". */
10587 : 12 : m = gfc_match_name (name);
10588 : 12 : if (m != MATCH_YES)
10589 : : {
10590 : : /* Let print match if it can, otherwise throw an error from
10591 : : * gfc_match_derived_decl. */
10592 : 7 : gfc_current_locus = old_loc;
10593 : 7 : if (gfc_match_print () == MATCH_YES)
10594 : : {
10595 : 7 : *st = ST_WRITE;
10596 : 7 : return MATCH_YES;
10597 : : }
10598 : 0 : goto derived;
10599 : : }
10600 : :
10601 : : /* Check for EOS. */
10602 : 5 : if (gfc_match_eos () == MATCH_YES)
10603 : : {
10604 : : /* By now we have "TYPE <name> <EOS>". Check first if the name is an
10605 : : * intrinsic typename - if so let gfc_match_derived_decl dump an error.
10606 : : * Otherwise if gfc_match_derived_decl fails it's probably an existing
10607 : : * symbol which can be printed. */
10608 : 3 : gfc_current_locus = old_loc;
10609 : 3 : m = gfc_match_derived_decl ();
10610 : 3 : if (gfc_is_intrinsic_typename (name) || m == MATCH_YES)
10611 : : {
10612 : 2 : *st = ST_DERIVED_DECL;
10613 : 2 : return m;
10614 : : }
10615 : : }
10616 : : else
10617 : : {
10618 : : /* Here we have "TYPE <name>". Check for <TYPE IS (> or a PDT declaration
10619 : : like <type name(parameter)>. */
10620 : 2 : gfc_gobble_whitespace ();
10621 : 2 : bool paren = gfc_peek_ascii_char () == '(';
10622 : 2 : if (paren)
10623 : : {
10624 : 1 : if (strcmp ("is", name) == 0)
10625 : 1 : goto typeis;
10626 : : else
10627 : 0 : goto derived;
10628 : : }
10629 : : }
10630 : :
10631 : : /* Treat TYPE... like PRINT... */
10632 : 2 : gfc_current_locus = old_loc;
10633 : 2 : *st = ST_WRITE;
10634 : 2 : return gfc_match_print ();
10635 : :
10636 : 8 : derived:
10637 : 8 : gfc_current_locus = old_loc;
10638 : 8 : *st = ST_DERIVED_DECL;
10639 : 8 : return gfc_match_derived_decl ();
10640 : :
10641 : 1 : typeis:
10642 : 1 : gfc_current_locus = old_loc;
10643 : 1 : *st = ST_TYPE_IS;
10644 : 1 : return gfc_match_type_is ();
10645 : : }
10646 : :
10647 : :
10648 : : /* Match the beginning of a derived type declaration. If a type name
10649 : : was the result of a function, then it is possible to have a symbol
10650 : : already to be known as a derived type yet have no components. */
10651 : :
10652 : : match
10653 : 15272 : gfc_match_derived_decl (void)
10654 : : {
10655 : 15272 : char name[GFC_MAX_SYMBOL_LEN + 1];
10656 : 15272 : char parent[GFC_MAX_SYMBOL_LEN + 1];
10657 : 15272 : symbol_attribute attr;
10658 : 15272 : gfc_symbol *sym, *gensym;
10659 : 15272 : gfc_symbol *extended;
10660 : 15272 : match m;
10661 : 15272 : match is_type_attr_spec = MATCH_NO;
10662 : 15272 : bool seen_attr = false;
10663 : 15272 : gfc_interface *intr = NULL, *head;
10664 : 15272 : bool parameterized_type = false;
10665 : 15272 : bool seen_colons = false;
10666 : :
10667 : 15272 : if (gfc_comp_struct (gfc_current_state ()))
10668 : : return MATCH_NO;
10669 : :
10670 : 15268 : name[0] = '\0';
10671 : 15268 : parent[0] = '\0';
10672 : 15268 : gfc_clear_attr (&attr);
10673 : 15268 : extended = NULL;
10674 : :
10675 : 17972 : do
10676 : : {
10677 : 17972 : is_type_attr_spec = gfc_get_type_attr_spec (&attr, parent);
10678 : 17972 : if (is_type_attr_spec == MATCH_ERROR)
10679 : : return MATCH_ERROR;
10680 : 17969 : if (is_type_attr_spec == MATCH_YES)
10681 : 2704 : seen_attr = true;
10682 : 17969 : } while (is_type_attr_spec == MATCH_YES);
10683 : :
10684 : : /* Deal with derived type extensions. The extension attribute has
10685 : : been added to 'attr' but now the parent type must be found and
10686 : : checked. */
10687 : 15265 : if (parent[0])
10688 : 1428 : extended = check_extended_derived_type (parent);
10689 : :
10690 : 15265 : if (parent[0] && !extended)
10691 : : return MATCH_ERROR;
10692 : :
10693 : 15261 : m = gfc_match (" ::");
10694 : 15261 : if (m == MATCH_YES)
10695 : : {
10696 : : seen_colons = true;
10697 : : }
10698 : 9620 : else if (seen_attr)
10699 : : {
10700 : 5 : gfc_error ("Expected :: in TYPE definition at %C");
10701 : 5 : return MATCH_ERROR;
10702 : : }
10703 : :
10704 : : /* In free source form, need to check for TYPE XXX as oppose to TYPEXXX.
10705 : : But, we need to simply return for TYPE(. */
10706 : 9615 : if (m == MATCH_NO && gfc_current_form == FORM_FREE)
10707 : : {
10708 : 9567 : char c = gfc_peek_ascii_char ();
10709 : 9567 : if (c == '(')
10710 : : return m;
10711 : 9506 : if (!gfc_is_whitespace (c))
10712 : : {
10713 : 4 : gfc_error ("Mangled derived type definition at %C");
10714 : 4 : return MATCH_NO;
10715 : : }
10716 : : }
10717 : :
10718 : 15191 : m = gfc_match (" %n ", name);
10719 : 15191 : if (m != MATCH_YES)
10720 : : return m;
10721 : :
10722 : : /* Make sure that we don't identify TYPE IS (...) as a parameterized
10723 : : derived type named 'is'.
10724 : : TODO Expand the check, when 'name' = "is" by matching " (tname) "
10725 : : and checking if this is a(n intrinsic) typename. This picks up
10726 : : misplaced TYPE IS statements such as in select_type_1.f03. */
10727 : 15181 : if (gfc_peek_ascii_char () == '(')
10728 : : {
10729 : 3497 : if (gfc_current_state () == COMP_SELECT_TYPE
10730 : 208 : || (!seen_colons && !strcmp (name, "is")))
10731 : : return MATCH_NO;
10732 : : parameterized_type = true;
10733 : : }
10734 : :
10735 : 11890 : m = gfc_match_eos ();
10736 : 11890 : if (m != MATCH_YES && !parameterized_type)
10737 : : return m;
10738 : :
10739 : : /* Make sure the name is not the name of an intrinsic type. */
10740 : 11887 : if (gfc_is_intrinsic_typename (name))
10741 : : {
10742 : 18 : gfc_error ("Type name %qs at %C cannot be the same as an intrinsic "
10743 : : "type", name);
10744 : 18 : return MATCH_ERROR;
10745 : : }
10746 : :
10747 : 11869 : if (gfc_get_symbol (name, NULL, &gensym))
10748 : : return MATCH_ERROR;
10749 : :
10750 : 11869 : if (!gensym->attr.generic && gensym->ts.type != BT_UNKNOWN)
10751 : : {
10752 : 5 : if (gensym->ts.u.derived)
10753 : 0 : gfc_error ("Derived type name %qs at %C already has a basic type "
10754 : : "of %s", gensym->name, gfc_typename (&gensym->ts));
10755 : : else
10756 : 5 : gfc_error ("Derived type name %qs at %C already has a basic type",
10757 : : gensym->name);
10758 : 5 : return MATCH_ERROR;
10759 : : }
10760 : :
10761 : 11864 : if (!gensym->attr.generic
10762 : 11864 : && !gfc_add_generic (&gensym->attr, gensym->name, NULL))
10763 : : return MATCH_ERROR;
10764 : :
10765 : 11860 : if (!gensym->attr.function
10766 : 11860 : && !gfc_add_function (&gensym->attr, gensym->name, NULL))
10767 : : return MATCH_ERROR;
10768 : :
10769 : 11859 : if (gensym->attr.dummy)
10770 : : {
10771 : 1 : gfc_error ("Dummy argument %qs at %L cannot be a derived type at %C",
10772 : : name, &gensym->declared_at);
10773 : 1 : return MATCH_ERROR;
10774 : : }
10775 : :
10776 : 11858 : sym = gfc_find_dt_in_generic (gensym);
10777 : :
10778 : 11858 : if (sym && (sym->components != NULL || sym->attr.zero_comp))
10779 : : {
10780 : 1 : gfc_error ("Derived type definition of %qs at %C has already been "
10781 : : "defined", sym->name);
10782 : 1 : return MATCH_ERROR;
10783 : : }
10784 : :
10785 : 11857 : if (!sym)
10786 : : {
10787 : : /* Use upper case to save the actual derived-type symbol. */
10788 : 11772 : gfc_get_symbol (gfc_dt_upper_string (gensym->name), NULL, &sym);
10789 : 11772 : sym->name = gfc_get_string ("%s", gensym->name);
10790 : 11772 : head = gensym->generic;
10791 : 11772 : intr = gfc_get_interface ();
10792 : 11772 : intr->sym = sym;
10793 : 11772 : intr->where = gfc_current_locus;
10794 : 11772 : intr->sym->declared_at = gfc_current_locus;
10795 : 11772 : intr->next = head;
10796 : 11772 : gensym->generic = intr;
10797 : 11772 : gensym->attr.if_source = IFSRC_DECL;
10798 : : }
10799 : :
10800 : : /* The symbol may already have the derived attribute without the
10801 : : components. The ways this can happen is via a function
10802 : : definition, an INTRINSIC statement or a subtype in another
10803 : : derived type that is a pointer. The first part of the AND clause
10804 : : is true if the symbol is not the return value of a function. */
10805 : 11857 : if (sym->attr.flavor != FL_DERIVED
10806 : 11857 : && !gfc_add_flavor (&sym->attr, FL_DERIVED, sym->name, NULL))
10807 : : return MATCH_ERROR;
10808 : :
10809 : 11857 : if (attr.access != ACCESS_UNKNOWN
10810 : 11857 : && !gfc_add_access (&sym->attr, attr.access, sym->name, NULL))
10811 : : return MATCH_ERROR;
10812 : 11857 : else if (sym->attr.access == ACCESS_UNKNOWN
10813 : 11310 : && gensym->attr.access != ACCESS_UNKNOWN
10814 : 12164 : && !gfc_add_access (&sym->attr, gensym->attr.access,
10815 : : sym->name, NULL))
10816 : : return MATCH_ERROR;
10817 : :
10818 : 11857 : if (sym->attr.access != ACCESS_UNKNOWN
10819 : 854 : && gensym->attr.access == ACCESS_UNKNOWN)
10820 : 547 : gensym->attr.access = sym->attr.access;
10821 : :
10822 : : /* See if the derived type was labeled as bind(c). */
10823 : 11857 : if (attr.is_bind_c != 0)
10824 : 404 : sym->attr.is_bind_c = attr.is_bind_c;
10825 : :
10826 : : /* Construct the f2k_derived namespace if it is not yet there. */
10827 : 11857 : if (!sym->f2k_derived)
10828 : 11857 : sym->f2k_derived = gfc_get_namespace (NULL, 0);
10829 : :
10830 : 11857 : if (parameterized_type)
10831 : : {
10832 : : /* Ignore error or mismatches by going to the end of the statement
10833 : : in order to avoid the component declarations causing problems. */
10834 : 206 : m = gfc_match_formal_arglist (sym, 0, 0, true);
10835 : 206 : if (m != MATCH_YES)
10836 : 4 : gfc_error_recovery ();
10837 : : else
10838 : 202 : sym->attr.pdt_template = 1;
10839 : 206 : m = gfc_match_eos ();
10840 : 206 : if (m != MATCH_YES)
10841 : : {
10842 : 1 : gfc_error_recovery ();
10843 : 1 : gfc_error_now ("Garbage after PARAMETERIZED TYPE declaration at %C");
10844 : : }
10845 : : }
10846 : :
10847 : 11857 : if (extended && !sym->components)
10848 : : {
10849 : 1424 : gfc_component *p;
10850 : 1424 : gfc_formal_arglist *f, *g, *h;
10851 : :
10852 : : /* Add the extended derived type as the first component. */
10853 : 1424 : gfc_add_component (sym, parent, &p);
10854 : 1424 : extended->refs++;
10855 : 1424 : gfc_set_sym_referenced (extended);
10856 : :
10857 : 1424 : p->ts.type = BT_DERIVED;
10858 : 1424 : p->ts.u.derived = extended;
10859 : 1424 : p->initializer = gfc_default_initializer (&p->ts);
10860 : :
10861 : : /* Set extension level. */
10862 : 1424 : if (extended->attr.extension == 255)
10863 : : {
10864 : : /* Since the extension field is 8 bit wide, we can only have
10865 : : up to 255 extension levels. */
10866 : 0 : gfc_error ("Maximum extension level reached with type %qs at %L",
10867 : : extended->name, &extended->declared_at);
10868 : 0 : return MATCH_ERROR;
10869 : : }
10870 : 1424 : sym->attr.extension = extended->attr.extension + 1;
10871 : :
10872 : : /* Provide the links between the extended type and its extension. */
10873 : 1424 : if (!extended->f2k_derived)
10874 : 1 : extended->f2k_derived = gfc_get_namespace (NULL, 0);
10875 : :
10876 : : /* Copy the extended type-param-name-list from the extended type,
10877 : : append those of the extension and add the whole lot to the
10878 : : extension. */
10879 : 1424 : if (extended->attr.pdt_template)
10880 : : {
10881 : 22 : g = h = NULL;
10882 : 22 : sym->attr.pdt_template = 1;
10883 : 75 : for (f = extended->formal; f; f = f->next)
10884 : : {
10885 : 53 : if (f == extended->formal)
10886 : : {
10887 : 22 : g = gfc_get_formal_arglist ();
10888 : 22 : h = g;
10889 : : }
10890 : : else
10891 : : {
10892 : 31 : g->next = gfc_get_formal_arglist ();
10893 : 31 : g = g->next;
10894 : : }
10895 : 53 : g->sym = f->sym;
10896 : : }
10897 : 22 : g->next = sym->formal;
10898 : 22 : sym->formal = h;
10899 : : }
10900 : : }
10901 : :
10902 : 11857 : if (!sym->hash_value)
10903 : : /* Set the hash for the compound name for this type. */
10904 : 11857 : sym->hash_value = gfc_hash_value (sym);
10905 : :
10906 : : /* Take over the ABSTRACT attribute. */
10907 : 11857 : sym->attr.abstract = attr.abstract;
10908 : :
10909 : 11857 : gfc_new_block = sym;
10910 : :
10911 : 11857 : return MATCH_YES;
10912 : : }
10913 : :
10914 : :
10915 : : /* Cray Pointees can be declared as:
10916 : : pointer (ipt, a (n,m,...,*)) */
10917 : :
10918 : : match
10919 : 240 : gfc_mod_pointee_as (gfc_array_spec *as)
10920 : : {
10921 : 240 : as->cray_pointee = true; /* This will be useful to know later. */
10922 : 240 : if (as->type == AS_ASSUMED_SIZE)
10923 : 72 : as->cp_was_assumed = true;
10924 : 168 : else if (as->type == AS_ASSUMED_SHAPE)
10925 : : {
10926 : 0 : gfc_error ("Cray Pointee at %C cannot be assumed shape array");
10927 : 0 : return MATCH_ERROR;
10928 : : }
10929 : : return MATCH_YES;
10930 : : }
10931 : :
10932 : :
10933 : : /* Match the enum definition statement, here we are trying to match
10934 : : the first line of enum definition statement.
10935 : : Returns MATCH_YES if match is found. */
10936 : :
10937 : : match
10938 : 158 : gfc_match_enum (void)
10939 : : {
10940 : 158 : match m;
10941 : :
10942 : 158 : m = gfc_match_eos ();
10943 : 158 : if (m != MATCH_YES)
10944 : : return m;
10945 : :
10946 : 158 : if (!gfc_notify_std (GFC_STD_F2003, "ENUM and ENUMERATOR at %C"))
10947 : 0 : return MATCH_ERROR;
10948 : :
10949 : : return MATCH_YES;
10950 : : }
10951 : :
10952 : :
10953 : : /* Returns an initializer whose value is one higher than the value of the
10954 : : LAST_INITIALIZER argument. If the argument is NULL, the
10955 : : initializers value will be set to zero. The initializer's kind
10956 : : will be set to gfc_c_int_kind.
10957 : :
10958 : : If -fshort-enums is given, the appropriate kind will be selected
10959 : : later after all enumerators have been parsed. A warning is issued
10960 : : here if an initializer exceeds gfc_c_int_kind. */
10961 : :
10962 : : static gfc_expr *
10963 : 377 : enum_initializer (gfc_expr *last_initializer, locus where)
10964 : : {
10965 : 377 : gfc_expr *result;
10966 : 377 : result = gfc_get_constant_expr (BT_INTEGER, gfc_c_int_kind, &where);
10967 : :
10968 : 377 : mpz_init (result->value.integer);
10969 : :
10970 : 377 : if (last_initializer != NULL)
10971 : : {
10972 : 266 : mpz_add_ui (result->value.integer, last_initializer->value.integer, 1);
10973 : 266 : result->where = last_initializer->where;
10974 : :
10975 : 266 : if (gfc_check_integer_range (result->value.integer,
10976 : : gfc_c_int_kind) != ARITH_OK)
10977 : : {
10978 : 0 : gfc_error ("Enumerator exceeds the C integer type at %C");
10979 : 0 : return NULL;
10980 : : }
10981 : : }
10982 : : else
10983 : : {
10984 : : /* Control comes here, if it's the very first enumerator and no
10985 : : initializer has been given. It will be initialized to zero. */
10986 : 111 : mpz_set_si (result->value.integer, 0);
10987 : : }
10988 : :
10989 : : return result;
10990 : : }
10991 : :
10992 : :
10993 : : /* Match a variable name with an optional initializer. When this
10994 : : subroutine is called, a variable is expected to be parsed next.
10995 : : Depending on what is happening at the moment, updates either the
10996 : : symbol table or the current interface. */
10997 : :
10998 : : static match
10999 : 549 : enumerator_decl (void)
11000 : : {
11001 : 549 : char name[GFC_MAX_SYMBOL_LEN + 1];
11002 : 549 : gfc_expr *initializer;
11003 : 549 : gfc_array_spec *as = NULL;
11004 : 549 : gfc_symbol *sym;
11005 : 549 : locus var_locus;
11006 : 549 : match m;
11007 : 549 : bool t;
11008 : 549 : locus old_locus;
11009 : :
11010 : 549 : initializer = NULL;
11011 : 549 : old_locus = gfc_current_locus;
11012 : :
11013 : : /* When we get here, we've just matched a list of attributes and
11014 : : maybe a type and a double colon. The next thing we expect to see
11015 : : is the name of the symbol. */
11016 : 549 : m = gfc_match_name (name);
11017 : 549 : if (m != MATCH_YES)
11018 : 1 : goto cleanup;
11019 : :
11020 : 548 : var_locus = gfc_current_locus;
11021 : :
11022 : : /* OK, we've successfully matched the declaration. Now put the
11023 : : symbol in the current namespace. If we fail to create the symbol,
11024 : : bail out. */
11025 : 548 : if (!build_sym (name, 1, NULL, false, &as, &var_locus))
11026 : : {
11027 : 1 : m = MATCH_ERROR;
11028 : 1 : goto cleanup;
11029 : : }
11030 : :
11031 : : /* The double colon must be present in order to have initializers.
11032 : : Otherwise the statement is ambiguous with an assignment statement. */
11033 : 547 : if (colon_seen)
11034 : : {
11035 : 471 : if (gfc_match_char ('=') == MATCH_YES)
11036 : : {
11037 : 170 : m = gfc_match_init_expr (&initializer);
11038 : 170 : if (m == MATCH_NO)
11039 : : {
11040 : 0 : gfc_error ("Expected an initialization expression at %C");
11041 : 0 : m = MATCH_ERROR;
11042 : : }
11043 : :
11044 : 170 : if (m != MATCH_YES)
11045 : 2 : goto cleanup;
11046 : : }
11047 : : }
11048 : :
11049 : : /* If we do not have an initializer, the initialization value of the
11050 : : previous enumerator (stored in last_initializer) is incremented
11051 : : by 1 and is used to initialize the current enumerator. */
11052 : 545 : if (initializer == NULL)
11053 : 377 : initializer = enum_initializer (last_initializer, old_locus);
11054 : :
11055 : 545 : if (initializer == NULL || initializer->ts.type != BT_INTEGER)
11056 : : {
11057 : 2 : gfc_error ("ENUMERATOR %L not initialized with integer expression",
11058 : : &var_locus);
11059 : 2 : m = MATCH_ERROR;
11060 : 2 : goto cleanup;
11061 : : }
11062 : :
11063 : : /* Store this current initializer, for the next enumerator variable
11064 : : to be parsed. add_init_expr_to_sym() zeros initializer, so we
11065 : : use last_initializer below. */
11066 : 543 : last_initializer = initializer;
11067 : 543 : t = add_init_expr_to_sym (name, &initializer, &var_locus);
11068 : :
11069 : : /* Maintain enumerator history. */
11070 : 543 : gfc_find_symbol (name, NULL, 0, &sym);
11071 : 543 : create_enum_history (sym, last_initializer);
11072 : :
11073 : 543 : return (t) ? MATCH_YES : MATCH_ERROR;
11074 : :
11075 : 6 : cleanup:
11076 : : /* Free stuff up and return. */
11077 : 6 : gfc_free_expr (initializer);
11078 : :
11079 : 6 : return m;
11080 : : }
11081 : :
11082 : :
11083 : : /* Match the enumerator definition statement. */
11084 : :
11085 : : match
11086 : 762665 : gfc_match_enumerator_def (void)
11087 : : {
11088 : 762665 : match m;
11089 : 762665 : bool t;
11090 : :
11091 : 762665 : gfc_clear_ts (¤t_ts);
11092 : :
11093 : 762665 : m = gfc_match (" enumerator");
11094 : 762665 : if (m != MATCH_YES)
11095 : : return m;
11096 : :
11097 : 269 : m = gfc_match (" :: ");
11098 : 269 : if (m == MATCH_ERROR)
11099 : : return m;
11100 : :
11101 : 269 : colon_seen = (m == MATCH_YES);
11102 : :
11103 : 269 : if (gfc_current_state () != COMP_ENUM)
11104 : : {
11105 : 4 : gfc_error ("ENUM definition statement expected before %C");
11106 : 4 : gfc_free_enum_history ();
11107 : 4 : return MATCH_ERROR;
11108 : : }
11109 : :
11110 : 265 : (¤t_ts)->type = BT_INTEGER;
11111 : 265 : (¤t_ts)->kind = gfc_c_int_kind;
11112 : :
11113 : 265 : gfc_clear_attr (¤t_attr);
11114 : 265 : t = gfc_add_flavor (¤t_attr, FL_PARAMETER, NULL, NULL);
11115 : 265 : if (!t)
11116 : : {
11117 : 0 : m = MATCH_ERROR;
11118 : 0 : goto cleanup;
11119 : : }
11120 : :
11121 : 549 : for (;;)
11122 : : {
11123 : 549 : m = enumerator_decl ();
11124 : 549 : if (m == MATCH_ERROR)
11125 : : {
11126 : 6 : gfc_free_enum_history ();
11127 : 6 : goto cleanup;
11128 : : }
11129 : 543 : if (m == MATCH_NO)
11130 : : break;
11131 : :
11132 : 542 : if (gfc_match_eos () == MATCH_YES)
11133 : 256 : goto cleanup;
11134 : 286 : if (gfc_match_char (',') != MATCH_YES)
11135 : : break;
11136 : : }
11137 : :
11138 : 3 : if (gfc_current_state () == COMP_ENUM)
11139 : : {
11140 : 3 : gfc_free_enum_history ();
11141 : 3 : gfc_error ("Syntax error in ENUMERATOR definition at %C");
11142 : 3 : m = MATCH_ERROR;
11143 : : }
11144 : :
11145 : 0 : cleanup:
11146 : 265 : gfc_free_array_spec (current_as);
11147 : 265 : current_as = NULL;
11148 : 265 : return m;
11149 : :
11150 : : }
11151 : :
11152 : :
11153 : : /* Match binding attributes. */
11154 : :
11155 : : static match
11156 : 4330 : match_binding_attributes (gfc_typebound_proc* ba, bool generic, bool ppc)
11157 : : {
11158 : 4330 : bool found_passing = false;
11159 : 4330 : bool seen_ptr = false;
11160 : 4330 : match m = MATCH_YES;
11161 : :
11162 : : /* Initialize to defaults. Do so even before the MATCH_NO check so that in
11163 : : this case the defaults are in there. */
11164 : 4330 : ba->access = ACCESS_UNKNOWN;
11165 : 4330 : ba->pass_arg = NULL;
11166 : 4330 : ba->pass_arg_num = 0;
11167 : 4330 : ba->nopass = 0;
11168 : 4330 : ba->non_overridable = 0;
11169 : 4330 : ba->deferred = 0;
11170 : 4330 : ba->ppc = ppc;
11171 : :
11172 : : /* If we find a comma, we believe there are binding attributes. */
11173 : 4330 : m = gfc_match_char (',');
11174 : 4330 : if (m == MATCH_NO)
11175 : 2191 : goto done;
11176 : :
11177 : 2660 : do
11178 : : {
11179 : : /* Access specifier. */
11180 : :
11181 : 2660 : m = gfc_match (" public");
11182 : 2660 : if (m == MATCH_ERROR)
11183 : 0 : goto error;
11184 : 2660 : if (m == MATCH_YES)
11185 : : {
11186 : 232 : if (ba->access != ACCESS_UNKNOWN)
11187 : : {
11188 : 0 : gfc_error ("Duplicate access-specifier at %C");
11189 : 0 : goto error;
11190 : : }
11191 : :
11192 : 232 : ba->access = ACCESS_PUBLIC;
11193 : 232 : continue;
11194 : : }
11195 : :
11196 : 2428 : m = gfc_match (" private");
11197 : 2428 : if (m == MATCH_ERROR)
11198 : 0 : goto error;
11199 : 2428 : if (m == MATCH_YES)
11200 : : {
11201 : 127 : if (ba->access != ACCESS_UNKNOWN)
11202 : : {
11203 : 1 : gfc_error ("Duplicate access-specifier at %C");
11204 : 1 : goto error;
11205 : : }
11206 : :
11207 : 126 : ba->access = ACCESS_PRIVATE;
11208 : 126 : continue;
11209 : : }
11210 : :
11211 : : /* If inside GENERIC, the following is not allowed. */
11212 : 2301 : if (!generic)
11213 : : {
11214 : :
11215 : : /* NOPASS flag. */
11216 : 2300 : m = gfc_match (" nopass");
11217 : 2300 : if (m == MATCH_ERROR)
11218 : 0 : goto error;
11219 : 2300 : if (m == MATCH_YES)
11220 : : {
11221 : 688 : if (found_passing)
11222 : : {
11223 : 1 : gfc_error ("Binding attributes already specify passing,"
11224 : : " illegal NOPASS at %C");
11225 : 1 : goto error;
11226 : : }
11227 : :
11228 : 687 : found_passing = true;
11229 : 687 : ba->nopass = 1;
11230 : 687 : continue;
11231 : : }
11232 : :
11233 : : /* PASS possibly including argument. */
11234 : 1612 : m = gfc_match (" pass");
11235 : 1612 : if (m == MATCH_ERROR)
11236 : 0 : goto error;
11237 : 1612 : if (m == MATCH_YES)
11238 : : {
11239 : 884 : char arg[GFC_MAX_SYMBOL_LEN + 1];
11240 : :
11241 : 884 : if (found_passing)
11242 : : {
11243 : 2 : gfc_error ("Binding attributes already specify passing,"
11244 : : " illegal PASS at %C");
11245 : 2 : goto error;
11246 : : }
11247 : :
11248 : 882 : m = gfc_match (" ( %n )", arg);
11249 : 882 : if (m == MATCH_ERROR)
11250 : 0 : goto error;
11251 : 882 : if (m == MATCH_YES)
11252 : 474 : ba->pass_arg = gfc_get_string ("%s", arg);
11253 : 882 : gcc_assert ((m == MATCH_YES) == (ba->pass_arg != NULL));
11254 : :
11255 : 882 : found_passing = true;
11256 : 882 : ba->nopass = 0;
11257 : 882 : continue;
11258 : 882 : }
11259 : :
11260 : 728 : if (ppc)
11261 : : {
11262 : : /* POINTER flag. */
11263 : 411 : m = gfc_match (" pointer");
11264 : 411 : if (m == MATCH_ERROR)
11265 : 0 : goto error;
11266 : 411 : if (m == MATCH_YES)
11267 : : {
11268 : 411 : if (seen_ptr)
11269 : : {
11270 : 1 : gfc_error ("Duplicate POINTER attribute at %C");
11271 : 1 : goto error;
11272 : : }
11273 : :
11274 : 410 : seen_ptr = true;
11275 : 410 : continue;
11276 : : }
11277 : : }
11278 : : else
11279 : : {
11280 : : /* NON_OVERRIDABLE flag. */
11281 : 317 : m = gfc_match (" non_overridable");
11282 : 317 : if (m == MATCH_ERROR)
11283 : 0 : goto error;
11284 : 317 : if (m == MATCH_YES)
11285 : : {
11286 : 61 : if (ba->non_overridable)
11287 : : {
11288 : 1 : gfc_error ("Duplicate NON_OVERRIDABLE at %C");
11289 : 1 : goto error;
11290 : : }
11291 : :
11292 : 60 : ba->non_overridable = 1;
11293 : 60 : continue;
11294 : : }
11295 : :
11296 : : /* DEFERRED flag. */
11297 : 256 : m = gfc_match (" deferred");
11298 : 256 : if (m == MATCH_ERROR)
11299 : 0 : goto error;
11300 : 256 : if (m == MATCH_YES)
11301 : : {
11302 : 256 : if (ba->deferred)
11303 : : {
11304 : 1 : gfc_error ("Duplicate DEFERRED at %C");
11305 : 1 : goto error;
11306 : : }
11307 : :
11308 : 255 : ba->deferred = 1;
11309 : 255 : continue;
11310 : : }
11311 : : }
11312 : :
11313 : : }
11314 : :
11315 : : /* Nothing matching found. */
11316 : 1 : if (generic)
11317 : 1 : gfc_error ("Expected access-specifier at %C");
11318 : : else
11319 : 0 : gfc_error ("Expected binding attribute at %C");
11320 : 1 : goto error;
11321 : : }
11322 : 2652 : while (gfc_match_char (',') == MATCH_YES);
11323 : :
11324 : : /* NON_OVERRIDABLE and DEFERRED exclude themselves. */
11325 : 2131 : if (ba->non_overridable && ba->deferred)
11326 : : {
11327 : 1 : gfc_error ("NON_OVERRIDABLE and DEFERRED cannot both appear at %C");
11328 : 1 : goto error;
11329 : : }
11330 : :
11331 : : m = MATCH_YES;
11332 : :
11333 : 4321 : done:
11334 : 4321 : if (ba->access == ACCESS_UNKNOWN)
11335 : 3964 : ba->access = ppc ? gfc_current_block()->component_access
11336 : : : gfc_typebound_default_access;
11337 : :
11338 : 4321 : if (ppc && !seen_ptr)
11339 : : {
11340 : 2 : gfc_error ("POINTER attribute is required for procedure pointer component"
11341 : : " at %C");
11342 : 2 : goto error;
11343 : : }
11344 : :
11345 : : return m;
11346 : :
11347 : : error:
11348 : : return MATCH_ERROR;
11349 : : }
11350 : :
11351 : :
11352 : : /* Match a PROCEDURE specific binding inside a derived type. */
11353 : :
11354 : : static match
11355 : 3054 : match_procedure_in_type (void)
11356 : : {
11357 : 3054 : char name[GFC_MAX_SYMBOL_LEN + 1];
11358 : 3054 : char target_buf[GFC_MAX_SYMBOL_LEN + 1];
11359 : 3054 : char* target = NULL, *ifc = NULL;
11360 : 3054 : gfc_typebound_proc tb;
11361 : 3054 : bool seen_colons;
11362 : 3054 : bool seen_attrs;
11363 : 3054 : match m;
11364 : 3054 : gfc_symtree* stree;
11365 : 3054 : gfc_namespace* ns;
11366 : 3054 : gfc_symbol* block;
11367 : 3054 : int num;
11368 : :
11369 : : /* Check current state. */
11370 : 3054 : gcc_assert (gfc_state_stack->state == COMP_DERIVED_CONTAINS);
11371 : 3054 : block = gfc_state_stack->previous->sym;
11372 : 3054 : gcc_assert (block);
11373 : :
11374 : : /* Try to match PROCEDURE(interface). */
11375 : 3054 : if (gfc_match (" (") == MATCH_YES)
11376 : : {
11377 : 257 : m = gfc_match_name (target_buf);
11378 : 257 : if (m == MATCH_ERROR)
11379 : : return m;
11380 : 257 : if (m != MATCH_YES)
11381 : : {
11382 : 1 : gfc_error ("Interface-name expected after %<(%> at %C");
11383 : 1 : return MATCH_ERROR;
11384 : : }
11385 : :
11386 : 256 : if (gfc_match (" )") != MATCH_YES)
11387 : : {
11388 : 1 : gfc_error ("%<)%> expected at %C");
11389 : 1 : return MATCH_ERROR;
11390 : : }
11391 : :
11392 : : ifc = target_buf;
11393 : : }
11394 : :
11395 : : /* Construct the data structure. */
11396 : 3052 : memset (&tb, 0, sizeof (tb));
11397 : 3052 : tb.where = gfc_current_locus;
11398 : :
11399 : : /* Match binding attributes. */
11400 : 3052 : m = match_binding_attributes (&tb, false, false);
11401 : 3052 : if (m == MATCH_ERROR)
11402 : : return m;
11403 : 3045 : seen_attrs = (m == MATCH_YES);
11404 : :
11405 : : /* Check that attribute DEFERRED is given if an interface is specified. */
11406 : 3045 : if (tb.deferred && !ifc)
11407 : : {
11408 : 1 : gfc_error ("Interface must be specified for DEFERRED binding at %C");
11409 : 1 : return MATCH_ERROR;
11410 : : }
11411 : 3044 : if (ifc && !tb.deferred)
11412 : : {
11413 : 1 : gfc_error ("PROCEDURE(interface) at %C should be declared DEFERRED");
11414 : 1 : return MATCH_ERROR;
11415 : : }
11416 : :
11417 : : /* Match the colons. */
11418 : 3043 : m = gfc_match (" ::");
11419 : 3043 : if (m == MATCH_ERROR)
11420 : : return m;
11421 : 3043 : seen_colons = (m == MATCH_YES);
11422 : 3043 : if (seen_attrs && !seen_colons)
11423 : : {
11424 : 4 : gfc_error ("Expected %<::%> after binding-attributes at %C");
11425 : 4 : return MATCH_ERROR;
11426 : : }
11427 : :
11428 : : /* Match the binding names. */
11429 : 17 : for(num=1;;num++)
11430 : : {
11431 : 3056 : m = gfc_match_name (name);
11432 : 3056 : if (m == MATCH_ERROR)
11433 : : return m;
11434 : 3056 : if (m == MATCH_NO)
11435 : : {
11436 : 5 : gfc_error ("Expected binding name at %C");
11437 : 5 : return MATCH_ERROR;
11438 : : }
11439 : :
11440 : 3051 : if (num>1 && !gfc_notify_std (GFC_STD_F2008, "PROCEDURE list at %C"))
11441 : : return MATCH_ERROR;
11442 : :
11443 : : /* Try to match the '=> target', if it's there. */
11444 : 3050 : target = ifc;
11445 : 3050 : m = gfc_match (" =>");
11446 : 3050 : if (m == MATCH_ERROR)
11447 : : return m;
11448 : 3050 : if (m == MATCH_YES)
11449 : : {
11450 : 1231 : if (tb.deferred)
11451 : : {
11452 : 1 : gfc_error ("%<=> target%> is invalid for DEFERRED binding at %C");
11453 : 1 : return MATCH_ERROR;
11454 : : }
11455 : :
11456 : 1230 : if (!seen_colons)
11457 : : {
11458 : 1 : gfc_error ("%<::%> needed in PROCEDURE binding with explicit target"
11459 : : " at %C");
11460 : 1 : return MATCH_ERROR;
11461 : : }
11462 : :
11463 : 1229 : m = gfc_match_name (target_buf);
11464 : 1229 : if (m == MATCH_ERROR)
11465 : : return m;
11466 : 1229 : if (m == MATCH_NO)
11467 : : {
11468 : 2 : gfc_error ("Expected binding target after %<=>%> at %C");
11469 : 2 : return MATCH_ERROR;
11470 : : }
11471 : : target = target_buf;
11472 : : }
11473 : :
11474 : : /* If no target was found, it has the same name as the binding. */
11475 : 1819 : if (!target)
11476 : 1568 : target = name;
11477 : :
11478 : : /* Get the namespace to insert the symbols into. */
11479 : 3046 : ns = block->f2k_derived;
11480 : 3046 : gcc_assert (ns);
11481 : :
11482 : : /* If the binding is DEFERRED, check that the containing type is ABSTRACT. */
11483 : 3046 : if (tb.deferred && !block->attr.abstract)
11484 : : {
11485 : 1 : gfc_error ("Type %qs containing DEFERRED binding at %C "
11486 : : "is not ABSTRACT", block->name);
11487 : 1 : return MATCH_ERROR;
11488 : : }
11489 : :
11490 : : /* See if we already have a binding with this name in the symtree which
11491 : : would be an error. If a GENERIC already targeted this binding, it may
11492 : : be already there but then typebound is still NULL. */
11493 : 3045 : stree = gfc_find_symtree (ns->tb_sym_root, name);
11494 : 3045 : if (stree && stree->n.tb)
11495 : : {
11496 : 2 : gfc_error ("There is already a procedure with binding name %qs for "
11497 : : "the derived type %qs at %C", name, block->name);
11498 : 2 : return MATCH_ERROR;
11499 : : }
11500 : :
11501 : : /* Insert it and set attributes. */
11502 : :
11503 : 2968 : if (!stree)
11504 : : {
11505 : 2968 : stree = gfc_new_symtree (&ns->tb_sym_root, name);
11506 : 2968 : gcc_assert (stree);
11507 : : }
11508 : 3043 : stree->n.tb = gfc_get_typebound_proc (&tb);
11509 : :
11510 : 3043 : if (gfc_get_sym_tree (target, gfc_current_ns, &stree->n.tb->u.specific,
11511 : : false))
11512 : : return MATCH_ERROR;
11513 : 3043 : gfc_set_sym_referenced (stree->n.tb->u.specific->n.sym);
11514 : 3043 : gfc_add_flavor(&stree->n.tb->u.specific->n.sym->attr, FL_PROCEDURE,
11515 : 3043 : target, &stree->n.tb->u.specific->n.sym->declared_at);
11516 : :
11517 : 3043 : if (gfc_match_eos () == MATCH_YES)
11518 : : return MATCH_YES;
11519 : 18 : if (gfc_match_char (',') != MATCH_YES)
11520 : 1 : goto syntax;
11521 : : }
11522 : :
11523 : 1 : syntax:
11524 : 1 : gfc_error ("Syntax error in PROCEDURE statement at %C");
11525 : 1 : return MATCH_ERROR;
11526 : : }
11527 : :
11528 : :
11529 : : /* Match a GENERIC procedure binding inside a derived type. */
11530 : :
11531 : : match
11532 : 866 : gfc_match_generic (void)
11533 : : {
11534 : 866 : char name[GFC_MAX_SYMBOL_LEN + 1];
11535 : 866 : char bind_name[GFC_MAX_SYMBOL_LEN + 16]; /* Allow space for OPERATOR(...). */
11536 : 866 : gfc_symbol* block;
11537 : 866 : gfc_typebound_proc tbattr; /* Used for match_binding_attributes. */
11538 : 866 : gfc_typebound_proc* tb;
11539 : 866 : gfc_namespace* ns;
11540 : 866 : interface_type op_type;
11541 : 866 : gfc_intrinsic_op op;
11542 : 866 : match m;
11543 : :
11544 : : /* Check current state. */
11545 : 866 : if (gfc_current_state () == COMP_DERIVED)
11546 : : {
11547 : 0 : gfc_error ("GENERIC at %C must be inside a derived-type CONTAINS");
11548 : 0 : return MATCH_ERROR;
11549 : : }
11550 : 866 : if (gfc_current_state () != COMP_DERIVED_CONTAINS)
11551 : : return MATCH_NO;
11552 : 866 : block = gfc_state_stack->previous->sym;
11553 : 866 : ns = block->f2k_derived;
11554 : 866 : gcc_assert (block && ns);
11555 : :
11556 : 866 : memset (&tbattr, 0, sizeof (tbattr));
11557 : 866 : tbattr.where = gfc_current_locus;
11558 : :
11559 : : /* See if we get an access-specifier. */
11560 : 866 : m = match_binding_attributes (&tbattr, true, false);
11561 : 866 : if (m == MATCH_ERROR)
11562 : 1 : goto error;
11563 : :
11564 : : /* Now the colons, those are required. */
11565 : 865 : if (gfc_match (" ::") != MATCH_YES)
11566 : : {
11567 : 0 : gfc_error ("Expected %<::%> at %C");
11568 : 0 : goto error;
11569 : : }
11570 : :
11571 : : /* Match the binding name; depending on type (operator / generic) format
11572 : : it for future error messages into bind_name. */
11573 : :
11574 : 865 : m = gfc_match_generic_spec (&op_type, name, &op);
11575 : 865 : if (m == MATCH_ERROR)
11576 : : return MATCH_ERROR;
11577 : 865 : if (m == MATCH_NO)
11578 : : {
11579 : 0 : gfc_error ("Expected generic name or operator descriptor at %C");
11580 : 0 : goto error;
11581 : : }
11582 : :
11583 : 865 : switch (op_type)
11584 : : {
11585 : 441 : case INTERFACE_GENERIC:
11586 : 441 : case INTERFACE_DTIO:
11587 : 441 : snprintf (bind_name, sizeof (bind_name), "%s", name);
11588 : 441 : break;
11589 : :
11590 : 21 : case INTERFACE_USER_OP:
11591 : 21 : snprintf (bind_name, sizeof (bind_name), "OPERATOR(.%s.)", name);
11592 : 21 : break;
11593 : :
11594 : 402 : case INTERFACE_INTRINSIC_OP:
11595 : 402 : snprintf (bind_name, sizeof (bind_name), "OPERATOR(%s)",
11596 : : gfc_op2string (op));
11597 : 402 : break;
11598 : :
11599 : 1 : case INTERFACE_NAMELESS:
11600 : 1 : gfc_error ("Malformed GENERIC statement at %C");
11601 : 1 : goto error;
11602 : 0 : break;
11603 : :
11604 : 0 : default:
11605 : 0 : gcc_unreachable ();
11606 : : }
11607 : :
11608 : : /* Match the required =>. */
11609 : 864 : if (gfc_match (" =>") != MATCH_YES)
11610 : : {
11611 : 0 : gfc_error ("Expected %<=>%> at %C");
11612 : 0 : goto error;
11613 : : }
11614 : :
11615 : : /* Try to find existing GENERIC binding with this name / for this operator;
11616 : : if there is something, check that it is another GENERIC and then extend
11617 : : it rather than building a new node. Otherwise, create it and put it
11618 : : at the right position. */
11619 : :
11620 : 864 : switch (op_type)
11621 : : {
11622 : 462 : case INTERFACE_DTIO:
11623 : 462 : case INTERFACE_USER_OP:
11624 : 462 : case INTERFACE_GENERIC:
11625 : 462 : {
11626 : 462 : const bool is_op = (op_type == INTERFACE_USER_OP);
11627 : 462 : gfc_symtree* st;
11628 : :
11629 : 462 : st = gfc_find_symtree (is_op ? ns->tb_uop_root : ns->tb_sym_root, name);
11630 : 462 : tb = st ? st->n.tb : NULL;
11631 : 11 : break;
11632 : : }
11633 : :
11634 : 402 : case INTERFACE_INTRINSIC_OP:
11635 : 402 : tb = ns->tb_op[op];
11636 : 402 : break;
11637 : :
11638 : 0 : default:
11639 : 0 : gcc_unreachable ();
11640 : : }
11641 : :
11642 : 413 : if (tb)
11643 : : {
11644 : 9 : if (!tb->is_generic)
11645 : : {
11646 : 1 : gcc_assert (op_type == INTERFACE_GENERIC);
11647 : 1 : gfc_error ("There's already a non-generic procedure with binding name"
11648 : : " %qs for the derived type %qs at %C",
11649 : : bind_name, block->name);
11650 : 1 : goto error;
11651 : : }
11652 : :
11653 : 8 : if (tb->access != tbattr.access)
11654 : : {
11655 : 2 : gfc_error ("Binding at %C must have the same access as already"
11656 : : " defined binding %qs", bind_name);
11657 : 2 : goto error;
11658 : : }
11659 : : }
11660 : : else
11661 : : {
11662 : 855 : tb = gfc_get_typebound_proc (NULL);
11663 : 855 : tb->where = gfc_current_locus;
11664 : 855 : tb->access = tbattr.access;
11665 : 855 : tb->is_generic = 1;
11666 : 855 : tb->u.generic = NULL;
11667 : :
11668 : 855 : switch (op_type)
11669 : : {
11670 : 453 : case INTERFACE_DTIO:
11671 : 453 : case INTERFACE_GENERIC:
11672 : 453 : case INTERFACE_USER_OP:
11673 : 453 : {
11674 : 453 : const bool is_op = (op_type == INTERFACE_USER_OP);
11675 : 453 : gfc_symtree* st = gfc_get_tbp_symtree (is_op ? &ns->tb_uop_root :
11676 : : &ns->tb_sym_root, name);
11677 : 453 : gcc_assert (st);
11678 : 453 : st->n.tb = tb;
11679 : :
11680 : 453 : break;
11681 : : }
11682 : :
11683 : 402 : case INTERFACE_INTRINSIC_OP:
11684 : 402 : ns->tb_op[op] = tb;
11685 : 402 : break;
11686 : :
11687 : 0 : default:
11688 : 0 : gcc_unreachable ();
11689 : : }
11690 : : }
11691 : :
11692 : : /* Now, match all following names as specific targets. */
11693 : 990 : do
11694 : : {
11695 : 990 : gfc_symtree* target_st;
11696 : 990 : gfc_tbp_generic* target;
11697 : :
11698 : 990 : m = gfc_match_name (name);
11699 : 990 : if (m == MATCH_ERROR)
11700 : 0 : goto error;
11701 : 990 : if (m == MATCH_NO)
11702 : : {
11703 : 1 : gfc_error ("Expected specific binding name at %C");
11704 : 1 : goto error;
11705 : : }
11706 : :
11707 : 989 : target_st = gfc_get_tbp_symtree (&ns->tb_sym_root, name);
11708 : :
11709 : : /* See if this is a duplicate specification. */
11710 : 1178 : for (target = tb->u.generic; target; target = target->next)
11711 : 190 : if (target_st == target->specific_st)
11712 : : {
11713 : 1 : gfc_error ("%qs already defined as specific binding for the"
11714 : : " generic %qs at %C", name, bind_name);
11715 : 1 : goto error;
11716 : : }
11717 : :
11718 : 988 : target = gfc_get_tbp_generic ();
11719 : 988 : target->specific_st = target_st;
11720 : 988 : target->specific = NULL;
11721 : 988 : target->next = tb->u.generic;
11722 : 988 : target->is_operator = ((op_type == INTERFACE_USER_OP)
11723 : 988 : || (op_type == INTERFACE_INTRINSIC_OP));
11724 : 988 : tb->u.generic = target;
11725 : : }
11726 : 988 : while (gfc_match (" ,") == MATCH_YES);
11727 : :
11728 : : /* Here should be the end. */
11729 : 859 : if (gfc_match_eos () != MATCH_YES)
11730 : : {
11731 : 1 : gfc_error ("Junk after GENERIC binding at %C");
11732 : 1 : goto error;
11733 : : }
11734 : :
11735 : : return MATCH_YES;
11736 : :
11737 : : error:
11738 : : return MATCH_ERROR;
11739 : : }
11740 : :
11741 : :
11742 : : /* Match a FINAL declaration inside a derived type. */
11743 : :
11744 : : match
11745 : 396 : gfc_match_final_decl (void)
11746 : : {
11747 : 396 : char name[GFC_MAX_SYMBOL_LEN + 1];
11748 : 396 : gfc_symbol* sym;
11749 : 396 : match m;
11750 : 396 : gfc_namespace* module_ns;
11751 : 396 : bool first, last;
11752 : 396 : gfc_symbol* block;
11753 : :
11754 : 396 : if (gfc_current_form == FORM_FREE)
11755 : : {
11756 : 396 : char c = gfc_peek_ascii_char ();
11757 : 396 : if (!gfc_is_whitespace (c) && c != ':')
11758 : : return MATCH_NO;
11759 : : }
11760 : :
11761 : 395 : if (gfc_state_stack->state != COMP_DERIVED_CONTAINS)
11762 : : {
11763 : 1 : if (gfc_current_form == FORM_FIXED)
11764 : : return MATCH_NO;
11765 : :
11766 : 1 : gfc_error ("FINAL declaration at %C must be inside a derived type "
11767 : : "CONTAINS section");
11768 : 1 : return MATCH_ERROR;
11769 : : }
11770 : :
11771 : 394 : block = gfc_state_stack->previous->sym;
11772 : 394 : gcc_assert (block);
11773 : :
11774 : 394 : if (gfc_state_stack->previous->previous
11775 : 394 : && gfc_state_stack->previous->previous->state != COMP_MODULE
11776 : 6 : && gfc_state_stack->previous->previous->state != COMP_SUBMODULE)
11777 : : {
11778 : 0 : gfc_error ("Derived type declaration with FINAL at %C must be in the"
11779 : : " specification part of a MODULE");
11780 : 0 : return MATCH_ERROR;
11781 : : }
11782 : :
11783 : 394 : module_ns = gfc_current_ns;
11784 : 394 : gcc_assert (module_ns);
11785 : 394 : gcc_assert (module_ns->proc_name->attr.flavor == FL_MODULE);
11786 : :
11787 : : /* Match optional ::, don't care about MATCH_YES or MATCH_NO. */
11788 : 394 : if (gfc_match (" ::") == MATCH_ERROR)
11789 : : return MATCH_ERROR;
11790 : :
11791 : : /* Match the sequence of procedure names. */
11792 : : first = true;
11793 : : last = false;
11794 : 468 : do
11795 : : {
11796 : 468 : gfc_finalizer* f;
11797 : :
11798 : 468 : if (first && gfc_match_eos () == MATCH_YES)
11799 : : {
11800 : 2 : gfc_error ("Empty FINAL at %C");
11801 : 2 : return MATCH_ERROR;
11802 : : }
11803 : :
11804 : 466 : m = gfc_match_name (name);
11805 : 466 : if (m == MATCH_NO)
11806 : : {
11807 : 1 : gfc_error ("Expected module procedure name at %C");
11808 : 1 : return MATCH_ERROR;
11809 : : }
11810 : 465 : else if (m != MATCH_YES)
11811 : : return MATCH_ERROR;
11812 : :
11813 : 465 : if (gfc_match_eos () == MATCH_YES)
11814 : : last = true;
11815 : 75 : if (!last && gfc_match_char (',') != MATCH_YES)
11816 : : {
11817 : 1 : gfc_error ("Expected %<,%> at %C");
11818 : 1 : return MATCH_ERROR;
11819 : : }
11820 : :
11821 : 464 : if (gfc_get_symbol (name, module_ns, &sym))
11822 : : {
11823 : 0 : gfc_error ("Unknown procedure name %qs at %C", name);
11824 : 0 : return MATCH_ERROR;
11825 : : }
11826 : :
11827 : : /* Mark the symbol as module procedure. */
11828 : 464 : if (sym->attr.proc != PROC_MODULE
11829 : 464 : && !gfc_add_procedure (&sym->attr, PROC_MODULE, sym->name, NULL))
11830 : : return MATCH_ERROR;
11831 : :
11832 : : /* Check if we already have this symbol in the list, this is an error. */
11833 : 627 : for (f = block->f2k_derived->finalizers; f; f = f->next)
11834 : 164 : if (f->proc_sym == sym)
11835 : : {
11836 : 1 : gfc_error ("%qs at %C is already defined as FINAL procedure",
11837 : : name);
11838 : 1 : return MATCH_ERROR;
11839 : : }
11840 : :
11841 : : /* Add this symbol to the list of finalizers. */
11842 : 463 : gcc_assert (block->f2k_derived);
11843 : 463 : sym->refs++;
11844 : 463 : f = XCNEW (gfc_finalizer);
11845 : 463 : f->proc_sym = sym;
11846 : 463 : f->proc_tree = NULL;
11847 : 463 : f->where = gfc_current_locus;
11848 : 463 : f->next = block->f2k_derived->finalizers;
11849 : 463 : block->f2k_derived->finalizers = f;
11850 : :
11851 : 463 : first = false;
11852 : : }
11853 : 463 : while (!last);
11854 : :
11855 : : return MATCH_YES;
11856 : : }
11857 : :
11858 : :
11859 : : const ext_attr_t ext_attr_list[] = {
11860 : : { "dllimport", EXT_ATTR_DLLIMPORT, "dllimport" },
11861 : : { "dllexport", EXT_ATTR_DLLEXPORT, "dllexport" },
11862 : : { "cdecl", EXT_ATTR_CDECL, "cdecl" },
11863 : : { "stdcall", EXT_ATTR_STDCALL, "stdcall" },
11864 : : { "fastcall", EXT_ATTR_FASTCALL, "fastcall" },
11865 : : { "no_arg_check", EXT_ATTR_NO_ARG_CHECK, NULL },
11866 : : { "deprecated", EXT_ATTR_DEPRECATED, NULL },
11867 : : { "noinline", EXT_ATTR_NOINLINE, NULL },
11868 : : { "noreturn", EXT_ATTR_NORETURN, NULL },
11869 : : { "weak", EXT_ATTR_WEAK, NULL },
11870 : : { NULL, EXT_ATTR_LAST, NULL }
11871 : : };
11872 : :
11873 : : /* Match a !GCC$ ATTRIBUTES statement of the form:
11874 : : !GCC$ ATTRIBUTES attribute-list :: var-name [, var-name] ...
11875 : : When we come here, we have already matched the !GCC$ ATTRIBUTES string.
11876 : :
11877 : : TODO: We should support all GCC attributes using the same syntax for
11878 : : the attribute list, i.e. the list in C
11879 : : __attributes(( attribute-list ))
11880 : : matches then
11881 : : !GCC$ ATTRIBUTES attribute-list ::
11882 : : Cf. c-parser.cc's c_parser_attributes; the data can then directly be
11883 : : saved into a TREE.
11884 : :
11885 : : As there is absolutely no risk of confusion, we should never return
11886 : : MATCH_NO. */
11887 : : match
11888 : 2660 : gfc_match_gcc_attributes (void)
11889 : : {
11890 : 2660 : symbol_attribute attr;
11891 : 2660 : char name[GFC_MAX_SYMBOL_LEN + 1];
11892 : 2660 : unsigned id;
11893 : 2660 : gfc_symbol *sym;
11894 : 2660 : match m;
11895 : :
11896 : 2660 : gfc_clear_attr (&attr);
11897 : 2660 : for(;;)
11898 : : {
11899 : 2660 : char ch;
11900 : :
11901 : 2660 : if (gfc_match_name (name) != MATCH_YES)
11902 : : return MATCH_ERROR;
11903 : :
11904 : 16033 : for (id = 0; id < EXT_ATTR_LAST; id++)
11905 : 16033 : if (strcmp (name, ext_attr_list[id].name) == 0)
11906 : : break;
11907 : :
11908 : 2660 : if (id == EXT_ATTR_LAST)
11909 : : {
11910 : 0 : gfc_error ("Unknown attribute in !GCC$ ATTRIBUTES statement at %C");
11911 : 0 : return MATCH_ERROR;
11912 : : }
11913 : :
11914 : 2660 : if (!gfc_add_ext_attribute (&attr, (ext_attr_id_t)id, &gfc_current_locus))
11915 : : return MATCH_ERROR;
11916 : :
11917 : 2660 : gfc_gobble_whitespace ();
11918 : 2660 : ch = gfc_next_ascii_char ();
11919 : 2660 : if (ch == ':')
11920 : : {
11921 : : /* This is the successful exit condition for the loop. */
11922 : 2660 : if (gfc_next_ascii_char () == ':')
11923 : : break;
11924 : : }
11925 : :
11926 : 0 : if (ch == ',')
11927 : 0 : continue;
11928 : :
11929 : 0 : goto syntax;
11930 : 0 : }
11931 : :
11932 : 2660 : if (gfc_match_eos () == MATCH_YES)
11933 : 0 : goto syntax;
11934 : :
11935 : 2667 : for(;;)
11936 : : {
11937 : 2667 : m = gfc_match_name (name);
11938 : 2667 : if (m != MATCH_YES)
11939 : : return m;
11940 : :
11941 : 2667 : if (find_special (name, &sym, true))
11942 : : return MATCH_ERROR;
11943 : :
11944 : 2667 : sym->attr.ext_attr |= attr.ext_attr;
11945 : :
11946 : 2667 : if (gfc_match_eos () == MATCH_YES)
11947 : : break;
11948 : :
11949 : 7 : if (gfc_match_char (',') != MATCH_YES)
11950 : 0 : goto syntax;
11951 : : }
11952 : :
11953 : : return MATCH_YES;
11954 : :
11955 : 0 : syntax:
11956 : 0 : gfc_error ("Syntax error in !GCC$ ATTRIBUTES statement at %C");
11957 : 0 : return MATCH_ERROR;
11958 : : }
11959 : :
11960 : :
11961 : : /* Match a !GCC$ UNROLL statement of the form:
11962 : : !GCC$ UNROLL n
11963 : :
11964 : : The parameter n is the number of times we are supposed to unroll.
11965 : :
11966 : : When we come here, we have already matched the !GCC$ UNROLL string. */
11967 : : match
11968 : 19 : gfc_match_gcc_unroll (void)
11969 : : {
11970 : 19 : int value;
11971 : :
11972 : : /* FIXME: use gfc_match_small_literal_int instead, delete small_int */
11973 : 19 : if (gfc_match_small_int (&value) == MATCH_YES)
11974 : : {
11975 : 19 : if (value < 0 || value > USHRT_MAX)
11976 : : {
11977 : 2 : gfc_error ("%<GCC unroll%> directive requires a"
11978 : : " non-negative integral constant"
11979 : : " less than or equal to %u at %C",
11980 : : USHRT_MAX
11981 : : );
11982 : 2 : return MATCH_ERROR;
11983 : : }
11984 : 17 : if (gfc_match_eos () == MATCH_YES)
11985 : : {
11986 : 17 : directive_unroll = value == 0 ? 1 : value;
11987 : 17 : return MATCH_YES;
11988 : : }
11989 : : }
11990 : :
11991 : 0 : gfc_error ("Syntax error in !GCC$ UNROLL directive at %C");
11992 : 0 : return MATCH_ERROR;
11993 : : }
11994 : :
11995 : : /* Match a !GCC$ builtin (b) attributes simd flags if('target') form:
11996 : :
11997 : : The parameter b is name of a middle-end built-in.
11998 : : FLAGS is optional and must be one of:
11999 : : - (inbranch)
12000 : : - (notinbranch)
12001 : :
12002 : : IF('target') is optional and TARGET is a name of a multilib ABI.
12003 : :
12004 : : When we come here, we have already matched the !GCC$ builtin string. */
12005 : :
12006 : : match
12007 : 3285500 : gfc_match_gcc_builtin (void)
12008 : : {
12009 : 3285500 : char builtin[GFC_MAX_SYMBOL_LEN + 1];
12010 : 3285500 : char target[GFC_MAX_SYMBOL_LEN + 1];
12011 : :
12012 : 3285500 : if (gfc_match (" ( %n ) attributes simd", builtin) != MATCH_YES)
12013 : : return MATCH_ERROR;
12014 : :
12015 : 3285500 : gfc_simd_clause clause = SIMD_NONE;
12016 : 3285500 : if (gfc_match (" ( notinbranch ) ") == MATCH_YES)
12017 : : clause = SIMD_NOTINBRANCH;
12018 : 21 : else if (gfc_match (" ( inbranch ) ") == MATCH_YES)
12019 : 15 : clause = SIMD_INBRANCH;
12020 : :
12021 : 3285500 : if (gfc_match (" if ( '%n' ) ", target) == MATCH_YES)
12022 : : {
12023 : 3285471 : const char *abi = targetm.get_multilib_abi_name ();
12024 : 3285471 : if (abi == NULL || strcmp (abi, target) != 0)
12025 : : return MATCH_YES;
12026 : : }
12027 : :
12028 : 1620787 : if (gfc_vectorized_builtins == NULL)
12029 : 30020 : gfc_vectorized_builtins = new hash_map<nofree_string_hash, int> ();
12030 : :
12031 : 1620787 : char *r = XNEWVEC (char, strlen (builtin) + 32);
12032 : 1620787 : sprintf (r, "__builtin_%s", builtin);
12033 : :
12034 : 1620787 : bool existed;
12035 : 1620787 : int &value = gfc_vectorized_builtins->get_or_insert (r, &existed);
12036 : 1620787 : value |= clause;
12037 : 1620787 : if (existed)
12038 : 22 : free (r);
12039 : :
12040 : : return MATCH_YES;
12041 : : }
12042 : :
12043 : : /* Match an !GCC$ IVDEP statement.
12044 : : When we come here, we have already matched the !GCC$ IVDEP string. */
12045 : :
12046 : : match
12047 : 3 : gfc_match_gcc_ivdep (void)
12048 : : {
12049 : 3 : if (gfc_match_eos () == MATCH_YES)
12050 : : {
12051 : 3 : directive_ivdep = true;
12052 : 3 : return MATCH_YES;
12053 : : }
12054 : :
12055 : 0 : gfc_error ("Syntax error in !GCC$ IVDEP directive at %C");
12056 : 0 : return MATCH_ERROR;
12057 : : }
12058 : :
12059 : : /* Match an !GCC$ VECTOR statement.
12060 : : When we come here, we have already matched the !GCC$ VECTOR string. */
12061 : :
12062 : : match
12063 : 3 : gfc_match_gcc_vector (void)
12064 : : {
12065 : 3 : if (gfc_match_eos () == MATCH_YES)
12066 : : {
12067 : 3 : directive_vector = true;
12068 : 3 : directive_novector = false;
12069 : 3 : return MATCH_YES;
12070 : : }
12071 : :
12072 : 0 : gfc_error ("Syntax error in !GCC$ VECTOR directive at %C");
12073 : 0 : return MATCH_ERROR;
12074 : : }
12075 : :
12076 : : /* Match an !GCC$ NOVECTOR statement.
12077 : : When we come here, we have already matched the !GCC$ NOVECTOR string. */
12078 : :
12079 : : match
12080 : 3 : gfc_match_gcc_novector (void)
12081 : : {
12082 : 3 : if (gfc_match_eos () == MATCH_YES)
12083 : : {
12084 : 3 : directive_novector = true;
12085 : 3 : directive_vector = false;
12086 : 3 : return MATCH_YES;
12087 : : }
12088 : :
12089 : 0 : gfc_error ("Syntax error in !GCC$ NOVECTOR directive at %C");
12090 : 0 : return MATCH_ERROR;
12091 : : }
|