Branch data Line data Source code
1 : : /* Primary expression subroutines
2 : : Copyright (C) 2000-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 "gfortran.h"
26 : : #include "arith.h"
27 : : #include "match.h"
28 : : #include "parse.h"
29 : : #include "constructor.h"
30 : :
31 : : int matching_actual_arglist = 0;
32 : :
33 : : /* Matches a kind-parameter expression, which is either a named
34 : : symbolic constant or a nonnegative integer constant. If
35 : : successful, sets the kind value to the correct integer.
36 : : The argument 'is_iso_c' signals whether the kind is an ISO_C_BINDING
37 : : symbol like e.g. 'c_int'. */
38 : :
39 : : static match
40 : 470221 : match_kind_param (int *kind, int *is_iso_c)
41 : : {
42 : 470221 : char name[GFC_MAX_SYMBOL_LEN + 1];
43 : 470221 : gfc_symbol *sym;
44 : 470221 : match m;
45 : :
46 : 470221 : *is_iso_c = 0;
47 : :
48 : 470221 : m = gfc_match_small_literal_int (kind, NULL, false);
49 : 470221 : if (m != MATCH_NO)
50 : : return m;
51 : :
52 : 94725 : m = gfc_match_name (name, false);
53 : 94725 : if (m != MATCH_YES)
54 : : return m;
55 : :
56 : 92993 : if (gfc_find_symbol (name, NULL, 1, &sym))
57 : : return MATCH_ERROR;
58 : :
59 : 92993 : if (sym == NULL)
60 : : return MATCH_NO;
61 : :
62 : 92992 : *is_iso_c = sym->attr.is_iso_c;
63 : :
64 : 92992 : if (sym->attr.flavor != FL_PARAMETER)
65 : : return MATCH_NO;
66 : :
67 : 92992 : if (sym->value == NULL)
68 : : return MATCH_NO;
69 : :
70 : 92991 : if (gfc_extract_int (sym->value, kind))
71 : : return MATCH_NO;
72 : :
73 : 92991 : gfc_set_sym_referenced (sym);
74 : :
75 : 92991 : if (*kind < 0)
76 : : return MATCH_NO;
77 : :
78 : : return MATCH_YES;
79 : : }
80 : :
81 : :
82 : : /* Get a trailing kind-specification for non-character variables.
83 : : Returns:
84 : : * the integer kind value or
85 : : * -1 if an error was generated,
86 : : * -2 if no kind was found.
87 : : The argument 'is_iso_c' signals whether the kind is an ISO_C_BINDING
88 : : symbol like e.g. 'c_int'. */
89 : :
90 : : static int
91 : 4505764 : get_kind (int *is_iso_c)
92 : : {
93 : 4505764 : int kind;
94 : 4505764 : match m;
95 : :
96 : 4505764 : *is_iso_c = 0;
97 : :
98 : 4505764 : if (gfc_match_char ('_', false) != MATCH_YES)
99 : : return -2;
100 : :
101 : 470221 : m = match_kind_param (&kind, is_iso_c);
102 : 470221 : if (m == MATCH_NO)
103 : 1734 : gfc_error ("Missing kind-parameter at %C");
104 : :
105 : 470221 : return (m == MATCH_YES) ? kind : -1;
106 : : }
107 : :
108 : :
109 : : /* Given a character and a radix, see if the character is a valid
110 : : digit in that radix. */
111 : :
112 : : bool
113 : 30405395 : gfc_check_digit (char c, int radix)
114 : : {
115 : 30405395 : bool r;
116 : :
117 : 30405395 : switch (radix)
118 : : {
119 : 15638 : case 2:
120 : 15638 : r = ('0' <= c && c <= '1');
121 : 15638 : break;
122 : :
123 : 19182 : case 8:
124 : 19182 : r = ('0' <= c && c <= '7');
125 : 19182 : break;
126 : :
127 : 30305894 : case 10:
128 : 30305894 : r = ('0' <= c && c <= '9');
129 : 30305894 : break;
130 : :
131 : 64681 : case 16:
132 : 64681 : r = ISXDIGIT (c);
133 : 64681 : break;
134 : :
135 : 0 : default:
136 : 0 : gfc_internal_error ("gfc_check_digit(): bad radix");
137 : : }
138 : :
139 : 30405395 : return r;
140 : : }
141 : :
142 : :
143 : : /* Match the digit string part of an integer if signflag is not set,
144 : : the signed digit string part if signflag is set. If the buffer
145 : : is NULL, we just count characters for the resolution pass. Returns
146 : : the number of characters matched, -1 for no match. */
147 : :
148 : : static int
149 : 17738242 : match_digits (int signflag, int radix, char *buffer)
150 : : {
151 : 17738242 : locus old_loc;
152 : 17738242 : int length;
153 : 17738242 : char c;
154 : :
155 : 17738242 : length = 0;
156 : 17738242 : c = gfc_next_ascii_char ();
157 : :
158 : 17738242 : if (signflag && (c == '+' || c == '-'))
159 : : {
160 : 4798 : if (buffer != NULL)
161 : 1881 : *buffer++ = c;
162 : 4798 : gfc_gobble_whitespace ();
163 : 4798 : c = gfc_next_ascii_char ();
164 : 4798 : length++;
165 : : }
166 : :
167 : 17738242 : if (!gfc_check_digit (c, radix))
168 : : return -1;
169 : :
170 : 8493154 : length++;
171 : 8493154 : if (buffer != NULL)
172 : 4238420 : *buffer++ = c;
173 : :
174 : 16790688 : for (;;)
175 : : {
176 : 12641921 : old_loc = gfc_current_locus;
177 : 12641921 : c = gfc_next_ascii_char ();
178 : :
179 : 12641921 : if (!gfc_check_digit (c, radix))
180 : : break;
181 : :
182 : 4148767 : if (buffer != NULL)
183 : 2072112 : *buffer++ = c;
184 : 4148767 : length++;
185 : : }
186 : :
187 : 8493154 : gfc_current_locus = old_loc;
188 : :
189 : 8493154 : return length;
190 : : }
191 : :
192 : : /* Convert an integer string to an expression node. */
193 : :
194 : : static gfc_expr *
195 : 4131169 : convert_integer (const char *buffer, int kind, int radix, locus *where)
196 : : {
197 : 4131169 : gfc_expr *e;
198 : 4131169 : const char *t;
199 : :
200 : 4131169 : e = gfc_get_constant_expr (BT_INTEGER, kind, where);
201 : : /* A leading plus is allowed, but not by mpz_set_str. */
202 : 4131169 : if (buffer[0] == '+')
203 : 21 : t = buffer + 1;
204 : : else
205 : : t = buffer;
206 : 4131169 : mpz_set_str (e->value.integer, t, radix);
207 : :
208 : 4131169 : return e;
209 : : }
210 : :
211 : :
212 : : /* Convert an unsigned string to an expression node. XXX:
213 : : This needs a calculation modulo 2^n. TODO: Implement restriction
214 : : that no unary minus is permitted. */
215 : : static gfc_expr *
216 : 101372 : convert_unsigned (const char *buffer, int kind, int radix, locus *where)
217 : : {
218 : 101372 : gfc_expr *e;
219 : 101372 : const char *t;
220 : 101372 : int k;
221 : 101372 : arith rc;
222 : :
223 : 101372 : e = gfc_get_constant_expr (BT_UNSIGNED, kind, where);
224 : : /* A leading plus is allowed, but not by mpz_set_str. */
225 : 101372 : if (buffer[0] == '+')
226 : 0 : t = buffer + 1;
227 : : else
228 : : t = buffer;
229 : :
230 : 101372 : mpz_set_str (e->value.integer, t, radix);
231 : :
232 : 101372 : k = gfc_validate_kind (BT_UNSIGNED, kind, false);
233 : :
234 : : /* TODO Maybe move this somewhere else. */
235 : 101372 : rc = gfc_range_check (e);
236 : 101372 : if (rc != ARITH_OK)
237 : : {
238 : 2 : if (pedantic)
239 : 1 : gfc_error_now (gfc_arith_error (rc), &e->where);
240 : : else
241 : 1 : gfc_warning (0, gfc_arith_error (rc), &e->where);
242 : : }
243 : :
244 : 101372 : gfc_convert_mpz_to_unsigned (e->value.integer, gfc_unsigned_kinds[k].bit_size,
245 : : false);
246 : :
247 : 101372 : return e;
248 : : }
249 : :
250 : : /* Convert a real string to an expression node. */
251 : :
252 : : static gfc_expr *
253 : 214991 : convert_real (const char *buffer, int kind, locus *where)
254 : : {
255 : 214991 : gfc_expr *e;
256 : :
257 : 214991 : e = gfc_get_constant_expr (BT_REAL, kind, where);
258 : 214991 : mpfr_set_str (e->value.real, buffer, 10, GFC_RND_MODE);
259 : :
260 : 214991 : return e;
261 : : }
262 : :
263 : :
264 : : /* Convert a pair of real, constant expression nodes to a single
265 : : complex expression node. */
266 : :
267 : : static gfc_expr *
268 : 6775 : convert_complex (gfc_expr *real, gfc_expr *imag, int kind)
269 : : {
270 : 6775 : gfc_expr *e;
271 : :
272 : 6775 : e = gfc_get_constant_expr (BT_COMPLEX, kind, &real->where);
273 : 6775 : mpc_set_fr_fr (e->value.complex, real->value.real, imag->value.real,
274 : : GFC_MPC_RND_MODE);
275 : :
276 : 6775 : return e;
277 : : }
278 : :
279 : :
280 : : /* Match an integer (digit string and optional kind).
281 : : A sign will be accepted if signflag is set. */
282 : :
283 : : static match
284 : 12906680 : match_integer_constant (gfc_expr **result, int signflag)
285 : : {
286 : 12906680 : int length, kind, is_iso_c;
287 : 12906680 : locus old_loc;
288 : 12906680 : char *buffer;
289 : 12906680 : gfc_expr *e;
290 : :
291 : 12906680 : old_loc = gfc_current_locus;
292 : 12906680 : gfc_gobble_whitespace ();
293 : :
294 : 12906680 : length = match_digits (signflag, 10, NULL);
295 : 12906680 : gfc_current_locus = old_loc;
296 : 12906680 : if (length == -1)
297 : : return MATCH_NO;
298 : :
299 : 4132903 : buffer = (char *) alloca (length + 1);
300 : 4132903 : memset (buffer, '\0', length + 1);
301 : :
302 : 4132903 : gfc_gobble_whitespace ();
303 : :
304 : 4132903 : match_digits (signflag, 10, buffer);
305 : :
306 : 4132903 : kind = get_kind (&is_iso_c);
307 : 4132903 : if (kind == -2)
308 : 3827282 : kind = gfc_default_integer_kind;
309 : 4132903 : if (kind == -1)
310 : : return MATCH_ERROR;
311 : :
312 : 4131173 : if (kind == 4 && flag_integer4_kind == 8)
313 : 0 : kind = 8;
314 : :
315 : 4131173 : if (gfc_validate_kind (BT_INTEGER, kind, true) < 0)
316 : : {
317 : 4 : gfc_error ("Integer kind %d at %C not available", kind);
318 : 4 : return MATCH_ERROR;
319 : : }
320 : :
321 : 4131169 : e = convert_integer (buffer, kind, 10, &gfc_current_locus);
322 : 4131169 : e->ts.is_c_interop = is_iso_c;
323 : :
324 : 4131169 : if (gfc_range_check (e) != ARITH_OK)
325 : : {
326 : 9586 : gfc_error ("Integer too big for its kind at %C. This check can be "
327 : : "disabled with the option %<-fno-range-check%>");
328 : :
329 : 9586 : gfc_free_expr (e);
330 : 9586 : return MATCH_ERROR;
331 : : }
332 : :
333 : 4121583 : *result = e;
334 : 4121583 : return MATCH_YES;
335 : : }
336 : :
337 : : /* Match an unsigned constant (an integer with suffix u). No sign
338 : : is currently accepted, in accordance with 24-116.txt, but that
339 : : could be changed later. This is very much like the integer
340 : : constant matching above, but with enough differences to put it into
341 : : its own function. */
342 : :
343 : : static match
344 : 588996 : match_unsigned_constant (gfc_expr **result)
345 : : {
346 : 588996 : int length, kind, is_iso_c;
347 : 588996 : locus old_loc;
348 : 588996 : char *buffer;
349 : 588996 : gfc_expr *e;
350 : 588996 : match m;
351 : :
352 : 588996 : old_loc = gfc_current_locus;
353 : 588996 : gfc_gobble_whitespace ();
354 : :
355 : 588996 : length = match_digits (/* signflag = */ false, 10, NULL);
356 : :
357 : 588996 : if (length == -1)
358 : 471311 : goto fail;
359 : :
360 : 117685 : m = gfc_match_char ('u');
361 : 117685 : if (m == MATCH_NO)
362 : 16313 : goto fail;
363 : :
364 : 101372 : gfc_current_locus = old_loc;
365 : :
366 : 101372 : buffer = (char *) alloca (length + 1);
367 : 101372 : memset (buffer, '\0', length + 1);
368 : :
369 : 101372 : gfc_gobble_whitespace ();
370 : :
371 : 101372 : match_digits (false, 10, buffer);
372 : :
373 : 101372 : m = gfc_match_char ('u');
374 : 101372 : if (m == MATCH_NO)
375 : 0 : goto fail;
376 : :
377 : 101372 : kind = get_kind (&is_iso_c);
378 : 101372 : if (kind == -2)
379 : 8357 : kind = gfc_default_unsigned_kind;
380 : 101372 : if (kind == -1)
381 : : return MATCH_ERROR;
382 : :
383 : 101372 : if (kind == 4 && flag_integer4_kind == 8)
384 : 0 : kind = 8;
385 : :
386 : 101372 : if (gfc_validate_kind (BT_UNSIGNED, kind, true) < 0)
387 : : {
388 : 0 : gfc_error ("Unsigned kind %d at %C not available", kind);
389 : 0 : return MATCH_ERROR;
390 : : }
391 : :
392 : 101372 : e = convert_unsigned (buffer, kind, 10, &gfc_current_locus);
393 : 101372 : e->ts.is_c_interop = is_iso_c;
394 : :
395 : 101372 : *result = e;
396 : 101372 : return MATCH_YES;
397 : :
398 : 487624 : fail:
399 : 487624 : gfc_current_locus = old_loc;
400 : 487624 : return MATCH_NO;
401 : : }
402 : :
403 : : /* Match a Hollerith constant. */
404 : :
405 : : static match
406 : 6459624 : match_hollerith_constant (gfc_expr **result)
407 : : {
408 : 6459624 : locus old_loc;
409 : 6459624 : gfc_expr *e = NULL;
410 : 6459624 : int num, pad;
411 : 6459624 : int i;
412 : :
413 : 6459624 : old_loc = gfc_current_locus;
414 : 6459624 : gfc_gobble_whitespace ();
415 : :
416 : 6459624 : if (match_integer_constant (&e, 0) == MATCH_YES
417 : 6459624 : && gfc_match_char ('h') == MATCH_YES)
418 : : {
419 : 2636 : if (!gfc_notify_std (GFC_STD_LEGACY, "Hollerith constant at %C"))
420 : 14 : goto cleanup;
421 : :
422 : 2622 : if (gfc_extract_int (e, &num, 1))
423 : 0 : goto cleanup;
424 : 2622 : if (num == 0)
425 : : {
426 : 1 : gfc_error ("Invalid Hollerith constant: %L must contain at least "
427 : : "one character", &old_loc);
428 : 1 : goto cleanup;
429 : : }
430 : 2621 : if (e->ts.kind != gfc_default_integer_kind)
431 : : {
432 : 1 : gfc_error ("Invalid Hollerith constant: Integer kind at %L "
433 : : "should be default", &old_loc);
434 : 1 : goto cleanup;
435 : : }
436 : : else
437 : : {
438 : 2620 : gfc_free_expr (e);
439 : 2620 : e = gfc_get_constant_expr (BT_HOLLERITH, gfc_default_character_kind,
440 : : &gfc_current_locus);
441 : :
442 : : /* Calculate padding needed to fit default integer memory. */
443 : 2620 : pad = gfc_default_integer_kind - (num % gfc_default_integer_kind);
444 : :
445 : 2620 : e->representation.string = XCNEWVEC (char, num + pad + 1);
446 : :
447 : 14886 : for (i = 0; i < num; i++)
448 : : {
449 : 12266 : gfc_char_t c = gfc_next_char_literal (INSTRING_WARN);
450 : 12266 : if (! gfc_wide_fits_in_byte (c))
451 : : {
452 : 0 : gfc_error ("Invalid Hollerith constant at %L contains a "
453 : : "wide character", &old_loc);
454 : 0 : goto cleanup;
455 : : }
456 : :
457 : 12266 : e->representation.string[i] = (unsigned char) c;
458 : : }
459 : :
460 : : /* Now pad with blanks and end with a null char. */
461 : 11762 : for (i = 0; i < pad; i++)
462 : 9142 : e->representation.string[num + i] = ' ';
463 : :
464 : 2620 : e->representation.string[num + i] = '\0';
465 : 2620 : e->representation.length = num + pad;
466 : 2620 : e->ts.u.pad = pad;
467 : :
468 : 2620 : *result = e;
469 : 2620 : return MATCH_YES;
470 : : }
471 : : }
472 : :
473 : 6456988 : gfc_free_expr (e);
474 : 6456988 : gfc_current_locus = old_loc;
475 : 6456988 : return MATCH_NO;
476 : :
477 : 16 : cleanup:
478 : 16 : gfc_free_expr (e);
479 : 16 : return MATCH_ERROR;
480 : : }
481 : :
482 : :
483 : : /* Match a binary, octal or hexadecimal constant that can be found in
484 : : a DATA statement. The standard permits b'010...', o'73...', and
485 : : z'a1...' where b, o, and z can be capital letters. This function
486 : : also accepts postfixed forms of the constants: '01...'b, '73...'o,
487 : : and 'a1...'z. An additional extension is the use of x for z. */
488 : :
489 : : static match
490 : 6665075 : match_boz_constant (gfc_expr **result)
491 : : {
492 : 6665075 : int radix, length, x_hex;
493 : 6665075 : locus old_loc, start_loc;
494 : 6665075 : char *buffer, post, delim;
495 : 6665075 : gfc_expr *e;
496 : :
497 : 6665075 : start_loc = old_loc = gfc_current_locus;
498 : 6665075 : gfc_gobble_whitespace ();
499 : :
500 : 6665075 : x_hex = 0;
501 : 6665075 : switch (post = gfc_next_ascii_char ())
502 : : {
503 : : case 'b':
504 : : radix = 2;
505 : : post = 0;
506 : : break;
507 : 53926 : case 'o':
508 : 53926 : radix = 8;
509 : 53926 : post = 0;
510 : 53926 : break;
511 : 90103 : case 'x':
512 : 90103 : x_hex = 1;
513 : : /* Fall through. */
514 : : case 'z':
515 : : radix = 16;
516 : : post = 0;
517 : : break;
518 : : case '\'':
519 : : /* Fall through. */
520 : : case '\"':
521 : : delim = post;
522 : : post = 1;
523 : : radix = 16; /* Set to accept any valid digit string. */
524 : : break;
525 : 6383682 : default:
526 : 6383682 : goto backup;
527 : : }
528 : :
529 : : /* No whitespace allowed here. */
530 : :
531 : 53926 : if (post == 0)
532 : 281368 : delim = gfc_next_ascii_char ();
533 : :
534 : 281393 : if (delim != '\'' && delim != '\"')
535 : 277245 : goto backup;
536 : :
537 : 4148 : if (x_hex
538 : 4148 : && gfc_invalid_boz (G_("Hexadecimal constant at %L uses "
539 : : "nonstandard X instead of Z"), &gfc_current_locus))
540 : : return MATCH_ERROR;
541 : :
542 : 4146 : old_loc = gfc_current_locus;
543 : :
544 : 4146 : length = match_digits (0, radix, NULL);
545 : 4146 : if (length == -1)
546 : : {
547 : 0 : gfc_error ("Empty set of digits in BOZ constant at %C");
548 : 0 : return MATCH_ERROR;
549 : : }
550 : :
551 : 4146 : if (gfc_next_ascii_char () != delim)
552 : : {
553 : 0 : gfc_error ("Illegal character in BOZ constant at %C");
554 : 0 : return MATCH_ERROR;
555 : : }
556 : :
557 : 4146 : if (post == 1)
558 : : {
559 : 25 : switch (gfc_next_ascii_char ())
560 : : {
561 : : case 'b':
562 : : radix = 2;
563 : : break;
564 : 6 : case 'o':
565 : 6 : radix = 8;
566 : 6 : break;
567 : 13 : case 'x':
568 : : /* Fall through. */
569 : 13 : case 'z':
570 : 13 : radix = 16;
571 : 13 : break;
572 : 0 : default:
573 : 0 : goto backup;
574 : : }
575 : :
576 : 25 : if (gfc_invalid_boz (G_("BOZ constant at %C uses nonstandard postfix "
577 : : "syntax"), &gfc_current_locus))
578 : : return MATCH_ERROR;
579 : : }
580 : :
581 : 4145 : gfc_current_locus = old_loc;
582 : :
583 : 4145 : buffer = (char *) alloca (length + 1);
584 : 4145 : memset (buffer, '\0', length + 1);
585 : :
586 : 4145 : match_digits (0, radix, buffer);
587 : 4145 : gfc_next_ascii_char (); /* Eat delimiter. */
588 : 4145 : if (post == 1)
589 : 24 : gfc_next_ascii_char (); /* Eat postfixed b, o, z, or x. */
590 : :
591 : 4145 : e = gfc_get_expr ();
592 : 4145 : e->expr_type = EXPR_CONSTANT;
593 : 4145 : e->ts.type = BT_BOZ;
594 : 4145 : e->where = gfc_current_locus;
595 : 4145 : e->boz.rdx = radix;
596 : 4145 : e->boz.len = length;
597 : 4145 : e->boz.str = XCNEWVEC (char, length + 1);
598 : 4145 : strncpy (e->boz.str, buffer, length);
599 : :
600 : 4145 : if (!gfc_in_match_data ()
601 : 4145 : && (!gfc_notify_std(GFC_STD_F2003, "BOZ used outside a DATA "
602 : : "statement at %L", &e->where)))
603 : : return MATCH_ERROR;
604 : :
605 : 4140 : *result = e;
606 : 4140 : return MATCH_YES;
607 : :
608 : 6660927 : backup:
609 : 6660927 : gfc_current_locus = start_loc;
610 : 6660927 : return MATCH_NO;
611 : : }
612 : :
613 : :
614 : : /* Match a real constant of some sort. Allow a signed constant if signflag
615 : : is nonzero. */
616 : :
617 : : static match
618 : 6766069 : match_real_constant (gfc_expr **result, int signflag)
619 : : {
620 : 6766069 : int kind, count, seen_dp, seen_digits, is_iso_c, default_exponent;
621 : 6766069 : locus old_loc, temp_loc;
622 : 6766069 : char *p, *buffer, c, exp_char;
623 : 6766069 : gfc_expr *e;
624 : 6766069 : bool negate;
625 : :
626 : 6766069 : old_loc = gfc_current_locus;
627 : 6766069 : gfc_gobble_whitespace ();
628 : :
629 : 6766069 : e = NULL;
630 : :
631 : 6766069 : default_exponent = 0;
632 : 6766069 : count = 0;
633 : 6766069 : seen_dp = 0;
634 : 6766069 : seen_digits = 0;
635 : 6766069 : exp_char = ' ';
636 : 6766069 : negate = false;
637 : :
638 : 6766069 : c = gfc_next_ascii_char ();
639 : 6766069 : if (signflag && (c == '+' || c == '-'))
640 : : {
641 : 5904 : if (c == '-')
642 : 5768 : negate = true;
643 : :
644 : 5904 : gfc_gobble_whitespace ();
645 : 5904 : c = gfc_next_ascii_char ();
646 : : }
647 : :
648 : : /* Scan significand. */
649 : 3869047 : for (;; c = gfc_next_ascii_char (), count++)
650 : : {
651 : 10635116 : if (c == '.')
652 : : {
653 : 275415 : if (seen_dp)
654 : 204 : goto done;
655 : :
656 : : /* Check to see if "." goes with a following operator like
657 : : ".eq.". */
658 : 275211 : temp_loc = gfc_current_locus;
659 : 275211 : c = gfc_next_ascii_char ();
660 : :
661 : 275211 : if (c == 'e' || c == 'd' || c == 'q')
662 : : {
663 : 17670 : c = gfc_next_ascii_char ();
664 : 17670 : if (c == '.')
665 : 0 : goto done; /* Operator named .e. or .d. */
666 : : }
667 : :
668 : 275211 : if (ISALPHA (c))
669 : 66778 : goto done; /* Distinguish 1.e9 from 1.eq.2 */
670 : :
671 : 208433 : gfc_current_locus = temp_loc;
672 : 208433 : seen_dp = 1;
673 : 208433 : continue;
674 : : }
675 : :
676 : 10359701 : if (ISDIGIT (c))
677 : : {
678 : 3660614 : seen_digits = 1;
679 : 3660614 : continue;
680 : : }
681 : :
682 : 6699087 : break;
683 : : }
684 : :
685 : 6699087 : if (!seen_digits || (c != 'e' && c != 'd' && c != 'q'))
686 : 2297689 : goto done;
687 : 37313 : exp_char = c;
688 : :
689 : :
690 : 37313 : if (c == 'q')
691 : : {
692 : 0 : if (!gfc_notify_std (GFC_STD_GNU, "exponent-letter %<q%> in "
693 : : "real-literal-constant at %C"))
694 : : return MATCH_ERROR;
695 : 0 : else if (warn_real_q_constant)
696 : 0 : gfc_warning (OPT_Wreal_q_constant,
697 : : "Extension: exponent-letter %<q%> in real-literal-constant "
698 : : "at %C");
699 : : }
700 : :
701 : : /* Scan exponent. */
702 : 37313 : c = gfc_next_ascii_char ();
703 : 37313 : count++;
704 : :
705 : 37313 : if (c == '+' || c == '-')
706 : : { /* optional sign */
707 : 6750 : c = gfc_next_ascii_char ();
708 : 6750 : count++;
709 : : }
710 : :
711 : 37313 : if (!ISDIGIT (c))
712 : : {
713 : : /* With -fdec, default exponent to 0 instead of complaining. */
714 : 40 : if (flag_dec)
715 : 37303 : default_exponent = 1;
716 : : else
717 : : {
718 : 10 : gfc_error ("Missing exponent in real number at %C");
719 : 10 : return MATCH_ERROR;
720 : : }
721 : : }
722 : :
723 : 77397 : while (ISDIGIT (c))
724 : : {
725 : 40094 : c = gfc_next_ascii_char ();
726 : 40094 : count++;
727 : : }
728 : :
729 : 6766059 : done:
730 : : /* Check that we have a numeric constant. */
731 : 6766059 : if (!seen_digits || (!seen_dp && exp_char == ' '))
732 : : {
733 : 6551064 : gfc_current_locus = old_loc;
734 : 6551064 : return MATCH_NO;
735 : : }
736 : :
737 : : /* Convert the number. */
738 : 214995 : gfc_current_locus = old_loc;
739 : 214995 : gfc_gobble_whitespace ();
740 : :
741 : 214995 : buffer = (char *) alloca (count + default_exponent + 1);
742 : 214995 : memset (buffer, '\0', count + default_exponent + 1);
743 : :
744 : 214995 : p = buffer;
745 : 214995 : c = gfc_next_ascii_char ();
746 : 214995 : if (c == '+' || c == '-')
747 : : {
748 : 2987 : gfc_gobble_whitespace ();
749 : 2987 : c = gfc_next_ascii_char ();
750 : : }
751 : :
752 : : /* Hack for mpfr_set_str(). */
753 : 1391051 : for (;;)
754 : : {
755 : 803023 : if (c == 'd' || c == 'q')
756 : 29909 : *p = 'e';
757 : : else
758 : 773114 : *p = c;
759 : 803023 : p++;
760 : 803023 : if (--count == 0)
761 : : break;
762 : :
763 : 588028 : c = gfc_next_ascii_char ();
764 : : }
765 : 214995 : if (default_exponent)
766 : 30 : *p++ = '0';
767 : :
768 : 214995 : kind = get_kind (&is_iso_c);
769 : 214995 : if (kind == -1)
770 : 4 : goto cleanup;
771 : :
772 : 214991 : if (kind == 4)
773 : : {
774 : 20358 : if (flag_real4_kind == 8)
775 : 192 : kind = 8;
776 : 20358 : if (flag_real4_kind == 10)
777 : 192 : kind = 10;
778 : 20358 : if (flag_real4_kind == 16)
779 : 384 : kind = 16;
780 : : }
781 : 194633 : else if (kind == 8)
782 : : {
783 : 26686 : if (flag_real8_kind == 4)
784 : 192 : kind = 4;
785 : 26686 : if (flag_real8_kind == 10)
786 : 192 : kind = 10;
787 : 26686 : if (flag_real8_kind == 16)
788 : 384 : kind = 16;
789 : : }
790 : :
791 : 214991 : switch (exp_char)
792 : : {
793 : 29909 : case 'd':
794 : 29909 : if (kind != -2)
795 : : {
796 : 0 : gfc_error ("Real number at %C has a %<d%> exponent and an explicit "
797 : : "kind");
798 : 0 : goto cleanup;
799 : : }
800 : 29909 : kind = gfc_default_double_kind;
801 : 29909 : break;
802 : :
803 : 0 : case 'q':
804 : 0 : if (kind != -2)
805 : : {
806 : 0 : gfc_error ("Real number at %C has a %<q%> exponent and an explicit "
807 : : "kind");
808 : 0 : goto cleanup;
809 : : }
810 : :
811 : : /* The maximum possible real kind type parameter is 16. First, try
812 : : that for the kind, then fallback to trying kind=10 (Intel 80 bit)
813 : : extended precision. If neither value works, just given up. */
814 : 0 : kind = 16;
815 : 0 : if (gfc_validate_kind (BT_REAL, kind, true) < 0)
816 : : {
817 : 0 : kind = 10;
818 : 0 : if (gfc_validate_kind (BT_REAL, kind, true) < 0)
819 : : {
820 : 0 : gfc_error ("Invalid exponent-letter %<q%> in "
821 : : "real-literal-constant at %C");
822 : 0 : goto cleanup;
823 : : }
824 : : }
825 : : break;
826 : :
827 : 185082 : default:
828 : 185082 : if (kind == -2)
829 : 113990 : kind = gfc_default_real_kind;
830 : :
831 : 185082 : if (gfc_validate_kind (BT_REAL, kind, true) < 0)
832 : : {
833 : 0 : gfc_error ("Invalid real kind %d at %C", kind);
834 : 0 : goto cleanup;
835 : : }
836 : : }
837 : :
838 : 214991 : e = convert_real (buffer, kind, &gfc_current_locus);
839 : 214991 : if (negate)
840 : 2882 : mpfr_neg (e->value.real, e->value.real, GFC_RND_MODE);
841 : 214991 : e->ts.is_c_interop = is_iso_c;
842 : :
843 : 214991 : switch (gfc_range_check (e))
844 : : {
845 : : case ARITH_OK:
846 : : break;
847 : 1 : case ARITH_OVERFLOW:
848 : 1 : gfc_error ("Real constant overflows its kind at %C");
849 : 1 : goto cleanup;
850 : :
851 : 0 : case ARITH_UNDERFLOW:
852 : 0 : if (warn_underflow)
853 : 0 : gfc_warning (OPT_Wunderflow, "Real constant underflows its kind at %C");
854 : 0 : mpfr_set_ui (e->value.real, 0, GFC_RND_MODE);
855 : 0 : break;
856 : :
857 : 0 : default:
858 : 0 : gfc_internal_error ("gfc_range_check() returned bad value");
859 : : }
860 : :
861 : : /* Warn about trailing digits which suggest the user added too many
862 : : trailing digits, which may cause the appearance of higher precision
863 : : than the kind can support.
864 : :
865 : : This is done by replacing the rightmost non-zero digit with zero
866 : : and comparing with the original value. If these are equal, we
867 : : assume the user supplied more digits than intended (or forgot to
868 : : convert to the correct kind).
869 : : */
870 : :
871 : 214990 : if (warn_conversion_extra)
872 : : {
873 : 21 : mpfr_t r;
874 : 21 : char *c1;
875 : 21 : bool did_break;
876 : :
877 : 21 : c1 = strchr (buffer, 'e');
878 : 21 : if (c1 == NULL)
879 : 18 : c1 = buffer + strlen(buffer);
880 : :
881 : 30 : did_break = false;
882 : 30 : for (p = c1; p > buffer;)
883 : : {
884 : 30 : p--;
885 : 30 : if (*p == '.')
886 : 7 : continue;
887 : :
888 : 23 : if (*p != '0')
889 : : {
890 : 21 : *p = '0';
891 : 21 : did_break = true;
892 : 21 : break;
893 : : }
894 : : }
895 : :
896 : 21 : if (did_break)
897 : : {
898 : 21 : mpfr_init (r);
899 : 21 : mpfr_set_str (r, buffer, 10, GFC_RND_MODE);
900 : 21 : if (negate)
901 : 0 : mpfr_neg (r, r, GFC_RND_MODE);
902 : :
903 : 21 : mpfr_sub (r, r, e->value.real, GFC_RND_MODE);
904 : :
905 : 21 : if (mpfr_cmp_ui (r, 0) == 0)
906 : 1 : gfc_warning (OPT_Wconversion_extra, "Non-significant digits "
907 : : "in %qs number at %C, maybe incorrect KIND",
908 : : gfc_typename (&e->ts));
909 : :
910 : 21 : mpfr_clear (r);
911 : : }
912 : : }
913 : :
914 : 214990 : *result = e;
915 : 214990 : return MATCH_YES;
916 : :
917 : 5 : cleanup:
918 : 5 : gfc_free_expr (e);
919 : 5 : return MATCH_ERROR;
920 : : }
921 : :
922 : :
923 : : /* Match a substring reference. */
924 : :
925 : : static match
926 : 598862 : match_substring (gfc_charlen *cl, int init, gfc_ref **result, bool deferred)
927 : : {
928 : 598862 : gfc_expr *start, *end;
929 : 598862 : locus old_loc;
930 : 598862 : gfc_ref *ref;
931 : 598862 : match m;
932 : :
933 : 598862 : start = NULL;
934 : 598862 : end = NULL;
935 : :
936 : 598862 : old_loc = gfc_current_locus;
937 : :
938 : 598862 : m = gfc_match_char ('(');
939 : 598862 : if (m != MATCH_YES)
940 : : return MATCH_NO;
941 : :
942 : 15224 : if (gfc_match_char (':') != MATCH_YES)
943 : : {
944 : 14346 : if (init)
945 : 0 : m = gfc_match_init_expr (&start);
946 : : else
947 : 14346 : m = gfc_match_expr (&start);
948 : :
949 : 14346 : if (m != MATCH_YES)
950 : : {
951 : 154 : m = MATCH_NO;
952 : 154 : goto cleanup;
953 : : }
954 : :
955 : 14192 : m = gfc_match_char (':');
956 : 14192 : if (m != MATCH_YES)
957 : 454 : goto cleanup;
958 : : }
959 : :
960 : 14616 : if (gfc_match_char (')') != MATCH_YES)
961 : : {
962 : 13687 : if (init)
963 : 0 : m = gfc_match_init_expr (&end);
964 : : else
965 : 13687 : m = gfc_match_expr (&end);
966 : :
967 : 13687 : if (m == MATCH_NO)
968 : 2 : goto syntax;
969 : 13685 : if (m == MATCH_ERROR)
970 : 0 : goto cleanup;
971 : :
972 : 13685 : m = gfc_match_char (')');
973 : 13685 : if (m == MATCH_NO)
974 : 3 : goto syntax;
975 : : }
976 : :
977 : : /* Optimize away the (:) reference. */
978 : 14611 : if (start == NULL && end == NULL && !deferred)
979 : : ref = NULL;
980 : : else
981 : : {
982 : 14406 : ref = gfc_get_ref ();
983 : :
984 : 14406 : ref->type = REF_SUBSTRING;
985 : 14406 : if (start == NULL)
986 : 671 : start = gfc_get_int_expr (gfc_charlen_int_kind, NULL, 1);
987 : 14406 : ref->u.ss.start = start;
988 : 14406 : if (end == NULL && cl)
989 : 722 : end = gfc_copy_expr (cl->length);
990 : 14406 : ref->u.ss.end = end;
991 : 14406 : ref->u.ss.length = cl;
992 : : }
993 : :
994 : 14611 : *result = ref;
995 : 14611 : return MATCH_YES;
996 : :
997 : 5 : syntax:
998 : 5 : gfc_error ("Syntax error in SUBSTRING specification at %C");
999 : 5 : m = MATCH_ERROR;
1000 : :
1001 : 613 : cleanup:
1002 : 613 : gfc_free_expr (start);
1003 : 613 : gfc_free_expr (end);
1004 : :
1005 : 613 : gfc_current_locus = old_loc;
1006 : 613 : return m;
1007 : : }
1008 : :
1009 : :
1010 : : /* Reads the next character of a string constant, taking care to
1011 : : return doubled delimiters on the input as a single instance of
1012 : : the delimiter.
1013 : :
1014 : : Special return values for "ret" argument are:
1015 : : -1 End of the string, as determined by the delimiter
1016 : : -2 Unterminated string detected
1017 : :
1018 : : Backslash codes are also expanded at this time. */
1019 : :
1020 : : static gfc_char_t
1021 : 4119009 : next_string_char (gfc_char_t delimiter, int *ret)
1022 : : {
1023 : 4119009 : locus old_locus;
1024 : 4119009 : gfc_char_t c;
1025 : :
1026 : 4119009 : c = gfc_next_char_literal (INSTRING_WARN);
1027 : 4119009 : *ret = 0;
1028 : :
1029 : 4119009 : if (c == '\n')
1030 : : {
1031 : 4 : *ret = -2;
1032 : 4 : return 0;
1033 : : }
1034 : :
1035 : 4119005 : if (flag_backslash && c == '\\')
1036 : : {
1037 : 12180 : old_locus = gfc_current_locus;
1038 : :
1039 : 12180 : if (gfc_match_special_char (&c) == MATCH_NO)
1040 : 0 : gfc_current_locus = old_locus;
1041 : :
1042 : 12180 : if (!(gfc_option.allow_std & GFC_STD_GNU) && !inhibit_warnings)
1043 : 0 : gfc_warning (0, "Extension: backslash character at %C");
1044 : : }
1045 : :
1046 : 4119005 : if (c != delimiter)
1047 : : return c;
1048 : :
1049 : 596580 : old_locus = gfc_current_locus;
1050 : 596580 : c = gfc_next_char_literal (NONSTRING);
1051 : :
1052 : 596580 : if (c == delimiter)
1053 : : return c;
1054 : 595762 : gfc_current_locus = old_locus;
1055 : :
1056 : 595762 : *ret = -1;
1057 : 595762 : return 0;
1058 : : }
1059 : :
1060 : :
1061 : : /* Special case of gfc_match_name() that matches a parameter kind name
1062 : : before a string constant. This takes case of the weird but legal
1063 : : case of:
1064 : :
1065 : : kind_____'string'
1066 : :
1067 : : where kind____ is a parameter. gfc_match_name() will happily slurp
1068 : : up all the underscores, which leads to problems. If we return
1069 : : MATCH_YES, the parse pointer points to the final underscore, which
1070 : : is not part of the name. We never return MATCH_ERROR-- errors in
1071 : : the name will be detected later. */
1072 : :
1073 : : static match
1074 : 4354303 : match_charkind_name (char *name)
1075 : : {
1076 : 4354303 : locus old_loc;
1077 : 4354303 : char c, peek;
1078 : 4354303 : int len;
1079 : :
1080 : 4354303 : gfc_gobble_whitespace ();
1081 : 4354303 : c = gfc_next_ascii_char ();
1082 : 4354303 : if (!ISALPHA (c))
1083 : : return MATCH_NO;
1084 : :
1085 : 3958123 : *name++ = c;
1086 : 3958123 : len = 1;
1087 : :
1088 : 16038378 : for (;;)
1089 : : {
1090 : 16038378 : old_loc = gfc_current_locus;
1091 : 16038378 : c = gfc_next_ascii_char ();
1092 : :
1093 : 16038378 : if (c == '_')
1094 : : {
1095 : 515514 : peek = gfc_peek_ascii_char ();
1096 : :
1097 : 515514 : if (peek == '\'' || peek == '\"')
1098 : : {
1099 : 996 : gfc_current_locus = old_loc;
1100 : 996 : *name = '\0';
1101 : 996 : return MATCH_YES;
1102 : : }
1103 : : }
1104 : :
1105 : 16037382 : if (!ISALNUM (c)
1106 : 4471645 : && c != '_'
1107 : 3957127 : && (c != '$' || !flag_dollar_ok))
1108 : : break;
1109 : :
1110 : 12080255 : *name++ = c;
1111 : 12080255 : if (++len > GFC_MAX_SYMBOL_LEN)
1112 : : break;
1113 : : }
1114 : :
1115 : : return MATCH_NO;
1116 : : }
1117 : :
1118 : :
1119 : : /* See if the current input matches a character constant. Lots of
1120 : : contortions have to be done to match the kind parameter which comes
1121 : : before the actual string. The main consideration is that we don't
1122 : : want to error out too quickly. For example, we don't actually do
1123 : : any validation of the kinds until we have actually seen a legal
1124 : : delimiter. Using match_kind_param() generates errors too quickly. */
1125 : :
1126 : : static match
1127 : 6962950 : match_string_constant (gfc_expr **result)
1128 : : {
1129 : 6962950 : char name[GFC_MAX_SYMBOL_LEN + 1], peek;
1130 : 6962950 : size_t length;
1131 : 6962950 : int kind,save_warn_ampersand, ret;
1132 : 6962950 : locus old_locus, start_locus;
1133 : 6962950 : gfc_symbol *sym;
1134 : 6962950 : gfc_expr *e;
1135 : 6962950 : match m;
1136 : 6962950 : gfc_char_t c, delimiter, *p;
1137 : :
1138 : 6962950 : old_locus = gfc_current_locus;
1139 : :
1140 : 6962950 : gfc_gobble_whitespace ();
1141 : :
1142 : 6962950 : c = gfc_next_char ();
1143 : 6962950 : if (c == '\'' || c == '"')
1144 : : {
1145 : 259750 : kind = gfc_default_character_kind;
1146 : 259750 : start_locus = gfc_current_locus;
1147 : 259750 : goto got_delim;
1148 : : }
1149 : :
1150 : 6703200 : if (gfc_wide_is_digit (c))
1151 : : {
1152 : 2348897 : kind = 0;
1153 : :
1154 : 5650183 : while (gfc_wide_is_digit (c))
1155 : : {
1156 : 3314727 : kind = kind * 10 + c - '0';
1157 : 3314727 : if (kind > 9999999)
1158 : 13441 : goto no_match;
1159 : 3301286 : c = gfc_next_char ();
1160 : : }
1161 : :
1162 : : }
1163 : : else
1164 : : {
1165 : 4354303 : gfc_current_locus = old_locus;
1166 : :
1167 : 4354303 : m = match_charkind_name (name);
1168 : 4354303 : if (m != MATCH_YES)
1169 : 4353307 : goto no_match;
1170 : :
1171 : 996 : if (gfc_find_symbol (name, NULL, 1, &sym)
1172 : 996 : || sym == NULL
1173 : 1991 : || sym->attr.flavor != FL_PARAMETER)
1174 : 1 : goto no_match;
1175 : :
1176 : 995 : kind = -1;
1177 : 995 : c = gfc_next_char ();
1178 : : }
1179 : :
1180 : 2336451 : if (c != '_')
1181 : 2150228 : goto no_match;
1182 : :
1183 : 186223 : c = gfc_next_char ();
1184 : 186223 : if (c != '\'' && c != '"')
1185 : 148073 : goto no_match;
1186 : :
1187 : 38150 : start_locus = gfc_current_locus;
1188 : :
1189 : 38150 : if (kind == -1)
1190 : : {
1191 : 995 : if (gfc_extract_int (sym->value, &kind, 1))
1192 : : return MATCH_ERROR;
1193 : 995 : gfc_set_sym_referenced (sym);
1194 : : }
1195 : :
1196 : 38150 : if (gfc_validate_kind (BT_CHARACTER, kind, true) < 0)
1197 : : {
1198 : 0 : gfc_error ("Invalid kind %d for CHARACTER constant at %C", kind);
1199 : 0 : return MATCH_ERROR;
1200 : : }
1201 : :
1202 : 38150 : got_delim:
1203 : : /* Scan the string into a block of memory by first figuring out how
1204 : : long it is, allocating the structure, then re-reading it. This
1205 : : isn't particularly efficient, but string constants aren't that
1206 : : common in most code. TODO: Use obstacks? */
1207 : :
1208 : 297900 : delimiter = c;
1209 : 297900 : length = 0;
1210 : :
1211 : 3821452 : for (;;)
1212 : : {
1213 : 2059676 : c = next_string_char (delimiter, &ret);
1214 : 2059676 : if (ret == -1)
1215 : : break;
1216 : 1761780 : if (ret == -2)
1217 : : {
1218 : 4 : gfc_current_locus = start_locus;
1219 : 4 : gfc_error ("Unterminated character constant beginning at %C");
1220 : 4 : return MATCH_ERROR;
1221 : : }
1222 : :
1223 : 1761776 : length++;
1224 : : }
1225 : :
1226 : : /* Peek at the next character to see if it is a b, o, z, or x for the
1227 : : postfixed BOZ literal constants. */
1228 : 297896 : peek = gfc_peek_ascii_char ();
1229 : 297896 : if (peek == 'b' || peek == 'o' || peek =='z' || peek == 'x')
1230 : 25 : goto no_match;
1231 : :
1232 : 297871 : e = gfc_get_character_expr (kind, &start_locus, NULL, length);
1233 : :
1234 : 297871 : gfc_current_locus = start_locus;
1235 : :
1236 : : /* We disable the warning for the following loop as the warning has already
1237 : : been printed in the loop above. */
1238 : 297871 : save_warn_ampersand = warn_ampersand;
1239 : 297871 : warn_ampersand = false;
1240 : :
1241 : 297871 : p = e->value.character.string;
1242 : 2059333 : for (size_t i = 0; i < length; i++)
1243 : : {
1244 : 1761467 : c = next_string_char (delimiter, &ret);
1245 : :
1246 : 1761467 : if (!gfc_check_character_range (c, kind))
1247 : : {
1248 : 5 : gfc_free_expr (e);
1249 : 5 : gfc_error ("Character %qs in string at %C is not representable "
1250 : : "in character kind %d", gfc_print_wide_char (c), kind);
1251 : 5 : return MATCH_ERROR;
1252 : : }
1253 : :
1254 : 1761462 : *p++ = c;
1255 : : }
1256 : :
1257 : 297866 : *p = '\0'; /* TODO: C-style string is for development/debug purposes. */
1258 : 297866 : warn_ampersand = save_warn_ampersand;
1259 : :
1260 : 297866 : next_string_char (delimiter, &ret);
1261 : 297866 : if (ret != -1)
1262 : 0 : gfc_internal_error ("match_string_constant(): Delimiter not found");
1263 : :
1264 : 297866 : if (match_substring (NULL, 0, &e->ref, false) != MATCH_NO)
1265 : 306 : e->expr_type = EXPR_SUBSTRING;
1266 : :
1267 : : /* Substrings with constant starting and ending points are eligible as
1268 : : designators (F2018, section 9.1). Simplify substrings to make them usable
1269 : : e.g. in data statements. */
1270 : 297866 : if (e->expr_type == EXPR_SUBSTRING
1271 : 306 : && e->ref && e->ref->type == REF_SUBSTRING
1272 : 302 : && e->ref->u.ss.start->expr_type == EXPR_CONSTANT
1273 : 76 : && (e->ref->u.ss.end == NULL
1274 : 74 : || e->ref->u.ss.end->expr_type == EXPR_CONSTANT))
1275 : : {
1276 : 74 : gfc_expr *res;
1277 : 74 : ptrdiff_t istart, iend;
1278 : 74 : size_t length;
1279 : 74 : bool equal_length = false;
1280 : :
1281 : : /* Basic checks on substring starting and ending indices. */
1282 : 74 : if (!gfc_resolve_substring (e->ref, &equal_length))
1283 : 6 : return MATCH_ERROR;
1284 : :
1285 : 71 : length = e->value.character.length;
1286 : 71 : istart = gfc_mpz_get_hwi (e->ref->u.ss.start->value.integer);
1287 : 71 : if (e->ref->u.ss.end == NULL)
1288 : : iend = length;
1289 : : else
1290 : 69 : iend = gfc_mpz_get_hwi (e->ref->u.ss.end->value.integer);
1291 : :
1292 : 71 : if (istart <= iend)
1293 : : {
1294 : 66 : if (istart < 1)
1295 : : {
1296 : 2 : gfc_error ("Substring start index (%td) at %L below 1",
1297 : 2 : istart, &e->ref->u.ss.start->where);
1298 : 2 : return MATCH_ERROR;
1299 : : }
1300 : 64 : if (iend > (ssize_t) length)
1301 : : {
1302 : 1 : gfc_error ("Substring end index (%td) at %L exceeds string "
1303 : 1 : "length", iend, &e->ref->u.ss.end->where);
1304 : 1 : return MATCH_ERROR;
1305 : : }
1306 : 63 : length = iend - istart + 1;
1307 : : }
1308 : : else
1309 : : length = 0;
1310 : :
1311 : 68 : res = gfc_get_constant_expr (BT_CHARACTER, e->ts.kind, &e->where);
1312 : 68 : res->value.character.string = gfc_get_wide_string (length + 1);
1313 : 68 : res->value.character.length = length;
1314 : 68 : if (length > 0)
1315 : 63 : memcpy (res->value.character.string,
1316 : 63 : &e->value.character.string[istart - 1],
1317 : : length * sizeof (gfc_char_t));
1318 : 68 : res->value.character.string[length] = '\0';
1319 : 68 : e = res;
1320 : : }
1321 : :
1322 : 297860 : *result = e;
1323 : :
1324 : 297860 : return MATCH_YES;
1325 : :
1326 : 6665075 : no_match:
1327 : 6665075 : gfc_current_locus = old_locus;
1328 : 6665075 : return MATCH_NO;
1329 : : }
1330 : :
1331 : :
1332 : : /* Match a .true. or .false. Returns 1 if a .true. was found,
1333 : : 0 if a .false. was found, and -1 otherwise. */
1334 : : static int
1335 : 4348139 : match_logical_constant_string (void)
1336 : : {
1337 : 4348139 : locus orig_loc = gfc_current_locus;
1338 : :
1339 : 4348139 : gfc_gobble_whitespace ();
1340 : 4348139 : if (gfc_next_ascii_char () == '.')
1341 : : {
1342 : 56495 : char ch = gfc_next_ascii_char ();
1343 : 56495 : if (ch == 'f')
1344 : : {
1345 : 28821 : if (gfc_next_ascii_char () == 'a'
1346 : 28821 : && gfc_next_ascii_char () == 'l'
1347 : 28821 : && gfc_next_ascii_char () == 's'
1348 : 28821 : && gfc_next_ascii_char () == 'e'
1349 : 57642 : && gfc_next_ascii_char () == '.')
1350 : : /* Matched ".false.". */
1351 : : return 0;
1352 : : }
1353 : 27674 : else if (ch == 't')
1354 : : {
1355 : 27673 : if (gfc_next_ascii_char () == 'r'
1356 : 27673 : && gfc_next_ascii_char () == 'u'
1357 : 27673 : && gfc_next_ascii_char () == 'e'
1358 : 55346 : && gfc_next_ascii_char () == '.')
1359 : : /* Matched ".true.". */
1360 : : return 1;
1361 : : }
1362 : : }
1363 : 4291645 : gfc_current_locus = orig_loc;
1364 : 4291645 : return -1;
1365 : : }
1366 : :
1367 : : /* Match a .true. or .false. */
1368 : :
1369 : : static match
1370 : 4348139 : match_logical_constant (gfc_expr **result)
1371 : : {
1372 : 4348139 : gfc_expr *e;
1373 : 4348139 : int i, kind, is_iso_c;
1374 : :
1375 : 4348139 : i = match_logical_constant_string ();
1376 : 4348139 : if (i == -1)
1377 : : return MATCH_NO;
1378 : :
1379 : 56494 : kind = get_kind (&is_iso_c);
1380 : 56494 : if (kind == -1)
1381 : : return MATCH_ERROR;
1382 : 56494 : if (kind == -2)
1383 : 56005 : kind = gfc_default_logical_kind;
1384 : :
1385 : 56494 : if (gfc_validate_kind (BT_LOGICAL, kind, true) < 0)
1386 : : {
1387 : 4 : gfc_error ("Bad kind for logical constant at %C");
1388 : 4 : return MATCH_ERROR;
1389 : : }
1390 : :
1391 : 56490 : e = gfc_get_logical_expr (kind, &gfc_current_locus, i);
1392 : 56490 : e->ts.is_c_interop = is_iso_c;
1393 : :
1394 : 56490 : *result = e;
1395 : 56490 : return MATCH_YES;
1396 : : }
1397 : :
1398 : :
1399 : : /* Match a real or imaginary part of a complex constant that is a
1400 : : symbolic constant. */
1401 : :
1402 : : static match
1403 : 137287 : match_sym_complex_part (gfc_expr **result)
1404 : : {
1405 : 137287 : char name[GFC_MAX_SYMBOL_LEN + 1];
1406 : 137287 : gfc_symbol *sym;
1407 : 137287 : gfc_expr *e;
1408 : 137287 : match m;
1409 : :
1410 : 137287 : m = gfc_match_name (name);
1411 : 137287 : if (m != MATCH_YES)
1412 : : return m;
1413 : :
1414 : 37451 : if (gfc_find_symbol (name, NULL, 1, &sym) || sym == NULL)
1415 : : return MATCH_NO;
1416 : :
1417 : 34817 : if (sym->attr.flavor != FL_PARAMETER)
1418 : : {
1419 : : /* Give the matcher for implied do-loops a chance to run. This yields
1420 : : a much saner error message for "write(*,*) (i, i=1, 6" where the
1421 : : right parenthesis is missing. */
1422 : 33367 : char c;
1423 : 33367 : gfc_gobble_whitespace ();
1424 : 33367 : c = gfc_peek_ascii_char ();
1425 : 33367 : if (c == '=' || c == ',')
1426 : : {
1427 : : m = MATCH_NO;
1428 : : }
1429 : : else
1430 : : {
1431 : 30695 : gfc_error ("Expected PARAMETER symbol in complex constant at %C");
1432 : 30695 : m = MATCH_ERROR;
1433 : : }
1434 : 33367 : return m;
1435 : : }
1436 : :
1437 : 1450 : if (!sym->value)
1438 : 2 : goto error;
1439 : :
1440 : 1448 : if (!gfc_numeric_ts (&sym->value->ts))
1441 : : {
1442 : 331 : gfc_error ("Numeric PARAMETER required in complex constant at %C");
1443 : 331 : return MATCH_ERROR;
1444 : : }
1445 : :
1446 : 1117 : if (sym->value->rank != 0)
1447 : : {
1448 : 174 : gfc_error ("Scalar PARAMETER required in complex constant at %C");
1449 : 174 : return MATCH_ERROR;
1450 : : }
1451 : :
1452 : 943 : if (!gfc_notify_std (GFC_STD_F2003, "PARAMETER symbol in "
1453 : : "complex constant at %C"))
1454 : : return MATCH_ERROR;
1455 : :
1456 : 940 : switch (sym->value->ts.type)
1457 : : {
1458 : 68 : case BT_REAL:
1459 : 68 : e = gfc_copy_expr (sym->value);
1460 : 68 : break;
1461 : :
1462 : 1 : case BT_COMPLEX:
1463 : 1 : e = gfc_complex2real (sym->value, sym->value->ts.kind);
1464 : 1 : if (e == NULL)
1465 : 0 : goto error;
1466 : : break;
1467 : :
1468 : 869 : case BT_INTEGER:
1469 : 869 : e = gfc_int2real (sym->value, gfc_default_real_kind);
1470 : 869 : if (e == NULL)
1471 : 0 : goto error;
1472 : : break;
1473 : :
1474 : 2 : case BT_UNSIGNED:
1475 : 2 : goto error;
1476 : :
1477 : 0 : default:
1478 : 0 : gfc_internal_error ("gfc_match_sym_complex_part(): Bad type");
1479 : : }
1480 : :
1481 : 938 : *result = e; /* e is a scalar, real, constant expression. */
1482 : 938 : return MATCH_YES;
1483 : :
1484 : 4 : error:
1485 : 4 : gfc_error ("Error converting PARAMETER constant in complex constant at %C");
1486 : 4 : return MATCH_ERROR;
1487 : : }
1488 : :
1489 : :
1490 : : /* Match a real or imaginary part of a complex number. */
1491 : :
1492 : : static match
1493 : 137287 : match_complex_part (gfc_expr **result)
1494 : : {
1495 : 137287 : match m;
1496 : :
1497 : 137287 : m = match_sym_complex_part (result);
1498 : 137287 : if (m != MATCH_NO)
1499 : : return m;
1500 : :
1501 : 105142 : m = match_real_constant (result, 1);
1502 : 105142 : if (m != MATCH_NO)
1503 : : return m;
1504 : :
1505 : 91440 : return match_integer_constant (result, 1);
1506 : : }
1507 : :
1508 : :
1509 : : /* Try to match a complex constant. */
1510 : :
1511 : : static match
1512 : 6972985 : match_complex_constant (gfc_expr **result)
1513 : : {
1514 : 6972985 : gfc_expr *e, *real, *imag;
1515 : 6972985 : gfc_error_buffer old_error;
1516 : 6972985 : gfc_typespec target;
1517 : 6972985 : locus old_loc;
1518 : 6972985 : int kind;
1519 : 6972985 : match m;
1520 : :
1521 : 6972985 : old_loc = gfc_current_locus;
1522 : 6972985 : real = imag = e = NULL;
1523 : :
1524 : 6972985 : m = gfc_match_char ('(');
1525 : 6972985 : if (m != MATCH_YES)
1526 : : return m;
1527 : :
1528 : 127256 : gfc_push_error (&old_error);
1529 : :
1530 : 127256 : m = match_complex_part (&real);
1531 : 127256 : if (m == MATCH_NO)
1532 : : {
1533 : 74311 : gfc_free_error (&old_error);
1534 : 74311 : goto cleanup;
1535 : : }
1536 : :
1537 : 52945 : if (gfc_match_char (',') == MATCH_NO)
1538 : : {
1539 : : /* It is possible that gfc_int2real issued a warning when
1540 : : converting an integer to real. Throw this away here. */
1541 : :
1542 : 42910 : gfc_clear_warning ();
1543 : 42910 : gfc_pop_error (&old_error);
1544 : 42910 : m = MATCH_NO;
1545 : 42910 : goto cleanup;
1546 : : }
1547 : :
1548 : : /* If m is error, then something was wrong with the real part and we
1549 : : assume we have a complex constant because we've seen the ','. An
1550 : : ambiguous case here is the start of an iterator list of some
1551 : : sort. These sort of lists are matched prior to coming here. */
1552 : :
1553 : 10035 : if (m == MATCH_ERROR)
1554 : : {
1555 : 4 : gfc_free_error (&old_error);
1556 : 4 : goto cleanup;
1557 : : }
1558 : 10031 : gfc_pop_error (&old_error);
1559 : :
1560 : 10031 : m = match_complex_part (&imag);
1561 : 10031 : if (m == MATCH_NO)
1562 : 3110 : goto syntax;
1563 : 6921 : if (m == MATCH_ERROR)
1564 : 133 : goto cleanup;
1565 : :
1566 : 6788 : m = gfc_match_char (')');
1567 : 6788 : if (m == MATCH_NO)
1568 : : {
1569 : : /* Give the matcher for implied do-loops a chance to run. This
1570 : : yields a much saner error message for (/ (i, 4=i, 6) /). */
1571 : 13 : if (gfc_peek_ascii_char () == '=')
1572 : : {
1573 : 0 : m = MATCH_ERROR;
1574 : 0 : goto cleanup;
1575 : : }
1576 : : else
1577 : 13 : goto syntax;
1578 : : }
1579 : :
1580 : 6775 : if (m == MATCH_ERROR)
1581 : 0 : goto cleanup;
1582 : :
1583 : : /* Decide on the kind of this complex number. */
1584 : 6775 : if (real->ts.type == BT_REAL)
1585 : : {
1586 : 6341 : if (imag->ts.type == BT_REAL)
1587 : 6316 : kind = gfc_kind_max (real, imag);
1588 : : else
1589 : 25 : kind = real->ts.kind;
1590 : : }
1591 : : else
1592 : : {
1593 : 434 : if (imag->ts.type == BT_REAL)
1594 : 7 : kind = imag->ts.kind;
1595 : : else
1596 : 427 : kind = gfc_default_real_kind;
1597 : : }
1598 : 6775 : gfc_clear_ts (&target);
1599 : 6775 : target.type = BT_REAL;
1600 : 6775 : target.kind = kind;
1601 : :
1602 : 6775 : if (real->ts.type != BT_REAL || kind != real->ts.kind)
1603 : 435 : gfc_convert_type (real, &target, 2);
1604 : 6775 : if (imag->ts.type != BT_REAL || kind != imag->ts.kind)
1605 : 490 : gfc_convert_type (imag, &target, 2);
1606 : :
1607 : 6775 : e = convert_complex (real, imag, kind);
1608 : 6775 : e->where = gfc_current_locus;
1609 : :
1610 : 6775 : gfc_free_expr (real);
1611 : 6775 : gfc_free_expr (imag);
1612 : :
1613 : 6775 : *result = e;
1614 : 6775 : return MATCH_YES;
1615 : :
1616 : 3123 : syntax:
1617 : 3123 : gfc_error ("Syntax error in COMPLEX constant at %C");
1618 : 3123 : m = MATCH_ERROR;
1619 : :
1620 : 120481 : cleanup:
1621 : 120481 : gfc_free_expr (e);
1622 : 120481 : gfc_free_expr (real);
1623 : 120481 : gfc_free_expr (imag);
1624 : 120481 : gfc_current_locus = old_loc;
1625 : :
1626 : 120481 : return m;
1627 : 6972985 : }
1628 : :
1629 : :
1630 : : /* Match constants in any of several forms. Returns nonzero for a
1631 : : match, zero for no match. */
1632 : :
1633 : : match
1634 : 6972985 : gfc_match_literal_constant (gfc_expr **result, int signflag)
1635 : : {
1636 : 6972985 : match m;
1637 : :
1638 : 6972985 : m = match_complex_constant (result);
1639 : 6972985 : if (m != MATCH_NO)
1640 : : return m;
1641 : :
1642 : 6962950 : m = match_string_constant (result);
1643 : 6962950 : if (m != MATCH_NO)
1644 : : return m;
1645 : :
1646 : 6665075 : m = match_boz_constant (result);
1647 : 6665075 : if (m != MATCH_NO)
1648 : : return m;
1649 : :
1650 : 6660927 : m = match_real_constant (result, signflag);
1651 : 6660927 : if (m != MATCH_NO)
1652 : : return m;
1653 : :
1654 : 6459624 : m = match_hollerith_constant (result);
1655 : 6459624 : if (m != MATCH_NO)
1656 : : return m;
1657 : :
1658 : 6456988 : if (flag_unsigned)
1659 : : {
1660 : 588996 : m = match_unsigned_constant (result);
1661 : 588996 : if (m != MATCH_NO)
1662 : : return m;
1663 : : }
1664 : :
1665 : 6355616 : m = match_integer_constant (result, signflag);
1666 : 6355616 : if (m != MATCH_NO)
1667 : : return m;
1668 : :
1669 : 4348139 : m = match_logical_constant (result);
1670 : 4348139 : if (m != MATCH_NO)
1671 : : return m;
1672 : :
1673 : : return MATCH_NO;
1674 : : }
1675 : :
1676 : :
1677 : : /* This checks if a symbol is the return value of an encompassing function.
1678 : : Function nesting can be maximally two levels deep, but we may have
1679 : : additional local namespaces like BLOCK etc. */
1680 : :
1681 : : bool
1682 : 766716 : gfc_is_function_return_value (gfc_symbol *sym, gfc_namespace *ns)
1683 : : {
1684 : 766716 : if (!sym->attr.function || (sym->result != sym))
1685 : : return false;
1686 : 1608155 : while (ns)
1687 : : {
1688 : 910700 : if (ns->proc_name == sym)
1689 : : return true;
1690 : 899188 : ns = ns->parent;
1691 : : }
1692 : : return false;
1693 : : }
1694 : :
1695 : :
1696 : : /* Match a single actual argument value. An actual argument is
1697 : : usually an expression, but can also be a procedure name. If the
1698 : : argument is a single name, it is not always possible to tell
1699 : : whether the name is a dummy procedure or not. We treat these cases
1700 : : by creating an argument that looks like a dummy procedure and
1701 : : fixing things later during resolution. */
1702 : :
1703 : : static match
1704 : 1982721 : match_actual_arg (gfc_expr **result)
1705 : : {
1706 : 1982721 : char name[GFC_MAX_SYMBOL_LEN + 1];
1707 : 1982721 : gfc_symtree *symtree;
1708 : 1982721 : locus where, w;
1709 : 1982721 : gfc_expr *e;
1710 : 1982721 : char c;
1711 : :
1712 : 1982721 : gfc_gobble_whitespace ();
1713 : 1982721 : where = gfc_current_locus;
1714 : :
1715 : 1982721 : switch (gfc_match_name (name))
1716 : : {
1717 : : case MATCH_ERROR:
1718 : : return MATCH_ERROR;
1719 : :
1720 : : case MATCH_NO:
1721 : : break;
1722 : :
1723 : 1293826 : case MATCH_YES:
1724 : 1293826 : w = gfc_current_locus;
1725 : 1293826 : gfc_gobble_whitespace ();
1726 : 1293826 : c = gfc_next_ascii_char ();
1727 : 1293826 : gfc_current_locus = w;
1728 : :
1729 : 1293826 : if (c != ',' && c != ')')
1730 : : break;
1731 : :
1732 : 681395 : if (gfc_find_sym_tree (name, NULL, 1, &symtree))
1733 : : break;
1734 : : /* Handle error elsewhere. */
1735 : :
1736 : : /* Eliminate a couple of common cases where we know we don't
1737 : : have a function argument. */
1738 : 681395 : if (symtree == NULL)
1739 : : {
1740 : 13936 : gfc_get_sym_tree (name, NULL, &symtree, false);
1741 : 13936 : gfc_set_sym_referenced (symtree->n.sym);
1742 : : }
1743 : : else
1744 : : {
1745 : 667459 : gfc_symbol *sym;
1746 : :
1747 : 667459 : sym = symtree->n.sym;
1748 : 667459 : gfc_set_sym_referenced (sym);
1749 : 667459 : if (sym->attr.flavor == FL_NAMELIST)
1750 : : {
1751 : 1091 : gfc_error ("Namelist %qs cannot be an argument at %L",
1752 : : sym->name, &where);
1753 : 1091 : break;
1754 : : }
1755 : 666368 : if (sym->attr.flavor != FL_PROCEDURE
1756 : 630294 : && sym->attr.flavor != FL_UNKNOWN)
1757 : : break;
1758 : :
1759 : 186574 : if (sym->attr.in_common && !sym->attr.proc_pointer)
1760 : : {
1761 : 224 : if (!gfc_add_flavor (&sym->attr, FL_VARIABLE,
1762 : : sym->name, &sym->declared_at))
1763 : : return MATCH_ERROR;
1764 : : break;
1765 : : }
1766 : :
1767 : : /* If the symbol is a function with itself as the result and
1768 : : is being defined, then we have a variable. */
1769 : 186350 : if (sym->attr.function && sym->result == sym)
1770 : : {
1771 : 3353 : if (gfc_is_function_return_value (sym, gfc_current_ns))
1772 : : break;
1773 : :
1774 : 2707 : if (sym->attr.entry
1775 : 55 : && (sym->ns == gfc_current_ns
1776 : 2 : || sym->ns == gfc_current_ns->parent))
1777 : : {
1778 : 54 : gfc_entry_list *el = NULL;
1779 : :
1780 : 54 : for (el = sym->ns->entries; el; el = el->next)
1781 : 54 : if (sym == el->sym)
1782 : : break;
1783 : :
1784 : 54 : if (el)
1785 : : break;
1786 : : }
1787 : : }
1788 : : }
1789 : :
1790 : 199586 : e = gfc_get_expr (); /* Leave it unknown for now */
1791 : 199586 : e->symtree = symtree;
1792 : 199586 : e->expr_type = EXPR_VARIABLE;
1793 : 199586 : e->ts.type = BT_PROCEDURE;
1794 : 199586 : e->where = where;
1795 : :
1796 : 199586 : *result = e;
1797 : 199586 : return MATCH_YES;
1798 : : }
1799 : :
1800 : 1783135 : gfc_current_locus = where;
1801 : 1783135 : return gfc_match_expr (result);
1802 : : }
1803 : :
1804 : :
1805 : : /* Match a keyword argument or type parameter spec list.. */
1806 : :
1807 : : static match
1808 : 1974663 : match_keyword_arg (gfc_actual_arglist *actual, gfc_actual_arglist *base, bool pdt)
1809 : : {
1810 : 1974663 : char name[GFC_MAX_SYMBOL_LEN + 1];
1811 : 1974663 : gfc_actual_arglist *a;
1812 : 1974663 : locus name_locus;
1813 : 1974663 : match m;
1814 : :
1815 : 1974663 : name_locus = gfc_current_locus;
1816 : 1974663 : m = gfc_match_name (name);
1817 : :
1818 : 1974663 : if (m != MATCH_YES)
1819 : 581245 : goto cleanup;
1820 : 1393418 : if (gfc_match_char ('=') != MATCH_YES)
1821 : : {
1822 : 1235814 : m = MATCH_NO;
1823 : 1235814 : goto cleanup;
1824 : : }
1825 : :
1826 : 157604 : if (pdt)
1827 : : {
1828 : 424 : if (gfc_match_char ('*') == MATCH_YES)
1829 : : {
1830 : 78 : actual->spec_type = SPEC_ASSUMED;
1831 : 78 : goto add_name;
1832 : : }
1833 : 346 : else if (gfc_match_char (':') == MATCH_YES)
1834 : : {
1835 : 50 : actual->spec_type = SPEC_DEFERRED;
1836 : 50 : goto add_name;
1837 : : }
1838 : : else
1839 : 296 : actual->spec_type = SPEC_EXPLICIT;
1840 : : }
1841 : :
1842 : 157476 : m = match_actual_arg (&actual->expr);
1843 : 157476 : if (m != MATCH_YES)
1844 : 10972 : goto cleanup;
1845 : :
1846 : : /* Make sure this name has not appeared yet. */
1847 : 146504 : add_name:
1848 : 146632 : if (name[0] != '\0')
1849 : : {
1850 : 471304 : for (a = base; a; a = a->next)
1851 : 324686 : if (a->name != NULL && strcmp (a->name, name) == 0)
1852 : : {
1853 : 14 : gfc_error ("Keyword %qs at %C has already appeared in the "
1854 : : "current argument list", name);
1855 : 14 : return MATCH_ERROR;
1856 : : }
1857 : : }
1858 : :
1859 : 146618 : actual->name = gfc_get_string ("%s", name);
1860 : 146618 : return MATCH_YES;
1861 : :
1862 : 1828031 : cleanup:
1863 : 1828031 : gfc_current_locus = name_locus;
1864 : 1828031 : return m;
1865 : : }
1866 : :
1867 : :
1868 : : /* Match an argument list function, such as %VAL. */
1869 : :
1870 : : static match
1871 : 1936307 : match_arg_list_function (gfc_actual_arglist *result)
1872 : : {
1873 : 1936307 : char name[GFC_MAX_SYMBOL_LEN + 1];
1874 : 1936307 : locus old_locus;
1875 : 1936307 : match m;
1876 : :
1877 : 1936307 : old_locus = gfc_current_locus;
1878 : :
1879 : 1936307 : if (gfc_match_char ('%') != MATCH_YES)
1880 : : {
1881 : 1936242 : m = MATCH_NO;
1882 : 1936242 : goto cleanup;
1883 : : }
1884 : :
1885 : 65 : m = gfc_match ("%n (", name);
1886 : 65 : if (m != MATCH_YES)
1887 : 0 : goto cleanup;
1888 : :
1889 : 65 : if (name[0] != '\0')
1890 : : {
1891 : 65 : switch (name[0])
1892 : : {
1893 : 16 : case 'l':
1894 : 16 : if (startswith (name, "loc"))
1895 : : {
1896 : 16 : result->name = "%LOC";
1897 : 16 : break;
1898 : : }
1899 : : /* FALLTHRU */
1900 : 12 : case 'r':
1901 : 12 : if (startswith (name, "ref"))
1902 : : {
1903 : 12 : result->name = "%REF";
1904 : 12 : break;
1905 : : }
1906 : : /* FALLTHRU */
1907 : 37 : case 'v':
1908 : 37 : if (startswith (name, "val"))
1909 : : {
1910 : 37 : result->name = "%VAL";
1911 : 37 : break;
1912 : : }
1913 : : /* FALLTHRU */
1914 : 0 : default:
1915 : 0 : m = MATCH_ERROR;
1916 : 0 : goto cleanup;
1917 : : }
1918 : : }
1919 : :
1920 : 65 : if (!gfc_notify_std (GFC_STD_GNU, "argument list function at %C"))
1921 : : {
1922 : 1 : m = MATCH_ERROR;
1923 : 1 : goto cleanup;
1924 : : }
1925 : :
1926 : 64 : m = match_actual_arg (&result->expr);
1927 : 64 : if (m != MATCH_YES)
1928 : 0 : goto cleanup;
1929 : :
1930 : 64 : if (gfc_match_char (')') != MATCH_YES)
1931 : : {
1932 : 0 : m = MATCH_NO;
1933 : 0 : goto cleanup;
1934 : : }
1935 : :
1936 : : return MATCH_YES;
1937 : :
1938 : 1936243 : cleanup:
1939 : 1936243 : gfc_current_locus = old_locus;
1940 : 1936243 : return m;
1941 : : }
1942 : :
1943 : :
1944 : : /* Matches an actual argument list of a function or subroutine, from
1945 : : the opening parenthesis to the closing parenthesis. The argument
1946 : : list is assumed to allow keyword arguments because we don't know if
1947 : : the symbol associated with the procedure has an implicit interface
1948 : : or not. We make sure keywords are unique. If sub_flag is set,
1949 : : we're matching the argument list of a subroutine.
1950 : :
1951 : : NOTE: An alternative use for this function is to match type parameter
1952 : : spec lists, which are so similar to actual argument lists that the
1953 : : machinery can be reused. This use is flagged by the optional argument
1954 : : 'pdt'. */
1955 : :
1956 : : match
1957 : 2039868 : gfc_match_actual_arglist (int sub_flag, gfc_actual_arglist **argp, bool pdt)
1958 : : {
1959 : 2039868 : gfc_actual_arglist *head, *tail;
1960 : 2039868 : int seen_keyword;
1961 : 2039868 : gfc_st_label *label;
1962 : 2039868 : locus old_loc;
1963 : 2039868 : match m;
1964 : :
1965 : 2039868 : *argp = tail = NULL;
1966 : 2039868 : old_loc = gfc_current_locus;
1967 : :
1968 : 2039868 : seen_keyword = 0;
1969 : :
1970 : 2039868 : if (gfc_match_char ('(') == MATCH_NO)
1971 : 1199910 : return (sub_flag) ? MATCH_YES : MATCH_NO;
1972 : :
1973 : 1423696 : if (gfc_match_char (')') == MATCH_YES)
1974 : : return MATCH_YES;
1975 : :
1976 : 1398172 : head = NULL;
1977 : :
1978 : 1398172 : matching_actual_arglist++;
1979 : :
1980 : 1974341 : for (;;)
1981 : : {
1982 : 1974341 : if (head == NULL)
1983 : 1398172 : head = tail = gfc_get_actual_arglist ();
1984 : : else
1985 : : {
1986 : 576169 : tail->next = gfc_get_actual_arglist ();
1987 : 576169 : tail = tail->next;
1988 : : }
1989 : :
1990 : 1974341 : if (sub_flag && !pdt && gfc_match_char ('*') == MATCH_YES)
1991 : : {
1992 : 238 : m = gfc_match_st_label (&label);
1993 : 238 : if (m == MATCH_NO)
1994 : 0 : gfc_error ("Expected alternate return label at %C");
1995 : 238 : if (m != MATCH_YES)
1996 : 0 : goto cleanup;
1997 : :
1998 : 238 : if (!gfc_notify_std (GFC_STD_F95_OBS, "Alternate-return argument "
1999 : : "at %C"))
2000 : 0 : goto cleanup;
2001 : :
2002 : 238 : tail->label = label;
2003 : 238 : goto next;
2004 : : }
2005 : :
2006 : 1974103 : if (pdt && !seen_keyword)
2007 : : {
2008 : 1246 : if (gfc_match_char (':') == MATCH_YES)
2009 : : {
2010 : 57 : tail->spec_type = SPEC_DEFERRED;
2011 : 57 : goto next;
2012 : : }
2013 : 1189 : else if (gfc_match_char ('*') == MATCH_YES)
2014 : : {
2015 : 98 : tail->spec_type = SPEC_ASSUMED;
2016 : 98 : goto next;
2017 : : }
2018 : : else
2019 : 1091 : tail->spec_type = SPEC_EXPLICIT;
2020 : :
2021 : 1091 : m = match_keyword_arg (tail, head, pdt);
2022 : 1091 : if (m == MATCH_YES)
2023 : : {
2024 : 311 : seen_keyword = 1;
2025 : 311 : goto next;
2026 : : }
2027 : 780 : if (m == MATCH_ERROR)
2028 : 0 : goto cleanup;
2029 : : }
2030 : :
2031 : : /* After the first keyword argument is seen, the following
2032 : : arguments must also have keywords. */
2033 : 1973637 : if (seen_keyword)
2034 : : {
2035 : 37330 : m = match_keyword_arg (tail, head, pdt);
2036 : :
2037 : 37330 : if (m == MATCH_ERROR)
2038 : 34 : goto cleanup;
2039 : 37296 : if (m == MATCH_NO)
2040 : : {
2041 : 1358 : gfc_error ("Missing keyword name in actual argument list at %C");
2042 : 1358 : goto cleanup;
2043 : : }
2044 : :
2045 : : }
2046 : : else
2047 : : {
2048 : : /* Try an argument list function, like %VAL. */
2049 : 1936307 : m = match_arg_list_function (tail);
2050 : 1936307 : if (m == MATCH_ERROR)
2051 : 1 : goto cleanup;
2052 : :
2053 : : /* See if we have the first keyword argument. */
2054 : 1936306 : if (m == MATCH_NO)
2055 : : {
2056 : 1936242 : m = match_keyword_arg (tail, head, false);
2057 : 1936242 : if (m == MATCH_YES)
2058 : : seen_keyword = 1;
2059 : 1825873 : if (m == MATCH_ERROR)
2060 : 692 : goto cleanup;
2061 : : }
2062 : :
2063 : 1935550 : if (m == MATCH_NO)
2064 : : {
2065 : : /* Try for a non-keyword argument. */
2066 : 1825181 : m = match_actual_arg (&tail->expr);
2067 : 1825181 : if (m == MATCH_ERROR)
2068 : 1887 : goto cleanup;
2069 : 1823294 : if (m == MATCH_NO)
2070 : 19628 : goto syntax;
2071 : : }
2072 : : }
2073 : :
2074 : : /* PDT kind expressions are acceptable as initialization expressions.
2075 : : However, intrinsics with a KIND argument reject them. Convert the
2076 : : expression now by use of the component initializer. */
2077 : 1950037 : if (tail->expr
2078 : 1949958 : && tail->expr->expr_type == EXPR_VARIABLE
2079 : 3899995 : && gfc_expr_attr (tail->expr).pdt_kind)
2080 : : {
2081 : 252 : gfc_ref *ref;
2082 : 252 : gfc_expr *tmp = NULL;
2083 : 274 : for (ref = tail->expr->ref; ref; ref = ref->next)
2084 : 22 : if (!ref->next && ref->type == REF_COMPONENT
2085 : 22 : && ref->u.c.component->attr.pdt_kind
2086 : 22 : && ref->u.c.component->initializer)
2087 : 22 : tmp = gfc_copy_expr (ref->u.c.component->initializer);
2088 : 252 : if (tmp)
2089 : 22 : gfc_replace_expr (tail->expr, tmp);
2090 : : }
2091 : :
2092 : 1950741 : next:
2093 : 1950741 : if (gfc_match_char (')') == MATCH_YES)
2094 : : break;
2095 : 584546 : if (gfc_match_char (',') != MATCH_YES)
2096 : 8377 : goto syntax;
2097 : : }
2098 : :
2099 : 1366195 : *argp = head;
2100 : 1366195 : matching_actual_arglist--;
2101 : 1366195 : return MATCH_YES;
2102 : :
2103 : 28005 : syntax:
2104 : 28005 : gfc_error ("Syntax error in argument list at %C");
2105 : :
2106 : 31977 : cleanup:
2107 : 31977 : gfc_free_actual_arglist (head);
2108 : 31977 : gfc_current_locus = old_loc;
2109 : 31977 : matching_actual_arglist--;
2110 : 31977 : return MATCH_ERROR;
2111 : : }
2112 : :
2113 : :
2114 : : /* Used by gfc_match_varspec() to extend the reference list by one
2115 : : element. */
2116 : :
2117 : : static gfc_ref *
2118 : 722822 : extend_ref (gfc_expr *primary, gfc_ref *tail)
2119 : : {
2120 : 722822 : if (primary->ref == NULL)
2121 : 661091 : primary->ref = tail = gfc_get_ref ();
2122 : 61731 : else if (tail == NULL)
2123 : : {
2124 : : /* Set tail to end of reference chain. */
2125 : 23 : for (gfc_ref *ref = primary->ref; ref; ref = ref->next)
2126 : 23 : if (ref->next == NULL)
2127 : : {
2128 : : tail = ref;
2129 : : break;
2130 : : }
2131 : : }
2132 : : else
2133 : : {
2134 : 61717 : tail->next = gfc_get_ref ();
2135 : 61717 : tail = tail->next;
2136 : : }
2137 : :
2138 : 722822 : return tail;
2139 : : }
2140 : :
2141 : :
2142 : : /* Used by gfc_match_varspec() to match an inquiry reference. */
2143 : :
2144 : : bool
2145 : 4100 : is_inquiry_ref (const char *name, gfc_ref **ref)
2146 : : {
2147 : 4100 : inquiry_type type;
2148 : :
2149 : 4100 : if (name == NULL)
2150 : : return false;
2151 : :
2152 : 4100 : if (ref) *ref = NULL;
2153 : :
2154 : 4100 : if (strcmp (name, "re") == 0)
2155 : : type = INQUIRY_RE;
2156 : 2751 : else if (strcmp (name, "im") == 0)
2157 : : type = INQUIRY_IM;
2158 : 1869 : else if (strcmp (name, "kind") == 0)
2159 : : type = INQUIRY_KIND;
2160 : 1362 : else if (strcmp (name, "len") == 0)
2161 : : type = INQUIRY_LEN;
2162 : : else
2163 : : return false;
2164 : :
2165 : 3180 : if (ref)
2166 : : {
2167 : 1797 : *ref = gfc_get_ref ();
2168 : 1797 : (*ref)->type = REF_INQUIRY;
2169 : 1797 : (*ref)->u.i = type;
2170 : : }
2171 : :
2172 : : return true;
2173 : : }
2174 : :
2175 : :
2176 : : /* Check to see if functions in operator expressions can be resolved now. */
2177 : :
2178 : : static bool
2179 : 210 : resolvable_fcns (gfc_expr *e,
2180 : : gfc_symbol *sym ATTRIBUTE_UNUSED,
2181 : : int *f ATTRIBUTE_UNUSED)
2182 : : {
2183 : 210 : bool p;
2184 : 210 : gfc_symbol *s;
2185 : :
2186 : 210 : if (e->expr_type != EXPR_FUNCTION)
2187 : : return false;
2188 : :
2189 : 72 : s = e && e->symtree && e->symtree->n.sym ? e->symtree->n.sym : NULL;
2190 : 72 : p = s && (s->attr.use_assoc
2191 : 54 : || s->attr.host_assoc
2192 : 54 : || s->attr.if_source == IFSRC_DECL
2193 : 54 : || s->attr.proc == PROC_INTRINSIC
2194 : 24 : || gfc_is_intrinsic (s, 0, e->where));
2195 : 72 : return !p;
2196 : : }
2197 : :
2198 : :
2199 : : /* Match any additional specifications associated with the current
2200 : : variable like member references or substrings. If equiv_flag is
2201 : : set we only match stuff that is allowed inside an EQUIVALENCE
2202 : : statement. sub_flag tells whether we expect a type-bound procedure found
2203 : : to be a subroutine as part of CALL or a FUNCTION. For procedure pointer
2204 : : components, 'ppc_arg' determines whether the PPC may be called (with an
2205 : : argument list), or whether it may just be referred to as a pointer. */
2206 : :
2207 : : match
2208 : 4984510 : gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
2209 : : bool ppc_arg)
2210 : : {
2211 : 4984510 : char name[GFC_MAX_SYMBOL_LEN + 1];
2212 : 4984510 : gfc_ref *substring, *tail, *tmp;
2213 : 4984510 : gfc_component *component = NULL;
2214 : 4984510 : gfc_component *previous = NULL;
2215 : 4984510 : gfc_symbol *sym = primary->symtree->n.sym;
2216 : 4984510 : gfc_expr *tgt_expr = NULL;
2217 : 4984510 : match m;
2218 : 4984510 : bool unknown;
2219 : 4984510 : bool inquiry;
2220 : 4984510 : bool intrinsic;
2221 : 4984510 : bool inferred_type;
2222 : 4984510 : locus old_loc;
2223 : 4984510 : char peeked_char;
2224 : :
2225 : 4984510 : tail = NULL;
2226 : :
2227 : 4984510 : gfc_gobble_whitespace ();
2228 : :
2229 : 4984510 : if (gfc_peek_ascii_char () == '[')
2230 : : {
2231 : 2849 : if ((sym->ts.type != BT_CLASS && sym->attr.dimension)
2232 : 2849 : || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)
2233 : 113 : && CLASS_DATA (sym)->attr.dimension))
2234 : : {
2235 : 0 : gfc_error ("Array section designator, e.g. %<(:)%>, is required "
2236 : : "besides the coarray designator %<[...]%> at %C");
2237 : 0 : return MATCH_ERROR;
2238 : : }
2239 : 2849 : if ((sym->ts.type != BT_CLASS && !sym->attr.codimension)
2240 : 2848 : || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)
2241 : 113 : && !CLASS_DATA (sym)->attr.codimension))
2242 : : {
2243 : 1 : gfc_error ("Coarray designator at %C but %qs is not a coarray",
2244 : : sym->name);
2245 : 1 : return MATCH_ERROR;
2246 : : }
2247 : : }
2248 : :
2249 : 4984509 : if (sym->assoc && sym->assoc->target)
2250 : 4984509 : tgt_expr = sym->assoc->target;
2251 : :
2252 : 4984509 : inferred_type = IS_INFERRED_TYPE (primary);
2253 : :
2254 : : /* SELECT TYPE temporaries within an ASSOCIATE block, whose selector has not
2255 : : been parsed, can generate errors with array refs.. The SELECT TYPE
2256 : : namespace is marked with 'assoc_name_inferred'. During resolution, this is
2257 : : detected and gfc_fixup_inferred_type_refs is called. */
2258 : 4983676 : if (!inferred_type
2259 : 4983676 : && sym->attr.select_type_temporary
2260 : 23262 : && sym->ns->assoc_name_inferred
2261 : 344 : && !sym->attr.select_rank_temporary)
2262 : 1177 : inferred_type = true;
2263 : :
2264 : : /* Try to resolve a typebound generic procedure so that the associate name
2265 : : has a chance to get a type before being used in a second, nested associate
2266 : : statement. Note that a copy is used for resolution so that failure does
2267 : : not result in a mutilated selector expression further down the line. */
2268 : 6219 : if (tgt_expr && !sym->assoc->dangling
2269 : 6219 : && tgt_expr->ts.type == BT_UNKNOWN
2270 : 1612 : && tgt_expr->symtree
2271 : 1165 : && tgt_expr->symtree->n.sym
2272 : 4984582 : && gfc_expr_attr (tgt_expr).generic
2273 : 4984582 : && ((sym->ts.type == BT_DERIVED && sym->ts.u.derived->attr.pdt_template)
2274 : 72 : || (sym->ts.type == BT_CLASS
2275 : 0 : && CLASS_DATA (sym)->ts.u.derived->attr.pdt_template)))
2276 : : {
2277 : 1 : gfc_expr *cpy = gfc_copy_expr (tgt_expr);
2278 : 1 : if (gfc_resolve_expr (cpy)
2279 : 1 : && cpy->ts.type != BT_UNKNOWN)
2280 : : {
2281 : 1 : gfc_replace_expr (tgt_expr, cpy);
2282 : 1 : sym->ts = tgt_expr->ts;
2283 : : }
2284 : : else
2285 : 0 : gfc_free_expr (cpy);
2286 : 1 : if (gfc_expr_attr (tgt_expr).generic)
2287 : 4984509 : inferred_type = true;
2288 : : }
2289 : :
2290 : : /* For associate names, we may not yet know whether they are arrays or not.
2291 : : If the selector expression is unambiguously an array; eg. a full array
2292 : : or an array section, then the associate name must be an array and we can
2293 : : fix it now. Otherwise, if parentheses follow and it is not a character
2294 : : type, we have to assume that it actually is one for now. The final
2295 : : decision will be made at resolution, of course. */
2296 : 4984509 : if (sym->assoc
2297 : 29481 : && gfc_peek_ascii_char () == '('
2298 : 9562 : && sym->ts.type != BT_CLASS
2299 : 4993930 : && !sym->attr.dimension)
2300 : : {
2301 : 386 : gfc_ref *ref = NULL;
2302 : :
2303 : 386 : if (!sym->assoc->dangling && tgt_expr)
2304 : : {
2305 : 326 : if (tgt_expr->expr_type == EXPR_VARIABLE)
2306 : 21 : gfc_resolve_expr (tgt_expr);
2307 : :
2308 : 326 : ref = tgt_expr->ref;
2309 : 340 : for (; ref; ref = ref->next)
2310 : 14 : if (ref->type == REF_ARRAY
2311 : 7 : && (ref->u.ar.type == AR_FULL
2312 : 7 : || ref->u.ar.type == AR_SECTION))
2313 : : break;
2314 : : }
2315 : :
2316 : 386 : if (ref || (!(sym->assoc->dangling || sym->ts.type == BT_CHARACTER)
2317 : 260 : && sym->assoc->st
2318 : 260 : && sym->assoc->st->n.sym
2319 : 260 : && sym->assoc->st->n.sym->attr.dimension == 0))
2320 : : {
2321 : 260 : sym->attr.dimension = 1;
2322 : 260 : if (sym->as == NULL
2323 : 260 : && sym->assoc->st
2324 : 260 : && sym->assoc->st->n.sym
2325 : 260 : && sym->assoc->st->n.sym->as)
2326 : 0 : sym->as = gfc_copy_array_spec (sym->assoc->st->n.sym->as);
2327 : : }
2328 : : }
2329 : 4984123 : else if (sym->ts.type == BT_CLASS
2330 : 43517 : && !(sym->assoc && sym->assoc->ar)
2331 : 43445 : && tgt_expr
2332 : 256 : && tgt_expr->expr_type == EXPR_VARIABLE
2333 : 130 : && sym->ts.u.derived != tgt_expr->ts.u.derived)
2334 : : {
2335 : 19 : gfc_resolve_expr (tgt_expr);
2336 : 19 : if (tgt_expr->rank)
2337 : 0 : sym->ts.u.derived = tgt_expr->ts.u.derived;
2338 : : }
2339 : :
2340 : 4984509 : peeked_char = gfc_peek_ascii_char ();
2341 : 1177 : if ((inferred_type && !sym->as && peeked_char == '(')
2342 : 4984288 : || (equiv_flag && peeked_char == '(') || peeked_char == '['
2343 : 4979869 : || sym->attr.codimension
2344 : 4966102 : || (sym->attr.dimension && sym->ts.type != BT_CLASS
2345 : 625434 : && !sym->attr.proc_pointer && !gfc_is_proc_ptr_comp (primary)
2346 : 625419 : && !(gfc_matching_procptr_assignment
2347 : 32 : && sym->attr.flavor == FL_PROCEDURE))
2348 : 9325212 : || (sym->ts.type == BT_CLASS && sym->attr.class_ok
2349 : 43356 : && sym->ts.u.derived && CLASS_DATA (sym)
2350 : 43352 : && (CLASS_DATA (sym)->attr.dimension
2351 : 26465 : || CLASS_DATA (sym)->attr.codimension)))
2352 : : {
2353 : 661094 : gfc_array_spec *as;
2354 : 16502 : bool coarray_only = sym->attr.codimension && !sym->attr.dimension
2355 : 669955 : && sym->ts.type == BT_CHARACTER;
2356 : 661094 : gfc_ref *ref, *strarr = NULL;
2357 : :
2358 : 661094 : tail = extend_ref (primary, tail);
2359 : 661094 : if (sym->ts.type == BT_CHARACTER && tail->type == REF_SUBSTRING)
2360 : : {
2361 : 3 : gcc_assert (sym->attr.dimension);
2362 : : /* Find array reference for substrings of character arrays. */
2363 : 3 : for (ref = primary->ref; ref && ref->next; ref = ref->next)
2364 : 3 : if (ref->type == REF_ARRAY && ref->next->type == REF_SUBSTRING)
2365 : : {
2366 : : strarr = ref;
2367 : : break;
2368 : : }
2369 : : }
2370 : : else
2371 : 661091 : tail->type = REF_ARRAY;
2372 : :
2373 : : /* In EQUIVALENCE, we don't know yet whether we are seeing
2374 : : an array, character variable or array of character
2375 : : variables. We'll leave the decision till resolve time. */
2376 : :
2377 : 661094 : if (equiv_flag)
2378 : : as = NULL;
2379 : 659093 : else if (sym->ts.type == BT_CLASS && CLASS_DATA (sym))
2380 : 17402 : as = CLASS_DATA (sym)->as;
2381 : : else
2382 : 641691 : as = sym->as;
2383 : :
2384 : 661094 : ref = strarr ? strarr : tail;
2385 : 661094 : m = gfc_match_array_ref (&ref->u.ar, as, equiv_flag, as ? as->corank : 0,
2386 : : coarray_only);
2387 : 661094 : if (m != MATCH_YES)
2388 : : return m;
2389 : :
2390 : 661019 : gfc_gobble_whitespace ();
2391 : 661019 : if (coarray_only)
2392 : : {
2393 : 1360 : primary->ts = sym->ts;
2394 : 1360 : goto check_substring;
2395 : : }
2396 : :
2397 : 659659 : if (equiv_flag && gfc_peek_ascii_char () == '(')
2398 : : {
2399 : 74 : tail = extend_ref (primary, tail);
2400 : 74 : tail->type = REF_ARRAY;
2401 : :
2402 : 74 : m = gfc_match_array_ref (&tail->u.ar, NULL, equiv_flag, 0);
2403 : 74 : if (m != MATCH_YES)
2404 : : return m;
2405 : : }
2406 : : }
2407 : :
2408 : 4983074 : primary->ts = sym->ts;
2409 : :
2410 : 4983074 : if (equiv_flag)
2411 : : return MATCH_YES;
2412 : :
2413 : : /* With DEC extensions, member separator may be '.' or '%'. */
2414 : 4980128 : peeked_char = gfc_peek_ascii_char ();
2415 : 4980128 : m = gfc_match_member_sep (sym);
2416 : 4980128 : if (m == MATCH_ERROR)
2417 : : return MATCH_ERROR;
2418 : :
2419 : 4980127 : inquiry = false;
2420 : 4980127 : if (m == MATCH_YES && peeked_char == '%' && primary->ts.type != BT_CLASS
2421 : 127846 : && (primary->ts.type != BT_DERIVED || inferred_type))
2422 : : {
2423 : 2298 : match mm;
2424 : 2298 : old_loc = gfc_current_locus;
2425 : 2298 : mm = gfc_match_name (name);
2426 : :
2427 : : /* Check to see if this has a default complex. */
2428 : 489 : if (sym->ts.type == BT_UNKNOWN && tgt_expr == NULL
2429 : 2316 : && gfc_get_default_type (sym->name, sym->ns)->type != BT_UNKNOWN)
2430 : : {
2431 : 6 : gfc_set_default_type (sym, 0, sym->ns);
2432 : 6 : primary->ts = sym->ts;
2433 : : }
2434 : :
2435 : : /* This is a usable inquiry reference, if the symbol is already known
2436 : : to have a type or no derived types with a component of this name
2437 : : can be found. If this was an inquiry reference with the same name
2438 : : as a derived component and the associate-name type is not derived
2439 : : or class, this is fixed up in 'gfc_fixup_inferred_type_refs'. */
2440 : 2298 : if (mm == MATCH_YES && is_inquiry_ref (name, NULL)
2441 : 3891 : && !(sym->ts.type == BT_UNKNOWN
2442 : 210 : && gfc_find_derived_types (sym, gfc_current_ns, name)))
2443 : : inquiry = true;
2444 : 2298 : gfc_current_locus = old_loc;
2445 : : }
2446 : :
2447 : : /* Use the default type if there is one. */
2448 : 2625594 : if (sym->ts.type == BT_UNKNOWN && m == MATCH_YES
2449 : 4980610 : && gfc_get_default_type (sym->name, sym->ns)->type == BT_DERIVED)
2450 : 0 : gfc_set_default_type (sym, 0, sym->ns);
2451 : :
2452 : : /* See if the type can be determined by resolution of the selector expression,
2453 : : if allowable now, or inferred from references. */
2454 : 4980127 : if ((sym->ts.type == BT_UNKNOWN || inferred_type)
2455 : 2626513 : && m == MATCH_YES)
2456 : : {
2457 : 1239 : bool sym_present, resolved = false;
2458 : 1239 : gfc_symbol *tgt_sym;
2459 : :
2460 : 1239 : sym_present = tgt_expr && tgt_expr->symtree && tgt_expr->symtree->n.sym;
2461 : 1239 : tgt_sym = sym_present ? tgt_expr->symtree->n.sym : NULL;
2462 : :
2463 : : /* These target expressions can be resolved at any time:
2464 : : (i) With a declared symbol or intrinsic function; or
2465 : : (ii) An operator expression,
2466 : : just as long as (iii) all the functions in the expression have been
2467 : : declared or are intrinsic. */
2468 : 1239 : if (((sym_present // (i)
2469 : 847 : && (tgt_sym->attr.use_assoc
2470 : 829 : || tgt_sym->attr.host_assoc
2471 : 829 : || tgt_sym->attr.if_source == IFSRC_DECL
2472 : 829 : || tgt_sym->attr.proc == PROC_INTRINSIC
2473 : 829 : || gfc_is_intrinsic (tgt_sym, 0, tgt_expr->where)))
2474 : 1209 : || (tgt_expr && tgt_expr->expr_type == EXPR_OP)) // (ii)
2475 : 54 : && !gfc_traverse_expr (tgt_expr, NULL, resolvable_fcns, 0) // (iii)
2476 : 48 : && gfc_resolve_expr (tgt_expr))
2477 : : {
2478 : 42 : sym->ts = tgt_expr->ts;
2479 : 42 : primary->ts = sym->ts;
2480 : 42 : resolved = true;
2481 : : }
2482 : :
2483 : : /* If this hasn't done the trick and the target expression is a function,
2484 : : or an unresolved operator expression, then this must be a derived type
2485 : : if 'name' matches an accessible type both in this namespace and in the
2486 : : as yet unparsed contained function. In principle, the type could have
2487 : : already been inferred to be complex and yet a derived type with a
2488 : : component name 're' or 'im' could be found. */
2489 : 42 : if (tgt_expr
2490 : 883 : && (tgt_expr->expr_type == EXPR_FUNCTION
2491 : 91 : || tgt_expr->expr_type == EXPR_ARRAY
2492 : 79 : || (!resolved && tgt_expr->expr_type == EXPR_OP))
2493 : 816 : && (sym->ts.type == BT_UNKNOWN
2494 : 388 : || (inferred_type && sym->ts.type != BT_COMPLEX))
2495 : 1941 : && gfc_find_derived_types (sym, gfc_current_ns, name, true))
2496 : : {
2497 : 552 : sym->assoc->inferred_type = 1;
2498 : : /* The first returned type is as good as any at this stage. The final
2499 : : determination is made in 'gfc_fixup_inferred_type_refs'*/
2500 : 552 : gfc_symbol **dts = &sym->assoc->derived_types;
2501 : 552 : tgt_expr->ts.type = BT_DERIVED;
2502 : 552 : tgt_expr->ts.kind = 0;
2503 : 552 : tgt_expr->ts.u.derived = *dts;
2504 : 552 : sym->ts = tgt_expr->ts;
2505 : 552 : primary->ts = sym->ts;
2506 : : /* Delete the dt list even if this process has to be done again for
2507 : : another primary expression. */
2508 : 1134 : while (*dts && (*dts)->dt_next)
2509 : : {
2510 : 582 : gfc_symbol **tmp = &(*dts)->dt_next;
2511 : 582 : *dts = NULL;
2512 : 582 : dts = tmp;
2513 : : }
2514 : : }
2515 : : /* If there is a usable inquiry reference not there are no matching
2516 : : derived types, force the inquiry reference by setting unknown the
2517 : : type of the primary expression. */
2518 : 258 : else if (inquiry && (sym->ts.type == BT_DERIVED && inferred_type)
2519 : 735 : && !gfc_find_derived_types (sym, gfc_current_ns, name))
2520 : 48 : primary->ts.type = BT_UNKNOWN;
2521 : :
2522 : : /* Otherwise try resolving a copy of a component call. If it succeeds,
2523 : : use that for the selector expression. */
2524 : 639 : else if (tgt_expr && tgt_expr->expr_type == EXPR_COMPCALL)
2525 : : {
2526 : 1 : gfc_expr *cpy = gfc_copy_expr (tgt_expr);
2527 : 1 : if (gfc_resolve_expr (cpy))
2528 : : {
2529 : 1 : gfc_replace_expr (tgt_expr, cpy);
2530 : 1 : sym->ts = tgt_expr->ts;
2531 : : }
2532 : : else
2533 : 0 : gfc_free_expr (cpy);
2534 : : }
2535 : :
2536 : : /* An inquiry reference might determine the type, otherwise we have an
2537 : : error. */
2538 : 1239 : if (sym->ts.type == BT_UNKNOWN && !inquiry)
2539 : : {
2540 : 12 : gfc_error ("Symbol %qs at %C has no IMPLICIT type", sym->name);
2541 : 12 : return MATCH_ERROR;
2542 : : }
2543 : : }
2544 : 4978888 : else if ((sym->ts.type != BT_DERIVED && sym->ts.type != BT_CLASS)
2545 : 4755139 : && m == MATCH_YES && !inquiry)
2546 : : {
2547 : 6 : gfc_error ("Unexpected %<%c%> for nonderived-type variable %qs at %C",
2548 : : peeked_char, sym->name);
2549 : 6 : return MATCH_ERROR;
2550 : : }
2551 : :
2552 : 4980109 : if ((sym->ts.type != BT_DERIVED && sym->ts.type != BT_CLASS && !inquiry)
2553 : 226029 : || m != MATCH_YES)
2554 : 4833333 : goto check_substring;
2555 : :
2556 : 146776 : if (!inquiry)
2557 : 145465 : sym = sym->ts.u.derived;
2558 : : else
2559 : : sym = NULL;
2560 : :
2561 : 169677 : for (;;)
2562 : : {
2563 : 169677 : bool t;
2564 : 169677 : gfc_symtree *tbp;
2565 : 169677 : gfc_typespec *ts = &primary->ts;
2566 : :
2567 : 169677 : m = gfc_match_name (name);
2568 : 169677 : if (m == MATCH_NO)
2569 : 0 : gfc_error ("Expected structure component name at %C");
2570 : 169677 : if (m != MATCH_YES)
2571 : 135 : return MATCH_ERROR;
2572 : :
2573 : : /* For derived type components find typespec of ultimate component. */
2574 : 169677 : if (ts->type == BT_DERIVED && primary->ref)
2575 : : {
2576 : 136921 : for (gfc_ref *ref = primary->ref; ref; ref = ref->next)
2577 : : {
2578 : 77839 : if (ref->type == REF_COMPONENT && ref->u.c.component)
2579 : 22054 : ts = &ref->u.c.component->ts;
2580 : : }
2581 : : }
2582 : :
2583 : 169677 : intrinsic = false;
2584 : 169677 : if (ts->type != BT_CLASS && ts->type != BT_DERIVED)
2585 : : {
2586 : 1790 : inquiry = is_inquiry_ref (name, &tmp);
2587 : 1790 : if (inquiry)
2588 : 1785 : sym = NULL;
2589 : :
2590 : 1790 : if (peeked_char == '%')
2591 : : {
2592 : 1790 : if (tmp)
2593 : : {
2594 : 1785 : gfc_symbol *s;
2595 : 1785 : switch (tmp->u.i)
2596 : : {
2597 : 1242 : case INQUIRY_RE:
2598 : 1242 : case INQUIRY_IM:
2599 : 1242 : if (!gfc_notify_std (GFC_STD_F2008,
2600 : : "RE or IM part_ref at %C"))
2601 : : return MATCH_ERROR;
2602 : : break;
2603 : :
2604 : 288 : case INQUIRY_KIND:
2605 : 288 : if (!gfc_notify_std (GFC_STD_F2003,
2606 : : "KIND part_ref at %C"))
2607 : : return MATCH_ERROR;
2608 : : break;
2609 : :
2610 : 255 : case INQUIRY_LEN:
2611 : 255 : if (!gfc_notify_std (GFC_STD_F2003, "LEN part_ref at %C"))
2612 : : return MATCH_ERROR;
2613 : : break;
2614 : : }
2615 : :
2616 : : /* If necessary, infer the type of the primary expression
2617 : : and the associate-name using the the inquiry ref.. */
2618 : 1776 : s = primary->symtree ? primary->symtree->n.sym : NULL;
2619 : 1748 : if (s && s->assoc && s->assoc->target
2620 : 258 : && (s->ts.type == BT_UNKNOWN
2621 : 138 : || (primary->ts.type == BT_UNKNOWN
2622 : 48 : && s->assoc->inferred_type
2623 : 48 : && s->ts.type == BT_DERIVED)))
2624 : : {
2625 : 168 : if (tmp->u.i == INQUIRY_RE || tmp->u.i == INQUIRY_IM)
2626 : : {
2627 : 72 : s->ts.type = BT_COMPLEX;
2628 : 72 : s->ts.kind = gfc_default_real_kind;;
2629 : 72 : s->assoc->inferred_type = 1;
2630 : 72 : primary->ts = s->ts;
2631 : : }
2632 : 96 : else if (tmp->u.i == INQUIRY_LEN)
2633 : : {
2634 : 48 : s->ts.type = BT_CHARACTER;
2635 : 48 : s->ts.kind = gfc_default_character_kind;;
2636 : 48 : s->assoc->inferred_type = 1;
2637 : 48 : primary->ts = s->ts;
2638 : : }
2639 : 48 : else if (s->ts.type == BT_UNKNOWN)
2640 : : {
2641 : : /* KIND inquiry gives no clue as to symbol type. */
2642 : 48 : primary->ref = tmp;
2643 : 48 : primary->ts.type = BT_INTEGER;
2644 : 48 : primary->ts.kind = gfc_default_integer_kind;
2645 : 48 : return MATCH_YES;
2646 : : }
2647 : : }
2648 : :
2649 : 1728 : if ((tmp->u.i == INQUIRY_RE || tmp->u.i == INQUIRY_IM)
2650 : 1238 : && primary->ts.type != BT_COMPLEX)
2651 : : {
2652 : 12 : gfc_error ("The RE or IM part_ref at %C must be "
2653 : : "applied to a COMPLEX expression");
2654 : 12 : return MATCH_ERROR;
2655 : : }
2656 : 1716 : else if (tmp->u.i == INQUIRY_LEN
2657 : 253 : && ts->type != BT_CHARACTER)
2658 : : {
2659 : 5 : gfc_error ("The LEN part_ref at %C must be applied "
2660 : : "to a CHARACTER expression");
2661 : 5 : return MATCH_ERROR;
2662 : : }
2663 : : }
2664 : 1716 : if (primary->ts.type != BT_UNKNOWN)
2665 : 169603 : intrinsic = true;
2666 : : }
2667 : : }
2668 : : else
2669 : : inquiry = false;
2670 : :
2671 : 169603 : if (sym && sym->f2k_derived)
2672 : 165088 : tbp = gfc_find_typebound_proc (sym, &t, name, false, &gfc_current_locus);
2673 : : else
2674 : : tbp = NULL;
2675 : :
2676 : 165088 : if (tbp)
2677 : : {
2678 : 3995 : gfc_symbol* tbp_sym;
2679 : :
2680 : 3995 : if (!t)
2681 : : return MATCH_ERROR;
2682 : :
2683 : 3993 : gcc_assert (!tail || !tail->next);
2684 : :
2685 : 3993 : if (!(primary->expr_type == EXPR_VARIABLE
2686 : : || (primary->expr_type == EXPR_STRUCTURE
2687 : 1 : && primary->symtree && primary->symtree->n.sym
2688 : 1 : && primary->symtree->n.sym->attr.flavor)))
2689 : : return MATCH_ERROR;
2690 : :
2691 : 3991 : if (tbp->n.tb->is_generic)
2692 : : tbp_sym = NULL;
2693 : : else
2694 : 3216 : tbp_sym = tbp->n.tb->u.specific->n.sym;
2695 : :
2696 : 3991 : primary->expr_type = EXPR_COMPCALL;
2697 : 3991 : primary->value.compcall.tbp = tbp->n.tb;
2698 : 3991 : primary->value.compcall.name = tbp->name;
2699 : 3991 : primary->value.compcall.ignore_pass = 0;
2700 : 3991 : primary->value.compcall.assign = 0;
2701 : 3991 : primary->value.compcall.base_object = NULL;
2702 : 3991 : gcc_assert (primary->symtree->n.sym->attr.referenced);
2703 : 3991 : if (tbp_sym)
2704 : 3216 : primary->ts = tbp_sym->ts;
2705 : : else
2706 : 775 : gfc_clear_ts (&primary->ts);
2707 : :
2708 : 3991 : m = gfc_match_actual_arglist (tbp->n.tb->subroutine,
2709 : : &primary->value.compcall.actual);
2710 : 3991 : if (m == MATCH_ERROR)
2711 : : return MATCH_ERROR;
2712 : 3991 : if (m == MATCH_NO)
2713 : : {
2714 : 162 : if (sub_flag)
2715 : 161 : primary->value.compcall.actual = NULL;
2716 : : else
2717 : : {
2718 : 1 : gfc_error ("Expected argument list at %C");
2719 : 1 : return MATCH_ERROR;
2720 : : }
2721 : : }
2722 : :
2723 : 146641 : break;
2724 : : }
2725 : :
2726 : 165608 : previous = component;
2727 : :
2728 : 165608 : if (!inquiry && !intrinsic)
2729 : 163894 : component = gfc_find_component (sym, name, false, false, &tmp);
2730 : : else
2731 : : component = NULL;
2732 : :
2733 : 165608 : if (previous && inquiry
2734 : 415 : && (previous->attr.pdt_kind || previous->attr.pdt_len))
2735 : : {
2736 : 4 : gfc_error_now ("R901: A type parameter ref is not a designtor and "
2737 : : "cannot be followed by the type inquiry ref at %C");
2738 : 4 : return MATCH_ERROR;
2739 : : }
2740 : :
2741 : 165604 : if (intrinsic && !inquiry)
2742 : : {
2743 : 3 : if (previous)
2744 : 2 : gfc_error ("%qs at %C is not an inquiry reference to an intrinsic "
2745 : : "type component %qs", name, previous->name);
2746 : : else
2747 : 1 : gfc_error ("%qs at %C is not an inquiry reference to an intrinsic "
2748 : : "type component", name);
2749 : 3 : return MATCH_ERROR;
2750 : : }
2751 : 165601 : else if (component == NULL && !inquiry)
2752 : : return MATCH_ERROR;
2753 : :
2754 : : /* Extend the reference chain determined by gfc_find_component or
2755 : : is_inquiry_ref. */
2756 : 165554 : if (primary->ref == NULL)
2757 : 99179 : primary->ref = tmp;
2758 : : else
2759 : : {
2760 : : /* Find end of reference chain if inquiry reference and tail not
2761 : : set. */
2762 : 66375 : if (tail == NULL && inquiry && tmp)
2763 : 11 : tail = extend_ref (primary, tail);
2764 : :
2765 : : /* Set by the for loop below for the last component ref. */
2766 : 66375 : gcc_assert (tail != NULL);
2767 : 66375 : tail->next = tmp;
2768 : : }
2769 : :
2770 : : /* The reference chain may be longer than one hop for union
2771 : : subcomponents; find the new tail. */
2772 : 167530 : for (tail = tmp; tail->next; tail = tail->next)
2773 : : ;
2774 : :
2775 : 165554 : if (tmp && tmp->type == REF_INQUIRY)
2776 : : {
2777 : 1707 : if (!primary->where.u.lb || !primary->where.nextc)
2778 : 1523 : primary->where = gfc_current_locus;
2779 : 1707 : gfc_simplify_expr (primary, 0);
2780 : :
2781 : 1707 : if (primary->expr_type == EXPR_CONSTANT)
2782 : 354 : goto check_done;
2783 : :
2784 : 1353 : if (primary->ref == NULL)
2785 : 60 : goto check_done;
2786 : :
2787 : 1293 : switch (tmp->u.i)
2788 : : {
2789 : 1082 : case INQUIRY_RE:
2790 : 1082 : case INQUIRY_IM:
2791 : 1082 : if (!gfc_notify_std (GFC_STD_F2008, "RE or IM part_ref at %C"))
2792 : : return MATCH_ERROR;
2793 : :
2794 : 1082 : if (primary->ts.type != BT_COMPLEX)
2795 : : {
2796 : 0 : gfc_error ("The RE or IM part_ref at %C must be "
2797 : : "applied to a COMPLEX expression");
2798 : 0 : return MATCH_ERROR;
2799 : : }
2800 : 1082 : primary->ts.type = BT_REAL;
2801 : 1082 : break;
2802 : :
2803 : 159 : case INQUIRY_LEN:
2804 : 159 : if (!gfc_notify_std (GFC_STD_F2003, "LEN part_ref at %C"))
2805 : : return MATCH_ERROR;
2806 : :
2807 : 159 : if (primary->ts.type != BT_CHARACTER)
2808 : : {
2809 : 0 : gfc_error ("The LEN part_ref at %C must be applied "
2810 : : "to a CHARACTER expression");
2811 : 0 : return MATCH_ERROR;
2812 : : }
2813 : 159 : primary->ts.u.cl = NULL;
2814 : 159 : primary->ts.type = BT_INTEGER;
2815 : 159 : primary->ts.kind = gfc_default_integer_kind;
2816 : 159 : break;
2817 : :
2818 : 52 : case INQUIRY_KIND:
2819 : 52 : if (!gfc_notify_std (GFC_STD_F2003, "KIND part_ref at %C"))
2820 : : return MATCH_ERROR;
2821 : :
2822 : 52 : if (primary->ts.type == BT_CLASS
2823 : 52 : || primary->ts.type == BT_DERIVED)
2824 : : {
2825 : 0 : gfc_error ("The KIND part_ref at %C must be applied "
2826 : : "to an expression of intrinsic type");
2827 : 0 : return MATCH_ERROR;
2828 : : }
2829 : 52 : primary->ts.type = BT_INTEGER;
2830 : 52 : primary->ts.kind = gfc_default_integer_kind;
2831 : 52 : break;
2832 : :
2833 : 0 : default:
2834 : 0 : gcc_unreachable ();
2835 : : }
2836 : :
2837 : 1293 : goto check_done;
2838 : : }
2839 : :
2840 : 163847 : primary->ts = component->ts;
2841 : :
2842 : 163847 : if (component->attr.proc_pointer && ppc_arg)
2843 : : {
2844 : : /* Procedure pointer component call: Look for argument list. */
2845 : 1083 : m = gfc_match_actual_arglist (sub_flag,
2846 : : &primary->value.compcall.actual);
2847 : 1083 : if (m == MATCH_ERROR)
2848 : : return MATCH_ERROR;
2849 : :
2850 : 1083 : if (m == MATCH_NO && !gfc_matching_ptr_assignment
2851 : 263 : && !gfc_matching_procptr_assignment && !matching_actual_arglist)
2852 : : {
2853 : 2 : gfc_error ("Procedure pointer component %qs requires an "
2854 : : "argument list at %C", component->name);
2855 : 2 : return MATCH_ERROR;
2856 : : }
2857 : :
2858 : 1081 : if (m == MATCH_YES)
2859 : 819 : primary->expr_type = EXPR_PPC;
2860 : :
2861 : : break;
2862 : : }
2863 : :
2864 : 162764 : if (component->as != NULL && !component->attr.proc_pointer)
2865 : : {
2866 : 56333 : tail = extend_ref (primary, tail);
2867 : 56333 : tail->type = REF_ARRAY;
2868 : :
2869 : 112666 : m = gfc_match_array_ref (&tail->u.ar, component->as, equiv_flag,
2870 : 56333 : component->as->corank);
2871 : 56333 : if (m != MATCH_YES)
2872 : : return m;
2873 : : }
2874 : 106431 : else if (component->ts.type == BT_CLASS && component->attr.class_ok
2875 : 10942 : && CLASS_DATA (component)->as && !component->attr.proc_pointer)
2876 : : {
2877 : 5310 : tail = extend_ref (primary, tail);
2878 : 5310 : tail->type = REF_ARRAY;
2879 : :
2880 : 10620 : m = gfc_match_array_ref (&tail->u.ar, CLASS_DATA (component)->as,
2881 : : equiv_flag,
2882 : 5310 : CLASS_DATA (component)->as->corank);
2883 : 5310 : if (m != MATCH_YES)
2884 : : return m;
2885 : : }
2886 : :
2887 : 101121 : check_done:
2888 : : /* In principle, we could have eg. expr%re%kind so we must allow for
2889 : : this possibility. */
2890 : 164471 : if (gfc_match_char ('%') == MATCH_YES)
2891 : : {
2892 : 22531 : if (component && (component->ts.type == BT_DERIVED
2893 : 3699 : || component->ts.type == BT_CLASS))
2894 : 22056 : sym = component->ts.u.derived;
2895 : 22531 : continue;
2896 : : }
2897 : 141940 : else if (inquiry)
2898 : : break;
2899 : :
2900 : 130917 : if ((component->ts.type != BT_DERIVED && component->ts.type != BT_CLASS)
2901 : 147951 : || gfc_match_member_sep (component->ts.u.derived) != MATCH_YES)
2902 : : break;
2903 : :
2904 : 370 : if (component->ts.type == BT_DERIVED || component->ts.type == BT_CLASS)
2905 : 370 : sym = component->ts.u.derived;
2906 : : }
2907 : :
2908 : 4981334 : check_substring:
2909 : 4981334 : unknown = false;
2910 : 4981334 : if (primary->ts.type == BT_UNKNOWN && !gfc_fl_struct (sym->attr.flavor))
2911 : : {
2912 : 2625111 : if (gfc_get_default_type (sym->name, sym->ns)->type == BT_CHARACTER)
2913 : : {
2914 : 352 : gfc_set_default_type (sym, 0, sym->ns);
2915 : 352 : primary->ts = sym->ts;
2916 : 352 : unknown = true;
2917 : : }
2918 : : }
2919 : :
2920 : 4981334 : if (primary->ts.type == BT_CHARACTER)
2921 : : {
2922 : 299622 : bool def = primary->ts.deferred == 1;
2923 : 299622 : switch (match_substring (primary->ts.u.cl, equiv_flag, &substring, def))
2924 : : {
2925 : 13399 : case MATCH_YES:
2926 : 13399 : if (tail == NULL)
2927 : 8227 : primary->ref = substring;
2928 : : else
2929 : 5172 : tail->next = substring;
2930 : :
2931 : 13399 : if (primary->expr_type == EXPR_CONSTANT)
2932 : 755 : primary->expr_type = EXPR_SUBSTRING;
2933 : :
2934 : 13399 : if (substring)
2935 : 13219 : primary->ts.u.cl = NULL;
2936 : :
2937 : 13399 : gfc_gobble_whitespace ();
2938 : 13399 : if (gfc_peek_ascii_char () == '(')
2939 : : {
2940 : 5 : gfc_error_now ("Unexpected array/substring ref at %C");
2941 : 5 : return MATCH_ERROR;
2942 : : }
2943 : : break;
2944 : :
2945 : 286223 : case MATCH_NO:
2946 : 286223 : if (unknown)
2947 : : {
2948 : 351 : gfc_clear_ts (&primary->ts);
2949 : 351 : gfc_clear_ts (&sym->ts);
2950 : : }
2951 : : break;
2952 : :
2953 : : case MATCH_ERROR:
2954 : : return MATCH_ERROR;
2955 : : }
2956 : : }
2957 : :
2958 : : /* F08:C611. */
2959 : 4981329 : if (primary->ts.type == BT_DERIVED && primary->ref
2960 : 27448 : && primary->ts.u.derived && primary->ts.u.derived->attr.abstract)
2961 : : {
2962 : 6 : gfc_error ("Nonpolymorphic reference to abstract type at %C");
2963 : 6 : return MATCH_ERROR;
2964 : : }
2965 : :
2966 : : /* F08:C727. */
2967 : 4981323 : if (primary->expr_type == EXPR_PPC && gfc_is_coindexed (primary))
2968 : : {
2969 : 3 : gfc_error ("Coindexed procedure-pointer component at %C");
2970 : 3 : return MATCH_ERROR;
2971 : : }
2972 : :
2973 : : return MATCH_YES;
2974 : : }
2975 : :
2976 : :
2977 : : /* Given an expression that is a variable, figure out what the
2978 : : ultimate variable's type and attribute is, traversing the reference
2979 : : structures if necessary.
2980 : :
2981 : : This subroutine is trickier than it looks. We start at the base
2982 : : symbol and store the attribute. Component references load a
2983 : : completely new attribute.
2984 : :
2985 : : A couple of rules come into play. Subobjects of targets are always
2986 : : targets themselves. If we see a component that goes through a
2987 : : pointer, then the expression must also be a target, since the
2988 : : pointer is associated with something (if it isn't core will soon be
2989 : : dumped). If we see a full part or section of an array, the
2990 : : expression is also an array.
2991 : :
2992 : : We can have at most one full array reference. */
2993 : :
2994 : : symbol_attribute
2995 : 5032099 : gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
2996 : : {
2997 : 5032099 : int dimension, codimension, pointer, allocatable, target, optional;
2998 : 5032099 : symbol_attribute attr;
2999 : 5032099 : gfc_ref *ref;
3000 : 5032099 : gfc_symbol *sym;
3001 : 5032099 : gfc_component *comp;
3002 : 5032099 : bool has_inquiry_part;
3003 : 5032099 : bool has_substring_ref = false;
3004 : :
3005 : 5032099 : if (expr->expr_type != EXPR_VARIABLE
3006 : 27441 : && expr->expr_type != EXPR_FUNCTION
3007 : 9 : && !(expr->expr_type == EXPR_NULL && expr->ts.type != BT_UNKNOWN))
3008 : 0 : gfc_internal_error ("gfc_variable_attr(): Expression isn't a variable");
3009 : :
3010 : 5032099 : sym = expr->symtree->n.sym;
3011 : 5032099 : attr = sym->attr;
3012 : :
3013 : 5032099 : optional = attr.optional;
3014 : 5032099 : if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived)
3015 : : {
3016 : 164123 : dimension = CLASS_DATA (sym)->attr.dimension;
3017 : 164123 : codimension = CLASS_DATA (sym)->attr.codimension;
3018 : 164123 : pointer = CLASS_DATA (sym)->attr.class_pointer;
3019 : 164123 : allocatable = CLASS_DATA (sym)->attr.allocatable;
3020 : : }
3021 : : else
3022 : : {
3023 : 4867976 : dimension = attr.dimension;
3024 : 4867976 : codimension = attr.codimension;
3025 : 4867976 : pointer = attr.pointer;
3026 : 4867976 : allocatable = attr.allocatable;
3027 : : }
3028 : :
3029 : 5032099 : target = attr.target;
3030 : 5032099 : if (pointer || attr.proc_pointer)
3031 : 250053 : target = 1;
3032 : :
3033 : : /* F2018:11.1.3.3: Other attributes of associate names
3034 : : "The associating entity does not have the ALLOCATABLE or POINTER
3035 : : attributes; it has the TARGET attribute if and only if the selector is
3036 : : a variable and has either the TARGET or POINTER attribute." */
3037 : 5032099 : if (sym->attr.associate_var && sym->assoc && sym->assoc->target)
3038 : : {
3039 : 32296 : if (sym->assoc->target->expr_type == EXPR_VARIABLE)
3040 : : {
3041 : 29434 : symbol_attribute tgt_attr;
3042 : 29434 : tgt_attr = gfc_expr_attr (sym->assoc->target);
3043 : 38042 : target = (tgt_attr.pointer || tgt_attr.target);
3044 : : }
3045 : : else
3046 : : target = 0;
3047 : : }
3048 : :
3049 : 5032099 : if (ts != NULL && expr->ts.type == BT_UNKNOWN)
3050 : 51482 : *ts = sym->ts;
3051 : :
3052 : : /* Catch left-overs from match_actual_arg, where an actual argument of a
3053 : : procedure is given a temporary ts.type == BT_PROCEDURE. The fixup is
3054 : : needed for structure constructors in DATA statements, where a pointer
3055 : : is associated with a data target, and the argument has not been fully
3056 : : resolved yet. Components references are dealt with further below. */
3057 : 51482 : if (ts != NULL
3058 : 1289401 : && expr->ts.type == BT_PROCEDURE
3059 : 2825 : && expr->ref == NULL
3060 : 2825 : && attr.flavor != FL_PROCEDURE
3061 : 87 : && attr.target)
3062 : 1 : *ts = sym->ts;
3063 : :
3064 : 5032099 : has_inquiry_part = false;
3065 : 6814811 : for (ref = expr->ref; ref; ref = ref->next)
3066 : 1784380 : if (ref->type == REF_SUBSTRING)
3067 : : {
3068 : : has_substring_ref = true;
3069 : : optional = false;
3070 : : }
3071 : 1766442 : else if (ref->type == REF_INQUIRY)
3072 : : {
3073 : : has_inquiry_part = true;
3074 : : optional = false;
3075 : : break;
3076 : : }
3077 : :
3078 : 6816486 : for (ref = expr->ref; ref; ref = ref->next)
3079 : 1784387 : switch (ref->type)
3080 : : {
3081 : 1398571 : case REF_ARRAY:
3082 : :
3083 : 1398571 : switch (ref->u.ar.type)
3084 : : {
3085 : : case AR_FULL:
3086 : 1784387 : dimension = 1;
3087 : : break;
3088 : :
3089 : 111911 : case AR_SECTION:
3090 : 111911 : allocatable = pointer = 0;
3091 : 111911 : dimension = 1;
3092 : 111911 : optional = false;
3093 : 111911 : break;
3094 : :
3095 : 314904 : case AR_ELEMENT:
3096 : : /* Handle coarrays. */
3097 : 314904 : if (ref->u.ar.dimen > 0)
3098 : 1784387 : allocatable = pointer = optional = false;
3099 : : break;
3100 : :
3101 : : case AR_UNKNOWN:
3102 : : /* For standard conforming code, AR_UNKNOWN should not happen.
3103 : : For nonconforming code, gfortran can end up here. Treat it
3104 : : as a no-op. */
3105 : : break;
3106 : : }
3107 : :
3108 : : break;
3109 : :
3110 : 366203 : case REF_COMPONENT:
3111 : 366203 : optional = false;
3112 : 366203 : comp = ref->u.c.component;
3113 : 366203 : attr = comp->attr;
3114 : 366203 : if (ts != NULL && !has_inquiry_part)
3115 : : {
3116 : 82586 : *ts = comp->ts;
3117 : : /* Don't set the string length if a substring reference
3118 : : follows. */
3119 : 82586 : if (ts->type == BT_CHARACTER && has_substring_ref)
3120 : 294 : ts->u.cl = NULL;
3121 : : }
3122 : :
3123 : 366203 : if (comp->ts.type == BT_CLASS)
3124 : : {
3125 : 29389 : dimension = CLASS_DATA (comp)->attr.dimension;
3126 : 29389 : codimension = CLASS_DATA (comp)->attr.codimension;
3127 : 29389 : pointer = CLASS_DATA (comp)->attr.class_pointer;
3128 : 29389 : allocatable = CLASS_DATA (comp)->attr.allocatable;
3129 : : }
3130 : : else
3131 : : {
3132 : 336814 : dimension = comp->attr.dimension;
3133 : 336814 : codimension = comp->attr.codimension;
3134 : 336814 : if (expr->ts.type == BT_CLASS && strcmp (comp->name, "_data") == 0)
3135 : 18751 : pointer = comp->attr.class_pointer;
3136 : : else
3137 : 318063 : pointer = comp->attr.pointer;
3138 : 336814 : allocatable = comp->attr.allocatable;
3139 : : }
3140 : 366203 : if (pointer || attr.proc_pointer)
3141 : 68453 : target = 1;
3142 : :
3143 : : break;
3144 : :
3145 : 19613 : case REF_INQUIRY:
3146 : 19613 : case REF_SUBSTRING:
3147 : 19613 : allocatable = pointer = optional = false;
3148 : 19613 : break;
3149 : : }
3150 : :
3151 : 5032099 : attr.dimension = dimension;
3152 : 5032099 : attr.codimension = codimension;
3153 : 5032099 : attr.pointer = pointer;
3154 : 5032099 : attr.allocatable = allocatable;
3155 : 5032099 : attr.target = target;
3156 : 5032099 : attr.save = sym->attr.save;
3157 : 5032099 : attr.optional = optional;
3158 : :
3159 : 5032099 : return attr;
3160 : : }
3161 : :
3162 : :
3163 : : /* Return the attribute from a general expression. */
3164 : :
3165 : : symbol_attribute
3166 : 4410566 : gfc_expr_attr (gfc_expr *e)
3167 : : {
3168 : 4410566 : symbol_attribute attr;
3169 : :
3170 : 4410566 : switch (e->expr_type)
3171 : : {
3172 : 3706592 : case EXPR_VARIABLE:
3173 : 3706592 : attr = gfc_variable_attr (e, NULL);
3174 : 3706592 : break;
3175 : :
3176 : 42773 : case EXPR_FUNCTION:
3177 : 42773 : gfc_clear_attr (&attr);
3178 : :
3179 : 42773 : if (e->value.function.esym && e->value.function.esym->result)
3180 : : {
3181 : 15061 : gfc_symbol *sym = e->value.function.esym->result;
3182 : 15061 : attr = sym->attr;
3183 : 15061 : if (sym->ts.type == BT_CLASS && sym->attr.class_ok)
3184 : : {
3185 : 1877 : attr.dimension = CLASS_DATA (sym)->attr.dimension;
3186 : 1877 : attr.pointer = CLASS_DATA (sym)->attr.class_pointer;
3187 : 1877 : attr.allocatable = CLASS_DATA (sym)->attr.allocatable;
3188 : : }
3189 : : }
3190 : 27712 : else if (e->value.function.isym
3191 : 25542 : && e->value.function.isym->transformational
3192 : 15594 : && e->ts.type == BT_CLASS)
3193 : 294 : attr = CLASS_DATA (e)->attr;
3194 : 27418 : else if (e->symtree)
3195 : 27418 : attr = gfc_variable_attr (e, NULL);
3196 : :
3197 : : /* TODO: NULL() returns pointers. May have to take care of this
3198 : : here. */
3199 : :
3200 : : break;
3201 : :
3202 : 661201 : default:
3203 : 661201 : gfc_clear_attr (&attr);
3204 : 661201 : break;
3205 : : }
3206 : :
3207 : 4410566 : return attr;
3208 : : }
3209 : :
3210 : :
3211 : : /* Given an expression, figure out what the ultimate expression
3212 : : attribute is. This routine is similar to gfc_variable_attr with
3213 : : parts of gfc_expr_attr, but focuses more on the needs of
3214 : : coarrays. For coarrays a codimension attribute is kind of
3215 : : "infectious" being propagated once set and never cleared.
3216 : : The coarray_comp is only set, when the expression refs a coarray
3217 : : component. REFS_COMP is set when present to true only, when this EXPR
3218 : : refs a (non-_data) component. To check whether EXPR refs an allocatable
3219 : : component in a derived type coarray *refs_comp needs to be set and
3220 : : coarray_comp has to false. */
3221 : :
3222 : : static symbol_attribute
3223 : 12631 : caf_variable_attr (gfc_expr *expr, bool in_allocate, bool *refs_comp)
3224 : : {
3225 : 12631 : int dimension, codimension, pointer, allocatable, target, coarray_comp;
3226 : 12631 : symbol_attribute attr;
3227 : 12631 : gfc_ref *ref;
3228 : 12631 : gfc_symbol *sym;
3229 : 12631 : gfc_component *comp;
3230 : :
3231 : 12631 : if (expr->expr_type != EXPR_VARIABLE && expr->expr_type != EXPR_FUNCTION)
3232 : 0 : gfc_internal_error ("gfc_caf_attr(): Expression isn't a variable");
3233 : :
3234 : 12631 : sym = expr->symtree->n.sym;
3235 : 12631 : gfc_clear_attr (&attr);
3236 : :
3237 : 12631 : if (refs_comp)
3238 : 7780 : *refs_comp = false;
3239 : :
3240 : 12631 : if (sym->ts.type == BT_CLASS && sym->attr.class_ok)
3241 : : {
3242 : 369 : dimension = CLASS_DATA (sym)->attr.dimension;
3243 : 369 : codimension = CLASS_DATA (sym)->attr.codimension;
3244 : 369 : pointer = CLASS_DATA (sym)->attr.class_pointer;
3245 : 369 : allocatable = CLASS_DATA (sym)->attr.allocatable;
3246 : 369 : attr.alloc_comp = CLASS_DATA (sym)->ts.u.derived->attr.alloc_comp;
3247 : 369 : attr.pointer_comp = CLASS_DATA (sym)->ts.u.derived->attr.pointer_comp;
3248 : : }
3249 : : else
3250 : : {
3251 : 12262 : dimension = sym->attr.dimension;
3252 : 12262 : codimension = sym->attr.codimension;
3253 : 12262 : pointer = sym->attr.pointer;
3254 : 12262 : allocatable = sym->attr.allocatable;
3255 : 24524 : attr.alloc_comp = sym->ts.type == BT_DERIVED
3256 : 12262 : ? sym->ts.u.derived->attr.alloc_comp : 0;
3257 : 12262 : attr.pointer_comp = sym->ts.type == BT_DERIVED
3258 : 12262 : ? sym->ts.u.derived->attr.pointer_comp : 0;
3259 : : }
3260 : :
3261 : 12631 : target = coarray_comp = 0;
3262 : 12631 : if (pointer || attr.proc_pointer)
3263 : 523 : target = 1;
3264 : :
3265 : 22502 : for (ref = expr->ref; ref; ref = ref->next)
3266 : 9871 : switch (ref->type)
3267 : : {
3268 : 6409 : case REF_ARRAY:
3269 : :
3270 : 6409 : switch (ref->u.ar.type)
3271 : : {
3272 : : case AR_FULL:
3273 : : case AR_SECTION:
3274 : : dimension = 1;
3275 : 6409 : break;
3276 : :
3277 : 2900 : case AR_ELEMENT:
3278 : : /* Handle coarrays. */
3279 : 2900 : if (ref->u.ar.dimen > 0 && !in_allocate)
3280 : 6409 : allocatable = pointer = 0;
3281 : : break;
3282 : :
3283 : 0 : case AR_UNKNOWN:
3284 : : /* If any of start, end or stride is not integer, there will
3285 : : already have been an error issued. */
3286 : 0 : int errors;
3287 : 0 : gfc_get_errors (NULL, &errors);
3288 : 0 : if (errors == 0)
3289 : 0 : gfc_internal_error ("gfc_caf_attr(): Bad array reference");
3290 : : }
3291 : :
3292 : : break;
3293 : :
3294 : 3461 : case REF_COMPONENT:
3295 : 3461 : comp = ref->u.c.component;
3296 : :
3297 : 3461 : if (comp->ts.type == BT_CLASS)
3298 : : {
3299 : : /* Set coarray_comp only, when this component introduces the
3300 : : coarray. */
3301 : 13 : coarray_comp = !codimension && CLASS_DATA (comp)->attr.codimension;
3302 : 13 : codimension |= CLASS_DATA (comp)->attr.codimension;
3303 : 13 : pointer = CLASS_DATA (comp)->attr.class_pointer;
3304 : 13 : allocatable = CLASS_DATA (comp)->attr.allocatable;
3305 : : }
3306 : : else
3307 : : {
3308 : : /* Set coarray_comp only, when this component introduces the
3309 : : coarray. */
3310 : 3448 : coarray_comp = !codimension && comp->attr.codimension;
3311 : 3448 : codimension |= comp->attr.codimension;
3312 : 3448 : pointer = comp->attr.pointer;
3313 : 3448 : allocatable = comp->attr.allocatable;
3314 : : }
3315 : :
3316 : 3461 : if (refs_comp && strcmp (comp->name, "_data") != 0
3317 : 2060 : && (ref->next == NULL
3318 : 1569 : || (ref->next->type == REF_ARRAY && ref->next->next == NULL)))
3319 : 1501 : *refs_comp = true;
3320 : :
3321 : 3461 : if (pointer || attr.proc_pointer)
3322 : 673 : target = 1;
3323 : :
3324 : : break;
3325 : :
3326 : : case REF_SUBSTRING:
3327 : : case REF_INQUIRY:
3328 : 9871 : allocatable = pointer = 0;
3329 : : break;
3330 : : }
3331 : :
3332 : 12631 : attr.dimension = dimension;
3333 : 12631 : attr.codimension = codimension;
3334 : 12631 : attr.pointer = pointer;
3335 : 12631 : attr.allocatable = allocatable;
3336 : 12631 : attr.target = target;
3337 : 12631 : attr.save = sym->attr.save;
3338 : 12631 : attr.coarray_comp = coarray_comp;
3339 : :
3340 : 12631 : return attr;
3341 : : }
3342 : :
3343 : :
3344 : : symbol_attribute
3345 : 15097 : gfc_caf_attr (gfc_expr *e, bool in_allocate, bool *refs_comp)
3346 : : {
3347 : 15097 : symbol_attribute attr;
3348 : :
3349 : 15097 : switch (e->expr_type)
3350 : : {
3351 : 11469 : case EXPR_VARIABLE:
3352 : 11469 : attr = caf_variable_attr (e, in_allocate, refs_comp);
3353 : 11469 : break;
3354 : :
3355 : 1166 : case EXPR_FUNCTION:
3356 : 1166 : gfc_clear_attr (&attr);
3357 : :
3358 : 1166 : if (e->value.function.esym && e->value.function.esym->result)
3359 : : {
3360 : 4 : gfc_symbol *sym = e->value.function.esym->result;
3361 : 4 : attr = sym->attr;
3362 : 4 : if (sym->ts.type == BT_CLASS)
3363 : : {
3364 : 0 : attr.dimension = CLASS_DATA (sym)->attr.dimension;
3365 : 0 : attr.pointer = CLASS_DATA (sym)->attr.class_pointer;
3366 : 0 : attr.allocatable = CLASS_DATA (sym)->attr.allocatable;
3367 : 0 : attr.alloc_comp = CLASS_DATA (sym)->ts.u.derived->attr.alloc_comp;
3368 : 0 : attr.pointer_comp = CLASS_DATA (sym)->ts.u.derived
3369 : 0 : ->attr.pointer_comp;
3370 : : }
3371 : : }
3372 : 1162 : else if (e->symtree)
3373 : 1162 : attr = caf_variable_attr (e, in_allocate, refs_comp);
3374 : : else
3375 : 0 : gfc_clear_attr (&attr);
3376 : : break;
3377 : :
3378 : 2462 : default:
3379 : 2462 : gfc_clear_attr (&attr);
3380 : 2462 : break;
3381 : : }
3382 : :
3383 : 15097 : return attr;
3384 : : }
3385 : :
3386 : :
3387 : : /* Match a structure constructor. The initial symbol has already been
3388 : : seen. */
3389 : :
3390 : : typedef struct gfc_structure_ctor_component
3391 : : {
3392 : : char* name;
3393 : : gfc_expr* val;
3394 : : locus where;
3395 : : struct gfc_structure_ctor_component* next;
3396 : : }
3397 : : gfc_structure_ctor_component;
3398 : :
3399 : : #define gfc_get_structure_ctor_component() XCNEW (gfc_structure_ctor_component)
3400 : :
3401 : : static void
3402 : 10043 : gfc_free_structure_ctor_component (gfc_structure_ctor_component *comp)
3403 : : {
3404 : 10043 : free (comp->name);
3405 : 10043 : gfc_free_expr (comp->val);
3406 : 10043 : free (comp);
3407 : 10043 : }
3408 : :
3409 : :
3410 : : /* Translate the component list into the actual constructor by sorting it in
3411 : : the order required; this also checks along the way that each and every
3412 : : component actually has an initializer and handles default initializers
3413 : : for components without explicit value given. */
3414 : : static bool
3415 : 7052 : build_actual_constructor (gfc_structure_ctor_component **comp_head,
3416 : : gfc_constructor_base *ctor_head, gfc_symbol *sym)
3417 : : {
3418 : 7052 : gfc_structure_ctor_component *comp_iter;
3419 : 7052 : gfc_component *comp;
3420 : :
3421 : 18459 : for (comp = sym->components; comp; comp = comp->next)
3422 : : {
3423 : 11412 : gfc_structure_ctor_component **next_ptr;
3424 : 11412 : gfc_expr *value = NULL;
3425 : :
3426 : : /* Try to find the initializer for the current component by name. */
3427 : 11412 : next_ptr = comp_head;
3428 : 12561 : for (comp_iter = *comp_head; comp_iter; comp_iter = comp_iter->next)
3429 : : {
3430 : 11168 : if (!strcmp (comp_iter->name, comp->name))
3431 : : break;
3432 : 1149 : next_ptr = &comp_iter->next;
3433 : : }
3434 : :
3435 : : /* If an extension, try building the parent derived type by building
3436 : : a value expression for the parent derived type and calling self. */
3437 : 11412 : if (!comp_iter && comp == sym->components && sym->attr.extension)
3438 : : {
3439 : 106 : value = gfc_get_structure_constructor_expr (comp->ts.type,
3440 : : comp->ts.kind,
3441 : : &gfc_current_locus);
3442 : 106 : value->ts = comp->ts;
3443 : :
3444 : 106 : if (!build_actual_constructor (comp_head,
3445 : : &value->value.constructor,
3446 : 106 : comp->ts.u.derived))
3447 : : {
3448 : 0 : gfc_free_expr (value);
3449 : 0 : return false;
3450 : : }
3451 : :
3452 : 106 : gfc_constructor_append_expr (ctor_head, value, NULL);
3453 : 106 : continue;
3454 : : }
3455 : :
3456 : : /* If it was not found, apply NULL expression to set the component as
3457 : : unallocated. Then try the default initializer if there's any;
3458 : : otherwise, it's an error unless this is a deferred parameter. */
3459 : 1287 : if (!comp_iter)
3460 : : {
3461 : : /* F2018 7.5.10: If an allocatable component has no corresponding
3462 : : component-data-source, then that component has an allocation
3463 : : status of unallocated.... */
3464 : 1287 : if (comp->attr.allocatable
3465 : 1152 : || (comp->ts.type == BT_CLASS
3466 : 15 : && CLASS_DATA (comp)->attr.allocatable))
3467 : : {
3468 : 144 : if (!gfc_notify_std (GFC_STD_F2008, "No initializer for "
3469 : : "allocatable component %qs given in the "
3470 : : "structure constructor at %C", comp->name))
3471 : : return false;
3472 : 144 : value = gfc_get_null_expr (&gfc_current_locus);
3473 : : }
3474 : : /* ....(Preceding sentence) If a component with default
3475 : : initialization has no corresponding component-data-source, then
3476 : : the default initialization is applied to that component. */
3477 : 1143 : else if (comp->initializer)
3478 : : {
3479 : 643 : if (!gfc_notify_std (GFC_STD_F2003, "Structure constructor "
3480 : : "with missing optional arguments at %C"))
3481 : : return false;
3482 : 641 : value = gfc_copy_expr (comp->initializer);
3483 : : }
3484 : : /* Do not trap components such as the string length for deferred
3485 : : length character components. */
3486 : 500 : else if (!comp->attr.artificial)
3487 : : {
3488 : 3 : gfc_error ("No initializer for component %qs given in the"
3489 : : " structure constructor at %C", comp->name);
3490 : 3 : return false;
3491 : : }
3492 : : }
3493 : : else
3494 : 10019 : value = comp_iter->val;
3495 : :
3496 : : /* Add the value to the constructor chain built. */
3497 : 11301 : gfc_constructor_append_expr (ctor_head, value, NULL);
3498 : :
3499 : : /* Remove the entry from the component list. We don't want the expression
3500 : : value to be free'd, so set it to NULL. */
3501 : 11301 : if (comp_iter)
3502 : : {
3503 : 10019 : *next_ptr = comp_iter->next;
3504 : 10019 : comp_iter->val = NULL;
3505 : 10019 : gfc_free_structure_ctor_component (comp_iter);
3506 : : }
3507 : : }
3508 : : return true;
3509 : : }
3510 : :
3511 : :
3512 : : bool
3513 : 6961 : gfc_convert_to_structure_constructor (gfc_expr *e, gfc_symbol *sym, gfc_expr **cexpr,
3514 : : gfc_actual_arglist **arglist,
3515 : : bool parent)
3516 : : {
3517 : 6961 : gfc_actual_arglist *actual;
3518 : 6961 : gfc_structure_ctor_component *comp_tail, *comp_head, *comp_iter;
3519 : 6961 : gfc_constructor_base ctor_head = NULL;
3520 : 6961 : gfc_component *comp; /* Is set NULL when named component is first seen */
3521 : 6961 : const char* last_name = NULL;
3522 : 6961 : locus old_locus;
3523 : 6961 : gfc_expr *expr;
3524 : :
3525 : 6961 : expr = parent ? *cexpr : e;
3526 : 6961 : old_locus = gfc_current_locus;
3527 : 6961 : if (parent)
3528 : : ; /* gfc_current_locus = *arglist->expr ? ->where;*/
3529 : : else
3530 : 6229 : gfc_current_locus = expr->where;
3531 : :
3532 : 6961 : comp_tail = comp_head = NULL;
3533 : :
3534 : 6961 : if (!parent && sym->attr.abstract)
3535 : : {
3536 : 1 : gfc_error ("Cannot construct ABSTRACT type %qs at %L",
3537 : : sym->name, &expr->where);
3538 : 1 : goto cleanup;
3539 : : }
3540 : :
3541 : 6960 : comp = sym->components;
3542 : 6960 : actual = parent ? *arglist : expr->value.function.actual;
3543 : 16384 : for ( ; actual; )
3544 : : {
3545 : 10043 : gfc_component *this_comp = NULL;
3546 : :
3547 : 10043 : if (!comp_head)
3548 : 6542 : comp_tail = comp_head = gfc_get_structure_ctor_component ();
3549 : : else
3550 : : {
3551 : 3501 : comp_tail->next = gfc_get_structure_ctor_component ();
3552 : 3501 : comp_tail = comp_tail->next;
3553 : : }
3554 : 10043 : if (actual->name)
3555 : : {
3556 : 1005 : if (!gfc_notify_std (GFC_STD_F2003, "Structure"
3557 : : " constructor with named arguments at %C"))
3558 : 1 : goto cleanup;
3559 : :
3560 : 1004 : comp_tail->name = xstrdup (actual->name);
3561 : 1004 : last_name = comp_tail->name;
3562 : 1004 : comp = NULL;
3563 : : }
3564 : : else
3565 : : {
3566 : : /* Components without name are not allowed after the first named
3567 : : component initializer! */
3568 : 9038 : if (!comp || comp->attr.artificial)
3569 : : {
3570 : 2 : if (last_name)
3571 : 0 : gfc_error ("Component initializer without name after component"
3572 : : " named %s at %L", last_name,
3573 : 0 : actual->expr ? &actual->expr->where
3574 : : : &gfc_current_locus);
3575 : : else
3576 : 2 : gfc_error ("Too many components in structure constructor at "
3577 : 2 : "%L", actual->expr ? &actual->expr->where
3578 : : : &gfc_current_locus);
3579 : 2 : goto cleanup;
3580 : : }
3581 : :
3582 : 9036 : comp_tail->name = xstrdup (comp->name);
3583 : : }
3584 : :
3585 : : /* Find the current component in the structure definition and check
3586 : : its access is not private. */
3587 : 10040 : if (comp)
3588 : 9036 : this_comp = gfc_find_component (sym, comp->name, false, false, NULL);
3589 : : else
3590 : : {
3591 : 1004 : this_comp = gfc_find_component (sym, (const char *)comp_tail->name,
3592 : : false, false, NULL);
3593 : 1004 : comp = NULL; /* Reset needed! */
3594 : : }
3595 : :
3596 : : /* Here we can check if a component name is given which does not
3597 : : correspond to any component of the defined structure. */
3598 : 10040 : if (!this_comp)
3599 : 8 : goto cleanup;
3600 : :
3601 : : /* For a constant string constructor, make sure the length is
3602 : : correct; truncate or fill with blanks if needed. */
3603 : 10032 : if (this_comp->ts.type == BT_CHARACTER && !this_comp->attr.allocatable
3604 : 1091 : && this_comp->ts.u.cl && this_comp->ts.u.cl->length
3605 : 1089 : && this_comp->ts.u.cl->length->expr_type == EXPR_CONSTANT
3606 : 1071 : && this_comp->ts.u.cl->length->ts.type == BT_INTEGER
3607 : 1070 : && actual->expr->ts.type == BT_CHARACTER
3608 : 956 : && actual->expr->expr_type == EXPR_CONSTANT)
3609 : : {
3610 : 733 : ptrdiff_t c, e1;
3611 : 733 : c = gfc_mpz_get_hwi (this_comp->ts.u.cl->length->value.integer);
3612 : 733 : e1 = actual->expr->value.character.length;
3613 : :
3614 : 733 : if (c != e1)
3615 : : {
3616 : 249 : ptrdiff_t i, to;
3617 : 249 : gfc_char_t *dest;
3618 : 249 : dest = gfc_get_wide_string (c + 1);
3619 : :
3620 : 249 : to = e1 < c ? e1 : c;
3621 : 4482 : for (i = 0; i < to; i++)
3622 : 4233 : dest[i] = actual->expr->value.character.string[i];
3623 : :
3624 : 5812 : for (i = e1; i < c; i++)
3625 : 5563 : dest[i] = ' ';
3626 : :
3627 : 249 : dest[c] = '\0';
3628 : 249 : free (actual->expr->value.character.string);
3629 : :
3630 : 249 : actual->expr->value.character.length = c;
3631 : 249 : actual->expr->value.character.string = dest;
3632 : :
3633 : 249 : if (warn_line_truncation && c < e1)
3634 : 14 : gfc_warning_now (OPT_Wcharacter_truncation,
3635 : : "CHARACTER expression will be truncated "
3636 : : "in constructor (%td/%td) at %L", c,
3637 : : e1, &actual->expr->where);
3638 : : }
3639 : : }
3640 : :
3641 : 10032 : comp_tail->val = actual->expr;
3642 : 10032 : if (actual->expr != NULL)
3643 : 10032 : comp_tail->where = actual->expr->where;
3644 : 10032 : actual->expr = NULL;
3645 : :
3646 : : /* Check if this component is already given a value. */
3647 : 15928 : for (comp_iter = comp_head; comp_iter != comp_tail;
3648 : 5896 : comp_iter = comp_iter->next)
3649 : : {
3650 : 5897 : gcc_assert (comp_iter);
3651 : 5897 : if (!strcmp (comp_iter->name, comp_tail->name))
3652 : : {
3653 : 1 : gfc_error ("Component %qs is initialized twice in the structure"
3654 : : " constructor at %L", comp_tail->name,
3655 : : comp_tail->val ? &comp_tail->where
3656 : : : &gfc_current_locus);
3657 : 1 : goto cleanup;
3658 : : }
3659 : : }
3660 : :
3661 : : /* F2008, R457/C725, for PURE C1283. */
3662 : 72 : if (this_comp->attr.pointer && comp_tail->val
3663 : 10103 : && gfc_is_coindexed (comp_tail->val))
3664 : : {
3665 : 2 : gfc_error ("Coindexed expression to pointer component %qs in "
3666 : : "structure constructor at %L", comp_tail->name,
3667 : : &comp_tail->where);
3668 : 2 : goto cleanup;
3669 : : }
3670 : :
3671 : : /* If not explicitly a parent constructor, gather up the components
3672 : : and build one. */
3673 : 10029 : if (comp && comp == sym->components
3674 : 6267 : && sym->attr.extension
3675 : 780 : && comp_tail->val
3676 : 780 : && (!gfc_bt_struct (comp_tail->val->ts.type)
3677 : 78 : ||
3678 : 78 : comp_tail->val->ts.u.derived != this_comp->ts.u.derived))
3679 : : {
3680 : 732 : bool m;
3681 : 732 : gfc_actual_arglist *arg_null = NULL;
3682 : :
3683 : 732 : actual->expr = comp_tail->val;
3684 : 732 : comp_tail->val = NULL;
3685 : :
3686 : 732 : m = gfc_convert_to_structure_constructor (NULL,
3687 : : comp->ts.u.derived, &comp_tail->val,
3688 : 732 : comp->ts.u.derived->attr.zero_comp
3689 : : ? &arg_null : &actual, true);
3690 : 732 : if (!m)
3691 : 0 : goto cleanup;
3692 : :
3693 : 732 : if (comp->ts.u.derived->attr.zero_comp)
3694 : : {
3695 : 126 : comp = comp->next;
3696 : 126 : continue;
3697 : : }
3698 : : }
3699 : :
3700 : 606 : if (comp)
3701 : 8902 : comp = comp->next;
3702 : 9903 : if (parent && !comp)
3703 : : break;
3704 : :
3705 : 9298 : if (actual)
3706 : 9297 : actual = actual->next;
3707 : : }
3708 : :
3709 : 6946 : if (!build_actual_constructor (&comp_head, &ctor_head, sym))
3710 : 5 : goto cleanup;
3711 : :
3712 : : /* No component should be left, as this should have caused an error in the
3713 : : loop constructing the component-list (name that does not correspond to any
3714 : : component in the structure definition). */
3715 : 6941 : if (comp_head && sym->attr.extension)
3716 : : {
3717 : 2 : for (comp_iter = comp_head; comp_iter; comp_iter = comp_iter->next)
3718 : : {
3719 : 1 : gfc_error ("component %qs at %L has already been set by a "
3720 : : "parent derived type constructor", comp_iter->name,
3721 : : &comp_iter->where);
3722 : : }
3723 : 1 : goto cleanup;
3724 : : }
3725 : : else
3726 : 6940 : gcc_assert (!comp_head);
3727 : :
3728 : 6940 : if (parent)
3729 : : {
3730 : 732 : expr = gfc_get_structure_constructor_expr (BT_DERIVED, 0, &gfc_current_locus);
3731 : 732 : expr->ts.u.derived = sym;
3732 : 732 : expr->value.constructor = ctor_head;
3733 : 732 : *cexpr = expr;
3734 : : }
3735 : : else
3736 : : {
3737 : 6208 : expr->ts.u.derived = sym;
3738 : 6208 : expr->ts.kind = 0;
3739 : 6208 : expr->ts.type = BT_DERIVED;
3740 : 6208 : expr->value.constructor = ctor_head;
3741 : 6208 : expr->expr_type = EXPR_STRUCTURE;
3742 : : }
3743 : :
3744 : 6940 : gfc_current_locus = old_locus;
3745 : 6940 : if (parent)
3746 : 732 : *arglist = actual;
3747 : : return true;
3748 : :
3749 : 21 : cleanup:
3750 : 21 : gfc_current_locus = old_locus;
3751 : :
3752 : 45 : for (comp_iter = comp_head; comp_iter; )
3753 : : {
3754 : 24 : gfc_structure_ctor_component *next = comp_iter->next;
3755 : 24 : gfc_free_structure_ctor_component (comp_iter);
3756 : 24 : comp_iter = next;
3757 : : }
3758 : 21 : gfc_constructor_free (ctor_head);
3759 : :
3760 : 21 : return false;
3761 : : }
3762 : :
3763 : :
3764 : : match
3765 : 60 : gfc_match_structure_constructor (gfc_symbol *sym, gfc_symtree *symtree,
3766 : : gfc_expr **result)
3767 : : {
3768 : 60 : match m;
3769 : 60 : gfc_expr *e;
3770 : 60 : bool t = true;
3771 : :
3772 : 60 : e = gfc_get_expr ();
3773 : 60 : e->expr_type = EXPR_FUNCTION;
3774 : 60 : e->symtree = symtree;
3775 : 60 : e->where = gfc_current_locus;
3776 : :
3777 : 60 : gcc_assert (gfc_fl_struct (sym->attr.flavor)
3778 : : && symtree->n.sym->attr.flavor == FL_PROCEDURE);
3779 : 60 : e->value.function.esym = sym;
3780 : 60 : e->symtree->n.sym->attr.generic = 1;
3781 : :
3782 : 60 : m = gfc_match_actual_arglist (0, &e->value.function.actual);
3783 : 60 : if (m != MATCH_YES)
3784 : : {
3785 : 0 : gfc_free_expr (e);
3786 : 0 : return m;
3787 : : }
3788 : :
3789 : 60 : if (!gfc_convert_to_structure_constructor (e, sym, NULL, NULL, false))
3790 : : {
3791 : 1 : gfc_free_expr (e);
3792 : 1 : return MATCH_ERROR;
3793 : : }
3794 : :
3795 : : /* If a structure constructor is in a DATA statement, then each entity
3796 : : in the structure constructor must be a constant. Try to reduce the
3797 : : expression here. */
3798 : 59 : if (gfc_in_match_data ())
3799 : 59 : t = gfc_reduce_init_expr (e);
3800 : :
3801 : 59 : if (t)
3802 : : {
3803 : 49 : *result = e;
3804 : 49 : return MATCH_YES;
3805 : : }
3806 : : else
3807 : : {
3808 : 10 : gfc_free_expr (e);
3809 : 10 : return MATCH_ERROR;
3810 : : }
3811 : : }
3812 : :
3813 : :
3814 : : /* If the symbol is an implicit do loop index and implicitly typed,
3815 : : it should not be host associated. Provide a symtree from the
3816 : : current namespace. */
3817 : : static match
3818 : 6749706 : check_for_implicit_index (gfc_symtree **st, gfc_symbol **sym)
3819 : : {
3820 : 6749706 : if ((*sym)->attr.flavor == FL_VARIABLE
3821 : 1963226 : && (*sym)->ns != gfc_current_ns
3822 : 58452 : && (*sym)->attr.implied_index
3823 : 575 : && (*sym)->attr.implicit_type
3824 : 32 : && !(*sym)->attr.use_assoc)
3825 : : {
3826 : 32 : int i;
3827 : 32 : i = gfc_get_sym_tree ((*sym)->name, NULL, st, false);
3828 : 32 : if (i)
3829 : : return MATCH_ERROR;
3830 : 32 : *sym = (*st)->n.sym;
3831 : : }
3832 : : return MATCH_YES;
3833 : : }
3834 : :
3835 : :
3836 : : /* Procedure pointer as function result: Replace the function symbol by the
3837 : : auto-generated hidden result variable named "ppr@". */
3838 : :
3839 : : static bool
3840 : 5044979 : replace_hidden_procptr_result (gfc_symbol **sym, gfc_symtree **st)
3841 : : {
3842 : : /* Check for procedure pointer result variable. */
3843 : 5044979 : if ((*sym)->attr.function && !(*sym)->attr.external
3844 : 1378110 : && (*sym)->result && (*sym)->result != *sym
3845 : 10533 : && (*sym)->result->attr.proc_pointer
3846 : 337 : && (*sym) == gfc_current_ns->proc_name
3847 : 285 : && (*sym) == (*sym)->result->ns->proc_name
3848 : 285 : && strcmp ("ppr@", (*sym)->result->name) == 0)
3849 : : {
3850 : : /* Automatic replacement with "hidden" result variable. */
3851 : 285 : (*sym)->result->attr.referenced = (*sym)->attr.referenced;
3852 : 285 : *sym = (*sym)->result;
3853 : 285 : *st = gfc_find_symtree ((*sym)->ns->sym_root, (*sym)->name);
3854 : 285 : return true;
3855 : : }
3856 : : return false;
3857 : : }
3858 : :
3859 : :
3860 : : /* Matches a variable name followed by anything that might follow it--
3861 : : array reference, argument list of a function, etc. */
3862 : :
3863 : : match
3864 : 4163147 : gfc_match_rvalue (gfc_expr **result)
3865 : : {
3866 : 4163147 : gfc_actual_arglist *actual_arglist;
3867 : 4163147 : char name[GFC_MAX_SYMBOL_LEN + 1], argname[GFC_MAX_SYMBOL_LEN + 1];
3868 : 4163147 : gfc_state_data *st;
3869 : 4163147 : gfc_symbol *sym;
3870 : 4163147 : gfc_symtree *symtree;
3871 : 4163147 : locus where, old_loc;
3872 : 4163147 : gfc_expr *e;
3873 : 4163147 : match m, m2;
3874 : 4163147 : int i;
3875 : 4163147 : gfc_typespec *ts;
3876 : 4163147 : bool implicit_char;
3877 : 4163147 : gfc_ref *ref;
3878 : 4163147 : gfc_symtree *pdt_st;
3879 : :
3880 : 4163147 : m = gfc_match ("%%loc");
3881 : 4163147 : if (m == MATCH_YES)
3882 : : {
3883 : 10878 : if (!gfc_notify_std (GFC_STD_LEGACY, "%%LOC() as an rvalue at %C"))
3884 : : return MATCH_ERROR;
3885 : 10877 : strncpy (name, "loc", 4);
3886 : : }
3887 : :
3888 : : else
3889 : : {
3890 : 4152269 : m = gfc_match_name (name);
3891 : 4152269 : if (m != MATCH_YES)
3892 : : return m;
3893 : : }
3894 : :
3895 : : /* Check if the symbol exists. */
3896 : 3963943 : if (gfc_find_sym_tree (name, NULL, 1, &symtree))
3897 : : return MATCH_ERROR;
3898 : :
3899 : : /* If the symbol doesn't exist, create it unless the name matches a FL_STRUCT
3900 : : type. For derived types we create a generic symbol which links to the
3901 : : derived type symbol; STRUCTUREs are simpler and must not conflict with
3902 : : variables. */
3903 : 3963941 : if (!symtree)
3904 : 174838 : if (gfc_find_sym_tree (gfc_dt_upper_string (name), NULL, 1, &symtree))
3905 : : return MATCH_ERROR;
3906 : 3963941 : if (!symtree || symtree->n.sym->attr.flavor != FL_STRUCT)
3907 : : {
3908 : 3963941 : if (gfc_find_state (COMP_INTERFACE)
3909 : 3963941 : && !gfc_current_ns->has_import_set)
3910 : 91535 : i = gfc_get_sym_tree (name, NULL, &symtree, false);
3911 : : else
3912 : 3872406 : i = gfc_get_ha_sym_tree (name, &symtree);
3913 : 3963941 : if (i)
3914 : : return MATCH_ERROR;
3915 : : }
3916 : :
3917 : :
3918 : 3963941 : sym = symtree->n.sym;
3919 : 3963941 : e = NULL;
3920 : 3963941 : where = gfc_current_locus;
3921 : :
3922 : 3963941 : replace_hidden_procptr_result (&sym, &symtree);
3923 : :
3924 : : /* If this is an implicit do loop index and implicitly typed,
3925 : : it should not be host associated. */
3926 : 3963941 : m = check_for_implicit_index (&symtree, &sym);
3927 : 3963941 : if (m != MATCH_YES)
3928 : : return m;
3929 : :
3930 : 3963941 : gfc_set_sym_referenced (sym);
3931 : 3963941 : sym->attr.implied_index = 0;
3932 : :
3933 : 3963941 : if (sym->attr.function && sym->result == sym)
3934 : : {
3935 : : /* See if this is a directly recursive function call. */
3936 : 692611 : gfc_gobble_whitespace ();
3937 : 692611 : if (sym->attr.recursive
3938 : 100 : && gfc_peek_ascii_char () == '('
3939 : 93 : && gfc_current_ns->proc_name == sym
3940 : 692618 : && !sym->attr.dimension)
3941 : : {
3942 : 4 : gfc_error ("%qs at %C is the name of a recursive function "
3943 : : "and so refers to the result variable. Use an "
3944 : : "explicit RESULT variable for direct recursion "
3945 : : "(12.5.2.1)", sym->name);
3946 : 4 : return MATCH_ERROR;
3947 : : }
3948 : :
3949 : 692607 : if (gfc_is_function_return_value (sym, gfc_current_ns))
3950 : 1693 : goto variable;
3951 : :
3952 : 690914 : if (sym->attr.entry
3953 : 187 : && (sym->ns == gfc_current_ns
3954 : 27 : || sym->ns == gfc_current_ns->parent))
3955 : : {
3956 : 180 : gfc_entry_list *el = NULL;
3957 : :
3958 : 180 : for (el = sym->ns->entries; el; el = el->next)
3959 : 180 : if (sym == el->sym)
3960 : 180 : goto variable;
3961 : : }
3962 : : }
3963 : :
3964 : 3962064 : if (gfc_matching_procptr_assignment)
3965 : : {
3966 : : /* It can be a procedure or a derived-type procedure or a not-yet-known
3967 : : type. */
3968 : 1323 : if (sym->attr.flavor != FL_UNKNOWN
3969 : 983 : && sym->attr.flavor != FL_PROCEDURE
3970 : : && sym->attr.flavor != FL_PARAMETER
3971 : : && sym->attr.flavor != FL_VARIABLE)
3972 : : {
3973 : 2 : gfc_error ("Symbol at %C is not appropriate for an expression");
3974 : 2 : return MATCH_ERROR;
3975 : : }
3976 : 1321 : goto procptr0;
3977 : : }
3978 : :
3979 : 3960741 : if (sym->attr.function || sym->attr.external || sym->attr.intrinsic)
3980 : 704851 : goto function0;
3981 : :
3982 : 3255890 : if (sym->attr.generic)
3983 : 67880 : goto generic_function;
3984 : :
3985 : 3188010 : switch (sym->attr.flavor)
3986 : : {
3987 : 1702080 : case FL_VARIABLE:
3988 : 1702080 : variable:
3989 : 1702080 : e = gfc_get_expr ();
3990 : :
3991 : 1702080 : e->expr_type = EXPR_VARIABLE;
3992 : 1702080 : e->symtree = symtree;
3993 : :
3994 : 1702080 : m = gfc_match_varspec (e, 0, false, true);
3995 : 1702080 : break;
3996 : :
3997 : 216578 : case FL_PARAMETER:
3998 : : /* A statement of the form "REAL, parameter :: a(0:10) = 1" will
3999 : : end up here. Unfortunately, sym->value->expr_type is set to
4000 : : EXPR_CONSTANT, and so the if () branch would be followed without
4001 : : the !sym->as check. */
4002 : 216578 : if (sym->value && sym->value->expr_type != EXPR_ARRAY && !sym->as)
4003 : 182058 : e = gfc_copy_expr (sym->value);
4004 : : else
4005 : : {
4006 : 34520 : e = gfc_get_expr ();
4007 : 34520 : e->expr_type = EXPR_VARIABLE;
4008 : : }
4009 : :
4010 : 216578 : e->symtree = symtree;
4011 : 216578 : m = gfc_match_varspec (e, 0, false, true);
4012 : :
4013 : 216578 : if (sym->ts.is_c_interop || sym->ts.is_iso_c)
4014 : : break;
4015 : :
4016 : : /* Variable array references to derived type parameters cause
4017 : : all sorts of headaches in simplification. Treating such
4018 : : expressions as variable works just fine for all array
4019 : : references. */
4020 : 168442 : if (sym->value && sym->ts.type == BT_DERIVED && e->ref)
4021 : : {
4022 : 2827 : for (ref = e->ref; ref; ref = ref->next)
4023 : 2641 : if (ref->type == REF_ARRAY)
4024 : : break;
4025 : :
4026 : 2596 : if (ref == NULL || ref->u.ar.type == AR_FULL)
4027 : : break;
4028 : :
4029 : 1001 : ref = e->ref;
4030 : 1001 : e->ref = NULL;
4031 : 1001 : gfc_free_expr (e);
4032 : 1001 : e = gfc_get_expr ();
4033 : 1001 : e->expr_type = EXPR_VARIABLE;
4034 : 1001 : e->symtree = symtree;
4035 : 1001 : e->ref = ref;
4036 : : }
4037 : :
4038 : : break;
4039 : :
4040 : 0 : case FL_STRUCT:
4041 : 0 : case FL_DERIVED:
4042 : 0 : sym = gfc_use_derived (sym);
4043 : 0 : if (sym == NULL)
4044 : : m = MATCH_ERROR;
4045 : : else
4046 : 0 : goto generic_function;
4047 : : break;
4048 : :
4049 : : /* If we're here, then the name is known to be the name of a
4050 : : procedure, yet it is not sure to be the name of a function. */
4051 : 989654 : case FL_PROCEDURE:
4052 : :
4053 : : /* Procedure Pointer Assignments. */
4054 : 989654 : procptr0:
4055 : 989654 : if (gfc_matching_procptr_assignment)
4056 : : {
4057 : 1321 : gfc_gobble_whitespace ();
4058 : 1321 : if (!sym->attr.dimension && gfc_peek_ascii_char () == '(')
4059 : : /* Parse functions returning a procptr. */
4060 : 209 : goto function0;
4061 : :
4062 : 1112 : e = gfc_get_expr ();
4063 : 1112 : e->expr_type = EXPR_VARIABLE;
4064 : 1112 : e->symtree = symtree;
4065 : 1112 : m = gfc_match_varspec (e, 0, false, true);
4066 : 1044 : if (!e->ref && sym->attr.flavor == FL_UNKNOWN
4067 : 196 : && sym->ts.type == BT_UNKNOWN
4068 : 1298 : && !gfc_add_flavor (&sym->attr, FL_PROCEDURE, sym->name, NULL))
4069 : : {
4070 : : m = MATCH_ERROR;
4071 : : break;
4072 : : }
4073 : : break;
4074 : : }
4075 : :
4076 : 988333 : if (sym->attr.subroutine)
4077 : : {
4078 : 57 : gfc_error ("Unexpected use of subroutine name %qs at %C",
4079 : : sym->name);
4080 : 57 : m = MATCH_ERROR;
4081 : 57 : break;
4082 : : }
4083 : :
4084 : : /* At this point, the name has to be a non-statement function.
4085 : : If the name is the same as the current function being
4086 : : compiled, then we have a variable reference (to the function
4087 : : result) if the name is non-recursive. */
4088 : :
4089 : 988276 : st = gfc_enclosing_unit (NULL);
4090 : :
4091 : 988276 : if (st != NULL
4092 : 944940 : && st->state == COMP_FUNCTION
4093 : 82111 : && st->sym == sym
4094 : 0 : && !sym->attr.recursive)
4095 : : {
4096 : 0 : e = gfc_get_expr ();
4097 : 0 : e->symtree = symtree;
4098 : 0 : e->expr_type = EXPR_VARIABLE;
4099 : :
4100 : 0 : m = gfc_match_varspec (e, 0, false, true);
4101 : 0 : break;
4102 : : }
4103 : :
4104 : : /* Match a function reference. */
4105 : 988276 : function0:
4106 : 1693336 : m = gfc_match_actual_arglist (0, &actual_arglist);
4107 : 1693336 : if (m == MATCH_NO)
4108 : : {
4109 : 583253 : if (sym->attr.proc == PROC_ST_FUNCTION)
4110 : 1 : gfc_error ("Statement function %qs requires argument list at %C",
4111 : : sym->name);
4112 : : else
4113 : 583252 : gfc_error ("Function %qs requires an argument list at %C",
4114 : : sym->name);
4115 : :
4116 : : m = MATCH_ERROR;
4117 : : break;
4118 : : }
4119 : :
4120 : 1110083 : if (m != MATCH_YES)
4121 : : {
4122 : : m = MATCH_ERROR;
4123 : : break;
4124 : : }
4125 : :
4126 : : /* Check to see if this is a PDT constructor. The format of these
4127 : : constructors is rather unusual:
4128 : : name [(type_params)](component_values)
4129 : : where, component_values excludes the type_params. With the present
4130 : : gfortran representation this is rather awkward because the two are not
4131 : : distinguished, other than by their attributes.
4132 : :
4133 : : Even if 'name' is that of a PDT template, priority has to be given to
4134 : : specific procedures, other than the constructor, in the generic
4135 : : interface. */
4136 : :
4137 : 1078246 : gfc_gobble_whitespace ();
4138 : 1078246 : gfc_find_sym_tree (gfc_dt_upper_string (name), NULL, 1, &pdt_st);
4139 : 10517 : if (sym->attr.generic && pdt_st != NULL
4140 : 1086807 : && !(sym->generic->next && gfc_peek_ascii_char() != '('))
4141 : : {
4142 : 8328 : gfc_symbol *pdt_sym;
4143 : 8328 : gfc_actual_arglist *ctr_arglist = NULL, *tmp;
4144 : 8328 : gfc_component *c;
4145 : :
4146 : : /* Use the template. */
4147 : 8328 : if (pdt_st->n.sym && pdt_st->n.sym->attr.pdt_template)
4148 : : {
4149 : 727 : bool type_spec_list = false;
4150 : 727 : pdt_sym = pdt_st->n.sym;
4151 : 727 : gfc_gobble_whitespace ();
4152 : : /* Look for a second actual arglist. If present, try the first
4153 : : for the type parameters. Otherwise, or if there is no match,
4154 : : depend on default values by setting the type parameters to
4155 : : NULL. */
4156 : 727 : if (gfc_peek_ascii_char() == '(')
4157 : 72 : type_spec_list = true;
4158 : 727 : if (!actual_arglist && !type_spec_list)
4159 : : {
4160 : 3 : gfc_error_now ("F2023 R755: The empty type specification at %C "
4161 : : "is not allowed");
4162 : 3 : m = MATCH_ERROR;
4163 : 3 : break;
4164 : : }
4165 : : /* Generate this instance using the type parameters from the
4166 : : first argument list and return the parameter list in
4167 : : ctr_arglist. */
4168 : 724 : m = gfc_get_pdt_instance (actual_arglist, &pdt_sym, &ctr_arglist);
4169 : 724 : if (m != MATCH_YES || !ctr_arglist)
4170 : : {
4171 : 23 : if (ctr_arglist)
4172 : 0 : gfc_free_actual_arglist (ctr_arglist);
4173 : : /* See if all the type parameters have default values. */
4174 : 23 : m = gfc_get_pdt_instance (NULL, &pdt_sym, &ctr_arglist);
4175 : 23 : if (m != MATCH_YES)
4176 : : {
4177 : : m = MATCH_NO;
4178 : : break;
4179 : : }
4180 : : }
4181 : :
4182 : : /* Now match the component_values if the type parameters were
4183 : : present. */
4184 : 712 : if (type_spec_list)
4185 : : {
4186 : 72 : m = gfc_match_actual_arglist (0, &actual_arglist);
4187 : 72 : if (m != MATCH_YES)
4188 : : {
4189 : : m = MATCH_ERROR;
4190 : : break;
4191 : : }
4192 : : }
4193 : :
4194 : : /* Make sure that the component names are in place so that this
4195 : : list can be safely appended to the type parameters. */
4196 : 712 : tmp = actual_arglist;
4197 : 2428 : for (c = pdt_sym->components; c && tmp; c = c->next)
4198 : : {
4199 : 1716 : if (c->attr.pdt_kind || c->attr.pdt_len)
4200 : 925 : continue;
4201 : 791 : tmp->name = c->name;
4202 : 791 : tmp = tmp->next;
4203 : : }
4204 : :
4205 : 712 : gfc_find_sym_tree (gfc_dt_lower_string (pdt_sym->name),
4206 : : NULL, 1, &symtree);
4207 : 712 : if (!symtree)
4208 : : {
4209 : 388 : gfc_get_ha_sym_tree (gfc_dt_lower_string (pdt_sym->name) ,
4210 : : &symtree);
4211 : 388 : symtree->n.sym = pdt_sym;
4212 : 388 : symtree->n.sym->ts.u.derived = pdt_sym;
4213 : 388 : symtree->n.sym->ts.type = BT_DERIVED;
4214 : : }
4215 : :
4216 : 712 : if (type_spec_list)
4217 : : {
4218 : : /* Append the type_params and the component_values. */
4219 : 84 : for (tmp = ctr_arglist; tmp && tmp->next;)
4220 : : tmp = tmp->next;
4221 : 72 : tmp->next = actual_arglist;
4222 : 72 : actual_arglist = ctr_arglist;
4223 : 72 : tmp = actual_arglist;
4224 : : /* Can now add all the component names. */
4225 : 246 : for (c = pdt_sym->components; c && tmp; c = c->next)
4226 : : {
4227 : 174 : tmp->name = c->name;
4228 : 174 : tmp = tmp->next;
4229 : : }
4230 : : }
4231 : : }
4232 : : }
4233 : :
4234 : 1078231 : gfc_get_ha_sym_tree (name, &symtree); /* Can't fail */
4235 : 1078231 : sym = symtree->n.sym;
4236 : :
4237 : 1078231 : replace_hidden_procptr_result (&sym, &symtree);
4238 : :
4239 : 1078231 : e = gfc_get_expr ();
4240 : 1078231 : e->symtree = symtree;
4241 : 1078231 : e->expr_type = EXPR_FUNCTION;
4242 : 1078231 : e->value.function.actual = actual_arglist;
4243 : 1078231 : e->where = gfc_current_locus;
4244 : :
4245 : 1078231 : if (sym->ts.type == BT_CLASS && sym->attr.class_ok
4246 : 206 : && CLASS_DATA (sym)->as)
4247 : : {
4248 : 91 : e->rank = CLASS_DATA (sym)->as->rank;
4249 : 91 : e->corank = CLASS_DATA (sym)->as->corank;
4250 : : }
4251 : 1078140 : else if (sym->as != NULL)
4252 : : {
4253 : 1139 : e->rank = sym->as->rank;
4254 : 1139 : e->corank = sym->as->corank;
4255 : : }
4256 : :
4257 : 1078231 : if (!sym->attr.function
4258 : 1078231 : && !gfc_add_function (&sym->attr, sym->name, NULL))
4259 : : {
4260 : : m = MATCH_ERROR;
4261 : : break;
4262 : : }
4263 : :
4264 : : /* Check here for the existence of at least one argument for the
4265 : : iso_c_binding functions C_LOC, C_FUNLOC, and C_ASSOCIATED. */
4266 : 1078231 : if (sym->attr.is_iso_c == 1
4267 : 2 : && (sym->from_intmod == INTMOD_ISO_C_BINDING
4268 : 2 : && (sym->intmod_sym_id == ISOCBINDING_LOC
4269 : 2 : || sym->intmod_sym_id == ISOCBINDING_F_C_STRING
4270 : 2 : || sym->intmod_sym_id == ISOCBINDING_FUNLOC
4271 : 2 : || sym->intmod_sym_id == ISOCBINDING_ASSOCIATED)))
4272 : : {
4273 : : /* make sure we were given a param */
4274 : 0 : if (actual_arglist == NULL)
4275 : : {
4276 : 0 : gfc_error ("Missing argument to %qs at %C", sym->name);
4277 : 0 : m = MATCH_ERROR;
4278 : 0 : break;
4279 : : }
4280 : : }
4281 : :
4282 : 1078231 : if (sym->result == NULL)
4283 : 380908 : sym->result = sym;
4284 : :
4285 : 1078231 : gfc_gobble_whitespace ();
4286 : : /* F08:C612. */
4287 : 1078231 : if (gfc_peek_ascii_char() == '%')
4288 : : {
4289 : 12 : gfc_error ("The leftmost part-ref in a data-ref cannot be a "
4290 : : "function reference at %C");
4291 : 12 : m = MATCH_ERROR;
4292 : 12 : break;
4293 : : }
4294 : :
4295 : : m = MATCH_YES;
4296 : : break;
4297 : :
4298 : 281396 : case FL_UNKNOWN:
4299 : :
4300 : : /* Special case for derived type variables that get their types
4301 : : via an IMPLICIT statement. This can't wait for the
4302 : : resolution phase. */
4303 : :
4304 : 281396 : old_loc = gfc_current_locus;
4305 : 281396 : if (gfc_match_member_sep (sym) == MATCH_YES
4306 : 9960 : && sym->ts.type == BT_UNKNOWN
4307 : 281401 : && gfc_get_default_type (sym->name, sym->ns)->type == BT_DERIVED)
4308 : 0 : gfc_set_default_type (sym, 0, sym->ns);
4309 : 281396 : gfc_current_locus = old_loc;
4310 : :
4311 : : /* If the symbol has a (co)dimension attribute, the expression is a
4312 : : variable. */
4313 : :
4314 : 281396 : if (sym->attr.dimension || sym->attr.codimension)
4315 : : {
4316 : 34952 : if (!gfc_add_flavor (&sym->attr, FL_VARIABLE, sym->name, NULL))
4317 : : {
4318 : : m = MATCH_ERROR;
4319 : : break;
4320 : : }
4321 : :
4322 : 34952 : e = gfc_get_expr ();
4323 : 34952 : e->symtree = symtree;
4324 : 34952 : e->expr_type = EXPR_VARIABLE;
4325 : 34952 : m = gfc_match_varspec (e, 0, false, true);
4326 : 34952 : break;
4327 : : }
4328 : :
4329 : 246444 : if (sym->ts.type == BT_CLASS && sym->attr.class_ok
4330 : 4640 : && (CLASS_DATA (sym)->attr.dimension
4331 : 3222 : || CLASS_DATA (sym)->attr.codimension))
4332 : : {
4333 : 1505 : if (!gfc_add_flavor (&sym->attr, FL_VARIABLE, sym->name, NULL))
4334 : : {
4335 : : m = MATCH_ERROR;
4336 : : break;
4337 : : }
4338 : :
4339 : 1505 : e = gfc_get_expr ();
4340 : 1505 : e->symtree = symtree;
4341 : 1505 : e->expr_type = EXPR_VARIABLE;
4342 : 1505 : m = gfc_match_varspec (e, 0, false, true);
4343 : 1505 : break;
4344 : : }
4345 : :
4346 : : /* Name is not an array, so we peek to see if a '(' implies a
4347 : : function call or a substring reference. Otherwise the
4348 : : variable is just a scalar. */
4349 : :
4350 : 244939 : gfc_gobble_whitespace ();
4351 : 244939 : if (gfc_peek_ascii_char () != '(')
4352 : : {
4353 : : /* Assume a scalar variable */
4354 : 74443 : e = gfc_get_expr ();
4355 : 74443 : e->symtree = symtree;
4356 : 74443 : e->expr_type = EXPR_VARIABLE;
4357 : :
4358 : 74443 : if (!gfc_add_flavor (&sym->attr, FL_VARIABLE, sym->name, NULL))
4359 : : {
4360 : : m = MATCH_ERROR;
4361 : : break;
4362 : : }
4363 : :
4364 : : /*FIXME:??? gfc_match_varspec does set this for us: */
4365 : 74443 : e->ts = sym->ts;
4366 : 74443 : m = gfc_match_varspec (e, 0, false, true);
4367 : 74443 : break;
4368 : : }
4369 : :
4370 : : /* See if this is a function reference with a keyword argument
4371 : : as first argument. We do this because otherwise a spurious
4372 : : symbol would end up in the symbol table. */
4373 : :
4374 : 170496 : old_loc = gfc_current_locus;
4375 : 170496 : m2 = gfc_match (" ( %n =", argname);
4376 : 170496 : gfc_current_locus = old_loc;
4377 : :
4378 : 170496 : e = gfc_get_expr ();
4379 : 170496 : e->symtree = symtree;
4380 : :
4381 : 170496 : if (m2 != MATCH_YES)
4382 : : {
4383 : : /* Try to figure out whether we're dealing with a character type.
4384 : : We're peeking ahead here, because we don't want to call
4385 : : match_substring if we're dealing with an implicitly typed
4386 : : non-character variable. */
4387 : 169422 : implicit_char = false;
4388 : 169422 : if (sym->ts.type == BT_UNKNOWN)
4389 : : {
4390 : 164723 : ts = gfc_get_default_type (sym->name, NULL);
4391 : 164723 : if (ts->type == BT_CHARACTER)
4392 : : implicit_char = true;
4393 : : }
4394 : :
4395 : : /* See if this could possibly be a substring reference of a name
4396 : : that we're not sure is a variable yet. */
4397 : :
4398 : 169405 : if ((implicit_char || sym->ts.type == BT_CHARACTER)
4399 : 1374 : && match_substring (sym->ts.u.cl, 0, &e->ref, false) == MATCH_YES)
4400 : : {
4401 : :
4402 : 910 : e->expr_type = EXPR_VARIABLE;
4403 : :
4404 : 910 : if (sym->attr.flavor != FL_VARIABLE
4405 : 910 : && !gfc_add_flavor (&sym->attr, FL_VARIABLE,
4406 : : sym->name, NULL))
4407 : : {
4408 : : m = MATCH_ERROR;
4409 : : break;
4410 : : }
4411 : :
4412 : 910 : if (sym->ts.type == BT_UNKNOWN
4413 : 910 : && !gfc_set_default_type (sym, 1, NULL))
4414 : : {
4415 : : m = MATCH_ERROR;
4416 : : break;
4417 : : }
4418 : :
4419 : 910 : e->ts = sym->ts;
4420 : 910 : if (e->ref)
4421 : 885 : e->ts.u.cl = NULL;
4422 : : m = MATCH_YES;
4423 : : break;
4424 : : }
4425 : : }
4426 : :
4427 : : /* Give up, assume we have a function. */
4428 : :
4429 : 169586 : gfc_get_sym_tree (name, NULL, &symtree, false); /* Can't fail */
4430 : 169586 : sym = symtree->n.sym;
4431 : 169586 : e->expr_type = EXPR_FUNCTION;
4432 : :
4433 : 169586 : if (!sym->attr.function
4434 : 169586 : && !gfc_add_function (&sym->attr, sym->name, NULL))
4435 : : {
4436 : : m = MATCH_ERROR;
4437 : : break;
4438 : : }
4439 : :
4440 : 169586 : sym->result = sym;
4441 : :
4442 : 169586 : m = gfc_match_actual_arglist (0, &e->value.function.actual);
4443 : 169586 : if (m == MATCH_NO)
4444 : 0 : gfc_error ("Missing argument list in function %qs at %C", sym->name);
4445 : :
4446 : 169586 : if (m != MATCH_YES)
4447 : : {
4448 : : m = MATCH_ERROR;
4449 : : break;
4450 : : }
4451 : :
4452 : : /* If our new function returns a character, array or structure
4453 : : type, it might have subsequent references. */
4454 : :
4455 : 169456 : m = gfc_match_varspec (e, 0, false, true);
4456 : 169456 : if (m == MATCH_NO)
4457 : : m = MATCH_YES;
4458 : :
4459 : : break;
4460 : :
4461 : 67880 : generic_function:
4462 : : /* Look for symbol first; if not found, look for STRUCTURE type symbol
4463 : : specially. Creates a generic symbol for derived types. */
4464 : 67880 : gfc_find_sym_tree (name, NULL, 1, &symtree);
4465 : 67880 : if (!symtree)
4466 : 0 : gfc_find_sym_tree (gfc_dt_upper_string (name), NULL, 1, &symtree);
4467 : 67880 : if (!symtree || symtree->n.sym->attr.flavor != FL_STRUCT)
4468 : 67880 : gfc_get_sym_tree (name, NULL, &symtree, false); /* Can't fail */
4469 : :
4470 : 67880 : e = gfc_get_expr ();
4471 : 67880 : e->symtree = symtree;
4472 : 67880 : e->expr_type = EXPR_FUNCTION;
4473 : :
4474 : 67880 : if (gfc_fl_struct (sym->attr.flavor))
4475 : : {
4476 : 0 : e->value.function.esym = sym;
4477 : 0 : e->symtree->n.sym->attr.generic = 1;
4478 : : }
4479 : :
4480 : 67880 : m = gfc_match_actual_arglist (0, &e->value.function.actual);
4481 : 67880 : break;
4482 : :
4483 : : case FL_NAMELIST:
4484 : : m = MATCH_ERROR;
4485 : : break;
4486 : :
4487 : 5 : default:
4488 : 5 : gfc_error ("Symbol at %C is not appropriate for an expression");
4489 : 5 : return MATCH_ERROR;
4490 : : }
4491 : :
4492 : : /* Scan for possible inquiry references. */
4493 : 84 : if (m == MATCH_YES
4494 : 3346964 : && e->expr_type == EXPR_VARIABLE
4495 : 4113903 : && gfc_peek_ascii_char () == '%')
4496 : : {
4497 : 14 : m = gfc_match_varspec (e, 0, false, false);
4498 : 14 : if (m == MATCH_NO)
4499 : : m = MATCH_YES;
4500 : : }
4501 : :
4502 : 3963930 : if (m == MATCH_YES)
4503 : : {
4504 : 3346964 : e->where = where;
4505 : 3346964 : *result = e;
4506 : : }
4507 : : else
4508 : 616966 : gfc_free_expr (e);
4509 : :
4510 : : return m;
4511 : : }
4512 : :
4513 : :
4514 : : /* Match a variable, i.e. something that can be assigned to. This
4515 : : starts as a symbol, can be a structure component or an array
4516 : : reference. It can be a function if the function doesn't have a
4517 : : separate RESULT variable. If the symbol has not been previously
4518 : : seen, we assume it is a variable.
4519 : :
4520 : : This function is called by two interface functions:
4521 : : gfc_match_variable, which has host_flag = 1, and
4522 : : gfc_match_equiv_variable, with host_flag = 0, to restrict the
4523 : : match of the symbol to the local scope. */
4524 : :
4525 : : static match
4526 : 2785791 : match_variable (gfc_expr **result, int equiv_flag, int host_flag)
4527 : : {
4528 : 2785791 : gfc_symbol *sym, *dt_sym;
4529 : 2785791 : gfc_symtree *st;
4530 : 2785791 : gfc_expr *expr;
4531 : 2785791 : locus where, old_loc;
4532 : 2785791 : match m;
4533 : :
4534 : 2785791 : *result = NULL;
4535 : :
4536 : : /* Since nothing has any business being an lvalue in a module
4537 : : specification block, an interface block or a contains section,
4538 : : we force the changed_symbols mechanism to work by setting
4539 : : host_flag to 0. This prevents valid symbols that have the name
4540 : : of keywords, such as 'end', being turned into variables by
4541 : : failed matching to assignments for, e.g., END INTERFACE. */
4542 : 2785791 : if (gfc_current_state () == COMP_MODULE
4543 : 2785791 : || gfc_current_state () == COMP_SUBMODULE
4544 : : || gfc_current_state () == COMP_INTERFACE
4545 : : || gfc_current_state () == COMP_CONTAINS)
4546 : 189915 : host_flag = 0;
4547 : :
4548 : 2785791 : where = gfc_current_locus;
4549 : 2785791 : m = gfc_match_sym_tree (&st, host_flag);
4550 : 2785790 : if (m != MATCH_YES)
4551 : : return m;
4552 : :
4553 : 2785765 : sym = st->n.sym;
4554 : :
4555 : : /* If this is an implicit do loop index and implicitly typed,
4556 : : it should not be host associated. */
4557 : 2785765 : m = check_for_implicit_index (&st, &sym);
4558 : 2785765 : if (m != MATCH_YES)
4559 : : return m;
4560 : :
4561 : 2785765 : sym->attr.implied_index = 0;
4562 : :
4563 : 2785765 : gfc_set_sym_referenced (sym);
4564 : :
4565 : : /* STRUCTUREs may share names with variables, but derived types may not. */
4566 : 14058 : if (sym->attr.flavor == FL_PROCEDURE && sym->generic
4567 : 2785831 : && (dt_sym = gfc_find_dt_in_generic (sym)))
4568 : : {
4569 : 5 : if (dt_sym->attr.flavor == FL_DERIVED)
4570 : 5 : gfc_error ("Derived type %qs cannot be used as a variable at %C",
4571 : : sym->name);
4572 : 5 : return MATCH_ERROR;
4573 : : }
4574 : :
4575 : 2785760 : switch (sym->attr.flavor)
4576 : : {
4577 : : case FL_VARIABLE:
4578 : : /* Everything is alright. */
4579 : : break;
4580 : :
4581 : 2508569 : case FL_UNKNOWN:
4582 : 2508569 : {
4583 : 2508569 : sym_flavor flavor = FL_UNKNOWN;
4584 : :
4585 : 2508569 : gfc_gobble_whitespace ();
4586 : :
4587 : 2508569 : if (sym->attr.external || sym->attr.procedure
4588 : 2508537 : || sym->attr.function || sym->attr.subroutine)
4589 : : flavor = FL_PROCEDURE;
4590 : :
4591 : : /* If it is not a procedure, is not typed and is host associated,
4592 : : we cannot give it a flavor yet. */
4593 : 2508537 : else if (sym->ns == gfc_current_ns->parent
4594 : 2700 : && sym->ts.type == BT_UNKNOWN)
4595 : : break;
4596 : :
4597 : : /* These are definitive indicators that this is a variable. */
4598 : 3341529 : else if (gfc_peek_ascii_char () != '(' || sym->ts.type != BT_UNKNOWN
4599 : 3323911 : || sym->attr.pointer || sym->as != NULL)
4600 : : flavor = FL_VARIABLE;
4601 : :
4602 : : if (flavor != FL_UNKNOWN
4603 : 1693799 : && !gfc_add_flavor (&sym->attr, flavor, sym->name, NULL))
4604 : : return MATCH_ERROR;
4605 : : }
4606 : : break;
4607 : :
4608 : 17 : case FL_PARAMETER:
4609 : 17 : if (equiv_flag)
4610 : : {
4611 : 0 : gfc_error ("Named constant at %C in an EQUIVALENCE");
4612 : 0 : return MATCH_ERROR;
4613 : : }
4614 : 17 : if (gfc_in_match_data())
4615 : : {
4616 : 4 : gfc_error ("PARAMETER %qs shall not appear in a DATA statement at %C",
4617 : : sym->name);
4618 : 4 : return MATCH_ERROR;
4619 : : }
4620 : : /* Otherwise this is checked for an error given in the
4621 : : variable definition context checks. */
4622 : : break;
4623 : :
4624 : 14053 : case FL_PROCEDURE:
4625 : : /* Check for a nonrecursive function result variable. */
4626 : 14053 : if (sym->attr.function
4627 : 12086 : && (!sym->attr.external || sym->abr_modproc_decl)
4628 : 11689 : && sym->result == sym
4629 : 25393 : && (gfc_is_function_return_value (sym, gfc_current_ns)
4630 : 2169 : || (sym->attr.entry
4631 : 467 : && sym->ns == gfc_current_ns)
4632 : 1709 : || (sym->attr.entry
4633 : 7 : && sym->ns == gfc_current_ns->parent)))
4634 : : {
4635 : : /* If a function result is a derived type, then the derived
4636 : : type may still have to be resolved. */
4637 : :
4638 : 9638 : if (sym->ts.type == BT_DERIVED
4639 : 9638 : && gfc_use_derived (sym->ts.u.derived) == NULL)
4640 : : return MATCH_ERROR;
4641 : : break;
4642 : : }
4643 : :
4644 : 4415 : if (sym->attr.proc_pointer
4645 : 4415 : || replace_hidden_procptr_result (&sym, &st))
4646 : : break;
4647 : :
4648 : : /* Fall through to error */
4649 : 2772 : gcc_fallthrough ();
4650 : :
4651 : 2772 : default:
4652 : 2772 : gfc_error ("%qs at %C is not a variable", sym->name);
4653 : 2772 : return MATCH_ERROR;
4654 : : }
4655 : :
4656 : : /* Special case for derived type variables that get their types
4657 : : via an IMPLICIT statement. This can't wait for the
4658 : : resolution phase. */
4659 : :
4660 : 2782980 : {
4661 : 2782980 : gfc_namespace * implicit_ns;
4662 : :
4663 : 2782980 : if (gfc_current_ns->proc_name == sym)
4664 : : implicit_ns = gfc_current_ns;
4665 : : else
4666 : 2774161 : implicit_ns = sym->ns;
4667 : :
4668 : 2782980 : old_loc = gfc_current_locus;
4669 : 2782980 : if (gfc_match_member_sep (sym) == MATCH_YES
4670 : 19762 : && sym->ts.type == BT_UNKNOWN
4671 : 2782992 : && gfc_get_default_type (sym->name, implicit_ns)->type == BT_DERIVED)
4672 : 3 : gfc_set_default_type (sym, 0, implicit_ns);
4673 : 2782980 : gfc_current_locus = old_loc;
4674 : : }
4675 : :
4676 : 2782980 : expr = gfc_get_expr ();
4677 : :
4678 : 2782980 : expr->expr_type = EXPR_VARIABLE;
4679 : 2782980 : expr->symtree = st;
4680 : 2782980 : expr->ts = sym->ts;
4681 : :
4682 : : /* Now see if we have to do more. */
4683 : 2782980 : m = gfc_match_varspec (expr, equiv_flag, false, false);
4684 : 2782980 : if (m != MATCH_YES)
4685 : : {
4686 : 79 : gfc_free_expr (expr);
4687 : 79 : return m;
4688 : : }
4689 : :
4690 : 2782901 : expr->where = gfc_get_location_range (NULL, 0, &where, 1, &gfc_current_locus);
4691 : 2782901 : *result = expr;
4692 : 2782901 : return MATCH_YES;
4693 : : }
4694 : :
4695 : :
4696 : : match
4697 : 2782844 : gfc_match_variable (gfc_expr **result, int equiv_flag)
4698 : : {
4699 : 2782844 : return match_variable (result, equiv_flag, 1);
4700 : : }
4701 : :
4702 : :
4703 : : match
4704 : 2947 : gfc_match_equiv_variable (gfc_expr **result)
4705 : : {
4706 : 2947 : return match_variable (result, 1, 0);
4707 : : }
|