]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | /* Declaration statement matcher |
5624e564 | 2 | Copyright (C) 2002-2015 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | Contributed by Andy Vaught |
4 | ||
9fc4d79b | 5 | This file is part of GCC. |
6de9cd9a | 6 | |
9fc4d79b TS |
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 | |
d234d788 | 9 | Software Foundation; either version 3, or (at your option) any later |
9fc4d79b | 10 | version. |
6de9cd9a | 11 | |
9fc4d79b TS |
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. | |
6de9cd9a DN |
16 | |
17 | You should have received a copy of the GNU General Public License | |
d234d788 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a | 20 | |
6de9cd9a | 21 | #include "config.h" |
d22e4895 | 22 | #include "system.h" |
953bee7c | 23 | #include "coretypes.h" |
6de9cd9a DN |
24 | #include "gfortran.h" |
25 | #include "match.h" | |
26 | #include "parse.h" | |
cab129d1 | 27 | #include "flags.h" |
b7e75771 | 28 | #include "constructor.h" |
40e23961 MC |
29 | #include "hash-set.h" |
30 | #include "machmode.h" | |
31 | #include "vec.h" | |
32 | #include "double-int.h" | |
33 | #include "input.h" | |
34 | #include "alias.h" | |
35 | #include "symtab.h" | |
36 | #include "wide-int.h" | |
37 | #include "inchash.h" | |
62603fae | 38 | #include "tree.h" |
d8a2d370 | 39 | #include "stringpool.h" |
ca39e6f2 FXC |
40 | |
41 | /* Macros to access allocate memory for gfc_data_variable, | |
42 | gfc_data_value and gfc_data. */ | |
ece3f663 KG |
43 | #define gfc_get_data_variable() XCNEW (gfc_data_variable) |
44 | #define gfc_get_data_value() XCNEW (gfc_data_value) | |
45 | #define gfc_get_data() XCNEW (gfc_data) | |
ca39e6f2 FXC |
46 | |
47 | ||
524af0d6 | 48 | static bool set_binding_label (const char **, const char *, int); |
62603fae JB |
49 | |
50 | ||
2054fc29 | 51 | /* This flag is set if an old-style length selector is matched |
6de9cd9a DN |
52 | during a type-declaration statement. */ |
53 | ||
54 | static int old_char_selector; | |
55 | ||
46fa431d | 56 | /* When variables acquire types and attributes from a declaration |
6de9cd9a DN |
57 | statement, they get them from the following static variables. The |
58 | first part of a declaration sets these variables and the second | |
59 | part copies these into symbol structures. */ | |
60 | ||
61 | static gfc_typespec current_ts; | |
62 | ||
63 | static symbol_attribute current_attr; | |
64 | static gfc_array_spec *current_as; | |
65 | static int colon_seen; | |
66 | ||
a8b3b0b6 | 67 | /* The current binding label (if any). */ |
9975a30b | 68 | static const char* curr_binding_label; |
a8b3b0b6 CR |
69 | /* Need to know how many identifiers are on the current data declaration |
70 | line in case we're given the BIND(C) attribute with a NAME= specifier. */ | |
71 | static int num_idents_on_line; | |
72 | /* Need to know if a NAME= specifier was found during gfc_match_bind_c so we | |
73 | can supply a name if the curr_binding_label is nil and NAME= was not. */ | |
74 | static int has_name_equals = 0; | |
75 | ||
25d8f0a2 TS |
76 | /* Initializer of the previous enumerator. */ |
77 | ||
78 | static gfc_expr *last_initializer; | |
79 | ||
80 | /* History of all the enumerators is maintained, so that | |
81 | kind values of all the enumerators could be updated depending | |
82 | upon the maximum initialized value. */ | |
83 | ||
84 | typedef struct enumerator_history | |
85 | { | |
86 | gfc_symbol *sym; | |
87 | gfc_expr *initializer; | |
88 | struct enumerator_history *next; | |
89 | } | |
90 | enumerator_history; | |
91 | ||
92 | /* Header of enum history chain. */ | |
93 | ||
94 | static enumerator_history *enum_history = NULL; | |
95 | ||
96 | /* Pointer of enum history node containing largest initializer. */ | |
97 | ||
98 | static enumerator_history *max_enum = NULL; | |
99 | ||
6de9cd9a DN |
100 | /* gfc_new_block points to the symbol of a newly matched block. */ |
101 | ||
102 | gfc_symbol *gfc_new_block; | |
103 | ||
1c8bcdf7 | 104 | bool gfc_matching_function; |
e2d29968 | 105 | |
6de9cd9a | 106 | |
294fbfc8 TS |
107 | /********************* DATA statement subroutines *********************/ |
108 | ||
2220652d PT |
109 | static bool in_match_data = false; |
110 | ||
111 | bool | |
112 | gfc_in_match_data (void) | |
113 | { | |
114 | return in_match_data; | |
115 | } | |
116 | ||
ca39e6f2 FXC |
117 | static void |
118 | set_in_match_data (bool set_value) | |
2220652d PT |
119 | { |
120 | in_match_data = set_value; | |
121 | } | |
122 | ||
294fbfc8 TS |
123 | /* Free a gfc_data_variable structure and everything beneath it. */ |
124 | ||
125 | static void | |
636dff67 | 126 | free_variable (gfc_data_variable *p) |
294fbfc8 TS |
127 | { |
128 | gfc_data_variable *q; | |
129 | ||
130 | for (; p; p = q) | |
131 | { | |
132 | q = p->next; | |
133 | gfc_free_expr (p->expr); | |
134 | gfc_free_iterator (&p->iter, 0); | |
135 | free_variable (p->list); | |
cede9502 | 136 | free (p); |
294fbfc8 TS |
137 | } |
138 | } | |
139 | ||
140 | ||
141 | /* Free a gfc_data_value structure and everything beneath it. */ | |
142 | ||
143 | static void | |
636dff67 | 144 | free_value (gfc_data_value *p) |
294fbfc8 TS |
145 | { |
146 | gfc_data_value *q; | |
147 | ||
148 | for (; p; p = q) | |
149 | { | |
150 | q = p->next; | |
c9d75a48 | 151 | mpz_clear (p->repeat); |
294fbfc8 | 152 | gfc_free_expr (p->expr); |
cede9502 | 153 | free (p); |
294fbfc8 TS |
154 | } |
155 | } | |
156 | ||
157 | ||
158 | /* Free a list of gfc_data structures. */ | |
159 | ||
160 | void | |
636dff67 | 161 | gfc_free_data (gfc_data *p) |
294fbfc8 TS |
162 | { |
163 | gfc_data *q; | |
164 | ||
165 | for (; p; p = q) | |
166 | { | |
167 | q = p->next; | |
294fbfc8 TS |
168 | free_variable (p->var); |
169 | free_value (p->value); | |
cede9502 | 170 | free (p); |
294fbfc8 TS |
171 | } |
172 | } | |
173 | ||
174 | ||
a9f6f1f2 | 175 | /* Free all data in a namespace. */ |
636dff67 | 176 | |
a9f6f1f2 | 177 | static void |
66e4ab31 | 178 | gfc_free_data_all (gfc_namespace *ns) |
a9f6f1f2 JD |
179 | { |
180 | gfc_data *d; | |
181 | ||
182 | for (;ns->data;) | |
183 | { | |
184 | d = ns->data->next; | |
cede9502 | 185 | free (ns->data); |
a9f6f1f2 JD |
186 | ns->data = d; |
187 | } | |
188 | } | |
189 | ||
d5e2274d SB |
190 | /* Reject data parsed since the last restore point was marked. */ |
191 | ||
192 | void | |
193 | gfc_reject_data (gfc_namespace *ns) | |
194 | { | |
195 | gfc_data *d; | |
196 | ||
197 | while (ns->data && ns->data != ns->old_data) | |
198 | { | |
199 | d = ns->data->next; | |
200 | free (ns->data); | |
201 | ns->data = d; | |
202 | } | |
203 | } | |
a9f6f1f2 | 204 | |
294fbfc8 TS |
205 | static match var_element (gfc_data_variable *); |
206 | ||
207 | /* Match a list of variables terminated by an iterator and a right | |
208 | parenthesis. */ | |
209 | ||
210 | static match | |
636dff67 | 211 | var_list (gfc_data_variable *parent) |
294fbfc8 TS |
212 | { |
213 | gfc_data_variable *tail, var; | |
214 | match m; | |
215 | ||
216 | m = var_element (&var); | |
217 | if (m == MATCH_ERROR) | |
218 | return MATCH_ERROR; | |
219 | if (m == MATCH_NO) | |
220 | goto syntax; | |
221 | ||
222 | tail = gfc_get_data_variable (); | |
223 | *tail = var; | |
224 | ||
225 | parent->list = tail; | |
226 | ||
227 | for (;;) | |
228 | { | |
229 | if (gfc_match_char (',') != MATCH_YES) | |
230 | goto syntax; | |
231 | ||
232 | m = gfc_match_iterator (&parent->iter, 1); | |
233 | if (m == MATCH_YES) | |
234 | break; | |
235 | if (m == MATCH_ERROR) | |
236 | return MATCH_ERROR; | |
237 | ||
238 | m = var_element (&var); | |
239 | if (m == MATCH_ERROR) | |
240 | return MATCH_ERROR; | |
241 | if (m == MATCH_NO) | |
242 | goto syntax; | |
243 | ||
244 | tail->next = gfc_get_data_variable (); | |
245 | tail = tail->next; | |
246 | ||
247 | *tail = var; | |
248 | } | |
249 | ||
250 | if (gfc_match_char (')') != MATCH_YES) | |
251 | goto syntax; | |
252 | return MATCH_YES; | |
253 | ||
254 | syntax: | |
255 | gfc_syntax_error (ST_DATA); | |
256 | return MATCH_ERROR; | |
257 | } | |
258 | ||
259 | ||
260 | /* Match a single element in a data variable list, which can be a | |
261 | variable-iterator list. */ | |
262 | ||
263 | static match | |
7b901ac4 | 264 | var_element (gfc_data_variable *new_var) |
294fbfc8 TS |
265 | { |
266 | match m; | |
267 | gfc_symbol *sym; | |
268 | ||
7b901ac4 | 269 | memset (new_var, 0, sizeof (gfc_data_variable)); |
294fbfc8 TS |
270 | |
271 | if (gfc_match_char ('(') == MATCH_YES) | |
7b901ac4 | 272 | return var_list (new_var); |
294fbfc8 | 273 | |
7b901ac4 | 274 | m = gfc_match_variable (&new_var->expr, 0); |
294fbfc8 TS |
275 | if (m != MATCH_YES) |
276 | return m; | |
277 | ||
7b901ac4 | 278 | sym = new_var->expr->symtree->n.sym; |
294fbfc8 | 279 | |
f37e928c | 280 | /* Symbol should already have an associated type. */ |
524af0d6 | 281 | if (!gfc_check_symbol_typed (sym, gfc_current_ns, false, gfc_current_locus)) |
f37e928c DK |
282 | return MATCH_ERROR; |
283 | ||
636dff67 SK |
284 | if (!sym->attr.function && gfc_current_ns->parent |
285 | && gfc_current_ns->parent == sym->ns) | |
294fbfc8 | 286 | { |
c4100eae | 287 | gfc_error ("Host associated variable %qs may not be in the DATA " |
e25a0da3 | 288 | "statement at %C", sym->name); |
294fbfc8 TS |
289 | return MATCH_ERROR; |
290 | } | |
291 | ||
4075a94e | 292 | if (gfc_current_state () != COMP_BLOCK_DATA |
636dff67 | 293 | && sym->attr.in_common |
524af0d6 | 294 | && !gfc_notify_std (GFC_STD_GNU, "initialization of " |
a4d9b221 | 295 | "common block variable %qs in DATA statement at %C", |
524af0d6 | 296 | sym->name)) |
4075a94e | 297 | return MATCH_ERROR; |
294fbfc8 | 298 | |
524af0d6 | 299 | if (!gfc_add_data (&sym->attr, sym->name, &new_var->expr->where)) |
294fbfc8 TS |
300 | return MATCH_ERROR; |
301 | ||
302 | return MATCH_YES; | |
303 | } | |
304 | ||
305 | ||
306 | /* Match the top-level list of data variables. */ | |
307 | ||
308 | static match | |
636dff67 | 309 | top_var_list (gfc_data *d) |
294fbfc8 | 310 | { |
7b901ac4 | 311 | gfc_data_variable var, *tail, *new_var; |
294fbfc8 TS |
312 | match m; |
313 | ||
314 | tail = NULL; | |
315 | ||
316 | for (;;) | |
317 | { | |
318 | m = var_element (&var); | |
319 | if (m == MATCH_NO) | |
320 | goto syntax; | |
321 | if (m == MATCH_ERROR) | |
322 | return MATCH_ERROR; | |
323 | ||
7b901ac4 KG |
324 | new_var = gfc_get_data_variable (); |
325 | *new_var = var; | |
294fbfc8 TS |
326 | |
327 | if (tail == NULL) | |
7b901ac4 | 328 | d->var = new_var; |
294fbfc8 | 329 | else |
7b901ac4 | 330 | tail->next = new_var; |
294fbfc8 | 331 | |
7b901ac4 | 332 | tail = new_var; |
294fbfc8 TS |
333 | |
334 | if (gfc_match_char ('/') == MATCH_YES) | |
335 | break; | |
336 | if (gfc_match_char (',') != MATCH_YES) | |
337 | goto syntax; | |
338 | } | |
339 | ||
340 | return MATCH_YES; | |
341 | ||
342 | syntax: | |
343 | gfc_syntax_error (ST_DATA); | |
a9f6f1f2 | 344 | gfc_free_data_all (gfc_current_ns); |
294fbfc8 TS |
345 | return MATCH_ERROR; |
346 | } | |
347 | ||
348 | ||
349 | static match | |
636dff67 | 350 | match_data_constant (gfc_expr **result) |
294fbfc8 TS |
351 | { |
352 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
c3f34952 | 353 | gfc_symbol *sym, *dt_sym = NULL; |
294fbfc8 TS |
354 | gfc_expr *expr; |
355 | match m; | |
36d3fb4c | 356 | locus old_loc; |
294fbfc8 TS |
357 | |
358 | m = gfc_match_literal_constant (&expr, 1); | |
359 | if (m == MATCH_YES) | |
360 | { | |
361 | *result = expr; | |
362 | return MATCH_YES; | |
363 | } | |
364 | ||
365 | if (m == MATCH_ERROR) | |
366 | return MATCH_ERROR; | |
367 | ||
368 | m = gfc_match_null (result); | |
369 | if (m != MATCH_NO) | |
370 | return m; | |
371 | ||
36d3fb4c PT |
372 | old_loc = gfc_current_locus; |
373 | ||
374 | /* Should this be a structure component, try to match it | |
375 | before matching a name. */ | |
376 | m = gfc_match_rvalue (result); | |
377 | if (m == MATCH_ERROR) | |
378 | return m; | |
379 | ||
380 | if (m == MATCH_YES && (*result)->expr_type == EXPR_STRUCTURE) | |
381 | { | |
524af0d6 | 382 | if (!gfc_simplify_expr (*result, 0)) |
36d3fb4c PT |
383 | m = MATCH_ERROR; |
384 | return m; | |
385 | } | |
46f4f794 TB |
386 | else if (m == MATCH_YES) |
387 | gfc_free_expr (*result); | |
36d3fb4c PT |
388 | |
389 | gfc_current_locus = old_loc; | |
390 | ||
294fbfc8 TS |
391 | m = gfc_match_name (name); |
392 | if (m != MATCH_YES) | |
393 | return m; | |
394 | ||
395 | if (gfc_find_symbol (name, NULL, 1, &sym)) | |
396 | return MATCH_ERROR; | |
397 | ||
c3f34952 TB |
398 | if (sym && sym->attr.generic) |
399 | dt_sym = gfc_find_dt_in_generic (sym); | |
400 | ||
294fbfc8 | 401 | if (sym == NULL |
c3f34952 TB |
402 | || (sym->attr.flavor != FL_PARAMETER |
403 | && (!dt_sym || dt_sym->attr.flavor != FL_DERIVED))) | |
294fbfc8 | 404 | { |
c4100eae | 405 | gfc_error ("Symbol %qs must be a PARAMETER in DATA statement at %C", |
294fbfc8 TS |
406 | name); |
407 | return MATCH_ERROR; | |
408 | } | |
c3f34952 TB |
409 | else if (dt_sym && dt_sym->attr.flavor == FL_DERIVED) |
410 | return gfc_match_structure_constructor (dt_sym, result); | |
294fbfc8 | 411 | |
d46e0870 JD |
412 | /* Check to see if the value is an initialization array expression. */ |
413 | if (sym->value->expr_type == EXPR_ARRAY) | |
414 | { | |
415 | gfc_current_locus = old_loc; | |
416 | ||
417 | m = gfc_match_init_expr (result); | |
418 | if (m == MATCH_ERROR) | |
419 | return m; | |
420 | ||
421 | if (m == MATCH_YES) | |
422 | { | |
524af0d6 | 423 | if (!gfc_simplify_expr (*result, 0)) |
d46e0870 JD |
424 | m = MATCH_ERROR; |
425 | ||
426 | if ((*result)->expr_type == EXPR_CONSTANT) | |
427 | return m; | |
428 | else | |
429 | { | |
430 | gfc_error ("Invalid initializer %s in Data statement at %C", name); | |
431 | return MATCH_ERROR; | |
432 | } | |
433 | } | |
434 | } | |
435 | ||
294fbfc8 TS |
436 | *result = gfc_copy_expr (sym->value); |
437 | return MATCH_YES; | |
438 | } | |
439 | ||
440 | ||
441 | /* Match a list of values in a DATA statement. The leading '/' has | |
442 | already been seen at this point. */ | |
443 | ||
444 | static match | |
636dff67 | 445 | top_val_list (gfc_data *data) |
294fbfc8 | 446 | { |
7b901ac4 | 447 | gfc_data_value *new_val, *tail; |
294fbfc8 | 448 | gfc_expr *expr; |
294fbfc8 TS |
449 | match m; |
450 | ||
451 | tail = NULL; | |
452 | ||
453 | for (;;) | |
454 | { | |
455 | m = match_data_constant (&expr); | |
456 | if (m == MATCH_NO) | |
457 | goto syntax; | |
458 | if (m == MATCH_ERROR) | |
459 | return MATCH_ERROR; | |
460 | ||
7b901ac4 KG |
461 | new_val = gfc_get_data_value (); |
462 | mpz_init (new_val->repeat); | |
294fbfc8 TS |
463 | |
464 | if (tail == NULL) | |
7b901ac4 | 465 | data->value = new_val; |
294fbfc8 | 466 | else |
7b901ac4 | 467 | tail->next = new_val; |
294fbfc8 | 468 | |
7b901ac4 | 469 | tail = new_val; |
294fbfc8 TS |
470 | |
471 | if (expr->ts.type != BT_INTEGER || gfc_match_char ('*') != MATCH_YES) | |
472 | { | |
473 | tail->expr = expr; | |
f2112868 | 474 | mpz_set_ui (tail->repeat, 1); |
294fbfc8 TS |
475 | } |
476 | else | |
477 | { | |
46f4f794 | 478 | mpz_set (tail->repeat, expr->value.integer); |
294fbfc8 | 479 | gfc_free_expr (expr); |
294fbfc8 TS |
480 | |
481 | m = match_data_constant (&tail->expr); | |
482 | if (m == MATCH_NO) | |
483 | goto syntax; | |
484 | if (m == MATCH_ERROR) | |
485 | return MATCH_ERROR; | |
486 | } | |
487 | ||
488 | if (gfc_match_char ('/') == MATCH_YES) | |
489 | break; | |
490 | if (gfc_match_char (',') == MATCH_NO) | |
491 | goto syntax; | |
492 | } | |
493 | ||
494 | return MATCH_YES; | |
495 | ||
496 | syntax: | |
497 | gfc_syntax_error (ST_DATA); | |
a9f6f1f2 | 498 | gfc_free_data_all (gfc_current_ns); |
294fbfc8 TS |
499 | return MATCH_ERROR; |
500 | } | |
501 | ||
502 | ||
503 | /* Matches an old style initialization. */ | |
504 | ||
505 | static match | |
506 | match_old_style_init (const char *name) | |
507 | { | |
508 | match m; | |
509 | gfc_symtree *st; | |
ed0e3607 | 510 | gfc_symbol *sym; |
294fbfc8 TS |
511 | gfc_data *newdata; |
512 | ||
513 | /* Set up data structure to hold initializers. */ | |
514 | gfc_find_sym_tree (name, NULL, 0, &st); | |
ed0e3607 AL |
515 | sym = st->n.sym; |
516 | ||
294fbfc8 TS |
517 | newdata = gfc_get_data (); |
518 | newdata->var = gfc_get_data_variable (); | |
519 | newdata->var->expr = gfc_get_variable_expr (st); | |
8c5c0b80 | 520 | newdata->where = gfc_current_locus; |
294fbfc8 | 521 | |
66e4ab31 | 522 | /* Match initial value list. This also eats the terminal '/'. */ |
294fbfc8 TS |
523 | m = top_val_list (newdata); |
524 | if (m != MATCH_YES) | |
525 | { | |
cede9502 | 526 | free (newdata); |
294fbfc8 TS |
527 | return m; |
528 | } | |
529 | ||
530 | if (gfc_pure (NULL)) | |
531 | { | |
532 | gfc_error ("Initialization at %C is not allowed in a PURE procedure"); | |
cede9502 | 533 | free (newdata); |
294fbfc8 TS |
534 | return MATCH_ERROR; |
535 | } | |
ccd7751b | 536 | gfc_unset_implicit_pure (gfc_current_ns->proc_name); |
f1f39033 | 537 | |
ed0e3607 | 538 | /* Mark the variable as having appeared in a data statement. */ |
524af0d6 | 539 | if (!gfc_add_data (&sym->attr, sym->name, &sym->declared_at)) |
ed0e3607 | 540 | { |
cede9502 | 541 | free (newdata); |
ed0e3607 AL |
542 | return MATCH_ERROR; |
543 | } | |
544 | ||
294fbfc8 TS |
545 | /* Chain in namespace list of DATA initializers. */ |
546 | newdata->next = gfc_current_ns->data; | |
547 | gfc_current_ns->data = newdata; | |
548 | ||
549 | return m; | |
550 | } | |
551 | ||
636dff67 | 552 | |
294fbfc8 | 553 | /* Match the stuff following a DATA statement. If ERROR_FLAG is set, |
13795658 | 554 | we are matching a DATA statement and are therefore issuing an error |
d51347f9 | 555 | if we encounter something unexpected, if not, we're trying to match |
69de3b83 | 556 | an old-style initialization expression of the form INTEGER I /2/. */ |
294fbfc8 TS |
557 | |
558 | match | |
559 | gfc_match_data (void) | |
560 | { | |
7b901ac4 | 561 | gfc_data *new_data; |
294fbfc8 TS |
562 | match m; |
563 | ||
ca39e6f2 | 564 | set_in_match_data (true); |
2220652d | 565 | |
294fbfc8 TS |
566 | for (;;) |
567 | { | |
7b901ac4 KG |
568 | new_data = gfc_get_data (); |
569 | new_data->where = gfc_current_locus; | |
294fbfc8 | 570 | |
7b901ac4 | 571 | m = top_var_list (new_data); |
294fbfc8 TS |
572 | if (m != MATCH_YES) |
573 | goto cleanup; | |
574 | ||
7b901ac4 | 575 | m = top_val_list (new_data); |
294fbfc8 TS |
576 | if (m != MATCH_YES) |
577 | goto cleanup; | |
578 | ||
7b901ac4 KG |
579 | new_data->next = gfc_current_ns->data; |
580 | gfc_current_ns->data = new_data; | |
294fbfc8 TS |
581 | |
582 | if (gfc_match_eos () == MATCH_YES) | |
583 | break; | |
584 | ||
585 | gfc_match_char (','); /* Optional comma */ | |
586 | } | |
587 | ||
ca39e6f2 | 588 | set_in_match_data (false); |
2220652d | 589 | |
294fbfc8 TS |
590 | if (gfc_pure (NULL)) |
591 | { | |
592 | gfc_error ("DATA statement at %C is not allowed in a PURE procedure"); | |
593 | return MATCH_ERROR; | |
594 | } | |
ccd7751b | 595 | gfc_unset_implicit_pure (gfc_current_ns->proc_name); |
f1f39033 | 596 | |
294fbfc8 TS |
597 | return MATCH_YES; |
598 | ||
599 | cleanup: | |
ca39e6f2 | 600 | set_in_match_data (false); |
7b901ac4 | 601 | gfc_free_data (new_data); |
294fbfc8 TS |
602 | return MATCH_ERROR; |
603 | } | |
604 | ||
605 | ||
606 | /************************ Declaration statements *********************/ | |
607 | ||
d3a9eea2 | 608 | |
eea58adb | 609 | /* Auxiliary function to merge DIMENSION and CODIMENSION array specs. */ |
d3a9eea2 | 610 | |
524af0d6 | 611 | static bool |
d3a9eea2 TB |
612 | merge_array_spec (gfc_array_spec *from, gfc_array_spec *to, bool copy) |
613 | { | |
614 | int i; | |
615 | ||
63fbf586 TB |
616 | if ((from->type == AS_ASSUMED_RANK && to->corank) |
617 | || (to->type == AS_ASSUMED_RANK && from->corank)) | |
618 | { | |
619 | gfc_error ("The assumed-rank array at %C shall not have a codimension"); | |
524af0d6 | 620 | return false; |
63fbf586 | 621 | } |
c62c6622 | 622 | |
d3a9eea2 TB |
623 | if (to->rank == 0 && from->rank > 0) |
624 | { | |
625 | to->rank = from->rank; | |
626 | to->type = from->type; | |
627 | to->cray_pointee = from->cray_pointee; | |
628 | to->cp_was_assumed = from->cp_was_assumed; | |
629 | ||
630 | for (i = 0; i < to->corank; i++) | |
631 | { | |
632 | to->lower[from->rank + i] = to->lower[i]; | |
633 | to->upper[from->rank + i] = to->upper[i]; | |
634 | } | |
635 | for (i = 0; i < from->rank; i++) | |
636 | { | |
637 | if (copy) | |
638 | { | |
639 | to->lower[i] = gfc_copy_expr (from->lower[i]); | |
640 | to->upper[i] = gfc_copy_expr (from->upper[i]); | |
641 | } | |
642 | else | |
643 | { | |
644 | to->lower[i] = from->lower[i]; | |
645 | to->upper[i] = from->upper[i]; | |
646 | } | |
647 | } | |
648 | } | |
649 | else if (to->corank == 0 && from->corank > 0) | |
650 | { | |
651 | to->corank = from->corank; | |
652 | to->cotype = from->cotype; | |
653 | ||
654 | for (i = 0; i < from->corank; i++) | |
655 | { | |
656 | if (copy) | |
657 | { | |
658 | to->lower[to->rank + i] = gfc_copy_expr (from->lower[i]); | |
659 | to->upper[to->rank + i] = gfc_copy_expr (from->upper[i]); | |
660 | } | |
661 | else | |
662 | { | |
663 | to->lower[to->rank + i] = from->lower[i]; | |
664 | to->upper[to->rank + i] = from->upper[i]; | |
665 | } | |
666 | } | |
667 | } | |
63fbf586 | 668 | |
524af0d6 | 669 | return true; |
d3a9eea2 TB |
670 | } |
671 | ||
672 | ||
6de9cd9a DN |
673 | /* Match an intent specification. Since this can only happen after an |
674 | INTENT word, a legal intent-spec must follow. */ | |
675 | ||
676 | static sym_intent | |
677 | match_intent_spec (void) | |
678 | { | |
679 | ||
680 | if (gfc_match (" ( in out )") == MATCH_YES) | |
681 | return INTENT_INOUT; | |
682 | if (gfc_match (" ( in )") == MATCH_YES) | |
683 | return INTENT_IN; | |
684 | if (gfc_match (" ( out )") == MATCH_YES) | |
685 | return INTENT_OUT; | |
686 | ||
687 | gfc_error ("Bad INTENT specification at %C"); | |
688 | return INTENT_UNKNOWN; | |
689 | } | |
690 | ||
691 | ||
692 | /* Matches a character length specification, which is either a | |
e69afb29 | 693 | specification expression, '*', or ':'. */ |
6de9cd9a DN |
694 | |
695 | static match | |
e69afb29 | 696 | char_len_param_value (gfc_expr **expr, bool *deferred) |
6de9cd9a | 697 | { |
cba28dad JD |
698 | match m; |
699 | ||
e69afb29 SK |
700 | *expr = NULL; |
701 | *deferred = false; | |
702 | ||
6de9cd9a | 703 | if (gfc_match_char ('*') == MATCH_YES) |
e69afb29 SK |
704 | return MATCH_YES; |
705 | ||
706 | if (gfc_match_char (':') == MATCH_YES) | |
6de9cd9a | 707 | { |
524af0d6 JB |
708 | if (!gfc_notify_std (GFC_STD_F2003, "deferred type " |
709 | "parameter at %C")) | |
e69afb29 SK |
710 | return MATCH_ERROR; |
711 | ||
712 | *deferred = true; | |
713 | ||
6de9cd9a DN |
714 | return MATCH_YES; |
715 | } | |
716 | ||
cba28dad | 717 | m = gfc_match_expr (expr); |
f37e928c DK |
718 | |
719 | if (m == MATCH_YES | |
524af0d6 | 720 | && !gfc_expr_check_typed (*expr, gfc_current_ns, false)) |
f37e928c DK |
721 | return MATCH_ERROR; |
722 | ||
cba28dad JD |
723 | if (m == MATCH_YES && (*expr)->expr_type == EXPR_FUNCTION) |
724 | { | |
725 | if ((*expr)->value.function.actual | |
726 | && (*expr)->value.function.actual->expr->symtree) | |
727 | { | |
728 | gfc_expr *e; | |
729 | e = (*expr)->value.function.actual->expr; | |
730 | if (e->symtree->n.sym->attr.flavor == FL_PROCEDURE | |
731 | && e->expr_type == EXPR_VARIABLE) | |
732 | { | |
733 | if (e->symtree->n.sym->ts.type == BT_UNKNOWN) | |
734 | goto syntax; | |
735 | if (e->symtree->n.sym->ts.type == BT_CHARACTER | |
bc21d315 JW |
736 | && e->symtree->n.sym->ts.u.cl |
737 | && e->symtree->n.sym->ts.u.cl->length->ts.type == BT_UNKNOWN) | |
cba28dad JD |
738 | goto syntax; |
739 | } | |
740 | } | |
741 | } | |
742 | return m; | |
743 | ||
744 | syntax: | |
745 | gfc_error ("Conflict in attributes of function argument at %C"); | |
746 | return MATCH_ERROR; | |
6de9cd9a DN |
747 | } |
748 | ||
749 | ||
750 | /* A character length is a '*' followed by a literal integer or a | |
751 | char_len_param_value in parenthesis. */ | |
752 | ||
753 | static match | |
62732c30 | 754 | match_char_length (gfc_expr **expr, bool *deferred, bool obsolescent_check) |
6de9cd9a | 755 | { |
5cf54585 | 756 | int length; |
6de9cd9a DN |
757 | match m; |
758 | ||
f5acf0f2 | 759 | *deferred = false; |
6de9cd9a DN |
760 | m = gfc_match_char ('*'); |
761 | if (m != MATCH_YES) | |
762 | return m; | |
763 | ||
5cf54585 | 764 | m = gfc_match_small_literal_int (&length, NULL); |
6de9cd9a DN |
765 | if (m == MATCH_ERROR) |
766 | return m; | |
767 | ||
768 | if (m == MATCH_YES) | |
769 | { | |
62732c30 | 770 | if (obsolescent_check |
524af0d6 | 771 | && !gfc_notify_std (GFC_STD_F95_OBS, "Old-style character length at %C")) |
e2ab8b09 | 772 | return MATCH_ERROR; |
b7e75771 | 773 | *expr = gfc_get_int_expr (gfc_default_integer_kind, NULL, length); |
6de9cd9a DN |
774 | return m; |
775 | } | |
776 | ||
777 | if (gfc_match_char ('(') == MATCH_NO) | |
778 | goto syntax; | |
779 | ||
e69afb29 | 780 | m = char_len_param_value (expr, deferred); |
1c8bcdf7 PT |
781 | if (m != MATCH_YES && gfc_matching_function) |
782 | { | |
783 | gfc_undo_symbols (); | |
784 | m = MATCH_YES; | |
785 | } | |
786 | ||
6de9cd9a DN |
787 | if (m == MATCH_ERROR) |
788 | return m; | |
789 | if (m == MATCH_NO) | |
790 | goto syntax; | |
791 | ||
792 | if (gfc_match_char (')') == MATCH_NO) | |
793 | { | |
794 | gfc_free_expr (*expr); | |
795 | *expr = NULL; | |
796 | goto syntax; | |
797 | } | |
798 | ||
799 | return MATCH_YES; | |
800 | ||
801 | syntax: | |
802 | gfc_error ("Syntax error in character length specification at %C"); | |
803 | return MATCH_ERROR; | |
804 | } | |
805 | ||
806 | ||
9e35b386 EE |
807 | /* Special subroutine for finding a symbol. Check if the name is found |
808 | in the current name space. If not, and we're compiling a function or | |
809 | subroutine and the parent compilation unit is an interface, then check | |
810 | to see if the name we've been given is the name of the interface | |
811 | (located in another namespace). */ | |
6de9cd9a DN |
812 | |
813 | static int | |
08a6b8e0 | 814 | find_special (const char *name, gfc_symbol **result, bool allow_subroutine) |
6de9cd9a DN |
815 | { |
816 | gfc_state_data *s; | |
08a6b8e0 | 817 | gfc_symtree *st; |
9e35b386 | 818 | int i; |
6de9cd9a | 819 | |
08a6b8e0 | 820 | i = gfc_get_sym_tree (name, NULL, &st, allow_subroutine); |
d51347f9 | 821 | if (i == 0) |
08a6b8e0 TB |
822 | { |
823 | *result = st ? st->n.sym : NULL; | |
824 | goto end; | |
825 | } | |
d51347f9 | 826 | |
6de9cd9a DN |
827 | if (gfc_current_state () != COMP_SUBROUTINE |
828 | && gfc_current_state () != COMP_FUNCTION) | |
9e35b386 | 829 | goto end; |
6de9cd9a DN |
830 | |
831 | s = gfc_state_stack->previous; | |
832 | if (s == NULL) | |
9e35b386 | 833 | goto end; |
6de9cd9a DN |
834 | |
835 | if (s->state != COMP_INTERFACE) | |
9e35b386 | 836 | goto end; |
6de9cd9a | 837 | if (s->sym == NULL) |
66e4ab31 | 838 | goto end; /* Nameless interface. */ |
6de9cd9a DN |
839 | |
840 | if (strcmp (name, s->sym->name) == 0) | |
841 | { | |
842 | *result = s->sym; | |
843 | return 0; | |
844 | } | |
845 | ||
9e35b386 EE |
846 | end: |
847 | return i; | |
6de9cd9a DN |
848 | } |
849 | ||
850 | ||
851 | /* Special subroutine for getting a symbol node associated with a | |
852 | procedure name, used in SUBROUTINE and FUNCTION statements. The | |
853 | symbol is created in the parent using with symtree node in the | |
854 | child unit pointing to the symbol. If the current namespace has no | |
855 | parent, then the symbol is just created in the current unit. */ | |
856 | ||
857 | static int | |
636dff67 | 858 | get_proc_name (const char *name, gfc_symbol **result, bool module_fcn_entry) |
6de9cd9a DN |
859 | { |
860 | gfc_symtree *st; | |
861 | gfc_symbol *sym; | |
a7ca4d8d | 862 | int rc = 0; |
6de9cd9a | 863 | |
1a492601 PT |
864 | /* Module functions have to be left in their own namespace because |
865 | they have potentially (almost certainly!) already been referenced. | |
866 | In this sense, they are rather like external functions. This is | |
867 | fixed up in resolve.c(resolve_entries), where the symbol name- | |
868 | space is set to point to the master function, so that the fake | |
869 | result mechanism can work. */ | |
870 | if (module_fcn_entry) | |
6c12686b PT |
871 | { |
872 | /* Present if entry is declared to be a module procedure. */ | |
873 | rc = gfc_find_symbol (name, gfc_current_ns->parent, 0, result); | |
aa84a9a5 | 874 | |
6c12686b PT |
875 | if (*result == NULL) |
876 | rc = gfc_get_symbol (name, NULL, result); | |
2e32a71e | 877 | else if (!gfc_get_symbol (name, NULL, &sym) && sym |
aa84a9a5 PT |
878 | && (*result)->ts.type == BT_UNKNOWN |
879 | && sym->attr.flavor == FL_UNKNOWN) | |
880 | /* Pick up the typespec for the entry, if declared in the function | |
881 | body. Note that this symbol is FL_UNKNOWN because it will | |
882 | only have appeared in a type declaration. The local symtree | |
883 | is set to point to the module symbol and a unique symtree | |
884 | to the local version. This latter ensures a correct clearing | |
885 | of the symbols. */ | |
2e32a71e PT |
886 | { |
887 | /* If the ENTRY proceeds its specification, we need to ensure | |
888 | that this does not raise a "has no IMPLICIT type" error. */ | |
889 | if (sym->ts.type == BT_UNKNOWN) | |
0e5a218b | 890 | sym->attr.untyped = 1; |
2e32a71e | 891 | |
0e5a218b | 892 | (*result)->ts = sym->ts; |
2e32a71e PT |
893 | |
894 | /* Put the symbol in the procedure namespace so that, should | |
df2fba9e | 895 | the ENTRY precede its specification, the specification |
2e32a71e PT |
896 | can be applied. */ |
897 | (*result)->ns = gfc_current_ns; | |
898 | ||
899 | gfc_find_sym_tree (name, gfc_current_ns, 0, &st); | |
900 | st->n.sym = *result; | |
901 | st = gfc_get_unique_symtree (gfc_current_ns); | |
902 | st->n.sym = sym; | |
903 | } | |
6c12686b | 904 | } |
68ea355b PT |
905 | else |
906 | rc = gfc_get_symbol (name, gfc_current_ns->parent, result); | |
6de9cd9a | 907 | |
a7ca4d8d PT |
908 | if (rc) |
909 | return rc; | |
910 | ||
68ea355b | 911 | sym = *result; |
6de9cd9a | 912 | |
7b901ac4 | 913 | if (sym && !sym->gfc_new && gfc_current_state () != COMP_INTERFACE) |
68ea355b | 914 | { |
cda7004b PT |
915 | /* Trap another encompassed procedure with the same name. All |
916 | these conditions are necessary to avoid picking up an entry | |
917 | whose name clashes with that of the encompassing procedure; | |
918 | this is handled using gsymbols to register unique,globally | |
919 | accessible names. */ | |
68ea355b | 920 | if (sym->attr.flavor != 0 |
636dff67 SK |
921 | && sym->attr.proc != 0 |
922 | && (sym->attr.subroutine || sym->attr.function) | |
923 | && sym->attr.if_source != IFSRC_UNKNOWN) | |
4daa149b TB |
924 | gfc_error_now_1 ("Procedure '%s' at %C is already defined at %L", |
925 | name, &sym->declared_at); | |
68ea355b | 926 | |
fd3e70af JD |
927 | /* Trap a procedure with a name the same as interface in the |
928 | encompassing scope. */ | |
929 | if (sym->attr.generic != 0 | |
2305fa31 JD |
930 | && (sym->attr.subroutine || sym->attr.function) |
931 | && !sym->attr.mod_proc) | |
4daa149b TB |
932 | gfc_error_now_1 ("Name '%s' at %C is already defined" |
933 | " as a generic interface at %L", | |
934 | name, &sym->declared_at); | |
fd3e70af | 935 | |
68ea355b PT |
936 | /* Trap declarations of attributes in encompassing scope. The |
937 | signature for this is that ts.kind is set. Legitimate | |
938 | references only set ts.type. */ | |
939 | if (sym->ts.kind != 0 | |
636dff67 SK |
940 | && !sym->attr.implicit_type |
941 | && sym->attr.proc == 0 | |
942 | && gfc_current_ns->parent != NULL | |
943 | && sym->attr.access == 0 | |
944 | && !module_fcn_entry) | |
4daa149b TB |
945 | gfc_error_now_1 ("Procedure '%s' at %C has an explicit interface " |
946 | "and must not have attributes declared at %L", | |
947 | name, &sym->declared_at); | |
68ea355b PT |
948 | } |
949 | ||
950 | if (gfc_current_ns->parent == NULL || *result == NULL) | |
951 | return rc; | |
6de9cd9a | 952 | |
1a492601 PT |
953 | /* Module function entries will already have a symtree in |
954 | the current namespace but will need one at module level. */ | |
955 | if (module_fcn_entry) | |
6c12686b PT |
956 | { |
957 | /* Present if entry is declared to be a module procedure. */ | |
958 | rc = gfc_find_sym_tree (name, gfc_current_ns->parent, 0, &st); | |
959 | if (st == NULL) | |
960 | st = gfc_new_symtree (&gfc_current_ns->parent->sym_root, name); | |
961 | } | |
1a492601 PT |
962 | else |
963 | st = gfc_new_symtree (&gfc_current_ns->sym_root, name); | |
6de9cd9a | 964 | |
6de9cd9a DN |
965 | st->n.sym = sym; |
966 | sym->refs++; | |
967 | ||
66e4ab31 | 968 | /* See if the procedure should be a module procedure. */ |
6de9cd9a | 969 | |
1a492601 | 970 | if (((sym->ns->proc_name != NULL |
6c12686b PT |
971 | && sym->ns->proc_name->attr.flavor == FL_MODULE |
972 | && sym->attr.proc != PROC_MODULE) | |
973 | || (module_fcn_entry && sym->attr.proc != PROC_MODULE)) | |
524af0d6 | 974 | && !gfc_add_procedure (&sym->attr, PROC_MODULE, sym->name, NULL)) |
6de9cd9a DN |
975 | rc = 2; |
976 | ||
977 | return rc; | |
978 | } | |
979 | ||
980 | ||
a8b3b0b6 CR |
981 | /* Verify that the given symbol representing a parameter is C |
982 | interoperable, by checking to see if it was marked as such after | |
983 | its declaration. If the given symbol is not interoperable, a | |
984 | warning is reported, thus removing the need to return the status to | |
985 | the calling function. The standard does not require the user use | |
986 | one of the iso_c_binding named constants to declare an | |
987 | interoperable parameter, but we can't be sure if the param is C | |
988 | interop or not if the user doesn't. For example, integer(4) may be | |
989 | legal Fortran, but doesn't have meaning in C. It may interop with | |
990 | a number of the C types, which causes a problem because the | |
991 | compiler can't know which one. This code is almost certainly not | |
992 | portable, and the user will get what they deserve if the C type | |
993 | across platforms isn't always interoperable with integer(4). If | |
994 | the user had used something like integer(c_int) or integer(c_long), | |
995 | the compiler could have automatically handled the varying sizes | |
996 | across platforms. */ | |
997 | ||
524af0d6 | 998 | bool |
00820a2a | 999 | gfc_verify_c_interop_param (gfc_symbol *sym) |
a8b3b0b6 CR |
1000 | { |
1001 | int is_c_interop = 0; | |
524af0d6 | 1002 | bool retval = true; |
a8b3b0b6 CR |
1003 | |
1004 | /* We check implicitly typed variables in symbol.c:gfc_set_default_type(). | |
1005 | Don't repeat the checks here. */ | |
1006 | if (sym->attr.implicit_type) | |
524af0d6 | 1007 | return true; |
f5acf0f2 | 1008 | |
a8b3b0b6 CR |
1009 | /* For subroutines or functions that are passed to a BIND(C) procedure, |
1010 | they're interoperable if they're BIND(C) and their params are all | |
1011 | interoperable. */ | |
1012 | if (sym->attr.flavor == FL_PROCEDURE) | |
1013 | { | |
1014 | if (sym->attr.is_bind_c == 0) | |
1015 | { | |
4daa149b TB |
1016 | gfc_error_now ("Procedure %qs at %L must have the BIND(C) " |
1017 | "attribute to be C interoperable", sym->name, | |
1018 | &(sym->declared_at)); | |
524af0d6 | 1019 | return false; |
a8b3b0b6 CR |
1020 | } |
1021 | else | |
1022 | { | |
1023 | if (sym->attr.is_c_interop == 1) | |
1024 | /* We've already checked this procedure; don't check it again. */ | |
524af0d6 | 1025 | return true; |
a8b3b0b6 CR |
1026 | else |
1027 | return verify_bind_c_sym (sym, &(sym->ts), sym->attr.in_common, | |
1028 | sym->common_block); | |
1029 | } | |
1030 | } | |
f5acf0f2 | 1031 | |
a8b3b0b6 CR |
1032 | /* See if we've stored a reference to a procedure that owns sym. */ |
1033 | if (sym->ns != NULL && sym->ns->proc_name != NULL) | |
1034 | { | |
1035 | if (sym->ns->proc_name->attr.is_bind_c == 1) | |
1036 | { | |
524af0d6 | 1037 | is_c_interop = (gfc_verify_c_interop(&(sym->ts)) ? 1 : 0); |
a8b3b0b6 CR |
1038 | |
1039 | if (is_c_interop != 1) | |
1040 | { | |
1041 | /* Make personalized messages to give better feedback. */ | |
1042 | if (sym->ts.type == BT_DERIVED) | |
c4100eae MLI |
1043 | gfc_error ("Variable %qs at %L is a dummy argument to the " |
1044 | "BIND(C) procedure %qs but is not C interoperable " | |
1045 | "because derived type %qs is not C interoperable", | |
a8b3b0b6 | 1046 | sym->name, &(sym->declared_at), |
f5acf0f2 | 1047 | sym->ns->proc_name->name, |
bc21d315 | 1048 | sym->ts.u.derived->name); |
00820a2a | 1049 | else if (sym->ts.type == BT_CLASS) |
c4100eae MLI |
1050 | gfc_error ("Variable %qs at %L is a dummy argument to the " |
1051 | "BIND(C) procedure %qs but is not C interoperable " | |
00820a2a JW |
1052 | "because it is polymorphic", |
1053 | sym->name, &(sym->declared_at), | |
1054 | sym->ns->proc_name->name); | |
4daa149b | 1055 | else if (warn_c_binding_type) |
48749dbc MLI |
1056 | gfc_warning (OPT_Wc_binding_type, |
1057 | "Variable %qs at %L is a dummy argument of the " | |
1058 | "BIND(C) procedure %qs but may not be C " | |
a8b3b0b6 CR |
1059 | "interoperable", |
1060 | sym->name, &(sym->declared_at), | |
1061 | sym->ns->proc_name->name); | |
1062 | } | |
aa5e22f0 CR |
1063 | |
1064 | /* Character strings are only C interoperable if they have a | |
1065 | length of 1. */ | |
1066 | if (sym->ts.type == BT_CHARACTER) | |
1067 | { | |
bc21d315 | 1068 | gfc_charlen *cl = sym->ts.u.cl; |
aa5e22f0 CR |
1069 | if (!cl || !cl->length || cl->length->expr_type != EXPR_CONSTANT |
1070 | || mpz_cmp_si (cl->length->value.integer, 1) != 0) | |
1071 | { | |
c4100eae | 1072 | gfc_error ("Character argument %qs at %L " |
aa5e22f0 | 1073 | "must be length 1 because " |
c4100eae | 1074 | "procedure %qs is BIND(C)", |
aa5e22f0 CR |
1075 | sym->name, &sym->declared_at, |
1076 | sym->ns->proc_name->name); | |
524af0d6 | 1077 | retval = false; |
aa5e22f0 CR |
1078 | } |
1079 | } | |
1080 | ||
a8b3b0b6 CR |
1081 | /* We have to make sure that any param to a bind(c) routine does |
1082 | not have the allocatable, pointer, or optional attributes, | |
1083 | according to J3/04-007, section 5.1. */ | |
60f6ca95 | 1084 | if (sym->attr.allocatable == 1 |
a4d9b221 TB |
1085 | && !gfc_notify_std (GFC_STD_F2008_TS, "Variable %qs at %L with " |
1086 | "ALLOCATABLE attribute in procedure %qs " | |
60f6ca95 TB |
1087 | "with BIND(C)", sym->name, |
1088 | &(sym->declared_at), | |
1089 | sym->ns->proc_name->name)) | |
1090 | retval = false; | |
1091 | ||
1092 | if (sym->attr.pointer == 1 | |
a4d9b221 TB |
1093 | && !gfc_notify_std (GFC_STD_F2008_TS, "Variable %qs at %L with " |
1094 | "POINTER attribute in procedure %qs " | |
60f6ca95 TB |
1095 | "with BIND(C)", sym->name, |
1096 | &(sym->declared_at), | |
1097 | sym->ns->proc_name->name)) | |
1098 | retval = false; | |
1099 | ||
1100 | if ((sym->attr.allocatable || sym->attr.pointer) && !sym->as) | |
a8b3b0b6 | 1101 | { |
c4100eae MLI |
1102 | gfc_error ("Scalar variable %qs at %L with POINTER or " |
1103 | "ALLOCATABLE in procedure %qs with BIND(C) is not yet" | |
60f6ca95 | 1104 | " supported", sym->name, &(sym->declared_at), |
a8b3b0b6 | 1105 | sym->ns->proc_name->name); |
524af0d6 | 1106 | retval = false; |
a8b3b0b6 CR |
1107 | } |
1108 | ||
2e8d9212 | 1109 | if (sym->attr.optional == 1 && sym->attr.value) |
a8b3b0b6 | 1110 | { |
c4100eae MLI |
1111 | gfc_error ("Variable %qs at %L cannot have both the OPTIONAL " |
1112 | "and the VALUE attribute because procedure %qs " | |
2e8d9212 | 1113 | "is BIND(C)", sym->name, &(sym->declared_at), |
a8b3b0b6 | 1114 | sym->ns->proc_name->name); |
524af0d6 | 1115 | retval = false; |
a8b3b0b6 | 1116 | } |
2e8d9212 | 1117 | else if (sym->attr.optional == 1 |
a4d9b221 | 1118 | && !gfc_notify_std (GFC_STD_F2008_TS, "Variable %qs " |
524af0d6 | 1119 | "at %L with OPTIONAL attribute in " |
a4d9b221 | 1120 | "procedure %qs which is BIND(C)", |
524af0d6 JB |
1121 | sym->name, &(sym->declared_at), |
1122 | sym->ns->proc_name->name)) | |
1123 | retval = false; | |
a8b3b0b6 CR |
1124 | |
1125 | /* Make sure that if it has the dimension attribute, that it is | |
95d47b8d TB |
1126 | either assumed size or explicit shape. Deferred shape is already |
1127 | covered by the pointer/allocatable attribute. */ | |
1128 | if (sym->as != NULL && sym->as->type == AS_ASSUMED_SHAPE | |
a4d9b221 | 1129 | && !gfc_notify_std_1 (GFC_STD_F2008_TS, "Assumed-shape array '%s' " |
524af0d6 JB |
1130 | "at %L as dummy argument to the BIND(C) " |
1131 | "procedure '%s' at %L", sym->name, | |
1132 | &(sym->declared_at), | |
1133 | sym->ns->proc_name->name, | |
1134 | &(sym->ns->proc_name->declared_at))) | |
1135 | retval = false; | |
a8b3b0b6 CR |
1136 | } |
1137 | } | |
1138 | ||
1139 | return retval; | |
1140 | } | |
1141 | ||
1142 | ||
cf2b3c22 | 1143 | |
a8b3b0b6 | 1144 | /* Function called by variable_decl() that adds a name to the symbol table. */ |
6de9cd9a | 1145 | |
524af0d6 | 1146 | static bool |
e69afb29 | 1147 | build_sym (const char *name, gfc_charlen *cl, bool cl_deferred, |
636dff67 | 1148 | gfc_array_spec **as, locus *var_locus) |
6de9cd9a DN |
1149 | { |
1150 | symbol_attribute attr; | |
1151 | gfc_symbol *sym; | |
1152 | ||
9e35b386 | 1153 | if (gfc_get_symbol (name, NULL, &sym)) |
524af0d6 | 1154 | return false; |
6de9cd9a | 1155 | |
66e4ab31 | 1156 | /* Start updating the symbol table. Add basic type attribute if present. */ |
6de9cd9a | 1157 | if (current_ts.type != BT_UNKNOWN |
636dff67 SK |
1158 | && (sym->attr.implicit_type == 0 |
1159 | || !gfc_compare_types (&sym->ts, ¤t_ts)) | |
524af0d6 JB |
1160 | && !gfc_add_type (sym, ¤t_ts, var_locus)) |
1161 | return false; | |
6de9cd9a DN |
1162 | |
1163 | if (sym->ts.type == BT_CHARACTER) | |
e69afb29 SK |
1164 | { |
1165 | sym->ts.u.cl = cl; | |
1166 | sym->ts.deferred = cl_deferred; | |
1167 | } | |
6de9cd9a DN |
1168 | |
1169 | /* Add dimension attribute if present. */ | |
524af0d6 JB |
1170 | if (!gfc_set_array_spec (sym, *as, var_locus)) |
1171 | return false; | |
6de9cd9a DN |
1172 | *as = NULL; |
1173 | ||
1174 | /* Add attribute to symbol. The copy is so that we can reset the | |
1175 | dimension attribute. */ | |
1176 | attr = current_attr; | |
1177 | attr.dimension = 0; | |
be59db2d | 1178 | attr.codimension = 0; |
6de9cd9a | 1179 | |
524af0d6 JB |
1180 | if (!gfc_copy_attr (&sym->attr, &attr, var_locus)) |
1181 | return false; | |
6de9cd9a | 1182 | |
a8b3b0b6 CR |
1183 | /* Finish any work that may need to be done for the binding label, |
1184 | if it's a bind(c). The bind(c) attr is found before the symbol | |
1185 | is made, and before the symbol name (for data decls), so the | |
1186 | current_ts is holding the binding label, or nothing if the | |
1187 | name= attr wasn't given. Therefore, test here if we're dealing | |
1188 | with a bind(c) and make sure the binding label is set correctly. */ | |
1189 | if (sym->attr.is_bind_c == 1) | |
1190 | { | |
62603fae | 1191 | if (!sym->binding_label) |
a8b3b0b6 | 1192 | { |
ad4a2f64 TB |
1193 | /* Set the binding label and verify that if a NAME= was specified |
1194 | then only one identifier was in the entity-decl-list. */ | |
524af0d6 JB |
1195 | if (!set_binding_label (&sym->binding_label, sym->name, |
1196 | num_idents_on_line)) | |
1197 | return false; | |
a8b3b0b6 CR |
1198 | } |
1199 | } | |
1200 | ||
1201 | /* See if we know we're in a common block, and if it's a bind(c) | |
1202 | common then we need to make sure we're an interoperable type. */ | |
1203 | if (sym->attr.in_common == 1) | |
1204 | { | |
1205 | /* Test the common block object. */ | |
1206 | if (sym->common_block != NULL && sym->common_block->is_bind_c == 1 | |
1207 | && sym->ts.is_c_interop != 1) | |
1208 | { | |
4daa149b | 1209 | gfc_error_now ("Variable %qs in common block %qs at %C " |
a8b3b0b6 | 1210 | "must be declared with a C interoperable " |
4daa149b | 1211 | "kind since common block %qs is BIND(C)", |
a8b3b0b6 CR |
1212 | sym->name, sym->common_block->name, |
1213 | sym->common_block->name); | |
1214 | gfc_clear_error (); | |
1215 | } | |
1216 | } | |
1217 | ||
9a3db5a3 PT |
1218 | sym->attr.implied_index = 0; |
1219 | ||
528622fd | 1220 | if (sym->ts.type == BT_CLASS) |
9b6da3c7 | 1221 | return gfc_build_class_symbol (&sym->ts, &sym->attr, &sym->as); |
cf2b3c22 | 1222 | |
524af0d6 | 1223 | return true; |
6de9cd9a DN |
1224 | } |
1225 | ||
636dff67 | 1226 | |
df7cc9b5 | 1227 | /* Set character constant to the given length. The constant will be padded or |
d2848082 DK |
1228 | truncated. If we're inside an array constructor without a typespec, we |
1229 | additionally check that all elements have the same length; check_len -1 | |
1230 | means no checking. */ | |
df7cc9b5 FW |
1231 | |
1232 | void | |
d2848082 | 1233 | gfc_set_constant_character_len (int len, gfc_expr *expr, int check_len) |
df7cc9b5 | 1234 | { |
00660189 | 1235 | gfc_char_t *s; |
df7cc9b5 FW |
1236 | int slen; |
1237 | ||
1238 | gcc_assert (expr->expr_type == EXPR_CONSTANT); | |
d393bbd7 | 1239 | gcc_assert (expr->ts.type == BT_CHARACTER); |
df7cc9b5 FW |
1240 | |
1241 | slen = expr->value.character.length; | |
1242 | if (len != slen) | |
1243 | { | |
00660189 FXC |
1244 | s = gfc_get_wide_string (len + 1); |
1245 | memcpy (s, expr->value.character.string, | |
1246 | MIN (len, slen) * sizeof (gfc_char_t)); | |
df7cc9b5 | 1247 | if (len > slen) |
00660189 | 1248 | gfc_wide_memset (&s[slen], ' ', len - slen); |
2220652d | 1249 | |
a96c39ea | 1250 | if (warn_character_truncation && slen > len) |
4daa149b TB |
1251 | gfc_warning_now (OPT_Wcharacter_truncation, |
1252 | "CHARACTER expression at %L is being truncated " | |
1253 | "(%d/%d)", &expr->where, slen, len); | |
2220652d PT |
1254 | |
1255 | /* Apply the standard by 'hand' otherwise it gets cleared for | |
1256 | initializers. */ | |
d2848082 DK |
1257 | if (check_len != -1 && slen != check_len |
1258 | && !(gfc_option.allow_std & GFC_STD_GNU)) | |
2220652d PT |
1259 | gfc_error_now ("The CHARACTER elements of the array constructor " |
1260 | "at %L must have the same length (%d/%d)", | |
d2848082 | 1261 | &expr->where, slen, check_len); |
2220652d | 1262 | |
150675a8 | 1263 | s[len] = '\0'; |
cede9502 | 1264 | free (expr->value.character.string); |
df7cc9b5 FW |
1265 | expr->value.character.string = s; |
1266 | expr->value.character.length = len; | |
1267 | } | |
1268 | } | |
6de9cd9a | 1269 | |
25d8f0a2 | 1270 | |
d51347f9 | 1271 | /* Function to create and update the enumerator history |
25d8f0a2 | 1272 | using the information passed as arguments. |
d51347f9 TB |
1273 | Pointer "max_enum" is also updated, to point to |
1274 | enum history node containing largest initializer. | |
25d8f0a2 TS |
1275 | |
1276 | SYM points to the symbol node of enumerator. | |
66e4ab31 | 1277 | INIT points to its enumerator value. */ |
25d8f0a2 | 1278 | |
d51347f9 | 1279 | static void |
636dff67 | 1280 | create_enum_history (gfc_symbol *sym, gfc_expr *init) |
25d8f0a2 TS |
1281 | { |
1282 | enumerator_history *new_enum_history; | |
1283 | gcc_assert (sym != NULL && init != NULL); | |
1284 | ||
ece3f663 | 1285 | new_enum_history = XCNEW (enumerator_history); |
25d8f0a2 TS |
1286 | |
1287 | new_enum_history->sym = sym; | |
1288 | new_enum_history->initializer = init; | |
1289 | new_enum_history->next = NULL; | |
1290 | ||
1291 | if (enum_history == NULL) | |
1292 | { | |
1293 | enum_history = new_enum_history; | |
1294 | max_enum = enum_history; | |
1295 | } | |
1296 | else | |
1297 | { | |
1298 | new_enum_history->next = enum_history; | |
1299 | enum_history = new_enum_history; | |
1300 | ||
d51347f9 | 1301 | if (mpz_cmp (max_enum->initializer->value.integer, |
25d8f0a2 | 1302 | new_enum_history->initializer->value.integer) < 0) |
636dff67 | 1303 | max_enum = new_enum_history; |
25d8f0a2 TS |
1304 | } |
1305 | } | |
1306 | ||
1307 | ||
d51347f9 | 1308 | /* Function to free enum kind history. */ |
25d8f0a2 | 1309 | |
d51347f9 | 1310 | void |
636dff67 | 1311 | gfc_free_enum_history (void) |
25d8f0a2 | 1312 | { |
d51347f9 TB |
1313 | enumerator_history *current = enum_history; |
1314 | enumerator_history *next; | |
25d8f0a2 TS |
1315 | |
1316 | while (current != NULL) | |
1317 | { | |
1318 | next = current->next; | |
cede9502 | 1319 | free (current); |
25d8f0a2 TS |
1320 | current = next; |
1321 | } | |
1322 | max_enum = NULL; | |
1323 | enum_history = NULL; | |
1324 | } | |
1325 | ||
1326 | ||
6de9cd9a DN |
1327 | /* Function called by variable_decl() that adds an initialization |
1328 | expression to a symbol. */ | |
1329 | ||
524af0d6 | 1330 | static bool |
66e4ab31 | 1331 | add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) |
6de9cd9a DN |
1332 | { |
1333 | symbol_attribute attr; | |
1334 | gfc_symbol *sym; | |
1335 | gfc_expr *init; | |
1336 | ||
1337 | init = *initp; | |
08a6b8e0 | 1338 | if (find_special (name, &sym, false)) |
524af0d6 | 1339 | return false; |
6de9cd9a DN |
1340 | |
1341 | attr = sym->attr; | |
1342 | ||
1343 | /* If this symbol is confirming an implicit parameter type, | |
1344 | then an initialization expression is not allowed. */ | |
1345 | if (attr.flavor == FL_PARAMETER | |
1346 | && sym->value != NULL | |
1347 | && *initp != NULL) | |
1348 | { | |
c4100eae | 1349 | gfc_error ("Initializer not allowed for PARAMETER %qs at %C", |
6de9cd9a | 1350 | sym->name); |
524af0d6 | 1351 | return false; |
6de9cd9a DN |
1352 | } |
1353 | ||
1354 | if (init == NULL) | |
1355 | { | |
1356 | /* An initializer is required for PARAMETER declarations. */ | |
1357 | if (attr.flavor == FL_PARAMETER) | |
1358 | { | |
1359 | gfc_error ("PARAMETER at %L is missing an initializer", var_locus); | |
524af0d6 | 1360 | return false; |
6de9cd9a DN |
1361 | } |
1362 | } | |
1363 | else | |
1364 | { | |
1365 | /* If a variable appears in a DATA block, it cannot have an | |
1de8a836 | 1366 | initializer. */ |
6de9cd9a DN |
1367 | if (sym->attr.data) |
1368 | { | |
c4100eae | 1369 | gfc_error ("Variable %qs at %C with an initializer already " |
636dff67 | 1370 | "appears in a DATA statement", sym->name); |
524af0d6 | 1371 | return false; |
6de9cd9a DN |
1372 | } |
1373 | ||
75d17889 | 1374 | /* Check if the assignment can happen. This has to be put off |
80f95228 | 1375 | until later for derived type variables and procedure pointers. */ |
6de9cd9a | 1376 | if (sym->ts.type != BT_DERIVED && init->ts.type != BT_DERIVED |
cf2b3c22 | 1377 | && sym->ts.type != BT_CLASS && init->ts.type != BT_CLASS |
f5acf0f2 | 1378 | && !sym->attr.proc_pointer |
524af0d6 JB |
1379 | && !gfc_check_assign_symbol (sym, NULL, init)) |
1380 | return false; | |
6de9cd9a | 1381 | |
bc21d315 | 1382 | if (sym->ts.type == BT_CHARACTER && sym->ts.u.cl |
51b128a0 | 1383 | && init->ts.type == BT_CHARACTER) |
df7cc9b5 FW |
1384 | { |
1385 | /* Update symbol character length according initializer. */ | |
524af0d6 JB |
1386 | if (!gfc_check_assign_symbol (sym, NULL, init)) |
1387 | return false; | |
51b128a0 | 1388 | |
bc21d315 | 1389 | if (sym->ts.u.cl->length == NULL) |
df7cc9b5 | 1390 | { |
a99288e5 | 1391 | int clen; |
66e4ab31 SK |
1392 | /* If there are multiple CHARACTER variables declared on the |
1393 | same line, we don't want them to share the same length. */ | |
b76e28c6 | 1394 | sym->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); |
96f4873b | 1395 | |
a99288e5 PT |
1396 | if (sym->attr.flavor == FL_PARAMETER) |
1397 | { | |
1398 | if (init->expr_type == EXPR_CONSTANT) | |
1399 | { | |
1400 | clen = init->value.character.length; | |
b7e75771 JD |
1401 | sym->ts.u.cl->length |
1402 | = gfc_get_int_expr (gfc_default_integer_kind, | |
1403 | NULL, clen); | |
a99288e5 PT |
1404 | } |
1405 | else if (init->expr_type == EXPR_ARRAY) | |
1406 | { | |
b7e75771 JD |
1407 | gfc_constructor *c; |
1408 | c = gfc_constructor_first (init->value.constructor); | |
1409 | clen = c->expr->value.character.length; | |
1410 | sym->ts.u.cl->length | |
1411 | = gfc_get_int_expr (gfc_default_integer_kind, | |
1412 | NULL, clen); | |
a99288e5 | 1413 | } |
bc21d315 JW |
1414 | else if (init->ts.u.cl && init->ts.u.cl->length) |
1415 | sym->ts.u.cl->length = | |
1416 | gfc_copy_expr (sym->value->ts.u.cl->length); | |
a99288e5 | 1417 | } |
df7cc9b5 FW |
1418 | } |
1419 | /* Update initializer character length according symbol. */ | |
bc21d315 | 1420 | else if (sym->ts.u.cl->length->expr_type == EXPR_CONSTANT) |
df7cc9b5 | 1421 | { |
bc21d315 | 1422 | int len = mpz_get_si (sym->ts.u.cl->length->value.integer); |
df7cc9b5 FW |
1423 | |
1424 | if (init->expr_type == EXPR_CONSTANT) | |
d2848082 | 1425 | gfc_set_constant_character_len (len, init, -1); |
df7cc9b5 FW |
1426 | else if (init->expr_type == EXPR_ARRAY) |
1427 | { | |
b7e75771 JD |
1428 | gfc_constructor *c; |
1429 | ||
dcdc7b6c PT |
1430 | /* Build a new charlen to prevent simplification from |
1431 | deleting the length before it is resolved. */ | |
b76e28c6 | 1432 | init->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); |
bc21d315 | 1433 | init->ts.u.cl->length = gfc_copy_expr (sym->ts.u.cl->length); |
dcdc7b6c | 1434 | |
b7e75771 JD |
1435 | for (c = gfc_constructor_first (init->value.constructor); |
1436 | c; c = gfc_constructor_next (c)) | |
1437 | gfc_set_constant_character_len (len, c->expr, -1); | |
df7cc9b5 FW |
1438 | } |
1439 | } | |
1440 | } | |
1441 | ||
f5ca06e6 DK |
1442 | /* If sym is implied-shape, set its upper bounds from init. */ |
1443 | if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension | |
1444 | && sym->as->type == AS_IMPLIED_SHAPE) | |
1445 | { | |
1446 | int dim; | |
1447 | ||
1448 | if (init->rank == 0) | |
1449 | { | |
1450 | gfc_error ("Can't initialize implied-shape array at %L" | |
1451 | " with scalar", &sym->declared_at); | |
524af0d6 | 1452 | return false; |
f5ca06e6 DK |
1453 | } |
1454 | gcc_assert (sym->as->rank == init->rank); | |
1455 | ||
1456 | /* Shape should be present, we get an initialization expression. */ | |
1457 | gcc_assert (init->shape); | |
1458 | ||
1459 | for (dim = 0; dim < sym->as->rank; ++dim) | |
1460 | { | |
1461 | int k; | |
1462 | gfc_expr* lower; | |
1463 | gfc_expr* e; | |
f5acf0f2 | 1464 | |
f5ca06e6 DK |
1465 | lower = sym->as->lower[dim]; |
1466 | if (lower->expr_type != EXPR_CONSTANT) | |
1467 | { | |
1468 | gfc_error ("Non-constant lower bound in implied-shape" | |
1469 | " declaration at %L", &lower->where); | |
524af0d6 | 1470 | return false; |
f5ca06e6 DK |
1471 | } |
1472 | ||
1473 | /* All dimensions must be without upper bound. */ | |
1474 | gcc_assert (!sym->as->upper[dim]); | |
1475 | ||
1476 | k = lower->ts.kind; | |
1477 | e = gfc_get_constant_expr (BT_INTEGER, k, &sym->declared_at); | |
1478 | mpz_add (e->value.integer, | |
1479 | lower->value.integer, init->shape[dim]); | |
1480 | mpz_sub_ui (e->value.integer, e->value.integer, 1); | |
1481 | sym->as->upper[dim] = e; | |
1482 | } | |
1483 | ||
1484 | sym->as->type = AS_EXPLICIT; | |
1485 | } | |
1486 | ||
a8b3b0b6 CR |
1487 | /* Need to check if the expression we initialized this |
1488 | to was one of the iso_c_binding named constants. If so, | |
1489 | and we're a parameter (constant), let it be iso_c. | |
1490 | For example: | |
1491 | integer(c_int), parameter :: my_int = c_int | |
1492 | integer(my_int) :: my_int_2 | |
1493 | If we mark my_int as iso_c (since we can see it's value | |
1494 | is equal to one of the named constants), then my_int_2 | |
1495 | will be considered C interoperable. */ | |
1496 | if (sym->ts.type != BT_CHARACTER && sym->ts.type != BT_DERIVED) | |
1497 | { | |
1498 | sym->ts.is_iso_c |= init->ts.is_iso_c; | |
1499 | sym->ts.is_c_interop |= init->ts.is_c_interop; | |
1500 | /* attr bits needed for module files. */ | |
1501 | sym->attr.is_iso_c |= init->ts.is_iso_c; | |
1502 | sym->attr.is_c_interop |= init->ts.is_c_interop; | |
1503 | if (init->ts.is_iso_c) | |
1504 | sym->ts.f90_type = init->ts.f90_type; | |
1505 | } | |
b7e75771 | 1506 | |
6de9cd9a DN |
1507 | /* Add initializer. Make sure we keep the ranks sane. */ |
1508 | if (sym->attr.dimension && init->rank == 0) | |
a9b43781 PT |
1509 | { |
1510 | mpz_t size; | |
1511 | gfc_expr *array; | |
a9b43781 PT |
1512 | int n; |
1513 | if (sym->attr.flavor == FL_PARAMETER | |
1514 | && init->expr_type == EXPR_CONSTANT | |
524af0d6 | 1515 | && spec_size (sym->as, &size) |
a9b43781 PT |
1516 | && mpz_cmp_si (size, 0) > 0) |
1517 | { | |
b7e75771 JD |
1518 | array = gfc_get_array_expr (init->ts.type, init->ts.kind, |
1519 | &init->where); | |
a9b43781 | 1520 | for (n = 0; n < (int)mpz_get_si (size); n++) |
b7e75771 JD |
1521 | gfc_constructor_append_expr (&array->value.constructor, |
1522 | n == 0 | |
1523 | ? init | |
1524 | : gfc_copy_expr (init), | |
1525 | &init->where); | |
f5acf0f2 | 1526 | |
a9b43781 PT |
1527 | array->shape = gfc_get_shape (sym->as->rank); |
1528 | for (n = 0; n < sym->as->rank; n++) | |
1529 | spec_dimen_size (sym->as, n, &array->shape[n]); | |
1530 | ||
1531 | init = array; | |
1532 | mpz_clear (size); | |
1533 | } | |
1534 | init->rank = sym->as->rank; | |
1535 | } | |
6de9cd9a DN |
1536 | |
1537 | sym->value = init; | |
ef7236d2 DF |
1538 | if (sym->attr.save == SAVE_NONE) |
1539 | sym->attr.save = SAVE_IMPLICIT; | |
6de9cd9a DN |
1540 | *initp = NULL; |
1541 | } | |
1542 | ||
524af0d6 | 1543 | return true; |
6de9cd9a DN |
1544 | } |
1545 | ||
1546 | ||
1547 | /* Function called by variable_decl() that adds a name to a structure | |
1548 | being built. */ | |
1549 | ||
524af0d6 | 1550 | static bool |
636dff67 SK |
1551 | build_struct (const char *name, gfc_charlen *cl, gfc_expr **init, |
1552 | gfc_array_spec **as) | |
6de9cd9a DN |
1553 | { |
1554 | gfc_component *c; | |
524af0d6 | 1555 | bool t = true; |
6de9cd9a | 1556 | |
619dd721 | 1557 | /* F03:C438/C439. If the current symbol is of the same derived type that we're |
6de9cd9a | 1558 | constructing, it must have the pointer attribute. */ |
619dd721 | 1559 | if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS) |
bc21d315 | 1560 | && current_ts.u.derived == gfc_current_block () |
6de9cd9a DN |
1561 | && current_attr.pointer == 0) |
1562 | { | |
1563 | gfc_error ("Component at %C must have the POINTER attribute"); | |
524af0d6 | 1564 | return false; |
6de9cd9a DN |
1565 | } |
1566 | ||
636dff67 | 1567 | if (gfc_current_block ()->attr.pointer && (*as)->rank != 0) |
6de9cd9a DN |
1568 | { |
1569 | if ((*as)->type != AS_DEFERRED && (*as)->type != AS_EXPLICIT) | |
1570 | { | |
1571 | gfc_error ("Array component of structure at %C must have explicit " | |
1572 | "or deferred shape"); | |
524af0d6 | 1573 | return false; |
6de9cd9a DN |
1574 | } |
1575 | } | |
1576 | ||
524af0d6 JB |
1577 | if (!gfc_add_component (gfc_current_block(), name, &c)) |
1578 | return false; | |
6de9cd9a DN |
1579 | |
1580 | c->ts = current_ts; | |
bc21d315 JW |
1581 | if (c->ts.type == BT_CHARACTER) |
1582 | c->ts.u.cl = cl; | |
d4b7d0f0 | 1583 | c->attr = current_attr; |
6de9cd9a DN |
1584 | |
1585 | c->initializer = *init; | |
1586 | *init = NULL; | |
1587 | ||
1588 | c->as = *as; | |
1589 | if (c->as != NULL) | |
be59db2d TB |
1590 | { |
1591 | if (c->as->corank) | |
1592 | c->attr.codimension = 1; | |
1593 | if (c->as->rank) | |
1594 | c->attr.dimension = 1; | |
1595 | } | |
6de9cd9a DN |
1596 | *as = NULL; |
1597 | ||
28d08315 PT |
1598 | /* Should this ever get more complicated, combine with similar section |
1599 | in add_init_expr_to_sym into a separate function. */ | |
f4347334 ZG |
1600 | if (c->ts.type == BT_CHARACTER && !c->attr.pointer && c->initializer |
1601 | && c->ts.u.cl | |
bc21d315 | 1602 | && c->ts.u.cl->length && c->ts.u.cl->length->expr_type == EXPR_CONSTANT) |
28d08315 | 1603 | { |
d2848082 DK |
1604 | int len; |
1605 | ||
bc21d315 JW |
1606 | gcc_assert (c->ts.u.cl && c->ts.u.cl->length); |
1607 | gcc_assert (c->ts.u.cl->length->expr_type == EXPR_CONSTANT); | |
1608 | gcc_assert (c->ts.u.cl->length->ts.type == BT_INTEGER); | |
d2848082 | 1609 | |
bc21d315 | 1610 | len = mpz_get_si (c->ts.u.cl->length->value.integer); |
28d08315 PT |
1611 | |
1612 | if (c->initializer->expr_type == EXPR_CONSTANT) | |
d2848082 | 1613 | gfc_set_constant_character_len (len, c->initializer, -1); |
bc21d315 JW |
1614 | else if (mpz_cmp (c->ts.u.cl->length->value.integer, |
1615 | c->initializer->ts.u.cl->length->value.integer)) | |
28d08315 | 1616 | { |
b7e75771 JD |
1617 | gfc_constructor *ctor; |
1618 | ctor = gfc_constructor_first (c->initializer->value.constructor); | |
d2848082 | 1619 | |
2f4d1994 | 1620 | if (ctor) |
d2848082 | 1621 | { |
2f4d1994 | 1622 | int first_len; |
b7e75771 JD |
1623 | bool has_ts = (c->initializer->ts.u.cl |
1624 | && c->initializer->ts.u.cl->length_from_typespec); | |
2f4d1994 ILT |
1625 | |
1626 | /* Remember the length of the first element for checking | |
1627 | that all elements *in the constructor* have the same | |
1628 | length. This need not be the length of the LHS! */ | |
1629 | gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT); | |
1630 | gcc_assert (ctor->expr->ts.type == BT_CHARACTER); | |
1631 | first_len = ctor->expr->value.character.length; | |
1632 | ||
b7e75771 JD |
1633 | for ( ; ctor; ctor = gfc_constructor_next (ctor)) |
1634 | if (ctor->expr->expr_type == EXPR_CONSTANT) | |
d2848082 | 1635 | { |
b7e75771 JD |
1636 | gfc_set_constant_character_len (len, ctor->expr, |
1637 | has_ts ? -1 : first_len); | |
1638 | ctor->expr->ts.u.cl->length = gfc_copy_expr (c->ts.u.cl->length); | |
d2848082 | 1639 | } |
d2848082 | 1640 | } |
28d08315 PT |
1641 | } |
1642 | } | |
1643 | ||
6de9cd9a | 1644 | /* Check array components. */ |
d4b7d0f0 | 1645 | if (!c->attr.dimension) |
2e23972e | 1646 | goto scalar; |
6de9cd9a | 1647 | |
d4b7d0f0 | 1648 | if (c->attr.pointer) |
6de9cd9a DN |
1649 | { |
1650 | if (c->as->type != AS_DEFERRED) | |
1651 | { | |
5046aff5 PT |
1652 | gfc_error ("Pointer array component of structure at %C must have a " |
1653 | "deferred shape"); | |
524af0d6 | 1654 | t = false; |
5046aff5 PT |
1655 | } |
1656 | } | |
d4b7d0f0 | 1657 | else if (c->attr.allocatable) |
5046aff5 PT |
1658 | { |
1659 | if (c->as->type != AS_DEFERRED) | |
1660 | { | |
1661 | gfc_error ("Allocatable component of structure at %C must have a " | |
1662 | "deferred shape"); | |
524af0d6 | 1663 | t = false; |
6de9cd9a DN |
1664 | } |
1665 | } | |
1666 | else | |
1667 | { | |
1668 | if (c->as->type != AS_EXPLICIT) | |
1669 | { | |
636dff67 SK |
1670 | gfc_error ("Array component of structure at %C must have an " |
1671 | "explicit shape"); | |
524af0d6 | 1672 | t = false; |
6de9cd9a DN |
1673 | } |
1674 | } | |
1675 | ||
2e23972e JW |
1676 | scalar: |
1677 | if (c->ts.type == BT_CLASS) | |
17643884 | 1678 | { |
9b6da3c7 | 1679 | bool t2 = gfc_build_class_symbol (&c->ts, &c->attr, &c->as); |
ea59b186 | 1680 | |
524af0d6 | 1681 | if (t) |
ea59b186 | 1682 | t = t2; |
17643884 JW |
1683 | } |
1684 | ||
2e23972e | 1685 | return t; |
6de9cd9a DN |
1686 | } |
1687 | ||
1688 | ||
1689 | /* Match a 'NULL()', and possibly take care of some side effects. */ | |
1690 | ||
1691 | match | |
636dff67 | 1692 | gfc_match_null (gfc_expr **result) |
6de9cd9a DN |
1693 | { |
1694 | gfc_symbol *sym; | |
576f6da6 | 1695 | match m, m2 = MATCH_NO; |
6de9cd9a | 1696 | |
576f6da6 TB |
1697 | if ((m = gfc_match (" null ( )")) == MATCH_ERROR) |
1698 | return MATCH_ERROR; | |
1699 | ||
1700 | if (m == MATCH_NO) | |
1701 | { | |
1702 | locus old_loc; | |
1703 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
1704 | ||
94241120 | 1705 | if ((m2 = gfc_match (" null (")) != MATCH_YES) |
576f6da6 TB |
1706 | return m2; |
1707 | ||
1708 | old_loc = gfc_current_locus; | |
1709 | if ((m2 = gfc_match (" %n ) ", name)) == MATCH_ERROR) | |
1710 | return MATCH_ERROR; | |
1711 | if (m2 != MATCH_YES | |
1712 | && ((m2 = gfc_match (" mold = %n )", name)) == MATCH_ERROR)) | |
1713 | return MATCH_ERROR; | |
1714 | if (m2 == MATCH_NO) | |
1715 | { | |
1716 | gfc_current_locus = old_loc; | |
1717 | return MATCH_NO; | |
1718 | } | |
1719 | } | |
6de9cd9a DN |
1720 | |
1721 | /* The NULL symbol now has to be/become an intrinsic function. */ | |
1722 | if (gfc_get_symbol ("null", NULL, &sym)) | |
1723 | { | |
1724 | gfc_error ("NULL() initialization at %C is ambiguous"); | |
1725 | return MATCH_ERROR; | |
1726 | } | |
1727 | ||
1728 | gfc_intrinsic_symbol (sym); | |
1729 | ||
1730 | if (sym->attr.proc != PROC_INTRINSIC | |
07416986 | 1731 | && !(sym->attr.use_assoc && sym->attr.intrinsic) |
524af0d6 JB |
1732 | && (!gfc_add_procedure(&sym->attr, PROC_INTRINSIC, sym->name, NULL) |
1733 | || !gfc_add_function (&sym->attr, sym->name, NULL))) | |
6de9cd9a DN |
1734 | return MATCH_ERROR; |
1735 | ||
b7e75771 | 1736 | *result = gfc_get_null_expr (&gfc_current_locus); |
6de9cd9a | 1737 | |
576f6da6 TB |
1738 | /* Invalid per F2008, C512. */ |
1739 | if (m2 == MATCH_YES) | |
1740 | { | |
1741 | gfc_error ("NULL() initialization at %C may not have MOLD"); | |
1742 | return MATCH_ERROR; | |
1743 | } | |
1744 | ||
6de9cd9a DN |
1745 | return MATCH_YES; |
1746 | } | |
1747 | ||
1748 | ||
80f95228 JW |
1749 | /* Match the initialization expr for a data pointer or procedure pointer. */ |
1750 | ||
1751 | static match | |
1752 | match_pointer_init (gfc_expr **init, int procptr) | |
1753 | { | |
1754 | match m; | |
1755 | ||
1756 | if (gfc_pure (NULL) && gfc_state_stack->state != COMP_DERIVED) | |
1757 | { | |
1758 | gfc_error ("Initialization of pointer at %C is not allowed in " | |
1759 | "a PURE procedure"); | |
1760 | return MATCH_ERROR; | |
1761 | } | |
ccd7751b | 1762 | gfc_unset_implicit_pure (gfc_current_ns->proc_name); |
80f95228 | 1763 | |
eea58adb | 1764 | /* Match NULL() initialization. */ |
80f95228 JW |
1765 | m = gfc_match_null (init); |
1766 | if (m != MATCH_NO) | |
1767 | return m; | |
1768 | ||
1769 | /* Match non-NULL initialization. */ | |
837c4b78 | 1770 | gfc_matching_ptr_assignment = !procptr; |
80f95228 JW |
1771 | gfc_matching_procptr_assignment = procptr; |
1772 | m = gfc_match_rvalue (init); | |
837c4b78 | 1773 | gfc_matching_ptr_assignment = 0; |
80f95228 JW |
1774 | gfc_matching_procptr_assignment = 0; |
1775 | if (m == MATCH_ERROR) | |
1776 | return MATCH_ERROR; | |
1777 | else if (m == MATCH_NO) | |
1778 | { | |
1779 | gfc_error ("Error in pointer initialization at %C"); | |
1780 | return MATCH_ERROR; | |
1781 | } | |
1782 | ||
dc9a54fa JW |
1783 | if (!procptr && !gfc_resolve_expr (*init)) |
1784 | return MATCH_ERROR; | |
f5acf0f2 | 1785 | |
524af0d6 JB |
1786 | if (!gfc_notify_std (GFC_STD_F2008, "non-NULL pointer " |
1787 | "initialization at %C")) | |
80f95228 JW |
1788 | return MATCH_ERROR; |
1789 | ||
1790 | return MATCH_YES; | |
1791 | } | |
1792 | ||
1793 | ||
524af0d6 | 1794 | static bool |
bb9de0c4 JW |
1795 | check_function_name (char *name) |
1796 | { | |
1797 | /* In functions that have a RESULT variable defined, the function name always | |
1798 | refers to function calls. Therefore, the name is not allowed to appear in | |
1799 | specification statements. When checking this, be careful about | |
1800 | 'hidden' procedure pointer results ('ppr@'). */ | |
1801 | ||
1802 | if (gfc_current_state () == COMP_FUNCTION) | |
1803 | { | |
1804 | gfc_symbol *block = gfc_current_block (); | |
1805 | if (block && block->result && block->result != block | |
1806 | && strcmp (block->result->name, "ppr@") != 0 | |
1807 | && strcmp (block->name, name) == 0) | |
1808 | { | |
c4100eae | 1809 | gfc_error ("Function name %qs not allowed at %C", name); |
524af0d6 | 1810 | return false; |
bb9de0c4 JW |
1811 | } |
1812 | } | |
1813 | ||
524af0d6 | 1814 | return true; |
bb9de0c4 JW |
1815 | } |
1816 | ||
1817 | ||
6de9cd9a DN |
1818 | /* Match a variable name with an optional initializer. When this |
1819 | subroutine is called, a variable is expected to be parsed next. | |
1820 | Depending on what is happening at the moment, updates either the | |
1821 | symbol table or the current interface. */ | |
1822 | ||
1823 | static match | |
949d5b72 | 1824 | variable_decl (int elem) |
6de9cd9a DN |
1825 | { |
1826 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
1827 | gfc_expr *initializer, *char_len; | |
1828 | gfc_array_spec *as; | |
83d890b9 | 1829 | gfc_array_spec *cp_as; /* Extra copy for Cray Pointees. */ |
6de9cd9a | 1830 | gfc_charlen *cl; |
e69afb29 | 1831 | bool cl_deferred; |
6de9cd9a DN |
1832 | locus var_locus; |
1833 | match m; | |
524af0d6 | 1834 | bool t; |
83d890b9 | 1835 | gfc_symbol *sym; |
6de9cd9a DN |
1836 | |
1837 | initializer = NULL; | |
1838 | as = NULL; | |
83d890b9 | 1839 | cp_as = NULL; |
6de9cd9a DN |
1840 | |
1841 | /* When we get here, we've just matched a list of attributes and | |
1842 | maybe a type and a double colon. The next thing we expect to see | |
1843 | is the name of the symbol. */ | |
1844 | m = gfc_match_name (name); | |
1845 | if (m != MATCH_YES) | |
1846 | goto cleanup; | |
1847 | ||
63645982 | 1848 | var_locus = gfc_current_locus; |
6de9cd9a DN |
1849 | |
1850 | /* Now we could see the optional array spec. or character length. */ | |
be59db2d | 1851 | m = gfc_match_array_spec (&as, true, true); |
11126dc0 | 1852 | if (m == MATCH_ERROR) |
6de9cd9a | 1853 | goto cleanup; |
25d8f0a2 | 1854 | |
6de9cd9a DN |
1855 | if (m == MATCH_NO) |
1856 | as = gfc_copy_array_spec (current_as); | |
63fbf586 | 1857 | else if (current_as |
524af0d6 | 1858 | && !merge_array_spec (current_as, as, true)) |
63fbf586 TB |
1859 | { |
1860 | m = MATCH_ERROR; | |
1861 | goto cleanup; | |
1862 | } | |
6de9cd9a | 1863 | |
c61819ff | 1864 | if (flag_cray_pointer) |
11126dc0 AL |
1865 | cp_as = gfc_copy_array_spec (as); |
1866 | ||
f5ca06e6 DK |
1867 | /* At this point, we know for sure if the symbol is PARAMETER and can thus |
1868 | determine (and check) whether it can be implied-shape. If it | |
1869 | was parsed as assumed-size, change it because PARAMETERs can not | |
1870 | be assumed-size. */ | |
1871 | if (as) | |
1872 | { | |
1873 | if (as->type == AS_IMPLIED_SHAPE && current_attr.flavor != FL_PARAMETER) | |
1874 | { | |
1875 | m = MATCH_ERROR; | |
c4100eae | 1876 | gfc_error ("Non-PARAMETER symbol %qs at %L can't be implied-shape", |
f5ca06e6 DK |
1877 | name, &var_locus); |
1878 | goto cleanup; | |
1879 | } | |
1880 | ||
1881 | if (as->type == AS_ASSUMED_SIZE && as->rank == 1 | |
1882 | && current_attr.flavor == FL_PARAMETER) | |
1883 | as->type = AS_IMPLIED_SHAPE; | |
1884 | ||
1885 | if (as->type == AS_IMPLIED_SHAPE | |
524af0d6 JB |
1886 | && !gfc_notify_std (GFC_STD_F2008, "Implied-shape array at %L", |
1887 | &var_locus)) | |
f5ca06e6 DK |
1888 | { |
1889 | m = MATCH_ERROR; | |
1890 | goto cleanup; | |
1891 | } | |
1892 | } | |
1893 | ||
6de9cd9a DN |
1894 | char_len = NULL; |
1895 | cl = NULL; | |
e69afb29 | 1896 | cl_deferred = false; |
6de9cd9a DN |
1897 | |
1898 | if (current_ts.type == BT_CHARACTER) | |
1899 | { | |
2767f2cc | 1900 | switch (match_char_length (&char_len, &cl_deferred, false)) |
6de9cd9a DN |
1901 | { |
1902 | case MATCH_YES: | |
b76e28c6 | 1903 | cl = gfc_new_charlen (gfc_current_ns, NULL); |
6de9cd9a DN |
1904 | |
1905 | cl->length = char_len; | |
1906 | break; | |
1907 | ||
949d5b72 | 1908 | /* Non-constant lengths need to be copied after the first |
9b21a380 | 1909 | element. Also copy assumed lengths. */ |
6de9cd9a | 1910 | case MATCH_NO: |
9b21a380 | 1911 | if (elem > 1 |
bc21d315 JW |
1912 | && (current_ts.u.cl->length == NULL |
1913 | || current_ts.u.cl->length->expr_type != EXPR_CONSTANT)) | |
949d5b72 | 1914 | { |
b76e28c6 | 1915 | cl = gfc_new_charlen (gfc_current_ns, NULL); |
bc21d315 | 1916 | cl->length = gfc_copy_expr (current_ts.u.cl->length); |
949d5b72 PT |
1917 | } |
1918 | else | |
bc21d315 | 1919 | cl = current_ts.u.cl; |
949d5b72 | 1920 | |
e69afb29 SK |
1921 | cl_deferred = current_ts.deferred; |
1922 | ||
6de9cd9a DN |
1923 | break; |
1924 | ||
1925 | case MATCH_ERROR: | |
1926 | goto cleanup; | |
1927 | } | |
1928 | } | |
1929 | ||
83d890b9 | 1930 | /* If this symbol has already shown up in a Cray Pointer declaration, |
88f7d6fb | 1931 | and this is not a component declaration, |
66e4ab31 | 1932 | then we want to set the type & bail out. */ |
c61819ff | 1933 | if (flag_cray_pointer && gfc_current_state () != COMP_DERIVED) |
83d890b9 AL |
1934 | { |
1935 | gfc_find_symbol (name, gfc_current_ns, 1, &sym); | |
1936 | if (sym != NULL && sym->attr.cray_pointee) | |
1937 | { | |
1938 | sym->ts.type = current_ts.type; | |
1939 | sym->ts.kind = current_ts.kind; | |
bc21d315 JW |
1940 | sym->ts.u.cl = cl; |
1941 | sym->ts.u.derived = current_ts.u.derived; | |
a8b3b0b6 CR |
1942 | sym->ts.is_c_interop = current_ts.is_c_interop; |
1943 | sym->ts.is_iso_c = current_ts.is_iso_c; | |
83d890b9 | 1944 | m = MATCH_YES; |
f5acf0f2 | 1945 | |
83d890b9 AL |
1946 | /* Check to see if we have an array specification. */ |
1947 | if (cp_as != NULL) | |
1948 | { | |
1949 | if (sym->as != NULL) | |
1950 | { | |
e25a0da3 | 1951 | gfc_error ("Duplicate array spec for Cray pointee at %C"); |
83d890b9 AL |
1952 | gfc_free_array_spec (cp_as); |
1953 | m = MATCH_ERROR; | |
1954 | goto cleanup; | |
1955 | } | |
1956 | else | |
1957 | { | |
524af0d6 | 1958 | if (!gfc_set_array_spec (sym, cp_as, &var_locus)) |
83d890b9 | 1959 | gfc_internal_error ("Couldn't set pointee array spec."); |
d51347f9 | 1960 | |
83d890b9 | 1961 | /* Fix the array spec. */ |
d51347f9 | 1962 | m = gfc_mod_pointee_as (sym->as); |
83d890b9 AL |
1963 | if (m == MATCH_ERROR) |
1964 | goto cleanup; | |
1965 | } | |
d51347f9 | 1966 | } |
83d890b9 AL |
1967 | goto cleanup; |
1968 | } | |
1969 | else | |
1970 | { | |
1971 | gfc_free_array_spec (cp_as); | |
1972 | } | |
1973 | } | |
d51347f9 | 1974 | |
3070bab4 JW |
1975 | /* Procedure pointer as function result. */ |
1976 | if (gfc_current_state () == COMP_FUNCTION | |
1977 | && strcmp ("ppr@", gfc_current_block ()->name) == 0 | |
1978 | && strcmp (name, gfc_current_block ()->ns->proc_name->name) == 0) | |
1979 | strcpy (name, "ppr@"); | |
1980 | ||
1981 | if (gfc_current_state () == COMP_FUNCTION | |
1982 | && strcmp (name, gfc_current_block ()->name) == 0 | |
1983 | && gfc_current_block ()->result | |
1984 | && strcmp ("ppr@", gfc_current_block ()->result->name) == 0) | |
1985 | strcpy (name, "ppr@"); | |
d51347f9 | 1986 | |
6de9cd9a DN |
1987 | /* OK, we've successfully matched the declaration. Now put the |
1988 | symbol in the current namespace, because it might be used in the | |
69de3b83 | 1989 | optional initialization expression for this symbol, e.g. this is |
6de9cd9a DN |
1990 | perfectly legal: |
1991 | ||
1992 | integer, parameter :: i = huge(i) | |
1993 | ||
1994 | This is only true for parameters or variables of a basic type. | |
1995 | For components of derived types, it is not true, so we don't | |
1996 | create a symbol for those yet. If we fail to create the symbol, | |
1997 | bail out. */ | |
1998 | if (gfc_current_state () != COMP_DERIVED | |
524af0d6 | 1999 | && !build_sym (name, cl, cl_deferred, &as, &var_locus)) |
6de9cd9a | 2000 | { |
72af9f0b PT |
2001 | m = MATCH_ERROR; |
2002 | goto cleanup; | |
2003 | } | |
2004 | ||
524af0d6 | 2005 | if (!check_function_name (name)) |
6de9cd9a | 2006 | { |
6de9cd9a DN |
2007 | m = MATCH_ERROR; |
2008 | goto cleanup; | |
2009 | } | |
2010 | ||
294fbfc8 TS |
2011 | /* We allow old-style initializations of the form |
2012 | integer i /2/, j(4) /3*3, 1/ | |
2013 | (if no colon has been seen). These are different from data | |
2014 | statements in that initializers are only allowed to apply to the | |
2015 | variable immediately preceding, i.e. | |
2016 | integer i, j /1, 2/ | |
2017 | is not allowed. Therefore we have to do some work manually, that | |
75d17889 | 2018 | could otherwise be left to the matchers for DATA statements. */ |
294fbfc8 TS |
2019 | |
2020 | if (!colon_seen && gfc_match (" /") == MATCH_YES) | |
2021 | { | |
524af0d6 JB |
2022 | if (!gfc_notify_std (GFC_STD_GNU, "Old-style " |
2023 | "initialization at %C")) | |
294fbfc8 | 2024 | return MATCH_ERROR; |
b18f1efc JJ |
2025 | else if (gfc_current_state () == COMP_DERIVED) |
2026 | { | |
2027 | gfc_error ("Invalid old style initialization for derived type " | |
2028 | "component at %C"); | |
2029 | m = MATCH_ERROR; | |
2030 | goto cleanup; | |
2031 | } | |
f5acf0f2 | 2032 | |
294fbfc8 TS |
2033 | return match_old_style_init (name); |
2034 | } | |
2035 | ||
6de9cd9a DN |
2036 | /* The double colon must be present in order to have initializers. |
2037 | Otherwise the statement is ambiguous with an assignment statement. */ | |
2038 | if (colon_seen) | |
2039 | { | |
2040 | if (gfc_match (" =>") == MATCH_YES) | |
2041 | { | |
6de9cd9a DN |
2042 | if (!current_attr.pointer) |
2043 | { | |
2044 | gfc_error ("Initialization at %C isn't for a pointer variable"); | |
2045 | m = MATCH_ERROR; | |
2046 | goto cleanup; | |
2047 | } | |
2048 | ||
80f95228 | 2049 | m = match_pointer_init (&initializer, 0); |
6de9cd9a DN |
2050 | if (m != MATCH_YES) |
2051 | goto cleanup; | |
6de9cd9a DN |
2052 | } |
2053 | else if (gfc_match_char ('=') == MATCH_YES) | |
2054 | { | |
2055 | if (current_attr.pointer) | |
2056 | { | |
a4d9b221 TB |
2057 | gfc_error ("Pointer initialization at %C requires %<=>%>, " |
2058 | "not %<=%>"); | |
6de9cd9a DN |
2059 | m = MATCH_ERROR; |
2060 | goto cleanup; | |
2061 | } | |
2062 | ||
2063 | m = gfc_match_init_expr (&initializer); | |
2064 | if (m == MATCH_NO) | |
2065 | { | |
2066 | gfc_error ("Expected an initialization expression at %C"); | |
2067 | m = MATCH_ERROR; | |
2068 | } | |
2069 | ||
ade20620 TB |
2070 | if (current_attr.flavor != FL_PARAMETER && gfc_pure (NULL) |
2071 | && gfc_state_stack->state != COMP_DERIVED) | |
6de9cd9a | 2072 | { |
636dff67 SK |
2073 | gfc_error ("Initialization of variable at %C is not allowed in " |
2074 | "a PURE procedure"); | |
6de9cd9a DN |
2075 | m = MATCH_ERROR; |
2076 | } | |
2077 | ||
ccd7751b TB |
2078 | if (current_attr.flavor != FL_PARAMETER |
2079 | && gfc_state_stack->state != COMP_DERIVED) | |
2080 | gfc_unset_implicit_pure (gfc_current_ns->proc_name); | |
2081 | ||
6de9cd9a DN |
2082 | if (m != MATCH_YES) |
2083 | goto cleanup; | |
2084 | } | |
cb44ab82 VL |
2085 | } |
2086 | ||
5046aff5 PT |
2087 | if (initializer != NULL && current_attr.allocatable |
2088 | && gfc_current_state () == COMP_DERIVED) | |
2089 | { | |
636dff67 SK |
2090 | gfc_error ("Initialization of allocatable component at %C is not " |
2091 | "allowed"); | |
5046aff5 PT |
2092 | m = MATCH_ERROR; |
2093 | goto cleanup; | |
2094 | } | |
2095 | ||
54b4ba60 | 2096 | /* Add the initializer. Note that it is fine if initializer is |
6de9cd9a DN |
2097 | NULL here, because we sometimes also need to check if a |
2098 | declaration *must* have an initialization expression. */ | |
2099 | if (gfc_current_state () != COMP_DERIVED) | |
2100 | t = add_init_expr_to_sym (name, &initializer, &var_locus); | |
2101 | else | |
54b4ba60 | 2102 | { |
5046aff5 | 2103 | if (current_ts.type == BT_DERIVED |
636dff67 | 2104 | && !current_attr.pointer && !initializer) |
54b4ba60 PB |
2105 | initializer = gfc_default_initializer (¤t_ts); |
2106 | t = build_struct (name, cl, &initializer, &as); | |
2107 | } | |
6de9cd9a | 2108 | |
524af0d6 | 2109 | m = (t) ? MATCH_YES : MATCH_ERROR; |
6de9cd9a DN |
2110 | |
2111 | cleanup: | |
2112 | /* Free stuff up and return. */ | |
2113 | gfc_free_expr (initializer); | |
2114 | gfc_free_array_spec (as); | |
2115 | ||
2116 | return m; | |
2117 | } | |
2118 | ||
2119 | ||
b2b81a3f BM |
2120 | /* Match an extended-f77 "TYPESPEC*bytesize"-style kind specification. |
2121 | This assumes that the byte size is equal to the kind number for | |
2122 | non-COMPLEX types, and equal to twice the kind number for COMPLEX. */ | |
6de9cd9a DN |
2123 | |
2124 | match | |
636dff67 | 2125 | gfc_match_old_kind_spec (gfc_typespec *ts) |
6de9cd9a DN |
2126 | { |
2127 | match m; | |
5cf54585 | 2128 | int original_kind; |
6de9cd9a DN |
2129 | |
2130 | if (gfc_match_char ('*') != MATCH_YES) | |
2131 | return MATCH_NO; | |
2132 | ||
5cf54585 | 2133 | m = gfc_match_small_literal_int (&ts->kind, NULL); |
6de9cd9a DN |
2134 | if (m != MATCH_YES) |
2135 | return MATCH_ERROR; | |
2136 | ||
e45b3c75 ES |
2137 | original_kind = ts->kind; |
2138 | ||
6de9cd9a | 2139 | /* Massage the kind numbers for complex types. */ |
e45b3c75 ES |
2140 | if (ts->type == BT_COMPLEX) |
2141 | { | |
2142 | if (ts->kind % 2) | |
636dff67 SK |
2143 | { |
2144 | gfc_error ("Old-style type declaration %s*%d not supported at %C", | |
2145 | gfc_basic_typename (ts->type), original_kind); | |
2146 | return MATCH_ERROR; | |
2147 | } | |
e45b3c75 | 2148 | ts->kind /= 2; |
f4347334 ZG |
2149 | |
2150 | } | |
2151 | ||
203c7ebf | 2152 | if (ts->type == BT_INTEGER && ts->kind == 4 && flag_integer4_kind == 8) |
f4347334 ZG |
2153 | ts->kind = 8; |
2154 | ||
2155 | if (ts->type == BT_REAL || ts->type == BT_COMPLEX) | |
2156 | { | |
2157 | if (ts->kind == 4) | |
2158 | { | |
203c7ebf | 2159 | if (flag_real4_kind == 8) |
f4347334 | 2160 | ts->kind = 8; |
203c7ebf | 2161 | if (flag_real4_kind == 10) |
f4347334 | 2162 | ts->kind = 10; |
203c7ebf | 2163 | if (flag_real4_kind == 16) |
f4347334 ZG |
2164 | ts->kind = 16; |
2165 | } | |
2166 | ||
2167 | if (ts->kind == 8) | |
2168 | { | |
203c7ebf | 2169 | if (flag_real8_kind == 4) |
f4347334 | 2170 | ts->kind = 4; |
203c7ebf | 2171 | if (flag_real8_kind == 10) |
f4347334 | 2172 | ts->kind = 10; |
203c7ebf | 2173 | if (flag_real8_kind == 16) |
f4347334 ZG |
2174 | ts->kind = 16; |
2175 | } | |
e45b3c75 | 2176 | } |
6de9cd9a | 2177 | |
e7a2d5fb | 2178 | if (gfc_validate_kind (ts->type, ts->kind, true) < 0) |
6de9cd9a | 2179 | { |
e45b3c75 | 2180 | gfc_error ("Old-style type declaration %s*%d not supported at %C", |
636dff67 | 2181 | gfc_basic_typename (ts->type), original_kind); |
6de9cd9a DN |
2182 | return MATCH_ERROR; |
2183 | } | |
2184 | ||
524af0d6 JB |
2185 | if (!gfc_notify_std (GFC_STD_GNU, |
2186 | "Nonstandard type declaration %s*%d at %C", | |
2187 | gfc_basic_typename(ts->type), original_kind)) | |
df8652dc SK |
2188 | return MATCH_ERROR; |
2189 | ||
6de9cd9a DN |
2190 | return MATCH_YES; |
2191 | } | |
2192 | ||
2193 | ||
2194 | /* Match a kind specification. Since kinds are generally optional, we | |
2195 | usually return MATCH_NO if something goes wrong. If a "kind=" | |
2196 | string is found, then we know we have an error. */ | |
2197 | ||
2198 | match | |
e2d29968 | 2199 | gfc_match_kind_spec (gfc_typespec *ts, bool kind_expr_only) |
6de9cd9a | 2200 | { |
e2d29968 | 2201 | locus where, loc; |
6de9cd9a DN |
2202 | gfc_expr *e; |
2203 | match m, n; | |
96ee3a4a | 2204 | char c; |
6de9cd9a DN |
2205 | const char *msg; |
2206 | ||
2207 | m = MATCH_NO; | |
e2d29968 | 2208 | n = MATCH_YES; |
6de9cd9a DN |
2209 | e = NULL; |
2210 | ||
e2d29968 PT |
2211 | where = loc = gfc_current_locus; |
2212 | ||
2213 | if (kind_expr_only) | |
2214 | goto kind_expr; | |
6de9cd9a DN |
2215 | |
2216 | if (gfc_match_char ('(') == MATCH_NO) | |
2217 | return MATCH_NO; | |
2218 | ||
2219 | /* Also gobbles optional text. */ | |
2220 | if (gfc_match (" kind = ") == MATCH_YES) | |
2221 | m = MATCH_ERROR; | |
2222 | ||
e2d29968 PT |
2223 | loc = gfc_current_locus; |
2224 | ||
2225 | kind_expr: | |
6de9cd9a | 2226 | n = gfc_match_init_expr (&e); |
e2d29968 | 2227 | |
6de9cd9a | 2228 | if (n != MATCH_YES) |
e2d29968 | 2229 | { |
1c8bcdf7 | 2230 | if (gfc_matching_function) |
e2d29968 | 2231 | { |
f5acf0f2 | 2232 | /* The function kind expression might include use associated or |
1c8bcdf7 PT |
2233 | imported parameters and try again after the specification |
2234 | expressions..... */ | |
e2d29968 PT |
2235 | if (gfc_match_char (')') != MATCH_YES) |
2236 | { | |
2237 | gfc_error ("Missing right parenthesis at %C"); | |
2238 | m = MATCH_ERROR; | |
2239 | goto no_match; | |
2240 | } | |
2241 | ||
2242 | gfc_free_expr (e); | |
e2d29968 PT |
2243 | gfc_undo_symbols (); |
2244 | return MATCH_YES; | |
2245 | } | |
2246 | else | |
2247 | { | |
2248 | /* ....or else, the match is real. */ | |
2249 | if (n == MATCH_NO) | |
2250 | gfc_error ("Expected initialization expression at %C"); | |
2251 | if (n != MATCH_YES) | |
2252 | return MATCH_ERROR; | |
2253 | } | |
2254 | } | |
6de9cd9a DN |
2255 | |
2256 | if (e->rank != 0) | |
2257 | { | |
2258 | gfc_error ("Expected scalar initialization expression at %C"); | |
2259 | m = MATCH_ERROR; | |
2260 | goto no_match; | |
2261 | } | |
2262 | ||
2263 | msg = gfc_extract_int (e, &ts->kind); | |
1c8bcdf7 | 2264 | |
6de9cd9a DN |
2265 | if (msg != NULL) |
2266 | { | |
2267 | gfc_error (msg); | |
2268 | m = MATCH_ERROR; | |
2269 | goto no_match; | |
2270 | } | |
2271 | ||
a8b3b0b6 CR |
2272 | /* Before throwing away the expression, let's see if we had a |
2273 | C interoperable kind (and store the fact). */ | |
2274 | if (e->ts.is_c_interop == 1) | |
2275 | { | |
eea58adb | 2276 | /* Mark this as C interoperable if being declared with one |
a8b3b0b6 CR |
2277 | of the named constants from iso_c_binding. */ |
2278 | ts->is_c_interop = e->ts.is_iso_c; | |
2279 | ts->f90_type = e->ts.f90_type; | |
2280 | } | |
f5acf0f2 | 2281 | |
6de9cd9a DN |
2282 | gfc_free_expr (e); |
2283 | e = NULL; | |
2284 | ||
a8b3b0b6 CR |
2285 | /* Ignore errors to this point, if we've gotten here. This means |
2286 | we ignore the m=MATCH_ERROR from above. */ | |
e7a2d5fb | 2287 | if (gfc_validate_kind (ts->type, ts->kind, true) < 0) |
6de9cd9a DN |
2288 | { |
2289 | gfc_error ("Kind %d not supported for type %s at %C", ts->kind, | |
2290 | gfc_basic_typename (ts->type)); | |
96ee3a4a TB |
2291 | gfc_current_locus = where; |
2292 | return MATCH_ERROR; | |
6de9cd9a | 2293 | } |
96ee3a4a | 2294 | |
2ec855f1 TB |
2295 | /* Warn if, e.g., c_int is used for a REAL variable, but not |
2296 | if, e.g., c_double is used for COMPLEX as the standard | |
2297 | explicitly says that the kind type parameter for complex and real | |
2298 | variable is the same, i.e. c_float == c_float_complex. */ | |
2299 | if (ts->f90_type != BT_UNKNOWN && ts->f90_type != ts->type | |
2300 | && !((ts->f90_type == BT_REAL && ts->type == BT_COMPLEX) | |
2301 | || (ts->f90_type == BT_COMPLEX && ts->type == BT_REAL))) | |
db30e21c | 2302 | gfc_warning_now (0, "C kind type parameter is for type %s but type at %L " |
2be51762 TB |
2303 | "is %s", gfc_basic_typename (ts->f90_type), &where, |
2304 | gfc_basic_typename (ts->type)); | |
2ec855f1 | 2305 | |
96ee3a4a | 2306 | gfc_gobble_whitespace (); |
8fc541d3 FXC |
2307 | if ((c = gfc_next_ascii_char ()) != ')' |
2308 | && (ts->type != BT_CHARACTER || c != ',')) | |
6de9cd9a | 2309 | { |
96ee3a4a TB |
2310 | if (ts->type == BT_CHARACTER) |
2311 | gfc_error ("Missing right parenthesis or comma at %C"); | |
2312 | else | |
2313 | gfc_error ("Missing right parenthesis at %C"); | |
e2d29968 | 2314 | m = MATCH_ERROR; |
6de9cd9a | 2315 | } |
a8b3b0b6 CR |
2316 | else |
2317 | /* All tests passed. */ | |
2318 | m = MATCH_YES; | |
6de9cd9a | 2319 | |
a8b3b0b6 CR |
2320 | if(m == MATCH_ERROR) |
2321 | gfc_current_locus = where; | |
f4347334 | 2322 | |
203c7ebf | 2323 | if (ts->type == BT_INTEGER && ts->kind == 4 && flag_integer4_kind == 8) |
f4347334 ZG |
2324 | ts->kind = 8; |
2325 | ||
2326 | if (ts->type == BT_REAL || ts->type == BT_COMPLEX) | |
2327 | { | |
2328 | if (ts->kind == 4) | |
2329 | { | |
203c7ebf | 2330 | if (flag_real4_kind == 8) |
f4347334 | 2331 | ts->kind = 8; |
203c7ebf | 2332 | if (flag_real4_kind == 10) |
f4347334 | 2333 | ts->kind = 10; |
203c7ebf | 2334 | if (flag_real4_kind == 16) |
f4347334 ZG |
2335 | ts->kind = 16; |
2336 | } | |
2337 | ||
2338 | if (ts->kind == 8) | |
2339 | { | |
203c7ebf | 2340 | if (flag_real8_kind == 4) |
f4347334 | 2341 | ts->kind = 4; |
203c7ebf | 2342 | if (flag_real8_kind == 10) |
f4347334 | 2343 | ts->kind = 10; |
203c7ebf | 2344 | if (flag_real8_kind == 16) |
f4347334 ZG |
2345 | ts->kind = 16; |
2346 | } | |
2347 | } | |
2348 | ||
a8b3b0b6 CR |
2349 | /* Return what we know from the test(s). */ |
2350 | return m; | |
6de9cd9a DN |
2351 | |
2352 | no_match: | |
2353 | gfc_free_expr (e); | |
63645982 | 2354 | gfc_current_locus = where; |
6de9cd9a DN |
2355 | return m; |
2356 | } | |
2357 | ||
2358 | ||
187de1ed FXC |
2359 | static match |
2360 | match_char_kind (int * kind, int * is_iso_c) | |
2361 | { | |
2362 | locus where; | |
2363 | gfc_expr *e; | |
2364 | match m, n; | |
2365 | const char *msg; | |
2366 | ||
2367 | m = MATCH_NO; | |
2368 | e = NULL; | |
2369 | where = gfc_current_locus; | |
2370 | ||
2371 | n = gfc_match_init_expr (&e); | |
96ee3a4a | 2372 | |
1c8bcdf7 | 2373 | if (n != MATCH_YES && gfc_matching_function) |
96ee3a4a | 2374 | { |
1c8bcdf7 | 2375 | /* The expression might include use-associated or imported |
f5acf0f2 | 2376 | parameters and try again after the specification |
1c8bcdf7 | 2377 | expressions. */ |
96ee3a4a | 2378 | gfc_free_expr (e); |
96ee3a4a TB |
2379 | gfc_undo_symbols (); |
2380 | return MATCH_YES; | |
2381 | } | |
2382 | ||
187de1ed FXC |
2383 | if (n == MATCH_NO) |
2384 | gfc_error ("Expected initialization expression at %C"); | |
2385 | if (n != MATCH_YES) | |
2386 | return MATCH_ERROR; | |
2387 | ||
2388 | if (e->rank != 0) | |
2389 | { | |
2390 | gfc_error ("Expected scalar initialization expression at %C"); | |
2391 | m = MATCH_ERROR; | |
2392 | goto no_match; | |
2393 | } | |
2394 | ||
2395 | msg = gfc_extract_int (e, kind); | |
2396 | *is_iso_c = e->ts.is_iso_c; | |
2397 | if (msg != NULL) | |
2398 | { | |
2399 | gfc_error (msg); | |
2400 | m = MATCH_ERROR; | |
2401 | goto no_match; | |
2402 | } | |
2403 | ||
2404 | gfc_free_expr (e); | |
2405 | ||
2406 | /* Ignore errors to this point, if we've gotten here. This means | |
2407 | we ignore the m=MATCH_ERROR from above. */ | |
2408 | if (gfc_validate_kind (BT_CHARACTER, *kind, true) < 0) | |
2409 | { | |
2410 | gfc_error ("Kind %d is not supported for CHARACTER at %C", *kind); | |
2411 | m = MATCH_ERROR; | |
2412 | } | |
2413 | else | |
2414 | /* All tests passed. */ | |
2415 | m = MATCH_YES; | |
2416 | ||
2417 | if (m == MATCH_ERROR) | |
2418 | gfc_current_locus = where; | |
f5acf0f2 | 2419 | |
187de1ed FXC |
2420 | /* Return what we know from the test(s). */ |
2421 | return m; | |
2422 | ||
2423 | no_match: | |
2424 | gfc_free_expr (e); | |
2425 | gfc_current_locus = where; | |
2426 | return m; | |
2427 | } | |
2428 | ||
8234e5e0 | 2429 | |
6de9cd9a DN |
2430 | /* Match the various kind/length specifications in a CHARACTER |
2431 | declaration. We don't return MATCH_NO. */ | |
2432 | ||
8234e5e0 SK |
2433 | match |
2434 | gfc_match_char_spec (gfc_typespec *ts) | |
6de9cd9a | 2435 | { |
187de1ed | 2436 | int kind, seen_length, is_iso_c; |
6de9cd9a DN |
2437 | gfc_charlen *cl; |
2438 | gfc_expr *len; | |
2439 | match m; | |
e69afb29 | 2440 | bool deferred; |
187de1ed | 2441 | |
6de9cd9a DN |
2442 | len = NULL; |
2443 | seen_length = 0; | |
187de1ed FXC |
2444 | kind = 0; |
2445 | is_iso_c = 0; | |
e69afb29 | 2446 | deferred = false; |
6de9cd9a DN |
2447 | |
2448 | /* Try the old-style specification first. */ | |
2449 | old_char_selector = 0; | |
2450 | ||
2767f2cc | 2451 | m = match_char_length (&len, &deferred, true); |
6de9cd9a DN |
2452 | if (m != MATCH_NO) |
2453 | { | |
2454 | if (m == MATCH_YES) | |
2455 | old_char_selector = 1; | |
2456 | seen_length = 1; | |
2457 | goto done; | |
2458 | } | |
2459 | ||
2460 | m = gfc_match_char ('('); | |
2461 | if (m != MATCH_YES) | |
2462 | { | |
a8b3b0b6 | 2463 | m = MATCH_YES; /* Character without length is a single char. */ |
6de9cd9a DN |
2464 | goto done; |
2465 | } | |
2466 | ||
a8b3b0b6 | 2467 | /* Try the weird case: ( KIND = <int> [ , LEN = <len-param> ] ). */ |
6de9cd9a DN |
2468 | if (gfc_match (" kind =") == MATCH_YES) |
2469 | { | |
187de1ed | 2470 | m = match_char_kind (&kind, &is_iso_c); |
f5acf0f2 | 2471 | |
6de9cd9a DN |
2472 | if (m == MATCH_ERROR) |
2473 | goto done; | |
2474 | if (m == MATCH_NO) | |
2475 | goto syntax; | |
2476 | ||
2477 | if (gfc_match (" , len =") == MATCH_NO) | |
2478 | goto rparen; | |
2479 | ||
e69afb29 | 2480 | m = char_len_param_value (&len, &deferred); |
6de9cd9a DN |
2481 | if (m == MATCH_NO) |
2482 | goto syntax; | |
2483 | if (m == MATCH_ERROR) | |
2484 | goto done; | |
2485 | seen_length = 1; | |
2486 | ||
2487 | goto rparen; | |
2488 | } | |
2489 | ||
66e4ab31 | 2490 | /* Try to match "LEN = <len-param>" or "LEN = <len-param>, KIND = <int>". */ |
6de9cd9a DN |
2491 | if (gfc_match (" len =") == MATCH_YES) |
2492 | { | |
e69afb29 | 2493 | m = char_len_param_value (&len, &deferred); |
6de9cd9a DN |
2494 | if (m == MATCH_NO) |
2495 | goto syntax; | |
2496 | if (m == MATCH_ERROR) | |
2497 | goto done; | |
2498 | seen_length = 1; | |
2499 | ||
2500 | if (gfc_match_char (')') == MATCH_YES) | |
2501 | goto done; | |
2502 | ||
2503 | if (gfc_match (" , kind =") != MATCH_YES) | |
2504 | goto syntax; | |
2505 | ||
187de1ed FXC |
2506 | if (match_char_kind (&kind, &is_iso_c) == MATCH_ERROR) |
2507 | goto done; | |
6de9cd9a DN |
2508 | |
2509 | goto rparen; | |
2510 | } | |
2511 | ||
66e4ab31 | 2512 | /* Try to match ( <len-param> ) or ( <len-param> , [ KIND = ] <int> ). */ |
e69afb29 | 2513 | m = char_len_param_value (&len, &deferred); |
6de9cd9a DN |
2514 | if (m == MATCH_NO) |
2515 | goto syntax; | |
2516 | if (m == MATCH_ERROR) | |
2517 | goto done; | |
2518 | seen_length = 1; | |
2519 | ||
2520 | m = gfc_match_char (')'); | |
2521 | if (m == MATCH_YES) | |
2522 | goto done; | |
2523 | ||
2524 | if (gfc_match_char (',') != MATCH_YES) | |
2525 | goto syntax; | |
2526 | ||
a8b3b0b6 | 2527 | gfc_match (" kind ="); /* Gobble optional text. */ |
6de9cd9a | 2528 | |
187de1ed | 2529 | m = match_char_kind (&kind, &is_iso_c); |
6de9cd9a DN |
2530 | if (m == MATCH_ERROR) |
2531 | goto done; | |
2532 | if (m == MATCH_NO) | |
2533 | goto syntax; | |
2534 | ||
2535 | rparen: | |
2536 | /* Require a right-paren at this point. */ | |
2537 | m = gfc_match_char (')'); | |
2538 | if (m == MATCH_YES) | |
2539 | goto done; | |
2540 | ||
2541 | syntax: | |
2542 | gfc_error ("Syntax error in CHARACTER declaration at %C"); | |
2543 | m = MATCH_ERROR; | |
16f8ffc8 JD |
2544 | gfc_free_expr (len); |
2545 | return m; | |
6de9cd9a DN |
2546 | |
2547 | done: | |
a99d95a2 PT |
2548 | /* Deal with character functions after USE and IMPORT statements. */ |
2549 | if (gfc_matching_function) | |
1c8bcdf7 | 2550 | { |
a99d95a2 | 2551 | gfc_free_expr (len); |
1c8bcdf7 PT |
2552 | gfc_undo_symbols (); |
2553 | return MATCH_YES; | |
2554 | } | |
2555 | ||
6de9cd9a DN |
2556 | if (m != MATCH_YES) |
2557 | { | |
2558 | gfc_free_expr (len); | |
2559 | return m; | |
2560 | } | |
2561 | ||
2562 | /* Do some final massaging of the length values. */ | |
b76e28c6 | 2563 | cl = gfc_new_charlen (gfc_current_ns, NULL); |
6de9cd9a DN |
2564 | |
2565 | if (seen_length == 0) | |
b7e75771 | 2566 | cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1); |
6de9cd9a | 2567 | else |
5cd09fac | 2568 | cl->length = len; |
6de9cd9a | 2569 | |
bc21d315 | 2570 | ts->u.cl = cl; |
187de1ed | 2571 | ts->kind = kind == 0 ? gfc_default_character_kind : kind; |
e69afb29 | 2572 | ts->deferred = deferred; |
6de9cd9a | 2573 | |
eea58adb | 2574 | /* We have to know if it was a C interoperable kind so we can |
a8b3b0b6 | 2575 | do accurate type checking of bind(c) procs, etc. */ |
187de1ed | 2576 | if (kind != 0) |
eea58adb | 2577 | /* Mark this as C interoperable if being declared with one |
187de1ed FXC |
2578 | of the named constants from iso_c_binding. */ |
2579 | ts->is_c_interop = is_iso_c; | |
a8b3b0b6 | 2580 | else if (len != NULL) |
187de1ed FXC |
2581 | /* Here, we might have parsed something such as: character(c_char) |
2582 | In this case, the parsing code above grabs the c_char when | |
2583 | looking for the length (line 1690, roughly). it's the last | |
2584 | testcase for parsing the kind params of a character variable. | |
2585 | However, it's not actually the length. this seems like it | |
f5acf0f2 | 2586 | could be an error. |
187de1ed FXC |
2587 | To see if the user used a C interop kind, test the expr |
2588 | of the so called length, and see if it's C interoperable. */ | |
2589 | ts->is_c_interop = len->ts.is_iso_c; | |
f5acf0f2 | 2590 | |
6de9cd9a DN |
2591 | return MATCH_YES; |
2592 | } | |
2593 | ||
2594 | ||
e74f1cc8 JW |
2595 | /* Matches a declaration-type-spec (F03:R502). If successful, sets the ts |
2596 | structure to the matched specification. This is necessary for FUNCTION and | |
6de9cd9a DN |
2597 | IMPLICIT statements. |
2598 | ||
d51347f9 | 2599 | If implicit_flag is nonzero, then we don't check for the optional |
e5ddaa24 | 2600 | kind specification. Not doing so is needed for matching an IMPLICIT |
6de9cd9a DN |
2601 | statement correctly. */ |
2602 | ||
e2d29968 | 2603 | match |
e74f1cc8 | 2604 | gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag) |
6de9cd9a DN |
2605 | { |
2606 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
c3f34952 | 2607 | gfc_symbol *sym, *dt_sym; |
6de9cd9a | 2608 | match m; |
8fc541d3 | 2609 | char c; |
0fb56814 | 2610 | bool seen_deferred_kind, matched_type; |
c3f34952 | 2611 | const char *dt_name; |
6de9cd9a | 2612 | |
1c8bcdf7 PT |
2613 | /* A belt and braces check that the typespec is correctly being treated |
2614 | as a deferred characteristic association. */ | |
2615 | seen_deferred_kind = (gfc_current_state () == COMP_FUNCTION) | |
a99d95a2 PT |
2616 | && (gfc_current_block ()->result->ts.kind == -1) |
2617 | && (ts->kind == -1); | |
6de9cd9a | 2618 | gfc_clear_ts (ts); |
1c8bcdf7 PT |
2619 | if (seen_deferred_kind) |
2620 | ts->kind = -1; | |
6de9cd9a | 2621 | |
a8b3b0b6 | 2622 | /* Clear the current binding label, in case one is given. */ |
62603fae | 2623 | curr_binding_label = NULL; |
a8b3b0b6 | 2624 | |
5f700e6d AL |
2625 | if (gfc_match (" byte") == MATCH_YES) |
2626 | { | |
524af0d6 | 2627 | if (!gfc_notify_std (GFC_STD_GNU, "BYTE type at %C")) |
5f700e6d AL |
2628 | return MATCH_ERROR; |
2629 | ||
2630 | if (gfc_validate_kind (BT_INTEGER, 1, true) < 0) | |
2631 | { | |
2632 | gfc_error ("BYTE type used at %C " | |
2633 | "is not available on the target machine"); | |
2634 | return MATCH_ERROR; | |
2635 | } | |
d51347f9 | 2636 | |
5f700e6d AL |
2637 | ts->type = BT_INTEGER; |
2638 | ts->kind = 1; | |
2639 | return MATCH_YES; | |
2640 | } | |
2641 | ||
0fb56814 | 2642 | |
45a69325 | 2643 | m = gfc_match (" type ("); |
0fb56814 | 2644 | matched_type = (m == MATCH_YES); |
45a69325 TB |
2645 | if (matched_type) |
2646 | { | |
2647 | gfc_gobble_whitespace (); | |
2648 | if (gfc_peek_ascii_char () == '*') | |
2649 | { | |
2650 | if ((m = gfc_match ("*)")) != MATCH_YES) | |
2651 | return m; | |
2652 | if (gfc_current_state () == COMP_DERIVED) | |
2653 | { | |
2654 | gfc_error ("Assumed type at %C is not allowed for components"); | |
2655 | return MATCH_ERROR; | |
2656 | } | |
524af0d6 JB |
2657 | if (!gfc_notify_std (GFC_STD_F2008_TS, "Assumed type " |
2658 | "at %C")) | |
45a69325 TB |
2659 | return MATCH_ERROR; |
2660 | ts->type = BT_ASSUMED; | |
2661 | return MATCH_YES; | |
2662 | } | |
2663 | ||
2664 | m = gfc_match ("%n", name); | |
2665 | matched_type = (m == MATCH_YES); | |
2666 | } | |
2667 | ||
0fb56814 TB |
2668 | if ((matched_type && strcmp ("integer", name) == 0) |
2669 | || (!matched_type && gfc_match (" integer") == MATCH_YES)) | |
6de9cd9a DN |
2670 | { |
2671 | ts->type = BT_INTEGER; | |
9d64df18 | 2672 | ts->kind = gfc_default_integer_kind; |
6de9cd9a DN |
2673 | goto get_kind; |
2674 | } | |
2675 | ||
0fb56814 TB |
2676 | if ((matched_type && strcmp ("character", name) == 0) |
2677 | || (!matched_type && gfc_match (" character") == MATCH_YES)) | |
6de9cd9a | 2678 | { |
0fb56814 | 2679 | if (matched_type |
524af0d6 JB |
2680 | && !gfc_notify_std (GFC_STD_F2008, "TYPE with " |
2681 | "intrinsic-type-spec at %C")) | |
0fb56814 TB |
2682 | return MATCH_ERROR; |
2683 | ||
6de9cd9a | 2684 | ts->type = BT_CHARACTER; |
e5ddaa24 | 2685 | if (implicit_flag == 0) |
0fb56814 | 2686 | m = gfc_match_char_spec (ts); |
e5ddaa24 | 2687 | else |
0fb56814 TB |
2688 | m = MATCH_YES; |
2689 | ||
2690 | if (matched_type && m == MATCH_YES && gfc_match_char (')') != MATCH_YES) | |
2691 | m = MATCH_ERROR; | |
2692 | ||
2693 | return m; | |
6de9cd9a DN |
2694 | } |
2695 | ||
0fb56814 TB |
2696 | if ((matched_type && strcmp ("real", name) == 0) |
2697 | || (!matched_type && gfc_match (" real") == MATCH_YES)) | |
6de9cd9a DN |
2698 | { |
2699 | ts->type = BT_REAL; | |
9d64df18 | 2700 | ts->kind = gfc_default_real_kind; |
6de9cd9a DN |
2701 | goto get_kind; |
2702 | } | |
2703 | ||
0fb56814 TB |
2704 | if ((matched_type |
2705 | && (strcmp ("doubleprecision", name) == 0 | |
2706 | || (strcmp ("double", name) == 0 | |
2707 | && gfc_match (" precision") == MATCH_YES))) | |
2708 | || (!matched_type && gfc_match (" double precision") == MATCH_YES)) | |
6de9cd9a | 2709 | { |
0fb56814 | 2710 | if (matched_type |
524af0d6 JB |
2711 | && !gfc_notify_std (GFC_STD_F2008, "TYPE with " |
2712 | "intrinsic-type-spec at %C")) | |
0fb56814 TB |
2713 | return MATCH_ERROR; |
2714 | if (matched_type && gfc_match_char (')') != MATCH_YES) | |
2715 | return MATCH_ERROR; | |
2716 | ||
6de9cd9a | 2717 | ts->type = BT_REAL; |
9d64df18 | 2718 | ts->kind = gfc_default_double_kind; |
6de9cd9a DN |
2719 | return MATCH_YES; |
2720 | } | |
2721 | ||
0fb56814 TB |
2722 | if ((matched_type && strcmp ("complex", name) == 0) |
2723 | || (!matched_type && gfc_match (" complex") == MATCH_YES)) | |
6de9cd9a DN |
2724 | { |
2725 | ts->type = BT_COMPLEX; | |
9d64df18 | 2726 | ts->kind = gfc_default_complex_kind; |
6de9cd9a DN |
2727 | goto get_kind; |
2728 | } | |
2729 | ||
0fb56814 TB |
2730 | if ((matched_type |
2731 | && (strcmp ("doublecomplex", name) == 0 | |
2732 | || (strcmp ("double", name) == 0 | |
2733 | && gfc_match (" complex") == MATCH_YES))) | |
2734 | || (!matched_type && gfc_match (" double complex") == MATCH_YES)) | |
6de9cd9a | 2735 | { |
524af0d6 | 2736 | if (!gfc_notify_std (GFC_STD_GNU, "DOUBLE COMPLEX at %C")) |
0fb56814 TB |
2737 | return MATCH_ERROR; |
2738 | ||
2739 | if (matched_type | |
524af0d6 JB |
2740 | && !gfc_notify_std (GFC_STD_F2008, "TYPE with " |
2741 | "intrinsic-type-spec at %C")) | |
0fb56814 TB |
2742 | return MATCH_ERROR; |
2743 | ||
2744 | if (matched_type && gfc_match_char (')') != MATCH_YES) | |
df8652dc SK |
2745 | return MATCH_ERROR; |
2746 | ||
6de9cd9a | 2747 | ts->type = BT_COMPLEX; |
9d64df18 | 2748 | ts->kind = gfc_default_double_kind; |
6de9cd9a DN |
2749 | return MATCH_YES; |
2750 | } | |
2751 | ||
0fb56814 TB |
2752 | if ((matched_type && strcmp ("logical", name) == 0) |
2753 | || (!matched_type && gfc_match (" logical") == MATCH_YES)) | |
6de9cd9a DN |
2754 | { |
2755 | ts->type = BT_LOGICAL; | |
9d64df18 | 2756 | ts->kind = gfc_default_logical_kind; |
6de9cd9a DN |
2757 | goto get_kind; |
2758 | } | |
2759 | ||
0fb56814 TB |
2760 | if (matched_type) |
2761 | m = gfc_match_char (')'); | |
2762 | ||
cf2b3c22 TB |
2763 | if (m == MATCH_YES) |
2764 | ts->type = BT_DERIVED; | |
2765 | else | |
727e8544 | 2766 | { |
528622fd JW |
2767 | /* Match CLASS declarations. */ |
2768 | m = gfc_match (" class ( * )"); | |
2769 | if (m == MATCH_ERROR) | |
2770 | return MATCH_ERROR; | |
2771 | else if (m == MATCH_YES) | |
2772 | { | |
8b704316 PT |
2773 | gfc_symbol *upe; |
2774 | gfc_symtree *st; | |
2775 | ts->type = BT_CLASS; | |
f5acf0f2 | 2776 | gfc_find_symbol ("STAR", gfc_current_ns, 1, &upe); |
8b704316 PT |
2777 | if (upe == NULL) |
2778 | { | |
f5acf0f2 PT |
2779 | upe = gfc_new_symbol ("STAR", gfc_current_ns); |
2780 | st = gfc_new_symtree (&gfc_current_ns->sym_root, "STAR"); | |
8b704316 PT |
2781 | st->n.sym = upe; |
2782 | gfc_set_sym_referenced (upe); | |
2783 | upe->refs++; | |
2784 | upe->ts.type = BT_VOID; | |
2785 | upe->attr.unlimited_polymorphic = 1; | |
2786 | /* This is essential to force the construction of | |
2787 | unlimited polymorphic component class containers. */ | |
2788 | upe->attr.zero_comp = 1; | |
524af0d6 JB |
2789 | if (!gfc_add_flavor (&upe->attr, FL_DERIVED, NULL, |
2790 | &gfc_current_locus)) | |
528622fd JW |
2791 | return MATCH_ERROR; |
2792 | } | |
8b704316 PT |
2793 | else |
2794 | { | |
f5acf0f2 | 2795 | st = gfc_find_symtree (gfc_current_ns->sym_root, "STAR"); |
8b704316 | 2796 | if (st == NULL) |
f5acf0f2 | 2797 | st = gfc_new_symtree (&gfc_current_ns->sym_root, "STAR"); |
8b704316 PT |
2798 | st->n.sym = upe; |
2799 | upe->refs++; | |
2800 | } | |
2801 | ts->u.derived = upe; | |
2802 | return m; | |
2803 | } | |
528622fd | 2804 | |
727e8544 JW |
2805 | m = gfc_match (" class ( %n )", name); |
2806 | if (m != MATCH_YES) | |
2807 | return m; | |
cf2b3c22 | 2808 | ts->type = BT_CLASS; |
727e8544 | 2809 | |
524af0d6 | 2810 | if (!gfc_notify_std (GFC_STD_F2003, "CLASS statement at %C")) |
e74f1cc8 | 2811 | return MATCH_ERROR; |
727e8544 | 2812 | } |
6de9cd9a | 2813 | |
1c8bcdf7 PT |
2814 | /* Defer association of the derived type until the end of the |
2815 | specification block. However, if the derived type can be | |
f5acf0f2 | 2816 | found, add it to the typespec. */ |
1c8bcdf7 | 2817 | if (gfc_matching_function) |
e2d29968 | 2818 | { |
bc21d315 | 2819 | ts->u.derived = NULL; |
1c8bcdf7 PT |
2820 | if (gfc_current_state () != COMP_INTERFACE |
2821 | && !gfc_find_symbol (name, NULL, 1, &sym) && sym) | |
c3f34952 TB |
2822 | { |
2823 | sym = gfc_find_dt_in_generic (sym); | |
2824 | ts->u.derived = sym; | |
2825 | } | |
e2d29968 PT |
2826 | return MATCH_YES; |
2827 | } | |
2828 | ||
2829 | /* Search for the name but allow the components to be defined later. If | |
2830 | type = -1, this typespec has been seen in a function declaration but | |
c3f34952 | 2831 | the type could not be accessed at that point. The actual derived type is |
eea58adb | 2832 | stored in a symtree with the first letter of the name capitalized; the |
c3f34952 TB |
2833 | symtree with the all lower-case name contains the associated |
2834 | generic function. */ | |
2835 | dt_name = gfc_get_string ("%c%s", | |
2836 | (char) TOUPPER ((unsigned char) name[0]), | |
2837 | (const char*)&name[1]); | |
1c8bcdf7 | 2838 | sym = NULL; |
c3f34952 TB |
2839 | dt_sym = NULL; |
2840 | if (ts->kind != -1) | |
6de9cd9a | 2841 | { |
c3f34952 TB |
2842 | gfc_get_ha_symbol (name, &sym); |
2843 | if (sym->generic && gfc_find_symbol (dt_name, NULL, 0, &dt_sym)) | |
2844 | { | |
c4100eae | 2845 | gfc_error ("Type name %qs at %C is ambiguous", name); |
c3f34952 TB |
2846 | return MATCH_ERROR; |
2847 | } | |
2848 | if (sym->generic && !dt_sym) | |
2849 | dt_sym = gfc_find_dt_in_generic (sym); | |
6de9cd9a | 2850 | } |
e2d29968 PT |
2851 | else if (ts->kind == -1) |
2852 | { | |
1c8bcdf7 PT |
2853 | int iface = gfc_state_stack->previous->state != COMP_INTERFACE |
2854 | || gfc_current_ns->has_import_set; | |
c3f34952 TB |
2855 | gfc_find_symbol (name, NULL, iface, &sym); |
2856 | if (sym && sym->generic && gfc_find_symbol (dt_name, NULL, 1, &dt_sym)) | |
f5acf0f2 | 2857 | { |
c4100eae | 2858 | gfc_error ("Type name %qs at %C is ambiguous", name); |
e2d29968 PT |
2859 | return MATCH_ERROR; |
2860 | } | |
c3f34952 TB |
2861 | if (sym && sym->generic && !dt_sym) |
2862 | dt_sym = gfc_find_dt_in_generic (sym); | |
e2d29968 | 2863 | |
1c8bcdf7 | 2864 | ts->kind = 0; |
e2d29968 PT |
2865 | if (sym == NULL) |
2866 | return MATCH_NO; | |
2867 | } | |
6de9cd9a | 2868 | |
c3f34952 TB |
2869 | if ((sym->attr.flavor != FL_UNKNOWN |
2870 | && !(sym->attr.flavor == FL_PROCEDURE && sym->attr.generic)) | |
2871 | || sym->attr.subroutine) | |
2872 | { | |
c4100eae MLI |
2873 | gfc_error_1 ("Type name '%s' at %C conflicts with previously declared " |
2874 | "entity at %L, which has the same name", name, | |
2875 | &sym->declared_at); | |
c3f34952 TB |
2876 | return MATCH_ERROR; |
2877 | } | |
6de9cd9a | 2878 | |
44c57c2f | 2879 | gfc_save_symbol_data (sym); |
1c8bcdf7 | 2880 | gfc_set_sym_referenced (sym); |
c3f34952 | 2881 | if (!sym->attr.generic |
524af0d6 | 2882 | && !gfc_add_generic (&sym->attr, sym->name, NULL)) |
c3f34952 TB |
2883 | return MATCH_ERROR; |
2884 | ||
2885 | if (!sym->attr.function | |
524af0d6 | 2886 | && !gfc_add_function (&sym->attr, sym->name, NULL)) |
c3f34952 TB |
2887 | return MATCH_ERROR; |
2888 | ||
2889 | if (!dt_sym) | |
2890 | { | |
2891 | gfc_interface *intr, *head; | |
2892 | ||
2893 | /* Use upper case to save the actual derived-type symbol. */ | |
2894 | gfc_get_symbol (dt_name, NULL, &dt_sym); | |
2895 | dt_sym->name = gfc_get_string (sym->name); | |
2896 | head = sym->generic; | |
2897 | intr = gfc_get_interface (); | |
2898 | intr->sym = dt_sym; | |
2899 | intr->where = gfc_current_locus; | |
2900 | intr->next = head; | |
2901 | sym->generic = intr; | |
2902 | sym->attr.if_source = IFSRC_DECL; | |
2903 | } | |
44c57c2f MM |
2904 | else |
2905 | gfc_save_symbol_data (dt_sym); | |
c3f34952 TB |
2906 | |
2907 | gfc_set_sym_referenced (dt_sym); | |
2908 | ||
2909 | if (dt_sym->attr.flavor != FL_DERIVED | |
524af0d6 | 2910 | && !gfc_add_flavor (&dt_sym->attr, FL_DERIVED, sym->name, NULL)) |
c3f34952 TB |
2911 | return MATCH_ERROR; |
2912 | ||
2913 | ts->u.derived = dt_sym; | |
6de9cd9a DN |
2914 | |
2915 | return MATCH_YES; | |
2916 | ||
2917 | get_kind: | |
0fb56814 | 2918 | if (matched_type |
524af0d6 JB |
2919 | && !gfc_notify_std (GFC_STD_F2008, "TYPE with " |
2920 | "intrinsic-type-spec at %C")) | |
0fb56814 TB |
2921 | return MATCH_ERROR; |
2922 | ||
6de9cd9a DN |
2923 | /* For all types except double, derived and character, look for an |
2924 | optional kind specifier. MATCH_NO is actually OK at this point. */ | |
e5ddaa24 | 2925 | if (implicit_flag == 1) |
0fb56814 TB |
2926 | { |
2927 | if (matched_type && gfc_match_char (')') != MATCH_YES) | |
2928 | return MATCH_ERROR; | |
2929 | ||
2930 | return MATCH_YES; | |
2931 | } | |
6de9cd9a | 2932 | |
0ff0dfbf TS |
2933 | if (gfc_current_form == FORM_FREE) |
2934 | { | |
0b3624f6 SK |
2935 | c = gfc_peek_ascii_char (); |
2936 | if (!gfc_is_whitespace (c) && c != '*' && c != '(' | |
636dff67 | 2937 | && c != ':' && c != ',') |
0fb56814 TB |
2938 | { |
2939 | if (matched_type && c == ')') | |
2940 | { | |
2941 | gfc_next_ascii_char (); | |
2942 | return MATCH_YES; | |
2943 | } | |
2944 | return MATCH_NO; | |
2945 | } | |
0ff0dfbf TS |
2946 | } |
2947 | ||
e2d29968 | 2948 | m = gfc_match_kind_spec (ts, false); |
6de9cd9a DN |
2949 | if (m == MATCH_NO && ts->type != BT_CHARACTER) |
2950 | m = gfc_match_old_kind_spec (ts); | |
2951 | ||
0fb56814 TB |
2952 | if (matched_type && gfc_match_char (')') != MATCH_YES) |
2953 | return MATCH_ERROR; | |
2954 | ||
1c8bcdf7 PT |
2955 | /* Defer association of the KIND expression of function results |
2956 | until after USE and IMPORT statements. */ | |
2957 | if ((gfc_current_state () == COMP_NONE && gfc_error_flag_test ()) | |
2958 | || gfc_matching_function) | |
2959 | return MATCH_YES; | |
2960 | ||
6de9cd9a DN |
2961 | if (m == MATCH_NO) |
2962 | m = MATCH_YES; /* No kind specifier found. */ | |
2963 | ||
2964 | return m; | |
2965 | } | |
2966 | ||
2967 | ||
e5ddaa24 TS |
2968 | /* Match an IMPLICIT NONE statement. Actually, this statement is |
2969 | already matched in parse.c, or we would not end up here in the | |
2970 | first place. So the only thing we need to check, is if there is | |
2971 | trailing garbage. If not, the match is successful. */ | |
2972 | ||
2973 | match | |
2974 | gfc_match_implicit_none (void) | |
2975 | { | |
8b7a967e TB |
2976 | char c; |
2977 | match m; | |
2978 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
2979 | bool type = false; | |
2980 | bool external = false; | |
a6c63173 TB |
2981 | locus cur_loc = gfc_current_locus; |
2982 | ||
2983 | if (gfc_current_ns->seen_implicit_none | |
2984 | || gfc_current_ns->has_implicit_none_export) | |
2985 | { | |
2986 | gfc_error ("Duplicate IMPLICIT NONE statement at %C"); | |
2987 | return MATCH_ERROR; | |
2988 | } | |
8b7a967e TB |
2989 | |
2990 | gfc_gobble_whitespace (); | |
2991 | c = gfc_peek_ascii_char (); | |
2992 | if (c == '(') | |
2993 | { | |
2994 | (void) gfc_next_ascii_char (); | |
2995 | if (!gfc_notify_std (GFC_STD_F2015, "IMPORT NONE with spec list at %C")) | |
2996 | return MATCH_ERROR; | |
a6c63173 TB |
2997 | |
2998 | gfc_gobble_whitespace (); | |
2999 | if (gfc_peek_ascii_char () == ')') | |
8b7a967e | 3000 | { |
a6c63173 TB |
3001 | (void) gfc_next_ascii_char (); |
3002 | type = true; | |
3003 | } | |
3004 | else | |
3005 | for(;;) | |
3006 | { | |
3007 | m = gfc_match (" %n", name); | |
3008 | if (m != MATCH_YES) | |
3009 | return MATCH_ERROR; | |
8b7a967e | 3010 | |
a6c63173 TB |
3011 | if (strcmp (name, "type") == 0) |
3012 | type = true; | |
3013 | else if (strcmp (name, "external") == 0) | |
3014 | external = true; | |
3015 | else | |
3016 | return MATCH_ERROR; | |
8b7a967e | 3017 | |
a6c63173 TB |
3018 | gfc_gobble_whitespace (); |
3019 | c = gfc_next_ascii_char (); | |
3020 | if (c == ',') | |
3021 | continue; | |
3022 | if (c == ')') | |
3023 | break; | |
3024 | return MATCH_ERROR; | |
3025 | } | |
8b7a967e TB |
3026 | } |
3027 | else | |
3028 | type = true; | |
3029 | ||
3030 | if (gfc_match_eos () != MATCH_YES) | |
3031 | return MATCH_ERROR; | |
3032 | ||
a6c63173 | 3033 | gfc_set_implicit_none (type, external, &cur_loc); |
8b7a967e TB |
3034 | |
3035 | return MATCH_YES; | |
e5ddaa24 TS |
3036 | } |
3037 | ||
3038 | ||
3039 | /* Match the letter range(s) of an IMPLICIT statement. */ | |
3040 | ||
3041 | static match | |
1107b970 | 3042 | match_implicit_range (void) |
e5ddaa24 | 3043 | { |
8fc541d3 FXC |
3044 | char c, c1, c2; |
3045 | int inner; | |
e5ddaa24 TS |
3046 | locus cur_loc; |
3047 | ||
3048 | cur_loc = gfc_current_locus; | |
3049 | ||
3050 | gfc_gobble_whitespace (); | |
8fc541d3 | 3051 | c = gfc_next_ascii_char (); |
e5ddaa24 TS |
3052 | if (c != '(') |
3053 | { | |
3054 | gfc_error ("Missing character range in IMPLICIT at %C"); | |
3055 | goto bad; | |
3056 | } | |
3057 | ||
3058 | inner = 1; | |
3059 | while (inner) | |
3060 | { | |
3061 | gfc_gobble_whitespace (); | |
8fc541d3 | 3062 | c1 = gfc_next_ascii_char (); |
e5ddaa24 TS |
3063 | if (!ISALPHA (c1)) |
3064 | goto bad; | |
3065 | ||
3066 | gfc_gobble_whitespace (); | |
8fc541d3 | 3067 | c = gfc_next_ascii_char (); |
e5ddaa24 TS |
3068 | |
3069 | switch (c) | |
3070 | { | |
3071 | case ')': | |
66e4ab31 | 3072 | inner = 0; /* Fall through. */ |
e5ddaa24 TS |
3073 | |
3074 | case ',': | |
3075 | c2 = c1; | |
3076 | break; | |
3077 | ||
3078 | case '-': | |
3079 | gfc_gobble_whitespace (); | |
8fc541d3 | 3080 | c2 = gfc_next_ascii_char (); |
e5ddaa24 TS |
3081 | if (!ISALPHA (c2)) |
3082 | goto bad; | |
3083 | ||
3084 | gfc_gobble_whitespace (); | |
8fc541d3 | 3085 | c = gfc_next_ascii_char (); |
e5ddaa24 TS |
3086 | |
3087 | if ((c != ',') && (c != ')')) | |
3088 | goto bad; | |
3089 | if (c == ')') | |
3090 | inner = 0; | |
3091 | ||
3092 | break; | |
3093 | ||
3094 | default: | |
3095 | goto bad; | |
3096 | } | |
3097 | ||
3098 | if (c1 > c2) | |
3099 | { | |
3100 | gfc_error ("Letters must be in alphabetic order in " | |
3101 | "IMPLICIT statement at %C"); | |
3102 | goto bad; | |
3103 | } | |
3104 | ||
3105 | /* See if we can add the newly matched range to the pending | |
636dff67 SK |
3106 | implicits from this IMPLICIT statement. We do not check for |
3107 | conflicts with whatever earlier IMPLICIT statements may have | |
3108 | set. This is done when we've successfully finished matching | |
3109 | the current one. */ | |
524af0d6 | 3110 | if (!gfc_add_new_implicit_range (c1, c2)) |
e5ddaa24 TS |
3111 | goto bad; |
3112 | } | |
3113 | ||
3114 | return MATCH_YES; | |
3115 | ||
3116 | bad: | |
3117 | gfc_syntax_error (ST_IMPLICIT); | |
3118 | ||
3119 | gfc_current_locus = cur_loc; | |
3120 | return MATCH_ERROR; | |
3121 | } | |
3122 | ||
3123 | ||
3124 | /* Match an IMPLICIT statement, storing the types for | |
3125 | gfc_set_implicit() if the statement is accepted by the parser. | |
3126 | There is a strange looking, but legal syntactic construction | |
3127 | possible. It looks like: | |
3128 | ||
3129 | IMPLICIT INTEGER (a-b) (c-d) | |
3130 | ||
3131 | This is legal if "a-b" is a constant expression that happens to | |
3132 | equal one of the legal kinds for integers. The real problem | |
3133 | happens with an implicit specification that looks like: | |
3134 | ||
3135 | IMPLICIT INTEGER (a-b) | |
3136 | ||
3137 | In this case, a typespec matcher that is "greedy" (as most of the | |
3138 | matchers are) gobbles the character range as a kindspec, leaving | |
3139 | nothing left. We therefore have to go a bit more slowly in the | |
3140 | matching process by inhibiting the kindspec checking during | |
3141 | typespec matching and checking for a kind later. */ | |
3142 | ||
3143 | match | |
3144 | gfc_match_implicit (void) | |
3145 | { | |
3146 | gfc_typespec ts; | |
3147 | locus cur_loc; | |
8fc541d3 | 3148 | char c; |
e5ddaa24 TS |
3149 | match m; |
3150 | ||
8b7a967e TB |
3151 | if (gfc_current_ns->seen_implicit_none) |
3152 | { | |
3153 | gfc_error ("IMPLICIT statement at %C following an IMPLICIT NONE (type) " | |
3154 | "statement"); | |
3155 | return MATCH_ERROR; | |
3156 | } | |
3157 | ||
44000dbb JD |
3158 | gfc_clear_ts (&ts); |
3159 | ||
e5ddaa24 TS |
3160 | /* We don't allow empty implicit statements. */ |
3161 | if (gfc_match_eos () == MATCH_YES) | |
3162 | { | |
3163 | gfc_error ("Empty IMPLICIT statement at %C"); | |
3164 | return MATCH_ERROR; | |
3165 | } | |
3166 | ||
e5ddaa24 TS |
3167 | do |
3168 | { | |
1107b970 PB |
3169 | /* First cleanup. */ |
3170 | gfc_clear_new_implicit (); | |
3171 | ||
e5ddaa24 | 3172 | /* A basic type is mandatory here. */ |
e74f1cc8 | 3173 | m = gfc_match_decl_type_spec (&ts, 1); |
e5ddaa24 TS |
3174 | if (m == MATCH_ERROR) |
3175 | goto error; | |
3176 | if (m == MATCH_NO) | |
3177 | goto syntax; | |
3178 | ||
3179 | cur_loc = gfc_current_locus; | |
1107b970 | 3180 | m = match_implicit_range (); |
e5ddaa24 TS |
3181 | |
3182 | if (m == MATCH_YES) | |
3183 | { | |
1107b970 | 3184 | /* We may have <TYPE> (<RANGE>). */ |
e5ddaa24 | 3185 | gfc_gobble_whitespace (); |
a6c63173 TB |
3186 | c = gfc_peek_ascii_char (); |
3187 | if (c == ',' || c == '\n' || c == ';' || c == '!') | |
1107b970 PB |
3188 | { |
3189 | /* Check for CHARACTER with no length parameter. */ | |
bc21d315 | 3190 | if (ts.type == BT_CHARACTER && !ts.u.cl) |
1107b970 | 3191 | { |
9d64df18 | 3192 | ts.kind = gfc_default_character_kind; |
b76e28c6 | 3193 | ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); |
b7e75771 JD |
3194 | ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, |
3195 | NULL, 1); | |
1107b970 PB |
3196 | } |
3197 | ||
3198 | /* Record the Successful match. */ | |
524af0d6 | 3199 | if (!gfc_merge_new_implicit (&ts)) |
1107b970 | 3200 | return MATCH_ERROR; |
a6c63173 TB |
3201 | if (c == ',') |
3202 | c = gfc_next_ascii_char (); | |
3203 | else if (gfc_match_eos () == MATCH_ERROR) | |
3204 | goto error; | |
1107b970 PB |
3205 | continue; |
3206 | } | |
e5ddaa24 TS |
3207 | |
3208 | gfc_current_locus = cur_loc; | |
3209 | } | |
3210 | ||
1107b970 PB |
3211 | /* Discard the (incorrectly) matched range. */ |
3212 | gfc_clear_new_implicit (); | |
3213 | ||
3214 | /* Last chance -- check <TYPE> <SELECTOR> (<RANGE>). */ | |
3215 | if (ts.type == BT_CHARACTER) | |
8234e5e0 | 3216 | m = gfc_match_char_spec (&ts); |
1107b970 | 3217 | else |
e5ddaa24 | 3218 | { |
e2d29968 | 3219 | m = gfc_match_kind_spec (&ts, false); |
e5ddaa24 | 3220 | if (m == MATCH_NO) |
1107b970 PB |
3221 | { |
3222 | m = gfc_match_old_kind_spec (&ts); | |
3223 | if (m == MATCH_ERROR) | |
3224 | goto error; | |
3225 | if (m == MATCH_NO) | |
3226 | goto syntax; | |
3227 | } | |
e5ddaa24 | 3228 | } |
1107b970 PB |
3229 | if (m == MATCH_ERROR) |
3230 | goto error; | |
e5ddaa24 | 3231 | |
1107b970 | 3232 | m = match_implicit_range (); |
e5ddaa24 TS |
3233 | if (m == MATCH_ERROR) |
3234 | goto error; | |
3235 | if (m == MATCH_NO) | |
3236 | goto syntax; | |
3237 | ||
3238 | gfc_gobble_whitespace (); | |
8fc541d3 | 3239 | c = gfc_next_ascii_char (); |
a6c63173 | 3240 | if (c != ',' && gfc_match_eos () != MATCH_YES) |
e5ddaa24 TS |
3241 | goto syntax; |
3242 | ||
524af0d6 | 3243 | if (!gfc_merge_new_implicit (&ts)) |
1107b970 | 3244 | return MATCH_ERROR; |
e5ddaa24 TS |
3245 | } |
3246 | while (c == ','); | |
3247 | ||
1107b970 | 3248 | return MATCH_YES; |
e5ddaa24 TS |
3249 | |
3250 | syntax: | |
3251 | gfc_syntax_error (ST_IMPLICIT); | |
3252 | ||
3253 | error: | |
3254 | return MATCH_ERROR; | |
3255 | } | |
3256 | ||
66e4ab31 | 3257 | |
8998be20 TB |
3258 | match |
3259 | gfc_match_import (void) | |
3260 | { | |
3261 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
3262 | match m; | |
3263 | gfc_symbol *sym; | |
3264 | gfc_symtree *st; | |
3265 | ||
66e4ab31 SK |
3266 | if (gfc_current_ns->proc_name == NULL |
3267 | || gfc_current_ns->proc_name->attr.if_source != IFSRC_IFBODY) | |
8998be20 TB |
3268 | { |
3269 | gfc_error ("IMPORT statement at %C only permitted in " | |
3270 | "an INTERFACE body"); | |
3271 | return MATCH_ERROR; | |
3272 | } | |
3273 | ||
524af0d6 | 3274 | if (!gfc_notify_std (GFC_STD_F2003, "IMPORT statement at %C")) |
8998be20 TB |
3275 | return MATCH_ERROR; |
3276 | ||
3277 | if (gfc_match_eos () == MATCH_YES) | |
3278 | { | |
3279 | /* All host variables should be imported. */ | |
3280 | gfc_current_ns->has_import_set = 1; | |
3281 | return MATCH_YES; | |
3282 | } | |
3283 | ||
3284 | if (gfc_match (" ::") == MATCH_YES) | |
3285 | { | |
3286 | if (gfc_match_eos () == MATCH_YES) | |
636dff67 SK |
3287 | { |
3288 | gfc_error ("Expecting list of named entities at %C"); | |
3289 | return MATCH_ERROR; | |
3290 | } | |
8998be20 TB |
3291 | } |
3292 | ||
3293 | for(;;) | |
3294 | { | |
2e8d9212 | 3295 | sym = NULL; |
8998be20 TB |
3296 | m = gfc_match (" %n", name); |
3297 | switch (m) | |
3298 | { | |
3299 | case MATCH_YES: | |
36d3fb4c | 3300 | if (gfc_current_ns->parent != NULL |
66e4ab31 | 3301 | && gfc_find_symbol (name, gfc_current_ns->parent, 1, &sym)) |
36d3fb4c | 3302 | { |
c4100eae | 3303 | gfc_error ("Type name %qs at %C is ambiguous", name); |
36d3fb4c PT |
3304 | return MATCH_ERROR; |
3305 | } | |
4e2cf5f5 | 3306 | else if (!sym && gfc_current_ns->proc_name->ns->parent != NULL |
66e4ab31 SK |
3307 | && gfc_find_symbol (name, |
3308 | gfc_current_ns->proc_name->ns->parent, | |
3309 | 1, &sym)) | |
636dff67 | 3310 | { |
c4100eae | 3311 | gfc_error ("Type name %qs at %C is ambiguous", name); |
636dff67 SK |
3312 | return MATCH_ERROR; |
3313 | } | |
3314 | ||
3315 | if (sym == NULL) | |
3316 | { | |
c4100eae | 3317 | gfc_error ("Cannot IMPORT %qs from host scoping unit " |
636dff67 SK |
3318 | "at %C - does not exist.", name); |
3319 | return MATCH_ERROR; | |
3320 | } | |
3321 | ||
dd8b9dde | 3322 | if (gfc_find_symtree (gfc_current_ns->sym_root, name)) |
636dff67 | 3323 | { |
db30e21c | 3324 | gfc_warning (0, "%qs is already IMPORTed from host scoping unit " |
48749dbc | 3325 | "at %C", name); |
636dff67 SK |
3326 | goto next_item; |
3327 | } | |
3328 | ||
dd8b9dde | 3329 | st = gfc_new_symtree (&gfc_current_ns->sym_root, name); |
636dff67 SK |
3330 | st->n.sym = sym; |
3331 | sym->refs++; | |
5a8af0b4 | 3332 | sym->attr.imported = 1; |
8998be20 | 3333 | |
c3f34952 TB |
3334 | if (sym->attr.generic && (sym = gfc_find_dt_in_generic (sym))) |
3335 | { | |
3336 | /* The actual derived type is stored in a symtree with the first | |
eea58adb | 3337 | letter of the name capitalized; the symtree with the all |
1cc0e193 | 3338 | lower-case name contains the associated generic function. */ |
c3f34952 TB |
3339 | st = gfc_new_symtree (&gfc_current_ns->sym_root, |
3340 | gfc_get_string ("%c%s", | |
dd8b9dde TB |
3341 | (char) TOUPPER ((unsigned char) name[0]), |
3342 | &name[1])); | |
c3f34952 TB |
3343 | st->n.sym = sym; |
3344 | sym->refs++; | |
3345 | sym->attr.imported = 1; | |
3346 | } | |
3347 | ||
8998be20 TB |
3348 | goto next_item; |
3349 | ||
3350 | case MATCH_NO: | |
3351 | break; | |
3352 | ||
3353 | case MATCH_ERROR: | |
3354 | return MATCH_ERROR; | |
3355 | } | |
3356 | ||
3357 | next_item: | |
3358 | if (gfc_match_eos () == MATCH_YES) | |
3359 | break; | |
3360 | if (gfc_match_char (',') != MATCH_YES) | |
3361 | goto syntax; | |
3362 | } | |
3363 | ||
3364 | return MATCH_YES; | |
3365 | ||
3366 | syntax: | |
3367 | gfc_error ("Syntax error in IMPORT statement at %C"); | |
3368 | return MATCH_ERROR; | |
3369 | } | |
e5ddaa24 | 3370 | |
66e4ab31 | 3371 | |
f2449db4 RS |
3372 | /* A minimal implementation of gfc_match without whitespace, escape |
3373 | characters or variable arguments. Returns true if the next | |
3374 | characters match the TARGET template exactly. */ | |
3375 | ||
3376 | static bool | |
3377 | match_string_p (const char *target) | |
3378 | { | |
3379 | const char *p; | |
3380 | ||
3381 | for (p = target; *p; p++) | |
8fc541d3 | 3382 | if ((char) gfc_next_ascii_char () != *p) |
f2449db4 RS |
3383 | return false; |
3384 | return true; | |
3385 | } | |
3386 | ||
6de9cd9a DN |
3387 | /* Matches an attribute specification including array specs. If |
3388 | successful, leaves the variables current_attr and current_as | |
3389 | holding the specification. Also sets the colon_seen variable for | |
3390 | later use by matchers associated with initializations. | |
3391 | ||
3392 | This subroutine is a little tricky in the sense that we don't know | |
3393 | if we really have an attr-spec until we hit the double colon. | |
3394 | Until that time, we can only return MATCH_NO. This forces us to | |
3395 | check for duplicate specification at this level. */ | |
3396 | ||
3397 | static match | |
3398 | match_attr_spec (void) | |
3399 | { | |
6de9cd9a | 3400 | /* Modifiers that can exist in a type statement. */ |
d75d9546 | 3401 | enum |
6de9cd9a DN |
3402 | { GFC_DECL_BEGIN = 0, |
3403 | DECL_ALLOCATABLE = GFC_DECL_BEGIN, DECL_DIMENSION, DECL_EXTERNAL, | |
3404 | DECL_IN, DECL_OUT, DECL_INOUT, DECL_INTRINSIC, DECL_OPTIONAL, | |
ee7e677f TB |
3405 | DECL_PARAMETER, DECL_POINTER, DECL_PROTECTED, DECL_PRIVATE, |
3406 | DECL_PUBLIC, DECL_SAVE, DECL_TARGET, DECL_VALUE, DECL_VOLATILE, | |
fe4e525c TB |
3407 | DECL_IS_BIND_C, DECL_CODIMENSION, DECL_ASYNCHRONOUS, DECL_CONTIGUOUS, |
3408 | DECL_NONE, GFC_DECL_END /* Sentinel */ | |
d75d9546 | 3409 | }; |
6de9cd9a DN |
3410 | |
3411 | /* GFC_DECL_END is the sentinel, index starts at 0. */ | |
3412 | #define NUM_DECL GFC_DECL_END | |
3413 | ||
6de9cd9a DN |
3414 | locus start, seen_at[NUM_DECL]; |
3415 | int seen[NUM_DECL]; | |
09639a83 | 3416 | unsigned int d; |
6de9cd9a DN |
3417 | const char *attr; |
3418 | match m; | |
524af0d6 | 3419 | bool t; |
6de9cd9a DN |
3420 | |
3421 | gfc_clear_attr (¤t_attr); | |
63645982 | 3422 | start = gfc_current_locus; |
6de9cd9a DN |
3423 | |
3424 | current_as = NULL; | |
3425 | colon_seen = 0; | |
3426 | ||
3427 | /* See if we get all of the keywords up to the final double colon. */ | |
3428 | for (d = GFC_DECL_BEGIN; d != GFC_DECL_END; d++) | |
3429 | seen[d] = 0; | |
3430 | ||
3431 | for (;;) | |
3432 | { | |
8fc541d3 | 3433 | char ch; |
a8b3b0b6 | 3434 | |
f2449db4 RS |
3435 | d = DECL_NONE; |
3436 | gfc_gobble_whitespace (); | |
3437 | ||
8fc541d3 | 3438 | ch = gfc_next_ascii_char (); |
f2449db4 RS |
3439 | if (ch == ':') |
3440 | { | |
3441 | /* This is the successful exit condition for the loop. */ | |
8fc541d3 | 3442 | if (gfc_next_ascii_char () == ':') |
f2449db4 RS |
3443 | break; |
3444 | } | |
3445 | else if (ch == ',') | |
a8b3b0b6 | 3446 | { |
a8b3b0b6 | 3447 | gfc_gobble_whitespace (); |
8fc541d3 | 3448 | switch (gfc_peek_ascii_char ()) |
a8b3b0b6 | 3449 | { |
f2449db4 | 3450 | case 'a': |
1eee5628 TB |
3451 | gfc_next_ascii_char (); |
3452 | switch (gfc_next_ascii_char ()) | |
3453 | { | |
3454 | case 'l': | |
3455 | if (match_string_p ("locatable")) | |
3456 | { | |
3457 | /* Matched "allocatable". */ | |
3458 | d = DECL_ALLOCATABLE; | |
3459 | } | |
3460 | break; | |
3461 | ||
3462 | case 's': | |
3463 | if (match_string_p ("ynchronous")) | |
3464 | { | |
3465 | /* Matched "asynchronous". */ | |
3466 | d = DECL_ASYNCHRONOUS; | |
3467 | } | |
3468 | break; | |
3469 | } | |
fe4e525c | 3470 | break; |
f2449db4 RS |
3471 | |
3472 | case 'b': | |
a8b3b0b6 | 3473 | /* Try and match the bind(c). */ |
1eabf70a | 3474 | m = gfc_match_bind_c (NULL, true); |
129d15a3 | 3475 | if (m == MATCH_YES) |
a8b3b0b6 | 3476 | d = DECL_IS_BIND_C; |
129d15a3 JW |
3477 | else if (m == MATCH_ERROR) |
3478 | goto cleanup; | |
f2449db4 RS |
3479 | break; |
3480 | ||
be59db2d | 3481 | case 'c': |
fe4e525c TB |
3482 | gfc_next_ascii_char (); |
3483 | if ('o' != gfc_next_ascii_char ()) | |
3484 | break; | |
3485 | switch (gfc_next_ascii_char ()) | |
3486 | { | |
3487 | case 'd': | |
3488 | if (match_string_p ("imension")) | |
3489 | { | |
3490 | d = DECL_CODIMENSION; | |
3491 | break; | |
3492 | } | |
3493 | case 'n': | |
3494 | if (match_string_p ("tiguous")) | |
3495 | { | |
3496 | d = DECL_CONTIGUOUS; | |
3497 | break; | |
3498 | } | |
3499 | } | |
be59db2d TB |
3500 | break; |
3501 | ||
f2449db4 RS |
3502 | case 'd': |
3503 | if (match_string_p ("dimension")) | |
3504 | d = DECL_DIMENSION; | |
3505 | break; | |
3506 | ||
3507 | case 'e': | |
3508 | if (match_string_p ("external")) | |
3509 | d = DECL_EXTERNAL; | |
3510 | break; | |
3511 | ||
3512 | case 'i': | |
3513 | if (match_string_p ("int")) | |
3514 | { | |
8fc541d3 | 3515 | ch = gfc_next_ascii_char (); |
f2449db4 RS |
3516 | if (ch == 'e') |
3517 | { | |
3518 | if (match_string_p ("nt")) | |
3519 | { | |
3520 | /* Matched "intent". */ | |
3521 | /* TODO: Call match_intent_spec from here. */ | |
3522 | if (gfc_match (" ( in out )") == MATCH_YES) | |
3523 | d = DECL_INOUT; | |
3524 | else if (gfc_match (" ( in )") == MATCH_YES) | |
3525 | d = DECL_IN; | |
3526 | else if (gfc_match (" ( out )") == MATCH_YES) | |
3527 | d = DECL_OUT; | |
3528 | } | |
3529 | } | |
3530 | else if (ch == 'r') | |
3531 | { | |
3532 | if (match_string_p ("insic")) | |
3533 | { | |
3534 | /* Matched "intrinsic". */ | |
3535 | d = DECL_INTRINSIC; | |
3536 | } | |
3537 | } | |
3538 | } | |
3539 | break; | |
3540 | ||
3541 | case 'o': | |
3542 | if (match_string_p ("optional")) | |
3543 | d = DECL_OPTIONAL; | |
3544 | break; | |
3545 | ||
3546 | case 'p': | |
8fc541d3 FXC |
3547 | gfc_next_ascii_char (); |
3548 | switch (gfc_next_ascii_char ()) | |
f2449db4 RS |
3549 | { |
3550 | case 'a': | |
3551 | if (match_string_p ("rameter")) | |
3552 | { | |
3553 | /* Matched "parameter". */ | |
3554 | d = DECL_PARAMETER; | |
3555 | } | |
3556 | break; | |
3557 | ||
3558 | case 'o': | |
3559 | if (match_string_p ("inter")) | |
3560 | { | |
3561 | /* Matched "pointer". */ | |
3562 | d = DECL_POINTER; | |
3563 | } | |
3564 | break; | |
3565 | ||
3566 | case 'r': | |
8fc541d3 | 3567 | ch = gfc_next_ascii_char (); |
f2449db4 RS |
3568 | if (ch == 'i') |
3569 | { | |
3570 | if (match_string_p ("vate")) | |
3571 | { | |
3572 | /* Matched "private". */ | |
3573 | d = DECL_PRIVATE; | |
3574 | } | |
3575 | } | |
3576 | else if (ch == 'o') | |
3577 | { | |
3578 | if (match_string_p ("tected")) | |
3579 | { | |
3580 | /* Matched "protected". */ | |
3581 | d = DECL_PROTECTED; | |
3582 | } | |
3583 | } | |
3584 | break; | |
3585 | ||
3586 | case 'u': | |
3587 | if (match_string_p ("blic")) | |
3588 | { | |
3589 | /* Matched "public". */ | |
3590 | d = DECL_PUBLIC; | |
3591 | } | |
3592 | break; | |
3593 | } | |
3594 | break; | |
3595 | ||
3596 | case 's': | |
3597 | if (match_string_p ("save")) | |
3598 | d = DECL_SAVE; | |
3599 | break; | |
3600 | ||
3601 | case 't': | |
3602 | if (match_string_p ("target")) | |
3603 | d = DECL_TARGET; | |
3604 | break; | |
3605 | ||
3606 | case 'v': | |
8fc541d3 FXC |
3607 | gfc_next_ascii_char (); |
3608 | ch = gfc_next_ascii_char (); | |
f2449db4 RS |
3609 | if (ch == 'a') |
3610 | { | |
3611 | if (match_string_p ("lue")) | |
3612 | { | |
3613 | /* Matched "value". */ | |
3614 | d = DECL_VALUE; | |
3615 | } | |
3616 | } | |
3617 | else if (ch == 'o') | |
3618 | { | |
3619 | if (match_string_p ("latile")) | |
3620 | { | |
3621 | /* Matched "volatile". */ | |
3622 | d = DECL_VOLATILE; | |
3623 | } | |
3624 | } | |
3625 | break; | |
a8b3b0b6 CR |
3626 | } |
3627 | } | |
d468bcdb | 3628 | |
f2449db4 RS |
3629 | /* No double colon and no recognizable decl_type, so assume that |
3630 | we've been looking at something else the whole time. */ | |
3631 | if (d == DECL_NONE) | |
3632 | { | |
3633 | m = MATCH_NO; | |
3634 | goto cleanup; | |
3635 | } | |
d51347f9 | 3636 | |
acb388a0 JD |
3637 | /* Check to make sure any parens are paired up correctly. */ |
3638 | if (gfc_match_parens () == MATCH_ERROR) | |
3639 | { | |
3640 | m = MATCH_ERROR; | |
3641 | goto cleanup; | |
3642 | } | |
3643 | ||
6de9cd9a | 3644 | seen[d]++; |
63645982 | 3645 | seen_at[d] = gfc_current_locus; |
6de9cd9a | 3646 | |
d3a9eea2 | 3647 | if (d == DECL_DIMENSION || d == DECL_CODIMENSION) |
6de9cd9a | 3648 | { |
d3a9eea2 | 3649 | gfc_array_spec *as = NULL; |
6de9cd9a | 3650 | |
d3a9eea2 TB |
3651 | m = gfc_match_array_spec (&as, d == DECL_DIMENSION, |
3652 | d == DECL_CODIMENSION); | |
3653 | ||
3654 | if (current_as == NULL) | |
3655 | current_as = as; | |
3656 | else if (m == MATCH_YES) | |
6de9cd9a | 3657 | { |
524af0d6 | 3658 | if (!merge_array_spec (as, current_as, false)) |
63fbf586 | 3659 | m = MATCH_ERROR; |
cede9502 | 3660 | free (as); |
6de9cd9a DN |
3661 | } |
3662 | ||
be59db2d TB |
3663 | if (m == MATCH_NO) |
3664 | { | |
d3a9eea2 TB |
3665 | if (d == DECL_CODIMENSION) |
3666 | gfc_error ("Missing codimension specification at %C"); | |
3667 | else | |
3668 | gfc_error ("Missing dimension specification at %C"); | |
be59db2d TB |
3669 | m = MATCH_ERROR; |
3670 | } | |
3671 | ||
3672 | if (m == MATCH_ERROR) | |
3673 | goto cleanup; | |
3674 | } | |
6de9cd9a DN |
3675 | } |
3676 | ||
6de9cd9a DN |
3677 | /* Since we've seen a double colon, we have to be looking at an |
3678 | attr-spec. This means that we can now issue errors. */ | |
3679 | for (d = GFC_DECL_BEGIN; d != GFC_DECL_END; d++) | |
3680 | if (seen[d] > 1) | |
3681 | { | |
3682 | switch (d) | |
3683 | { | |
3684 | case DECL_ALLOCATABLE: | |
3685 | attr = "ALLOCATABLE"; | |
3686 | break; | |
1eee5628 TB |
3687 | case DECL_ASYNCHRONOUS: |
3688 | attr = "ASYNCHRONOUS"; | |
3689 | break; | |
be59db2d TB |
3690 | case DECL_CODIMENSION: |
3691 | attr = "CODIMENSION"; | |
3692 | break; | |
fe4e525c TB |
3693 | case DECL_CONTIGUOUS: |
3694 | attr = "CONTIGUOUS"; | |
3695 | break; | |
6de9cd9a DN |
3696 | case DECL_DIMENSION: |
3697 | attr = "DIMENSION"; | |
3698 | break; | |
3699 | case DECL_EXTERNAL: | |
3700 | attr = "EXTERNAL"; | |
3701 | break; | |
3702 | case DECL_IN: | |
3703 | attr = "INTENT (IN)"; | |
3704 | break; | |
3705 | case DECL_OUT: | |
3706 | attr = "INTENT (OUT)"; | |
3707 | break; | |
3708 | case DECL_INOUT: | |
3709 | attr = "INTENT (IN OUT)"; | |
3710 | break; | |
3711 | case DECL_INTRINSIC: | |
3712 | attr = "INTRINSIC"; | |
3713 | break; | |
3714 | case DECL_OPTIONAL: | |
3715 | attr = "OPTIONAL"; | |
3716 | break; | |
3717 | case DECL_PARAMETER: | |
3718 | attr = "PARAMETER"; | |
3719 | break; | |
3720 | case DECL_POINTER: | |
3721 | attr = "POINTER"; | |
3722 | break; | |
ee7e677f TB |
3723 | case DECL_PROTECTED: |
3724 | attr = "PROTECTED"; | |
3725 | break; | |
6de9cd9a DN |
3726 | case DECL_PRIVATE: |
3727 | attr = "PRIVATE"; | |
3728 | break; | |
3729 | case DECL_PUBLIC: | |
3730 | attr = "PUBLIC"; | |
3731 | break; | |
3732 | case DECL_SAVE: | |
3733 | attr = "SAVE"; | |
3734 | break; | |
3735 | case DECL_TARGET: | |
3736 | attr = "TARGET"; | |
3737 | break; | |
a8b3b0b6 CR |
3738 | case DECL_IS_BIND_C: |
3739 | attr = "IS_BIND_C"; | |
3740 | break; | |
3741 | case DECL_VALUE: | |
3742 | attr = "VALUE"; | |
3743 | break; | |
775e6c3a TB |
3744 | case DECL_VOLATILE: |
3745 | attr = "VOLATILE"; | |
3746 | break; | |
6de9cd9a | 3747 | default: |
66e4ab31 | 3748 | attr = NULL; /* This shouldn't happen. */ |
6de9cd9a DN |
3749 | } |
3750 | ||
3751 | gfc_error ("Duplicate %s attribute at %L", attr, &seen_at[d]); | |
3752 | m = MATCH_ERROR; | |
3753 | goto cleanup; | |
3754 | } | |
3755 | ||
3756 | /* Now that we've dealt with duplicate attributes, add the attributes | |
3757 | to the current attribute. */ | |
3758 | for (d = GFC_DECL_BEGIN; d != GFC_DECL_END; d++) | |
3759 | { | |
3760 | if (seen[d] == 0) | |
3761 | continue; | |
3762 | ||
3763 | if (gfc_current_state () == COMP_DERIVED | |
be59db2d TB |
3764 | && d != DECL_DIMENSION && d != DECL_CODIMENSION |
3765 | && d != DECL_POINTER && d != DECL_PRIVATE | |
fe4e525c | 3766 | && d != DECL_PUBLIC && d != DECL_CONTIGUOUS && d != DECL_NONE) |
6de9cd9a | 3767 | { |
5046aff5 PT |
3768 | if (d == DECL_ALLOCATABLE) |
3769 | { | |
524af0d6 JB |
3770 | if (!gfc_notify_std (GFC_STD_F2003, "ALLOCATABLE " |
3771 | "attribute at %C in a TYPE definition")) | |
5046aff5 PT |
3772 | { |
3773 | m = MATCH_ERROR; | |
3774 | goto cleanup; | |
3775 | } | |
636dff67 SK |
3776 | } |
3777 | else | |
5046aff5 PT |
3778 | { |
3779 | gfc_error ("Attribute at %L is not allowed in a TYPE definition", | |
d51347f9 | 3780 | &seen_at[d]); |
5046aff5 PT |
3781 | m = MATCH_ERROR; |
3782 | goto cleanup; | |
3783 | } | |
6de9cd9a DN |
3784 | } |
3785 | ||
4213f93b | 3786 | if ((d == DECL_PRIVATE || d == DECL_PUBLIC) |
636dff67 | 3787 | && gfc_current_state () != COMP_MODULE) |
4213f93b PT |
3788 | { |
3789 | if (d == DECL_PRIVATE) | |
3790 | attr = "PRIVATE"; | |
3791 | else | |
3792 | attr = "PUBLIC"; | |
d51347f9 TB |
3793 | if (gfc_current_state () == COMP_DERIVED |
3794 | && gfc_state_stack->previous | |
3795 | && gfc_state_stack->previous->state == COMP_MODULE) | |
3796 | { | |
524af0d6 JB |
3797 | if (!gfc_notify_std (GFC_STD_F2003, "Attribute %s " |
3798 | "at %L in a TYPE definition", attr, | |
3799 | &seen_at[d])) | |
d51347f9 TB |
3800 | { |
3801 | m = MATCH_ERROR; | |
3802 | goto cleanup; | |
3803 | } | |
3804 | } | |
3805 | else | |
3806 | { | |
3807 | gfc_error ("%s attribute at %L is not allowed outside of the " | |
3808 | "specification part of a module", attr, &seen_at[d]); | |
3809 | m = MATCH_ERROR; | |
3810 | goto cleanup; | |
3811 | } | |
4213f93b PT |
3812 | } |
3813 | ||
6de9cd9a DN |
3814 | switch (d) |
3815 | { | |
3816 | case DECL_ALLOCATABLE: | |
3817 | t = gfc_add_allocatable (¤t_attr, &seen_at[d]); | |
3818 | break; | |
3819 | ||
1eee5628 | 3820 | case DECL_ASYNCHRONOUS: |
524af0d6 JB |
3821 | if (!gfc_notify_std (GFC_STD_F2003, "ASYNCHRONOUS attribute at %C")) |
3822 | t = false; | |
1eee5628 TB |
3823 | else |
3824 | t = gfc_add_asynchronous (¤t_attr, NULL, &seen_at[d]); | |
3825 | break; | |
3826 | ||
be59db2d TB |
3827 | case DECL_CODIMENSION: |
3828 | t = gfc_add_codimension (¤t_attr, NULL, &seen_at[d]); | |
3829 | break; | |
3830 | ||
fe4e525c | 3831 | case DECL_CONTIGUOUS: |
524af0d6 JB |
3832 | if (!gfc_notify_std (GFC_STD_F2008, "CONTIGUOUS attribute at %C")) |
3833 | t = false; | |
fe4e525c TB |
3834 | else |
3835 | t = gfc_add_contiguous (¤t_attr, NULL, &seen_at[d]); | |
3836 | break; | |
3837 | ||
6de9cd9a | 3838 | case DECL_DIMENSION: |
231b2fcc | 3839 | t = gfc_add_dimension (¤t_attr, NULL, &seen_at[d]); |
6de9cd9a DN |
3840 | break; |
3841 | ||
3842 | case DECL_EXTERNAL: | |
3843 | t = gfc_add_external (¤t_attr, &seen_at[d]); | |
3844 | break; | |
3845 | ||
3846 | case DECL_IN: | |
3847 | t = gfc_add_intent (¤t_attr, INTENT_IN, &seen_at[d]); | |
3848 | break; | |
3849 | ||
3850 | case DECL_OUT: | |
3851 | t = gfc_add_intent (¤t_attr, INTENT_OUT, &seen_at[d]); | |
3852 | break; | |
3853 | ||
3854 | case DECL_INOUT: | |
3855 | t = gfc_add_intent (¤t_attr, INTENT_INOUT, &seen_at[d]); | |
3856 | break; | |
3857 | ||
3858 | case DECL_INTRINSIC: | |
3859 | t = gfc_add_intrinsic (¤t_attr, &seen_at[d]); | |
3860 | break; | |
3861 | ||
3862 | case DECL_OPTIONAL: | |
3863 | t = gfc_add_optional (¤t_attr, &seen_at[d]); | |
3864 | break; | |
3865 | ||
3866 | case DECL_PARAMETER: | |
231b2fcc | 3867 | t = gfc_add_flavor (¤t_attr, FL_PARAMETER, NULL, &seen_at[d]); |
6de9cd9a DN |
3868 | break; |
3869 | ||
3870 | case DECL_POINTER: | |
3871 | t = gfc_add_pointer (¤t_attr, &seen_at[d]); | |
3872 | break; | |
3873 | ||
ee7e677f TB |
3874 | case DECL_PROTECTED: |
3875 | if (gfc_current_ns->proc_name->attr.flavor != FL_MODULE) | |
3876 | { | |
3877 | gfc_error ("PROTECTED at %C only allowed in specification " | |
3878 | "part of a module"); | |
524af0d6 | 3879 | t = false; |
ee7e677f TB |
3880 | break; |
3881 | } | |
3882 | ||
524af0d6 JB |
3883 | if (!gfc_notify_std (GFC_STD_F2003, "PROTECTED attribute at %C")) |
3884 | t = false; | |
ee7e677f TB |
3885 | else |
3886 | t = gfc_add_protected (¤t_attr, NULL, &seen_at[d]); | |
3887 | break; | |
3888 | ||
6de9cd9a | 3889 | case DECL_PRIVATE: |
231b2fcc TS |
3890 | t = gfc_add_access (¤t_attr, ACCESS_PRIVATE, NULL, |
3891 | &seen_at[d]); | |
6de9cd9a DN |
3892 | break; |
3893 | ||
3894 | case DECL_PUBLIC: | |
231b2fcc TS |
3895 | t = gfc_add_access (¤t_attr, ACCESS_PUBLIC, NULL, |
3896 | &seen_at[d]); | |
6de9cd9a DN |
3897 | break; |
3898 | ||
3899 | case DECL_SAVE: | |
80f95228 | 3900 | t = gfc_add_save (¤t_attr, SAVE_EXPLICIT, NULL, &seen_at[d]); |
6de9cd9a DN |
3901 | break; |
3902 | ||
3903 | case DECL_TARGET: | |
3904 | t = gfc_add_target (¤t_attr, &seen_at[d]); | |
3905 | break; | |
3906 | ||
a8b3b0b6 CR |
3907 | case DECL_IS_BIND_C: |
3908 | t = gfc_add_is_bind_c(¤t_attr, NULL, &seen_at[d], 0); | |
3909 | break; | |
f5acf0f2 | 3910 | |
06469efd | 3911 | case DECL_VALUE: |
524af0d6 JB |
3912 | if (!gfc_notify_std (GFC_STD_F2003, "VALUE attribute at %C")) |
3913 | t = false; | |
06469efd PT |
3914 | else |
3915 | t = gfc_add_value (¤t_attr, NULL, &seen_at[d]); | |
3916 | break; | |
3917 | ||
775e6c3a | 3918 | case DECL_VOLATILE: |
524af0d6 JB |
3919 | if (!gfc_notify_std (GFC_STD_F2003, "VOLATILE attribute at %C")) |
3920 | t = false; | |
775e6c3a TB |
3921 | else |
3922 | t = gfc_add_volatile (¤t_attr, NULL, &seen_at[d]); | |
3923 | break; | |
3924 | ||
6de9cd9a DN |
3925 | default: |
3926 | gfc_internal_error ("match_attr_spec(): Bad attribute"); | |
3927 | } | |
3928 | ||
524af0d6 | 3929 | if (!t) |
6de9cd9a DN |
3930 | { |
3931 | m = MATCH_ERROR; | |
3932 | goto cleanup; | |
3933 | } | |
3934 | } | |
3935 | ||
dab2cbf8 JW |
3936 | /* Since Fortran 2008 module variables implicitly have the SAVE attribute. */ |
3937 | if (gfc_current_state () == COMP_MODULE && !current_attr.save | |
3938 | && (gfc_option.allow_std & GFC_STD_F2008) != 0) | |
80f95228 JW |
3939 | current_attr.save = SAVE_IMPLICIT; |
3940 | ||
6de9cd9a DN |
3941 | colon_seen = 1; |
3942 | return MATCH_YES; | |
3943 | ||
3944 | cleanup: | |
63645982 | 3945 | gfc_current_locus = start; |
6de9cd9a DN |
3946 | gfc_free_array_spec (current_as); |
3947 | current_as = NULL; | |
3948 | return m; | |
3949 | } | |
3950 | ||
3951 | ||
a8b3b0b6 CR |
3952 | /* Set the binding label, dest_label, either with the binding label |
3953 | stored in the given gfc_typespec, ts, or if none was provided, it | |
3954 | will be the symbol name in all lower case, as required by the draft | |
3955 | (J3/04-007, section 15.4.1). If a binding label was given and | |
3956 | there is more than one argument (num_idents), it is an error. */ | |
3957 | ||
524af0d6 | 3958 | static bool |
f5acf0f2 | 3959 | set_binding_label (const char **dest_label, const char *sym_name, |
9975a30b | 3960 | int num_idents) |
a8b3b0b6 | 3961 | { |
ad4a2f64 | 3962 | if (num_idents > 1 && has_name_equals) |
a8b3b0b6 | 3963 | { |
ad4a2f64 TB |
3964 | gfc_error ("Multiple identifiers provided with " |
3965 | "single NAME= specifier at %C"); | |
524af0d6 | 3966 | return false; |
ad4a2f64 | 3967 | } |
a8b3b0b6 | 3968 | |
62603fae | 3969 | if (curr_binding_label) |
eea58adb | 3970 | /* Binding label given; store in temp holder till have sym. */ |
62603fae | 3971 | *dest_label = curr_binding_label; |
a8b3b0b6 CR |
3972 | else |
3973 | { | |
3974 | /* No binding label given, and the NAME= specifier did not exist, | |
3975 | which means there was no NAME="". */ | |
3976 | if (sym_name != NULL && has_name_equals == 0) | |
62603fae | 3977 | *dest_label = IDENTIFIER_POINTER (get_identifier (sym_name)); |
a8b3b0b6 | 3978 | } |
f5acf0f2 | 3979 | |
524af0d6 | 3980 | return true; |
a8b3b0b6 CR |
3981 | } |
3982 | ||
3983 | ||
3984 | /* Set the status of the given common block as being BIND(C) or not, | |
3985 | depending on the given parameter, is_bind_c. */ | |
3986 | ||
3987 | void | |
3988 | set_com_block_bind_c (gfc_common_head *com_block, int is_bind_c) | |
3989 | { | |
3990 | com_block->is_bind_c = is_bind_c; | |
3991 | return; | |
3992 | } | |
3993 | ||
3994 | ||
3995 | /* Verify that the given gfc_typespec is for a C interoperable type. */ | |
3996 | ||
524af0d6 | 3997 | bool |
00820a2a | 3998 | gfc_verify_c_interop (gfc_typespec *ts) |
a8b3b0b6 | 3999 | { |
bc21d315 | 4000 | if (ts->type == BT_DERIVED && ts->u.derived != NULL) |
ba3721c1 | 4001 | return (ts->u.derived->ts.is_c_interop || ts->u.derived->attr.is_bind_c) |
524af0d6 | 4002 | ? true : false; |
00820a2a | 4003 | else if (ts->type == BT_CLASS) |
524af0d6 | 4004 | return false; |
45a69325 | 4005 | else if (ts->is_c_interop != 1 && ts->type != BT_ASSUMED) |
524af0d6 | 4006 | return false; |
45a69325 | 4007 | |
524af0d6 | 4008 | return true; |
a8b3b0b6 CR |
4009 | } |
4010 | ||
4011 | ||
4012 | /* Verify that the variables of a given common block, which has been | |
4013 | defined with the attribute specifier bind(c), to be of a C | |
4014 | interoperable type. Errors will be reported here, if | |
4015 | encountered. */ | |
4016 | ||
524af0d6 | 4017 | bool |
a8b3b0b6 CR |
4018 | verify_com_block_vars_c_interop (gfc_common_head *com_block) |
4019 | { | |
4020 | gfc_symbol *curr_sym = NULL; | |
524af0d6 | 4021 | bool retval = true; |
a8b3b0b6 CR |
4022 | |
4023 | curr_sym = com_block->head; | |
f5acf0f2 | 4024 | |
a8b3b0b6 CR |
4025 | /* Make sure we have at least one symbol. */ |
4026 | if (curr_sym == NULL) | |
4027 | return retval; | |
4028 | ||
4029 | /* Here we know we have a symbol, so we'll execute this loop | |
4030 | at least once. */ | |
4031 | do | |
4032 | { | |
4033 | /* The second to last param, 1, says this is in a common block. */ | |
4034 | retval = verify_bind_c_sym (curr_sym, &(curr_sym->ts), 1, com_block); | |
4035 | curr_sym = curr_sym->common_next; | |
f5acf0f2 | 4036 | } while (curr_sym != NULL); |
a8b3b0b6 CR |
4037 | |
4038 | return retval; | |
4039 | } | |
4040 | ||
4041 | ||
4042 | /* Verify that a given BIND(C) symbol is C interoperable. If it is not, | |
4043 | an appropriate error message is reported. */ | |
4044 | ||
524af0d6 | 4045 | bool |
a8b3b0b6 CR |
4046 | verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts, |
4047 | int is_in_common, gfc_common_head *com_block) | |
4048 | { | |
8327f9c2 | 4049 | bool bind_c_function = false; |
524af0d6 | 4050 | bool retval = true; |
d8fa96e0 | 4051 | |
8327f9c2 TB |
4052 | if (tmp_sym->attr.function && tmp_sym->attr.is_bind_c) |
4053 | bind_c_function = true; | |
4054 | ||
d8fa96e0 CR |
4055 | if (tmp_sym->attr.function && tmp_sym->result != NULL) |
4056 | { | |
4057 | tmp_sym = tmp_sym->result; | |
4058 | /* Make sure it wasn't an implicitly typed result. */ | |
4daa149b | 4059 | if (tmp_sym->attr.implicit_type && warn_c_binding_type) |
d8fa96e0 | 4060 | { |
48749dbc MLI |
4061 | gfc_warning (OPT_Wc_binding_type, |
4062 | "Implicitly declared BIND(C) function %qs at " | |
d8fa96e0 CR |
4063 | "%L may not be C interoperable", tmp_sym->name, |
4064 | &tmp_sym->declared_at); | |
4065 | tmp_sym->ts.f90_type = tmp_sym->ts.type; | |
4066 | /* Mark it as C interoperable to prevent duplicate warnings. */ | |
4067 | tmp_sym->ts.is_c_interop = 1; | |
4068 | tmp_sym->attr.is_c_interop = 1; | |
4069 | } | |
4070 | } | |
8327f9c2 | 4071 | |
a8b3b0b6 CR |
4072 | /* Here, we know we have the bind(c) attribute, so if we have |
4073 | enough type info, then verify that it's a C interop kind. | |
4074 | The info could be in the symbol already, or possibly still in | |
4075 | the given ts (current_ts), so look in both. */ | |
f5acf0f2 | 4076 | if (tmp_sym->ts.type != BT_UNKNOWN || ts->type != BT_UNKNOWN) |
a8b3b0b6 | 4077 | { |
524af0d6 | 4078 | if (!gfc_verify_c_interop (&(tmp_sym->ts))) |
a8b3b0b6 CR |
4079 | { |
4080 | /* See if we're dealing with a sym in a common block or not. */ | |
4daa149b | 4081 | if (is_in_common == 1 && warn_c_binding_type) |
a8b3b0b6 | 4082 | { |
48749dbc MLI |
4083 | gfc_warning (OPT_Wc_binding_type, |
4084 | "Variable %qs in common block %qs at %L " | |
a8b3b0b6 | 4085 | "may not be a C interoperable " |
48749dbc | 4086 | "kind though common block %qs is BIND(C)", |
a8b3b0b6 CR |
4087 | tmp_sym->name, com_block->name, |
4088 | &(tmp_sym->declared_at), com_block->name); | |
4089 | } | |
4090 | else | |
4091 | { | |
4092 | if (tmp_sym->ts.type == BT_DERIVED || ts->type == BT_DERIVED) | |
c4100eae | 4093 | gfc_error ("Type declaration %qs at %L is not C " |
a8b3b0b6 CR |
4094 | "interoperable but it is BIND(C)", |
4095 | tmp_sym->name, &(tmp_sym->declared_at)); | |
4daa149b | 4096 | else if (warn_c_binding_type) |
48749dbc | 4097 | gfc_warning (OPT_Wc_binding_type, "Variable %qs at %L " |
a8b3b0b6 | 4098 | "may not be a C interoperable " |
c4100eae | 4099 | "kind but it is BIND(C)", |
a8b3b0b6 CR |
4100 | tmp_sym->name, &(tmp_sym->declared_at)); |
4101 | } | |
4102 | } | |
f5acf0f2 | 4103 | |
a8b3b0b6 CR |
4104 | /* Variables declared w/in a common block can't be bind(c) |
4105 | since there's no way for C to see these variables, so there's | |
4106 | semantically no reason for the attribute. */ | |
4107 | if (is_in_common == 1 && tmp_sym->attr.is_bind_c == 1) | |
4108 | { | |
c4100eae | 4109 | gfc_error ("Variable %qs in common block %qs at " |
a8b3b0b6 CR |
4110 | "%L cannot be declared with BIND(C) " |
4111 | "since it is not a global", | |
4112 | tmp_sym->name, com_block->name, | |
4113 | &(tmp_sym->declared_at)); | |
524af0d6 | 4114 | retval = false; |
a8b3b0b6 | 4115 | } |
f5acf0f2 | 4116 | |
a8b3b0b6 CR |
4117 | /* Scalar variables that are bind(c) can not have the pointer |
4118 | or allocatable attributes. */ | |
4119 | if (tmp_sym->attr.is_bind_c == 1) | |
4120 | { | |
4121 | if (tmp_sym->attr.pointer == 1) | |
4122 | { | |
c4100eae | 4123 | gfc_error ("Variable %qs at %L cannot have both the " |
a8b3b0b6 CR |
4124 | "POINTER and BIND(C) attributes", |
4125 | tmp_sym->name, &(tmp_sym->declared_at)); | |
524af0d6 | 4126 | retval = false; |
a8b3b0b6 CR |
4127 | } |
4128 | ||
4129 | if (tmp_sym->attr.allocatable == 1) | |
4130 | { | |
c4100eae | 4131 | gfc_error ("Variable %qs at %L cannot have both the " |
a8b3b0b6 CR |
4132 | "ALLOCATABLE and BIND(C) attributes", |
4133 | tmp_sym->name, &(tmp_sym->declared_at)); | |
524af0d6 | 4134 | retval = false; |
a8b3b0b6 CR |
4135 | } |
4136 | ||
8327f9c2 TB |
4137 | } |
4138 | ||
4139 | /* If it is a BIND(C) function, make sure the return value is a | |
4140 | scalar value. The previous tests in this function made sure | |
4141 | the type is interoperable. */ | |
4142 | if (bind_c_function && tmp_sym->as != NULL) | |
c4100eae | 4143 | gfc_error ("Return type of BIND(C) function %qs at %L cannot " |
8327f9c2 TB |
4144 | "be an array", tmp_sym->name, &(tmp_sym->declared_at)); |
4145 | ||
4146 | /* BIND(C) functions can not return a character string. */ | |
4147 | if (bind_c_function && tmp_sym->ts.type == BT_CHARACTER) | |
bc21d315 JW |
4148 | if (tmp_sym->ts.u.cl == NULL || tmp_sym->ts.u.cl->length == NULL |
4149 | || tmp_sym->ts.u.cl->length->expr_type != EXPR_CONSTANT | |
4150 | || mpz_cmp_si (tmp_sym->ts.u.cl->length->value.integer, 1) != 0) | |
c4100eae | 4151 | gfc_error ("Return type of BIND(C) function %qs at %L cannot " |
a8b3b0b6 CR |
4152 | "be a character string", tmp_sym->name, |
4153 | &(tmp_sym->declared_at)); | |
a8b3b0b6 CR |
4154 | } |
4155 | ||
4156 | /* See if the symbol has been marked as private. If it has, make sure | |
4157 | there is no binding label and warn the user if there is one. */ | |
4158 | if (tmp_sym->attr.access == ACCESS_PRIVATE | |
62603fae | 4159 | && tmp_sym->binding_label) |
a8b3b0b6 CR |
4160 | /* Use gfc_warning_now because we won't say that the symbol fails |
4161 | just because of this. */ | |
db30e21c | 4162 | gfc_warning_now (0, "Symbol %qs at %L is marked PRIVATE but has been " |
4daa149b | 4163 | "given the binding label %qs", tmp_sym->name, |
a8b3b0b6 CR |
4164 | &(tmp_sym->declared_at), tmp_sym->binding_label); |
4165 | ||
4166 | return retval; | |
4167 | } | |
4168 | ||
4169 | ||
4170 | /* Set the appropriate fields for a symbol that's been declared as | |
4171 | BIND(C) (the is_bind_c flag and the binding label), and verify that | |
4172 | the type is C interoperable. Errors are reported by the functions | |
4173 | used to set/test these fields. */ | |
4174 | ||
524af0d6 | 4175 | bool |
a8b3b0b6 CR |
4176 | set_verify_bind_c_sym (gfc_symbol *tmp_sym, int num_idents) |
4177 | { | |
524af0d6 | 4178 | bool retval = true; |
f5acf0f2 | 4179 | |
a8b3b0b6 CR |
4180 | /* TODO: Do we need to make sure the vars aren't marked private? */ |
4181 | ||
4182 | /* Set the is_bind_c bit in symbol_attribute. */ | |
4183 | gfc_add_is_bind_c (&(tmp_sym->attr), tmp_sym->name, &gfc_current_locus, 0); | |
4184 | ||
524af0d6 JB |
4185 | if (!set_binding_label (&tmp_sym->binding_label, tmp_sym->name, num_idents)) |
4186 | return false; | |
a8b3b0b6 CR |
4187 | |
4188 | return retval; | |
4189 | } | |
4190 | ||
4191 | ||
4192 | /* Set the fields marking the given common block as BIND(C), including | |
4193 | a binding label, and report any errors encountered. */ | |
4194 | ||
524af0d6 | 4195 | bool |
a8b3b0b6 CR |
4196 | set_verify_bind_c_com_block (gfc_common_head *com_block, int num_idents) |
4197 | { | |
524af0d6 | 4198 | bool retval = true; |
f5acf0f2 | 4199 | |
a8b3b0b6 | 4200 | /* destLabel, common name, typespec (which may have binding label). */ |
524af0d6 JB |
4201 | if (!set_binding_label (&com_block->binding_label, com_block->name, |
4202 | num_idents)) | |
4203 | return false; | |
a8b3b0b6 CR |
4204 | |
4205 | /* Set the given common block (com_block) to being bind(c) (1). */ | |
4206 | set_com_block_bind_c (com_block, 1); | |
4207 | ||
4208 | return retval; | |
4209 | } | |
4210 | ||
4211 | ||
4212 | /* Retrieve the list of one or more identifiers that the given bind(c) | |
4213 | attribute applies to. */ | |
4214 | ||
524af0d6 | 4215 | bool |
a8b3b0b6 CR |
4216 | get_bind_c_idents (void) |
4217 | { | |
4218 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
4219 | int num_idents = 0; | |
4220 | gfc_symbol *tmp_sym = NULL; | |
4221 | match found_id; | |
4222 | gfc_common_head *com_block = NULL; | |
f5acf0f2 | 4223 | |
a8b3b0b6 CR |
4224 | if (gfc_match_name (name) == MATCH_YES) |
4225 | { | |
4226 | found_id = MATCH_YES; | |
4227 | gfc_get_ha_symbol (name, &tmp_sym); | |
4228 | } | |
4229 | else if (match_common_name (name) == MATCH_YES) | |
4230 | { | |
4231 | found_id = MATCH_YES; | |
4232 | com_block = gfc_get_common (name, 0); | |
4233 | } | |
4234 | else | |
4235 | { | |
4236 | gfc_error ("Need either entity or common block name for " | |
4237 | "attribute specification statement at %C"); | |
524af0d6 | 4238 | return false; |
a8b3b0b6 | 4239 | } |
f5acf0f2 | 4240 | |
a8b3b0b6 CR |
4241 | /* Save the current identifier and look for more. */ |
4242 | do | |
4243 | { | |
4244 | /* Increment the number of identifiers found for this spec stmt. */ | |
4245 | num_idents++; | |
4246 | ||
4247 | /* Make sure we have a sym or com block, and verify that it can | |
4248 | be bind(c). Set the appropriate field(s) and look for more | |
4249 | identifiers. */ | |
f5acf0f2 | 4250 | if (tmp_sym != NULL || com_block != NULL) |
a8b3b0b6 CR |
4251 | { |
4252 | if (tmp_sym != NULL) | |
4253 | { | |
524af0d6 JB |
4254 | if (!set_verify_bind_c_sym (tmp_sym, num_idents)) |
4255 | return false; | |
a8b3b0b6 CR |
4256 | } |
4257 | else | |
4258 | { | |
524af0d6 JB |
4259 | if (!set_verify_bind_c_com_block (com_block, num_idents)) |
4260 | return false; | |
a8b3b0b6 | 4261 | } |
f5acf0f2 | 4262 | |
a8b3b0b6 CR |
4263 | /* Look to see if we have another identifier. */ |
4264 | tmp_sym = NULL; | |
4265 | if (gfc_match_eos () == MATCH_YES) | |
4266 | found_id = MATCH_NO; | |
4267 | else if (gfc_match_char (',') != MATCH_YES) | |
4268 | found_id = MATCH_NO; | |
4269 | else if (gfc_match_name (name) == MATCH_YES) | |
4270 | { | |
4271 | found_id = MATCH_YES; | |
4272 | gfc_get_ha_symbol (name, &tmp_sym); | |
4273 | } | |
4274 | else if (match_common_name (name) == MATCH_YES) | |
4275 | { | |
4276 | found_id = MATCH_YES; | |
4277 | com_block = gfc_get_common (name, 0); | |
4278 | } | |
4279 | else | |
4280 | { | |
4281 | gfc_error ("Missing entity or common block name for " | |
4282 | "attribute specification statement at %C"); | |
524af0d6 | 4283 | return false; |
a8b3b0b6 CR |
4284 | } |
4285 | } | |
4286 | else | |
4287 | { | |
4288 | gfc_internal_error ("Missing symbol"); | |
4289 | } | |
4290 | } while (found_id == MATCH_YES); | |
4291 | ||
4292 | /* if we get here we were successful */ | |
524af0d6 | 4293 | return true; |
a8b3b0b6 CR |
4294 | } |
4295 | ||
4296 | ||
4297 | /* Try and match a BIND(C) attribute specification statement. */ | |
f5acf0f2 | 4298 | |
a8b3b0b6 CR |
4299 | match |
4300 | gfc_match_bind_c_stmt (void) | |
4301 | { | |
4302 | match found_match = MATCH_NO; | |
4303 | gfc_typespec *ts; | |
4304 | ||
4305 | ts = ¤t_ts; | |
f5acf0f2 | 4306 | |
a8b3b0b6 CR |
4307 | /* This may not be necessary. */ |
4308 | gfc_clear_ts (ts); | |
4309 | /* Clear the temporary binding label holder. */ | |
62603fae | 4310 | curr_binding_label = NULL; |
a8b3b0b6 CR |
4311 | |
4312 | /* Look for the bind(c). */ | |
1eabf70a | 4313 | found_match = gfc_match_bind_c (NULL, true); |
a8b3b0b6 CR |
4314 | |
4315 | if (found_match == MATCH_YES) | |
4316 | { | |
878cdb7b TB |
4317 | if (!gfc_notify_std (GFC_STD_F2003, "BIND(C) statement at %C")) |
4318 | return MATCH_ERROR; | |
4319 | ||
a8b3b0b6 CR |
4320 | /* Look for the :: now, but it is not required. */ |
4321 | gfc_match (" :: "); | |
4322 | ||
4323 | /* Get the identifier(s) that needs to be updated. This may need to | |
4324 | change to hand the flag(s) for the attr specified so all identifiers | |
4325 | found can have all appropriate parts updated (assuming that the same | |
4326 | spec stmt can have multiple attrs, such as both bind(c) and | |
4327 | allocatable...). */ | |
524af0d6 | 4328 | if (!get_bind_c_idents ()) |
a8b3b0b6 CR |
4329 | /* Error message should have printed already. */ |
4330 | return MATCH_ERROR; | |
4331 | } | |
4332 | ||
4333 | return found_match; | |
4334 | } | |
4335 | ||
4336 | ||
6de9cd9a DN |
4337 | /* Match a data declaration statement. */ |
4338 | ||
4339 | match | |
4340 | gfc_match_data_decl (void) | |
4341 | { | |
4342 | gfc_symbol *sym; | |
4343 | match m; | |
949d5b72 | 4344 | int elem; |
6de9cd9a | 4345 | |
a8b3b0b6 | 4346 | num_idents_on_line = 0; |
f5acf0f2 | 4347 | |
e74f1cc8 | 4348 | m = gfc_match_decl_type_spec (¤t_ts, 0); |
6de9cd9a DN |
4349 | if (m != MATCH_YES) |
4350 | return m; | |
4351 | ||
2e23972e JW |
4352 | if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS) |
4353 | && gfc_current_state () != COMP_DERIVED) | |
6de9cd9a | 4354 | { |
bc21d315 | 4355 | sym = gfc_use_derived (current_ts.u.derived); |
6de9cd9a DN |
4356 | |
4357 | if (sym == NULL) | |
4358 | { | |
4359 | m = MATCH_ERROR; | |
4360 | goto cleanup; | |
4361 | } | |
4362 | ||
bc21d315 | 4363 | current_ts.u.derived = sym; |
6de9cd9a DN |
4364 | } |
4365 | ||
4366 | m = match_attr_spec (); | |
4367 | if (m == MATCH_ERROR) | |
4368 | { | |
4369 | m = MATCH_NO; | |
4370 | goto cleanup; | |
4371 | } | |
4372 | ||
8b704316 PT |
4373 | if (current_ts.type == BT_CLASS |
4374 | && current_ts.u.derived->attr.unlimited_polymorphic) | |
4375 | goto ok; | |
4376 | ||
2e23972e JW |
4377 | if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS) |
4378 | && current_ts.u.derived->components == NULL | |
bc21d315 | 4379 | && !current_ts.u.derived->attr.zero_comp) |
6de9cd9a DN |
4380 | { |
4381 | ||
4382 | if (current_attr.pointer && gfc_current_state () == COMP_DERIVED) | |
4383 | goto ok; | |
4384 | ||
bc21d315 | 4385 | gfc_find_symbol (current_ts.u.derived->name, |
dd8b9dde | 4386 | current_ts.u.derived->ns, 1, &sym); |
6de9cd9a | 4387 | |
976e21f6 | 4388 | /* Any symbol that we find had better be a type definition |
636dff67 | 4389 | which has its components defined. */ |
976e21f6 | 4390 | if (sym != NULL && sym->attr.flavor == FL_DERIVED |
bc21d315 JW |
4391 | && (current_ts.u.derived->components != NULL |
4392 | || current_ts.u.derived->attr.zero_comp)) | |
6de9cd9a DN |
4393 | goto ok; |
4394 | ||
a1b80ec7 JW |
4395 | gfc_error ("Derived type at %C has not been previously defined " |
4396 | "and so cannot appear in a derived type definition"); | |
4397 | m = MATCH_ERROR; | |
4398 | goto cleanup; | |
6de9cd9a DN |
4399 | } |
4400 | ||
4401 | ok: | |
4402 | /* If we have an old-style character declaration, and no new-style | |
4403 | attribute specifications, then there a comma is optional between | |
4404 | the type specification and the variable list. */ | |
4405 | if (m == MATCH_NO && current_ts.type == BT_CHARACTER && old_char_selector) | |
4406 | gfc_match_char (','); | |
4407 | ||
949d5b72 PT |
4408 | /* Give the types/attributes to symbols that follow. Give the element |
4409 | a number so that repeat character length expressions can be copied. */ | |
4410 | elem = 1; | |
6de9cd9a DN |
4411 | for (;;) |
4412 | { | |
a8b3b0b6 | 4413 | num_idents_on_line++; |
949d5b72 | 4414 | m = variable_decl (elem++); |
6de9cd9a DN |
4415 | if (m == MATCH_ERROR) |
4416 | goto cleanup; | |
4417 | if (m == MATCH_NO) | |
4418 | break; | |
4419 | ||
4420 | if (gfc_match_eos () == MATCH_YES) | |
4421 | goto cleanup; | |
4422 | if (gfc_match_char (',') != MATCH_YES) | |
4423 | break; | |
4424 | } | |
4425 | ||
0f447a6e | 4426 | if (!gfc_error_flag_test ()) |
8f81c3c6 | 4427 | gfc_error ("Syntax error in data declaration at %C"); |
6de9cd9a DN |
4428 | m = MATCH_ERROR; |
4429 | ||
a9f6f1f2 JD |
4430 | gfc_free_data_all (gfc_current_ns); |
4431 | ||
6de9cd9a DN |
4432 | cleanup: |
4433 | gfc_free_array_spec (current_as); | |
4434 | current_as = NULL; | |
4435 | return m; | |
4436 | } | |
4437 | ||
4438 | ||
4439 | /* Match a prefix associated with a function or subroutine | |
4440 | declaration. If the typespec pointer is nonnull, then a typespec | |
4441 | can be matched. Note that if nothing matches, MATCH_YES is | |
4442 | returned (the null string was matched). */ | |
4443 | ||
1c8bcdf7 PT |
4444 | match |
4445 | gfc_match_prefix (gfc_typespec *ts) | |
6de9cd9a | 4446 | { |
7389bce6 | 4447 | bool seen_type; |
e6c14898 DK |
4448 | bool seen_impure; |
4449 | bool found_prefix; | |
6de9cd9a DN |
4450 | |
4451 | gfc_clear_attr (¤t_attr); | |
e6c14898 DK |
4452 | seen_type = false; |
4453 | seen_impure = false; | |
6de9cd9a | 4454 | |
3df684e2 DK |
4455 | gcc_assert (!gfc_matching_prefix); |
4456 | gfc_matching_prefix = true; | |
f37e928c | 4457 | |
e6c14898 | 4458 | do |
6de9cd9a | 4459 | { |
e6c14898 | 4460 | found_prefix = false; |
6de9cd9a | 4461 | |
e6c14898 DK |
4462 | if (!seen_type && ts != NULL |
4463 | && gfc_match_decl_type_spec (ts, 0) == MATCH_YES | |
4464 | && gfc_match_space () == MATCH_YES) | |
4465 | { | |
6de9cd9a | 4466 | |
e6c14898 DK |
4467 | seen_type = true; |
4468 | found_prefix = true; | |
4469 | } | |
4470 | ||
4471 | if (gfc_match ("elemental% ") == MATCH_YES) | |
4472 | { | |
524af0d6 | 4473 | if (!gfc_add_elemental (¤t_attr, NULL)) |
e6c14898 DK |
4474 | goto error; |
4475 | ||
4476 | found_prefix = true; | |
4477 | } | |
4478 | ||
4479 | if (gfc_match ("pure% ") == MATCH_YES) | |
4480 | { | |
524af0d6 | 4481 | if (!gfc_add_pure (¤t_attr, NULL)) |
e6c14898 DK |
4482 | goto error; |
4483 | ||
4484 | found_prefix = true; | |
4485 | } | |
6de9cd9a | 4486 | |
e6c14898 DK |
4487 | if (gfc_match ("recursive% ") == MATCH_YES) |
4488 | { | |
524af0d6 | 4489 | if (!gfc_add_recursive (¤t_attr, NULL)) |
e6c14898 DK |
4490 | goto error; |
4491 | ||
4492 | found_prefix = true; | |
4493 | } | |
4494 | ||
4495 | /* IMPURE is a somewhat special case, as it needs not set an actual | |
4496 | attribute but rather only prevents ELEMENTAL routines from being | |
4497 | automatically PURE. */ | |
4498 | if (gfc_match ("impure% ") == MATCH_YES) | |
4499 | { | |
524af0d6 | 4500 | if (!gfc_notify_std (GFC_STD_F2008, "IMPURE procedure at %C")) |
e6c14898 DK |
4501 | goto error; |
4502 | ||
4503 | seen_impure = true; | |
4504 | found_prefix = true; | |
4505 | } | |
6de9cd9a | 4506 | } |
e6c14898 | 4507 | while (found_prefix); |
6de9cd9a | 4508 | |
e6c14898 DK |
4509 | /* IMPURE and PURE must not both appear, of course. */ |
4510 | if (seen_impure && current_attr.pure) | |
6de9cd9a | 4511 | { |
e6c14898 DK |
4512 | gfc_error ("PURE and IMPURE must not appear both at %C"); |
4513 | goto error; | |
6de9cd9a DN |
4514 | } |
4515 | ||
e6c14898 DK |
4516 | /* If IMPURE it not seen but the procedure is ELEMENTAL, mark it as PURE. */ |
4517 | if (!seen_impure && current_attr.elemental && !current_attr.pure) | |
6de9cd9a | 4518 | { |
524af0d6 | 4519 | if (!gfc_add_pure (¤t_attr, NULL)) |
f37e928c | 4520 | goto error; |
6de9cd9a DN |
4521 | } |
4522 | ||
4523 | /* At this point, the next item is not a prefix. */ | |
3df684e2 DK |
4524 | gcc_assert (gfc_matching_prefix); |
4525 | gfc_matching_prefix = false; | |
6de9cd9a | 4526 | return MATCH_YES; |
f37e928c DK |
4527 | |
4528 | error: | |
3df684e2 DK |
4529 | gcc_assert (gfc_matching_prefix); |
4530 | gfc_matching_prefix = false; | |
f37e928c | 4531 | return MATCH_ERROR; |
6de9cd9a DN |
4532 | } |
4533 | ||
4534 | ||
1c8bcdf7 | 4535 | /* Copy attributes matched by gfc_match_prefix() to attributes on a symbol. */ |
6de9cd9a | 4536 | |
524af0d6 | 4537 | static bool |
636dff67 | 4538 | copy_prefix (symbol_attribute *dest, locus *where) |
6de9cd9a | 4539 | { |
524af0d6 JB |
4540 | if (current_attr.pure && !gfc_add_pure (dest, where)) |
4541 | return false; | |
6de9cd9a | 4542 | |
524af0d6 JB |
4543 | if (current_attr.elemental && !gfc_add_elemental (dest, where)) |
4544 | return false; | |
6de9cd9a | 4545 | |
524af0d6 JB |
4546 | if (current_attr.recursive && !gfc_add_recursive (dest, where)) |
4547 | return false; | |
6de9cd9a | 4548 | |
524af0d6 | 4549 | return true; |
6de9cd9a DN |
4550 | } |
4551 | ||
4552 | ||
4553 | /* Match a formal argument list. */ | |
4554 | ||
4555 | match | |
636dff67 | 4556 | gfc_match_formal_arglist (gfc_symbol *progname, int st_flag, int null_flag) |
6de9cd9a DN |
4557 | { |
4558 | gfc_formal_arglist *head, *tail, *p, *q; | |
4559 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
4560 | gfc_symbol *sym; | |
4561 | match m; | |
4562 | ||
4563 | head = tail = NULL; | |
4564 | ||
4565 | if (gfc_match_char ('(') != MATCH_YES) | |
4566 | { | |
4567 | if (null_flag) | |
4568 | goto ok; | |
4569 | return MATCH_NO; | |
4570 | } | |
4571 | ||
4572 | if (gfc_match_char (')') == MATCH_YES) | |
4573 | goto ok; | |
4574 | ||
4575 | for (;;) | |
4576 | { | |
4577 | if (gfc_match_char ('*') == MATCH_YES) | |
9362a03b JW |
4578 | { |
4579 | sym = NULL; | |
524af0d6 JB |
4580 | if (!gfc_notify_std (GFC_STD_F95_OBS, "Alternate-return argument " |
4581 | "at %C")) | |
9362a03b JW |
4582 | { |
4583 | m = MATCH_ERROR; | |
4584 | goto cleanup; | |
4585 | } | |
4586 | } | |
6de9cd9a DN |
4587 | else |
4588 | { | |
4589 | m = gfc_match_name (name); | |
4590 | if (m != MATCH_YES) | |
4591 | goto cleanup; | |
4592 | ||
4593 | if (gfc_get_symbol (name, NULL, &sym)) | |
4594 | goto cleanup; | |
4595 | } | |
4596 | ||
4597 | p = gfc_get_formal_arglist (); | |
4598 | ||
4599 | if (head == NULL) | |
4600 | head = tail = p; | |
4601 | else | |
4602 | { | |
4603 | tail->next = p; | |
4604 | tail = p; | |
4605 | } | |
4606 | ||
4607 | tail->sym = sym; | |
4608 | ||
4609 | /* We don't add the VARIABLE flavor because the name could be a | |
636dff67 SK |
4610 | dummy procedure. We don't apply these attributes to formal |
4611 | arguments of statement functions. */ | |
6de9cd9a | 4612 | if (sym != NULL && !st_flag |
524af0d6 JB |
4613 | && (!gfc_add_dummy(&sym->attr, sym->name, NULL) |
4614 | || !gfc_missing_attr (&sym->attr, NULL))) | |
6de9cd9a DN |
4615 | { |
4616 | m = MATCH_ERROR; | |
4617 | goto cleanup; | |
4618 | } | |
4619 | ||
4620 | /* The name of a program unit can be in a different namespace, | |
636dff67 SK |
4621 | so check for it explicitly. After the statement is accepted, |
4622 | the name is checked for especially in gfc_get_symbol(). */ | |
6de9cd9a DN |
4623 | if (gfc_new_block != NULL && sym != NULL |
4624 | && strcmp (sym->name, gfc_new_block->name) == 0) | |
4625 | { | |
c4100eae | 4626 | gfc_error ("Name %qs at %C is the name of the procedure", |
6de9cd9a DN |
4627 | sym->name); |
4628 | m = MATCH_ERROR; | |
4629 | goto cleanup; | |
4630 | } | |
4631 | ||
4632 | if (gfc_match_char (')') == MATCH_YES) | |
4633 | goto ok; | |
4634 | ||
4635 | m = gfc_match_char (','); | |
4636 | if (m != MATCH_YES) | |
4637 | { | |
4638 | gfc_error ("Unexpected junk in formal argument list at %C"); | |
4639 | goto cleanup; | |
4640 | } | |
4641 | } | |
4642 | ||
4643 | ok: | |
4644 | /* Check for duplicate symbols in the formal argument list. */ | |
4645 | if (head != NULL) | |
4646 | { | |
4647 | for (p = head; p->next; p = p->next) | |
4648 | { | |
4649 | if (p->sym == NULL) | |
4650 | continue; | |
4651 | ||
4652 | for (q = p->next; q; q = q->next) | |
4653 | if (p->sym == q->sym) | |
4654 | { | |
c4100eae | 4655 | gfc_error ("Duplicate symbol %qs in formal argument list " |
636dff67 | 4656 | "at %C", p->sym->name); |
6de9cd9a DN |
4657 | |
4658 | m = MATCH_ERROR; | |
4659 | goto cleanup; | |
4660 | } | |
4661 | } | |
4662 | } | |
4663 | ||
524af0d6 | 4664 | if (!gfc_add_explicit_interface (progname, IFSRC_DECL, head, NULL)) |
6de9cd9a DN |
4665 | { |
4666 | m = MATCH_ERROR; | |
4667 | goto cleanup; | |
4668 | } | |
4669 | ||
4670 | return MATCH_YES; | |
4671 | ||
4672 | cleanup: | |
4673 | gfc_free_formal_arglist (head); | |
4674 | return m; | |
4675 | } | |
4676 | ||
4677 | ||
4678 | /* Match a RESULT specification following a function declaration or | |
4679 | ENTRY statement. Also matches the end-of-statement. */ | |
4680 | ||
4681 | static match | |
66e4ab31 | 4682 | match_result (gfc_symbol *function, gfc_symbol **result) |
6de9cd9a DN |
4683 | { |
4684 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
4685 | gfc_symbol *r; | |
4686 | match m; | |
4687 | ||
4688 | if (gfc_match (" result (") != MATCH_YES) | |
4689 | return MATCH_NO; | |
4690 | ||
4691 | m = gfc_match_name (name); | |
4692 | if (m != MATCH_YES) | |
4693 | return m; | |
4694 | ||
a8b3b0b6 CR |
4695 | /* Get the right paren, and that's it because there could be the |
4696 | bind(c) attribute after the result clause. */ | |
524af0d6 | 4697 | if (gfc_match_char (')') != MATCH_YES) |
6de9cd9a | 4698 | { |
a8b3b0b6 | 4699 | /* TODO: should report the missing right paren here. */ |
6de9cd9a DN |
4700 | return MATCH_ERROR; |
4701 | } | |
4702 | ||
4703 | if (strcmp (function->name, name) == 0) | |
4704 | { | |
636dff67 | 4705 | gfc_error ("RESULT variable at %C must be different than function name"); |
6de9cd9a DN |
4706 | return MATCH_ERROR; |
4707 | } | |
4708 | ||
4709 | if (gfc_get_symbol (name, NULL, &r)) | |
4710 | return MATCH_ERROR; | |
4711 | ||
524af0d6 | 4712 | if (!gfc_add_result (&r->attr, r->name, NULL)) |
6de9cd9a DN |
4713 | return MATCH_ERROR; |
4714 | ||
4715 | *result = r; | |
4716 | ||
4717 | return MATCH_YES; | |
4718 | } | |
4719 | ||
4720 | ||
a8b3b0b6 CR |
4721 | /* Match a function suffix, which could be a combination of a result |
4722 | clause and BIND(C), either one, or neither. The draft does not | |
4723 | require them to come in a specific order. */ | |
4724 | ||
4725 | match | |
4726 | gfc_match_suffix (gfc_symbol *sym, gfc_symbol **result) | |
4727 | { | |
4728 | match is_bind_c; /* Found bind(c). */ | |
4729 | match is_result; /* Found result clause. */ | |
4730 | match found_match; /* Status of whether we've found a good match. */ | |
8fc541d3 | 4731 | char peek_char; /* Character we're going to peek at. */ |
1eabf70a | 4732 | bool allow_binding_name; |
a8b3b0b6 CR |
4733 | |
4734 | /* Initialize to having found nothing. */ | |
4735 | found_match = MATCH_NO; | |
f5acf0f2 | 4736 | is_bind_c = MATCH_NO; |
a8b3b0b6 CR |
4737 | is_result = MATCH_NO; |
4738 | ||
4739 | /* Get the next char to narrow between result and bind(c). */ | |
4740 | gfc_gobble_whitespace (); | |
8fc541d3 | 4741 | peek_char = gfc_peek_ascii_char (); |
a8b3b0b6 | 4742 | |
1eabf70a TB |
4743 | /* C binding names are not allowed for internal procedures. */ |
4744 | if (gfc_current_state () == COMP_CONTAINS | |
4745 | && sym->ns->proc_name->attr.flavor != FL_MODULE) | |
4746 | allow_binding_name = false; | |
4747 | else | |
4748 | allow_binding_name = true; | |
4749 | ||
a8b3b0b6 CR |
4750 | switch (peek_char) |
4751 | { | |
4752 | case 'r': | |
4753 | /* Look for result clause. */ | |
4754 | is_result = match_result (sym, result); | |
4755 | if (is_result == MATCH_YES) | |
4756 | { | |
4757 | /* Now see if there is a bind(c) after it. */ | |
1eabf70a | 4758 | is_bind_c = gfc_match_bind_c (sym, allow_binding_name); |
a8b3b0b6 CR |
4759 | /* We've found the result clause and possibly bind(c). */ |
4760 | found_match = MATCH_YES; | |
4761 | } | |
4762 | else | |
4763 | /* This should only be MATCH_ERROR. */ | |
f5acf0f2 | 4764 | found_match = is_result; |
a8b3b0b6 CR |
4765 | break; |
4766 | case 'b': | |
4767 | /* Look for bind(c) first. */ | |
1eabf70a | 4768 | is_bind_c = gfc_match_bind_c (sym, allow_binding_name); |
a8b3b0b6 CR |
4769 | if (is_bind_c == MATCH_YES) |
4770 | { | |
4771 | /* Now see if a result clause followed it. */ | |
4772 | is_result = match_result (sym, result); | |
4773 | found_match = MATCH_YES; | |
4774 | } | |
4775 | else | |
4776 | { | |
4777 | /* Should only be a MATCH_ERROR if we get here after seeing 'b'. */ | |
4778 | found_match = MATCH_ERROR; | |
4779 | } | |
4780 | break; | |
4781 | default: | |
4782 | gfc_error ("Unexpected junk after function declaration at %C"); | |
4783 | found_match = MATCH_ERROR; | |
4784 | break; | |
4785 | } | |
4786 | ||
a8b3b0b6 | 4787 | if (is_bind_c == MATCH_YES) |
01f4fff1 | 4788 | { |
1eabf70a | 4789 | /* Fortran 2008 draft allows BIND(C) for internal procedures. */ |
01f4fff1 | 4790 | if (gfc_current_state () == COMP_CONTAINS |
1eabf70a | 4791 | && sym->ns->proc_name->attr.flavor != FL_MODULE |
524af0d6 JB |
4792 | && !gfc_notify_std (GFC_STD_F2008, "BIND(C) attribute " |
4793 | "at %L may not be specified for an internal " | |
4794 | "procedure", &gfc_current_locus)) | |
1eabf70a TB |
4795 | return MATCH_ERROR; |
4796 | ||
524af0d6 | 4797 | if (!gfc_add_is_bind_c (&(sym->attr), sym->name, &gfc_current_locus, 1)) |
01f4fff1 TB |
4798 | return MATCH_ERROR; |
4799 | } | |
f5acf0f2 | 4800 | |
a8b3b0b6 CR |
4801 | return found_match; |
4802 | } | |
4803 | ||
4804 | ||
3070bab4 JW |
4805 | /* Procedure pointer return value without RESULT statement: |
4806 | Add "hidden" result variable named "ppr@". */ | |
4807 | ||
524af0d6 | 4808 | static bool |
3070bab4 JW |
4809 | add_hidden_procptr_result (gfc_symbol *sym) |
4810 | { | |
4811 | bool case1,case2; | |
4812 | ||
4813 | if (gfc_notification_std (GFC_STD_F2003) == ERROR) | |
524af0d6 | 4814 | return false; |
3070bab4 JW |
4815 | |
4816 | /* First usage case: PROCEDURE and EXTERNAL statements. */ | |
4817 | case1 = gfc_current_state () == COMP_FUNCTION && gfc_current_block () | |
4818 | && strcmp (gfc_current_block ()->name, sym->name) == 0 | |
4819 | && sym->attr.external; | |
4820 | /* Second usage case: INTERFACE statements. */ | |
4821 | case2 = gfc_current_state () == COMP_INTERFACE && gfc_state_stack->previous | |
4822 | && gfc_state_stack->previous->state == COMP_FUNCTION | |
4823 | && strcmp (gfc_state_stack->previous->sym->name, sym->name) == 0; | |
4824 | ||
4825 | if (case1 || case2) | |
4826 | { | |
4827 | gfc_symtree *stree; | |
4828 | if (case1) | |
08a6b8e0 | 4829 | gfc_get_sym_tree ("ppr@", gfc_current_ns, &stree, false); |
3070bab4 | 4830 | else if (case2) |
c73b6478 JW |
4831 | { |
4832 | gfc_symtree *st2; | |
08a6b8e0 | 4833 | gfc_get_sym_tree ("ppr@", gfc_current_ns->parent, &stree, false); |
c73b6478 JW |
4834 | st2 = gfc_new_symtree (&gfc_current_ns->sym_root, "ppr@"); |
4835 | st2->n.sym = stree->n.sym; | |
4836 | } | |
3070bab4 JW |
4837 | sym->result = stree->n.sym; |
4838 | ||
4839 | sym->result->attr.proc_pointer = sym->attr.proc_pointer; | |
4840 | sym->result->attr.pointer = sym->attr.pointer; | |
4841 | sym->result->attr.external = sym->attr.external; | |
4842 | sym->result->attr.referenced = sym->attr.referenced; | |
fc9c6e5d | 4843 | sym->result->ts = sym->ts; |
3070bab4 JW |
4844 | sym->attr.proc_pointer = 0; |
4845 | sym->attr.pointer = 0; | |
4846 | sym->attr.external = 0; | |
4847 | if (sym->result->attr.external && sym->result->attr.pointer) | |
4848 | { | |
4849 | sym->result->attr.pointer = 0; | |
4850 | sym->result->attr.proc_pointer = 1; | |
4851 | } | |
4852 | ||
4853 | return gfc_add_result (&sym->result->attr, sym->result->name, NULL); | |
4854 | } | |
4855 | /* POINTER after PROCEDURE/EXTERNAL/INTERFACE statement. */ | |
4856 | else if (sym->attr.function && !sym->attr.external && sym->attr.pointer | |
4857 | && sym->result && sym->result != sym && sym->result->attr.external | |
4858 | && sym == gfc_current_ns->proc_name | |
4859 | && sym == sym->result->ns->proc_name | |
4860 | && strcmp ("ppr@", sym->result->name) == 0) | |
4861 | { | |
4862 | sym->result->attr.proc_pointer = 1; | |
4863 | sym->attr.pointer = 0; | |
524af0d6 | 4864 | return true; |
3070bab4 JW |
4865 | } |
4866 | else | |
524af0d6 | 4867 | return false; |
3070bab4 JW |
4868 | } |
4869 | ||
4870 | ||
713485cc JW |
4871 | /* Match the interface for a PROCEDURE declaration, |
4872 | including brackets (R1212). */ | |
69773742 JW |
4873 | |
4874 | static match | |
713485cc | 4875 | match_procedure_interface (gfc_symbol **proc_if) |
69773742 JW |
4876 | { |
4877 | match m; | |
3276e0b3 | 4878 | gfc_symtree *st; |
69773742 | 4879 | locus old_loc, entry_loc; |
3276e0b3 PT |
4880 | gfc_namespace *old_ns = gfc_current_ns; |
4881 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
69773742 | 4882 | |
3276e0b3 | 4883 | old_loc = entry_loc = gfc_current_locus; |
69773742 JW |
4884 | gfc_clear_ts (¤t_ts); |
4885 | ||
4886 | if (gfc_match (" (") != MATCH_YES) | |
4887 | { | |
4888 | gfc_current_locus = entry_loc; | |
4889 | return MATCH_NO; | |
4890 | } | |
4891 | ||
4892 | /* Get the type spec. for the procedure interface. */ | |
4893 | old_loc = gfc_current_locus; | |
e74f1cc8 | 4894 | m = gfc_match_decl_type_spec (¤t_ts, 0); |
f4256439 | 4895 | gfc_gobble_whitespace (); |
8fc541d3 | 4896 | if (m == MATCH_YES || (m == MATCH_NO && gfc_peek_ascii_char () == ')')) |
69773742 JW |
4897 | goto got_ts; |
4898 | ||
4899 | if (m == MATCH_ERROR) | |
4900 | return m; | |
4901 | ||
3276e0b3 | 4902 | /* Procedure interface is itself a procedure. */ |
69773742 | 4903 | gfc_current_locus = old_loc; |
3276e0b3 | 4904 | m = gfc_match_name (name); |
69773742 | 4905 | |
3276e0b3 PT |
4906 | /* First look to see if it is already accessible in the current |
4907 | namespace because it is use associated or contained. */ | |
4908 | st = NULL; | |
4909 | if (gfc_find_sym_tree (name, NULL, 0, &st)) | |
4910 | return MATCH_ERROR; | |
4911 | ||
4912 | /* If it is still not found, then try the parent namespace, if it | |
4913 | exists and create the symbol there if it is still not found. */ | |
4914 | if (gfc_current_ns->parent) | |
4915 | gfc_current_ns = gfc_current_ns->parent; | |
4916 | if (st == NULL && gfc_get_ha_sym_tree (name, &st)) | |
4917 | return MATCH_ERROR; | |
4918 | ||
4919 | gfc_current_ns = old_ns; | |
4920 | *proc_if = st->n.sym; | |
69773742 | 4921 | |
713485cc | 4922 | if (*proc_if) |
69773742 | 4923 | { |
713485cc | 4924 | (*proc_if)->refs++; |
bb343a6c TB |
4925 | /* Resolve interface if possible. That way, attr.procedure is only set |
4926 | if it is declared by a later procedure-declaration-stmt, which is | |
0e8d854e | 4927 | invalid per F08:C1216 (cf. resolve_procedure_interface). */ |
713485cc JW |
4928 | while ((*proc_if)->ts.interface) |
4929 | *proc_if = (*proc_if)->ts.interface; | |
bb343a6c | 4930 | |
0e8d854e JW |
4931 | if ((*proc_if)->attr.flavor == FL_UNKNOWN |
4932 | && (*proc_if)->ts.type == BT_UNKNOWN | |
524af0d6 JB |
4933 | && !gfc_add_flavor (&(*proc_if)->attr, FL_PROCEDURE, |
4934 | (*proc_if)->name, NULL)) | |
0e8d854e | 4935 | return MATCH_ERROR; |
69773742 JW |
4936 | } |
4937 | ||
4938 | got_ts: | |
69773742 JW |
4939 | if (gfc_match (" )") != MATCH_YES) |
4940 | { | |
4941 | gfc_current_locus = entry_loc; | |
4942 | return MATCH_NO; | |
4943 | } | |
4944 | ||
713485cc JW |
4945 | return MATCH_YES; |
4946 | } | |
4947 | ||
4948 | ||
4949 | /* Match a PROCEDURE declaration (R1211). */ | |
4950 | ||
4951 | static match | |
4952 | match_procedure_decl (void) | |
4953 | { | |
4954 | match m; | |
4955 | gfc_symbol *sym, *proc_if = NULL; | |
4956 | int num; | |
4957 | gfc_expr *initializer = NULL; | |
4958 | ||
1cc0e193 | 4959 | /* Parse interface (with brackets). */ |
713485cc JW |
4960 | m = match_procedure_interface (&proc_if); |
4961 | if (m != MATCH_YES) | |
4962 | return m; | |
4963 | ||
4964 | /* Parse attributes (with colons). */ | |
69773742 JW |
4965 | m = match_attr_spec(); |
4966 | if (m == MATCH_ERROR) | |
4967 | return MATCH_ERROR; | |
4968 | ||
0859be17 TB |
4969 | if (proc_if && proc_if->attr.is_bind_c && !current_attr.is_bind_c) |
4970 | { | |
4971 | current_attr.is_bind_c = 1; | |
4972 | has_name_equals = 0; | |
4973 | curr_binding_label = NULL; | |
4974 | } | |
4975 | ||
69773742 JW |
4976 | /* Get procedure symbols. */ |
4977 | for(num=1;;num++) | |
4978 | { | |
69773742 JW |
4979 | m = gfc_match_symbol (&sym, 0); |
4980 | if (m == MATCH_NO) | |
4981 | goto syntax; | |
4982 | else if (m == MATCH_ERROR) | |
4983 | return m; | |
4984 | ||
4985 | /* Add current_attr to the symbol attributes. */ | |
524af0d6 | 4986 | if (!gfc_copy_attr (&sym->attr, ¤t_attr, NULL)) |
69773742 JW |
4987 | return MATCH_ERROR; |
4988 | ||
4989 | if (sym->attr.is_bind_c) | |
4990 | { | |
4991 | /* Check for C1218. */ | |
4992 | if (!proc_if || !proc_if->attr.is_bind_c) | |
4993 | { | |
4994 | gfc_error ("BIND(C) attribute at %C requires " | |
4995 | "an interface with BIND(C)"); | |
4996 | return MATCH_ERROR; | |
4997 | } | |
4998 | /* Check for C1217. */ | |
4999 | if (has_name_equals && sym->attr.pointer) | |
5000 | { | |
5001 | gfc_error ("BIND(C) procedure with NAME may not have " | |
5002 | "POINTER attribute at %C"); | |
5003 | return MATCH_ERROR; | |
5004 | } | |
5005 | if (has_name_equals && sym->attr.dummy) | |
5006 | { | |
5007 | gfc_error ("Dummy procedure at %C may not have " | |
5008 | "BIND(C) attribute with NAME"); | |
5009 | return MATCH_ERROR; | |
5010 | } | |
5011 | /* Set binding label for BIND(C). */ | |
524af0d6 | 5012 | if (!set_binding_label (&sym->binding_label, sym->name, num)) |
69773742 JW |
5013 | return MATCH_ERROR; |
5014 | } | |
5015 | ||
524af0d6 | 5016 | if (!gfc_add_external (&sym->attr, NULL)) |
69773742 | 5017 | return MATCH_ERROR; |
3070bab4 | 5018 | |
524af0d6 | 5019 | if (add_hidden_procptr_result (sym)) |
3070bab4 JW |
5020 | sym = sym->result; |
5021 | ||
524af0d6 | 5022 | if (!gfc_add_proc (&sym->attr, sym->name, NULL)) |
69773742 JW |
5023 | return MATCH_ERROR; |
5024 | ||
5025 | /* Set interface. */ | |
5026 | if (proc_if != NULL) | |
6cc309c9 | 5027 | { |
1d146030 JW |
5028 | if (sym->ts.type != BT_UNKNOWN) |
5029 | { | |
c4100eae | 5030 | gfc_error ("Procedure %qs at %L already has basic type of %s", |
1d146030 JW |
5031 | sym->name, &gfc_current_locus, |
5032 | gfc_basic_typename (sym->ts.type)); | |
5033 | return MATCH_ERROR; | |
5034 | } | |
32d99e68 | 5035 | sym->ts.interface = proc_if; |
6cc309c9 | 5036 | sym->attr.untyped = 1; |
c73b6478 | 5037 | sym->attr.if_source = IFSRC_IFBODY; |
6cc309c9 | 5038 | } |
69773742 JW |
5039 | else if (current_ts.type != BT_UNKNOWN) |
5040 | { | |
524af0d6 | 5041 | if (!gfc_add_type (sym, ¤t_ts, &gfc_current_locus)) |
1d146030 | 5042 | return MATCH_ERROR; |
32d99e68 JW |
5043 | sym->ts.interface = gfc_new_symbol ("", gfc_current_ns); |
5044 | sym->ts.interface->ts = current_ts; | |
d91909c0 | 5045 | sym->ts.interface->attr.flavor = FL_PROCEDURE; |
32d99e68 | 5046 | sym->ts.interface->attr.function = 1; |
d91909c0 | 5047 | sym->attr.function = 1; |
c73b6478 | 5048 | sym->attr.if_source = IFSRC_UNKNOWN; |
69773742 JW |
5049 | } |
5050 | ||
8fb74da4 JW |
5051 | if (gfc_match (" =>") == MATCH_YES) |
5052 | { | |
5053 | if (!current_attr.pointer) | |
5054 | { | |
5055 | gfc_error ("Initialization at %C isn't for a pointer variable"); | |
5056 | m = MATCH_ERROR; | |
5057 | goto cleanup; | |
5058 | } | |
5059 | ||
80f95228 | 5060 | m = match_pointer_init (&initializer, 1); |
8fb74da4 JW |
5061 | if (m != MATCH_YES) |
5062 | goto cleanup; | |
5063 | ||
524af0d6 | 5064 | if (!add_init_expr_to_sym (sym->name, &initializer, &gfc_current_locus)) |
8fb74da4 JW |
5065 | goto cleanup; |
5066 | ||
5067 | } | |
5068 | ||
69773742 JW |
5069 | if (gfc_match_eos () == MATCH_YES) |
5070 | return MATCH_YES; | |
5071 | if (gfc_match_char (',') != MATCH_YES) | |
5072 | goto syntax; | |
5073 | } | |
5074 | ||
5075 | syntax: | |
5076 | gfc_error ("Syntax error in PROCEDURE statement at %C"); | |
5077 | return MATCH_ERROR; | |
8fb74da4 JW |
5078 | |
5079 | cleanup: | |
5080 | /* Free stuff up and return. */ | |
5081 | gfc_free_expr (initializer); | |
5082 | return m; | |
69773742 JW |
5083 | } |
5084 | ||
5085 | ||
713485cc JW |
5086 | static match |
5087 | match_binding_attributes (gfc_typebound_proc* ba, bool generic, bool ppc); | |
5088 | ||
5089 | ||
5090 | /* Match a procedure pointer component declaration (R445). */ | |
5091 | ||
5092 | static match | |
5093 | match_ppc_decl (void) | |
5094 | { | |
5095 | match m; | |
5096 | gfc_symbol *proc_if = NULL; | |
5097 | gfc_typespec ts; | |
5098 | int num; | |
5099 | gfc_component *c; | |
5100 | gfc_expr *initializer = NULL; | |
5101 | gfc_typebound_proc* tb; | |
5102 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
5103 | ||
5104 | /* Parse interface (with brackets). */ | |
5105 | m = match_procedure_interface (&proc_if); | |
5106 | if (m != MATCH_YES) | |
5107 | goto syntax; | |
5108 | ||
5109 | /* Parse attributes. */ | |
5110 | tb = XCNEW (gfc_typebound_proc); | |
5111 | tb->where = gfc_current_locus; | |
5112 | m = match_binding_attributes (tb, false, true); | |
5113 | if (m == MATCH_ERROR) | |
5114 | return m; | |
5115 | ||
713485cc JW |
5116 | gfc_clear_attr (¤t_attr); |
5117 | current_attr.procedure = 1; | |
5118 | current_attr.proc_pointer = 1; | |
5119 | current_attr.access = tb->access; | |
5120 | current_attr.flavor = FL_PROCEDURE; | |
5121 | ||
5122 | /* Match the colons (required). */ | |
5123 | if (gfc_match (" ::") != MATCH_YES) | |
5124 | { | |
a4d9b221 | 5125 | gfc_error ("Expected %<::%> after binding-attributes at %C"); |
713485cc JW |
5126 | return MATCH_ERROR; |
5127 | } | |
5128 | ||
5129 | /* Check for C450. */ | |
5130 | if (!tb->nopass && proc_if == NULL) | |
5131 | { | |
5132 | gfc_error("NOPASS or explicit interface required at %C"); | |
5133 | return MATCH_ERROR; | |
5134 | } | |
5135 | ||
524af0d6 | 5136 | if (!gfc_notify_std (GFC_STD_F2003, "Procedure pointer component at %C")) |
3212c187 SK |
5137 | return MATCH_ERROR; |
5138 | ||
713485cc JW |
5139 | /* Match PPC names. */ |
5140 | ts = current_ts; | |
5141 | for(num=1;;num++) | |
5142 | { | |
5143 | m = gfc_match_name (name); | |
5144 | if (m == MATCH_NO) | |
5145 | goto syntax; | |
5146 | else if (m == MATCH_ERROR) | |
5147 | return m; | |
5148 | ||
524af0d6 | 5149 | if (!gfc_add_component (gfc_current_block(), name, &c)) |
713485cc JW |
5150 | return MATCH_ERROR; |
5151 | ||
5152 | /* Add current_attr to the symbol attributes. */ | |
524af0d6 | 5153 | if (!gfc_copy_attr (&c->attr, ¤t_attr, NULL)) |
713485cc JW |
5154 | return MATCH_ERROR; |
5155 | ||
524af0d6 | 5156 | if (!gfc_add_external (&c->attr, NULL)) |
713485cc JW |
5157 | return MATCH_ERROR; |
5158 | ||
524af0d6 | 5159 | if (!gfc_add_proc (&c->attr, name, NULL)) |
713485cc JW |
5160 | return MATCH_ERROR; |
5161 | ||
2be03814 TB |
5162 | if (num == 1) |
5163 | c->tb = tb; | |
5164 | else | |
5165 | { | |
5166 | c->tb = XCNEW (gfc_typebound_proc); | |
5167 | c->tb->where = gfc_current_locus; | |
5168 | *c->tb = *tb; | |
5169 | } | |
90661f26 | 5170 | |
713485cc JW |
5171 | /* Set interface. */ |
5172 | if (proc_if != NULL) | |
5173 | { | |
5174 | c->ts.interface = proc_if; | |
5175 | c->attr.untyped = 1; | |
5176 | c->attr.if_source = IFSRC_IFBODY; | |
5177 | } | |
5178 | else if (ts.type != BT_UNKNOWN) | |
5179 | { | |
5180 | c->ts = ts; | |
5181 | c->ts.interface = gfc_new_symbol ("", gfc_current_ns); | |
d7fee03d | 5182 | c->ts.interface->result = c->ts.interface; |
713485cc | 5183 | c->ts.interface->ts = ts; |
d91909c0 | 5184 | c->ts.interface->attr.flavor = FL_PROCEDURE; |
713485cc | 5185 | c->ts.interface->attr.function = 1; |
d91909c0 | 5186 | c->attr.function = 1; |
713485cc JW |
5187 | c->attr.if_source = IFSRC_UNKNOWN; |
5188 | } | |
5189 | ||
5190 | if (gfc_match (" =>") == MATCH_YES) | |
5191 | { | |
80f95228 | 5192 | m = match_pointer_init (&initializer, 1); |
713485cc JW |
5193 | if (m != MATCH_YES) |
5194 | { | |
5195 | gfc_free_expr (initializer); | |
5196 | return m; | |
5197 | } | |
5198 | c->initializer = initializer; | |
5199 | } | |
5200 | ||
5201 | if (gfc_match_eos () == MATCH_YES) | |
5202 | return MATCH_YES; | |
5203 | if (gfc_match_char (',') != MATCH_YES) | |
5204 | goto syntax; | |
5205 | } | |
5206 | ||
5207 | syntax: | |
5208 | gfc_error ("Syntax error in procedure pointer component at %C"); | |
5209 | return MATCH_ERROR; | |
5210 | } | |
5211 | ||
5212 | ||
69773742 JW |
5213 | /* Match a PROCEDURE declaration inside an interface (R1206). */ |
5214 | ||
5215 | static match | |
5216 | match_procedure_in_interface (void) | |
5217 | { | |
5218 | match m; | |
5219 | gfc_symbol *sym; | |
5220 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
a6fcd41a | 5221 | locus old_locus; |
69773742 JW |
5222 | |
5223 | if (current_interface.type == INTERFACE_NAMELESS | |
5224 | || current_interface.type == INTERFACE_ABSTRACT) | |
5225 | { | |
5226 | gfc_error ("PROCEDURE at %C must be in a generic interface"); | |
5227 | return MATCH_ERROR; | |
5228 | } | |
5229 | ||
a6fcd41a TB |
5230 | /* Check if the F2008 optional double colon appears. */ |
5231 | gfc_gobble_whitespace (); | |
5232 | old_locus = gfc_current_locus; | |
5233 | if (gfc_match ("::") == MATCH_YES) | |
5234 | { | |
524af0d6 JB |
5235 | if (!gfc_notify_std (GFC_STD_F2008, "double colon in " |
5236 | "MODULE PROCEDURE statement at %L", &old_locus)) | |
a6fcd41a TB |
5237 | return MATCH_ERROR; |
5238 | } | |
5239 | else | |
5240 | gfc_current_locus = old_locus; | |
5241 | ||
69773742 JW |
5242 | for(;;) |
5243 | { | |
5244 | m = gfc_match_name (name); | |
5245 | if (m == MATCH_NO) | |
5246 | goto syntax; | |
5247 | else if (m == MATCH_ERROR) | |
5248 | return m; | |
5249 | if (gfc_get_symbol (name, gfc_current_ns->parent, &sym)) | |
5250 | return MATCH_ERROR; | |
5251 | ||
524af0d6 | 5252 | if (!gfc_add_interface (sym)) |
69773742 JW |
5253 | return MATCH_ERROR; |
5254 | ||
69773742 JW |
5255 | if (gfc_match_eos () == MATCH_YES) |
5256 | break; | |
5257 | if (gfc_match_char (',') != MATCH_YES) | |
5258 | goto syntax; | |
5259 | } | |
5260 | ||
5261 | return MATCH_YES; | |
5262 | ||
5263 | syntax: | |
5264 | gfc_error ("Syntax error in PROCEDURE statement at %C"); | |
5265 | return MATCH_ERROR; | |
5266 | } | |
5267 | ||
5268 | ||
5269 | /* General matcher for PROCEDURE declarations. */ | |
5270 | ||
30b608eb DK |
5271 | static match match_procedure_in_type (void); |
5272 | ||
69773742 JW |
5273 | match |
5274 | gfc_match_procedure (void) | |
5275 | { | |
5276 | match m; | |
5277 | ||
5278 | switch (gfc_current_state ()) | |
5279 | { | |
5280 | case COMP_NONE: | |
5281 | case COMP_PROGRAM: | |
5282 | case COMP_MODULE: | |
5283 | case COMP_SUBROUTINE: | |
5284 | case COMP_FUNCTION: | |
3547d57e | 5285 | case COMP_BLOCK: |
69773742 JW |
5286 | m = match_procedure_decl (); |
5287 | break; | |
5288 | case COMP_INTERFACE: | |
5289 | m = match_procedure_in_interface (); | |
5290 | break; | |
5291 | case COMP_DERIVED: | |
713485cc JW |
5292 | m = match_ppc_decl (); |
5293 | break; | |
30b608eb DK |
5294 | case COMP_DERIVED_CONTAINS: |
5295 | m = match_procedure_in_type (); | |
5296 | break; | |
69773742 JW |
5297 | default: |
5298 | return MATCH_NO; | |
5299 | } | |
5300 | ||
5301 | if (m != MATCH_YES) | |
5302 | return m; | |
5303 | ||
524af0d6 | 5304 | if (!gfc_notify_std (GFC_STD_F2003, "PROCEDURE statement at %C")) |
69773742 JW |
5305 | return MATCH_ERROR; |
5306 | ||
5307 | return m; | |
5308 | } | |
5309 | ||
5310 | ||
c3005b0f DK |
5311 | /* Warn if a matched procedure has the same name as an intrinsic; this is |
5312 | simply a wrapper around gfc_warn_intrinsic_shadow that interprets the current | |
5313 | parser-state-stack to find out whether we're in a module. */ | |
5314 | ||
5315 | static void | |
73e42eef | 5316 | do_warn_intrinsic_shadow (const gfc_symbol* sym, bool func) |
c3005b0f DK |
5317 | { |
5318 | bool in_module; | |
5319 | ||
5320 | in_module = (gfc_state_stack->previous | |
5321 | && gfc_state_stack->previous->state == COMP_MODULE); | |
5322 | ||
5323 | gfc_warn_intrinsic_shadow (sym, in_module, func); | |
5324 | } | |
5325 | ||
5326 | ||
6de9cd9a DN |
5327 | /* Match a function declaration. */ |
5328 | ||
5329 | match | |
5330 | gfc_match_function_decl (void) | |
5331 | { | |
5332 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
5333 | gfc_symbol *sym, *result; | |
5334 | locus old_loc; | |
5335 | match m; | |
a8b3b0b6 | 5336 | match suffix_match; |
f5acf0f2 | 5337 | match found_match; /* Status returned by match func. */ |
6de9cd9a DN |
5338 | |
5339 | if (gfc_current_state () != COMP_NONE | |
5340 | && gfc_current_state () != COMP_INTERFACE | |
5341 | && gfc_current_state () != COMP_CONTAINS) | |
5342 | return MATCH_NO; | |
5343 | ||
5344 | gfc_clear_ts (¤t_ts); | |
5345 | ||
63645982 | 5346 | old_loc = gfc_current_locus; |
6de9cd9a | 5347 | |
1c8bcdf7 | 5348 | m = gfc_match_prefix (¤t_ts); |
6de9cd9a DN |
5349 | if (m != MATCH_YES) |
5350 | { | |
63645982 | 5351 | gfc_current_locus = old_loc; |
6de9cd9a DN |
5352 | return m; |
5353 | } | |
5354 | ||
5355 | if (gfc_match ("function% %n", name) != MATCH_YES) | |
5356 | { | |
63645982 | 5357 | gfc_current_locus = old_loc; |
6de9cd9a DN |
5358 | return MATCH_NO; |
5359 | } | |
1a492601 | 5360 | if (get_proc_name (name, &sym, false)) |
6de9cd9a | 5361 | return MATCH_ERROR; |
3070bab4 | 5362 | |
524af0d6 | 5363 | if (add_hidden_procptr_result (sym)) |
3070bab4 JW |
5364 | sym = sym->result; |
5365 | ||
6de9cd9a DN |
5366 | gfc_new_block = sym; |
5367 | ||
5368 | m = gfc_match_formal_arglist (sym, 0, 0); | |
5369 | if (m == MATCH_NO) | |
2b9a33ae TS |
5370 | { |
5371 | gfc_error ("Expected formal argument list in function " | |
636dff67 | 5372 | "definition at %C"); |
2b9a33ae TS |
5373 | m = MATCH_ERROR; |
5374 | goto cleanup; | |
5375 | } | |
6de9cd9a DN |
5376 | else if (m == MATCH_ERROR) |
5377 | goto cleanup; | |
5378 | ||
5379 | result = NULL; | |
5380 | ||
a8b3b0b6 CR |
5381 | /* According to the draft, the bind(c) and result clause can |
5382 | come in either order after the formal_arg_list (i.e., either | |
5383 | can be first, both can exist together or by themselves or neither | |
5384 | one). Therefore, the match_result can't match the end of the | |
5385 | string, and check for the bind(c) or result clause in either order. */ | |
5386 | found_match = gfc_match_eos (); | |
5387 | ||
5388 | /* Make sure that it isn't already declared as BIND(C). If it is, it | |
5389 | must have been marked BIND(C) with a BIND(C) attribute and that is | |
5390 | not allowed for procedures. */ | |
5391 | if (sym->attr.is_bind_c == 1) | |
5392 | { | |
5393 | sym->attr.is_bind_c = 0; | |
5394 | if (sym->old_symbol != NULL) | |
5395 | gfc_error_now ("BIND(C) attribute at %L can only be used for " | |
5396 | "variables or common blocks", | |
5397 | &(sym->old_symbol->declared_at)); | |
5398 | else | |
5399 | gfc_error_now ("BIND(C) attribute at %L can only be used for " | |
5400 | "variables or common blocks", &gfc_current_locus); | |
6de9cd9a DN |
5401 | } |
5402 | ||
a8b3b0b6 | 5403 | if (found_match != MATCH_YES) |
6de9cd9a | 5404 | { |
a8b3b0b6 CR |
5405 | /* If we haven't found the end-of-statement, look for a suffix. */ |
5406 | suffix_match = gfc_match_suffix (sym, &result); | |
5407 | if (suffix_match == MATCH_YES) | |
5408 | /* Need to get the eos now. */ | |
5409 | found_match = gfc_match_eos (); | |
5410 | else | |
5411 | found_match = suffix_match; | |
6de9cd9a DN |
5412 | } |
5413 | ||
a8b3b0b6 CR |
5414 | if(found_match != MATCH_YES) |
5415 | m = MATCH_ERROR; | |
6de9cd9a DN |
5416 | else |
5417 | { | |
a8b3b0b6 CR |
5418 | /* Make changes to the symbol. */ |
5419 | m = MATCH_ERROR; | |
f5acf0f2 | 5420 | |
524af0d6 | 5421 | if (!gfc_add_function (&sym->attr, sym->name, NULL)) |
a8b3b0b6 | 5422 | goto cleanup; |
f5acf0f2 | 5423 | |
524af0d6 JB |
5424 | if (!gfc_missing_attr (&sym->attr, NULL) |
5425 | || !copy_prefix (&sym->attr, &sym->declared_at)) | |
a8b3b0b6 | 5426 | goto cleanup; |
6de9cd9a | 5427 | |
a99d95a2 | 5428 | /* Delay matching the function characteristics until after the |
1c8bcdf7 | 5429 | specification block by signalling kind=-1. */ |
a99d95a2 PT |
5430 | sym->declared_at = old_loc; |
5431 | if (current_ts.type != BT_UNKNOWN) | |
5432 | current_ts.kind = -1; | |
5433 | else | |
5434 | current_ts.kind = 0; | |
1c8bcdf7 | 5435 | |
a8b3b0b6 CR |
5436 | if (result == NULL) |
5437 | { | |
6de7294f | 5438 | if (current_ts.type != BT_UNKNOWN |
524af0d6 | 5439 | && !gfc_add_type (sym, ¤t_ts, &gfc_current_locus)) |
6de7294f | 5440 | goto cleanup; |
a8b3b0b6 CR |
5441 | sym->result = sym; |
5442 | } | |
5443 | else | |
5444 | { | |
6de7294f | 5445 | if (current_ts.type != BT_UNKNOWN |
524af0d6 | 5446 | && !gfc_add_type (result, ¤t_ts, &gfc_current_locus)) |
6de7294f | 5447 | goto cleanup; |
a8b3b0b6 CR |
5448 | sym->result = result; |
5449 | } | |
5450 | ||
c3005b0f | 5451 | /* Warn if this procedure has the same name as an intrinsic. */ |
73e42eef | 5452 | do_warn_intrinsic_shadow (sym, true); |
c3005b0f | 5453 | |
a8b3b0b6 CR |
5454 | return MATCH_YES; |
5455 | } | |
6de9cd9a DN |
5456 | |
5457 | cleanup: | |
63645982 | 5458 | gfc_current_locus = old_loc; |
6de9cd9a DN |
5459 | return m; |
5460 | } | |
5461 | ||
636dff67 SK |
5462 | |
5463 | /* This is mostly a copy of parse.c(add_global_procedure) but modified to | |
5464 | pass the name of the entry, rather than the gfc_current_block name, and | |
5465 | to return false upon finding an existing global entry. */ | |
68ea355b PT |
5466 | |
5467 | static bool | |
3a43b5b3 TB |
5468 | add_global_entry (const char *name, const char *binding_label, bool sub, |
5469 | locus *where) | |
68ea355b PT |
5470 | { |
5471 | gfc_gsymbol *s; | |
32e8bb8e | 5472 | enum gfc_symbol_type type; |
68ea355b | 5473 | |
7389bce6 | 5474 | type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION; |
68ea355b | 5475 | |
f11de7c5 TB |
5476 | /* Only in Fortran 2003: For procedures with a binding label also the Fortran |
5477 | name is a global identifier. */ | |
5478 | if (!binding_label || gfc_notification_std (GFC_STD_F2008)) | |
68ea355b | 5479 | { |
f11de7c5 TB |
5480 | s = gfc_get_gsymbol (name); |
5481 | ||
5482 | if (s->defined || (s->type != GSYM_UNKNOWN && s->type != type)) | |
5483 | { | |
3a43b5b3 | 5484 | gfc_global_used (s, where); |
f11de7c5 TB |
5485 | return false; |
5486 | } | |
5487 | else | |
5488 | { | |
5489 | s->type = type; | |
77f8682b | 5490 | s->sym_name = name; |
3a43b5b3 | 5491 | s->where = *where; |
f11de7c5 TB |
5492 | s->defined = 1; |
5493 | s->ns = gfc_current_ns; | |
5494 | } | |
68ea355b | 5495 | } |
f11de7c5 TB |
5496 | |
5497 | /* Don't add the symbol multiple times. */ | |
5498 | if (binding_label | |
5499 | && (!gfc_notification_std (GFC_STD_F2008) | |
5500 | || strcmp (name, binding_label) != 0)) | |
5501 | { | |
5502 | s = gfc_get_gsymbol (binding_label); | |
5503 | ||
5504 | if (s->defined || (s->type != GSYM_UNKNOWN && s->type != type)) | |
5505 | { | |
3a43b5b3 | 5506 | gfc_global_used (s, where); |
f11de7c5 TB |
5507 | return false; |
5508 | } | |
5509 | else | |
5510 | { | |
5511 | s->type = type; | |
77f8682b | 5512 | s->sym_name = name; |
f11de7c5 | 5513 | s->binding_label = binding_label; |
3a43b5b3 | 5514 | s->where = *where; |
f11de7c5 TB |
5515 | s->defined = 1; |
5516 | s->ns = gfc_current_ns; | |
5517 | } | |
5518 | } | |
5519 | ||
5520 | return true; | |
68ea355b | 5521 | } |
6de9cd9a | 5522 | |
636dff67 | 5523 | |
6de9cd9a DN |
5524 | /* Match an ENTRY statement. */ |
5525 | ||
5526 | match | |
5527 | gfc_match_entry (void) | |
5528 | { | |
3d79abbd PB |
5529 | gfc_symbol *proc; |
5530 | gfc_symbol *result; | |
5531 | gfc_symbol *entry; | |
6de9cd9a DN |
5532 | char name[GFC_MAX_SYMBOL_LEN + 1]; |
5533 | gfc_compile_state state; | |
5534 | match m; | |
3d79abbd | 5535 | gfc_entry_list *el; |
c96cfa49 | 5536 | locus old_loc; |
1a492601 | 5537 | bool module_procedure; |
bc3e7a8c TB |
5538 | char peek_char; |
5539 | match is_bind_c; | |
6de9cd9a DN |
5540 | |
5541 | m = gfc_match_name (name); | |
5542 | if (m != MATCH_YES) | |
5543 | return m; | |
5544 | ||
524af0d6 | 5545 | if (!gfc_notify_std (GFC_STD_F2008_OBS, "ENTRY statement at %C")) |
58fc89f6 TB |
5546 | return MATCH_ERROR; |
5547 | ||
3d79abbd | 5548 | state = gfc_current_state (); |
4c93c95a | 5549 | if (state != COMP_SUBROUTINE && state != COMP_FUNCTION) |
3d79abbd | 5550 | { |
4c93c95a FXC |
5551 | switch (state) |
5552 | { | |
5553 | case COMP_PROGRAM: | |
5554 | gfc_error ("ENTRY statement at %C cannot appear within a PROGRAM"); | |
5555 | break; | |
5556 | case COMP_MODULE: | |
5557 | gfc_error ("ENTRY statement at %C cannot appear within a MODULE"); | |
5558 | break; | |
5559 | case COMP_BLOCK_DATA: | |
636dff67 SK |
5560 | gfc_error ("ENTRY statement at %C cannot appear within " |
5561 | "a BLOCK DATA"); | |
4c93c95a FXC |
5562 | break; |
5563 | case COMP_INTERFACE: | |
636dff67 SK |
5564 | gfc_error ("ENTRY statement at %C cannot appear within " |
5565 | "an INTERFACE"); | |
4c93c95a FXC |
5566 | break; |
5567 | case COMP_DERIVED: | |
636dff67 SK |
5568 | gfc_error ("ENTRY statement at %C cannot appear within " |
5569 | "a DERIVED TYPE block"); | |
4c93c95a FXC |
5570 | break; |
5571 | case COMP_IF: | |
636dff67 SK |
5572 | gfc_error ("ENTRY statement at %C cannot appear within " |
5573 | "an IF-THEN block"); | |
4c93c95a FXC |
5574 | break; |
5575 | case COMP_DO: | |
8c6a85e3 | 5576 | case COMP_DO_CONCURRENT: |
636dff67 SK |
5577 | gfc_error ("ENTRY statement at %C cannot appear within " |
5578 | "a DO block"); | |
4c93c95a FXC |
5579 | break; |
5580 | case COMP_SELECT: | |
636dff67 SK |
5581 | gfc_error ("ENTRY statement at %C cannot appear within " |
5582 | "a SELECT block"); | |
4c93c95a FXC |
5583 | break; |
5584 | case COMP_FORALL: | |
636dff67 SK |
5585 | gfc_error ("ENTRY statement at %C cannot appear within " |
5586 | "a FORALL block"); | |
4c93c95a FXC |
5587 | break; |
5588 | case COMP_WHERE: | |
636dff67 SK |
5589 | gfc_error ("ENTRY statement at %C cannot appear within " |
5590 | "a WHERE block"); | |
4c93c95a FXC |
5591 | break; |
5592 | case COMP_CONTAINS: | |
636dff67 SK |
5593 | gfc_error ("ENTRY statement at %C cannot appear within " |
5594 | "a contained subprogram"); | |
4c93c95a FXC |
5595 | break; |
5596 | default: | |
5597 | gfc_internal_error ("gfc_match_entry(): Bad state"); | |
5598 | } | |
3d79abbd PB |
5599 | return MATCH_ERROR; |
5600 | } | |
5601 | ||
1a492601 | 5602 | module_procedure = gfc_current_ns->parent != NULL |
636dff67 SK |
5603 | && gfc_current_ns->parent->proc_name |
5604 | && gfc_current_ns->parent->proc_name->attr.flavor | |
5605 | == FL_MODULE; | |
1a492601 | 5606 | |
3d79abbd PB |
5607 | if (gfc_current_ns->parent != NULL |
5608 | && gfc_current_ns->parent->proc_name | |
1a492601 | 5609 | && !module_procedure) |
3d79abbd PB |
5610 | { |
5611 | gfc_error("ENTRY statement at %C cannot appear in a " | |
5612 | "contained procedure"); | |
5613 | return MATCH_ERROR; | |
5614 | } | |
5615 | ||
1a492601 PT |
5616 | /* Module function entries need special care in get_proc_name |
5617 | because previous references within the function will have | |
5618 | created symbols attached to the current namespace. */ | |
5619 | if (get_proc_name (name, &entry, | |
5620 | gfc_current_ns->parent != NULL | |
ecd3b73c | 5621 | && module_procedure)) |
6de9cd9a DN |
5622 | return MATCH_ERROR; |
5623 | ||
3d79abbd PB |
5624 | proc = gfc_current_block (); |
5625 | ||
bc3e7a8c TB |
5626 | /* Make sure that it isn't already declared as BIND(C). If it is, it |
5627 | must have been marked BIND(C) with a BIND(C) attribute and that is | |
5628 | not allowed for procedures. */ | |
5629 | if (entry->attr.is_bind_c == 1) | |
5630 | { | |
5631 | entry->attr.is_bind_c = 0; | |
5632 | if (entry->old_symbol != NULL) | |
5633 | gfc_error_now ("BIND(C) attribute at %L can only be used for " | |
5634 | "variables or common blocks", | |
5635 | &(entry->old_symbol->declared_at)); | |
5636 | else | |
5637 | gfc_error_now ("BIND(C) attribute at %L can only be used for " | |
5638 | "variables or common blocks", &gfc_current_locus); | |
5639 | } | |
f5acf0f2 | 5640 | |
bc3e7a8c TB |
5641 | /* Check what next non-whitespace character is so we can tell if there |
5642 | is the required parens if we have a BIND(C). */ | |
3a43b5b3 | 5643 | old_loc = gfc_current_locus; |
bc3e7a8c | 5644 | gfc_gobble_whitespace (); |
8fc541d3 | 5645 | peek_char = gfc_peek_ascii_char (); |
bc3e7a8c | 5646 | |
3d79abbd | 5647 | if (state == COMP_SUBROUTINE) |
6de9cd9a | 5648 | { |
6de9cd9a DN |
5649 | m = gfc_match_formal_arglist (entry, 0, 1); |
5650 | if (m != MATCH_YES) | |
5651 | return MATCH_ERROR; | |
5652 | ||
1eabf70a TB |
5653 | /* Call gfc_match_bind_c with allow_binding_name = true as ENTRY can |
5654 | never be an internal procedure. */ | |
5655 | is_bind_c = gfc_match_bind_c (entry, true); | |
bc3e7a8c TB |
5656 | if (is_bind_c == MATCH_ERROR) |
5657 | return MATCH_ERROR; | |
5658 | if (is_bind_c == MATCH_YES) | |
5659 | { | |
5660 | if (peek_char != '(') | |
5661 | { | |
5662 | gfc_error ("Missing required parentheses before BIND(C) at %C"); | |
5663 | return MATCH_ERROR; | |
5664 | } | |
524af0d6 JB |
5665 | if (!gfc_add_is_bind_c (&(entry->attr), entry->name, |
5666 | &(entry->declared_at), 1)) | |
bc3e7a8c TB |
5667 | return MATCH_ERROR; |
5668 | } | |
5669 | ||
f11de7c5 | 5670 | if (!gfc_current_ns->parent |
3a43b5b3 TB |
5671 | && !add_global_entry (name, entry->binding_label, true, |
5672 | &old_loc)) | |
f11de7c5 TB |
5673 | return MATCH_ERROR; |
5674 | ||
5675 | /* An entry in a subroutine. */ | |
524af0d6 JB |
5676 | if (!gfc_add_entry (&entry->attr, entry->name, NULL) |
5677 | || !gfc_add_subroutine (&entry->attr, entry->name, NULL)) | |
6de9cd9a | 5678 | return MATCH_ERROR; |
3d79abbd PB |
5679 | } |
5680 | else | |
5681 | { | |
c96cfa49 | 5682 | /* An entry in a function. |
636dff67 SK |
5683 | We need to take special care because writing |
5684 | ENTRY f() | |
5685 | as | |
5686 | ENTRY f | |
5687 | is allowed, whereas | |
5688 | ENTRY f() RESULT (r) | |
5689 | can't be written as | |
5690 | ENTRY f RESULT (r). */ | |
c96cfa49 TS |
5691 | if (gfc_match_eos () == MATCH_YES) |
5692 | { | |
5693 | gfc_current_locus = old_loc; | |
5694 | /* Match the empty argument list, and add the interface to | |
5695 | the symbol. */ | |
5696 | m = gfc_match_formal_arglist (entry, 0, 1); | |
5697 | } | |
5698 | else | |
5699 | m = gfc_match_formal_arglist (entry, 0, 0); | |
5700 | ||
6de9cd9a DN |
5701 | if (m != MATCH_YES) |
5702 | return MATCH_ERROR; | |
5703 | ||
6de9cd9a DN |
5704 | result = NULL; |
5705 | ||
5706 | if (gfc_match_eos () == MATCH_YES) | |
5707 | { | |
524af0d6 JB |
5708 | if (!gfc_add_entry (&entry->attr, entry->name, NULL) |
5709 | || !gfc_add_function (&entry->attr, entry->name, NULL)) | |
6de9cd9a DN |
5710 | return MATCH_ERROR; |
5711 | ||
d198b59a | 5712 | entry->result = entry; |
6de9cd9a DN |
5713 | } |
5714 | else | |
5715 | { | |
bc3e7a8c | 5716 | m = gfc_match_suffix (entry, &result); |
6de9cd9a DN |
5717 | if (m == MATCH_NO) |
5718 | gfc_syntax_error (ST_ENTRY); | |
5719 | if (m != MATCH_YES) | |
5720 | return MATCH_ERROR; | |
5721 | ||
bc3e7a8c TB |
5722 | if (result) |
5723 | { | |
524af0d6 JB |
5724 | if (!gfc_add_result (&result->attr, result->name, NULL) |
5725 | || !gfc_add_entry (&entry->attr, result->name, NULL) | |
5726 | || !gfc_add_function (&entry->attr, result->name, NULL)) | |
bc3e7a8c TB |
5727 | return MATCH_ERROR; |
5728 | entry->result = result; | |
5729 | } | |
5730 | else | |
5731 | { | |
524af0d6 JB |
5732 | if (!gfc_add_entry (&entry->attr, entry->name, NULL) |
5733 | || !gfc_add_function (&entry->attr, entry->name, NULL)) | |
bc3e7a8c TB |
5734 | return MATCH_ERROR; |
5735 | entry->result = entry; | |
5736 | } | |
6de9cd9a | 5737 | } |
f11de7c5 TB |
5738 | |
5739 | if (!gfc_current_ns->parent | |
3a43b5b3 TB |
5740 | && !add_global_entry (name, entry->binding_label, false, |
5741 | &old_loc)) | |
f11de7c5 | 5742 | return MATCH_ERROR; |
6de9cd9a DN |
5743 | } |
5744 | ||
5745 | if (gfc_match_eos () != MATCH_YES) | |
5746 | { | |
5747 | gfc_syntax_error (ST_ENTRY); | |
5748 | return MATCH_ERROR; | |
5749 | } | |
5750 | ||
3d79abbd PB |
5751 | entry->attr.recursive = proc->attr.recursive; |
5752 | entry->attr.elemental = proc->attr.elemental; | |
5753 | entry->attr.pure = proc->attr.pure; | |
6de9cd9a | 5754 | |
3d79abbd PB |
5755 | el = gfc_get_entry_list (); |
5756 | el->sym = entry; | |
5757 | el->next = gfc_current_ns->entries; | |
5758 | gfc_current_ns->entries = el; | |
5759 | if (el->next) | |
5760 | el->id = el->next->id + 1; | |
5761 | else | |
5762 | el->id = 1; | |
6de9cd9a | 5763 | |
3d79abbd PB |
5764 | new_st.op = EXEC_ENTRY; |
5765 | new_st.ext.entry = el; | |
5766 | ||
5767 | return MATCH_YES; | |
6de9cd9a DN |
5768 | } |
5769 | ||
5770 | ||
5771 | /* Match a subroutine statement, including optional prefixes. */ | |
5772 | ||
5773 | match | |
5774 | gfc_match_subroutine (void) | |
5775 | { | |
5776 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
5777 | gfc_symbol *sym; | |
5778 | match m; | |
a8b3b0b6 CR |
5779 | match is_bind_c; |
5780 | char peek_char; | |
1eabf70a | 5781 | bool allow_binding_name; |
6de9cd9a DN |
5782 | |
5783 | if (gfc_current_state () != COMP_NONE | |
5784 | && gfc_current_state () != COMP_INTERFACE | |
5785 | && gfc_current_state () != COMP_CONTAINS) | |
5786 | return MATCH_NO; | |
5787 | ||
1c8bcdf7 | 5788 | m = gfc_match_prefix (NULL); |
6de9cd9a DN |
5789 | if (m != MATCH_YES) |
5790 | return m; | |
5791 | ||
5792 | m = gfc_match ("subroutine% %n", name); | |
5793 | if (m != MATCH_YES) | |
5794 | return m; | |
5795 | ||
1a492601 | 5796 | if (get_proc_name (name, &sym, false)) |
6de9cd9a | 5797 | return MATCH_ERROR; |
3070bab4 | 5798 | |
7fcd5ad5 | 5799 | /* Set declared_at as it might point to, e.g., a PUBLIC statement, if |
1cc0e193 | 5800 | the symbol existed before. */ |
7fcd5ad5 TB |
5801 | sym->declared_at = gfc_current_locus; |
5802 | ||
524af0d6 | 5803 | if (add_hidden_procptr_result (sym)) |
3070bab4 JW |
5804 | sym = sym->result; |
5805 | ||
6de9cd9a DN |
5806 | gfc_new_block = sym; |
5807 | ||
a8b3b0b6 | 5808 | /* Check what next non-whitespace character is so we can tell if there |
bc3e7a8c | 5809 | is the required parens if we have a BIND(C). */ |
a8b3b0b6 | 5810 | gfc_gobble_whitespace (); |
8fc541d3 | 5811 | peek_char = gfc_peek_ascii_char (); |
f5acf0f2 | 5812 | |
524af0d6 | 5813 | if (!gfc_add_subroutine (&sym->attr, sym->name, NULL)) |
6de9cd9a DN |
5814 | return MATCH_ERROR; |
5815 | ||
5816 | if (gfc_match_formal_arglist (sym, 0, 1) != MATCH_YES) | |
5817 | return MATCH_ERROR; | |
5818 | ||
a8b3b0b6 CR |
5819 | /* Make sure that it isn't already declared as BIND(C). If it is, it |
5820 | must have been marked BIND(C) with a BIND(C) attribute and that is | |
5821 | not allowed for procedures. */ | |
5822 | if (sym->attr.is_bind_c == 1) | |
5823 | { | |
5824 | sym->attr.is_bind_c = 0; | |
5825 | if (sym->old_symbol != NULL) | |
5826 | gfc_error_now ("BIND(C) attribute at %L can only be used for " | |
5827 | "variables or common blocks", | |
5828 | &(sym->old_symbol->declared_at)); | |
5829 | else | |
5830 | gfc_error_now ("BIND(C) attribute at %L can only be used for " | |
5831 | "variables or common blocks", &gfc_current_locus); | |
5832 | } | |
1eabf70a TB |
5833 | |
5834 | /* C binding names are not allowed for internal procedures. */ | |
5835 | if (gfc_current_state () == COMP_CONTAINS | |
5836 | && sym->ns->proc_name->attr.flavor != FL_MODULE) | |
5837 | allow_binding_name = false; | |
5838 | else | |
5839 | allow_binding_name = true; | |
5840 | ||
a8b3b0b6 CR |
5841 | /* Here, we are just checking if it has the bind(c) attribute, and if |
5842 | so, then we need to make sure it's all correct. If it doesn't, | |
5843 | we still need to continue matching the rest of the subroutine line. */ | |
1eabf70a | 5844 | is_bind_c = gfc_match_bind_c (sym, allow_binding_name); |
a8b3b0b6 CR |
5845 | if (is_bind_c == MATCH_ERROR) |
5846 | { | |
5847 | /* There was an attempt at the bind(c), but it was wrong. An | |
5848 | error message should have been printed w/in the gfc_match_bind_c | |
5849 | so here we'll just return the MATCH_ERROR. */ | |
5850 | return MATCH_ERROR; | |
5851 | } | |
5852 | ||
5853 | if (is_bind_c == MATCH_YES) | |
5854 | { | |
1eabf70a | 5855 | /* The following is allowed in the Fortran 2008 draft. */ |
01f4fff1 | 5856 | if (gfc_current_state () == COMP_CONTAINS |
1eabf70a | 5857 | && sym->ns->proc_name->attr.flavor != FL_MODULE |
524af0d6 JB |
5858 | && !gfc_notify_std (GFC_STD_F2008, "BIND(C) attribute " |
5859 | "at %L may not be specified for an internal " | |
5860 | "procedure", &gfc_current_locus)) | |
1eabf70a TB |
5861 | return MATCH_ERROR; |
5862 | ||
a8b3b0b6 CR |
5863 | if (peek_char != '(') |
5864 | { | |
5865 | gfc_error ("Missing required parentheses before BIND(C) at %C"); | |
5866 | return MATCH_ERROR; | |
5867 | } | |
524af0d6 JB |
5868 | if (!gfc_add_is_bind_c (&(sym->attr), sym->name, |
5869 | &(sym->declared_at), 1)) | |
a8b3b0b6 CR |
5870 | return MATCH_ERROR; |
5871 | } | |
f5acf0f2 | 5872 | |
6de9cd9a DN |
5873 | if (gfc_match_eos () != MATCH_YES) |
5874 | { | |
5875 | gfc_syntax_error (ST_SUBROUTINE); | |
5876 | return MATCH_ERROR; | |
5877 | } | |
5878 | ||
524af0d6 | 5879 | if (!copy_prefix (&sym->attr, &sym->declared_at)) |
6de9cd9a DN |
5880 | return MATCH_ERROR; |
5881 | ||
c3005b0f | 5882 | /* Warn if it has the same name as an intrinsic. */ |
73e42eef | 5883 | do_warn_intrinsic_shadow (sym, false); |
c3005b0f | 5884 | |
6de9cd9a DN |
5885 | return MATCH_YES; |
5886 | } | |
5887 | ||
5888 | ||
3b37ccd4 FXC |
5889 | /* Check that the NAME identifier in a BIND attribute or statement |
5890 | is conform to C identifier rules. */ | |
5891 | ||
5892 | match | |
5893 | check_bind_name_identifier (char **name) | |
5894 | { | |
5895 | char *n = *name, *p; | |
5896 | ||
5897 | /* Remove leading spaces. */ | |
5898 | while (*n == ' ') | |
5899 | n++; | |
5900 | ||
5901 | /* On an empty string, free memory and set name to NULL. */ | |
5902 | if (*n == '\0') | |
5903 | { | |
5904 | free (*name); | |
5905 | *name = NULL; | |
5906 | return MATCH_YES; | |
5907 | } | |
5908 | ||
5909 | /* Remove trailing spaces. */ | |
5910 | p = n + strlen(n) - 1; | |
5911 | while (*p == ' ') | |
5912 | *(p--) = '\0'; | |
5913 | ||
5914 | /* Insert the identifier into the symbol table. */ | |
5915 | p = xstrdup (n); | |
5916 | free (*name); | |
5917 | *name = p; | |
5918 | ||
5919 | /* Now check that identifier is valid under C rules. */ | |
5920 | if (ISDIGIT (*p)) | |
5921 | { | |
5922 | gfc_error ("Invalid C identifier in NAME= specifier at %C"); | |
5923 | return MATCH_ERROR; | |
5924 | } | |
5925 | ||
5926 | for (; *p; p++) | |
5927 | if (!(ISALNUM (*p) || *p == '_' || *p == '$')) | |
5928 | { | |
5929 | gfc_error ("Invalid C identifier in NAME= specifier at %C"); | |
5930 | return MATCH_ERROR; | |
5931 | } | |
5932 | ||
5933 | return MATCH_YES; | |
5934 | } | |
5935 | ||
5936 | ||
a8b3b0b6 CR |
5937 | /* Match a BIND(C) specifier, with the optional 'name=' specifier if |
5938 | given, and set the binding label in either the given symbol (if not | |
86bf520d | 5939 | NULL), or in the current_ts. The symbol may be NULL because we may |
a8b3b0b6 CR |
5940 | encounter the BIND(C) before the declaration itself. Return |
5941 | MATCH_NO if what we're looking at isn't a BIND(C) specifier, | |
5942 | MATCH_ERROR if it is a BIND(C) clause but an error was encountered, | |
5943 | or MATCH_YES if the specifier was correct and the binding label and | |
5944 | bind(c) fields were set correctly for the given symbol or the | |
1eabf70a TB |
5945 | current_ts. If allow_binding_name is false, no binding name may be |
5946 | given. */ | |
a8b3b0b6 CR |
5947 | |
5948 | match | |
1eabf70a | 5949 | gfc_match_bind_c (gfc_symbol *sym, bool allow_binding_name) |
a8b3b0b6 | 5950 | { |
3b37ccd4 FXC |
5951 | char *binding_label = NULL; |
5952 | gfc_expr *e = NULL; | |
a8b3b0b6 | 5953 | |
f5acf0f2 | 5954 | /* Initialize the flag that specifies whether we encountered a NAME= |
a8b3b0b6 CR |
5955 | specifier or not. */ |
5956 | has_name_equals = 0; | |
5957 | ||
a8b3b0b6 CR |
5958 | /* This much we have to be able to match, in this order, if |
5959 | there is a bind(c) label. */ | |
5960 | if (gfc_match (" bind ( c ") != MATCH_YES) | |
5961 | return MATCH_NO; | |
5962 | ||
5963 | /* Now see if there is a binding label, or if we've reached the | |
5964 | end of the bind(c) attribute without one. */ | |
5965 | if (gfc_match_char (',') == MATCH_YES) | |
5966 | { | |
5967 | if (gfc_match (" name = ") != MATCH_YES) | |
5968 | { | |
5969 | gfc_error ("Syntax error in NAME= specifier for binding label " | |
5970 | "at %C"); | |
5971 | /* should give an error message here */ | |
5972 | return MATCH_ERROR; | |
5973 | } | |
5974 | ||
5975 | has_name_equals = 1; | |
5976 | ||
3b37ccd4 FXC |
5977 | if (gfc_match_init_expr (&e) != MATCH_YES) |
5978 | { | |
5979 | gfc_free_expr (e); | |
5980 | return MATCH_ERROR; | |
5981 | } | |
f5acf0f2 | 5982 | |
3b37ccd4 | 5983 | if (!gfc_simplify_expr(e, 0)) |
a8b3b0b6 | 5984 | { |
3b37ccd4 FXC |
5985 | gfc_error ("NAME= specifier at %C should be a constant expression"); |
5986 | gfc_free_expr (e); | |
5987 | return MATCH_ERROR; | |
a8b3b0b6 | 5988 | } |
3b37ccd4 FXC |
5989 | |
5990 | if (e->expr_type != EXPR_CONSTANT || e->ts.type != BT_CHARACTER | |
5991 | || e->ts.kind != gfc_default_character_kind || e->rank != 0) | |
a8b3b0b6 | 5992 | { |
3b37ccd4 FXC |
5993 | gfc_error ("NAME= specifier at %C should be a scalar of " |
5994 | "default character kind"); | |
5995 | gfc_free_expr(e); | |
5996 | return MATCH_ERROR; | |
a8b3b0b6 | 5997 | } |
3b37ccd4 FXC |
5998 | |
5999 | // Get a C string from the Fortran string constant | |
6000 | binding_label = gfc_widechar_to_char (e->value.character.string, | |
6001 | e->value.character.length); | |
6002 | gfc_free_expr(e); | |
6003 | ||
6004 | // Check that it is valid (old gfc_match_name_C) | |
6005 | if (check_bind_name_identifier (&binding_label) != MATCH_YES) | |
6006 | return MATCH_ERROR; | |
6007 | } | |
a8b3b0b6 CR |
6008 | |
6009 | /* Get the required right paren. */ | |
6010 | if (gfc_match_char (')') != MATCH_YES) | |
6011 | { | |
6012 | gfc_error ("Missing closing paren for binding label at %C"); | |
6013 | return MATCH_ERROR; | |
6014 | } | |
6015 | ||
1eabf70a TB |
6016 | if (has_name_equals && !allow_binding_name) |
6017 | { | |
6018 | gfc_error ("No binding name is allowed in BIND(C) at %C"); | |
6019 | return MATCH_ERROR; | |
6020 | } | |
6021 | ||
6022 | if (has_name_equals && sym != NULL && sym->attr.dummy) | |
6023 | { | |
6024 | gfc_error ("For dummy procedure %s, no binding name is " | |
6025 | "allowed in BIND(C) at %C", sym->name); | |
6026 | return MATCH_ERROR; | |
6027 | } | |
6028 | ||
6029 | ||
a8b3b0b6 CR |
6030 | /* Save the binding label to the symbol. If sym is null, we're |
6031 | probably matching the typespec attributes of a declaration and | |
6032 | haven't gotten the name yet, and therefore, no symbol yet. */ | |
62603fae | 6033 | if (binding_label) |
a8b3b0b6 CR |
6034 | { |
6035 | if (sym != NULL) | |
62603fae | 6036 | sym->binding_label = binding_label; |
a8b3b0b6 | 6037 | else |
62603fae | 6038 | curr_binding_label = binding_label; |
a8b3b0b6 | 6039 | } |
1eabf70a | 6040 | else if (allow_binding_name) |
a8b3b0b6 CR |
6041 | { |
6042 | /* No binding label, but if symbol isn't null, we | |
1eabf70a TB |
6043 | can set the label for it here. |
6044 | If name="" or allow_binding_name is false, no C binding name is | |
1cc0e193 | 6045 | created. */ |
a8b3b0b6 | 6046 | if (sym != NULL && sym->name != NULL && has_name_equals == 0) |
62603fae | 6047 | sym->binding_label = IDENTIFIER_POINTER (get_identifier (sym->name)); |
a8b3b0b6 | 6048 | } |
9e1d712c | 6049 | |
129d15a3 JW |
6050 | if (has_name_equals && gfc_current_state () == COMP_INTERFACE |
6051 | && current_interface.type == INTERFACE_ABSTRACT) | |
9e1d712c TB |
6052 | { |
6053 | gfc_error ("NAME not allowed on BIND(C) for ABSTRACT INTERFACE at %C"); | |
6054 | return MATCH_ERROR; | |
6055 | } | |
6056 | ||
a8b3b0b6 CR |
6057 | return MATCH_YES; |
6058 | } | |
6059 | ||
6060 | ||
1f2959f0 | 6061 | /* Return nonzero if we're currently compiling a contained procedure. */ |
ddc9ce91 TS |
6062 | |
6063 | static int | |
6064 | contained_procedure (void) | |
6065 | { | |
083de129 | 6066 | gfc_state_data *s = gfc_state_stack; |
ddc9ce91 | 6067 | |
083de129 TB |
6068 | if ((s->state == COMP_SUBROUTINE || s->state == COMP_FUNCTION) |
6069 | && s->previous != NULL && s->previous->state == COMP_CONTAINS) | |
6070 | return 1; | |
ddc9ce91 TS |
6071 | |
6072 | return 0; | |
6073 | } | |
6074 | ||
d51347f9 | 6075 | /* Set the kind of each enumerator. The kind is selected such that it is |
25d8f0a2 TS |
6076 | interoperable with the corresponding C enumeration type, making |
6077 | sure that -fshort-enums is honored. */ | |
6078 | ||
6079 | static void | |
6080 | set_enum_kind(void) | |
6081 | { | |
6082 | enumerator_history *current_history = NULL; | |
6083 | int kind; | |
6084 | int i; | |
6085 | ||
6086 | if (max_enum == NULL || enum_history == NULL) | |
6087 | return; | |
6088 | ||
cab129d1 | 6089 | if (!flag_short_enums) |
d51347f9 TB |
6090 | return; |
6091 | ||
25d8f0a2 TS |
6092 | i = 0; |
6093 | do | |
6094 | { | |
6095 | kind = gfc_integer_kinds[i++].kind; | |
6096 | } | |
d51347f9 | 6097 | while (kind < gfc_c_int_kind |
25d8f0a2 TS |
6098 | && gfc_check_integer_range (max_enum->initializer->value.integer, |
6099 | kind) != ARITH_OK); | |
6100 | ||
6101 | current_history = enum_history; | |
6102 | while (current_history != NULL) | |
6103 | { | |
6104 | current_history->sym->ts.kind = kind; | |
6105 | current_history = current_history->next; | |
6106 | } | |
6107 | } | |
6108 | ||
636dff67 | 6109 | |
6de9cd9a | 6110 | /* Match any of the various end-block statements. Returns the type of |
9abe5e56 DK |
6111 | END to the caller. The END INTERFACE, END IF, END DO, END SELECT |
6112 | and END BLOCK statements cannot be replaced by a single END statement. */ | |
6de9cd9a DN |
6113 | |
6114 | match | |
636dff67 | 6115 | gfc_match_end (gfc_statement *st) |
6de9cd9a DN |
6116 | { |
6117 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
6118 | gfc_compile_state state; | |
6119 | locus old_loc; | |
6120 | const char *block_name; | |
6121 | const char *target; | |
ddc9ce91 | 6122 | int eos_ok; |
6de9cd9a | 6123 | match m; |
0cab6b73 TK |
6124 | gfc_namespace *parent_ns, *ns, *prev_ns; |
6125 | gfc_namespace **nsp; | |
6de9cd9a | 6126 | |
63645982 | 6127 | old_loc = gfc_current_locus; |
6de9cd9a DN |
6128 | if (gfc_match ("end") != MATCH_YES) |
6129 | return MATCH_NO; | |
6130 | ||
6131 | state = gfc_current_state (); | |
636dff67 SK |
6132 | block_name = gfc_current_block () == NULL |
6133 | ? NULL : gfc_current_block ()->name; | |
6de9cd9a | 6134 | |
03af1e4c | 6135 | switch (state) |
6de9cd9a | 6136 | { |
03af1e4c DK |
6137 | case COMP_ASSOCIATE: |
6138 | case COMP_BLOCK: | |
3a1fd30c | 6139 | if (!strncmp (block_name, "block@", strlen("block@"))) |
03af1e4c DK |
6140 | block_name = NULL; |
6141 | break; | |
6142 | ||
6143 | case COMP_CONTAINS: | |
6144 | case COMP_DERIVED_CONTAINS: | |
6de9cd9a | 6145 | state = gfc_state_stack->previous->state; |
636dff67 SK |
6146 | block_name = gfc_state_stack->previous->sym == NULL |
6147 | ? NULL : gfc_state_stack->previous->sym->name; | |
03af1e4c DK |
6148 | break; |
6149 | ||
6150 | default: | |
6151 | break; | |
6de9cd9a DN |
6152 | } |
6153 | ||
6154 | switch (state) | |
6155 | { | |
6156 | case COMP_NONE: | |
6157 | case COMP_PROGRAM: | |
6158 | *st = ST_END_PROGRAM; | |
6159 | target = " program"; | |
ddc9ce91 | 6160 | eos_ok = 1; |
6de9cd9a DN |
6161 | break; |
6162 | ||
6163 | case COMP_SUBROUTINE: | |
6164 | *st = ST_END_SUBROUTINE; | |
6165 | target = " subroutine"; | |
ddc9ce91 | 6166 | eos_ok = !contained_procedure (); |
6de9cd9a DN |
6167 | break; |
6168 | ||
6169 | case COMP_FUNCTION: | |
6170 | *st = ST_END_FUNCTION; | |
6171 | target = " function"; | |
ddc9ce91 | 6172 | eos_ok = !contained_procedure (); |
6de9cd9a DN |
6173 | break; |
6174 | ||
6175 | case COMP_BLOCK_DATA: | |
6176 | *st = ST_END_BLOCK_DATA; | |
6177 | target = " block data"; | |
ddc9ce91 | 6178 | eos_ok = 1; |
6de9cd9a DN |
6179 | break; |
6180 | ||
6181 | case COMP_MODULE: | |
6182 | *st = ST_END_MODULE; | |
6183 | target = " module"; | |
ddc9ce91 | 6184 | eos_ok = 1; |
6de9cd9a DN |
6185 | break; |
6186 | ||
6187 | case COMP_INTERFACE: | |
6188 | *st = ST_END_INTERFACE; | |
6189 | target = " interface"; | |
ddc9ce91 | 6190 | eos_ok = 0; |
6de9cd9a DN |
6191 | break; |
6192 | ||
6193 | case COMP_DERIVED: | |
30b608eb | 6194 | case COMP_DERIVED_CONTAINS: |
6de9cd9a DN |
6195 | *st = ST_END_TYPE; |
6196 | target = " type"; | |
ddc9ce91 | 6197 | eos_ok = 0; |
6de9cd9a DN |
6198 | break; |
6199 | ||
03af1e4c DK |
6200 | case COMP_ASSOCIATE: |
6201 | *st = ST_END_ASSOCIATE; | |
6202 | target = " associate"; | |
6203 | eos_ok = 0; | |
6204 | break; | |
6205 | ||
9abe5e56 DK |
6206 | case COMP_BLOCK: |
6207 | *st = ST_END_BLOCK; | |
6208 | target = " block"; | |
6209 | eos_ok = 0; | |
6210 | break; | |
6211 | ||
6de9cd9a DN |
6212 | case COMP_IF: |
6213 | *st = ST_ENDIF; | |
6214 | target = " if"; | |
ddc9ce91 | 6215 | eos_ok = 0; |
6de9cd9a DN |
6216 | break; |
6217 | ||
6218 | case COMP_DO: | |
8c6a85e3 | 6219 | case COMP_DO_CONCURRENT: |
6de9cd9a DN |
6220 | *st = ST_ENDDO; |
6221 | target = " do"; | |
ddc9ce91 | 6222 | eos_ok = 0; |
6de9cd9a DN |
6223 | break; |
6224 | ||
d0a4a61c TB |
6225 | case COMP_CRITICAL: |
6226 | *st = ST_END_CRITICAL; | |
6227 | target = " critical"; | |
6228 | eos_ok = 0; | |
6229 | break; | |
6230 | ||
6de9cd9a | 6231 | case COMP_SELECT: |
cf2b3c22 | 6232 | case COMP_SELECT_TYPE: |
6de9cd9a DN |
6233 | *st = ST_END_SELECT; |
6234 | target = " select"; | |
ddc9ce91 | 6235 | eos_ok = 0; |
6de9cd9a DN |
6236 | break; |
6237 | ||
6238 | case COMP_FORALL: | |
6239 | *st = ST_END_FORALL; | |
6240 | target = " forall"; | |
ddc9ce91 | 6241 | eos_ok = 0; |
6de9cd9a DN |
6242 | break; |
6243 | ||
6244 | case COMP_WHERE: | |
6245 | *st = ST_END_WHERE; | |
6246 | target = " where"; | |
ddc9ce91 | 6247 | eos_ok = 0; |
6de9cd9a DN |
6248 | break; |
6249 | ||
25d8f0a2 TS |
6250 | case COMP_ENUM: |
6251 | *st = ST_END_ENUM; | |
6252 | target = " enum"; | |
6253 | eos_ok = 0; | |
6254 | last_initializer = NULL; | |
6255 | set_enum_kind (); | |
6256 | gfc_free_enum_history (); | |
6257 | break; | |
6258 | ||
6de9cd9a DN |
6259 | default: |
6260 | gfc_error ("Unexpected END statement at %C"); | |
6261 | goto cleanup; | |
6262 | } | |
6263 | ||
3a43b5b3 | 6264 | old_loc = gfc_current_locus; |
6de9cd9a DN |
6265 | if (gfc_match_eos () == MATCH_YES) |
6266 | { | |
272001a2 TB |
6267 | if (!eos_ok && (*st == ST_END_SUBROUTINE || *st == ST_END_FUNCTION)) |
6268 | { | |
524af0d6 JB |
6269 | if (!gfc_notify_std (GFC_STD_F2008, "END statement " |
6270 | "instead of %s statement at %L", | |
6271 | gfc_ascii_statement(*st), &old_loc)) | |
272001a2 TB |
6272 | goto cleanup; |
6273 | } | |
6274 | else if (!eos_ok) | |
6de9cd9a | 6275 | { |
66e4ab31 | 6276 | /* We would have required END [something]. */ |
59ce85b5 TS |
6277 | gfc_error ("%s statement expected at %L", |
6278 | gfc_ascii_statement (*st), &old_loc); | |
6de9cd9a DN |
6279 | goto cleanup; |
6280 | } | |
6281 | ||
6282 | return MATCH_YES; | |
6283 | } | |
6284 | ||
6285 | /* Verify that we've got the sort of end-block that we're expecting. */ | |
6286 | if (gfc_match (target) != MATCH_YES) | |
6287 | { | |
3a43b5b3 TB |
6288 | gfc_error ("Expecting %s statement at %L", gfc_ascii_statement (*st), |
6289 | &old_loc); | |
6de9cd9a DN |
6290 | goto cleanup; |
6291 | } | |
6292 | ||
3a43b5b3 | 6293 | old_loc = gfc_current_locus; |
6de9cd9a DN |
6294 | /* If we're at the end, make sure a block name wasn't required. */ |
6295 | if (gfc_match_eos () == MATCH_YES) | |
6296 | { | |
6297 | ||
690af379 | 6298 | if (*st != ST_ENDDO && *st != ST_ENDIF && *st != ST_END_SELECT |
d0a4a61c | 6299 | && *st != ST_END_FORALL && *st != ST_END_WHERE && *st != ST_END_BLOCK |
03af1e4c | 6300 | && *st != ST_END_ASSOCIATE && *st != ST_END_CRITICAL) |
6de9cd9a DN |
6301 | return MATCH_YES; |
6302 | ||
9abe5e56 | 6303 | if (!block_name) |
6de9cd9a DN |
6304 | return MATCH_YES; |
6305 | ||
c4100eae | 6306 | gfc_error ("Expected block name of %qs in %s statement at %L", |
3a43b5b3 | 6307 | block_name, gfc_ascii_statement (*st), &old_loc); |
6de9cd9a DN |
6308 | |
6309 | return MATCH_ERROR; | |
6310 | } | |
6311 | ||
6312 | /* END INTERFACE has a special handler for its several possible endings. */ | |
6313 | if (*st == ST_END_INTERFACE) | |
6314 | return gfc_match_end_interface (); | |
6315 | ||
66e4ab31 SK |
6316 | /* We haven't hit the end of statement, so what is left must be an |
6317 | end-name. */ | |
6de9cd9a DN |
6318 | m = gfc_match_space (); |
6319 | if (m == MATCH_YES) | |
6320 | m = gfc_match_name (name); | |
6321 | ||
6322 | if (m == MATCH_NO) | |
6323 | gfc_error ("Expected terminating name at %C"); | |
6324 | if (m != MATCH_YES) | |
6325 | goto cleanup; | |
6326 | ||
6327 | if (block_name == NULL) | |
6328 | goto syntax; | |
6329 | ||
3070bab4 | 6330 | if (strcmp (name, block_name) != 0 && strcmp (block_name, "ppr@") != 0) |
6de9cd9a | 6331 | { |
c4100eae | 6332 | gfc_error ("Expected label %qs for %s statement at %C", block_name, |
6de9cd9a DN |
6333 | gfc_ascii_statement (*st)); |
6334 | goto cleanup; | |
6335 | } | |
3070bab4 JW |
6336 | /* Procedure pointer as function result. */ |
6337 | else if (strcmp (block_name, "ppr@") == 0 | |
6338 | && strcmp (name, gfc_current_block ()->ns->proc_name->name) != 0) | |
6339 | { | |
c4100eae | 6340 | gfc_error ("Expected label %qs for %s statement at %C", |
3070bab4 JW |
6341 | gfc_current_block ()->ns->proc_name->name, |
6342 | gfc_ascii_statement (*st)); | |
6343 | goto cleanup; | |
6344 | } | |
6de9cd9a DN |
6345 | |
6346 | if (gfc_match_eos () == MATCH_YES) | |
6347 | return MATCH_YES; | |
6348 | ||
6349 | syntax: | |
6350 | gfc_syntax_error (*st); | |
6351 | ||
6352 | cleanup: | |
63645982 | 6353 | gfc_current_locus = old_loc; |
0cab6b73 TK |
6354 | |
6355 | /* If we are missing an END BLOCK, we created a half-ready namespace. | |
6356 | Remove it from the parent namespace's sibling list. */ | |
6357 | ||
6358 | if (state == COMP_BLOCK) | |
6359 | { | |
6360 | parent_ns = gfc_current_ns->parent; | |
6361 | ||
6362 | nsp = &(gfc_state_stack->previous->tail->ext.block.ns); | |
6363 | ||
6364 | prev_ns = NULL; | |
6365 | ns = *nsp; | |
6366 | while (ns) | |
6367 | { | |
6368 | if (ns == gfc_current_ns) | |
6369 | { | |
6370 | if (prev_ns == NULL) | |
6371 | *nsp = NULL; | |
6372 | else | |
6373 | prev_ns->sibling = ns->sibling; | |
6374 | } | |
6375 | prev_ns = ns; | |
6376 | ns = ns->sibling; | |
6377 | } | |
6378 | ||
6379 | gfc_free_namespace (gfc_current_ns); | |
6380 | gfc_current_ns = parent_ns; | |
6381 | } | |
6382 | ||
6de9cd9a DN |
6383 | return MATCH_ERROR; |
6384 | } | |
6385 | ||
6386 | ||
6387 | ||
6388 | /***************** Attribute declaration statements ****************/ | |
6389 | ||
6390 | /* Set the attribute of a single variable. */ | |
6391 | ||
6392 | static match | |
6393 | attr_decl1 (void) | |
6394 | { | |
6395 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
6396 | gfc_array_spec *as; | |
97440db5 ML |
6397 | |
6398 | /* Workaround -Wmaybe-uninitialized false positive during | |
6399 | profiledbootstrap by initializing them. */ | |
6400 | gfc_symbol *sym = NULL; | |
6de9cd9a DN |
6401 | locus var_locus; |
6402 | match m; | |
6403 | ||
6404 | as = NULL; | |
6405 | ||
6406 | m = gfc_match_name (name); | |
6407 | if (m != MATCH_YES) | |
6408 | goto cleanup; | |
6409 | ||
08a6b8e0 | 6410 | if (find_special (name, &sym, false)) |
6de9cd9a DN |
6411 | return MATCH_ERROR; |
6412 | ||
524af0d6 | 6413 | if (!check_function_name (name)) |
bb9de0c4 JW |
6414 | { |
6415 | m = MATCH_ERROR; | |
6416 | goto cleanup; | |
6417 | } | |
f5acf0f2 | 6418 | |
63645982 | 6419 | var_locus = gfc_current_locus; |
6de9cd9a DN |
6420 | |
6421 | /* Deal with possible array specification for certain attributes. */ | |
6422 | if (current_attr.dimension | |
be59db2d | 6423 | || current_attr.codimension |
6de9cd9a DN |
6424 | || current_attr.allocatable |
6425 | || current_attr.pointer | |
6426 | || current_attr.target) | |
6427 | { | |
be59db2d TB |
6428 | m = gfc_match_array_spec (&as, !current_attr.codimension, |
6429 | !current_attr.dimension | |
6430 | && !current_attr.pointer | |
6431 | && !current_attr.target); | |
6de9cd9a DN |
6432 | if (m == MATCH_ERROR) |
6433 | goto cleanup; | |
6434 | ||
6435 | if (current_attr.dimension && m == MATCH_NO) | |
6436 | { | |
636dff67 SK |
6437 | gfc_error ("Missing array specification at %L in DIMENSION " |
6438 | "statement", &var_locus); | |
6de9cd9a DN |
6439 | m = MATCH_ERROR; |
6440 | goto cleanup; | |
6441 | } | |
6442 | ||
1283ab12 TB |
6443 | if (current_attr.dimension && sym->value) |
6444 | { | |
6445 | gfc_error ("Dimensions specified for %s at %L after its " | |
6446 | "initialisation", sym->name, &var_locus); | |
6447 | m = MATCH_ERROR; | |
6448 | goto cleanup; | |
6449 | } | |
6450 | ||
be59db2d TB |
6451 | if (current_attr.codimension && m == MATCH_NO) |
6452 | { | |
6453 | gfc_error ("Missing array specification at %L in CODIMENSION " | |
6454 | "statement", &var_locus); | |
6455 | m = MATCH_ERROR; | |
6456 | goto cleanup; | |
6457 | } | |
6458 | ||
6de9cd9a DN |
6459 | if ((current_attr.allocatable || current_attr.pointer) |
6460 | && (m == MATCH_YES) && (as->type != AS_DEFERRED)) | |
6461 | { | |
636dff67 | 6462 | gfc_error ("Array specification must be deferred at %L", &var_locus); |
6de9cd9a DN |
6463 | m = MATCH_ERROR; |
6464 | goto cleanup; | |
6465 | } | |
6466 | } | |
6467 | ||
2e23972e JW |
6468 | /* Update symbol table. DIMENSION attribute is set in |
6469 | gfc_set_array_spec(). For CLASS variables, this must be applied | |
b04533af | 6470 | to the first component, or '_data' field. */ |
d40477b4 | 6471 | if (sym->ts.type == BT_CLASS && sym->ts.u.derived->attr.is_class) |
6de9cd9a | 6472 | { |
524af0d6 | 6473 | if (!gfc_copy_attr (&CLASS_DATA(sym)->attr, ¤t_attr, &var_locus)) |
2e23972e JW |
6474 | { |
6475 | m = MATCH_ERROR; | |
6476 | goto cleanup; | |
6477 | } | |
2e23972e JW |
6478 | } |
6479 | else | |
6480 | { | |
be59db2d | 6481 | if (current_attr.dimension == 0 && current_attr.codimension == 0 |
524af0d6 | 6482 | && !gfc_copy_attr (&sym->attr, ¤t_attr, &var_locus)) |
2e23972e JW |
6483 | { |
6484 | m = MATCH_ERROR; | |
6485 | goto cleanup; | |
6486 | } | |
6de9cd9a | 6487 | } |
f5acf0f2 | 6488 | |
528622fd | 6489 | if (sym->ts.type == BT_CLASS |
9b6da3c7 | 6490 | && !gfc_build_class_symbol (&sym->ts, &sym->attr, &sym->as)) |
96d9b22c JW |
6491 | { |
6492 | m = MATCH_ERROR; | |
6493 | goto cleanup; | |
6494 | } | |
6de9cd9a | 6495 | |
524af0d6 | 6496 | if (!gfc_set_array_spec (sym, as, &var_locus)) |
6de9cd9a DN |
6497 | { |
6498 | m = MATCH_ERROR; | |
6499 | goto cleanup; | |
6500 | } | |
d51347f9 | 6501 | |
83d890b9 AL |
6502 | if (sym->attr.cray_pointee && sym->as != NULL) |
6503 | { | |
6504 | /* Fix the array spec. */ | |
f5acf0f2 | 6505 | m = gfc_mod_pointee_as (sym->as); |
83d890b9 AL |
6506 | if (m == MATCH_ERROR) |
6507 | goto cleanup; | |
6508 | } | |
6de9cd9a | 6509 | |
524af0d6 | 6510 | if (!gfc_add_attribute (&sym->attr, &var_locus)) |
1902704e PT |
6511 | { |
6512 | m = MATCH_ERROR; | |
6513 | goto cleanup; | |
6514 | } | |
6515 | ||
6de9cd9a DN |
6516 | if ((current_attr.external || current_attr.intrinsic) |
6517 | && sym->attr.flavor != FL_PROCEDURE | |
524af0d6 | 6518 | && !gfc_add_flavor (&sym->attr, FL_PROCEDURE, sym->name, NULL)) |
6de9cd9a DN |
6519 | { |
6520 | m = MATCH_ERROR; | |
6521 | goto cleanup; | |
6522 | } | |
6523 | ||
3070bab4 JW |
6524 | add_hidden_procptr_result (sym); |
6525 | ||
6de9cd9a DN |
6526 | return MATCH_YES; |
6527 | ||
6528 | cleanup: | |
6529 | gfc_free_array_spec (as); | |
6530 | return m; | |
6531 | } | |
6532 | ||
6533 | ||
6534 | /* Generic attribute declaration subroutine. Used for attributes that | |
6535 | just have a list of names. */ | |
6536 | ||
6537 | static match | |
6538 | attr_decl (void) | |
6539 | { | |
6540 | match m; | |
6541 | ||
6542 | /* Gobble the optional double colon, by simply ignoring the result | |
6543 | of gfc_match(). */ | |
6544 | gfc_match (" ::"); | |
6545 | ||
6546 | for (;;) | |
6547 | { | |
6548 | m = attr_decl1 (); | |
6549 | if (m != MATCH_YES) | |
6550 | break; | |
6551 | ||
6552 | if (gfc_match_eos () == MATCH_YES) | |
6553 | { | |
6554 | m = MATCH_YES; | |
6555 | break; | |
6556 | } | |
6557 | ||
6558 | if (gfc_match_char (',') != MATCH_YES) | |
6559 | { | |
6560 | gfc_error ("Unexpected character in variable list at %C"); | |
6561 | m = MATCH_ERROR; | |
6562 | break; | |
6563 | } | |
6564 | } | |
6565 | ||
6566 | return m; | |
6567 | } | |
6568 | ||
6569 | ||
83d890b9 AL |
6570 | /* This routine matches Cray Pointer declarations of the form: |
6571 | pointer ( <pointer>, <pointee> ) | |
6572 | or | |
d51347f9 TB |
6573 | pointer ( <pointer1>, <pointee1> ), ( <pointer2>, <pointee2> ), ... |
6574 | The pointer, if already declared, should be an integer. Otherwise, we | |
83d890b9 AL |
6575 | set it as BT_INTEGER with kind gfc_index_integer_kind. The pointee may |
6576 | be either a scalar, or an array declaration. No space is allocated for | |
d51347f9 | 6577 | the pointee. For the statement |
83d890b9 AL |
6578 | pointer (ipt, ar(10)) |
6579 | any subsequent uses of ar will be translated (in C-notation) as | |
d51347f9 | 6580 | ar(i) => ((<type> *) ipt)(i) |
b122dc6a | 6581 | After gimplification, pointee variable will disappear in the code. */ |
83d890b9 AL |
6582 | |
6583 | static match | |
6584 | cray_pointer_decl (void) | |
6585 | { | |
6586 | match m; | |
be59db2d | 6587 | gfc_array_spec *as = NULL; |
83d890b9 AL |
6588 | gfc_symbol *cptr; /* Pointer symbol. */ |
6589 | gfc_symbol *cpte; /* Pointee symbol. */ | |
6590 | locus var_locus; | |
6591 | bool done = false; | |
6592 | ||
6593 | while (!done) | |
6594 | { | |
6595 | if (gfc_match_char ('(') != MATCH_YES) | |
6596 | { | |
a4d9b221 | 6597 | gfc_error ("Expected %<(%> at %C"); |
d51347f9 | 6598 | return MATCH_ERROR; |
83d890b9 | 6599 | } |
d51347f9 | 6600 | |
83d890b9 AL |
6601 | /* Match pointer. */ |
6602 | var_locus = gfc_current_locus; | |
6603 | gfc_clear_attr (¤t_attr); | |
6604 | gfc_add_cray_pointer (¤t_attr, &var_locus); | |
6605 | current_ts.type = BT_INTEGER; | |
6606 | current_ts.kind = gfc_index_integer_kind; | |
6607 | ||
d51347f9 | 6608 | m = gfc_match_symbol (&cptr, 0); |
83d890b9 AL |
6609 | if (m != MATCH_YES) |
6610 | { | |
6611 | gfc_error ("Expected variable name at %C"); | |
6612 | return m; | |
6613 | } | |
d51347f9 | 6614 | |
524af0d6 | 6615 | if (!gfc_add_cray_pointer (&cptr->attr, &var_locus)) |
83d890b9 AL |
6616 | return MATCH_ERROR; |
6617 | ||
d51347f9 | 6618 | gfc_set_sym_referenced (cptr); |
83d890b9 AL |
6619 | |
6620 | if (cptr->ts.type == BT_UNKNOWN) /* Override the type, if necessary. */ | |
6621 | { | |
6622 | cptr->ts.type = BT_INTEGER; | |
d51347f9 | 6623 | cptr->ts.kind = gfc_index_integer_kind; |
83d890b9 AL |
6624 | } |
6625 | else if (cptr->ts.type != BT_INTEGER) | |
6626 | { | |
e25a0da3 | 6627 | gfc_error ("Cray pointer at %C must be an integer"); |
83d890b9 AL |
6628 | return MATCH_ERROR; |
6629 | } | |
6630 | else if (cptr->ts.kind < gfc_index_integer_kind) | |
db30e21c | 6631 | gfc_warning (0, "Cray pointer at %C has %d bytes of precision;" |
e25a0da3 | 6632 | " memory addresses require %d bytes", |
636dff67 | 6633 | cptr->ts.kind, gfc_index_integer_kind); |
83d890b9 AL |
6634 | |
6635 | if (gfc_match_char (',') != MATCH_YES) | |
6636 | { | |
6637 | gfc_error ("Expected \",\" at %C"); | |
d51347f9 | 6638 | return MATCH_ERROR; |
83d890b9 AL |
6639 | } |
6640 | ||
d51347f9 | 6641 | /* Match Pointee. */ |
83d890b9 AL |
6642 | var_locus = gfc_current_locus; |
6643 | gfc_clear_attr (¤t_attr); | |
6644 | gfc_add_cray_pointee (¤t_attr, &var_locus); | |
6645 | current_ts.type = BT_UNKNOWN; | |
6646 | current_ts.kind = 0; | |
6647 | ||
6648 | m = gfc_match_symbol (&cpte, 0); | |
6649 | if (m != MATCH_YES) | |
6650 | { | |
6651 | gfc_error ("Expected variable name at %C"); | |
6652 | return m; | |
6653 | } | |
d51347f9 | 6654 | |
83d890b9 | 6655 | /* Check for an optional array spec. */ |
be59db2d | 6656 | m = gfc_match_array_spec (&as, true, false); |
83d890b9 AL |
6657 | if (m == MATCH_ERROR) |
6658 | { | |
6659 | gfc_free_array_spec (as); | |
6660 | return m; | |
6661 | } | |
6662 | else if (m == MATCH_NO) | |
6663 | { | |
6664 | gfc_free_array_spec (as); | |
6665 | as = NULL; | |
f5acf0f2 | 6666 | } |
83d890b9 | 6667 | |
524af0d6 | 6668 | if (!gfc_add_cray_pointee (&cpte->attr, &var_locus)) |
83d890b9 AL |
6669 | return MATCH_ERROR; |
6670 | ||
6671 | gfc_set_sym_referenced (cpte); | |
6672 | ||
6673 | if (cpte->as == NULL) | |
6674 | { | |
524af0d6 | 6675 | if (!gfc_set_array_spec (cpte, as, &var_locus)) |
83d890b9 AL |
6676 | gfc_internal_error ("Couldn't set Cray pointee array spec."); |
6677 | } | |
6678 | else if (as != NULL) | |
6679 | { | |
e25a0da3 | 6680 | gfc_error ("Duplicate array spec for Cray pointee at %C"); |
83d890b9 AL |
6681 | gfc_free_array_spec (as); |
6682 | return MATCH_ERROR; | |
6683 | } | |
f5acf0f2 | 6684 | |
83d890b9 | 6685 | as = NULL; |
f5acf0f2 | 6686 | |
83d890b9 AL |
6687 | if (cpte->as != NULL) |
6688 | { | |
6689 | /* Fix array spec. */ | |
6690 | m = gfc_mod_pointee_as (cpte->as); | |
6691 | if (m == MATCH_ERROR) | |
6692 | return m; | |
f5acf0f2 PT |
6693 | } |
6694 | ||
83d890b9 | 6695 | /* Point the Pointee at the Pointer. */ |
b122dc6a | 6696 | cpte->cp_pointer = cptr; |
83d890b9 AL |
6697 | |
6698 | if (gfc_match_char (')') != MATCH_YES) | |
6699 | { | |
6700 | gfc_error ("Expected \")\" at %C"); | |
f5acf0f2 | 6701 | return MATCH_ERROR; |
83d890b9 AL |
6702 | } |
6703 | m = gfc_match_char (','); | |
6704 | if (m != MATCH_YES) | |
6705 | done = true; /* Stop searching for more declarations. */ | |
6706 | ||
6707 | } | |
f5acf0f2 | 6708 | |
83d890b9 AL |
6709 | if (m == MATCH_ERROR /* Failed when trying to find ',' above. */ |
6710 | || gfc_match_eos () != MATCH_YES) | |
6711 | { | |
a4d9b221 | 6712 | gfc_error ("Expected %<,%> or end of statement at %C"); |
83d890b9 AL |
6713 | return MATCH_ERROR; |
6714 | } | |
6715 | return MATCH_YES; | |
6716 | } | |
6717 | ||
6718 | ||
6de9cd9a DN |
6719 | match |
6720 | gfc_match_external (void) | |
6721 | { | |
6722 | ||
6723 | gfc_clear_attr (¤t_attr); | |
1902704e | 6724 | current_attr.external = 1; |
6de9cd9a DN |
6725 | |
6726 | return attr_decl (); | |
6727 | } | |
6728 | ||
6729 | ||
6de9cd9a DN |
6730 | match |
6731 | gfc_match_intent (void) | |
6732 | { | |
6733 | sym_intent intent; | |
6734 | ||
9abe5e56 DK |
6735 | /* This is not allowed within a BLOCK construct! */ |
6736 | if (gfc_current_state () == COMP_BLOCK) | |
6737 | { | |
6738 | gfc_error ("INTENT is not allowed inside of BLOCK at %C"); | |
6739 | return MATCH_ERROR; | |
6740 | } | |
6741 | ||
6de9cd9a DN |
6742 | intent = match_intent_spec (); |
6743 | if (intent == INTENT_UNKNOWN) | |
6744 | return MATCH_ERROR; | |
6745 | ||
6746 | gfc_clear_attr (¤t_attr); | |
1902704e | 6747 | current_attr.intent = intent; |
6de9cd9a DN |
6748 | |
6749 | return attr_decl (); | |
6750 | } | |
6751 | ||
6752 | ||
6753 | match | |
6754 | gfc_match_intrinsic (void) | |
6755 | { | |
6756 | ||
6757 | gfc_clear_attr (¤t_attr); | |
1902704e | 6758 | current_attr.intrinsic = 1; |
6de9cd9a DN |
6759 | |
6760 | return attr_decl (); | |
6761 | } | |
6762 | ||
6763 | ||
6764 | match | |
6765 | gfc_match_optional (void) | |
6766 | { | |
9abe5e56 DK |
6767 | /* This is not allowed within a BLOCK construct! */ |
6768 | if (gfc_current_state () == COMP_BLOCK) | |
6769 | { | |
6770 | gfc_error ("OPTIONAL is not allowed inside of BLOCK at %C"); | |
6771 | return MATCH_ERROR; | |
6772 | } | |
6de9cd9a DN |
6773 | |
6774 | gfc_clear_attr (¤t_attr); | |
1902704e | 6775 | current_attr.optional = 1; |
6de9cd9a DN |
6776 | |
6777 | return attr_decl (); | |
6778 | } | |
6779 | ||
6780 | ||
6781 | match | |
6782 | gfc_match_pointer (void) | |
6783 | { | |
83d890b9 | 6784 | gfc_gobble_whitespace (); |
8fc541d3 | 6785 | if (gfc_peek_ascii_char () == '(') |
83d890b9 | 6786 | { |
c61819ff | 6787 | if (!flag_cray_pointer) |
83d890b9 | 6788 | { |
636dff67 SK |
6789 | gfc_error ("Cray pointer declaration at %C requires -fcray-pointer " |
6790 | "flag"); | |
83d890b9 AL |
6791 | return MATCH_ERROR; |
6792 | } | |
6793 | return cray_pointer_decl (); | |
6794 | } | |
6795 | else | |
6796 | { | |
6797 | gfc_clear_attr (¤t_attr); | |
1902704e | 6798 | current_attr.pointer = 1; |
f5acf0f2 | 6799 | |
83d890b9 AL |
6800 | return attr_decl (); |
6801 | } | |
6de9cd9a DN |
6802 | } |
6803 | ||
6804 | ||
6805 | match | |
6806 | gfc_match_allocatable (void) | |
6807 | { | |
6de9cd9a | 6808 | gfc_clear_attr (¤t_attr); |
1902704e | 6809 | current_attr.allocatable = 1; |
6de9cd9a DN |
6810 | |
6811 | return attr_decl (); | |
6812 | } | |
6813 | ||
6814 | ||
be59db2d TB |
6815 | match |
6816 | gfc_match_codimension (void) | |
6817 | { | |
6818 | gfc_clear_attr (¤t_attr); | |
6819 | current_attr.codimension = 1; | |
6820 | ||
6821 | return attr_decl (); | |
6822 | } | |
6823 | ||
6824 | ||
fe4e525c TB |
6825 | match |
6826 | gfc_match_contiguous (void) | |
6827 | { | |
524af0d6 | 6828 | if (!gfc_notify_std (GFC_STD_F2008, "CONTIGUOUS statement at %C")) |
fe4e525c TB |
6829 | return MATCH_ERROR; |
6830 | ||
6831 | gfc_clear_attr (¤t_attr); | |
6832 | current_attr.contiguous = 1; | |
6833 | ||
6834 | return attr_decl (); | |
6835 | } | |
6836 | ||
6837 | ||
6de9cd9a DN |
6838 | match |
6839 | gfc_match_dimension (void) | |
6840 | { | |
6de9cd9a | 6841 | gfc_clear_attr (¤t_attr); |
1902704e | 6842 | current_attr.dimension = 1; |
6de9cd9a DN |
6843 | |
6844 | return attr_decl (); | |
6845 | } | |
6846 | ||
6847 | ||
6848 | match | |
6849 | gfc_match_target (void) | |
6850 | { | |
6de9cd9a | 6851 | gfc_clear_attr (¤t_attr); |
1902704e | 6852 | current_attr.target = 1; |
6de9cd9a DN |
6853 | |
6854 | return attr_decl (); | |
6855 | } | |
6856 | ||
6857 | ||
6858 | /* Match the list of entities being specified in a PUBLIC or PRIVATE | |
6859 | statement. */ | |
6860 | ||
6861 | static match | |
6862 | access_attr_decl (gfc_statement st) | |
6863 | { | |
6864 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
6865 | interface_type type; | |
6866 | gfc_user_op *uop; | |
c3f34952 | 6867 | gfc_symbol *sym, *dt_sym; |
a1ee985f | 6868 | gfc_intrinsic_op op; |
6de9cd9a DN |
6869 | match m; |
6870 | ||
6871 | if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO) | |
6872 | goto done; | |
6873 | ||
6874 | for (;;) | |
6875 | { | |
a1ee985f | 6876 | m = gfc_match_generic_spec (&type, name, &op); |
6de9cd9a DN |
6877 | if (m == MATCH_NO) |
6878 | goto syntax; | |
6879 | if (m == MATCH_ERROR) | |
6880 | return MATCH_ERROR; | |
6881 | ||
6882 | switch (type) | |
6883 | { | |
6884 | case INTERFACE_NAMELESS: | |
9e1d712c | 6885 | case INTERFACE_ABSTRACT: |
6de9cd9a DN |
6886 | goto syntax; |
6887 | ||
6888 | case INTERFACE_GENERIC: | |
6889 | if (gfc_get_symbol (name, NULL, &sym)) | |
6890 | goto done; | |
6891 | ||
524af0d6 JB |
6892 | if (!gfc_add_access (&sym->attr, |
6893 | (st == ST_PUBLIC) | |
6894 | ? ACCESS_PUBLIC : ACCESS_PRIVATE, | |
6895 | sym->name, NULL)) | |
6de9cd9a DN |
6896 | return MATCH_ERROR; |
6897 | ||
c3f34952 | 6898 | if (sym->attr.generic && (dt_sym = gfc_find_dt_in_generic (sym)) |
524af0d6 JB |
6899 | && !gfc_add_access (&dt_sym->attr, |
6900 | (st == ST_PUBLIC) | |
6901 | ? ACCESS_PUBLIC : ACCESS_PRIVATE, | |
6902 | sym->name, NULL)) | |
c3f34952 TB |
6903 | return MATCH_ERROR; |
6904 | ||
6de9cd9a DN |
6905 | break; |
6906 | ||
6907 | case INTERFACE_INTRINSIC_OP: | |
a1ee985f | 6908 | if (gfc_current_ns->operator_access[op] == ACCESS_UNKNOWN) |
6de9cd9a | 6909 | { |
fb03a37e TK |
6910 | gfc_intrinsic_op other_op; |
6911 | ||
a1ee985f | 6912 | gfc_current_ns->operator_access[op] = |
6de9cd9a | 6913 | (st == ST_PUBLIC) ? ACCESS_PUBLIC : ACCESS_PRIVATE; |
fb03a37e TK |
6914 | |
6915 | /* Handle the case if there is another op with the same | |
6916 | function, for INTRINSIC_EQ vs. INTRINSIC_EQ_OS and so on. */ | |
6917 | other_op = gfc_equivalent_op (op); | |
6918 | ||
6919 | if (other_op != INTRINSIC_NONE) | |
6920 | gfc_current_ns->operator_access[other_op] = | |
6921 | (st == ST_PUBLIC) ? ACCESS_PUBLIC : ACCESS_PRIVATE; | |
6922 | ||
6de9cd9a DN |
6923 | } |
6924 | else | |
6925 | { | |
6926 | gfc_error ("Access specification of the %s operator at %C has " | |
a1ee985f | 6927 | "already been specified", gfc_op2string (op)); |
6de9cd9a DN |
6928 | goto done; |
6929 | } | |
6930 | ||
6931 | break; | |
6932 | ||
6933 | case INTERFACE_USER_OP: | |
6934 | uop = gfc_get_uop (name); | |
6935 | ||
6936 | if (uop->access == ACCESS_UNKNOWN) | |
6937 | { | |
636dff67 SK |
6938 | uop->access = (st == ST_PUBLIC) |
6939 | ? ACCESS_PUBLIC : ACCESS_PRIVATE; | |
6de9cd9a DN |
6940 | } |
6941 | else | |
6942 | { | |
636dff67 SK |
6943 | gfc_error ("Access specification of the .%s. operator at %C " |
6944 | "has already been specified", sym->name); | |
6de9cd9a DN |
6945 | goto done; |
6946 | } | |
6947 | ||
6948 | break; | |
6949 | } | |
6950 | ||
6951 | if (gfc_match_char (',') == MATCH_NO) | |
6952 | break; | |
6953 | } | |
6954 | ||
6955 | if (gfc_match_eos () != MATCH_YES) | |
6956 | goto syntax; | |
6957 | return MATCH_YES; | |
6958 | ||
6959 | syntax: | |
6960 | gfc_syntax_error (st); | |
6961 | ||
6962 | done: | |
6963 | return MATCH_ERROR; | |
6964 | } | |
6965 | ||
6966 | ||
ee7e677f TB |
6967 | match |
6968 | gfc_match_protected (void) | |
6969 | { | |
6970 | gfc_symbol *sym; | |
6971 | match m; | |
6972 | ||
6973 | if (gfc_current_ns->proc_name->attr.flavor != FL_MODULE) | |
6974 | { | |
6975 | gfc_error ("PROTECTED at %C only allowed in specification " | |
6976 | "part of a module"); | |
6977 | return MATCH_ERROR; | |
6978 | ||
6979 | } | |
6980 | ||
524af0d6 | 6981 | if (!gfc_notify_std (GFC_STD_F2003, "PROTECTED statement at %C")) |
ee7e677f TB |
6982 | return MATCH_ERROR; |
6983 | ||
6984 | if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO) | |
6985 | { | |
6986 | return MATCH_ERROR; | |
6987 | } | |
6988 | ||
6989 | if (gfc_match_eos () == MATCH_YES) | |
6990 | goto syntax; | |
6991 | ||
6992 | for(;;) | |
6993 | { | |
6994 | m = gfc_match_symbol (&sym, 0); | |
6995 | switch (m) | |
6996 | { | |
6997 | case MATCH_YES: | |
524af0d6 | 6998 | if (!gfc_add_protected (&sym->attr, sym->name, &gfc_current_locus)) |
ee7e677f TB |
6999 | return MATCH_ERROR; |
7000 | goto next_item; | |
7001 | ||
7002 | case MATCH_NO: | |
7003 | break; | |
7004 | ||
7005 | case MATCH_ERROR: | |
7006 | return MATCH_ERROR; | |
7007 | } | |
7008 | ||
7009 | next_item: | |
7010 | if (gfc_match_eos () == MATCH_YES) | |
7011 | break; | |
7012 | if (gfc_match_char (',') != MATCH_YES) | |
7013 | goto syntax; | |
7014 | } | |
7015 | ||
7016 | return MATCH_YES; | |
7017 | ||
7018 | syntax: | |
7019 | gfc_error ("Syntax error in PROTECTED statement at %C"); | |
7020 | return MATCH_ERROR; | |
7021 | } | |
7022 | ||
7023 | ||
86bf520d | 7024 | /* The PRIVATE statement is a bit weird in that it can be an attribute |
df2fba9e | 7025 | declaration, but also works as a standalone statement inside of a |
6de9cd9a DN |
7026 | type declaration or a module. */ |
7027 | ||
7028 | match | |
636dff67 | 7029 | gfc_match_private (gfc_statement *st) |
6de9cd9a DN |
7030 | { |
7031 | ||
7032 | if (gfc_match ("private") != MATCH_YES) | |
7033 | return MATCH_NO; | |
7034 | ||
d51347f9 | 7035 | if (gfc_current_state () != COMP_MODULE |
30b608eb DK |
7036 | && !(gfc_current_state () == COMP_DERIVED |
7037 | && gfc_state_stack->previous | |
7038 | && gfc_state_stack->previous->state == COMP_MODULE) | |
7039 | && !(gfc_current_state () == COMP_DERIVED_CONTAINS | |
7040 | && gfc_state_stack->previous && gfc_state_stack->previous->previous | |
7041 | && gfc_state_stack->previous->previous->state == COMP_MODULE)) | |
d51347f9 TB |
7042 | { |
7043 | gfc_error ("PRIVATE statement at %C is only allowed in the " | |
7044 | "specification part of a module"); | |
7045 | return MATCH_ERROR; | |
7046 | } | |
7047 | ||
6de9cd9a DN |
7048 | if (gfc_current_state () == COMP_DERIVED) |
7049 | { | |
7050 | if (gfc_match_eos () == MATCH_YES) | |
7051 | { | |
7052 | *st = ST_PRIVATE; | |
7053 | return MATCH_YES; | |
7054 | } | |
7055 | ||
7056 | gfc_syntax_error (ST_PRIVATE); | |
7057 | return MATCH_ERROR; | |
7058 | } | |
7059 | ||
7060 | if (gfc_match_eos () == MATCH_YES) | |
7061 | { | |
7062 | *st = ST_PRIVATE; | |
7063 | return MATCH_YES; | |
7064 | } | |
7065 | ||
7066 | *st = ST_ATTR_DECL; | |
7067 | return access_attr_decl (ST_PRIVATE); | |
7068 | } | |
7069 | ||
7070 | ||
7071 | match | |
636dff67 | 7072 | gfc_match_public (gfc_statement *st) |
6de9cd9a DN |
7073 | { |
7074 | ||
7075 | if (gfc_match ("public") != MATCH_YES) | |
7076 | return MATCH_NO; | |
7077 | ||
d51347f9 TB |
7078 | if (gfc_current_state () != COMP_MODULE) |
7079 | { | |
7080 | gfc_error ("PUBLIC statement at %C is only allowed in the " | |
7081 | "specification part of a module"); | |
7082 | return MATCH_ERROR; | |
7083 | } | |
7084 | ||
6de9cd9a DN |
7085 | if (gfc_match_eos () == MATCH_YES) |
7086 | { | |
7087 | *st = ST_PUBLIC; | |
7088 | return MATCH_YES; | |
7089 | } | |
7090 | ||
7091 | *st = ST_ATTR_DECL; | |
7092 | return access_attr_decl (ST_PUBLIC); | |
7093 | } | |
7094 | ||
7095 | ||
7096 | /* Workhorse for gfc_match_parameter. */ | |
7097 | ||
7098 | static match | |
7099 | do_parm (void) | |
7100 | { | |
7101 | gfc_symbol *sym; | |
7102 | gfc_expr *init; | |
7103 | match m; | |
524af0d6 | 7104 | bool t; |
6de9cd9a DN |
7105 | |
7106 | m = gfc_match_symbol (&sym, 0); | |
7107 | if (m == MATCH_NO) | |
7108 | gfc_error ("Expected variable name at %C in PARAMETER statement"); | |
7109 | ||
7110 | if (m != MATCH_YES) | |
7111 | return m; | |
7112 | ||
7113 | if (gfc_match_char ('=') == MATCH_NO) | |
7114 | { | |
7115 | gfc_error ("Expected = sign in PARAMETER statement at %C"); | |
7116 | return MATCH_ERROR; | |
7117 | } | |
7118 | ||
7119 | m = gfc_match_init_expr (&init); | |
7120 | if (m == MATCH_NO) | |
7121 | gfc_error ("Expected expression at %C in PARAMETER statement"); | |
7122 | if (m != MATCH_YES) | |
7123 | return m; | |
7124 | ||
7125 | if (sym->ts.type == BT_UNKNOWN | |
524af0d6 | 7126 | && !gfc_set_default_type (sym, 1, NULL)) |
6de9cd9a DN |
7127 | { |
7128 | m = MATCH_ERROR; | |
7129 | goto cleanup; | |
7130 | } | |
7131 | ||
524af0d6 JB |
7132 | if (!gfc_check_assign_symbol (sym, NULL, init) |
7133 | || !gfc_add_flavor (&sym->attr, FL_PARAMETER, sym->name, NULL)) | |
6de9cd9a DN |
7134 | { |
7135 | m = MATCH_ERROR; | |
7136 | goto cleanup; | |
7137 | } | |
7138 | ||
1283ab12 TB |
7139 | if (sym->value) |
7140 | { | |
7141 | gfc_error ("Initializing already initialized variable at %C"); | |
7142 | m = MATCH_ERROR; | |
7143 | goto cleanup; | |
7144 | } | |
7145 | ||
7919373d | 7146 | t = add_init_expr_to_sym (sym->name, &init, &gfc_current_locus); |
524af0d6 | 7147 | return (t) ? MATCH_YES : MATCH_ERROR; |
6de9cd9a DN |
7148 | |
7149 | cleanup: | |
7150 | gfc_free_expr (init); | |
7151 | return m; | |
7152 | } | |
7153 | ||
7154 | ||
7155 | /* Match a parameter statement, with the weird syntax that these have. */ | |
7156 | ||
7157 | match | |
7158 | gfc_match_parameter (void) | |
7159 | { | |
7160 | match m; | |
7161 | ||
7162 | if (gfc_match_char ('(') == MATCH_NO) | |
7163 | return MATCH_NO; | |
7164 | ||
7165 | for (;;) | |
7166 | { | |
7167 | m = do_parm (); | |
7168 | if (m != MATCH_YES) | |
7169 | break; | |
7170 | ||
7171 | if (gfc_match (" )%t") == MATCH_YES) | |
7172 | break; | |
7173 | ||
7174 | if (gfc_match_char (',') != MATCH_YES) | |
7175 | { | |
7176 | gfc_error ("Unexpected characters in PARAMETER statement at %C"); | |
7177 | m = MATCH_ERROR; | |
7178 | break; | |
7179 | } | |
7180 | } | |
7181 | ||
7182 | return m; | |
7183 | } | |
7184 | ||
7185 | ||
7186 | /* Save statements have a special syntax. */ | |
7187 | ||
7188 | match | |
7189 | gfc_match_save (void) | |
7190 | { | |
9056bd70 TS |
7191 | char n[GFC_MAX_SYMBOL_LEN+1]; |
7192 | gfc_common_head *c; | |
6de9cd9a DN |
7193 | gfc_symbol *sym; |
7194 | match m; | |
7195 | ||
7196 | if (gfc_match_eos () == MATCH_YES) | |
7197 | { | |
7198 | if (gfc_current_ns->seen_save) | |
7199 | { | |
524af0d6 JB |
7200 | if (!gfc_notify_std (GFC_STD_LEGACY, "Blanket SAVE statement at %C " |
7201 | "follows previous SAVE statement")) | |
09e87839 | 7202 | return MATCH_ERROR; |
6de9cd9a DN |
7203 | } |
7204 | ||
7205 | gfc_current_ns->save_all = gfc_current_ns->seen_save = 1; | |
7206 | return MATCH_YES; | |
7207 | } | |
7208 | ||
7209 | if (gfc_current_ns->save_all) | |
7210 | { | |
524af0d6 JB |
7211 | if (!gfc_notify_std (GFC_STD_LEGACY, "SAVE statement at %C follows " |
7212 | "blanket SAVE statement")) | |
09e87839 | 7213 | return MATCH_ERROR; |
6de9cd9a DN |
7214 | } |
7215 | ||
7216 | gfc_match (" ::"); | |
7217 | ||
7218 | for (;;) | |
7219 | { | |
7220 | m = gfc_match_symbol (&sym, 0); | |
7221 | switch (m) | |
7222 | { | |
7223 | case MATCH_YES: | |
524af0d6 JB |
7224 | if (!gfc_add_save (&sym->attr, SAVE_EXPLICIT, sym->name, |
7225 | &gfc_current_locus)) | |
6de9cd9a DN |
7226 | return MATCH_ERROR; |
7227 | goto next_item; | |
7228 | ||
7229 | case MATCH_NO: | |
7230 | break; | |
7231 | ||
7232 | case MATCH_ERROR: | |
7233 | return MATCH_ERROR; | |
7234 | } | |
7235 | ||
9056bd70 | 7236 | m = gfc_match (" / %n /", &n); |
6de9cd9a DN |
7237 | if (m == MATCH_ERROR) |
7238 | return MATCH_ERROR; | |
7239 | if (m == MATCH_NO) | |
7240 | goto syntax; | |
7241 | ||
53814b8f | 7242 | c = gfc_get_common (n, 0); |
9056bd70 TS |
7243 | c->saved = 1; |
7244 | ||
6de9cd9a DN |
7245 | gfc_current_ns->seen_save = 1; |
7246 | ||
7247 | next_item: | |
7248 | if (gfc_match_eos () == MATCH_YES) | |
7249 | break; | |
7250 | if (gfc_match_char (',') != MATCH_YES) | |
7251 | goto syntax; | |
7252 | } | |
7253 | ||
7254 | return MATCH_YES; | |
7255 | ||
7256 | syntax: | |
7257 | gfc_error ("Syntax error in SAVE statement at %C"); | |
7258 | return MATCH_ERROR; | |
7259 | } | |
7260 | ||
7261 | ||
06469efd PT |
7262 | match |
7263 | gfc_match_value (void) | |
7264 | { | |
7265 | gfc_symbol *sym; | |
7266 | match m; | |
7267 | ||
9abe5e56 DK |
7268 | /* This is not allowed within a BLOCK construct! */ |
7269 | if (gfc_current_state () == COMP_BLOCK) | |
7270 | { | |
7271 | gfc_error ("VALUE is not allowed inside of BLOCK at %C"); | |
7272 | return MATCH_ERROR; | |
7273 | } | |
7274 | ||
524af0d6 | 7275 | if (!gfc_notify_std (GFC_STD_F2003, "VALUE statement at %C")) |
06469efd PT |
7276 | return MATCH_ERROR; |
7277 | ||
7278 | if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO) | |
7279 | { | |
7280 | return MATCH_ERROR; | |
7281 | } | |
7282 | ||
7283 | if (gfc_match_eos () == MATCH_YES) | |
7284 | goto syntax; | |
7285 | ||
7286 | for(;;) | |
7287 | { | |
7288 | m = gfc_match_symbol (&sym, 0); | |
7289 | switch (m) | |
7290 | { | |
7291 | case MATCH_YES: | |
524af0d6 | 7292 | if (!gfc_add_value (&sym->attr, sym->name, &gfc_current_locus)) |
06469efd PT |
7293 | return MATCH_ERROR; |
7294 | goto next_item; | |
7295 | ||
7296 | case MATCH_NO: | |
7297 | break; | |
7298 | ||
7299 | case MATCH_ERROR: | |
7300 | return MATCH_ERROR; | |
7301 | } | |
7302 | ||
7303 | next_item: | |
7304 | if (gfc_match_eos () == MATCH_YES) | |
7305 | break; | |
7306 | if (gfc_match_char (',') != MATCH_YES) | |
7307 | goto syntax; | |
7308 | } | |
7309 | ||
7310 | return MATCH_YES; | |
7311 | ||
7312 | syntax: | |
7313 | gfc_error ("Syntax error in VALUE statement at %C"); | |
7314 | return MATCH_ERROR; | |
7315 | } | |
7316 | ||
66e4ab31 | 7317 | |
775e6c3a TB |
7318 | match |
7319 | gfc_match_volatile (void) | |
7320 | { | |
7321 | gfc_symbol *sym; | |
7322 | match m; | |
7323 | ||
524af0d6 | 7324 | if (!gfc_notify_std (GFC_STD_F2003, "VOLATILE statement at %C")) |
775e6c3a TB |
7325 | return MATCH_ERROR; |
7326 | ||
7327 | if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO) | |
7328 | { | |
7329 | return MATCH_ERROR; | |
7330 | } | |
7331 | ||
7332 | if (gfc_match_eos () == MATCH_YES) | |
7333 | goto syntax; | |
7334 | ||
7335 | for(;;) | |
7336 | { | |
f5acf0f2 | 7337 | /* VOLATILE is special because it can be added to host-associated |
1cc0e193 | 7338 | symbols locally. Except for coarrays. */ |
9bce3c1c | 7339 | m = gfc_match_symbol (&sym, 1); |
775e6c3a TB |
7340 | switch (m) |
7341 | { | |
7342 | case MATCH_YES: | |
be59db2d TB |
7343 | /* F2008, C560+C561. VOLATILE for host-/use-associated variable or |
7344 | for variable in a BLOCK which is defined outside of the BLOCK. */ | |
7345 | if (sym->ns != gfc_current_ns && sym->attr.codimension) | |
7346 | { | |
c4100eae | 7347 | gfc_error ("Specifying VOLATILE for coarray variable %qs at " |
be59db2d TB |
7348 | "%C, which is use-/host-associated", sym->name); |
7349 | return MATCH_ERROR; | |
7350 | } | |
524af0d6 | 7351 | if (!gfc_add_volatile (&sym->attr, sym->name, &gfc_current_locus)) |
775e6c3a TB |
7352 | return MATCH_ERROR; |
7353 | goto next_item; | |
7354 | ||
7355 | case MATCH_NO: | |
7356 | break; | |
7357 | ||
7358 | case MATCH_ERROR: | |
7359 | return MATCH_ERROR; | |
7360 | } | |
7361 | ||
7362 | next_item: | |
7363 | if (gfc_match_eos () == MATCH_YES) | |
7364 | break; | |
7365 | if (gfc_match_char (',') != MATCH_YES) | |
7366 | goto syntax; | |
7367 | } | |
7368 | ||
7369 | return MATCH_YES; | |
7370 | ||
7371 | syntax: | |
7372 | gfc_error ("Syntax error in VOLATILE statement at %C"); | |
7373 | return MATCH_ERROR; | |
7374 | } | |
7375 | ||
7376 | ||
1eee5628 TB |
7377 | match |
7378 | gfc_match_asynchronous (void) | |
7379 | { | |
7380 | gfc_symbol *sym; | |
7381 | match m; | |
7382 | ||
524af0d6 | 7383 | if (!gfc_notify_std (GFC_STD_F2003, "ASYNCHRONOUS statement at %C")) |
1eee5628 TB |
7384 | return MATCH_ERROR; |
7385 | ||
7386 | if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO) | |
7387 | { | |
7388 | return MATCH_ERROR; | |
7389 | } | |
7390 | ||
7391 | if (gfc_match_eos () == MATCH_YES) | |
7392 | goto syntax; | |
7393 | ||
7394 | for(;;) | |
7395 | { | |
f5acf0f2 | 7396 | /* ASYNCHRONOUS is special because it can be added to host-associated |
1eee5628 TB |
7397 | symbols locally. */ |
7398 | m = gfc_match_symbol (&sym, 1); | |
7399 | switch (m) | |
7400 | { | |
7401 | case MATCH_YES: | |
524af0d6 | 7402 | if (!gfc_add_asynchronous (&sym->attr, sym->name, &gfc_current_locus)) |
1eee5628 TB |
7403 | return MATCH_ERROR; |
7404 | goto next_item; | |
7405 | ||
7406 | case MATCH_NO: | |
7407 | break; | |
7408 | ||
7409 | case MATCH_ERROR: | |
7410 | return MATCH_ERROR; | |
7411 | } | |
7412 | ||
7413 | next_item: | |
7414 | if (gfc_match_eos () == MATCH_YES) | |
7415 | break; | |
7416 | if (gfc_match_char (',') != MATCH_YES) | |
7417 | goto syntax; | |
7418 | } | |
7419 | ||
7420 | return MATCH_YES; | |
7421 | ||
7422 | syntax: | |
7423 | gfc_error ("Syntax error in ASYNCHRONOUS statement at %C"); | |
7424 | return MATCH_ERROR; | |
7425 | } | |
7426 | ||
7427 | ||
6de9cd9a DN |
7428 | /* Match a module procedure statement. Note that we have to modify |
7429 | symbols in the parent's namespace because the current one was there | |
49de9e73 | 7430 | to receive symbols that are in an interface's formal argument list. */ |
6de9cd9a DN |
7431 | |
7432 | match | |
7433 | gfc_match_modproc (void) | |
7434 | { | |
7435 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
7436 | gfc_symbol *sym; | |
7437 | match m; | |
162b5a21 | 7438 | locus old_locus; |
060fca4a | 7439 | gfc_namespace *module_ns; |
2b77e908 | 7440 | gfc_interface *old_interface_head, *interface; |
6de9cd9a DN |
7441 | |
7442 | if (gfc_state_stack->state != COMP_INTERFACE | |
7443 | || gfc_state_stack->previous == NULL | |
129d15a3 JW |
7444 | || current_interface.type == INTERFACE_NAMELESS |
7445 | || current_interface.type == INTERFACE_ABSTRACT) | |
6de9cd9a | 7446 | { |
636dff67 SK |
7447 | gfc_error ("MODULE PROCEDURE at %C must be in a generic module " |
7448 | "interface"); | |
6de9cd9a DN |
7449 | return MATCH_ERROR; |
7450 | } | |
7451 | ||
060fca4a PT |
7452 | module_ns = gfc_current_ns->parent; |
7453 | for (; module_ns; module_ns = module_ns->parent) | |
43dfd40c SK |
7454 | if (module_ns->proc_name->attr.flavor == FL_MODULE |
7455 | || module_ns->proc_name->attr.flavor == FL_PROGRAM | |
7456 | || (module_ns->proc_name->attr.flavor == FL_PROCEDURE | |
7457 | && !module_ns->proc_name->attr.contained)) | |
060fca4a PT |
7458 | break; |
7459 | ||
7460 | if (module_ns == NULL) | |
7461 | return MATCH_ERROR; | |
7462 | ||
2b77e908 FXC |
7463 | /* Store the current state of the interface. We will need it if we |
7464 | end up with a syntax error and need to recover. */ | |
7465 | old_interface_head = gfc_current_interface_head (); | |
7466 | ||
162b5a21 SK |
7467 | /* Check if the F2008 optional double colon appears. */ |
7468 | gfc_gobble_whitespace (); | |
7469 | old_locus = gfc_current_locus; | |
7470 | if (gfc_match ("::") == MATCH_YES) | |
7471 | { | |
524af0d6 JB |
7472 | if (!gfc_notify_std (GFC_STD_F2008, "double colon in " |
7473 | "MODULE PROCEDURE statement at %L", &old_locus)) | |
162b5a21 SK |
7474 | return MATCH_ERROR; |
7475 | } | |
7476 | else | |
7477 | gfc_current_locus = old_locus; | |
f5acf0f2 | 7478 | |
6de9cd9a DN |
7479 | for (;;) |
7480 | { | |
2b77e908 | 7481 | bool last = false; |
162b5a21 | 7482 | old_locus = gfc_current_locus; |
2b77e908 | 7483 | |
6de9cd9a DN |
7484 | m = gfc_match_name (name); |
7485 | if (m == MATCH_NO) | |
7486 | goto syntax; | |
7487 | if (m != MATCH_YES) | |
7488 | return MATCH_ERROR; | |
7489 | ||
2b77e908 FXC |
7490 | /* Check for syntax error before starting to add symbols to the |
7491 | current namespace. */ | |
7492 | if (gfc_match_eos () == MATCH_YES) | |
7493 | last = true; | |
162b5a21 | 7494 | |
2b77e908 FXC |
7495 | if (!last && gfc_match_char (',') != MATCH_YES) |
7496 | goto syntax; | |
7497 | ||
7498 | /* Now we're sure the syntax is valid, we process this item | |
7499 | further. */ | |
060fca4a | 7500 | if (gfc_get_symbol (name, module_ns, &sym)) |
6de9cd9a DN |
7501 | return MATCH_ERROR; |
7502 | ||
43dfd40c SK |
7503 | if (sym->attr.intrinsic) |
7504 | { | |
7505 | gfc_error ("Intrinsic procedure at %L cannot be a MODULE " | |
7506 | "PROCEDURE", &old_locus); | |
7507 | return MATCH_ERROR; | |
7508 | } | |
7509 | ||
6de9cd9a | 7510 | if (sym->attr.proc != PROC_MODULE |
524af0d6 | 7511 | && !gfc_add_procedure (&sym->attr, PROC_MODULE, sym->name, NULL)) |
6de9cd9a DN |
7512 | return MATCH_ERROR; |
7513 | ||
524af0d6 | 7514 | if (!gfc_add_interface (sym)) |
6de9cd9a DN |
7515 | return MATCH_ERROR; |
7516 | ||
71f77fd7 | 7517 | sym->attr.mod_proc = 1; |
43dfd40c | 7518 | sym->declared_at = old_locus; |
71f77fd7 | 7519 | |
2b77e908 | 7520 | if (last) |
6de9cd9a | 7521 | break; |
6de9cd9a DN |
7522 | } |
7523 | ||
7524 | return MATCH_YES; | |
7525 | ||
7526 | syntax: | |
2b77e908 FXC |
7527 | /* Restore the previous state of the interface. */ |
7528 | interface = gfc_current_interface_head (); | |
7529 | gfc_set_current_interface_head (old_interface_head); | |
7530 | ||
7531 | /* Free the new interfaces. */ | |
7532 | while (interface != old_interface_head) | |
7533 | { | |
7534 | gfc_interface *i = interface->next; | |
cede9502 | 7535 | free (interface); |
2b77e908 FXC |
7536 | interface = i; |
7537 | } | |
7538 | ||
7539 | /* And issue a syntax error. */ | |
6de9cd9a DN |
7540 | gfc_syntax_error (ST_MODULE_PROC); |
7541 | return MATCH_ERROR; | |
7542 | } | |
7543 | ||
7544 | ||
7d1f1e61 | 7545 | /* Check a derived type that is being extended. */ |
42e3d759 | 7546 | |
7d1f1e61 PT |
7547 | static gfc_symbol* |
7548 | check_extended_derived_type (char *name) | |
7549 | { | |
7550 | gfc_symbol *extended; | |
7551 | ||
7552 | if (gfc_find_symbol (name, gfc_current_ns, 1, &extended)) | |
7553 | { | |
7554 | gfc_error ("Ambiguous symbol in TYPE definition at %C"); | |
7555 | return NULL; | |
7556 | } | |
7557 | ||
42e3d759 JW |
7558 | extended = gfc_find_dt_in_generic (extended); |
7559 | ||
7560 | /* F08:C428. */ | |
7d1f1e61 PT |
7561 | if (!extended) |
7562 | { | |
c4100eae | 7563 | gfc_error ("Symbol %qs at %C has not been previously defined", name); |
7d1f1e61 PT |
7564 | return NULL; |
7565 | } | |
7566 | ||
7567 | if (extended->attr.flavor != FL_DERIVED) | |
7568 | { | |
c4100eae | 7569 | gfc_error ("%qs in EXTENDS expression at %C is not a " |
7d1f1e61 PT |
7570 | "derived type", name); |
7571 | return NULL; | |
7572 | } | |
7573 | ||
7574 | if (extended->attr.is_bind_c) | |
7575 | { | |
c4100eae | 7576 | gfc_error ("%qs cannot be extended at %C because it " |
7d1f1e61 PT |
7577 | "is BIND(C)", extended->name); |
7578 | return NULL; | |
7579 | } | |
7580 | ||
7581 | if (extended->attr.sequence) | |
7582 | { | |
c4100eae | 7583 | gfc_error ("%qs cannot be extended at %C because it " |
7d1f1e61 PT |
7584 | "is a SEQUENCE type", extended->name); |
7585 | return NULL; | |
7586 | } | |
7587 | ||
7588 | return extended; | |
7589 | } | |
7590 | ||
7591 | ||
a8b3b0b6 CR |
7592 | /* Match the optional attribute specifiers for a type declaration. |
7593 | Return MATCH_ERROR if an error is encountered in one of the handled | |
7594 | attributes (public, private, bind(c)), MATCH_NO if what's found is | |
7595 | not a handled attribute, and MATCH_YES otherwise. TODO: More error | |
7596 | checking on attribute conflicts needs to be done. */ | |
6de9cd9a DN |
7597 | |
7598 | match | |
7d1f1e61 | 7599 | gfc_get_type_attr_spec (symbol_attribute *attr, char *name) |
6de9cd9a | 7600 | { |
a8b3b0b6 | 7601 | /* See if the derived type is marked as private. */ |
6de9cd9a DN |
7602 | if (gfc_match (" , private") == MATCH_YES) |
7603 | { | |
d51347f9 | 7604 | if (gfc_current_state () != COMP_MODULE) |
6de9cd9a | 7605 | { |
d51347f9 TB |
7606 | gfc_error ("Derived type at %C can only be PRIVATE in the " |
7607 | "specification part of a module"); | |
6de9cd9a DN |
7608 | return MATCH_ERROR; |
7609 | } | |
7610 | ||
524af0d6 | 7611 | if (!gfc_add_access (attr, ACCESS_PRIVATE, NULL, NULL)) |
6de9cd9a | 7612 | return MATCH_ERROR; |
6de9cd9a | 7613 | } |
a8b3b0b6 | 7614 | else if (gfc_match (" , public") == MATCH_YES) |
6de9cd9a | 7615 | { |
d51347f9 | 7616 | if (gfc_current_state () != COMP_MODULE) |
6de9cd9a | 7617 | { |
d51347f9 TB |
7618 | gfc_error ("Derived type at %C can only be PUBLIC in the " |
7619 | "specification part of a module"); | |
6de9cd9a DN |
7620 | return MATCH_ERROR; |
7621 | } | |
7622 | ||
524af0d6 | 7623 | if (!gfc_add_access (attr, ACCESS_PUBLIC, NULL, NULL)) |
6de9cd9a | 7624 | return MATCH_ERROR; |
6de9cd9a | 7625 | } |
52f49934 | 7626 | else if (gfc_match (" , bind ( c )") == MATCH_YES) |
a8b3b0b6 CR |
7627 | { |
7628 | /* If the type is defined to be bind(c) it then needs to make | |
7629 | sure that all fields are interoperable. This will | |
7630 | need to be a semantic check on the finished derived type. | |
7631 | See 15.2.3 (lines 9-12) of F2003 draft. */ | |
524af0d6 | 7632 | if (!gfc_add_is_bind_c (attr, NULL, &gfc_current_locus, 0)) |
a8b3b0b6 CR |
7633 | return MATCH_ERROR; |
7634 | ||
7635 | /* TODO: attr conflicts need to be checked, probably in symbol.c. */ | |
7636 | } | |
52f49934 DK |
7637 | else if (gfc_match (" , abstract") == MATCH_YES) |
7638 | { | |
524af0d6 | 7639 | if (!gfc_notify_std (GFC_STD_F2003, "ABSTRACT type at %C")) |
52f49934 DK |
7640 | return MATCH_ERROR; |
7641 | ||
524af0d6 | 7642 | if (!gfc_add_abstract (attr, &gfc_current_locus)) |
52f49934 DK |
7643 | return MATCH_ERROR; |
7644 | } | |
524af0d6 | 7645 | else if (name && gfc_match (" , extends ( %n )", name) == MATCH_YES) |
7d1f1e61 | 7646 | { |
524af0d6 | 7647 | if (!gfc_add_extension (attr, &gfc_current_locus)) |
7d1f1e61 PT |
7648 | return MATCH_ERROR; |
7649 | } | |
a8b3b0b6 CR |
7650 | else |
7651 | return MATCH_NO; | |
7652 | ||
7653 | /* If we get here, something matched. */ | |
7654 | return MATCH_YES; | |
7655 | } | |
7656 | ||
7657 | ||
7658 | /* Match the beginning of a derived type declaration. If a type name | |
7659 | was the result of a function, then it is possible to have a symbol | |
7660 | already to be known as a derived type yet have no components. */ | |
7661 | ||
7662 | match | |
7663 | gfc_match_derived_decl (void) | |
7664 | { | |
7665 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
7d1f1e61 | 7666 | char parent[GFC_MAX_SYMBOL_LEN + 1]; |
a8b3b0b6 | 7667 | symbol_attribute attr; |
c3f34952 | 7668 | gfc_symbol *sym, *gensym; |
7d1f1e61 | 7669 | gfc_symbol *extended; |
a8b3b0b6 CR |
7670 | match m; |
7671 | match is_type_attr_spec = MATCH_NO; | |
e7303e85 | 7672 | bool seen_attr = false; |
c3f34952 | 7673 | gfc_interface *intr = NULL, *head; |
a8b3b0b6 CR |
7674 | |
7675 | if (gfc_current_state () == COMP_DERIVED) | |
7676 | return MATCH_NO; | |
7677 | ||
7d1f1e61 PT |
7678 | name[0] = '\0'; |
7679 | parent[0] = '\0'; | |
a8b3b0b6 | 7680 | gfc_clear_attr (&attr); |
7d1f1e61 | 7681 | extended = NULL; |
a8b3b0b6 CR |
7682 | |
7683 | do | |
7684 | { | |
7d1f1e61 | 7685 | is_type_attr_spec = gfc_get_type_attr_spec (&attr, parent); |
a8b3b0b6 CR |
7686 | if (is_type_attr_spec == MATCH_ERROR) |
7687 | return MATCH_ERROR; | |
e7303e85 FXC |
7688 | if (is_type_attr_spec == MATCH_YES) |
7689 | seen_attr = true; | |
a8b3b0b6 | 7690 | } while (is_type_attr_spec == MATCH_YES); |
6de9cd9a | 7691 | |
63a3341a PT |
7692 | /* Deal with derived type extensions. The extension attribute has |
7693 | been added to 'attr' but now the parent type must be found and | |
7694 | checked. */ | |
7d1f1e61 PT |
7695 | if (parent[0]) |
7696 | extended = check_extended_derived_type (parent); | |
7697 | ||
7698 | if (parent[0] && !extended) | |
7699 | return MATCH_ERROR; | |
7700 | ||
e7303e85 | 7701 | if (gfc_match (" ::") != MATCH_YES && seen_attr) |
6de9cd9a DN |
7702 | { |
7703 | gfc_error ("Expected :: in TYPE definition at %C"); | |
7704 | return MATCH_ERROR; | |
7705 | } | |
7706 | ||
7707 | m = gfc_match (" %n%t", name); | |
7708 | if (m != MATCH_YES) | |
7709 | return m; | |
7710 | ||
e9c06563 TB |
7711 | /* Make sure the name is not the name of an intrinsic type. */ |
7712 | if (gfc_is_intrinsic_typename (name)) | |
6de9cd9a | 7713 | { |
c4100eae | 7714 | gfc_error ("Type name %qs at %C cannot be the same as an intrinsic " |
636dff67 | 7715 | "type", name); |
6de9cd9a DN |
7716 | return MATCH_ERROR; |
7717 | } | |
7718 | ||
c3f34952 | 7719 | if (gfc_get_symbol (name, NULL, &gensym)) |
6de9cd9a DN |
7720 | return MATCH_ERROR; |
7721 | ||
c3f34952 | 7722 | if (!gensym->attr.generic && gensym->ts.type != BT_UNKNOWN) |
6de9cd9a | 7723 | { |
c4100eae | 7724 | gfc_error ("Derived type name %qs at %C already has a basic type " |
c3f34952 TB |
7725 | "of %s", gensym->name, gfc_typename (&gensym->ts)); |
7726 | return MATCH_ERROR; | |
7727 | } | |
7728 | ||
7729 | if (!gensym->attr.generic | |
524af0d6 | 7730 | && !gfc_add_generic (&gensym->attr, gensym->name, NULL)) |
c3f34952 TB |
7731 | return MATCH_ERROR; |
7732 | ||
7733 | if (!gensym->attr.function | |
524af0d6 | 7734 | && !gfc_add_function (&gensym->attr, gensym->name, NULL)) |
c3f34952 TB |
7735 | return MATCH_ERROR; |
7736 | ||
7737 | sym = gfc_find_dt_in_generic (gensym); | |
7738 | ||
7739 | if (sym && (sym->components != NULL || sym->attr.zero_comp)) | |
7740 | { | |
c4100eae | 7741 | gfc_error ("Derived type definition of %qs at %C has already been " |
c3f34952 | 7742 | "defined", sym->name); |
6de9cd9a DN |
7743 | return MATCH_ERROR; |
7744 | } | |
7745 | ||
c3f34952 TB |
7746 | if (!sym) |
7747 | { | |
7748 | /* Use upper case to save the actual derived-type symbol. */ | |
7749 | gfc_get_symbol (gfc_get_string ("%c%s", | |
7750 | (char) TOUPPER ((unsigned char) gensym->name[0]), | |
7751 | &gensym->name[1]), NULL, &sym); | |
7752 | sym->name = gfc_get_string (gensym->name); | |
7753 | head = gensym->generic; | |
7754 | intr = gfc_get_interface (); | |
7755 | intr->sym = sym; | |
7756 | intr->where = gfc_current_locus; | |
7757 | intr->sym->declared_at = gfc_current_locus; | |
7758 | intr->next = head; | |
7759 | gensym->generic = intr; | |
7760 | gensym->attr.if_source = IFSRC_DECL; | |
7761 | } | |
7762 | ||
6de9cd9a DN |
7763 | /* The symbol may already have the derived attribute without the |
7764 | components. The ways this can happen is via a function | |
7765 | definition, an INTRINSIC statement or a subtype in another | |
7766 | derived type that is a pointer. The first part of the AND clause | |
df2fba9e | 7767 | is true if the symbol is not the return value of a function. */ |
6de9cd9a | 7768 | if (sym->attr.flavor != FL_DERIVED |
524af0d6 | 7769 | && !gfc_add_flavor (&sym->attr, FL_DERIVED, sym->name, NULL)) |
6de9cd9a DN |
7770 | return MATCH_ERROR; |
7771 | ||
6de9cd9a | 7772 | if (attr.access != ACCESS_UNKNOWN |
524af0d6 | 7773 | && !gfc_add_access (&sym->attr, attr.access, sym->name, NULL)) |
6de9cd9a | 7774 | return MATCH_ERROR; |
c3f34952 TB |
7775 | else if (sym->attr.access == ACCESS_UNKNOWN |
7776 | && gensym->attr.access != ACCESS_UNKNOWN | |
524af0d6 JB |
7777 | && !gfc_add_access (&sym->attr, gensym->attr.access, |
7778 | sym->name, NULL)) | |
c3f34952 TB |
7779 | return MATCH_ERROR; |
7780 | ||
7781 | if (sym->attr.access != ACCESS_UNKNOWN | |
7782 | && gensym->attr.access == ACCESS_UNKNOWN) | |
7783 | gensym->attr.access = sym->attr.access; | |
6de9cd9a | 7784 | |
a8b3b0b6 CR |
7785 | /* See if the derived type was labeled as bind(c). */ |
7786 | if (attr.is_bind_c != 0) | |
7787 | sym->attr.is_bind_c = attr.is_bind_c; | |
7788 | ||
34523524 DK |
7789 | /* Construct the f2k_derived namespace if it is not yet there. */ |
7790 | if (!sym->f2k_derived) | |
7791 | sym->f2k_derived = gfc_get_namespace (NULL, 0); | |
f5acf0f2 | 7792 | |
7d1f1e61 PT |
7793 | if (extended && !sym->components) |
7794 | { | |
7795 | gfc_component *p; | |
7d1f1e61 PT |
7796 | |
7797 | /* Add the extended derived type as the first component. */ | |
7798 | gfc_add_component (sym, parent, &p); | |
7d1f1e61 PT |
7799 | extended->refs++; |
7800 | gfc_set_sym_referenced (extended); | |
7801 | ||
7802 | p->ts.type = BT_DERIVED; | |
bc21d315 | 7803 | p->ts.u.derived = extended; |
7d1f1e61 | 7804 | p->initializer = gfc_default_initializer (&p->ts); |
f5acf0f2 | 7805 | |
7c1dab0d JW |
7806 | /* Set extension level. */ |
7807 | if (extended->attr.extension == 255) | |
7808 | { | |
7809 | /* Since the extension field is 8 bit wide, we can only have | |
7810 | up to 255 extension levels. */ | |
c4100eae | 7811 | gfc_error ("Maximum extension level reached with type %qs at %L", |
7c1dab0d JW |
7812 | extended->name, &extended->declared_at); |
7813 | return MATCH_ERROR; | |
7814 | } | |
7815 | sym->attr.extension = extended->attr.extension + 1; | |
7d1f1e61 PT |
7816 | |
7817 | /* Provide the links between the extended type and its extension. */ | |
7818 | if (!extended->f2k_derived) | |
7819 | extended->f2k_derived = gfc_get_namespace (NULL, 0); | |
7d1f1e61 PT |
7820 | } |
7821 | ||
7c1dab0d JW |
7822 | if (!sym->hash_value) |
7823 | /* Set the hash for the compound name for this type. */ | |
4fa02692 | 7824 | sym->hash_value = gfc_hash_value (sym); |
cf2b3c22 | 7825 | |
52f49934 DK |
7826 | /* Take over the ABSTRACT attribute. */ |
7827 | sym->attr.abstract = attr.abstract; | |
7828 | ||
6de9cd9a DN |
7829 | gfc_new_block = sym; |
7830 | ||
7831 | return MATCH_YES; | |
7832 | } | |
83d890b9 AL |
7833 | |
7834 | ||
f5acf0f2 | 7835 | /* Cray Pointees can be declared as: |
b3aefde2 | 7836 | pointer (ipt, a (n,m,...,*)) */ |
83d890b9 | 7837 | |
32e8bb8e | 7838 | match |
83d890b9 AL |
7839 | gfc_mod_pointee_as (gfc_array_spec *as) |
7840 | { | |
7841 | as->cray_pointee = true; /* This will be useful to know later. */ | |
7842 | if (as->type == AS_ASSUMED_SIZE) | |
b3aefde2 | 7843 | as->cp_was_assumed = true; |
83d890b9 AL |
7844 | else if (as->type == AS_ASSUMED_SHAPE) |
7845 | { | |
7846 | gfc_error ("Cray Pointee at %C cannot be assumed shape array"); | |
7847 | return MATCH_ERROR; | |
7848 | } | |
7849 | return MATCH_YES; | |
7850 | } | |
25d8f0a2 TS |
7851 | |
7852 | ||
f5acf0f2 PT |
7853 | /* Match the enum definition statement, here we are trying to match |
7854 | the first line of enum definition statement. | |
25d8f0a2 TS |
7855 | Returns MATCH_YES if match is found. */ |
7856 | ||
7857 | match | |
7858 | gfc_match_enum (void) | |
7859 | { | |
7860 | match m; | |
f5acf0f2 | 7861 | |
25d8f0a2 TS |
7862 | m = gfc_match_eos (); |
7863 | if (m != MATCH_YES) | |
7864 | return m; | |
7865 | ||
524af0d6 | 7866 | if (!gfc_notify_std (GFC_STD_F2003, "ENUM and ENUMERATOR at %C")) |
25d8f0a2 TS |
7867 | return MATCH_ERROR; |
7868 | ||
7869 | return MATCH_YES; | |
7870 | } | |
7871 | ||
7872 | ||
31224396 SK |
7873 | /* Returns an initializer whose value is one higher than the value of the |
7874 | LAST_INITIALIZER argument. If the argument is NULL, the | |
7875 | initializers value will be set to zero. The initializer's kind | |
7876 | will be set to gfc_c_int_kind. | |
7877 | ||
7878 | If -fshort-enums is given, the appropriate kind will be selected | |
7879 | later after all enumerators have been parsed. A warning is issued | |
7880 | here if an initializer exceeds gfc_c_int_kind. */ | |
7881 | ||
7882 | static gfc_expr * | |
7883 | enum_initializer (gfc_expr *last_initializer, locus where) | |
7884 | { | |
7885 | gfc_expr *result; | |
b7e75771 | 7886 | result = gfc_get_constant_expr (BT_INTEGER, gfc_c_int_kind, &where); |
31224396 SK |
7887 | |
7888 | mpz_init (result->value.integer); | |
7889 | ||
7890 | if (last_initializer != NULL) | |
7891 | { | |
7892 | mpz_add_ui (result->value.integer, last_initializer->value.integer, 1); | |
7893 | result->where = last_initializer->where; | |
7894 | ||
7895 | if (gfc_check_integer_range (result->value.integer, | |
7896 | gfc_c_int_kind) != ARITH_OK) | |
7897 | { | |
7898 | gfc_error ("Enumerator exceeds the C integer type at %C"); | |
7899 | return NULL; | |
7900 | } | |
7901 | } | |
7902 | else | |
7903 | { | |
7904 | /* Control comes here, if it's the very first enumerator and no | |
7905 | initializer has been given. It will be initialized to zero. */ | |
7906 | mpz_set_si (result->value.integer, 0); | |
7907 | } | |
7908 | ||
7909 | return result; | |
7910 | } | |
7911 | ||
7912 | ||
6133c68a TS |
7913 | /* Match a variable name with an optional initializer. When this |
7914 | subroutine is called, a variable is expected to be parsed next. | |
7915 | Depending on what is happening at the moment, updates either the | |
7916 | symbol table or the current interface. */ | |
7917 | ||
7918 | static match | |
7919 | enumerator_decl (void) | |
7920 | { | |
7921 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
7922 | gfc_expr *initializer; | |
7923 | gfc_array_spec *as = NULL; | |
7924 | gfc_symbol *sym; | |
7925 | locus var_locus; | |
7926 | match m; | |
524af0d6 | 7927 | bool t; |
6133c68a TS |
7928 | locus old_locus; |
7929 | ||
7930 | initializer = NULL; | |
7931 | old_locus = gfc_current_locus; | |
7932 | ||
7933 | /* When we get here, we've just matched a list of attributes and | |
7934 | maybe a type and a double colon. The next thing we expect to see | |
7935 | is the name of the symbol. */ | |
7936 | m = gfc_match_name (name); | |
7937 | if (m != MATCH_YES) | |
7938 | goto cleanup; | |
7939 | ||
7940 | var_locus = gfc_current_locus; | |
7941 | ||
7942 | /* OK, we've successfully matched the declaration. Now put the | |
7943 | symbol in the current namespace. If we fail to create the symbol, | |
7944 | bail out. */ | |
524af0d6 | 7945 | if (!build_sym (name, NULL, false, &as, &var_locus)) |
6133c68a TS |
7946 | { |
7947 | m = MATCH_ERROR; | |
7948 | goto cleanup; | |
7949 | } | |
7950 | ||
7951 | /* The double colon must be present in order to have initializers. | |
7952 | Otherwise the statement is ambiguous with an assignment statement. */ | |
7953 | if (colon_seen) | |
7954 | { | |
7955 | if (gfc_match_char ('=') == MATCH_YES) | |
7956 | { | |
7957 | m = gfc_match_init_expr (&initializer); | |
7958 | if (m == MATCH_NO) | |
7959 | { | |
7960 | gfc_error ("Expected an initialization expression at %C"); | |
7961 | m = MATCH_ERROR; | |
7962 | } | |
7963 | ||
7964 | if (m != MATCH_YES) | |
7965 | goto cleanup; | |
7966 | } | |
7967 | } | |
7968 | ||
7969 | /* If we do not have an initializer, the initialization value of the | |
7970 | previous enumerator (stored in last_initializer) is incremented | |
7971 | by 1 and is used to initialize the current enumerator. */ | |
7972 | if (initializer == NULL) | |
31224396 | 7973 | initializer = enum_initializer (last_initializer, old_locus); |
d51347f9 | 7974 | |
6133c68a TS |
7975 | if (initializer == NULL || initializer->ts.type != BT_INTEGER) |
7976 | { | |
01e64c3d JJ |
7977 | gfc_error ("ENUMERATOR %L not initialized with integer expression", |
7978 | &var_locus); | |
d51347f9 | 7979 | m = MATCH_ERROR; |
6133c68a TS |
7980 | goto cleanup; |
7981 | } | |
7982 | ||
7983 | /* Store this current initializer, for the next enumerator variable | |
7984 | to be parsed. add_init_expr_to_sym() zeros initializer, so we | |
7985 | use last_initializer below. */ | |
7986 | last_initializer = initializer; | |
7987 | t = add_init_expr_to_sym (name, &initializer, &var_locus); | |
7988 | ||
7989 | /* Maintain enumerator history. */ | |
7990 | gfc_find_symbol (name, NULL, 0, &sym); | |
7991 | create_enum_history (sym, last_initializer); | |
7992 | ||
524af0d6 | 7993 | return (t) ? MATCH_YES : MATCH_ERROR; |
6133c68a TS |
7994 | |
7995 | cleanup: | |
7996 | /* Free stuff up and return. */ | |
7997 | gfc_free_expr (initializer); | |
7998 | ||
7999 | return m; | |
8000 | } | |
8001 | ||
8002 | ||
66e4ab31 | 8003 | /* Match the enumerator definition statement. */ |
25d8f0a2 TS |
8004 | |
8005 | match | |
8006 | gfc_match_enumerator_def (void) | |
8007 | { | |
8008 | match m; | |
524af0d6 | 8009 | bool t; |
d51347f9 | 8010 | |
25d8f0a2 | 8011 | gfc_clear_ts (¤t_ts); |
d51347f9 | 8012 | |
25d8f0a2 TS |
8013 | m = gfc_match (" enumerator"); |
8014 | if (m != MATCH_YES) | |
8015 | return m; | |
6133c68a TS |
8016 | |
8017 | m = gfc_match (" :: "); | |
8018 | if (m == MATCH_ERROR) | |
8019 | return m; | |
8020 | ||
8021 | colon_seen = (m == MATCH_YES); | |
d51347f9 | 8022 | |
25d8f0a2 TS |
8023 | if (gfc_current_state () != COMP_ENUM) |
8024 | { | |
8025 | gfc_error ("ENUM definition statement expected before %C"); | |
8026 | gfc_free_enum_history (); | |
8027 | return MATCH_ERROR; | |
8028 | } | |
8029 | ||
8030 | (¤t_ts)->type = BT_INTEGER; | |
8031 | (¤t_ts)->kind = gfc_c_int_kind; | |
d51347f9 | 8032 | |
6133c68a TS |
8033 | gfc_clear_attr (¤t_attr); |
8034 | t = gfc_add_flavor (¤t_attr, FL_PARAMETER, NULL, NULL); | |
524af0d6 | 8035 | if (!t) |
25d8f0a2 | 8036 | { |
6133c68a | 8037 | m = MATCH_ERROR; |
25d8f0a2 TS |
8038 | goto cleanup; |
8039 | } | |
8040 | ||
25d8f0a2 TS |
8041 | for (;;) |
8042 | { | |
6133c68a | 8043 | m = enumerator_decl (); |
25d8f0a2 | 8044 | if (m == MATCH_ERROR) |
01e64c3d JJ |
8045 | { |
8046 | gfc_free_enum_history (); | |
8047 | goto cleanup; | |
8048 | } | |
25d8f0a2 TS |
8049 | if (m == MATCH_NO) |
8050 | break; | |
8051 | ||
8052 | if (gfc_match_eos () == MATCH_YES) | |
8053 | goto cleanup; | |
8054 | if (gfc_match_char (',') != MATCH_YES) | |
8055 | break; | |
8056 | } | |
8057 | ||
8058 | if (gfc_current_state () == COMP_ENUM) | |
8059 | { | |
8060 | gfc_free_enum_history (); | |
8061 | gfc_error ("Syntax error in ENUMERATOR definition at %C"); | |
8062 | m = MATCH_ERROR; | |
8063 | } | |
8064 | ||
8065 | cleanup: | |
8066 | gfc_free_array_spec (current_as); | |
8067 | current_as = NULL; | |
8068 | return m; | |
8069 | ||
8070 | } | |
8071 | ||
f6fad28e | 8072 | |
30b608eb DK |
8073 | /* Match binding attributes. */ |
8074 | ||
8075 | static match | |
713485cc | 8076 | match_binding_attributes (gfc_typebound_proc* ba, bool generic, bool ppc) |
30b608eb DK |
8077 | { |
8078 | bool found_passing = false; | |
713485cc | 8079 | bool seen_ptr = false; |
90661f26 | 8080 | match m = MATCH_YES; |
30b608eb | 8081 | |
eea58adb | 8082 | /* Initialize to defaults. Do so even before the MATCH_NO check so that in |
30b608eb DK |
8083 | this case the defaults are in there. */ |
8084 | ba->access = ACCESS_UNKNOWN; | |
8085 | ba->pass_arg = NULL; | |
8086 | ba->pass_arg_num = 0; | |
8087 | ba->nopass = 0; | |
8088 | ba->non_overridable = 0; | |
b0e5fa94 | 8089 | ba->deferred = 0; |
90661f26 | 8090 | ba->ppc = ppc; |
30b608eb DK |
8091 | |
8092 | /* If we find a comma, we believe there are binding attributes. */ | |
90661f26 JW |
8093 | m = gfc_match_char (','); |
8094 | if (m == MATCH_NO) | |
8095 | goto done; | |
30b608eb DK |
8096 | |
8097 | do | |
8098 | { | |
e157f736 DK |
8099 | /* Access specifier. */ |
8100 | ||
8101 | m = gfc_match (" public"); | |
30b608eb DK |
8102 | if (m == MATCH_ERROR) |
8103 | goto error; | |
8104 | if (m == MATCH_YES) | |
8105 | { | |
e157f736 | 8106 | if (ba->access != ACCESS_UNKNOWN) |
30b608eb | 8107 | { |
e157f736 | 8108 | gfc_error ("Duplicate access-specifier at %C"); |
30b608eb DK |
8109 | goto error; |
8110 | } | |
8111 | ||
e157f736 | 8112 | ba->access = ACCESS_PUBLIC; |
30b608eb DK |
8113 | continue; |
8114 | } | |
8115 | ||
e157f736 | 8116 | m = gfc_match (" private"); |
30b608eb DK |
8117 | if (m == MATCH_ERROR) |
8118 | goto error; | |
8119 | if (m == MATCH_YES) | |
8120 | { | |
e157f736 | 8121 | if (ba->access != ACCESS_UNKNOWN) |
30b608eb | 8122 | { |
e157f736 | 8123 | gfc_error ("Duplicate access-specifier at %C"); |
30b608eb DK |
8124 | goto error; |
8125 | } | |
8126 | ||
e157f736 | 8127 | ba->access = ACCESS_PRIVATE; |
30b608eb DK |
8128 | continue; |
8129 | } | |
8130 | ||
e157f736 DK |
8131 | /* If inside GENERIC, the following is not allowed. */ |
8132 | if (!generic) | |
30b608eb | 8133 | { |
30b608eb | 8134 | |
e157f736 DK |
8135 | /* NOPASS flag. */ |
8136 | m = gfc_match (" nopass"); | |
8137 | if (m == MATCH_ERROR) | |
8138 | goto error; | |
8139 | if (m == MATCH_YES) | |
30b608eb | 8140 | { |
e157f736 DK |
8141 | if (found_passing) |
8142 | { | |
8143 | gfc_error ("Binding attributes already specify passing," | |
8144 | " illegal NOPASS at %C"); | |
8145 | goto error; | |
8146 | } | |
8147 | ||
8148 | found_passing = true; | |
8149 | ba->nopass = 1; | |
8150 | continue; | |
30b608eb DK |
8151 | } |
8152 | ||
e157f736 DK |
8153 | /* PASS possibly including argument. */ |
8154 | m = gfc_match (" pass"); | |
8155 | if (m == MATCH_ERROR) | |
8156 | goto error; | |
8157 | if (m == MATCH_YES) | |
30b608eb | 8158 | { |
e157f736 DK |
8159 | char arg[GFC_MAX_SYMBOL_LEN + 1]; |
8160 | ||
8161 | if (found_passing) | |
8162 | { | |
8163 | gfc_error ("Binding attributes already specify passing," | |
8164 | " illegal PASS at %C"); | |
8165 | goto error; | |
8166 | } | |
8167 | ||
8168 | m = gfc_match (" ( %n )", arg); | |
8169 | if (m == MATCH_ERROR) | |
8170 | goto error; | |
8171 | if (m == MATCH_YES) | |
90661f26 | 8172 | ba->pass_arg = gfc_get_string (arg); |
e157f736 DK |
8173 | gcc_assert ((m == MATCH_YES) == (ba->pass_arg != NULL)); |
8174 | ||
8175 | found_passing = true; | |
8176 | ba->nopass = 0; | |
8177 | continue; | |
30b608eb DK |
8178 | } |
8179 | ||
713485cc JW |
8180 | if (ppc) |
8181 | { | |
8182 | /* POINTER flag. */ | |
8183 | m = gfc_match (" pointer"); | |
8184 | if (m == MATCH_ERROR) | |
8185 | goto error; | |
8186 | if (m == MATCH_YES) | |
8187 | { | |
8188 | if (seen_ptr) | |
8189 | { | |
8190 | gfc_error ("Duplicate POINTER attribute at %C"); | |
8191 | goto error; | |
8192 | } | |
8193 | ||
8194 | seen_ptr = true; | |
713485cc JW |
8195 | continue; |
8196 | } | |
8197 | } | |
8198 | else | |
8199 | { | |
8200 | /* NON_OVERRIDABLE flag. */ | |
8201 | m = gfc_match (" non_overridable"); | |
8202 | if (m == MATCH_ERROR) | |
8203 | goto error; | |
8204 | if (m == MATCH_YES) | |
8205 | { | |
8206 | if (ba->non_overridable) | |
8207 | { | |
8208 | gfc_error ("Duplicate NON_OVERRIDABLE at %C"); | |
8209 | goto error; | |
8210 | } | |
8211 | ||
8212 | ba->non_overridable = 1; | |
8213 | continue; | |
8214 | } | |
8215 | ||
8216 | /* DEFERRED flag. */ | |
8217 | m = gfc_match (" deferred"); | |
8218 | if (m == MATCH_ERROR) | |
8219 | goto error; | |
8220 | if (m == MATCH_YES) | |
8221 | { | |
8222 | if (ba->deferred) | |
8223 | { | |
8224 | gfc_error ("Duplicate DEFERRED at %C"); | |
8225 | goto error; | |
8226 | } | |
8227 | ||
8228 | ba->deferred = 1; | |
8229 | continue; | |
8230 | } | |
8231 | } | |
8232 | ||
30b608eb DK |
8233 | } |
8234 | ||
8235 | /* Nothing matching found. */ | |
e157f736 DK |
8236 | if (generic) |
8237 | gfc_error ("Expected access-specifier at %C"); | |
8238 | else | |
8239 | gfc_error ("Expected binding attribute at %C"); | |
30b608eb DK |
8240 | goto error; |
8241 | } | |
8242 | while (gfc_match_char (',') == MATCH_YES); | |
8243 | ||
b0e5fa94 DK |
8244 | /* NON_OVERRIDABLE and DEFERRED exclude themselves. */ |
8245 | if (ba->non_overridable && ba->deferred) | |
8246 | { | |
8247 | gfc_error ("NON_OVERRIDABLE and DEFERRED can't both appear at %C"); | |
8248 | goto error; | |
8249 | } | |
8250 | ||
90661f26 JW |
8251 | m = MATCH_YES; |
8252 | ||
8253 | done: | |
e157f736 DK |
8254 | if (ba->access == ACCESS_UNKNOWN) |
8255 | ba->access = gfc_typebound_default_access; | |
8256 | ||
713485cc JW |
8257 | if (ppc && !seen_ptr) |
8258 | { | |
8259 | gfc_error ("POINTER attribute is required for procedure pointer component" | |
8260 | " at %C"); | |
8261 | goto error; | |
8262 | } | |
8263 | ||
90661f26 | 8264 | return m; |
30b608eb DK |
8265 | |
8266 | error: | |
30b608eb DK |
8267 | return MATCH_ERROR; |
8268 | } | |
8269 | ||
8270 | ||
8271 | /* Match a PROCEDURE specific binding inside a derived type. */ | |
8272 | ||
8273 | static match | |
8274 | match_procedure_in_type (void) | |
8275 | { | |
8276 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
8277 | char target_buf[GFC_MAX_SYMBOL_LEN + 1]; | |
1be17993 | 8278 | char* target = NULL, *ifc = NULL; |
3e15518b | 8279 | gfc_typebound_proc tb; |
30b608eb DK |
8280 | bool seen_colons; |
8281 | bool seen_attrs; | |
8282 | match m; | |
8283 | gfc_symtree* stree; | |
8284 | gfc_namespace* ns; | |
8285 | gfc_symbol* block; | |
1be17993 | 8286 | int num; |
30b608eb DK |
8287 | |
8288 | /* Check current state. */ | |
8289 | gcc_assert (gfc_state_stack->state == COMP_DERIVED_CONTAINS); | |
8290 | block = gfc_state_stack->previous->sym; | |
8291 | gcc_assert (block); | |
8292 | ||
b0e5fa94 | 8293 | /* Try to match PROCEDURE(interface). */ |
30b608eb DK |
8294 | if (gfc_match (" (") == MATCH_YES) |
8295 | { | |
b0e5fa94 DK |
8296 | m = gfc_match_name (target_buf); |
8297 | if (m == MATCH_ERROR) | |
8298 | return m; | |
8299 | if (m != MATCH_YES) | |
8300 | { | |
a4d9b221 | 8301 | gfc_error ("Interface-name expected after %<(%> at %C"); |
b0e5fa94 DK |
8302 | return MATCH_ERROR; |
8303 | } | |
8304 | ||
8305 | if (gfc_match (" )") != MATCH_YES) | |
8306 | { | |
a4d9b221 | 8307 | gfc_error ("%<)%> expected at %C"); |
b0e5fa94 DK |
8308 | return MATCH_ERROR; |
8309 | } | |
8310 | ||
1be17993 | 8311 | ifc = target_buf; |
30b608eb DK |
8312 | } |
8313 | ||
8314 | /* Construct the data structure. */ | |
ff5b6492 | 8315 | memset (&tb, 0, sizeof (tb)); |
3e15518b | 8316 | tb.where = gfc_current_locus; |
30b608eb DK |
8317 | |
8318 | /* Match binding attributes. */ | |
3e15518b | 8319 | m = match_binding_attributes (&tb, false, false); |
30b608eb DK |
8320 | if (m == MATCH_ERROR) |
8321 | return m; | |
8322 | seen_attrs = (m == MATCH_YES); | |
8323 | ||
1be17993 | 8324 | /* Check that attribute DEFERRED is given if an interface is specified. */ |
3e15518b | 8325 | if (tb.deferred && !ifc) |
b0e5fa94 DK |
8326 | { |
8327 | gfc_error ("Interface must be specified for DEFERRED binding at %C"); | |
8328 | return MATCH_ERROR; | |
8329 | } | |
3e15518b | 8330 | if (ifc && !tb.deferred) |
b0e5fa94 DK |
8331 | { |
8332 | gfc_error ("PROCEDURE(interface) at %C should be declared DEFERRED"); | |
8333 | return MATCH_ERROR; | |
8334 | } | |
8335 | ||
30b608eb DK |
8336 | /* Match the colons. */ |
8337 | m = gfc_match (" ::"); | |
8338 | if (m == MATCH_ERROR) | |
8339 | return m; | |
8340 | seen_colons = (m == MATCH_YES); | |
8341 | if (seen_attrs && !seen_colons) | |
8342 | { | |
a4d9b221 | 8343 | gfc_error ("Expected %<::%> after binding-attributes at %C"); |
30b608eb DK |
8344 | return MATCH_ERROR; |
8345 | } | |
8346 | ||
f5acf0f2 | 8347 | /* Match the binding names. */ |
1be17993 | 8348 | for(num=1;;num++) |
30b608eb | 8349 | { |
1be17993 JW |
8350 | m = gfc_match_name (name); |
8351 | if (m == MATCH_ERROR) | |
8352 | return m; | |
8353 | if (m == MATCH_NO) | |
b0e5fa94 | 8354 | { |
1be17993 | 8355 | gfc_error ("Expected binding name at %C"); |
b0e5fa94 DK |
8356 | return MATCH_ERROR; |
8357 | } | |
8358 | ||
524af0d6 | 8359 | if (num>1 && !gfc_notify_std (GFC_STD_F2008, "PROCEDURE list at %C")) |
1be17993 | 8360 | return MATCH_ERROR; |
30b608eb | 8361 | |
1be17993 JW |
8362 | /* Try to match the '=> target', if it's there. */ |
8363 | target = ifc; | |
8364 | m = gfc_match (" =>"); | |
30b608eb DK |
8365 | if (m == MATCH_ERROR) |
8366 | return m; | |
1be17993 | 8367 | if (m == MATCH_YES) |
30b608eb | 8368 | { |
3e15518b | 8369 | if (tb.deferred) |
1be17993 | 8370 | { |
a4d9b221 | 8371 | gfc_error ("%<=> target%> is invalid for DEFERRED binding at %C"); |
1be17993 JW |
8372 | return MATCH_ERROR; |
8373 | } | |
8374 | ||
8375 | if (!seen_colons) | |
8376 | { | |
a4d9b221 | 8377 | gfc_error ("%<::%> needed in PROCEDURE binding with explicit target" |
1be17993 JW |
8378 | " at %C"); |
8379 | return MATCH_ERROR; | |
8380 | } | |
8381 | ||
8382 | m = gfc_match_name (target_buf); | |
8383 | if (m == MATCH_ERROR) | |
8384 | return m; | |
8385 | if (m == MATCH_NO) | |
8386 | { | |
a4d9b221 | 8387 | gfc_error ("Expected binding target after %<=>%> at %C"); |
1be17993 JW |
8388 | return MATCH_ERROR; |
8389 | } | |
8390 | target = target_buf; | |
30b608eb | 8391 | } |
30b608eb | 8392 | |
1be17993 JW |
8393 | /* If no target was found, it has the same name as the binding. */ |
8394 | if (!target) | |
8395 | target = name; | |
30b608eb | 8396 | |
1be17993 JW |
8397 | /* Get the namespace to insert the symbols into. */ |
8398 | ns = block->f2k_derived; | |
8399 | gcc_assert (ns); | |
30b608eb | 8400 | |
1be17993 | 8401 | /* If the binding is DEFERRED, check that the containing type is ABSTRACT. */ |
3e15518b | 8402 | if (tb.deferred && !block->attr.abstract) |
1be17993 | 8403 | { |
c4100eae | 8404 | gfc_error ("Type %qs containing DEFERRED binding at %C " |
1be17993 JW |
8405 | "is not ABSTRACT", block->name); |
8406 | return MATCH_ERROR; | |
8407 | } | |
30b608eb | 8408 | |
1be17993 | 8409 | /* See if we already have a binding with this name in the symtree which |
6bd2c800 | 8410 | would be an error. If a GENERIC already targeted this binding, it may |
1be17993 JW |
8411 | be already there but then typebound is still NULL. */ |
8412 | stree = gfc_find_symtree (ns->tb_sym_root, name); | |
9f23af48 | 8413 | if (stree && stree->n.tb) |
1be17993 | 8414 | { |
c4100eae MLI |
8415 | gfc_error ("There is already a procedure with binding name %qs for " |
8416 | "the derived type %qs at %C", name, block->name); | |
1be17993 JW |
8417 | return MATCH_ERROR; |
8418 | } | |
b0e5fa94 | 8419 | |
1be17993 | 8420 | /* Insert it and set attributes. */ |
30b608eb | 8421 | |
9f23af48 MM |
8422 | if (!stree) |
8423 | { | |
8424 | stree = gfc_new_symtree (&ns->tb_sym_root, name); | |
8425 | gcc_assert (stree); | |
8426 | } | |
3e15518b | 8427 | stree->n.tb = gfc_get_typebound_proc (&tb); |
e34ccb4c | 8428 | |
3e15518b JW |
8429 | if (gfc_get_sym_tree (target, gfc_current_ns, &stree->n.tb->u.specific, |
8430 | false)) | |
1be17993 | 8431 | return MATCH_ERROR; |
3e15518b | 8432 | gfc_set_sym_referenced (stree->n.tb->u.specific->n.sym); |
f5acf0f2 | 8433 | |
1be17993 JW |
8434 | if (gfc_match_eos () == MATCH_YES) |
8435 | return MATCH_YES; | |
8436 | if (gfc_match_char (',') != MATCH_YES) | |
8437 | goto syntax; | |
e34ccb4c | 8438 | } |
30b608eb | 8439 | |
1be17993 JW |
8440 | syntax: |
8441 | gfc_error ("Syntax error in PROCEDURE statement at %C"); | |
8442 | return MATCH_ERROR; | |
30b608eb DK |
8443 | } |
8444 | ||
8445 | ||
e157f736 DK |
8446 | /* Match a GENERIC procedure binding inside a derived type. */ |
8447 | ||
8448 | match | |
8449 | gfc_match_generic (void) | |
8450 | { | |
8451 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
94747289 | 8452 | char bind_name[GFC_MAX_SYMBOL_LEN + 16]; /* Allow space for OPERATOR(...). */ |
e157f736 DK |
8453 | gfc_symbol* block; |
8454 | gfc_typebound_proc tbattr; /* Used for match_binding_attributes. */ | |
8455 | gfc_typebound_proc* tb; | |
e157f736 | 8456 | gfc_namespace* ns; |
94747289 DK |
8457 | interface_type op_type; |
8458 | gfc_intrinsic_op op; | |
e157f736 DK |
8459 | match m; |
8460 | ||
8461 | /* Check current state. */ | |
8462 | if (gfc_current_state () == COMP_DERIVED) | |
8463 | { | |
8464 | gfc_error ("GENERIC at %C must be inside a derived-type CONTAINS"); | |
8465 | return MATCH_ERROR; | |
8466 | } | |
8467 | if (gfc_current_state () != COMP_DERIVED_CONTAINS) | |
8468 | return MATCH_NO; | |
8469 | block = gfc_state_stack->previous->sym; | |
8470 | ns = block->f2k_derived; | |
8471 | gcc_assert (block && ns); | |
8472 | ||
ff5b6492 MM |
8473 | memset (&tbattr, 0, sizeof (tbattr)); |
8474 | tbattr.where = gfc_current_locus; | |
8475 | ||
e157f736 | 8476 | /* See if we get an access-specifier. */ |
713485cc | 8477 | m = match_binding_attributes (&tbattr, true, false); |
e157f736 DK |
8478 | if (m == MATCH_ERROR) |
8479 | goto error; | |
8480 | ||
8481 | /* Now the colons, those are required. */ | |
8482 | if (gfc_match (" ::") != MATCH_YES) | |
8483 | { | |
a4d9b221 | 8484 | gfc_error ("Expected %<::%> at %C"); |
e157f736 DK |
8485 | goto error; |
8486 | } | |
8487 | ||
94747289 DK |
8488 | /* Match the binding name; depending on type (operator / generic) format |
8489 | it for future error messages into bind_name. */ | |
f5acf0f2 | 8490 | |
94747289 | 8491 | m = gfc_match_generic_spec (&op_type, name, &op); |
e157f736 DK |
8492 | if (m == MATCH_ERROR) |
8493 | return MATCH_ERROR; | |
8494 | if (m == MATCH_NO) | |
8495 | { | |
94747289 | 8496 | gfc_error ("Expected generic name or operator descriptor at %C"); |
e157f736 DK |
8497 | goto error; |
8498 | } | |
8499 | ||
94747289 | 8500 | switch (op_type) |
e157f736 | 8501 | { |
94747289 DK |
8502 | case INTERFACE_GENERIC: |
8503 | snprintf (bind_name, sizeof (bind_name), "%s", name); | |
8504 | break; | |
f5acf0f2 | 8505 | |
94747289 DK |
8506 | case INTERFACE_USER_OP: |
8507 | snprintf (bind_name, sizeof (bind_name), "OPERATOR(.%s.)", name); | |
8508 | break; | |
f5acf0f2 | 8509 | |
94747289 DK |
8510 | case INTERFACE_INTRINSIC_OP: |
8511 | snprintf (bind_name, sizeof (bind_name), "OPERATOR(%s)", | |
8512 | gfc_op2string (op)); | |
8513 | break; | |
8514 | ||
8515 | default: | |
8516 | gcc_unreachable (); | |
8517 | } | |
e34ccb4c | 8518 | |
94747289 DK |
8519 | /* Match the required =>. */ |
8520 | if (gfc_match (" =>") != MATCH_YES) | |
8521 | { | |
a4d9b221 | 8522 | gfc_error ("Expected %<=>%> at %C"); |
94747289 DK |
8523 | goto error; |
8524 | } | |
f5acf0f2 | 8525 | |
94747289 DK |
8526 | /* Try to find existing GENERIC binding with this name / for this operator; |
8527 | if there is something, check that it is another GENERIC and then extend | |
8528 | it rather than building a new node. Otherwise, create it and put it | |
8529 | at the right position. */ | |
8530 | ||
8531 | switch (op_type) | |
8532 | { | |
8533 | case INTERFACE_USER_OP: | |
8534 | case INTERFACE_GENERIC: | |
8535 | { | |
8536 | const bool is_op = (op_type == INTERFACE_USER_OP); | |
8537 | gfc_symtree* st; | |
8538 | ||
8539 | st = gfc_find_symtree (is_op ? ns->tb_uop_root : ns->tb_sym_root, name); | |
8540 | if (st) | |
8541 | { | |
8542 | tb = st->n.tb; | |
8543 | gcc_assert (tb); | |
8544 | } | |
8545 | else | |
8546 | tb = NULL; | |
8547 | ||
8548 | break; | |
8549 | } | |
8550 | ||
8551 | case INTERFACE_INTRINSIC_OP: | |
8552 | tb = ns->tb_op[op]; | |
8553 | break; | |
8554 | ||
8555 | default: | |
8556 | gcc_unreachable (); | |
8557 | } | |
8558 | ||
8559 | if (tb) | |
8560 | { | |
e34ccb4c | 8561 | if (!tb->is_generic) |
e157f736 | 8562 | { |
94747289 | 8563 | gcc_assert (op_type == INTERFACE_GENERIC); |
e157f736 | 8564 | gfc_error ("There's already a non-generic procedure with binding name" |
c4100eae | 8565 | " %qs for the derived type %qs at %C", |
94747289 | 8566 | bind_name, block->name); |
e157f736 DK |
8567 | goto error; |
8568 | } | |
8569 | ||
e157f736 DK |
8570 | if (tb->access != tbattr.access) |
8571 | { | |
8572 | gfc_error ("Binding at %C must have the same access as already" | |
c4100eae | 8573 | " defined binding %qs", bind_name); |
e157f736 DK |
8574 | goto error; |
8575 | } | |
8576 | } | |
8577 | else | |
8578 | { | |
3e15518b | 8579 | tb = gfc_get_typebound_proc (NULL); |
e157f736 DK |
8580 | tb->where = gfc_current_locus; |
8581 | tb->access = tbattr.access; | |
8582 | tb->is_generic = 1; | |
8583 | tb->u.generic = NULL; | |
94747289 DK |
8584 | |
8585 | switch (op_type) | |
8586 | { | |
8587 | case INTERFACE_GENERIC: | |
8588 | case INTERFACE_USER_OP: | |
8589 | { | |
8590 | const bool is_op = (op_type == INTERFACE_USER_OP); | |
8591 | gfc_symtree* st; | |
8592 | ||
8593 | st = gfc_new_symtree (is_op ? &ns->tb_uop_root : &ns->tb_sym_root, | |
8594 | name); | |
8595 | gcc_assert (st); | |
8596 | st->n.tb = tb; | |
8597 | ||
8598 | break; | |
8599 | } | |
f5acf0f2 | 8600 | |
94747289 DK |
8601 | case INTERFACE_INTRINSIC_OP: |
8602 | ns->tb_op[op] = tb; | |
8603 | break; | |
8604 | ||
8605 | default: | |
8606 | gcc_unreachable (); | |
8607 | } | |
e157f736 DK |
8608 | } |
8609 | ||
8610 | /* Now, match all following names as specific targets. */ | |
8611 | do | |
8612 | { | |
8613 | gfc_symtree* target_st; | |
8614 | gfc_tbp_generic* target; | |
8615 | ||
8616 | m = gfc_match_name (name); | |
8617 | if (m == MATCH_ERROR) | |
8618 | goto error; | |
8619 | if (m == MATCH_NO) | |
8620 | { | |
8621 | gfc_error ("Expected specific binding name at %C"); | |
8622 | goto error; | |
8623 | } | |
8624 | ||
e34ccb4c | 8625 | target_st = gfc_get_tbp_symtree (&ns->tb_sym_root, name); |
e157f736 DK |
8626 | |
8627 | /* See if this is a duplicate specification. */ | |
8628 | for (target = tb->u.generic; target; target = target->next) | |
8629 | if (target_st == target->specific_st) | |
8630 | { | |
c4100eae MLI |
8631 | gfc_error ("%qs already defined as specific binding for the" |
8632 | " generic %qs at %C", name, bind_name); | |
e157f736 DK |
8633 | goto error; |
8634 | } | |
8635 | ||
e157f736 DK |
8636 | target = gfc_get_tbp_generic (); |
8637 | target->specific_st = target_st; | |
8638 | target->specific = NULL; | |
8639 | target->next = tb->u.generic; | |
218e1228 TB |
8640 | target->is_operator = ((op_type == INTERFACE_USER_OP) |
8641 | || (op_type == INTERFACE_INTRINSIC_OP)); | |
e157f736 DK |
8642 | tb->u.generic = target; |
8643 | } | |
8644 | while (gfc_match (" ,") == MATCH_YES); | |
8645 | ||
8646 | /* Here should be the end. */ | |
8647 | if (gfc_match_eos () != MATCH_YES) | |
8648 | { | |
8649 | gfc_error ("Junk after GENERIC binding at %C"); | |
8650 | goto error; | |
8651 | } | |
8652 | ||
8653 | return MATCH_YES; | |
8654 | ||
8655 | error: | |
8656 | return MATCH_ERROR; | |
8657 | } | |
8658 | ||
8659 | ||
34523524 DK |
8660 | /* Match a FINAL declaration inside a derived type. */ |
8661 | ||
8662 | match | |
8663 | gfc_match_final_decl (void) | |
8664 | { | |
8665 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
8666 | gfc_symbol* sym; | |
8667 | match m; | |
8668 | gfc_namespace* module_ns; | |
8669 | bool first, last; | |
30b608eb | 8670 | gfc_symbol* block; |
34523524 | 8671 | |
33344e0f JW |
8672 | if (gfc_current_form == FORM_FREE) |
8673 | { | |
8674 | char c = gfc_peek_ascii_char (); | |
8675 | if (!gfc_is_whitespace (c) && c != ':') | |
8676 | return MATCH_NO; | |
8677 | } | |
f5acf0f2 | 8678 | |
30b608eb | 8679 | if (gfc_state_stack->state != COMP_DERIVED_CONTAINS) |
34523524 | 8680 | { |
33344e0f JW |
8681 | if (gfc_current_form == FORM_FIXED) |
8682 | return MATCH_NO; | |
8683 | ||
34523524 | 8684 | gfc_error ("FINAL declaration at %C must be inside a derived type " |
30b608eb | 8685 | "CONTAINS section"); |
34523524 DK |
8686 | return MATCH_ERROR; |
8687 | } | |
8688 | ||
30b608eb DK |
8689 | block = gfc_state_stack->previous->sym; |
8690 | gcc_assert (block); | |
34523524 | 8691 | |
30b608eb DK |
8692 | if (!gfc_state_stack->previous || !gfc_state_stack->previous->previous |
8693 | || gfc_state_stack->previous->previous->state != COMP_MODULE) | |
34523524 DK |
8694 | { |
8695 | gfc_error ("Derived type declaration with FINAL at %C must be in the" | |
8696 | " specification part of a MODULE"); | |
8697 | return MATCH_ERROR; | |
8698 | } | |
8699 | ||
8700 | module_ns = gfc_current_ns; | |
8701 | gcc_assert (module_ns); | |
8702 | gcc_assert (module_ns->proc_name->attr.flavor == FL_MODULE); | |
8703 | ||
8704 | /* Match optional ::, don't care about MATCH_YES or MATCH_NO. */ | |
8705 | if (gfc_match (" ::") == MATCH_ERROR) | |
8706 | return MATCH_ERROR; | |
8707 | ||
8708 | /* Match the sequence of procedure names. */ | |
8709 | first = true; | |
8710 | last = false; | |
8711 | do | |
8712 | { | |
8713 | gfc_finalizer* f; | |
8714 | ||
8715 | if (first && gfc_match_eos () == MATCH_YES) | |
8716 | { | |
8717 | gfc_error ("Empty FINAL at %C"); | |
8718 | return MATCH_ERROR; | |
8719 | } | |
8720 | ||
8721 | m = gfc_match_name (name); | |
8722 | if (m == MATCH_NO) | |
8723 | { | |
8724 | gfc_error ("Expected module procedure name at %C"); | |
8725 | return MATCH_ERROR; | |
8726 | } | |
8727 | else if (m != MATCH_YES) | |
8728 | return MATCH_ERROR; | |
8729 | ||
8730 | if (gfc_match_eos () == MATCH_YES) | |
8731 | last = true; | |
8732 | if (!last && gfc_match_char (',') != MATCH_YES) | |
8733 | { | |
a4d9b221 | 8734 | gfc_error ("Expected %<,%> at %C"); |
34523524 DK |
8735 | return MATCH_ERROR; |
8736 | } | |
8737 | ||
8738 | if (gfc_get_symbol (name, module_ns, &sym)) | |
8739 | { | |
c4100eae | 8740 | gfc_error ("Unknown procedure name %qs at %C", name); |
34523524 DK |
8741 | return MATCH_ERROR; |
8742 | } | |
8743 | ||
8744 | /* Mark the symbol as module procedure. */ | |
8745 | if (sym->attr.proc != PROC_MODULE | |
524af0d6 | 8746 | && !gfc_add_procedure (&sym->attr, PROC_MODULE, sym->name, NULL)) |
34523524 DK |
8747 | return MATCH_ERROR; |
8748 | ||
8749 | /* Check if we already have this symbol in the list, this is an error. */ | |
30b608eb | 8750 | for (f = block->f2k_derived->finalizers; f; f = f->next) |
f6fad28e | 8751 | if (f->proc_sym == sym) |
34523524 | 8752 | { |
c4100eae | 8753 | gfc_error ("%qs at %C is already defined as FINAL procedure!", |
34523524 DK |
8754 | name); |
8755 | return MATCH_ERROR; | |
8756 | } | |
8757 | ||
8758 | /* Add this symbol to the list of finalizers. */ | |
30b608eb | 8759 | gcc_assert (block->f2k_derived); |
34523524 | 8760 | ++sym->refs; |
ece3f663 | 8761 | f = XCNEW (gfc_finalizer); |
f6fad28e DK |
8762 | f->proc_sym = sym; |
8763 | f->proc_tree = NULL; | |
34523524 | 8764 | f->where = gfc_current_locus; |
30b608eb DK |
8765 | f->next = block->f2k_derived->finalizers; |
8766 | block->f2k_derived->finalizers = f; | |
34523524 DK |
8767 | |
8768 | first = false; | |
8769 | } | |
8770 | while (!last); | |
8771 | ||
8772 | return MATCH_YES; | |
8773 | } | |
08a6b8e0 TB |
8774 | |
8775 | ||
8776 | const ext_attr_t ext_attr_list[] = { | |
e7ac6a7c TB |
8777 | { "dllimport", EXT_ATTR_DLLIMPORT, "dllimport" }, |
8778 | { "dllexport", EXT_ATTR_DLLEXPORT, "dllexport" }, | |
8779 | { "cdecl", EXT_ATTR_CDECL, "cdecl" }, | |
8780 | { "stdcall", EXT_ATTR_STDCALL, "stdcall" }, | |
8781 | { "fastcall", EXT_ATTR_FASTCALL, "fastcall" }, | |
8782 | { "no_arg_check", EXT_ATTR_NO_ARG_CHECK, NULL }, | |
8783 | { NULL, EXT_ATTR_LAST, NULL } | |
08a6b8e0 TB |
8784 | }; |
8785 | ||
8786 | /* Match a !GCC$ ATTRIBUTES statement of the form: | |
8787 | !GCC$ ATTRIBUTES attribute-list :: var-name [, var-name] ... | |
8788 | When we come here, we have already matched the !GCC$ ATTRIBUTES string. | |
8789 | ||
8790 | TODO: We should support all GCC attributes using the same syntax for | |
8791 | the attribute list, i.e. the list in C | |
8792 | __attributes(( attribute-list )) | |
8793 | matches then | |
8794 | !GCC$ ATTRIBUTES attribute-list :: | |
8795 | Cf. c-parser.c's c_parser_attributes; the data can then directly be | |
8796 | saved into a TREE. | |
8797 | ||
8798 | As there is absolutely no risk of confusion, we should never return | |
8799 | MATCH_NO. */ | |
8800 | match | |
8801 | gfc_match_gcc_attributes (void) | |
f5acf0f2 | 8802 | { |
08a6b8e0 TB |
8803 | symbol_attribute attr; |
8804 | char name[GFC_MAX_SYMBOL_LEN + 1]; | |
8805 | unsigned id; | |
8806 | gfc_symbol *sym; | |
8807 | match m; | |
8808 | ||
8809 | gfc_clear_attr (&attr); | |
8810 | for(;;) | |
8811 | { | |
8812 | char ch; | |
8813 | ||
8814 | if (gfc_match_name (name) != MATCH_YES) | |
8815 | return MATCH_ERROR; | |
8816 | ||
8817 | for (id = 0; id < EXT_ATTR_LAST; id++) | |
8818 | if (strcmp (name, ext_attr_list[id].name) == 0) | |
8819 | break; | |
8820 | ||
8821 | if (id == EXT_ATTR_LAST) | |
8822 | { | |
8823 | gfc_error ("Unknown attribute in !GCC$ ATTRIBUTES statement at %C"); | |
8824 | return MATCH_ERROR; | |
8825 | } | |
8826 | ||
524af0d6 | 8827 | if (!gfc_add_ext_attribute (&attr, (ext_attr_id_t)id, &gfc_current_locus)) |
08a6b8e0 TB |
8828 | return MATCH_ERROR; |
8829 | ||
8830 | gfc_gobble_whitespace (); | |
8831 | ch = gfc_next_ascii_char (); | |
8832 | if (ch == ':') | |
8833 | { | |
8834 | /* This is the successful exit condition for the loop. */ | |
8835 | if (gfc_next_ascii_char () == ':') | |
8836 | break; | |
8837 | } | |
8838 | ||
8839 | if (ch == ',') | |
8840 | continue; | |
8841 | ||
8842 | goto syntax; | |
8843 | } | |
8844 | ||
8845 | if (gfc_match_eos () == MATCH_YES) | |
8846 | goto syntax; | |
8847 | ||
8848 | for(;;) | |
8849 | { | |
8850 | m = gfc_match_name (name); | |
8851 | if (m != MATCH_YES) | |
8852 | return m; | |
8853 | ||
8854 | if (find_special (name, &sym, true)) | |
8855 | return MATCH_ERROR; | |
f5acf0f2 | 8856 | |
08a6b8e0 TB |
8857 | sym->attr.ext_attr |= attr.ext_attr; |
8858 | ||
8859 | if (gfc_match_eos () == MATCH_YES) | |
8860 | break; | |
8861 | ||
8862 | if (gfc_match_char (',') != MATCH_YES) | |
8863 | goto syntax; | |
8864 | } | |
8865 | ||
8866 | return MATCH_YES; | |
8867 | ||
8868 | syntax: | |
8869 | gfc_error ("Syntax error in !GCC$ ATTRIBUTES statement at %C"); | |
8870 | return MATCH_ERROR; | |
8871 | } |