| 1 |
/* Main parser. |
| 2 |
Copyright (C) 2000-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Andy Vaught |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify it under |
| 8 |
the terms of the GNU General Public License as published by the Free |
| 9 |
Software Foundation; either version 3, or (at your option) any later |
| 10 |
version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 |
for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
#include "system.h" |
| 23 |
#include "coretypes.h" |
| 24 |
#include "options.h" |
| 25 |
#include "gfortran.h" |
| 26 |
#include <setjmp.h> |
| 27 |
#include "match.h" |
| 28 |
#include "parse.h" |
| 29 |
#include "tree-core.h" |
| 30 |
#include "omp-general.h" |
| 31 |
|
| 32 |
/* Current statement label. Zero means no statement label. Because new_st |
| 33 |
can get wiped during statement matching, we have to keep it separate. */ |
| 34 |
|
| 35 |
gfc_st_label *gfc_statement_label; |
| 36 |
|
| 37 |
static locus label_locus; |
| 38 |
static jmp_buf eof_buf; |
| 39 |
|
| 40 |
/* Respectively pointer and content of the current interface body being parsed |
| 41 |
as they were at the beginning of decode_statement. Used to restore the |
| 42 |
interface to its previous state in case a parsed statement is rejected after |
| 43 |
some symbols have been added to the interface. */ |
| 44 |
static gfc_interface **current_interface_ptr = nullptr; |
| 45 |
static gfc_interface *previous_interface_head = nullptr; |
| 46 |
|
| 47 |
gfc_state_data *gfc_state_stack; |
| 48 |
static bool last_was_use_stmt = false; |
| 49 |
bool in_exec_part; |
| 50 |
|
| 51 |
/* True when matching an OpenMP context selector. */ |
| 52 |
bool gfc_matching_omp_context_selector; |
| 53 |
|
| 54 |
/* True when parsing the body of an OpenMP metadirective. */ |
| 55 |
bool gfc_in_omp_metadirective_body; |
| 56 |
|
| 57 |
/* Each metadirective body in the translation unit is given a unique |
| 58 |
number, used to ensure that labels in the body have unique names. */ |
| 59 |
int gfc_omp_metadirective_region_count; |
| 60 |
|
| 61 |
/* TODO: Re-order functions to kill these forward decls. */ |
| 62 |
static void check_statement_label (gfc_statement); |
| 63 |
static void undo_new_statement (void); |
| 64 |
static void reject_statement (void); |
| 65 |
|
| 66 |
|
| 67 |
/* A sort of half-matching function. We try to match the word on the |
| 68 |
input with the passed string. If this succeeds, we call the |
| 69 |
keyword-dependent matching function that will match the rest of the |
| 70 |
statement. For single keywords, the matching subroutine is |
| 71 |
gfc_match_eos(). */ |
| 72 |
|
| 73 |
static match |
| 74 |
match_word (const char *str, match (*subr) (void), locus *old_locus) |
| 75 |
{ |
| 76 |
match m; |
| 77 |
|
| 78 |
if (str != NULL) |
| 79 |
{ |
| 80 |
m = gfc_match (str); |
| 81 |
if (m != MATCH_YES) |
| 82 |
return m; |
| 83 |
} |
| 84 |
|
| 85 |
m = (*subr) (); |
| 86 |
|
| 87 |
if (m != MATCH_YES) |
| 88 |
{ |
| 89 |
gfc_current_locus = *old_locus; |
| 90 |
reject_statement (); |
| 91 |
} |
| 92 |
|
| 93 |
return m; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
/* Like match_word, but if str is matched, set a flag that it |
| 98 |
was matched. */ |
| 99 |
static match |
| 100 |
match_word_omp_simd (const char *str, match (*subr) (void), locus *old_locus, |
| 101 |
bool *simd_matched) |
| 102 |
{ |
| 103 |
match m; |
| 104 |
|
| 105 |
if (str != NULL) |
| 106 |
{ |
| 107 |
m = gfc_match (str); |
| 108 |
if (m != MATCH_YES) |
| 109 |
return m; |
| 110 |
*simd_matched = true; |
| 111 |
} |
| 112 |
|
| 113 |
m = (*subr) (); |
| 114 |
|
| 115 |
if (m != MATCH_YES) |
| 116 |
{ |
| 117 |
gfc_current_locus = *old_locus; |
| 118 |
reject_statement (); |
| 119 |
} |
| 120 |
|
| 121 |
return m; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
/* Load symbols from all USE statements encountered in this scoping unit. */ |
| 126 |
|
| 127 |
static void |
| 128 |
use_modules (void) |
| 129 |
{ |
| 130 |
gfc_error_buffer old_error; |
| 131 |
|
| 132 |
gfc_push_error (&old_error); |
| 133 |
gfc_buffer_error (false); |
| 134 |
gfc_use_modules (); |
| 135 |
gfc_buffer_error (true); |
| 136 |
gfc_pop_error (&old_error); |
| 137 |
gfc_commit_symbols (); |
| 138 |
gfc_warning_check (); |
| 139 |
gfc_current_ns->old_equiv = gfc_current_ns->equiv; |
| 140 |
gfc_current_ns->old_data = gfc_current_ns->data; |
| 141 |
last_was_use_stmt = false; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
/* Figure out what the next statement is, (mostly) regardless of |
| 146 |
proper ordering. The do...while(0) is there to prevent if/else |
| 147 |
ambiguity. */ |
| 148 |
|
| 149 |
#define match(keyword, subr, st) \ |
| 150 |
do { \ |
| 151 |
if (match_word (keyword, subr, &old_locus) == MATCH_YES) \ |
| 152 |
return st; \ |
| 153 |
else \ |
| 154 |
undo_new_statement (); \ |
| 155 |
} while (0) |
| 156 |
|
| 157 |
|
| 158 |
/* This is a specialist version of decode_statement that is used |
| 159 |
for the specification statements in a function, whose |
| 160 |
characteristics are deferred into the specification statements. |
| 161 |
eg.: INTEGER (king = mykind) foo () |
| 162 |
USE mymodule, ONLY mykind..... |
| 163 |
The KIND parameter needs a return after USE or IMPORT, whereas |
| 164 |
derived type declarations can occur anywhere, up the executable |
| 165 |
block. ST_GET_FCN_CHARACTERISTICS is returned when we have run |
| 166 |
out of the correct kind of specification statements. */ |
| 167 |
static gfc_statement |
| 168 |
decode_specification_statement (void) |
| 169 |
{ |
| 170 |
gfc_statement st; |
| 171 |
locus old_locus; |
| 172 |
char c; |
| 173 |
|
| 174 |
if (gfc_match_eos () == MATCH_YES) |
| 175 |
return ST_NONE; |
| 176 |
|
| 177 |
old_locus = gfc_current_locus; |
| 178 |
|
| 179 |
if (match_word ("use", gfc_match_use, &old_locus) == MATCH_YES) |
| 180 |
{ |
| 181 |
last_was_use_stmt = true; |
| 182 |
return ST_USE; |
| 183 |
} |
| 184 |
else |
| 185 |
{ |
| 186 |
undo_new_statement (); |
| 187 |
if (last_was_use_stmt) |
| 188 |
use_modules (); |
| 189 |
} |
| 190 |
|
| 191 |
match ("import", gfc_match_import, ST_IMPORT); |
| 192 |
|
| 193 |
if (gfc_current_block ()->result->ts.type != BT_DERIVED) |
| 194 |
goto end_of_block; |
| 195 |
|
| 196 |
match (NULL, gfc_match_st_function, ST_STATEMENT_FUNCTION); |
| 197 |
match (NULL, gfc_match_data_decl, ST_DATA_DECL); |
| 198 |
match (NULL, gfc_match_enumerator_def, ST_ENUMERATOR); |
| 199 |
|
| 200 |
/* General statement matching: Instead of testing every possible |
| 201 |
statement, we eliminate most possibilities by peeking at the |
| 202 |
first character. */ |
| 203 |
|
| 204 |
c = gfc_peek_ascii_char (); |
| 205 |
|
| 206 |
switch (c) |
| 207 |
{ |
| 208 |
case 'a': |
| 209 |
match ("abstract% interface", gfc_match_abstract_interface, |
| 210 |
ST_INTERFACE); |
| 211 |
match ("allocatable", gfc_match_allocatable, ST_ATTR_DECL); |
| 212 |
match ("asynchronous", gfc_match_asynchronous, ST_ATTR_DECL); |
| 213 |
match ("automatic", gfc_match_automatic, ST_ATTR_DECL); |
| 214 |
break; |
| 215 |
|
| 216 |
case 'b': |
| 217 |
match (NULL, gfc_match_bind_c_stmt, ST_ATTR_DECL); |
| 218 |
break; |
| 219 |
|
| 220 |
case 'c': |
| 221 |
match ("codimension", gfc_match_codimension, ST_ATTR_DECL); |
| 222 |
match ("contiguous", gfc_match_contiguous, ST_ATTR_DECL); |
| 223 |
break; |
| 224 |
|
| 225 |
case 'd': |
| 226 |
match ("data", gfc_match_data, ST_DATA); |
| 227 |
match ("dimension", gfc_match_dimension, ST_ATTR_DECL); |
| 228 |
break; |
| 229 |
|
| 230 |
case 'e': |
| 231 |
match ("enum , bind ( c )", gfc_match_enum, ST_ENUM); |
| 232 |
match ("entry% ", gfc_match_entry, ST_ENTRY); |
| 233 |
match ("equivalence", gfc_match_equivalence, ST_EQUIVALENCE); |
| 234 |
match ("external", gfc_match_external, ST_ATTR_DECL); |
| 235 |
break; |
| 236 |
|
| 237 |
case 'f': |
| 238 |
match ("format", gfc_match_format, ST_FORMAT); |
| 239 |
break; |
| 240 |
|
| 241 |
case 'g': |
| 242 |
break; |
| 243 |
|
| 244 |
case 'i': |
| 245 |
match ("implicit", gfc_match_implicit, ST_IMPLICIT); |
| 246 |
match ("implicit% none", gfc_match_implicit_none, ST_IMPLICIT_NONE); |
| 247 |
match ("interface", gfc_match_interface, ST_INTERFACE); |
| 248 |
match ("intent", gfc_match_intent, ST_ATTR_DECL); |
| 249 |
match ("intrinsic", gfc_match_intrinsic, ST_ATTR_DECL); |
| 250 |
break; |
| 251 |
|
| 252 |
case 'm': |
| 253 |
break; |
| 254 |
|
| 255 |
case 'n': |
| 256 |
match ("namelist", gfc_match_namelist, ST_NAMELIST); |
| 257 |
break; |
| 258 |
|
| 259 |
case 'o': |
| 260 |
match ("optional", gfc_match_optional, ST_ATTR_DECL); |
| 261 |
break; |
| 262 |
|
| 263 |
case 'p': |
| 264 |
match ("parameter", gfc_match_parameter, ST_PARAMETER); |
| 265 |
match ("pointer", gfc_match_pointer, ST_ATTR_DECL); |
| 266 |
if (gfc_match_private (&st) == MATCH_YES) |
| 267 |
return st; |
| 268 |
match ("procedure", gfc_match_procedure, ST_PROCEDURE); |
| 269 |
if (gfc_match_public (&st) == MATCH_YES) |
| 270 |
return st; |
| 271 |
match ("protected", gfc_match_protected, ST_ATTR_DECL); |
| 272 |
break; |
| 273 |
|
| 274 |
case 'r': |
| 275 |
break; |
| 276 |
|
| 277 |
case 's': |
| 278 |
match ("save", gfc_match_save, ST_ATTR_DECL); |
| 279 |
match ("static", gfc_match_static, ST_ATTR_DECL); |
| 280 |
match ("structure", gfc_match_structure_decl, ST_STRUCTURE_DECL); |
| 281 |
break; |
| 282 |
|
| 283 |
case 't': |
| 284 |
match ("target", gfc_match_target, ST_ATTR_DECL); |
| 285 |
match ("type", gfc_match_derived_decl, ST_DERIVED_DECL); |
| 286 |
break; |
| 287 |
|
| 288 |
case 'u': |
| 289 |
break; |
| 290 |
|
| 291 |
case 'v': |
| 292 |
match ("value", gfc_match_value, ST_ATTR_DECL); |
| 293 |
match ("volatile", gfc_match_volatile, ST_ATTR_DECL); |
| 294 |
break; |
| 295 |
|
| 296 |
case 'w': |
| 297 |
break; |
| 298 |
} |
| 299 |
|
| 300 |
/* This is not a specification statement. See if any of the matchers |
| 301 |
has stored an error message of some sort. */ |
| 302 |
|
| 303 |
end_of_block: |
| 304 |
gfc_clear_error (); |
| 305 |
gfc_buffer_error (false); |
| 306 |
gfc_current_locus = old_locus; |
| 307 |
|
| 308 |
return ST_GET_FCN_CHARACTERISTICS; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
/* Tells whether gfc_get_current_interface_head can be used safely. */ |
| 313 |
|
| 314 |
static bool |
| 315 |
current_interface_valid_p () |
| 316 |
{ |
| 317 |
switch (current_interface.type) |
| 318 |
{ |
| 319 |
case INTERFACE_INTRINSIC_OP: |
| 320 |
return current_interface.ns != nullptr; |
| 321 |
|
| 322 |
case INTERFACE_GENERIC: |
| 323 |
case INTERFACE_DTIO: |
| 324 |
return current_interface.sym != nullptr; |
| 325 |
|
| 326 |
case INTERFACE_USER_OP: |
| 327 |
return current_interface.uop != nullptr; |
| 328 |
|
| 329 |
default: |
| 330 |
return false; |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
/* Return a pointer to the interface currently being parsed, or nullptr if |
| 336 |
we are not currently parsing an interface body. */ |
| 337 |
|
| 338 |
static gfc_interface ** |
| 339 |
get_current_interface_ptr () |
| 340 |
{ |
| 341 |
if (current_interface_valid_p ()) |
| 342 |
{ |
| 343 |
gfc_interface *& ifc_ptr = gfc_current_interface_head (); |
| 344 |
return &ifc_ptr; |
| 345 |
} |
| 346 |
else |
| 347 |
return nullptr; |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
static bool in_specification_block; |
| 352 |
|
| 353 |
/* This is the primary 'decode_statement'. */ |
| 354 |
static gfc_statement |
| 355 |
decode_statement (void) |
| 356 |
{ |
| 357 |
gfc_statement st; |
| 358 |
locus old_locus; |
| 359 |
match m = MATCH_NO; |
| 360 |
char c; |
| 361 |
|
| 362 |
gfc_enforce_clean_symbol_state (); |
| 363 |
|
| 364 |
gfc_clear_error (); /* Clear any pending errors. */ |
| 365 |
gfc_clear_warning (); /* Clear any pending warnings. */ |
| 366 |
|
| 367 |
current_interface_ptr = get_current_interface_ptr (); |
| 368 |
previous_interface_head = current_interface_ptr == nullptr |
| 369 |
? nullptr |
| 370 |
: *current_interface_ptr; |
| 371 |
|
| 372 |
gfc_matching_function = false; |
| 373 |
|
| 374 |
if (gfc_match_eos () == MATCH_YES) |
| 375 |
return ST_NONE; |
| 376 |
|
| 377 |
if (gfc_current_state () == COMP_FUNCTION |
| 378 |
&& gfc_current_block ()->result->ts.kind == -1) |
| 379 |
return decode_specification_statement (); |
| 380 |
|
| 381 |
old_locus = gfc_current_locus; |
| 382 |
|
| 383 |
c = gfc_peek_ascii_char (); |
| 384 |
|
| 385 |
if (c == 'u') |
| 386 |
{ |
| 387 |
if (match_word ("use", gfc_match_use, &old_locus) == MATCH_YES) |
| 388 |
{ |
| 389 |
last_was_use_stmt = true; |
| 390 |
return ST_USE; |
| 391 |
} |
| 392 |
else |
| 393 |
undo_new_statement (); |
| 394 |
} |
| 395 |
|
| 396 |
if (last_was_use_stmt) |
| 397 |
use_modules (); |
| 398 |
|
| 399 |
/* Try matching a data declaration or function declaration. The |
| 400 |
input "REALFUNCTIONA(N)" can mean several things in different |
| 401 |
contexts, so it (and its relatives) get special treatment. */ |
| 402 |
|
| 403 |
if (gfc_current_state () == COMP_NONE |
| 404 |
|| gfc_current_state () == COMP_INTERFACE |
| 405 |
|| gfc_current_state () == COMP_CONTAINS) |
| 406 |
{ |
| 407 |
gfc_matching_function = true; |
| 408 |
m = gfc_match_function_decl (); |
| 409 |
if (m == MATCH_YES) |
| 410 |
return ST_FUNCTION; |
| 411 |
else if (m == MATCH_ERROR) |
| 412 |
reject_statement (); |
| 413 |
else |
| 414 |
gfc_undo_symbols (); |
| 415 |
gfc_current_locus = old_locus; |
| 416 |
} |
| 417 |
gfc_matching_function = false; |
| 418 |
|
| 419 |
/* Legacy parameter statements are ambiguous with assignments so try parameter |
| 420 |
first. */ |
| 421 |
match ("parameter", gfc_match_parameter, ST_PARAMETER); |
| 422 |
|
| 423 |
/* Match statements whose error messages are meant to be overwritten |
| 424 |
by something better. */ |
| 425 |
|
| 426 |
match (NULL, gfc_match_assignment, ST_ASSIGNMENT); |
| 427 |
match (NULL, gfc_match_pointer_assignment, ST_POINTER_ASSIGNMENT); |
| 428 |
|
| 429 |
if (in_specification_block) |
| 430 |
{ |
| 431 |
m = match_word (NULL, gfc_match_st_function, &old_locus); |
| 432 |
if (m == MATCH_YES) |
| 433 |
return ST_STATEMENT_FUNCTION; |
| 434 |
} |
| 435 |
|
| 436 |
if (!(in_specification_block && m == MATCH_ERROR)) |
| 437 |
{ |
| 438 |
match (NULL, gfc_match_ptr_fcn_assign, ST_ASSIGNMENT); |
| 439 |
} |
| 440 |
|
| 441 |
match (NULL, gfc_match_data_decl, ST_DATA_DECL); |
| 442 |
match (NULL, gfc_match_enumerator_def, ST_ENUMERATOR); |
| 443 |
|
| 444 |
/* Try to match a subroutine statement, which has the same optional |
| 445 |
prefixes that functions can have. */ |
| 446 |
|
| 447 |
if (gfc_match_subroutine () == MATCH_YES) |
| 448 |
return ST_SUBROUTINE; |
| 449 |
gfc_undo_symbols (); |
| 450 |
gfc_current_locus = old_locus; |
| 451 |
|
| 452 |
if (gfc_match_submod_proc () == MATCH_YES) |
| 453 |
{ |
| 454 |
if (gfc_new_block->attr.subroutine) |
| 455 |
return ST_SUBROUTINE; |
| 456 |
else if (gfc_new_block->attr.function) |
| 457 |
return ST_FUNCTION; |
| 458 |
} |
| 459 |
gfc_undo_symbols (); |
| 460 |
gfc_current_locus = old_locus; |
| 461 |
|
| 462 |
/* Check for the IF, DO, SELECT, WHERE, FORALL, CRITICAL, BLOCK and ASSOCIATE |
| 463 |
statements, which might begin with a block label. The match functions for |
| 464 |
these statements are unusual in that their keyword is not seen before |
| 465 |
the matcher is called. */ |
| 466 |
|
| 467 |
if (gfc_match_if (&st) == MATCH_YES) |
| 468 |
return st; |
| 469 |
gfc_undo_symbols (); |
| 470 |
gfc_current_locus = old_locus; |
| 471 |
|
| 472 |
if (gfc_match_where (&st) == MATCH_YES) |
| 473 |
return st; |
| 474 |
gfc_undo_symbols (); |
| 475 |
gfc_current_locus = old_locus; |
| 476 |
|
| 477 |
if (gfc_match_forall (&st) == MATCH_YES) |
| 478 |
return st; |
| 479 |
gfc_undo_symbols (); |
| 480 |
gfc_current_locus = old_locus; |
| 481 |
|
| 482 |
/* Try to match TYPE as an alias for PRINT. */ |
| 483 |
if (gfc_match_type (&st) == MATCH_YES) |
| 484 |
return st; |
| 485 |
gfc_undo_symbols (); |
| 486 |
gfc_current_locus = old_locus; |
| 487 |
|
| 488 |
match (NULL, gfc_match_do, ST_DO); |
| 489 |
match (NULL, gfc_match_block, ST_BLOCK); |
| 490 |
match (NULL, gfc_match_associate, ST_ASSOCIATE); |
| 491 |
match (NULL, gfc_match_critical, ST_CRITICAL); |
| 492 |
match (NULL, gfc_match_select, ST_SELECT_CASE); |
| 493 |
match (NULL, gfc_match_select_type, ST_SELECT_TYPE); |
| 494 |
match (NULL, gfc_match_select_rank, ST_SELECT_RANK); |
| 495 |
|
| 496 |
/* General statement matching: Instead of testing every possible |
| 497 |
statement, we eliminate most possibilities by peeking at the |
| 498 |
first character. */ |
| 499 |
|
| 500 |
switch (c) |
| 501 |
{ |
| 502 |
case 'a': |
| 503 |
match ("abstract% interface", gfc_match_abstract_interface, |
| 504 |
ST_INTERFACE); |
| 505 |
match ("allocate", gfc_match_allocate, ST_ALLOCATE); |
| 506 |
match ("allocatable", gfc_match_allocatable, ST_ATTR_DECL); |
| 507 |
match ("assign", gfc_match_assign, ST_LABEL_ASSIGNMENT); |
| 508 |
match ("asynchronous", gfc_match_asynchronous, ST_ATTR_DECL); |
| 509 |
match ("automatic", gfc_match_automatic, ST_ATTR_DECL); |
| 510 |
break; |
| 511 |
|
| 512 |
case 'b': |
| 513 |
match ("backspace", gfc_match_backspace, ST_BACKSPACE); |
| 514 |
match ("block data", gfc_match_block_data, ST_BLOCK_DATA); |
| 515 |
match (NULL, gfc_match_bind_c_stmt, ST_ATTR_DECL); |
| 516 |
break; |
| 517 |
|
| 518 |
case 'c': |
| 519 |
match ("call", gfc_match_call, ST_CALL); |
| 520 |
match ("change% team", gfc_match_change_team, ST_CHANGE_TEAM); |
| 521 |
match ("close", gfc_match_close, ST_CLOSE); |
| 522 |
match ("continue", gfc_match_continue, ST_CONTINUE); |
| 523 |
match ("contiguous", gfc_match_contiguous, ST_ATTR_DECL); |
| 524 |
match ("cycle", gfc_match_cycle, ST_CYCLE); |
| 525 |
match ("case", gfc_match_case, ST_CASE); |
| 526 |
match ("common", gfc_match_common, ST_COMMON); |
| 527 |
match ("contains", gfc_match_eos, ST_CONTAINS); |
| 528 |
match ("class", gfc_match_class_is, ST_CLASS_IS); |
| 529 |
match ("codimension", gfc_match_codimension, ST_ATTR_DECL); |
| 530 |
break; |
| 531 |
|
| 532 |
case 'd': |
| 533 |
match ("deallocate", gfc_match_deallocate, ST_DEALLOCATE); |
| 534 |
match ("data", gfc_match_data, ST_DATA); |
| 535 |
match ("dimension", gfc_match_dimension, ST_ATTR_DECL); |
| 536 |
break; |
| 537 |
|
| 538 |
case 'e': |
| 539 |
match ("end file", gfc_match_endfile, ST_END_FILE); |
| 540 |
match ("end team", gfc_match_end_team, ST_END_TEAM); |
| 541 |
match ("exit", gfc_match_exit, ST_EXIT); |
| 542 |
match ("else", gfc_match_else, ST_ELSE); |
| 543 |
match ("else where", gfc_match_elsewhere, ST_ELSEWHERE); |
| 544 |
match ("else if", gfc_match_elseif, ST_ELSEIF); |
| 545 |
match ("error% stop", gfc_match_error_stop, ST_ERROR_STOP); |
| 546 |
match ("enum , bind ( c )", gfc_match_enum, ST_ENUM); |
| 547 |
|
| 548 |
if (gfc_match_end (&st) == MATCH_YES) |
| 549 |
return st; |
| 550 |
|
| 551 |
match ("entry% ", gfc_match_entry, ST_ENTRY); |
| 552 |
match ("equivalence", gfc_match_equivalence, ST_EQUIVALENCE); |
| 553 |
match ("external", gfc_match_external, ST_ATTR_DECL); |
| 554 |
match ("event% post", gfc_match_event_post, ST_EVENT_POST); |
| 555 |
match ("event% wait", gfc_match_event_wait, ST_EVENT_WAIT); |
| 556 |
break; |
| 557 |
|
| 558 |
case 'f': |
| 559 |
match ("fail% image", gfc_match_fail_image, ST_FAIL_IMAGE); |
| 560 |
match ("final", gfc_match_final_decl, ST_FINAL); |
| 561 |
match ("flush", gfc_match_flush, ST_FLUSH); |
| 562 |
match ("form% team", gfc_match_form_team, ST_FORM_TEAM); |
| 563 |
match ("format", gfc_match_format, ST_FORMAT); |
| 564 |
break; |
| 565 |
|
| 566 |
case 'g': |
| 567 |
match ("generic", gfc_match_generic, ST_GENERIC); |
| 568 |
match ("go to", gfc_match_goto, ST_GOTO); |
| 569 |
break; |
| 570 |
|
| 571 |
case 'i': |
| 572 |
match ("inquire", gfc_match_inquire, ST_INQUIRE); |
| 573 |
match ("implicit", gfc_match_implicit, ST_IMPLICIT); |
| 574 |
match ("implicit% none", gfc_match_implicit_none, ST_IMPLICIT_NONE); |
| 575 |
match ("import", gfc_match_import, ST_IMPORT); |
| 576 |
match ("interface", gfc_match_interface, ST_INTERFACE); |
| 577 |
match ("intent", gfc_match_intent, ST_ATTR_DECL); |
| 578 |
match ("intrinsic", gfc_match_intrinsic, ST_ATTR_DECL); |
| 579 |
break; |
| 580 |
|
| 581 |
case 'l': |
| 582 |
match ("lock", gfc_match_lock, ST_LOCK); |
| 583 |
break; |
| 584 |
|
| 585 |
case 'm': |
| 586 |
match ("map", gfc_match_map, ST_MAP); |
| 587 |
match ("module% procedure", gfc_match_modproc, ST_MODULE_PROC); |
| 588 |
match ("module", gfc_match_module, ST_MODULE); |
| 589 |
break; |
| 590 |
|
| 591 |
case 'n': |
| 592 |
match ("nullify", gfc_match_nullify, ST_NULLIFY); |
| 593 |
match ("namelist", gfc_match_namelist, ST_NAMELIST); |
| 594 |
break; |
| 595 |
|
| 596 |
case 'o': |
| 597 |
match ("open", gfc_match_open, ST_OPEN); |
| 598 |
match ("optional", gfc_match_optional, ST_ATTR_DECL); |
| 599 |
break; |
| 600 |
|
| 601 |
case 'p': |
| 602 |
match ("print", gfc_match_print, ST_WRITE); |
| 603 |
match ("pause", gfc_match_pause, ST_PAUSE); |
| 604 |
match ("pointer", gfc_match_pointer, ST_ATTR_DECL); |
| 605 |
if (gfc_match_private (&st) == MATCH_YES) |
| 606 |
return st; |
| 607 |
match ("procedure", gfc_match_procedure, ST_PROCEDURE); |
| 608 |
match ("program", gfc_match_program, ST_PROGRAM); |
| 609 |
if (gfc_match_public (&st) == MATCH_YES) |
| 610 |
return st; |
| 611 |
match ("protected", gfc_match_protected, ST_ATTR_DECL); |
| 612 |
break; |
| 613 |
|
| 614 |
case 'r': |
| 615 |
match ("rank", gfc_match_rank_is, ST_RANK); |
| 616 |
match ("read", gfc_match_read, ST_READ); |
| 617 |
match ("return", gfc_match_return, ST_RETURN); |
| 618 |
match ("rewind", gfc_match_rewind, ST_REWIND); |
| 619 |
break; |
| 620 |
|
| 621 |
case 's': |
| 622 |
match ("structure", gfc_match_structure_decl, ST_STRUCTURE_DECL); |
| 623 |
match ("sequence", gfc_match_eos, ST_SEQUENCE); |
| 624 |
match ("stop", gfc_match_stop, ST_STOP); |
| 625 |
match ("save", gfc_match_save, ST_ATTR_DECL); |
| 626 |
match ("static", gfc_match_static, ST_ATTR_DECL); |
| 627 |
match ("submodule", gfc_match_submodule, ST_SUBMODULE); |
| 628 |
match ("sync% all", gfc_match_sync_all, ST_SYNC_ALL); |
| 629 |
match ("sync% images", gfc_match_sync_images, ST_SYNC_IMAGES); |
| 630 |
match ("sync% memory", gfc_match_sync_memory, ST_SYNC_MEMORY); |
| 631 |
match ("sync% team", gfc_match_sync_team, ST_SYNC_TEAM); |
| 632 |
break; |
| 633 |
|
| 634 |
case 't': |
| 635 |
match ("target", gfc_match_target, ST_ATTR_DECL); |
| 636 |
match ("type", gfc_match_derived_decl, ST_DERIVED_DECL); |
| 637 |
match ("type% is", gfc_match_type_is, ST_TYPE_IS); |
| 638 |
break; |
| 639 |
|
| 640 |
case 'u': |
| 641 |
match ("union", gfc_match_union, ST_UNION); |
| 642 |
match ("unlock", gfc_match_unlock, ST_UNLOCK); |
| 643 |
break; |
| 644 |
|
| 645 |
case 'v': |
| 646 |
match ("value", gfc_match_value, ST_ATTR_DECL); |
| 647 |
match ("volatile", gfc_match_volatile, ST_ATTR_DECL); |
| 648 |
break; |
| 649 |
|
| 650 |
case 'w': |
| 651 |
match ("wait", gfc_match_wait, ST_WAIT); |
| 652 |
match ("write", gfc_match_write, ST_WRITE); |
| 653 |
break; |
| 654 |
} |
| 655 |
|
| 656 |
/* All else has failed, so give up. See if any of the matchers has |
| 657 |
stored an error message of some sort. Suppress the "Unclassifiable |
| 658 |
statement" if a previous error message was emitted, e.g., by |
| 659 |
gfc_error_now (). */ |
| 660 |
if (!gfc_error_check ()) |
| 661 |
{ |
| 662 |
int ecnt; |
| 663 |
gfc_get_errors (NULL, &ecnt); |
| 664 |
if (ecnt <= 0) |
| 665 |
gfc_error_now ("Unclassifiable statement at %C"); |
| 666 |
} |
| 667 |
|
| 668 |
reject_statement (); |
| 669 |
|
| 670 |
gfc_error_recovery (); |
| 671 |
|
| 672 |
return ST_NONE; |
| 673 |
} |
| 674 |
|
| 675 |
/* Like match and if spec_only, goto do_spec_only without actually |
| 676 |
matching. */ |
| 677 |
/* If the directive matched but the clauses failed, do not start |
| 678 |
matching the next directive in the same switch statement. */ |
| 679 |
#define matcha(keyword, subr, st) \ |
| 680 |
do { \ |
| 681 |
match m2; \ |
| 682 |
if (spec_only && gfc_match (keyword) == MATCH_YES) \ |
| 683 |
goto do_spec_only; \ |
| 684 |
else if ((m2 = match_word (keyword, subr, &old_locus)) \ |
| 685 |
== MATCH_YES) \ |
| 686 |
return st; \ |
| 687 |
else if (m2 == MATCH_ERROR) \ |
| 688 |
goto error_handling; \ |
| 689 |
else \ |
| 690 |
undo_new_statement (); \ |
| 691 |
} while (0) |
| 692 |
|
| 693 |
static gfc_statement |
| 694 |
decode_oacc_directive (void) |
| 695 |
{ |
| 696 |
locus old_locus; |
| 697 |
char c; |
| 698 |
bool spec_only = false; |
| 699 |
|
| 700 |
gfc_enforce_clean_symbol_state (); |
| 701 |
|
| 702 |
gfc_clear_error (); /* Clear any pending errors. */ |
| 703 |
gfc_clear_warning (); /* Clear any pending warnings. */ |
| 704 |
|
| 705 |
gfc_matching_function = false; |
| 706 |
|
| 707 |
if (gfc_current_state () == COMP_FUNCTION |
| 708 |
&& gfc_current_block ()->result->ts.kind == -1) |
| 709 |
spec_only = true; |
| 710 |
|
| 711 |
old_locus = gfc_current_locus; |
| 712 |
|
| 713 |
/* General OpenACC directive matching: Instead of testing every possible |
| 714 |
statement, we eliminate most possibilities by peeking at the |
| 715 |
first character. */ |
| 716 |
|
| 717 |
c = gfc_peek_ascii_char (); |
| 718 |
|
| 719 |
switch (c) |
| 720 |
{ |
| 721 |
case 'r': |
| 722 |
matcha ("routine", gfc_match_oacc_routine, ST_OACC_ROUTINE); |
| 723 |
break; |
| 724 |
} |
| 725 |
|
| 726 |
gfc_unset_implicit_pure (NULL); |
| 727 |
if (gfc_pure (NULL)) |
| 728 |
{ |
| 729 |
gfc_error_now ("OpenACC directives other than ROUTINE may not appear in PURE " |
| 730 |
"procedures at %C"); |
| 731 |
goto error_handling; |
| 732 |
} |
| 733 |
|
| 734 |
switch (c) |
| 735 |
{ |
| 736 |
case 'a': |
| 737 |
matcha ("atomic", gfc_match_oacc_atomic, ST_OACC_ATOMIC); |
| 738 |
break; |
| 739 |
case 'c': |
| 740 |
matcha ("cache", gfc_match_oacc_cache, ST_OACC_CACHE); |
| 741 |
break; |
| 742 |
case 'd': |
| 743 |
matcha ("data", gfc_match_oacc_data, ST_OACC_DATA); |
| 744 |
match ("declare", gfc_match_oacc_declare, ST_OACC_DECLARE); |
| 745 |
break; |
| 746 |
case 'e': |
| 747 |
matcha ("end atomic", gfc_match_omp_eos_error, ST_OACC_END_ATOMIC); |
| 748 |
matcha ("end data", gfc_match_omp_eos_error, ST_OACC_END_DATA); |
| 749 |
matcha ("end host_data", gfc_match_omp_eos_error, ST_OACC_END_HOST_DATA); |
| 750 |
matcha ("end kernels loop", gfc_match_omp_eos_error, ST_OACC_END_KERNELS_LOOP); |
| 751 |
matcha ("end kernels", gfc_match_omp_eos_error, ST_OACC_END_KERNELS); |
| 752 |
matcha ("end loop", gfc_match_omp_eos_error, ST_OACC_END_LOOP); |
| 753 |
matcha ("end parallel loop", gfc_match_omp_eos_error, |
| 754 |
ST_OACC_END_PARALLEL_LOOP); |
| 755 |
matcha ("end parallel", gfc_match_omp_eos_error, ST_OACC_END_PARALLEL); |
| 756 |
matcha ("end serial loop", gfc_match_omp_eos_error, |
| 757 |
ST_OACC_END_SERIAL_LOOP); |
| 758 |
matcha ("end serial", gfc_match_omp_eos_error, ST_OACC_END_SERIAL); |
| 759 |
matcha ("enter data", gfc_match_oacc_enter_data, ST_OACC_ENTER_DATA); |
| 760 |
matcha ("exit data", gfc_match_oacc_exit_data, ST_OACC_EXIT_DATA); |
| 761 |
break; |
| 762 |
case 'h': |
| 763 |
matcha ("host_data", gfc_match_oacc_host_data, ST_OACC_HOST_DATA); |
| 764 |
break; |
| 765 |
case 'p': |
| 766 |
matcha ("parallel loop", gfc_match_oacc_parallel_loop, |
| 767 |
ST_OACC_PARALLEL_LOOP); |
| 768 |
matcha ("parallel", gfc_match_oacc_parallel, ST_OACC_PARALLEL); |
| 769 |
break; |
| 770 |
case 'k': |
| 771 |
matcha ("kernels loop", gfc_match_oacc_kernels_loop, |
| 772 |
ST_OACC_KERNELS_LOOP); |
| 773 |
matcha ("kernels", gfc_match_oacc_kernels, ST_OACC_KERNELS); |
| 774 |
break; |
| 775 |
case 'l': |
| 776 |
matcha ("loop", gfc_match_oacc_loop, ST_OACC_LOOP); |
| 777 |
break; |
| 778 |
case 's': |
| 779 |
matcha ("serial loop", gfc_match_oacc_serial_loop, ST_OACC_SERIAL_LOOP); |
| 780 |
matcha ("serial", gfc_match_oacc_serial, ST_OACC_SERIAL); |
| 781 |
break; |
| 782 |
case 'u': |
| 783 |
matcha ("update", gfc_match_oacc_update, ST_OACC_UPDATE); |
| 784 |
break; |
| 785 |
case 'w': |
| 786 |
matcha ("wait", gfc_match_oacc_wait, ST_OACC_WAIT); |
| 787 |
break; |
| 788 |
} |
| 789 |
|
| 790 |
/* Directive not found or stored an error message. |
| 791 |
Check and give up. */ |
| 792 |
|
| 793 |
error_handling: |
| 794 |
if (gfc_error_check () == 0) |
| 795 |
gfc_error_now ("Unclassifiable OpenACC directive at %C"); |
| 796 |
|
| 797 |
reject_statement (); |
| 798 |
|
| 799 |
gfc_error_recovery (); |
| 800 |
|
| 801 |
return ST_NONE; |
| 802 |
|
| 803 |
do_spec_only: |
| 804 |
reject_statement (); |
| 805 |
gfc_clear_error (); |
| 806 |
gfc_buffer_error (false); |
| 807 |
gfc_current_locus = old_locus; |
| 808 |
return ST_GET_FCN_CHARACTERISTICS; |
| 809 |
} |
| 810 |
|
| 811 |
/* Checks for the ST_OMP_ALLOCATE. First, check whether all list items |
| 812 |
are allocatables/pointers - and if so, assume it is associated with a Fortran |
| 813 |
ALLOCATE stmt. If not, do some initial parsing-related checks and append |
| 814 |
namelist to namespace. |
| 815 |
The check follows OpenMP 5.1 by requiring an executable stmt or OpenMP |
| 816 |
construct before a directive associated with an allocate statement |
| 817 |
(-> ST_OMP_ALLOCATE_EXEC); instead of showing an error, conversion of |
| 818 |
ST_OMP_ALLOCATE -> ST_OMP_ALLOCATE_EXEC would be an alternative. */ |
| 819 |
|
| 820 |
bool |
| 821 |
check_omp_allocate_stmt (locus *loc) |
| 822 |
{ |
| 823 |
gfc_omp_namelist *n; |
| 824 |
|
| 825 |
if (new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym == NULL) |
| 826 |
{ |
| 827 |
gfc_error ("%qs directive at %L must either have a variable argument or, " |
| 828 |
"if associated with an ALLOCATE stmt, must be preceded by an " |
| 829 |
"executable statement or OpenMP construct", |
| 830 |
gfc_ascii_statement (ST_OMP_ALLOCATE), loc); |
| 831 |
return false; |
| 832 |
} |
| 833 |
bool has_allocatable = false; |
| 834 |
bool has_non_allocatable = false; |
| 835 |
for (n = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]; n; n = n->next) |
| 836 |
{ |
| 837 |
if (n->expr) |
| 838 |
{ |
| 839 |
gfc_error ("Structure-component expression at %L in %qs directive not" |
| 840 |
" permitted in declarative directive; as directive " |
| 841 |
"associated with an ALLOCATE stmt it must be preceded by " |
| 842 |
"an executable statement or OpenMP construct", |
| 843 |
&n->expr->where, gfc_ascii_statement (ST_OMP_ALLOCATE)); |
| 844 |
return false; |
| 845 |
} |
| 846 |
/* Procedure pointers are not allocatable; hence, we do not regard them as |
| 847 |
pointers here - and reject them later in gfc_resolve_omp_allocate. */ |
| 848 |
bool alloc_ptr; |
| 849 |
if (n->sym->ts.type == BT_CLASS && n->sym->attr.class_ok) |
| 850 |
alloc_ptr = (CLASS_DATA (n->sym)->attr.allocatable |
| 851 |
|| CLASS_DATA (n->sym)->attr.class_pointer); |
| 852 |
else |
| 853 |
alloc_ptr = n->sym->attr.allocatable || n->sym->attr.pointer; |
| 854 |
if (alloc_ptr |
| 855 |
|| (n->sym->ns && n->sym->ns->proc_name |
| 856 |
&& (n->sym->ns->proc_name->attr.allocatable |
| 857 |
|| n->sym->ns->proc_name->attr.pointer))) |
| 858 |
has_allocatable = true; |
| 859 |
else |
| 860 |
has_non_allocatable = true; |
| 861 |
} |
| 862 |
/* All allocatables - assume it is allocated with an ALLOCATE stmt. */ |
| 863 |
if (has_allocatable && !has_non_allocatable) |
| 864 |
{ |
| 865 |
gfc_error ("%qs directive at %L associated with an ALLOCATE stmt must be " |
| 866 |
"preceded by an executable statement or OpenMP construct; " |
| 867 |
"note the variables in the list all have the allocatable or " |
| 868 |
"pointer attribute", gfc_ascii_statement (ST_OMP_ALLOCATE), |
| 869 |
loc); |
| 870 |
return false; |
| 871 |
} |
| 872 |
if (!gfc_current_ns->omp_allocate) |
| 873 |
gfc_current_ns->omp_allocate |
| 874 |
= new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]; |
| 875 |
else |
| 876 |
{ |
| 877 |
for (n = gfc_current_ns->omp_allocate; n->next; n = n->next) |
| 878 |
; |
| 879 |
n->next = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]; |
| 880 |
} |
| 881 |
new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE] = NULL; |
| 882 |
gfc_free_omp_clauses (new_st.ext.omp_clauses); |
| 883 |
return true; |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
/* Like match, but set a flag simd_matched if keyword matched |
| 888 |
and if spec_only, goto do_spec_only without actually matching. */ |
| 889 |
#define matchs(keyword, subr, st) \ |
| 890 |
do { \ |
| 891 |
match m2; \ |
| 892 |
if (spec_only && gfc_match (keyword) == MATCH_YES) \ |
| 893 |
goto do_spec_only; \ |
| 894 |
if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \ |
| 895 |
&simd_matched)) == MATCH_YES) \ |
| 896 |
{ \ |
| 897 |
ret = st; \ |
| 898 |
goto finish; \ |
| 899 |
} \ |
| 900 |
else if (m2 == MATCH_ERROR) \ |
| 901 |
goto error_handling; \ |
| 902 |
else \ |
| 903 |
undo_new_statement (); \ |
| 904 |
} while (0) |
| 905 |
|
| 906 |
/* Like match, but don't match anything if not -fopenmp |
| 907 |
and if spec_only, goto do_spec_only without actually matching. */ |
| 908 |
/* If the directive matched but the clauses failed, do not start |
| 909 |
matching the next directive in the same switch statement. */ |
| 910 |
#define matcho(keyword, subr, st) \ |
| 911 |
do { \ |
| 912 |
match m2; \ |
| 913 |
if (!flag_openmp) \ |
| 914 |
; \ |
| 915 |
else if (spec_only && gfc_match (keyword) == MATCH_YES) \ |
| 916 |
goto do_spec_only; \ |
| 917 |
else if ((m2 = match_word (keyword, subr, &old_locus)) \ |
| 918 |
== MATCH_YES) \ |
| 919 |
{ \ |
| 920 |
ret = st; \ |
| 921 |
goto finish; \ |
| 922 |
} \ |
| 923 |
else if (m2 == MATCH_ERROR) \ |
| 924 |
goto error_handling; \ |
| 925 |
else \ |
| 926 |
undo_new_statement (); \ |
| 927 |
} while (0) |
| 928 |
|
| 929 |
/* Like match, but set a flag simd_matched if keyword matched. */ |
| 930 |
#define matchds(keyword, subr, st) \ |
| 931 |
do { \ |
| 932 |
match m2; \ |
| 933 |
if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \ |
| 934 |
&simd_matched)) == MATCH_YES) \ |
| 935 |
{ \ |
| 936 |
ret = st; \ |
| 937 |
goto finish; \ |
| 938 |
} \ |
| 939 |
else if (m2 == MATCH_ERROR) \ |
| 940 |
goto error_handling; \ |
| 941 |
else \ |
| 942 |
undo_new_statement (); \ |
| 943 |
} while (0) |
| 944 |
|
| 945 |
/* Like match, but don't match anything if not -fopenmp. */ |
| 946 |
#define matchdo(keyword, subr, st) \ |
| 947 |
do { \ |
| 948 |
match m2; \ |
| 949 |
if (!flag_openmp) \ |
| 950 |
; \ |
| 951 |
else if ((m2 = match_word (keyword, subr, &old_locus)) \ |
| 952 |
== MATCH_YES) \ |
| 953 |
{ \ |
| 954 |
ret = st; \ |
| 955 |
goto finish; \ |
| 956 |
} \ |
| 957 |
else if (m2 == MATCH_ERROR) \ |
| 958 |
goto error_handling; \ |
| 959 |
else \ |
| 960 |
undo_new_statement (); \ |
| 961 |
} while (0) |
| 962 |
|
| 963 |
static gfc_statement |
| 964 |
decode_omp_directive (void) |
| 965 |
{ |
| 966 |
locus old_locus; |
| 967 |
char c; |
| 968 |
bool simd_matched = false; |
| 969 |
bool spec_only = false; |
| 970 |
gfc_statement ret = ST_NONE; |
| 971 |
bool pure_ok = true; |
| 972 |
|
| 973 |
gfc_enforce_clean_symbol_state (); |
| 974 |
|
| 975 |
gfc_clear_error (); /* Clear any pending errors. */ |
| 976 |
gfc_clear_warning (); /* Clear any pending warnings. */ |
| 977 |
|
| 978 |
gfc_matching_function = false; |
| 979 |
|
| 980 |
if (gfc_current_state () == COMP_FUNCTION |
| 981 |
&& gfc_current_block ()->result->ts.kind == -1) |
| 982 |
spec_only = true; |
| 983 |
|
| 984 |
old_locus = gfc_current_locus; |
| 985 |
|
| 986 |
/* General OpenMP directive matching: Instead of testing every possible |
| 987 |
statement, we eliminate most possibilities by peeking at the |
| 988 |
first character. */ |
| 989 |
|
| 990 |
c = gfc_peek_ascii_char (); |
| 991 |
|
| 992 |
/* match is for directives that should be recognized only if |
| 993 |
-fopenmp, matchs for directives that should be recognized |
| 994 |
if either -fopenmp or -fopenmp-simd. |
| 995 |
Handle only the directives allowed in PURE procedures |
| 996 |
first (those also shall not turn off implicit pure). */ |
| 997 |
switch (c) |
| 998 |
{ |
| 999 |
case 'a': |
| 1000 |
/* For -fopenmp-simd, ignore 'assumes'; note no clause starts with 's'. */ |
| 1001 |
if (!flag_openmp && gfc_match ("assumes") == MATCH_YES) |
| 1002 |
break; |
| 1003 |
matcho ("assumes", gfc_match_omp_assumes, ST_OMP_ASSUMES); |
| 1004 |
matchs ("assume", gfc_match_omp_assume, ST_OMP_ASSUME); |
| 1005 |
break; |
| 1006 |
|
| 1007 |
case 'b': |
| 1008 |
matcho ("begin metadirective", gfc_match_omp_begin_metadirective, |
| 1009 |
ST_OMP_BEGIN_METADIRECTIVE); |
| 1010 |
break; |
| 1011 |
|
| 1012 |
case 'd': |
| 1013 |
matchds ("declare reduction", gfc_match_omp_declare_reduction, |
| 1014 |
ST_OMP_DECLARE_REDUCTION); |
| 1015 |
matchds ("declare simd", gfc_match_omp_declare_simd, |
| 1016 |
ST_OMP_DECLARE_SIMD); |
| 1017 |
matchdo ("declare target", gfc_match_omp_declare_target, |
| 1018 |
ST_OMP_DECLARE_TARGET); |
| 1019 |
matchdo ("declare variant", gfc_match_omp_declare_variant, |
| 1020 |
ST_OMP_DECLARE_VARIANT); |
| 1021 |
break; |
| 1022 |
case 'e': |
| 1023 |
matchs ("end assume", gfc_match_omp_eos_error, ST_OMP_END_ASSUME); |
| 1024 |
matcho ("end metadirective", gfc_match_omp_eos_error, |
| 1025 |
ST_OMP_END_METADIRECTIVE); |
| 1026 |
matchs ("end simd", gfc_match_omp_eos_error, ST_OMP_END_SIMD); |
| 1027 |
matchs ("end tile", gfc_match_omp_eos_error, ST_OMP_END_TILE); |
| 1028 |
matchs ("end unroll", gfc_match_omp_eos_error, ST_OMP_END_UNROLL); |
| 1029 |
matcho ("error", gfc_match_omp_error, ST_OMP_ERROR); |
| 1030 |
break; |
| 1031 |
|
| 1032 |
case 'm': |
| 1033 |
matcho ("metadirective", gfc_match_omp_metadirective, |
| 1034 |
ST_OMP_METADIRECTIVE); |
| 1035 |
break; |
| 1036 |
|
| 1037 |
case 'n': |
| 1038 |
matcho ("nothing", gfc_match_omp_nothing, ST_NONE); |
| 1039 |
break; |
| 1040 |
case 's': |
| 1041 |
matchs ("scan", gfc_match_omp_scan, ST_OMP_SCAN); |
| 1042 |
matchs ("simd", gfc_match_omp_simd, ST_OMP_SIMD); |
| 1043 |
break; |
| 1044 |
case 't': |
| 1045 |
matchs ("tile", gfc_match_omp_tile, ST_OMP_TILE); |
| 1046 |
break; |
| 1047 |
case 'u': |
| 1048 |
matchs ("unroll", gfc_match_omp_unroll, ST_OMP_UNROLL); |
| 1049 |
break; |
| 1050 |
} |
| 1051 |
|
| 1052 |
pure_ok = false; |
| 1053 |
if (flag_openmp && gfc_pure (NULL)) |
| 1054 |
{ |
| 1055 |
gfc_error_now ("OpenMP directive at %C is not pure and thus may not " |
| 1056 |
"appear in a PURE procedure"); |
| 1057 |
gfc_error_recovery (); |
| 1058 |
return ST_NONE; |
| 1059 |
} |
| 1060 |
|
| 1061 |
/* match is for directives that should be recognized only if |
| 1062 |
-fopenmp, matchs for directives that should be recognized |
| 1063 |
if either -fopenmp or -fopenmp-simd. */ |
| 1064 |
switch (c) |
| 1065 |
{ |
| 1066 |
case 'a': |
| 1067 |
if (in_exec_part) |
| 1068 |
matcho ("allocate", gfc_match_omp_allocate, ST_OMP_ALLOCATE_EXEC); |
| 1069 |
else |
| 1070 |
matcho ("allocate", gfc_match_omp_allocate, ST_OMP_ALLOCATE); |
| 1071 |
matcho ("allocators", gfc_match_omp_allocators, ST_OMP_ALLOCATORS); |
| 1072 |
matcho ("atomic", gfc_match_omp_atomic, ST_OMP_ATOMIC); |
| 1073 |
break; |
| 1074 |
case 'b': |
| 1075 |
matcho ("barrier", gfc_match_omp_barrier, ST_OMP_BARRIER); |
| 1076 |
break; |
| 1077 |
case 'c': |
| 1078 |
matcho ("cancellation% point", gfc_match_omp_cancellation_point, |
| 1079 |
ST_OMP_CANCELLATION_POINT); |
| 1080 |
matcho ("cancel", gfc_match_omp_cancel, ST_OMP_CANCEL); |
| 1081 |
matcho ("critical", gfc_match_omp_critical, ST_OMP_CRITICAL); |
| 1082 |
break; |
| 1083 |
case 'd': |
| 1084 |
matcho ("depobj", gfc_match_omp_depobj, ST_OMP_DEPOBJ); |
| 1085 |
matcho ("dispatch", gfc_match_omp_dispatch, ST_OMP_DISPATCH); |
| 1086 |
matchs ("distribute parallel do simd", |
| 1087 |
gfc_match_omp_distribute_parallel_do_simd, |
| 1088 |
ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD); |
| 1089 |
matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do, |
| 1090 |
ST_OMP_DISTRIBUTE_PARALLEL_DO); |
| 1091 |
matchs ("distribute simd", gfc_match_omp_distribute_simd, |
| 1092 |
ST_OMP_DISTRIBUTE_SIMD); |
| 1093 |
matcho ("distribute", gfc_match_omp_distribute, ST_OMP_DISTRIBUTE); |
| 1094 |
matchs ("do simd", gfc_match_omp_do_simd, ST_OMP_DO_SIMD); |
| 1095 |
matcho ("do", gfc_match_omp_do, ST_OMP_DO); |
| 1096 |
break; |
| 1097 |
case 'e': |
| 1098 |
matcho ("end allocators", gfc_match_omp_eos_error, ST_OMP_END_ALLOCATORS); |
| 1099 |
matcho ("end atomic", gfc_match_omp_eos_error, ST_OMP_END_ATOMIC); |
| 1100 |
matcho ("end critical", gfc_match_omp_end_critical, ST_OMP_END_CRITICAL); |
| 1101 |
matcho ("end dispatch", gfc_match_omp_end_nowait, ST_OMP_END_DISPATCH); |
| 1102 |
matchs ("end distribute parallel do simd", gfc_match_omp_eos_error, |
| 1103 |
ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD); |
| 1104 |
matcho ("end distribute parallel do", gfc_match_omp_eos_error, |
| 1105 |
ST_OMP_END_DISTRIBUTE_PARALLEL_DO); |
| 1106 |
matchs ("end distribute simd", gfc_match_omp_eos_error, |
| 1107 |
ST_OMP_END_DISTRIBUTE_SIMD); |
| 1108 |
matcho ("end distribute", gfc_match_omp_eos_error, ST_OMP_END_DISTRIBUTE); |
| 1109 |
matchs ("end do simd", gfc_match_omp_end_nowait, ST_OMP_END_DO_SIMD); |
| 1110 |
matcho ("end do", gfc_match_omp_end_nowait, ST_OMP_END_DO); |
| 1111 |
matchs ("end loop", gfc_match_omp_eos_error, ST_OMP_END_LOOP); |
| 1112 |
matcho ("end masked taskloop simd", gfc_match_omp_eos_error, |
| 1113 |
ST_OMP_END_MASKED_TASKLOOP_SIMD); |
| 1114 |
matcho ("end masked taskloop", gfc_match_omp_eos_error, |
| 1115 |
ST_OMP_END_MASKED_TASKLOOP); |
| 1116 |
matcho ("end masked", gfc_match_omp_eos_error, ST_OMP_END_MASKED); |
| 1117 |
matcho ("end master taskloop simd", gfc_match_omp_eos_error, |
| 1118 |
ST_OMP_END_MASTER_TASKLOOP_SIMD); |
| 1119 |
matcho ("end master taskloop", gfc_match_omp_eos_error, |
| 1120 |
ST_OMP_END_MASTER_TASKLOOP); |
| 1121 |
matcho ("end master", gfc_match_omp_eos_error, ST_OMP_END_MASTER); |
| 1122 |
matchs ("end ordered", gfc_match_omp_eos_error, ST_OMP_END_ORDERED); |
| 1123 |
matchs ("end parallel do simd", gfc_match_omp_eos_error, |
| 1124 |
ST_OMP_END_PARALLEL_DO_SIMD); |
| 1125 |
matcho ("end parallel do", gfc_match_omp_eos_error, |
| 1126 |
ST_OMP_END_PARALLEL_DO); |
| 1127 |
matcho ("end parallel loop", gfc_match_omp_eos_error, |
| 1128 |
ST_OMP_END_PARALLEL_LOOP); |
| 1129 |
matcho ("end parallel masked taskloop simd", gfc_match_omp_eos_error, |
| 1130 |
ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD); |
| 1131 |
matcho ("end parallel masked taskloop", gfc_match_omp_eos_error, |
| 1132 |
ST_OMP_END_PARALLEL_MASKED_TASKLOOP); |
| 1133 |
matcho ("end parallel masked", gfc_match_omp_eos_error, |
| 1134 |
ST_OMP_END_PARALLEL_MASKED); |
| 1135 |
matcho ("end parallel master taskloop simd", gfc_match_omp_eos_error, |
| 1136 |
ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD); |
| 1137 |
matcho ("end parallel master taskloop", gfc_match_omp_eos_error, |
| 1138 |
ST_OMP_END_PARALLEL_MASTER_TASKLOOP); |
| 1139 |
matcho ("end parallel master", gfc_match_omp_eos_error, |
| 1140 |
ST_OMP_END_PARALLEL_MASTER); |
| 1141 |
matcho ("end parallel sections", gfc_match_omp_eos_error, |
| 1142 |
ST_OMP_END_PARALLEL_SECTIONS); |
| 1143 |
matcho ("end parallel workshare", gfc_match_omp_eos_error, |
| 1144 |
ST_OMP_END_PARALLEL_WORKSHARE); |
| 1145 |
matcho ("end parallel", gfc_match_omp_eos_error, ST_OMP_END_PARALLEL); |
| 1146 |
matcho ("end scope", gfc_match_omp_end_nowait, ST_OMP_END_SCOPE); |
| 1147 |
matcho ("end sections", gfc_match_omp_end_nowait, ST_OMP_END_SECTIONS); |
| 1148 |
matcho ("end single", gfc_match_omp_end_single, ST_OMP_END_SINGLE); |
| 1149 |
matcho ("end target data", gfc_match_omp_eos_error, ST_OMP_END_TARGET_DATA); |
| 1150 |
matchs ("end target parallel do simd", gfc_match_omp_end_nowait, |
| 1151 |
ST_OMP_END_TARGET_PARALLEL_DO_SIMD); |
| 1152 |
matcho ("end target parallel do", gfc_match_omp_end_nowait, |
| 1153 |
ST_OMP_END_TARGET_PARALLEL_DO); |
| 1154 |
matcho ("end target parallel loop", gfc_match_omp_end_nowait, |
| 1155 |
ST_OMP_END_TARGET_PARALLEL_LOOP); |
| 1156 |
matcho ("end target parallel", gfc_match_omp_end_nowait, |
| 1157 |
ST_OMP_END_TARGET_PARALLEL); |
| 1158 |
matchs ("end target simd", gfc_match_omp_end_nowait, ST_OMP_END_TARGET_SIMD); |
| 1159 |
matchs ("end target teams distribute parallel do simd", |
| 1160 |
gfc_match_omp_end_nowait, |
| 1161 |
ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD); |
| 1162 |
matcho ("end target teams distribute parallel do", gfc_match_omp_end_nowait, |
| 1163 |
ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO); |
| 1164 |
matchs ("end target teams distribute simd", gfc_match_omp_end_nowait, |
| 1165 |
ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD); |
| 1166 |
matcho ("end target teams distribute", gfc_match_omp_end_nowait, |
| 1167 |
ST_OMP_END_TARGET_TEAMS_DISTRIBUTE); |
| 1168 |
matcho ("end target teams loop", gfc_match_omp_end_nowait, |
| 1169 |
ST_OMP_END_TARGET_TEAMS_LOOP); |
| 1170 |
matcho ("end target teams", gfc_match_omp_end_nowait, |
| 1171 |
ST_OMP_END_TARGET_TEAMS); |
| 1172 |
matcho ("end target", gfc_match_omp_end_nowait, ST_OMP_END_TARGET); |
| 1173 |
matcho ("end taskgroup", gfc_match_omp_eos_error, ST_OMP_END_TASKGROUP); |
| 1174 |
matchs ("end taskloop simd", gfc_match_omp_eos_error, |
| 1175 |
ST_OMP_END_TASKLOOP_SIMD); |
| 1176 |
matcho ("end taskloop", gfc_match_omp_eos_error, ST_OMP_END_TASKLOOP); |
| 1177 |
matcho ("end task", gfc_match_omp_eos_error, ST_OMP_END_TASK); |
| 1178 |
matchs ("end teams distribute parallel do simd", gfc_match_omp_eos_error, |
| 1179 |
ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD); |
| 1180 |
matcho ("end teams distribute parallel do", gfc_match_omp_eos_error, |
| 1181 |
ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO); |
| 1182 |
matchs ("end teams distribute simd", gfc_match_omp_eos_error, |
| 1183 |
ST_OMP_END_TEAMS_DISTRIBUTE_SIMD); |
| 1184 |
matcho ("end teams distribute", gfc_match_omp_eos_error, |
| 1185 |
ST_OMP_END_TEAMS_DISTRIBUTE); |
| 1186 |
matcho ("end teams loop", gfc_match_omp_eos_error, ST_OMP_END_TEAMS_LOOP); |
| 1187 |
matcho ("end teams", gfc_match_omp_eos_error, ST_OMP_END_TEAMS); |
| 1188 |
matcho ("end workshare", gfc_match_omp_end_nowait, |
| 1189 |
ST_OMP_END_WORKSHARE); |
| 1190 |
break; |
| 1191 |
case 'f': |
| 1192 |
matcho ("flush", gfc_match_omp_flush, ST_OMP_FLUSH); |
| 1193 |
break; |
| 1194 |
case 'i': |
| 1195 |
matcho ("interop", gfc_match_omp_interop, ST_OMP_INTEROP); |
| 1196 |
break; |
| 1197 |
case 'm': |
| 1198 |
matcho ("masked taskloop simd", gfc_match_omp_masked_taskloop_simd, |
| 1199 |
ST_OMP_MASKED_TASKLOOP_SIMD); |
| 1200 |
matcho ("masked taskloop", gfc_match_omp_masked_taskloop, |
| 1201 |
ST_OMP_MASKED_TASKLOOP); |
| 1202 |
matcho ("masked", gfc_match_omp_masked, ST_OMP_MASKED); |
| 1203 |
matcho ("master taskloop simd", gfc_match_omp_master_taskloop_simd, |
| 1204 |
ST_OMP_MASTER_TASKLOOP_SIMD); |
| 1205 |
matcho ("master taskloop", gfc_match_omp_master_taskloop, |
| 1206 |
ST_OMP_MASTER_TASKLOOP); |
| 1207 |
matcho ("master", gfc_match_omp_master, ST_OMP_MASTER); |
| 1208 |
break; |
| 1209 |
case 'n': |
| 1210 |
matcho ("nothing", gfc_match_omp_nothing, ST_NONE); |
| 1211 |
break; |
| 1212 |
case 'l': |
| 1213 |
matchs ("loop", gfc_match_omp_loop, ST_OMP_LOOP); |
| 1214 |
break; |
| 1215 |
case 'o': |
| 1216 |
if (gfc_match ("ordered depend (") == MATCH_YES |
| 1217 |
|| gfc_match ("ordered doacross (") == MATCH_YES) |
| 1218 |
{ |
| 1219 |
gfc_current_locus = old_locus; |
| 1220 |
if (!flag_openmp) |
| 1221 |
break; |
| 1222 |
matcho ("ordered", gfc_match_omp_ordered_depend, |
| 1223 |
ST_OMP_ORDERED_DEPEND); |
| 1224 |
} |
| 1225 |
else |
| 1226 |
matchs ("ordered", gfc_match_omp_ordered, ST_OMP_ORDERED); |
| 1227 |
break; |
| 1228 |
case 'p': |
| 1229 |
matchs ("parallel do simd", gfc_match_omp_parallel_do_simd, |
| 1230 |
ST_OMP_PARALLEL_DO_SIMD); |
| 1231 |
matcho ("parallel do", gfc_match_omp_parallel_do, ST_OMP_PARALLEL_DO); |
| 1232 |
matcho ("parallel loop", gfc_match_omp_parallel_loop, |
| 1233 |
ST_OMP_PARALLEL_LOOP); |
| 1234 |
matcho ("parallel masked taskloop simd", |
| 1235 |
gfc_match_omp_parallel_masked_taskloop_simd, |
| 1236 |
ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD); |
| 1237 |
matcho ("parallel masked taskloop", |
| 1238 |
gfc_match_omp_parallel_masked_taskloop, |
| 1239 |
ST_OMP_PARALLEL_MASKED_TASKLOOP); |
| 1240 |
matcho ("parallel masked", gfc_match_omp_parallel_masked, |
| 1241 |
ST_OMP_PARALLEL_MASKED); |
| 1242 |
matcho ("parallel master taskloop simd", |
| 1243 |
gfc_match_omp_parallel_master_taskloop_simd, |
| 1244 |
ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD); |
| 1245 |
matcho ("parallel master taskloop", |
| 1246 |
gfc_match_omp_parallel_master_taskloop, |
| 1247 |
ST_OMP_PARALLEL_MASTER_TASKLOOP); |
| 1248 |
matcho ("parallel master", gfc_match_omp_parallel_master, |
| 1249 |
ST_OMP_PARALLEL_MASTER); |
| 1250 |
matcho ("parallel sections", gfc_match_omp_parallel_sections, |
| 1251 |
ST_OMP_PARALLEL_SECTIONS); |
| 1252 |
matcho ("parallel workshare", gfc_match_omp_parallel_workshare, |
| 1253 |
ST_OMP_PARALLEL_WORKSHARE); |
| 1254 |
matcho ("parallel", gfc_match_omp_parallel, ST_OMP_PARALLEL); |
| 1255 |
break; |
| 1256 |
case 'r': |
| 1257 |
matcho ("requires", gfc_match_omp_requires, ST_OMP_REQUIRES); |
| 1258 |
break; |
| 1259 |
case 's': |
| 1260 |
matcho ("scope", gfc_match_omp_scope, ST_OMP_SCOPE); |
| 1261 |
matcho ("sections", gfc_match_omp_sections, ST_OMP_SECTIONS); |
| 1262 |
matcho ("section", gfc_match_omp_eos_error, ST_OMP_SECTION); |
| 1263 |
matcho ("single", gfc_match_omp_single, ST_OMP_SINGLE); |
| 1264 |
break; |
| 1265 |
case 't': |
| 1266 |
matcho ("target data", gfc_match_omp_target_data, ST_OMP_TARGET_DATA); |
| 1267 |
matcho ("target enter data", gfc_match_omp_target_enter_data, |
| 1268 |
ST_OMP_TARGET_ENTER_DATA); |
| 1269 |
matcho ("target exit data", gfc_match_omp_target_exit_data, |
| 1270 |
ST_OMP_TARGET_EXIT_DATA); |
| 1271 |
matchs ("target parallel do simd", gfc_match_omp_target_parallel_do_simd, |
| 1272 |
ST_OMP_TARGET_PARALLEL_DO_SIMD); |
| 1273 |
matcho ("target parallel do", gfc_match_omp_target_parallel_do, |
| 1274 |
ST_OMP_TARGET_PARALLEL_DO); |
| 1275 |
matcho ("target parallel loop", gfc_match_omp_target_parallel_loop, |
| 1276 |
ST_OMP_TARGET_PARALLEL_LOOP); |
| 1277 |
matcho ("target parallel", gfc_match_omp_target_parallel, |
| 1278 |
ST_OMP_TARGET_PARALLEL); |
| 1279 |
matchs ("target simd", gfc_match_omp_target_simd, ST_OMP_TARGET_SIMD); |
| 1280 |
matchs ("target teams distribute parallel do simd", |
| 1281 |
gfc_match_omp_target_teams_distribute_parallel_do_simd, |
| 1282 |
ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD); |
| 1283 |
matcho ("target teams distribute parallel do", |
| 1284 |
gfc_match_omp_target_teams_distribute_parallel_do, |
| 1285 |
ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO); |
| 1286 |
matchs ("target teams distribute simd", |
| 1287 |
gfc_match_omp_target_teams_distribute_simd, |
| 1288 |
ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD); |
| 1289 |
matcho ("target teams distribute", gfc_match_omp_target_teams_distribute, |
| 1290 |
ST_OMP_TARGET_TEAMS_DISTRIBUTE); |
| 1291 |
matcho ("target teams loop", gfc_match_omp_target_teams_loop, |
| 1292 |
ST_OMP_TARGET_TEAMS_LOOP); |
| 1293 |
matcho ("target teams", gfc_match_omp_target_teams, ST_OMP_TARGET_TEAMS); |
| 1294 |
matcho ("target update", gfc_match_omp_target_update, |
| 1295 |
ST_OMP_TARGET_UPDATE); |
| 1296 |
matcho ("target", gfc_match_omp_target, ST_OMP_TARGET); |
| 1297 |
matcho ("taskgroup", gfc_match_omp_taskgroup, ST_OMP_TASKGROUP); |
| 1298 |
matchs ("taskloop simd", gfc_match_omp_taskloop_simd, |
| 1299 |
ST_OMP_TASKLOOP_SIMD); |
| 1300 |
matcho ("taskloop", gfc_match_omp_taskloop, ST_OMP_TASKLOOP); |
| 1301 |
matcho ("taskwait", gfc_match_omp_taskwait, ST_OMP_TASKWAIT); |
| 1302 |
matcho ("taskyield", gfc_match_omp_taskyield, ST_OMP_TASKYIELD); |
| 1303 |
matcho ("task", gfc_match_omp_task, ST_OMP_TASK); |
| 1304 |
matchs ("teams distribute parallel do simd", |
| 1305 |
gfc_match_omp_teams_distribute_parallel_do_simd, |
| 1306 |
ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD); |
| 1307 |
matcho ("teams distribute parallel do", |
| 1308 |
gfc_match_omp_teams_distribute_parallel_do, |
| 1309 |
ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO); |
| 1310 |
matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd, |
| 1311 |
ST_OMP_TEAMS_DISTRIBUTE_SIMD); |
| 1312 |
matcho ("teams distribute", gfc_match_omp_teams_distribute, |
| 1313 |
ST_OMP_TEAMS_DISTRIBUTE); |
| 1314 |
matcho ("teams loop", gfc_match_omp_teams_loop, ST_OMP_TEAMS_LOOP); |
| 1315 |
matcho ("teams", gfc_match_omp_teams, ST_OMP_TEAMS); |
| 1316 |
matchdo ("threadprivate", gfc_match_omp_threadprivate, |
| 1317 |
ST_OMP_THREADPRIVATE); |
| 1318 |
break; |
| 1319 |
case 'w': |
| 1320 |
matcho ("workshare", gfc_match_omp_workshare, ST_OMP_WORKSHARE); |
| 1321 |
break; |
| 1322 |
} |
| 1323 |
|
| 1324 |
/* All else has failed, so give up. See if any of the matchers has |
| 1325 |
stored an error message of some sort. Don't error out if |
| 1326 |
not -fopenmp and simd_matched is false, i.e. if a directive other |
| 1327 |
than one marked with match has been seen. */ |
| 1328 |
|
| 1329 |
error_handling: |
| 1330 |
if (flag_openmp || simd_matched) |
| 1331 |
{ |
| 1332 |
if (!gfc_error_check ()) |
| 1333 |
gfc_error_now ("Unclassifiable OpenMP directive at %C"); |
| 1334 |
} |
| 1335 |
|
| 1336 |
/* If parsing a metadirective, let the caller deal with the cleanup. */ |
| 1337 |
if (gfc_matching_omp_context_selector) |
| 1338 |
return ST_NONE; |
| 1339 |
|
| 1340 |
reject_statement (); |
| 1341 |
|
| 1342 |
gfc_error_recovery (); |
| 1343 |
|
| 1344 |
return ST_NONE; |
| 1345 |
|
| 1346 |
finish: |
| 1347 |
if (ret == ST_OMP_ERROR && new_st.ext.omp_clauses->at == OMP_AT_EXECUTION) |
| 1348 |
{ |
| 1349 |
gfc_unset_implicit_pure (NULL); |
| 1350 |
|
| 1351 |
if (gfc_pure (NULL)) |
| 1352 |
{ |
| 1353 |
gfc_error_now ("OpenMP ERROR directive at %L with %<at(execution)%> " |
| 1354 |
"clause in a PURE procedure", &old_locus); |
| 1355 |
reject_statement (); |
| 1356 |
gfc_error_recovery (); |
| 1357 |
return ST_NONE; |
| 1358 |
} |
| 1359 |
} |
| 1360 |
if (!pure_ok) |
| 1361 |
{ |
| 1362 |
gfc_unset_implicit_pure (NULL); |
| 1363 |
|
| 1364 |
if (!flag_openmp && gfc_pure (NULL)) |
| 1365 |
{ |
| 1366 |
gfc_error_now ("OpenMP directive at %C is not pure and thus may not " |
| 1367 |
"appear in a PURE procedure"); |
| 1368 |
reject_statement (); |
| 1369 |
gfc_error_recovery (); |
| 1370 |
return ST_NONE; |
| 1371 |
} |
| 1372 |
} |
| 1373 |
if (ret == ST_OMP_ALLOCATE && !check_omp_allocate_stmt (&old_locus)) |
| 1374 |
goto error_handling; |
| 1375 |
|
| 1376 |
switch (ret) |
| 1377 |
{ |
| 1378 |
/* For the constraints on clauses with the global requirement property, |
| 1379 |
we set omp_target_seen. This included all clauses that take the |
| 1380 |
DEVICE clause, (BEGIN) DECLARE_TARGET and procedures run the device |
| 1381 |
(which effectively is implied by the former). */ |
| 1382 |
case ST_OMP_DECLARE_TARGET: |
| 1383 |
case ST_OMP_INTEROP: |
| 1384 |
case ST_OMP_TARGET: |
| 1385 |
case ST_OMP_TARGET_DATA: |
| 1386 |
case ST_OMP_TARGET_ENTER_DATA: |
| 1387 |
case ST_OMP_TARGET_EXIT_DATA: |
| 1388 |
case ST_OMP_TARGET_TEAMS: |
| 1389 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE: |
| 1390 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: |
| 1391 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 1392 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 1393 |
case ST_OMP_TARGET_TEAMS_LOOP: |
| 1394 |
case ST_OMP_TARGET_PARALLEL: |
| 1395 |
case ST_OMP_TARGET_PARALLEL_DO: |
| 1396 |
case ST_OMP_TARGET_PARALLEL_DO_SIMD: |
| 1397 |
case ST_OMP_TARGET_PARALLEL_LOOP: |
| 1398 |
case ST_OMP_TARGET_SIMD: |
| 1399 |
case ST_OMP_TARGET_UPDATE: |
| 1400 |
{ |
| 1401 |
gfc_namespace *prog_unit = gfc_current_ns; |
| 1402 |
while (prog_unit->parent) |
| 1403 |
{ |
| 1404 |
if (gfc_state_stack->previous |
| 1405 |
&& gfc_state_stack->previous->state == COMP_INTERFACE) |
| 1406 |
break; |
| 1407 |
prog_unit = prog_unit->parent; |
| 1408 |
} |
| 1409 |
prog_unit->omp_target_seen = true; |
| 1410 |
break; |
| 1411 |
} |
| 1412 |
case ST_OMP_ALLOCATE_EXEC: |
| 1413 |
case ST_OMP_ALLOCATORS: |
| 1414 |
case ST_OMP_TEAMS: |
| 1415 |
case ST_OMP_TEAMS_DISTRIBUTE: |
| 1416 |
case ST_OMP_TEAMS_DISTRIBUTE_SIMD: |
| 1417 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 1418 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 1419 |
case ST_OMP_TEAMS_LOOP: |
| 1420 |
for (gfc_state_data *stk = gfc_state_stack->previous; stk; |
| 1421 |
stk = stk->previous) |
| 1422 |
if (stk && stk->tail) |
| 1423 |
switch (stk->tail->op) |
| 1424 |
{ |
| 1425 |
case EXEC_OMP_TARGET: |
| 1426 |
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE: |
| 1427 |
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: |
| 1428 |
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 1429 |
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 1430 |
case EXEC_OMP_TARGET_TEAMS_LOOP: |
| 1431 |
case EXEC_OMP_TARGET_PARALLEL: |
| 1432 |
case EXEC_OMP_TARGET_PARALLEL_DO: |
| 1433 |
case EXEC_OMP_TARGET_PARALLEL_DO_SIMD: |
| 1434 |
case EXEC_OMP_TARGET_PARALLEL_LOOP: |
| 1435 |
case EXEC_OMP_TARGET_SIMD: |
| 1436 |
if (ret == ST_OMP_ALLOCATE_EXEC || ret == ST_OMP_ALLOCATORS) |
| 1437 |
new_st.ext.omp_clauses->contained_in_target_construct = 1; |
| 1438 |
else |
| 1439 |
stk->tail->ext.omp_clauses->contains_teams_construct = 1; |
| 1440 |
break; |
| 1441 |
default: |
| 1442 |
break; |
| 1443 |
} |
| 1444 |
break; |
| 1445 |
case ST_OMP_ERROR: |
| 1446 |
if (new_st.ext.omp_clauses->at != OMP_AT_EXECUTION) |
| 1447 |
return ST_NONE; |
| 1448 |
default: |
| 1449 |
break; |
| 1450 |
} |
| 1451 |
return ret; |
| 1452 |
|
| 1453 |
do_spec_only: |
| 1454 |
reject_statement (); |
| 1455 |
gfc_clear_error (); |
| 1456 |
gfc_buffer_error (false); |
| 1457 |
gfc_current_locus = old_locus; |
| 1458 |
return ST_GET_FCN_CHARACTERISTICS; |
| 1459 |
} |
| 1460 |
|
| 1461 |
gfc_statement |
| 1462 |
match_omp_directive (void) |
| 1463 |
{ |
| 1464 |
return decode_omp_directive (); |
| 1465 |
} |
| 1466 |
|
| 1467 |
static gfc_statement |
| 1468 |
decode_gcc_attribute (void) |
| 1469 |
{ |
| 1470 |
locus old_locus; |
| 1471 |
|
| 1472 |
gfc_enforce_clean_symbol_state (); |
| 1473 |
|
| 1474 |
gfc_clear_error (); /* Clear any pending errors. */ |
| 1475 |
gfc_clear_warning (); /* Clear any pending warnings. */ |
| 1476 |
old_locus = gfc_current_locus; |
| 1477 |
|
| 1478 |
match ("attributes", gfc_match_gcc_attributes, ST_ATTR_DECL); |
| 1479 |
match ("unroll", gfc_match_gcc_unroll, ST_NONE); |
| 1480 |
match ("builtin", gfc_match_gcc_builtin, ST_NONE); |
| 1481 |
match ("ivdep", gfc_match_gcc_ivdep, ST_NONE); |
| 1482 |
match ("vector", gfc_match_gcc_vector, ST_NONE); |
| 1483 |
match ("novector", gfc_match_gcc_novector, ST_NONE); |
| 1484 |
|
| 1485 |
/* All else has failed, so give up. See if any of the matchers has |
| 1486 |
stored an error message of some sort. */ |
| 1487 |
|
| 1488 |
if (!gfc_error_check ()) |
| 1489 |
{ |
| 1490 |
if (pedantic) |
| 1491 |
gfc_error_now ("Unclassifiable GCC directive at %C"); |
| 1492 |
else |
| 1493 |
gfc_warning_now (0, "Unclassifiable GCC directive at %C, ignored"); |
| 1494 |
} |
| 1495 |
|
| 1496 |
reject_statement (); |
| 1497 |
|
| 1498 |
gfc_error_recovery (); |
| 1499 |
|
| 1500 |
return ST_NONE; |
| 1501 |
} |
| 1502 |
|
| 1503 |
#undef match |
| 1504 |
|
| 1505 |
/* Assert next length characters to be equal to token in free form. */ |
| 1506 |
|
| 1507 |
static void |
| 1508 |
verify_token_free (const char* token, int length, bool last_was_use_stmt) |
| 1509 |
{ |
| 1510 |
int i; |
| 1511 |
char c; |
| 1512 |
|
| 1513 |
c = gfc_next_ascii_char (); |
| 1514 |
for (i = 0; i < length; i++, c = gfc_next_ascii_char ()) |
| 1515 |
gcc_assert (c == token[i]); |
| 1516 |
|
| 1517 |
gcc_assert (gfc_is_whitespace(c)); |
| 1518 |
gfc_gobble_whitespace (); |
| 1519 |
if (last_was_use_stmt) |
| 1520 |
use_modules (); |
| 1521 |
} |
| 1522 |
|
| 1523 |
/* Get the next statement in free form source. */ |
| 1524 |
|
| 1525 |
static gfc_statement |
| 1526 |
next_free (void) |
| 1527 |
{ |
| 1528 |
match m; |
| 1529 |
int i, cnt, at_bol; |
| 1530 |
char c; |
| 1531 |
|
| 1532 |
at_bol = gfc_at_bol (); |
| 1533 |
gfc_gobble_whitespace (); |
| 1534 |
|
| 1535 |
c = gfc_peek_ascii_char (); |
| 1536 |
|
| 1537 |
if (ISDIGIT (c)) |
| 1538 |
{ |
| 1539 |
char d; |
| 1540 |
|
| 1541 |
/* Found a statement label? */ |
| 1542 |
m = gfc_match_st_label (&gfc_statement_label); |
| 1543 |
|
| 1544 |
d = gfc_peek_ascii_char (); |
| 1545 |
if (m != MATCH_YES || !gfc_is_whitespace (d)) |
| 1546 |
{ |
| 1547 |
gfc_match_small_literal_int (&i, &cnt); |
| 1548 |
|
| 1549 |
if (cnt > 5) |
| 1550 |
gfc_error_now ("Too many digits in statement label at %C"); |
| 1551 |
|
| 1552 |
if (i == 0) |
| 1553 |
gfc_error_now ("Zero is not a valid statement label at %C"); |
| 1554 |
|
| 1555 |
do |
| 1556 |
c = gfc_next_ascii_char (); |
| 1557 |
while (ISDIGIT(c)); |
| 1558 |
|
| 1559 |
if (!gfc_is_whitespace (c)) |
| 1560 |
gfc_error_now ("Non-numeric character in statement label at %C"); |
| 1561 |
|
| 1562 |
return ST_NONE; |
| 1563 |
} |
| 1564 |
else |
| 1565 |
{ |
| 1566 |
label_locus = gfc_current_locus; |
| 1567 |
|
| 1568 |
gfc_gobble_whitespace (); |
| 1569 |
|
| 1570 |
if (at_bol && gfc_peek_ascii_char () == ';') |
| 1571 |
{ |
| 1572 |
gfc_error_now ("Semicolon at %C needs to be preceded by " |
| 1573 |
"statement"); |
| 1574 |
gfc_next_ascii_char (); /* Eat up the semicolon. */ |
| 1575 |
return ST_NONE; |
| 1576 |
} |
| 1577 |
|
| 1578 |
if (gfc_match_eos () == MATCH_YES) |
| 1579 |
gfc_error_now ("Statement label without statement at %L", |
| 1580 |
&label_locus); |
| 1581 |
} |
| 1582 |
} |
| 1583 |
else if (c == '!') |
| 1584 |
{ |
| 1585 |
/* Comments have already been skipped by the time we get here, |
| 1586 |
except for GCC attributes and OpenMP/OpenACC directives. */ |
| 1587 |
|
| 1588 |
gfc_next_ascii_char (); /* Eat up the exclamation sign. */ |
| 1589 |
c = gfc_peek_ascii_char (); |
| 1590 |
|
| 1591 |
if (c == 'g') |
| 1592 |
{ |
| 1593 |
int i; |
| 1594 |
|
| 1595 |
c = gfc_next_ascii_char (); |
| 1596 |
for (i = 0; i < 4; i++, c = gfc_next_ascii_char ()) |
| 1597 |
gcc_assert (c == "gcc$"[i]); |
| 1598 |
|
| 1599 |
gfc_gobble_whitespace (); |
| 1600 |
return decode_gcc_attribute (); |
| 1601 |
|
| 1602 |
} |
| 1603 |
else if (c == '$') |
| 1604 |
{ |
| 1605 |
/* Since both OpenMP and OpenACC directives starts with |
| 1606 |
!$ character sequence, we must check all flags combinations */ |
| 1607 |
if ((flag_openmp || flag_openmp_simd) |
| 1608 |
&& !flag_openacc) |
| 1609 |
{ |
| 1610 |
verify_token_free ("$omp", 4, last_was_use_stmt); |
| 1611 |
return decode_omp_directive (); |
| 1612 |
} |
| 1613 |
else if ((flag_openmp || flag_openmp_simd) |
| 1614 |
&& flag_openacc) |
| 1615 |
{ |
| 1616 |
gfc_next_ascii_char (); /* Eat up dollar character */ |
| 1617 |
c = gfc_peek_ascii_char (); |
| 1618 |
|
| 1619 |
if (c == 'o') |
| 1620 |
{ |
| 1621 |
verify_token_free ("omp", 3, last_was_use_stmt); |
| 1622 |
return decode_omp_directive (); |
| 1623 |
} |
| 1624 |
else if (c == 'a') |
| 1625 |
{ |
| 1626 |
verify_token_free ("acc", 3, last_was_use_stmt); |
| 1627 |
return decode_oacc_directive (); |
| 1628 |
} |
| 1629 |
} |
| 1630 |
else if (flag_openacc) |
| 1631 |
{ |
| 1632 |
verify_token_free ("$acc", 4, last_was_use_stmt); |
| 1633 |
return decode_oacc_directive (); |
| 1634 |
} |
| 1635 |
} |
| 1636 |
gcc_unreachable (); |
| 1637 |
} |
| 1638 |
|
| 1639 |
if (at_bol && c == ';') |
| 1640 |
{ |
| 1641 |
if (!(gfc_option.allow_std & GFC_STD_F2008)) |
| 1642 |
gfc_error_now ("Fortran 2008: Semicolon at %C without preceding " |
| 1643 |
"statement"); |
| 1644 |
gfc_next_ascii_char (); /* Eat up the semicolon. */ |
| 1645 |
return ST_NONE; |
| 1646 |
} |
| 1647 |
|
| 1648 |
return decode_statement (); |
| 1649 |
} |
| 1650 |
|
| 1651 |
/* Assert next length characters to be equal to token in fixed form. */ |
| 1652 |
|
| 1653 |
static bool |
| 1654 |
verify_token_fixed (const char *token, int length, bool last_was_use_stmt) |
| 1655 |
{ |
| 1656 |
int i; |
| 1657 |
char c = gfc_next_char_literal (NONSTRING); |
| 1658 |
|
| 1659 |
for (i = 0; i < length; i++, c = gfc_next_char_literal (NONSTRING)) |
| 1660 |
gcc_assert ((char) gfc_wide_tolower (c) == token[i]); |
| 1661 |
|
| 1662 |
if (c != ' ' && c != '0') |
| 1663 |
{ |
| 1664 |
gfc_buffer_error (false); |
| 1665 |
gfc_error ("Bad continuation line at %C"); |
| 1666 |
return false; |
| 1667 |
} |
| 1668 |
if (last_was_use_stmt) |
| 1669 |
use_modules (); |
| 1670 |
|
| 1671 |
return true; |
| 1672 |
} |
| 1673 |
|
| 1674 |
/* Get the next statement in fixed-form source. */ |
| 1675 |
|
| 1676 |
static gfc_statement |
| 1677 |
next_fixed (void) |
| 1678 |
{ |
| 1679 |
int label, digit_flag, i; |
| 1680 |
locus loc; |
| 1681 |
gfc_char_t c; |
| 1682 |
|
| 1683 |
if (!gfc_at_bol ()) |
| 1684 |
return decode_statement (); |
| 1685 |
|
| 1686 |
/* Skip past the current label field, parsing a statement label if |
| 1687 |
one is there. This is a weird number parser, since the number is |
| 1688 |
contained within five columns and can have any kind of embedded |
| 1689 |
spaces. We also check for characters that make the rest of the |
| 1690 |
line a comment. */ |
| 1691 |
|
| 1692 |
label = 0; |
| 1693 |
digit_flag = 0; |
| 1694 |
|
| 1695 |
for (i = 0; i < 5; i++) |
| 1696 |
{ |
| 1697 |
c = gfc_next_char_literal (NONSTRING); |
| 1698 |
|
| 1699 |
switch (c) |
| 1700 |
{ |
| 1701 |
case ' ': |
| 1702 |
break; |
| 1703 |
|
| 1704 |
case '0': |
| 1705 |
case '1': |
| 1706 |
case '2': |
| 1707 |
case '3': |
| 1708 |
case '4': |
| 1709 |
case '5': |
| 1710 |
case '6': |
| 1711 |
case '7': |
| 1712 |
case '8': |
| 1713 |
case '9': |
| 1714 |
label = label * 10 + ((unsigned char) c - '0'); |
| 1715 |
label_locus = gfc_current_locus; |
| 1716 |
digit_flag = 1; |
| 1717 |
break; |
| 1718 |
|
| 1719 |
/* Comments have already been skipped by the time we get |
| 1720 |
here, except for GCC attributes and OpenMP directives. */ |
| 1721 |
|
| 1722 |
case '*': |
| 1723 |
c = gfc_next_char_literal (NONSTRING); |
| 1724 |
|
| 1725 |
if (TOLOWER (c) == 'g') |
| 1726 |
{ |
| 1727 |
for (i = 0; i < 4; i++, c = gfc_next_char_literal (NONSTRING)) |
| 1728 |
gcc_assert (TOLOWER (c) == "gcc$"[i]); |
| 1729 |
|
| 1730 |
return decode_gcc_attribute (); |
| 1731 |
} |
| 1732 |
else if (c == '$') |
| 1733 |
{ |
| 1734 |
if ((flag_openmp || flag_openmp_simd) |
| 1735 |
&& !flag_openacc) |
| 1736 |
{ |
| 1737 |
if (!verify_token_fixed ("omp", 3, last_was_use_stmt)) |
| 1738 |
return ST_NONE; |
| 1739 |
return decode_omp_directive (); |
| 1740 |
} |
| 1741 |
else if ((flag_openmp || flag_openmp_simd) |
| 1742 |
&& flag_openacc) |
| 1743 |
{ |
| 1744 |
c = gfc_next_char_literal(NONSTRING); |
| 1745 |
if (c == 'o' || c == 'O') |
| 1746 |
{ |
| 1747 |
if (!verify_token_fixed ("mp", 2, last_was_use_stmt)) |
| 1748 |
return ST_NONE; |
| 1749 |
return decode_omp_directive (); |
| 1750 |
} |
| 1751 |
else if (c == 'a' || c == 'A') |
| 1752 |
{ |
| 1753 |
if (!verify_token_fixed ("cc", 2, last_was_use_stmt)) |
| 1754 |
return ST_NONE; |
| 1755 |
return decode_oacc_directive (); |
| 1756 |
} |
| 1757 |
} |
| 1758 |
else if (flag_openacc) |
| 1759 |
{ |
| 1760 |
if (!verify_token_fixed ("acc", 3, last_was_use_stmt)) |
| 1761 |
return ST_NONE; |
| 1762 |
return decode_oacc_directive (); |
| 1763 |
} |
| 1764 |
} |
| 1765 |
gcc_fallthrough (); |
| 1766 |
|
| 1767 |
/* Comments have already been skipped by the time we get |
| 1768 |
here so don't bother checking for them. */ |
| 1769 |
|
| 1770 |
default: |
| 1771 |
gfc_buffer_error (false); |
| 1772 |
gfc_error ("Non-numeric character in statement label at %C"); |
| 1773 |
return ST_NONE; |
| 1774 |
} |
| 1775 |
} |
| 1776 |
|
| 1777 |
if (digit_flag) |
| 1778 |
{ |
| 1779 |
if (label == 0) |
| 1780 |
gfc_warning_now (0, "Zero is not a valid statement label at %C"); |
| 1781 |
else |
| 1782 |
{ |
| 1783 |
/* We've found a valid statement label. */ |
| 1784 |
gfc_statement_label = gfc_get_st_label (label); |
| 1785 |
} |
| 1786 |
} |
| 1787 |
|
| 1788 |
/* Since this line starts a statement, it cannot be a continuation |
| 1789 |
of a previous statement. If we see something here besides a |
| 1790 |
space or zero, it must be a bad continuation line. */ |
| 1791 |
|
| 1792 |
c = gfc_next_char_literal (NONSTRING); |
| 1793 |
if (c == '\n') |
| 1794 |
goto blank_line; |
| 1795 |
|
| 1796 |
if (c != ' ' && c != '0') |
| 1797 |
{ |
| 1798 |
gfc_buffer_error (false); |
| 1799 |
gfc_error ("Bad continuation line at %C"); |
| 1800 |
return ST_NONE; |
| 1801 |
} |
| 1802 |
|
| 1803 |
/* Now that we've taken care of the statement label columns, we have |
| 1804 |
to make sure that the first nonblank character is not a '!'. If |
| 1805 |
it is, the rest of the line is a comment. */ |
| 1806 |
|
| 1807 |
do |
| 1808 |
{ |
| 1809 |
loc = gfc_current_locus; |
| 1810 |
c = gfc_next_char_literal (NONSTRING); |
| 1811 |
} |
| 1812 |
while (gfc_is_whitespace (c)); |
| 1813 |
|
| 1814 |
if (c == '!') |
| 1815 |
goto blank_line; |
| 1816 |
gfc_current_locus = loc; |
| 1817 |
|
| 1818 |
if (c == ';') |
| 1819 |
{ |
| 1820 |
if (digit_flag) |
| 1821 |
gfc_error_now ("Semicolon at %C needs to be preceded by statement"); |
| 1822 |
else if (!(gfc_option.allow_std & GFC_STD_F2008)) |
| 1823 |
gfc_error_now ("Fortran 2008: Semicolon at %C without preceding " |
| 1824 |
"statement"); |
| 1825 |
return ST_NONE; |
| 1826 |
} |
| 1827 |
|
| 1828 |
if (gfc_match_eos () == MATCH_YES) |
| 1829 |
goto blank_line; |
| 1830 |
|
| 1831 |
/* At this point, we've got a nonblank statement to parse. */ |
| 1832 |
return decode_statement (); |
| 1833 |
|
| 1834 |
blank_line: |
| 1835 |
if (digit_flag) |
| 1836 |
gfc_error_now ("Statement label without statement at %L", &label_locus); |
| 1837 |
|
| 1838 |
gfc_current_locus.u.lb->truncated = 0; |
| 1839 |
gfc_advance_line (); |
| 1840 |
return ST_NONE; |
| 1841 |
} |
| 1842 |
|
| 1843 |
|
| 1844 |
/* Return the next non-ST_NONE statement to the caller. We also worry |
| 1845 |
about including files and the ends of include files at this stage. */ |
| 1846 |
|
| 1847 |
static gfc_statement |
| 1848 |
next_statement (void) |
| 1849 |
{ |
| 1850 |
gfc_statement st; |
| 1851 |
locus old_locus; |
| 1852 |
|
| 1853 |
gfc_enforce_clean_symbol_state (); |
| 1854 |
gfc_save_module_list (); |
| 1855 |
|
| 1856 |
gfc_new_block = NULL; |
| 1857 |
|
| 1858 |
gfc_current_ns->old_equiv = gfc_current_ns->equiv; |
| 1859 |
gfc_current_ns->old_data = gfc_current_ns->data; |
| 1860 |
for (;;) |
| 1861 |
{ |
| 1862 |
gfc_statement_label = NULL; |
| 1863 |
gfc_buffer_error (true); |
| 1864 |
|
| 1865 |
if (gfc_at_eol ()) |
| 1866 |
gfc_advance_line (); |
| 1867 |
|
| 1868 |
gfc_skip_comments (); |
| 1869 |
|
| 1870 |
if (gfc_at_end ()) |
| 1871 |
{ |
| 1872 |
st = ST_NONE; |
| 1873 |
break; |
| 1874 |
} |
| 1875 |
|
| 1876 |
if (gfc_define_undef_line ()) |
| 1877 |
continue; |
| 1878 |
|
| 1879 |
old_locus = gfc_current_locus; |
| 1880 |
|
| 1881 |
st = (gfc_current_form == FORM_FIXED) ? next_fixed () : next_free (); |
| 1882 |
|
| 1883 |
if (st != ST_NONE) |
| 1884 |
break; |
| 1885 |
} |
| 1886 |
|
| 1887 |
gfc_buffer_error (false); |
| 1888 |
|
| 1889 |
if (st == ST_GET_FCN_CHARACTERISTICS) |
| 1890 |
{ |
| 1891 |
if (gfc_statement_label != NULL) |
| 1892 |
{ |
| 1893 |
gfc_free_st_label (gfc_statement_label); |
| 1894 |
gfc_statement_label = NULL; |
| 1895 |
} |
| 1896 |
gfc_current_locus = old_locus; |
| 1897 |
} |
| 1898 |
|
| 1899 |
if (st != ST_NONE) |
| 1900 |
check_statement_label (st); |
| 1901 |
|
| 1902 |
return st; |
| 1903 |
} |
| 1904 |
|
| 1905 |
|
| 1906 |
/****************************** Parser ***********************************/ |
| 1907 |
|
| 1908 |
/* The parser subroutines are of type 'try' that fail if the file ends |
| 1909 |
unexpectedly. */ |
| 1910 |
|
| 1911 |
/* Macros that expand to case-labels for various classes of |
| 1912 |
statements. Start with executable statements that directly do |
| 1913 |
things. */ |
| 1914 |
|
| 1915 |
#define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \ |
| 1916 |
case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \ |
| 1917 |
case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \ |
| 1918 |
case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \ |
| 1919 |
case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \ |
| 1920 |
case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \ |
| 1921 |
case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \ |
| 1922 |
case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \ |
| 1923 |
case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \ |
| 1924 |
case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: case ST_OMP_DEPOBJ: \ |
| 1925 |
case ST_OMP_TARGET_UPDATE: case ST_OMP_TARGET_ENTER_DATA: \ |
| 1926 |
case ST_OMP_TARGET_EXIT_DATA: case ST_OMP_ORDERED_DEPEND: case ST_OMP_ERROR: \ |
| 1927 |
case ST_OMP_INTEROP: \ |
| 1928 |
case ST_ERROR_STOP: case ST_OMP_SCAN: case ST_SYNC_ALL: \ |
| 1929 |
case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \ |
| 1930 |
case ST_FORM_TEAM: case ST_CHANGE_TEAM: \ |
| 1931 |
case ST_END_TEAM: case ST_SYNC_TEAM: \ |
| 1932 |
case ST_EVENT_POST: case ST_EVENT_WAIT: case ST_FAIL_IMAGE: \ |
| 1933 |
case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \ |
| 1934 |
case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA |
| 1935 |
|
| 1936 |
/* Statements that mark other executable statements. */ |
| 1937 |
|
| 1938 |
#define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \ |
| 1939 |
case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \ |
| 1940 |
case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \ |
| 1941 |
case ST_SELECT_RANK: case ST_OMP_PARALLEL: case ST_OMP_PARALLEL_MASKED: \ |
| 1942 |
case ST_OMP_PARALLEL_MASKED_TASKLOOP: \ |
| 1943 |
case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: case ST_OMP_PARALLEL_MASTER: \ |
| 1944 |
case ST_OMP_PARALLEL_MASTER_TASKLOOP: \ |
| 1945 |
case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \ |
| 1946 |
case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \ |
| 1947 |
case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASKED_TASKLOOP: \ |
| 1948 |
case ST_OMP_MASKED_TASKLOOP_SIMD: \ |
| 1949 |
case ST_OMP_MASTER: case ST_OMP_MASTER_TASKLOOP: \ |
| 1950 |
case ST_OMP_MASTER_TASKLOOP_SIMD: case ST_OMP_SCOPE: case ST_OMP_SINGLE: \ |
| 1951 |
case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \ |
| 1952 |
case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \ |
| 1953 |
case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \ |
| 1954 |
case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \ |
| 1955 |
case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \ |
| 1956 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \ |
| 1957 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \ |
| 1958 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \ |
| 1959 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \ |
| 1960 |
case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \ |
| 1961 |
case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \ |
| 1962 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \ |
| 1963 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \ |
| 1964 |
case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \ |
| 1965 |
case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_TARGET_PARALLEL: \ |
| 1966 |
case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \ |
| 1967 |
case ST_OMP_TARGET_SIMD: case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \ |
| 1968 |
case ST_OMP_LOOP: case ST_OMP_PARALLEL_LOOP: case ST_OMP_TEAMS_LOOP: \ |
| 1969 |
case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_TEAMS_LOOP: \ |
| 1970 |
case ST_OMP_ALLOCATE_EXEC: case ST_OMP_ALLOCATORS: case ST_OMP_ASSUME: \ |
| 1971 |
case ST_OMP_TILE: case ST_OMP_UNROLL: case ST_OMP_DISPATCH: \ |
| 1972 |
case ST_CRITICAL: \ |
| 1973 |
case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \ |
| 1974 |
case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \ |
| 1975 |
case ST_OACC_KERNELS_LOOP: case ST_OACC_SERIAL_LOOP: case ST_OACC_SERIAL: \ |
| 1976 |
case ST_OACC_ATOMIC |
| 1977 |
|
| 1978 |
/* Declaration statements */ |
| 1979 |
|
| 1980 |
#define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \ |
| 1981 |
case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \ |
| 1982 |
case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE |
| 1983 |
|
| 1984 |
/* OpenMP and OpenACC declaration statements, which may appear anywhere in |
| 1985 |
the specification part. */ |
| 1986 |
|
| 1987 |
#define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \ |
| 1988 |
case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION: \ |
| 1989 |
case ST_OMP_DECLARE_VARIANT: case ST_OMP_ALLOCATE: case ST_OMP_ASSUMES: \ |
| 1990 |
case ST_OMP_REQUIRES: case ST_OACC_ROUTINE: case ST_OACC_DECLARE |
| 1991 |
|
| 1992 |
/* OpenMP statements that are followed by a structured block. */ |
| 1993 |
|
| 1994 |
#define case_omp_structured_block case ST_OMP_ASSUME: case ST_OMP_PARALLEL: \ |
| 1995 |
case ST_OMP_PARALLEL_MASKED: case ST_OMP_PARALLEL_MASTER: \ |
| 1996 |
case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_ORDERED: \ |
| 1997 |
case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASTER: \ |
| 1998 |
case ST_OMP_SCOPE: case ST_OMP_SECTIONS: case ST_OMP_SINGLE: \ |
| 1999 |
case ST_OMP_TARGET: case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_PARALLEL: \ |
| 2000 |
case ST_OMP_TARGET_TEAMS: case ST_OMP_TEAMS: case ST_OMP_TASK: \ |
| 2001 |
case ST_OMP_TASKGROUP: \ |
| 2002 |
case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE |
| 2003 |
|
| 2004 |
/* OpenMP statements that are followed by a do loop. */ |
| 2005 |
|
| 2006 |
#define case_omp_do case ST_OMP_DISTRIBUTE: \ |
| 2007 |
case ST_OMP_DISTRIBUTE_PARALLEL_DO: \ |
| 2008 |
case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE_SIMD: \ |
| 2009 |
case ST_OMP_DO: case ST_OMP_DO_SIMD: case ST_OMP_LOOP: \ |
| 2010 |
case ST_OMP_PARALLEL_DO: case ST_OMP_PARALLEL_DO_SIMD: \ |
| 2011 |
case ST_OMP_PARALLEL_LOOP: case ST_OMP_PARALLEL_MASKED_TASKLOOP: \ |
| 2012 |
case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: \ |
| 2013 |
case ST_OMP_PARALLEL_MASTER_TASKLOOP: \ |
| 2014 |
case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \ |
| 2015 |
case ST_OMP_MASKED_TASKLOOP: case ST_OMP_MASKED_TASKLOOP_SIMD: \ |
| 2016 |
case ST_OMP_MASTER_TASKLOOP: case ST_OMP_MASTER_TASKLOOP_SIMD: \ |
| 2017 |
case ST_OMP_SIMD: \ |
| 2018 |
case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \ |
| 2019 |
case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_SIMD: \ |
| 2020 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \ |
| 2021 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \ |
| 2022 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \ |
| 2023 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: case ST_OMP_TARGET_TEAMS_LOOP: \ |
| 2024 |
case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \ |
| 2025 |
case ST_OMP_TEAMS_DISTRIBUTE: case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \ |
| 2026 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \ |
| 2027 |
case ST_OMP_TEAMS_DISTRIBUTE_SIMD: case ST_OMP_TEAMS_LOOP: \ |
| 2028 |
case ST_OMP_TILE: case ST_OMP_UNROLL |
| 2029 |
|
| 2030 |
/* Block end statements. Errors associated with interchanging these |
| 2031 |
are detected in gfc_match_end(). */ |
| 2032 |
|
| 2033 |
#define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \ |
| 2034 |
case ST_END_PROGRAM: case ST_END_SUBROUTINE: \ |
| 2035 |
case ST_END_BLOCK: case ST_END_ASSOCIATE |
| 2036 |
|
| 2037 |
|
| 2038 |
/* Push a new state onto the stack. */ |
| 2039 |
|
| 2040 |
static void |
| 2041 |
push_state (gfc_state_data *p, gfc_compile_state new_state, gfc_symbol *sym) |
| 2042 |
{ |
| 2043 |
p->state = new_state; |
| 2044 |
p->previous = gfc_state_stack; |
| 2045 |
p->sym = sym; |
| 2046 |
p->head = p->tail = NULL; |
| 2047 |
p->do_variable = NULL; |
| 2048 |
if (p->state != COMP_DO && p->state != COMP_DO_CONCURRENT) |
| 2049 |
p->ext.oacc_declare_clauses = NULL; |
| 2050 |
|
| 2051 |
/* If this the state of a construct like BLOCK, DO or IF, the corresponding |
| 2052 |
construct statement was accepted right before pushing the state. Thus, |
| 2053 |
the construct's gfc_code is available as tail of the parent state. */ |
| 2054 |
gcc_assert (gfc_state_stack); |
| 2055 |
p->construct = gfc_state_stack->tail; |
| 2056 |
|
| 2057 |
gfc_state_stack = p; |
| 2058 |
} |
| 2059 |
|
| 2060 |
|
| 2061 |
/* Pop the current state. */ |
| 2062 |
static void |
| 2063 |
pop_state (void) |
| 2064 |
{ |
| 2065 |
gfc_state_stack = gfc_state_stack->previous; |
| 2066 |
} |
| 2067 |
|
| 2068 |
|
| 2069 |
/* Try to find the given state in the state stack. */ |
| 2070 |
|
| 2071 |
bool |
| 2072 |
gfc_find_state (gfc_compile_state state) |
| 2073 |
{ |
| 2074 |
gfc_state_data *p; |
| 2075 |
|
| 2076 |
for (p = gfc_state_stack; p; p = p->previous) |
| 2077 |
if (p->state == state) |
| 2078 |
break; |
| 2079 |
|
| 2080 |
return (p == NULL) ? false : true; |
| 2081 |
} |
| 2082 |
|
| 2083 |
|
| 2084 |
/* Starts a new level in the statement list. */ |
| 2085 |
|
| 2086 |
static gfc_code * |
| 2087 |
new_level (gfc_code *q) |
| 2088 |
{ |
| 2089 |
gfc_code *p; |
| 2090 |
|
| 2091 |
p = q->block = gfc_get_code (EXEC_NOP); |
| 2092 |
|
| 2093 |
gfc_state_stack->head = gfc_state_stack->tail = p; |
| 2094 |
|
| 2095 |
return p; |
| 2096 |
} |
| 2097 |
|
| 2098 |
|
| 2099 |
/* Add the current new_st code structure and adds it to the current |
| 2100 |
program unit. As a side-effect, it zeroes the new_st. */ |
| 2101 |
|
| 2102 |
static gfc_code * |
| 2103 |
add_statement (void) |
| 2104 |
{ |
| 2105 |
gfc_code *p; |
| 2106 |
|
| 2107 |
p = XCNEW (gfc_code); |
| 2108 |
*p = new_st; |
| 2109 |
|
| 2110 |
p->loc = gfc_current_locus; |
| 2111 |
|
| 2112 |
if (gfc_state_stack->head == NULL) |
| 2113 |
gfc_state_stack->head = p; |
| 2114 |
else |
| 2115 |
gfc_state_stack->tail->next = p; |
| 2116 |
|
| 2117 |
while (p->next != NULL) |
| 2118 |
p = p->next; |
| 2119 |
|
| 2120 |
gfc_state_stack->tail = p; |
| 2121 |
|
| 2122 |
gfc_clear_new_st (); |
| 2123 |
|
| 2124 |
return p; |
| 2125 |
} |
| 2126 |
|
| 2127 |
|
| 2128 |
/* Frees everything associated with the current statement. */ |
| 2129 |
|
| 2130 |
static void |
| 2131 |
undo_new_statement (void) |
| 2132 |
{ |
| 2133 |
gfc_free_statements (new_st.block); |
| 2134 |
gfc_free_statements (new_st.next); |
| 2135 |
gfc_free_statement (&new_st); |
| 2136 |
gfc_clear_new_st (); |
| 2137 |
} |
| 2138 |
|
| 2139 |
|
| 2140 |
/* If the current statement has a statement label, make sure that it |
| 2141 |
is allowed to, or should have one. */ |
| 2142 |
|
| 2143 |
static void |
| 2144 |
check_statement_label (gfc_statement st) |
| 2145 |
{ |
| 2146 |
gfc_sl_type type; |
| 2147 |
|
| 2148 |
if (gfc_statement_label == NULL) |
| 2149 |
{ |
| 2150 |
if (st == ST_FORMAT) |
| 2151 |
gfc_error ("FORMAT statement at %L does not have a statement label", |
| 2152 |
&new_st.loc); |
| 2153 |
return; |
| 2154 |
} |
| 2155 |
|
| 2156 |
switch (st) |
| 2157 |
{ |
| 2158 |
case ST_END_PROGRAM: |
| 2159 |
case ST_END_FUNCTION: |
| 2160 |
case ST_END_SUBROUTINE: |
| 2161 |
case ST_ENDDO: |
| 2162 |
case ST_ENDIF: |
| 2163 |
case ST_END_SELECT: |
| 2164 |
case ST_END_CRITICAL: |
| 2165 |
case ST_END_BLOCK: |
| 2166 |
case ST_END_ASSOCIATE: |
| 2167 |
case_executable: |
| 2168 |
case_exec_markers: |
| 2169 |
if (st == ST_ENDDO || st == ST_CONTINUE) |
| 2170 |
type = ST_LABEL_DO_TARGET; |
| 2171 |
else |
| 2172 |
type = ST_LABEL_TARGET; |
| 2173 |
break; |
| 2174 |
|
| 2175 |
case ST_FORMAT: |
| 2176 |
type = ST_LABEL_FORMAT; |
| 2177 |
break; |
| 2178 |
|
| 2179 |
/* Statement labels are not restricted from appearing on a |
| 2180 |
particular line. However, there are plenty of situations |
| 2181 |
where the resulting label can't be referenced. */ |
| 2182 |
|
| 2183 |
default: |
| 2184 |
type = ST_LABEL_BAD_TARGET; |
| 2185 |
break; |
| 2186 |
} |
| 2187 |
|
| 2188 |
gfc_define_st_label (gfc_statement_label, type, &label_locus); |
| 2189 |
|
| 2190 |
new_st.here = gfc_statement_label; |
| 2191 |
} |
| 2192 |
|
| 2193 |
|
| 2194 |
/* Figures out what the enclosing program unit is. This will be a |
| 2195 |
function, subroutine, program, block data or module. */ |
| 2196 |
|
| 2197 |
gfc_state_data * |
| 2198 |
gfc_enclosing_unit (gfc_compile_state * result) |
| 2199 |
{ |
| 2200 |
gfc_state_data *p; |
| 2201 |
|
| 2202 |
for (p = gfc_state_stack; p; p = p->previous) |
| 2203 |
if (p->state == COMP_FUNCTION || p->state == COMP_SUBROUTINE |
| 2204 |
|| p->state == COMP_MODULE || p->state == COMP_SUBMODULE |
| 2205 |
|| p->state == COMP_BLOCK_DATA || p->state == COMP_PROGRAM) |
| 2206 |
{ |
| 2207 |
|
| 2208 |
if (result != NULL) |
| 2209 |
*result = p->state; |
| 2210 |
return p; |
| 2211 |
} |
| 2212 |
|
| 2213 |
if (result != NULL) |
| 2214 |
*result = COMP_PROGRAM; |
| 2215 |
return NULL; |
| 2216 |
} |
| 2217 |
|
| 2218 |
|
| 2219 |
/* Translate a statement enum to a string. If strip_sentinel is true, |
| 2220 |
the !$OMP/!$ACC sentinel is excluded. */ |
| 2221 |
|
| 2222 |
const char * |
| 2223 |
gfc_ascii_statement (gfc_statement st, bool strip_sentinel) |
| 2224 |
{ |
| 2225 |
const char *p; |
| 2226 |
|
| 2227 |
switch (st) |
| 2228 |
{ |
| 2229 |
case ST_ARITHMETIC_IF: |
| 2230 |
p = _("arithmetic IF"); |
| 2231 |
break; |
| 2232 |
case ST_ALLOCATE: |
| 2233 |
p = "ALLOCATE"; |
| 2234 |
break; |
| 2235 |
case ST_ASSOCIATE: |
| 2236 |
p = "ASSOCIATE"; |
| 2237 |
break; |
| 2238 |
case ST_ATTR_DECL: |
| 2239 |
p = _("attribute declaration"); |
| 2240 |
break; |
| 2241 |
case ST_BACKSPACE: |
| 2242 |
p = "BACKSPACE"; |
| 2243 |
break; |
| 2244 |
case ST_BLOCK: |
| 2245 |
p = "BLOCK"; |
| 2246 |
break; |
| 2247 |
case ST_BLOCK_DATA: |
| 2248 |
p = "BLOCK DATA"; |
| 2249 |
break; |
| 2250 |
case ST_CALL: |
| 2251 |
p = "CALL"; |
| 2252 |
break; |
| 2253 |
case ST_CASE: |
| 2254 |
p = "CASE"; |
| 2255 |
break; |
| 2256 |
case ST_CLOSE: |
| 2257 |
p = "CLOSE"; |
| 2258 |
break; |
| 2259 |
case ST_COMMON: |
| 2260 |
p = "COMMON"; |
| 2261 |
break; |
| 2262 |
case ST_CONTINUE: |
| 2263 |
p = "CONTINUE"; |
| 2264 |
break; |
| 2265 |
case ST_CONTAINS: |
| 2266 |
p = "CONTAINS"; |
| 2267 |
break; |
| 2268 |
case ST_CRITICAL: |
| 2269 |
p = "CRITICAL"; |
| 2270 |
break; |
| 2271 |
case ST_CYCLE: |
| 2272 |
p = "CYCLE"; |
| 2273 |
break; |
| 2274 |
case ST_DATA_DECL: |
| 2275 |
p = _("data declaration"); |
| 2276 |
break; |
| 2277 |
case ST_DATA: |
| 2278 |
p = "DATA"; |
| 2279 |
break; |
| 2280 |
case ST_DEALLOCATE: |
| 2281 |
p = "DEALLOCATE"; |
| 2282 |
break; |
| 2283 |
case ST_MAP: |
| 2284 |
p = "MAP"; |
| 2285 |
break; |
| 2286 |
case ST_UNION: |
| 2287 |
p = "UNION"; |
| 2288 |
break; |
| 2289 |
case ST_STRUCTURE_DECL: |
| 2290 |
p = "STRUCTURE"; |
| 2291 |
break; |
| 2292 |
case ST_DERIVED_DECL: |
| 2293 |
p = _("derived type declaration"); |
| 2294 |
break; |
| 2295 |
case ST_DO: |
| 2296 |
p = "DO"; |
| 2297 |
break; |
| 2298 |
case ST_ELSE: |
| 2299 |
p = "ELSE"; |
| 2300 |
break; |
| 2301 |
case ST_ELSEIF: |
| 2302 |
p = "ELSE IF"; |
| 2303 |
break; |
| 2304 |
case ST_ELSEWHERE: |
| 2305 |
p = "ELSEWHERE"; |
| 2306 |
break; |
| 2307 |
case ST_EVENT_POST: |
| 2308 |
p = "EVENT POST"; |
| 2309 |
break; |
| 2310 |
case ST_EVENT_WAIT: |
| 2311 |
p = "EVENT WAIT"; |
| 2312 |
break; |
| 2313 |
case ST_FAIL_IMAGE: |
| 2314 |
p = "FAIL IMAGE"; |
| 2315 |
break; |
| 2316 |
case ST_CHANGE_TEAM: |
| 2317 |
p = "CHANGE TEAM"; |
| 2318 |
break; |
| 2319 |
case ST_END_TEAM: |
| 2320 |
p = "END TEAM"; |
| 2321 |
break; |
| 2322 |
case ST_FORM_TEAM: |
| 2323 |
p = "FORM TEAM"; |
| 2324 |
break; |
| 2325 |
case ST_SYNC_TEAM: |
| 2326 |
p = "SYNC TEAM"; |
| 2327 |
break; |
| 2328 |
case ST_END_ASSOCIATE: |
| 2329 |
p = "END ASSOCIATE"; |
| 2330 |
break; |
| 2331 |
case ST_END_BLOCK: |
| 2332 |
p = "END BLOCK"; |
| 2333 |
break; |
| 2334 |
case ST_END_BLOCK_DATA: |
| 2335 |
p = "END BLOCK DATA"; |
| 2336 |
break; |
| 2337 |
case ST_END_CRITICAL: |
| 2338 |
p = "END CRITICAL"; |
| 2339 |
break; |
| 2340 |
case ST_ENDDO: |
| 2341 |
p = "END DO"; |
| 2342 |
break; |
| 2343 |
case ST_END_FILE: |
| 2344 |
p = "END FILE"; |
| 2345 |
break; |
| 2346 |
case ST_END_FORALL: |
| 2347 |
p = "END FORALL"; |
| 2348 |
break; |
| 2349 |
case ST_END_FUNCTION: |
| 2350 |
p = "END FUNCTION"; |
| 2351 |
break; |
| 2352 |
case ST_ENDIF: |
| 2353 |
p = "END IF"; |
| 2354 |
break; |
| 2355 |
case ST_END_INTERFACE: |
| 2356 |
p = "END INTERFACE"; |
| 2357 |
break; |
| 2358 |
case ST_END_MODULE: |
| 2359 |
p = "END MODULE"; |
| 2360 |
break; |
| 2361 |
case ST_END_SUBMODULE: |
| 2362 |
p = "END SUBMODULE"; |
| 2363 |
break; |
| 2364 |
case ST_END_PROGRAM: |
| 2365 |
p = "END PROGRAM"; |
| 2366 |
break; |
| 2367 |
case ST_END_SELECT: |
| 2368 |
p = "END SELECT"; |
| 2369 |
break; |
| 2370 |
case ST_END_SUBROUTINE: |
| 2371 |
p = "END SUBROUTINE"; |
| 2372 |
break; |
| 2373 |
case ST_END_WHERE: |
| 2374 |
p = "END WHERE"; |
| 2375 |
break; |
| 2376 |
case ST_END_STRUCTURE: |
| 2377 |
p = "END STRUCTURE"; |
| 2378 |
break; |
| 2379 |
case ST_END_UNION: |
| 2380 |
p = "END UNION"; |
| 2381 |
break; |
| 2382 |
case ST_END_MAP: |
| 2383 |
p = "END MAP"; |
| 2384 |
break; |
| 2385 |
case ST_END_TYPE: |
| 2386 |
p = "END TYPE"; |
| 2387 |
break; |
| 2388 |
case ST_ENTRY: |
| 2389 |
p = "ENTRY"; |
| 2390 |
break; |
| 2391 |
case ST_EQUIVALENCE: |
| 2392 |
p = "EQUIVALENCE"; |
| 2393 |
break; |
| 2394 |
case ST_ERROR_STOP: |
| 2395 |
p = "ERROR STOP"; |
| 2396 |
break; |
| 2397 |
case ST_EXIT: |
| 2398 |
p = "EXIT"; |
| 2399 |
break; |
| 2400 |
case ST_FLUSH: |
| 2401 |
p = "FLUSH"; |
| 2402 |
break; |
| 2403 |
case ST_FORALL_BLOCK: /* Fall through */ |
| 2404 |
case ST_FORALL: |
| 2405 |
p = "FORALL"; |
| 2406 |
break; |
| 2407 |
case ST_FORMAT: |
| 2408 |
p = "FORMAT"; |
| 2409 |
break; |
| 2410 |
case ST_FUNCTION: |
| 2411 |
p = "FUNCTION"; |
| 2412 |
break; |
| 2413 |
case ST_GENERIC: |
| 2414 |
p = "GENERIC"; |
| 2415 |
break; |
| 2416 |
case ST_GOTO: |
| 2417 |
p = "GOTO"; |
| 2418 |
break; |
| 2419 |
case ST_IF_BLOCK: |
| 2420 |
p = _("block IF"); |
| 2421 |
break; |
| 2422 |
case ST_IMPLICIT: |
| 2423 |
p = "IMPLICIT"; |
| 2424 |
break; |
| 2425 |
case ST_IMPLICIT_NONE: |
| 2426 |
p = "IMPLICIT NONE"; |
| 2427 |
break; |
| 2428 |
case ST_IMPLIED_ENDDO: |
| 2429 |
p = _("implied END DO"); |
| 2430 |
break; |
| 2431 |
case ST_IMPORT: |
| 2432 |
p = "IMPORT"; |
| 2433 |
break; |
| 2434 |
case ST_INQUIRE: |
| 2435 |
p = "INQUIRE"; |
| 2436 |
break; |
| 2437 |
case ST_INTERFACE: |
| 2438 |
p = "INTERFACE"; |
| 2439 |
break; |
| 2440 |
case ST_LOCK: |
| 2441 |
p = "LOCK"; |
| 2442 |
break; |
| 2443 |
case ST_PARAMETER: |
| 2444 |
p = "PARAMETER"; |
| 2445 |
break; |
| 2446 |
case ST_PRIVATE: |
| 2447 |
p = "PRIVATE"; |
| 2448 |
break; |
| 2449 |
case ST_PUBLIC: |
| 2450 |
p = "PUBLIC"; |
| 2451 |
break; |
| 2452 |
case ST_MODULE: |
| 2453 |
p = "MODULE"; |
| 2454 |
break; |
| 2455 |
case ST_SUBMODULE: |
| 2456 |
p = "SUBMODULE"; |
| 2457 |
break; |
| 2458 |
case ST_PAUSE: |
| 2459 |
p = "PAUSE"; |
| 2460 |
break; |
| 2461 |
case ST_MODULE_PROC: |
| 2462 |
p = "MODULE PROCEDURE"; |
| 2463 |
break; |
| 2464 |
case ST_NAMELIST: |
| 2465 |
p = "NAMELIST"; |
| 2466 |
break; |
| 2467 |
case ST_NULLIFY: |
| 2468 |
p = "NULLIFY"; |
| 2469 |
break; |
| 2470 |
case ST_OPEN: |
| 2471 |
p = "OPEN"; |
| 2472 |
break; |
| 2473 |
case ST_PROGRAM: |
| 2474 |
p = "PROGRAM"; |
| 2475 |
break; |
| 2476 |
case ST_PROCEDURE: |
| 2477 |
p = "PROCEDURE"; |
| 2478 |
break; |
| 2479 |
case ST_READ: |
| 2480 |
p = "READ"; |
| 2481 |
break; |
| 2482 |
case ST_RETURN: |
| 2483 |
p = "RETURN"; |
| 2484 |
break; |
| 2485 |
case ST_REWIND: |
| 2486 |
p = "REWIND"; |
| 2487 |
break; |
| 2488 |
case ST_STOP: |
| 2489 |
p = "STOP"; |
| 2490 |
break; |
| 2491 |
case ST_SYNC_ALL: |
| 2492 |
p = "SYNC ALL"; |
| 2493 |
break; |
| 2494 |
case ST_SYNC_IMAGES: |
| 2495 |
p = "SYNC IMAGES"; |
| 2496 |
break; |
| 2497 |
case ST_SYNC_MEMORY: |
| 2498 |
p = "SYNC MEMORY"; |
| 2499 |
break; |
| 2500 |
case ST_SUBROUTINE: |
| 2501 |
p = "SUBROUTINE"; |
| 2502 |
break; |
| 2503 |
case ST_TYPE: |
| 2504 |
p = "TYPE"; |
| 2505 |
break; |
| 2506 |
case ST_UNLOCK: |
| 2507 |
p = "UNLOCK"; |
| 2508 |
break; |
| 2509 |
case ST_USE: |
| 2510 |
p = "USE"; |
| 2511 |
break; |
| 2512 |
case ST_WHERE_BLOCK: /* Fall through */ |
| 2513 |
case ST_WHERE: |
| 2514 |
p = "WHERE"; |
| 2515 |
break; |
| 2516 |
case ST_WAIT: |
| 2517 |
p = "WAIT"; |
| 2518 |
break; |
| 2519 |
case ST_WRITE: |
| 2520 |
p = "WRITE"; |
| 2521 |
break; |
| 2522 |
case ST_ASSIGNMENT: |
| 2523 |
p = _("assignment"); |
| 2524 |
break; |
| 2525 |
case ST_POINTER_ASSIGNMENT: |
| 2526 |
p = _("pointer assignment"); |
| 2527 |
break; |
| 2528 |
case ST_SELECT_CASE: |
| 2529 |
p = "SELECT CASE"; |
| 2530 |
break; |
| 2531 |
case ST_SELECT_TYPE: |
| 2532 |
p = "SELECT TYPE"; |
| 2533 |
break; |
| 2534 |
case ST_SELECT_RANK: |
| 2535 |
p = "SELECT RANK"; |
| 2536 |
break; |
| 2537 |
case ST_TYPE_IS: |
| 2538 |
p = "TYPE IS"; |
| 2539 |
break; |
| 2540 |
case ST_CLASS_IS: |
| 2541 |
p = "CLASS IS"; |
| 2542 |
break; |
| 2543 |
case ST_RANK: |
| 2544 |
p = "RANK"; |
| 2545 |
break; |
| 2546 |
case ST_SEQUENCE: |
| 2547 |
p = "SEQUENCE"; |
| 2548 |
break; |
| 2549 |
case ST_SIMPLE_IF: |
| 2550 |
p = _("simple IF"); |
| 2551 |
break; |
| 2552 |
case ST_STATEMENT_FUNCTION: |
| 2553 |
p = "STATEMENT FUNCTION"; |
| 2554 |
break; |
| 2555 |
case ST_LABEL_ASSIGNMENT: |
| 2556 |
p = "LABEL ASSIGNMENT"; |
| 2557 |
break; |
| 2558 |
case ST_ENUM: |
| 2559 |
p = "ENUM DEFINITION"; |
| 2560 |
break; |
| 2561 |
case ST_ENUMERATOR: |
| 2562 |
p = "ENUMERATOR DEFINITION"; |
| 2563 |
break; |
| 2564 |
case ST_END_ENUM: |
| 2565 |
p = "END ENUM"; |
| 2566 |
break; |
| 2567 |
case ST_OACC_PARALLEL_LOOP: |
| 2568 |
p = "!$ACC PARALLEL LOOP"; |
| 2569 |
break; |
| 2570 |
case ST_OACC_END_PARALLEL_LOOP: |
| 2571 |
p = "!$ACC END PARALLEL LOOP"; |
| 2572 |
break; |
| 2573 |
case ST_OACC_PARALLEL: |
| 2574 |
p = "!$ACC PARALLEL"; |
| 2575 |
break; |
| 2576 |
case ST_OACC_END_PARALLEL: |
| 2577 |
p = "!$ACC END PARALLEL"; |
| 2578 |
break; |
| 2579 |
case ST_OACC_KERNELS: |
| 2580 |
p = "!$ACC KERNELS"; |
| 2581 |
break; |
| 2582 |
case ST_OACC_END_KERNELS: |
| 2583 |
p = "!$ACC END KERNELS"; |
| 2584 |
break; |
| 2585 |
case ST_OACC_KERNELS_LOOP: |
| 2586 |
p = "!$ACC KERNELS LOOP"; |
| 2587 |
break; |
| 2588 |
case ST_OACC_END_KERNELS_LOOP: |
| 2589 |
p = "!$ACC END KERNELS LOOP"; |
| 2590 |
break; |
| 2591 |
case ST_OACC_SERIAL_LOOP: |
| 2592 |
p = "!$ACC SERIAL LOOP"; |
| 2593 |
break; |
| 2594 |
case ST_OACC_END_SERIAL_LOOP: |
| 2595 |
p = "!$ACC END SERIAL LOOP"; |
| 2596 |
break; |
| 2597 |
case ST_OACC_SERIAL: |
| 2598 |
p = "!$ACC SERIAL"; |
| 2599 |
break; |
| 2600 |
case ST_OACC_END_SERIAL: |
| 2601 |
p = "!$ACC END SERIAL"; |
| 2602 |
break; |
| 2603 |
case ST_OACC_DATA: |
| 2604 |
p = "!$ACC DATA"; |
| 2605 |
break; |
| 2606 |
case ST_OACC_END_DATA: |
| 2607 |
p = "!$ACC END DATA"; |
| 2608 |
break; |
| 2609 |
case ST_OACC_HOST_DATA: |
| 2610 |
p = "!$ACC HOST_DATA"; |
| 2611 |
break; |
| 2612 |
case ST_OACC_END_HOST_DATA: |
| 2613 |
p = "!$ACC END HOST_DATA"; |
| 2614 |
break; |
| 2615 |
case ST_OACC_LOOP: |
| 2616 |
p = "!$ACC LOOP"; |
| 2617 |
break; |
| 2618 |
case ST_OACC_END_LOOP: |
| 2619 |
p = "!$ACC END LOOP"; |
| 2620 |
break; |
| 2621 |
case ST_OACC_DECLARE: |
| 2622 |
p = "!$ACC DECLARE"; |
| 2623 |
break; |
| 2624 |
case ST_OACC_UPDATE: |
| 2625 |
p = "!$ACC UPDATE"; |
| 2626 |
break; |
| 2627 |
case ST_OACC_WAIT: |
| 2628 |
p = "!$ACC WAIT"; |
| 2629 |
break; |
| 2630 |
case ST_OACC_CACHE: |
| 2631 |
p = "!$ACC CACHE"; |
| 2632 |
break; |
| 2633 |
case ST_OACC_ENTER_DATA: |
| 2634 |
p = "!$ACC ENTER DATA"; |
| 2635 |
break; |
| 2636 |
case ST_OACC_EXIT_DATA: |
| 2637 |
p = "!$ACC EXIT DATA"; |
| 2638 |
break; |
| 2639 |
case ST_OACC_ROUTINE: |
| 2640 |
p = "!$ACC ROUTINE"; |
| 2641 |
break; |
| 2642 |
case ST_OACC_ATOMIC: |
| 2643 |
p = "!$ACC ATOMIC"; |
| 2644 |
break; |
| 2645 |
case ST_OACC_END_ATOMIC: |
| 2646 |
p = "!$ACC END ATOMIC"; |
| 2647 |
break; |
| 2648 |
case ST_OMP_ALLOCATE: |
| 2649 |
case ST_OMP_ALLOCATE_EXEC: |
| 2650 |
p = "!$OMP ALLOCATE"; |
| 2651 |
break; |
| 2652 |
case ST_OMP_ALLOCATORS: |
| 2653 |
p = "!$OMP ALLOCATORS"; |
| 2654 |
break; |
| 2655 |
case ST_OMP_ASSUME: |
| 2656 |
p = "!$OMP ASSUME"; |
| 2657 |
break; |
| 2658 |
case ST_OMP_ASSUMES: |
| 2659 |
p = "!$OMP ASSUMES"; |
| 2660 |
break; |
| 2661 |
case ST_OMP_ATOMIC: |
| 2662 |
p = "!$OMP ATOMIC"; |
| 2663 |
break; |
| 2664 |
case ST_OMP_BARRIER: |
| 2665 |
p = "!$OMP BARRIER"; |
| 2666 |
break; |
| 2667 |
case ST_OMP_BEGIN_METADIRECTIVE: |
| 2668 |
p = "!$OMP BEGIN METADIRECTIVE"; |
| 2669 |
break; |
| 2670 |
case ST_OMP_CANCEL: |
| 2671 |
p = "!$OMP CANCEL"; |
| 2672 |
break; |
| 2673 |
case ST_OMP_CANCELLATION_POINT: |
| 2674 |
p = "!$OMP CANCELLATION POINT"; |
| 2675 |
break; |
| 2676 |
case ST_OMP_CRITICAL: |
| 2677 |
p = "!$OMP CRITICAL"; |
| 2678 |
break; |
| 2679 |
case ST_OMP_DECLARE_REDUCTION: |
| 2680 |
p = "!$OMP DECLARE REDUCTION"; |
| 2681 |
break; |
| 2682 |
case ST_OMP_DECLARE_SIMD: |
| 2683 |
p = "!$OMP DECLARE SIMD"; |
| 2684 |
break; |
| 2685 |
case ST_OMP_DECLARE_TARGET: |
| 2686 |
p = "!$OMP DECLARE TARGET"; |
| 2687 |
break; |
| 2688 |
case ST_OMP_DECLARE_VARIANT: |
| 2689 |
p = "!$OMP DECLARE VARIANT"; |
| 2690 |
break; |
| 2691 |
case ST_OMP_DEPOBJ: |
| 2692 |
p = "!$OMP DEPOBJ"; |
| 2693 |
break; |
| 2694 |
case ST_OMP_DISPATCH: |
| 2695 |
p = "!$OMP DISPATCH"; |
| 2696 |
break; |
| 2697 |
case ST_OMP_DISTRIBUTE: |
| 2698 |
p = "!$OMP DISTRIBUTE"; |
| 2699 |
break; |
| 2700 |
case ST_OMP_DISTRIBUTE_PARALLEL_DO: |
| 2701 |
p = "!$OMP DISTRIBUTE PARALLEL DO"; |
| 2702 |
break; |
| 2703 |
case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 2704 |
p = "!$OMP DISTRIBUTE PARALLEL DO SIMD"; |
| 2705 |
break; |
| 2706 |
case ST_OMP_DISTRIBUTE_SIMD: |
| 2707 |
p = "!$OMP DISTRIBUTE SIMD"; |
| 2708 |
break; |
| 2709 |
case ST_OMP_DO: |
| 2710 |
p = "!$OMP DO"; |
| 2711 |
break; |
| 2712 |
case ST_OMP_DO_SIMD: |
| 2713 |
p = "!$OMP DO SIMD"; |
| 2714 |
break; |
| 2715 |
case ST_OMP_END_ALLOCATORS: |
| 2716 |
p = "!$OMP END ALLOCATORS"; |
| 2717 |
break; |
| 2718 |
case ST_OMP_END_ASSUME: |
| 2719 |
p = "!$OMP END ASSUME"; |
| 2720 |
break; |
| 2721 |
case ST_OMP_END_ATOMIC: |
| 2722 |
p = "!$OMP END ATOMIC"; |
| 2723 |
break; |
| 2724 |
case ST_OMP_END_CRITICAL: |
| 2725 |
p = "!$OMP END CRITICAL"; |
| 2726 |
break; |
| 2727 |
case ST_OMP_END_DISPATCH: |
| 2728 |
p = "!$OMP END DISPATCH"; |
| 2729 |
break; |
| 2730 |
case ST_OMP_END_DISTRIBUTE: |
| 2731 |
p = "!$OMP END DISTRIBUTE"; |
| 2732 |
break; |
| 2733 |
case ST_OMP_END_DISTRIBUTE_PARALLEL_DO: |
| 2734 |
p = "!$OMP END DISTRIBUTE PARALLEL DO"; |
| 2735 |
break; |
| 2736 |
case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 2737 |
p = "!$OMP END DISTRIBUTE PARALLEL DO SIMD"; |
| 2738 |
break; |
| 2739 |
case ST_OMP_END_DISTRIBUTE_SIMD: |
| 2740 |
p = "!$OMP END DISTRIBUTE SIMD"; |
| 2741 |
break; |
| 2742 |
case ST_OMP_END_DO: |
| 2743 |
p = "!$OMP END DO"; |
| 2744 |
break; |
| 2745 |
case ST_OMP_END_DO_SIMD: |
| 2746 |
p = "!$OMP END DO SIMD"; |
| 2747 |
break; |
| 2748 |
case ST_OMP_END_SCOPE: |
| 2749 |
p = "!$OMP END SCOPE"; |
| 2750 |
break; |
| 2751 |
case ST_OMP_END_SIMD: |
| 2752 |
p = "!$OMP END SIMD"; |
| 2753 |
break; |
| 2754 |
case ST_OMP_END_LOOP: |
| 2755 |
p = "!$OMP END LOOP"; |
| 2756 |
break; |
| 2757 |
case ST_OMP_END_MASKED: |
| 2758 |
p = "!$OMP END MASKED"; |
| 2759 |
break; |
| 2760 |
case ST_OMP_END_MASKED_TASKLOOP: |
| 2761 |
p = "!$OMP END MASKED TASKLOOP"; |
| 2762 |
break; |
| 2763 |
case ST_OMP_END_MASKED_TASKLOOP_SIMD: |
| 2764 |
p = "!$OMP END MASKED TASKLOOP SIMD"; |
| 2765 |
break; |
| 2766 |
case ST_OMP_END_MASTER: |
| 2767 |
p = "!$OMP END MASTER"; |
| 2768 |
break; |
| 2769 |
case ST_OMP_END_MASTER_TASKLOOP: |
| 2770 |
p = "!$OMP END MASTER TASKLOOP"; |
| 2771 |
break; |
| 2772 |
case ST_OMP_END_MASTER_TASKLOOP_SIMD: |
| 2773 |
p = "!$OMP END MASTER TASKLOOP SIMD"; |
| 2774 |
break; |
| 2775 |
case ST_OMP_END_METADIRECTIVE: |
| 2776 |
p = "!$OMP END METADIRECTIVE"; |
| 2777 |
break; |
| 2778 |
case ST_OMP_END_ORDERED: |
| 2779 |
p = "!$OMP END ORDERED"; |
| 2780 |
break; |
| 2781 |
case ST_OMP_END_PARALLEL: |
| 2782 |
p = "!$OMP END PARALLEL"; |
| 2783 |
break; |
| 2784 |
case ST_OMP_END_PARALLEL_DO: |
| 2785 |
p = "!$OMP END PARALLEL DO"; |
| 2786 |
break; |
| 2787 |
case ST_OMP_END_PARALLEL_DO_SIMD: |
| 2788 |
p = "!$OMP END PARALLEL DO SIMD"; |
| 2789 |
break; |
| 2790 |
case ST_OMP_END_PARALLEL_LOOP: |
| 2791 |
p = "!$OMP END PARALLEL LOOP"; |
| 2792 |
break; |
| 2793 |
case ST_OMP_END_PARALLEL_MASKED: |
| 2794 |
p = "!$OMP END PARALLEL MASKED"; |
| 2795 |
break; |
| 2796 |
case ST_OMP_END_PARALLEL_MASKED_TASKLOOP: |
| 2797 |
p = "!$OMP END PARALLEL MASKED TASKLOOP"; |
| 2798 |
break; |
| 2799 |
case ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD: |
| 2800 |
p = "!$OMP END PARALLEL MASKED TASKLOOP SIMD"; |
| 2801 |
break; |
| 2802 |
case ST_OMP_END_PARALLEL_MASTER: |
| 2803 |
p = "!$OMP END PARALLEL MASTER"; |
| 2804 |
break; |
| 2805 |
case ST_OMP_END_PARALLEL_MASTER_TASKLOOP: |
| 2806 |
p = "!$OMP END PARALLEL MASTER TASKLOOP"; |
| 2807 |
break; |
| 2808 |
case ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD: |
| 2809 |
p = "!$OMP END PARALLEL MASTER TASKLOOP SIMD"; |
| 2810 |
break; |
| 2811 |
case ST_OMP_END_PARALLEL_SECTIONS: |
| 2812 |
p = "!$OMP END PARALLEL SECTIONS"; |
| 2813 |
break; |
| 2814 |
case ST_OMP_END_PARALLEL_WORKSHARE: |
| 2815 |
p = "!$OMP END PARALLEL WORKSHARE"; |
| 2816 |
break; |
| 2817 |
case ST_OMP_END_SECTIONS: |
| 2818 |
p = "!$OMP END SECTIONS"; |
| 2819 |
break; |
| 2820 |
case ST_OMP_END_SINGLE: |
| 2821 |
p = "!$OMP END SINGLE"; |
| 2822 |
break; |
| 2823 |
case ST_OMP_END_TASK: |
| 2824 |
p = "!$OMP END TASK"; |
| 2825 |
break; |
| 2826 |
case ST_OMP_END_TARGET: |
| 2827 |
p = "!$OMP END TARGET"; |
| 2828 |
break; |
| 2829 |
case ST_OMP_END_TARGET_DATA: |
| 2830 |
p = "!$OMP END TARGET DATA"; |
| 2831 |
break; |
| 2832 |
case ST_OMP_END_TARGET_PARALLEL: |
| 2833 |
p = "!$OMP END TARGET PARALLEL"; |
| 2834 |
break; |
| 2835 |
case ST_OMP_END_TARGET_PARALLEL_DO: |
| 2836 |
p = "!$OMP END TARGET PARALLEL DO"; |
| 2837 |
break; |
| 2838 |
case ST_OMP_END_TARGET_PARALLEL_DO_SIMD: |
| 2839 |
p = "!$OMP END TARGET PARALLEL DO SIMD"; |
| 2840 |
break; |
| 2841 |
case ST_OMP_END_TARGET_PARALLEL_LOOP: |
| 2842 |
p = "!$OMP END TARGET PARALLEL LOOP"; |
| 2843 |
break; |
| 2844 |
case ST_OMP_END_TARGET_SIMD: |
| 2845 |
p = "!$OMP END TARGET SIMD"; |
| 2846 |
break; |
| 2847 |
case ST_OMP_END_TARGET_TEAMS: |
| 2848 |
p = "!$OMP END TARGET TEAMS"; |
| 2849 |
break; |
| 2850 |
case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE: |
| 2851 |
p = "!$OMP END TARGET TEAMS DISTRIBUTE"; |
| 2852 |
break; |
| 2853 |
case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 2854 |
p = "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO"; |
| 2855 |
break; |
| 2856 |
case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 2857 |
p = "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD"; |
| 2858 |
break; |
| 2859 |
case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD: |
| 2860 |
p = "!$OMP END TARGET TEAMS DISTRIBUTE SIMD"; |
| 2861 |
break; |
| 2862 |
case ST_OMP_END_TARGET_TEAMS_LOOP: |
| 2863 |
p = "!$OMP END TARGET TEAMS LOOP"; |
| 2864 |
break; |
| 2865 |
case ST_OMP_END_TASKGROUP: |
| 2866 |
p = "!$OMP END TASKGROUP"; |
| 2867 |
break; |
| 2868 |
case ST_OMP_END_TASKLOOP: |
| 2869 |
p = "!$OMP END TASKLOOP"; |
| 2870 |
break; |
| 2871 |
case ST_OMP_END_TASKLOOP_SIMD: |
| 2872 |
p = "!$OMP END TASKLOOP SIMD"; |
| 2873 |
break; |
| 2874 |
case ST_OMP_END_TEAMS: |
| 2875 |
p = "!$OMP END TEAMS"; |
| 2876 |
break; |
| 2877 |
case ST_OMP_END_TEAMS_DISTRIBUTE: |
| 2878 |
p = "!$OMP END TEAMS DISTRIBUTE"; |
| 2879 |
break; |
| 2880 |
case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 2881 |
p = "!$OMP END TEAMS DISTRIBUTE PARALLEL DO"; |
| 2882 |
break; |
| 2883 |
case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 2884 |
p = "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD"; |
| 2885 |
break; |
| 2886 |
case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD: |
| 2887 |
p = "!$OMP END TEAMS DISTRIBUTE SIMD"; |
| 2888 |
break; |
| 2889 |
case ST_OMP_END_TEAMS_LOOP: |
| 2890 |
p = "!$OMP END TEAMS LOOP"; |
| 2891 |
break; |
| 2892 |
case ST_OMP_END_TILE: |
| 2893 |
p = "!$OMP END TILE"; |
| 2894 |
break; |
| 2895 |
case ST_OMP_END_UNROLL: |
| 2896 |
p = "!$OMP END UNROLL"; |
| 2897 |
break; |
| 2898 |
case ST_OMP_END_WORKSHARE: |
| 2899 |
p = "!$OMP END WORKSHARE"; |
| 2900 |
break; |
| 2901 |
case ST_OMP_ERROR: |
| 2902 |
p = "!$OMP ERROR"; |
| 2903 |
break; |
| 2904 |
case ST_OMP_FLUSH: |
| 2905 |
p = "!$OMP FLUSH"; |
| 2906 |
break; |
| 2907 |
case ST_OMP_INTEROP: |
| 2908 |
p = "!$OMP INTEROP"; |
| 2909 |
break; |
| 2910 |
case ST_OMP_LOOP: |
| 2911 |
p = "!$OMP LOOP"; |
| 2912 |
break; |
| 2913 |
case ST_OMP_MASKED: |
| 2914 |
p = "!$OMP MASKED"; |
| 2915 |
break; |
| 2916 |
case ST_OMP_MASKED_TASKLOOP: |
| 2917 |
p = "!$OMP MASKED TASKLOOP"; |
| 2918 |
break; |
| 2919 |
case ST_OMP_MASKED_TASKLOOP_SIMD: |
| 2920 |
p = "!$OMP MASKED TASKLOOP SIMD"; |
| 2921 |
break; |
| 2922 |
case ST_OMP_MASTER: |
| 2923 |
p = "!$OMP MASTER"; |
| 2924 |
break; |
| 2925 |
case ST_OMP_MASTER_TASKLOOP: |
| 2926 |
p = "!$OMP MASTER TASKLOOP"; |
| 2927 |
break; |
| 2928 |
case ST_OMP_MASTER_TASKLOOP_SIMD: |
| 2929 |
p = "!$OMP MASTER TASKLOOP SIMD"; |
| 2930 |
break; |
| 2931 |
case ST_OMP_METADIRECTIVE: |
| 2932 |
p = "!$OMP METADIRECTIVE"; |
| 2933 |
break; |
| 2934 |
case ST_OMP_ORDERED: |
| 2935 |
case ST_OMP_ORDERED_DEPEND: |
| 2936 |
p = "!$OMP ORDERED"; |
| 2937 |
break; |
| 2938 |
case ST_OMP_NOTHING: |
| 2939 |
/* Note: gfc_match_omp_nothing returns ST_NONE. */ |
| 2940 |
p = "!$OMP NOTHING"; |
| 2941 |
break; |
| 2942 |
case ST_OMP_PARALLEL: |
| 2943 |
p = "!$OMP PARALLEL"; |
| 2944 |
break; |
| 2945 |
case ST_OMP_PARALLEL_DO: |
| 2946 |
p = "!$OMP PARALLEL DO"; |
| 2947 |
break; |
| 2948 |
case ST_OMP_PARALLEL_LOOP: |
| 2949 |
p = "!$OMP PARALLEL LOOP"; |
| 2950 |
break; |
| 2951 |
case ST_OMP_PARALLEL_DO_SIMD: |
| 2952 |
p = "!$OMP PARALLEL DO SIMD"; |
| 2953 |
break; |
| 2954 |
case ST_OMP_PARALLEL_MASKED: |
| 2955 |
p = "!$OMP PARALLEL MASKED"; |
| 2956 |
break; |
| 2957 |
case ST_OMP_PARALLEL_MASKED_TASKLOOP: |
| 2958 |
p = "!$OMP PARALLEL MASKED TASKLOOP"; |
| 2959 |
break; |
| 2960 |
case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: |
| 2961 |
p = "!$OMP PARALLEL MASKED TASKLOOP SIMD"; |
| 2962 |
break; |
| 2963 |
case ST_OMP_PARALLEL_MASTER: |
| 2964 |
p = "!$OMP PARALLEL MASTER"; |
| 2965 |
break; |
| 2966 |
case ST_OMP_PARALLEL_MASTER_TASKLOOP: |
| 2967 |
p = "!$OMP PARALLEL MASTER TASKLOOP"; |
| 2968 |
break; |
| 2969 |
case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: |
| 2970 |
p = "!$OMP PARALLEL MASTER TASKLOOP SIMD"; |
| 2971 |
break; |
| 2972 |
case ST_OMP_PARALLEL_SECTIONS: |
| 2973 |
p = "!$OMP PARALLEL SECTIONS"; |
| 2974 |
break; |
| 2975 |
case ST_OMP_PARALLEL_WORKSHARE: |
| 2976 |
p = "!$OMP PARALLEL WORKSHARE"; |
| 2977 |
break; |
| 2978 |
case ST_OMP_REQUIRES: |
| 2979 |
p = "!$OMP REQUIRES"; |
| 2980 |
break; |
| 2981 |
case ST_OMP_SCAN: |
| 2982 |
p = "!$OMP SCAN"; |
| 2983 |
break; |
| 2984 |
case ST_OMP_SCOPE: |
| 2985 |
p = "!$OMP SCOPE"; |
| 2986 |
break; |
| 2987 |
case ST_OMP_SECTIONS: |
| 2988 |
p = "!$OMP SECTIONS"; |
| 2989 |
break; |
| 2990 |
case ST_OMP_SECTION: |
| 2991 |
p = "!$OMP SECTION"; |
| 2992 |
break; |
| 2993 |
case ST_OMP_SIMD: |
| 2994 |
p = "!$OMP SIMD"; |
| 2995 |
break; |
| 2996 |
case ST_OMP_SINGLE: |
| 2997 |
p = "!$OMP SINGLE"; |
| 2998 |
break; |
| 2999 |
case ST_OMP_TARGET: |
| 3000 |
p = "!$OMP TARGET"; |
| 3001 |
break; |
| 3002 |
case ST_OMP_TARGET_DATA: |
| 3003 |
p = "!$OMP TARGET DATA"; |
| 3004 |
break; |
| 3005 |
case ST_OMP_TARGET_ENTER_DATA: |
| 3006 |
p = "!$OMP TARGET ENTER DATA"; |
| 3007 |
break; |
| 3008 |
case ST_OMP_TARGET_EXIT_DATA: |
| 3009 |
p = "!$OMP TARGET EXIT DATA"; |
| 3010 |
break; |
| 3011 |
case ST_OMP_TARGET_PARALLEL: |
| 3012 |
p = "!$OMP TARGET PARALLEL"; |
| 3013 |
break; |
| 3014 |
case ST_OMP_TARGET_PARALLEL_DO: |
| 3015 |
p = "!$OMP TARGET PARALLEL DO"; |
| 3016 |
break; |
| 3017 |
case ST_OMP_TARGET_PARALLEL_DO_SIMD: |
| 3018 |
p = "!$OMP TARGET PARALLEL DO SIMD"; |
| 3019 |
break; |
| 3020 |
case ST_OMP_TARGET_PARALLEL_LOOP: |
| 3021 |
p = "!$OMP TARGET PARALLEL LOOP"; |
| 3022 |
break; |
| 3023 |
case ST_OMP_TARGET_SIMD: |
| 3024 |
p = "!$OMP TARGET SIMD"; |
| 3025 |
break; |
| 3026 |
case ST_OMP_TARGET_TEAMS: |
| 3027 |
p = "!$OMP TARGET TEAMS"; |
| 3028 |
break; |
| 3029 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE: |
| 3030 |
p = "!$OMP TARGET TEAMS DISTRIBUTE"; |
| 3031 |
break; |
| 3032 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 3033 |
p = "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO"; |
| 3034 |
break; |
| 3035 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 3036 |
p = "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD"; |
| 3037 |
break; |
| 3038 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: |
| 3039 |
p = "!$OMP TARGET TEAMS DISTRIBUTE SIMD"; |
| 3040 |
break; |
| 3041 |
case ST_OMP_TARGET_TEAMS_LOOP: |
| 3042 |
p = "!$OMP TARGET TEAMS LOOP"; |
| 3043 |
break; |
| 3044 |
case ST_OMP_TARGET_UPDATE: |
| 3045 |
p = "!$OMP TARGET UPDATE"; |
| 3046 |
break; |
| 3047 |
case ST_OMP_TASK: |
| 3048 |
p = "!$OMP TASK"; |
| 3049 |
break; |
| 3050 |
case ST_OMP_TASKGROUP: |
| 3051 |
p = "!$OMP TASKGROUP"; |
| 3052 |
break; |
| 3053 |
case ST_OMP_TASKLOOP: |
| 3054 |
p = "!$OMP TASKLOOP"; |
| 3055 |
break; |
| 3056 |
case ST_OMP_TASKLOOP_SIMD: |
| 3057 |
p = "!$OMP TASKLOOP SIMD"; |
| 3058 |
break; |
| 3059 |
case ST_OMP_TASKWAIT: |
| 3060 |
p = "!$OMP TASKWAIT"; |
| 3061 |
break; |
| 3062 |
case ST_OMP_TASKYIELD: |
| 3063 |
p = "!$OMP TASKYIELD"; |
| 3064 |
break; |
| 3065 |
case ST_OMP_TEAMS: |
| 3066 |
p = "!$OMP TEAMS"; |
| 3067 |
break; |
| 3068 |
case ST_OMP_TEAMS_DISTRIBUTE: |
| 3069 |
p = "!$OMP TEAMS DISTRIBUTE"; |
| 3070 |
break; |
| 3071 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 3072 |
p = "!$OMP TEAMS DISTRIBUTE PARALLEL DO"; |
| 3073 |
break; |
| 3074 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 3075 |
p = "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD"; |
| 3076 |
break; |
| 3077 |
case ST_OMP_TEAMS_DISTRIBUTE_SIMD: |
| 3078 |
p = "!$OMP TEAMS DISTRIBUTE SIMD"; |
| 3079 |
break; |
| 3080 |
case ST_OMP_TEAMS_LOOP: |
| 3081 |
p = "!$OMP TEAMS LOOP"; |
| 3082 |
break; |
| 3083 |
case ST_OMP_THREADPRIVATE: |
| 3084 |
p = "!$OMP THREADPRIVATE"; |
| 3085 |
break; |
| 3086 |
case ST_OMP_TILE: |
| 3087 |
p = "!$OMP TILE"; |
| 3088 |
break; |
| 3089 |
case ST_OMP_UNROLL: |
| 3090 |
p = "!$OMP UNROLL"; |
| 3091 |
break; |
| 3092 |
case ST_OMP_WORKSHARE: |
| 3093 |
p = "!$OMP WORKSHARE"; |
| 3094 |
break; |
| 3095 |
default: |
| 3096 |
gfc_internal_error ("gfc_ascii_statement(): Bad statement code"); |
| 3097 |
} |
| 3098 |
|
| 3099 |
if (strip_sentinel && p[0] == '!') |
| 3100 |
return p + strlen ("!$OMP "); |
| 3101 |
return p; |
| 3102 |
} |
| 3103 |
|
| 3104 |
|
| 3105 |
/* Create a symbol for the main program and assign it to ns->proc_name. */ |
| 3106 |
|
| 3107 |
static void |
| 3108 |
main_program_symbol (gfc_namespace *ns, const char *name) |
| 3109 |
{ |
| 3110 |
gfc_symbol *main_program; |
| 3111 |
symbol_attribute attr; |
| 3112 |
|
| 3113 |
gfc_get_symbol (name, ns, &main_program); |
| 3114 |
gfc_clear_attr (&attr); |
| 3115 |
attr.flavor = FL_PROGRAM; |
| 3116 |
attr.proc = PROC_UNKNOWN; |
| 3117 |
attr.subroutine = 1; |
| 3118 |
attr.access = ACCESS_PUBLIC; |
| 3119 |
attr.is_main_program = 1; |
| 3120 |
main_program->attr = attr; |
| 3121 |
main_program->declared_at = gfc_current_locus; |
| 3122 |
ns->proc_name = main_program; |
| 3123 |
gfc_commit_symbols (); |
| 3124 |
} |
| 3125 |
|
| 3126 |
|
| 3127 |
/* Do whatever is necessary to accept the last statement. */ |
| 3128 |
|
| 3129 |
static void |
| 3130 |
accept_statement (gfc_statement st) |
| 3131 |
{ |
| 3132 |
switch (st) |
| 3133 |
{ |
| 3134 |
case ST_IMPLICIT_NONE: |
| 3135 |
case ST_IMPLICIT: |
| 3136 |
break; |
| 3137 |
|
| 3138 |
case ST_FUNCTION: |
| 3139 |
case ST_SUBROUTINE: |
| 3140 |
case ST_MODULE: |
| 3141 |
case ST_SUBMODULE: |
| 3142 |
gfc_current_ns->proc_name = gfc_new_block; |
| 3143 |
break; |
| 3144 |
|
| 3145 |
/* If the statement is the end of a block, lay down a special code |
| 3146 |
that allows a branch to the end of the block from within the |
| 3147 |
construct. IF and SELECT are treated differently from DO |
| 3148 |
(where EXEC_NOP is added inside the loop) for two |
| 3149 |
reasons: |
| 3150 |
1. END DO has a meaning in the sense that after a GOTO to |
| 3151 |
it, the loop counter must be increased. |
| 3152 |
2. IF blocks and SELECT blocks can consist of multiple |
| 3153 |
parallel blocks (IF ... ELSE IF ... ELSE ... END IF). |
| 3154 |
Putting the label before the END IF would make the jump |
| 3155 |
from, say, the ELSE IF block to the END IF illegal. */ |
| 3156 |
|
| 3157 |
case ST_ENDIF: |
| 3158 |
case ST_END_SELECT: |
| 3159 |
case ST_END_CRITICAL: |
| 3160 |
if (gfc_statement_label != NULL) |
| 3161 |
{ |
| 3162 |
new_st.op = EXEC_END_NESTED_BLOCK; |
| 3163 |
add_statement (); |
| 3164 |
} |
| 3165 |
break; |
| 3166 |
|
| 3167 |
/* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than |
| 3168 |
one parallel block. Thus, we add the special code to the nested block |
| 3169 |
itself, instead of the parent one. */ |
| 3170 |
case ST_END_BLOCK: |
| 3171 |
case ST_END_ASSOCIATE: |
| 3172 |
if (gfc_statement_label != NULL) |
| 3173 |
{ |
| 3174 |
new_st.op = EXEC_END_BLOCK; |
| 3175 |
add_statement (); |
| 3176 |
} |
| 3177 |
break; |
| 3178 |
|
| 3179 |
/* The end-of-program unit statements do not get the special |
| 3180 |
marker and require a statement of some sort if they are a |
| 3181 |
branch target. */ |
| 3182 |
|
| 3183 |
case ST_END_PROGRAM: |
| 3184 |
case ST_END_FUNCTION: |
| 3185 |
case ST_END_SUBROUTINE: |
| 3186 |
if (gfc_statement_label != NULL) |
| 3187 |
{ |
| 3188 |
new_st.op = EXEC_RETURN; |
| 3189 |
add_statement (); |
| 3190 |
} |
| 3191 |
else |
| 3192 |
{ |
| 3193 |
new_st.op = EXEC_END_PROCEDURE; |
| 3194 |
add_statement (); |
| 3195 |
} |
| 3196 |
|
| 3197 |
break; |
| 3198 |
|
| 3199 |
case ST_ENTRY: |
| 3200 |
case ST_OMP_METADIRECTIVE: |
| 3201 |
case ST_OMP_BEGIN_METADIRECTIVE: |
| 3202 |
case_executable: |
| 3203 |
case_exec_markers: |
| 3204 |
add_statement (); |
| 3205 |
break; |
| 3206 |
|
| 3207 |
default: |
| 3208 |
break; |
| 3209 |
} |
| 3210 |
|
| 3211 |
gfc_commit_symbols (); |
| 3212 |
gfc_warning_check (); |
| 3213 |
gfc_clear_new_st (); |
| 3214 |
} |
| 3215 |
|
| 3216 |
|
| 3217 |
/* Undo anything tentative that has been built for the current statement, |
| 3218 |
except if a gfc_charlen structure has been added to current namespace's |
| 3219 |
list of gfc_charlen structure. */ |
| 3220 |
|
| 3221 |
static void |
| 3222 |
reject_statement (void) |
| 3223 |
{ |
| 3224 |
gfc_free_equiv_until (gfc_current_ns->equiv, gfc_current_ns->old_equiv); |
| 3225 |
gfc_current_ns->equiv = gfc_current_ns->old_equiv; |
| 3226 |
gfc_drop_interface_elements_before (current_interface_ptr, |
| 3227 |
previous_interface_head); |
| 3228 |
|
| 3229 |
gfc_reject_data (gfc_current_ns); |
| 3230 |
|
| 3231 |
/* Don't queue use-association of a module if we reject the use statement. */ |
| 3232 |
gfc_restore_old_module_list (); |
| 3233 |
|
| 3234 |
gfc_new_block = NULL; |
| 3235 |
gfc_undo_symbols (); |
| 3236 |
gfc_clear_warning (); |
| 3237 |
undo_new_statement (); |
| 3238 |
} |
| 3239 |
|
| 3240 |
|
| 3241 |
/* Generic complaint about an out of order statement. We also do |
| 3242 |
whatever is necessary to clean up. */ |
| 3243 |
|
| 3244 |
static void |
| 3245 |
unexpected_statement (gfc_statement st) |
| 3246 |
{ |
| 3247 |
gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st)); |
| 3248 |
|
| 3249 |
reject_statement (); |
| 3250 |
} |
| 3251 |
|
| 3252 |
|
| 3253 |
/* Given the next statement seen by the matcher, make sure that it is |
| 3254 |
in proper order with the last. This subroutine is initialized by |
| 3255 |
calling it with an argument of ST_NONE. If there is a problem, we |
| 3256 |
issue an error and return false. Otherwise we return true. |
| 3257 |
|
| 3258 |
Individual parsers need to verify that the statements seen are |
| 3259 |
valid before calling here, i.e., ENTRY statements are not allowed in |
| 3260 |
INTERFACE blocks. The following diagram is taken from the standard: |
| 3261 |
|
| 3262 |
+---------------------------------------+ |
| 3263 |
| program subroutine function module | |
| 3264 |
+---------------------------------------+ |
| 3265 |
| use | |
| 3266 |
+---------------------------------------+ |
| 3267 |
| import | |
| 3268 |
+---------------------------------------+ |
| 3269 |
| | implicit none | |
| 3270 |
| +-----------+------------------+ |
| 3271 |
| | parameter | implicit | |
| 3272 |
| +-----------+------------------+ |
| 3273 |
| format | | derived type | |
| 3274 |
| entry | parameter | interface | |
| 3275 |
| | data | specification | |
| 3276 |
| | | statement func | |
| 3277 |
| +-----------+------------------+ |
| 3278 |
| | data | executable | |
| 3279 |
+--------+-----------+------------------+ |
| 3280 |
| contains | |
| 3281 |
+---------------------------------------+ |
| 3282 |
| internal module/subprogram | |
| 3283 |
+---------------------------------------+ |
| 3284 |
| end | |
| 3285 |
+---------------------------------------+ |
| 3286 |
|
| 3287 |
*/ |
| 3288 |
|
| 3289 |
enum state_order |
| 3290 |
{ |
| 3291 |
ORDER_START, |
| 3292 |
ORDER_USE, |
| 3293 |
ORDER_IMPORT, |
| 3294 |
ORDER_IMPLICIT_NONE, |
| 3295 |
ORDER_IMPLICIT, |
| 3296 |
ORDER_SPEC, |
| 3297 |
ORDER_EXEC |
| 3298 |
}; |
| 3299 |
|
| 3300 |
typedef struct |
| 3301 |
{ |
| 3302 |
enum state_order state; |
| 3303 |
gfc_statement last_statement; |
| 3304 |
locus where; |
| 3305 |
} |
| 3306 |
st_state; |
| 3307 |
|
| 3308 |
static bool |
| 3309 |
verify_st_order (st_state *p, gfc_statement st, bool silent) |
| 3310 |
{ |
| 3311 |
|
| 3312 |
switch (st) |
| 3313 |
{ |
| 3314 |
case ST_NONE: |
| 3315 |
p->state = ORDER_START; |
| 3316 |
in_exec_part = false; |
| 3317 |
break; |
| 3318 |
|
| 3319 |
case ST_USE: |
| 3320 |
if (p->state > ORDER_USE) |
| 3321 |
goto order; |
| 3322 |
p->state = ORDER_USE; |
| 3323 |
break; |
| 3324 |
|
| 3325 |
case ST_IMPORT: |
| 3326 |
if (p->state > ORDER_IMPORT) |
| 3327 |
goto order; |
| 3328 |
p->state = ORDER_IMPORT; |
| 3329 |
break; |
| 3330 |
|
| 3331 |
case ST_IMPLICIT_NONE: |
| 3332 |
if (p->state > ORDER_IMPLICIT) |
| 3333 |
goto order; |
| 3334 |
|
| 3335 |
/* The '>' sign cannot be a '>=', because a FORMAT or ENTRY |
| 3336 |
statement disqualifies a USE but not an IMPLICIT NONE. |
| 3337 |
Duplicate IMPLICIT NONEs are caught when the implicit types |
| 3338 |
are set. */ |
| 3339 |
|
| 3340 |
p->state = ORDER_IMPLICIT_NONE; |
| 3341 |
break; |
| 3342 |
|
| 3343 |
case ST_IMPLICIT: |
| 3344 |
if (p->state > ORDER_IMPLICIT) |
| 3345 |
goto order; |
| 3346 |
p->state = ORDER_IMPLICIT; |
| 3347 |
break; |
| 3348 |
|
| 3349 |
case ST_FORMAT: |
| 3350 |
case ST_ENTRY: |
| 3351 |
if (p->state < ORDER_IMPLICIT_NONE) |
| 3352 |
p->state = ORDER_IMPLICIT_NONE; |
| 3353 |
break; |
| 3354 |
|
| 3355 |
case ST_PARAMETER: |
| 3356 |
if (p->state >= ORDER_EXEC) |
| 3357 |
goto order; |
| 3358 |
if (p->state < ORDER_IMPLICIT) |
| 3359 |
p->state = ORDER_IMPLICIT; |
| 3360 |
break; |
| 3361 |
|
| 3362 |
case ST_DATA: |
| 3363 |
if (p->state < ORDER_SPEC) |
| 3364 |
p->state = ORDER_SPEC; |
| 3365 |
break; |
| 3366 |
|
| 3367 |
case ST_PUBLIC: |
| 3368 |
case ST_PRIVATE: |
| 3369 |
case ST_STRUCTURE_DECL: |
| 3370 |
case ST_DERIVED_DECL: |
| 3371 |
case_decl: |
| 3372 |
if (p->state >= ORDER_EXEC) |
| 3373 |
goto order; |
| 3374 |
if (p->state < ORDER_SPEC) |
| 3375 |
p->state = ORDER_SPEC; |
| 3376 |
break; |
| 3377 |
|
| 3378 |
case_omp_decl: |
| 3379 |
/* The OpenMP/OpenACC directives have to be somewhere in the specification |
| 3380 |
part, but there are no further requirements on their ordering. |
| 3381 |
Thus don't adjust p->state, just ignore them. */ |
| 3382 |
if (p->state >= ORDER_EXEC) |
| 3383 |
goto order; |
| 3384 |
break; |
| 3385 |
|
| 3386 |
case_executable: |
| 3387 |
case_exec_markers: |
| 3388 |
if (p->state < ORDER_EXEC) |
| 3389 |
p->state = ORDER_EXEC; |
| 3390 |
in_exec_part = true; |
| 3391 |
break; |
| 3392 |
|
| 3393 |
default: |
| 3394 |
return false; |
| 3395 |
} |
| 3396 |
|
| 3397 |
/* All is well, record the statement in case we need it next time. */ |
| 3398 |
p->where = gfc_current_locus; |
| 3399 |
p->last_statement = st; |
| 3400 |
return true; |
| 3401 |
|
| 3402 |
order: |
| 3403 |
if (!silent) |
| 3404 |
gfc_error ("%s statement at %C cannot follow %s statement at %L", |
| 3405 |
gfc_ascii_statement (st), |
| 3406 |
gfc_ascii_statement (p->last_statement), &p->where); |
| 3407 |
|
| 3408 |
return false; |
| 3409 |
} |
| 3410 |
|
| 3411 |
|
| 3412 |
/* Handle an unexpected end of file. This is a show-stopper... */ |
| 3413 |
|
| 3414 |
static void unexpected_eof (void) ATTRIBUTE_NORETURN; |
| 3415 |
|
| 3416 |
static void |
| 3417 |
unexpected_eof (void) |
| 3418 |
{ |
| 3419 |
gfc_state_data *p; |
| 3420 |
|
| 3421 |
gfc_error ("Unexpected end of file in %qs", gfc_source_file); |
| 3422 |
|
| 3423 |
/* Memory cleanup. Move to "second to last". */ |
| 3424 |
for (p = gfc_state_stack; p && p->previous && p->previous->previous; |
| 3425 |
p = p->previous); |
| 3426 |
|
| 3427 |
gfc_current_ns->code = (p && p->previous) ? p->head : NULL; |
| 3428 |
gfc_done_2 (); |
| 3429 |
|
| 3430 |
longjmp (eof_buf, 1); |
| 3431 |
|
| 3432 |
/* Avoids build error on systems where longjmp is not declared noreturn. */ |
| 3433 |
gcc_unreachable (); |
| 3434 |
} |
| 3435 |
|
| 3436 |
|
| 3437 |
/* Parse the CONTAINS section of a derived type definition. */ |
| 3438 |
|
| 3439 |
gfc_access gfc_typebound_default_access; |
| 3440 |
|
| 3441 |
static bool |
| 3442 |
parse_derived_contains (void) |
| 3443 |
{ |
| 3444 |
gfc_state_data s; |
| 3445 |
bool seen_private = false; |
| 3446 |
bool seen_comps = false; |
| 3447 |
bool error_flag = false; |
| 3448 |
bool to_finish; |
| 3449 |
|
| 3450 |
gcc_assert (gfc_current_state () == COMP_DERIVED); |
| 3451 |
gcc_assert (gfc_current_block ()); |
| 3452 |
|
| 3453 |
/* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS |
| 3454 |
section. */ |
| 3455 |
if (gfc_current_block ()->attr.sequence) |
| 3456 |
gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS" |
| 3457 |
" section at %C", gfc_current_block ()->name); |
| 3458 |
if (gfc_current_block ()->attr.is_bind_c) |
| 3459 |
gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS" |
| 3460 |
" section at %C", gfc_current_block ()->name); |
| 3461 |
|
| 3462 |
accept_statement (ST_CONTAINS); |
| 3463 |
push_state (&s, COMP_DERIVED_CONTAINS, NULL); |
| 3464 |
|
| 3465 |
gfc_typebound_default_access = ACCESS_PUBLIC; |
| 3466 |
|
| 3467 |
to_finish = false; |
| 3468 |
while (!to_finish) |
| 3469 |
{ |
| 3470 |
gfc_statement st; |
| 3471 |
st = next_statement (); |
| 3472 |
switch (st) |
| 3473 |
{ |
| 3474 |
case ST_NONE: |
| 3475 |
unexpected_eof (); |
| 3476 |
break; |
| 3477 |
|
| 3478 |
case ST_DATA_DECL: |
| 3479 |
gfc_error ("Components in TYPE at %C must precede CONTAINS"); |
| 3480 |
goto error; |
| 3481 |
|
| 3482 |
case ST_PROCEDURE: |
| 3483 |
if (!gfc_notify_std (GFC_STD_F2003, "Type-bound procedure at %C")) |
| 3484 |
goto error; |
| 3485 |
|
| 3486 |
accept_statement (ST_PROCEDURE); |
| 3487 |
seen_comps = true; |
| 3488 |
break; |
| 3489 |
|
| 3490 |
case ST_GENERIC: |
| 3491 |
if (!gfc_notify_std (GFC_STD_F2003, "GENERIC binding at %C")) |
| 3492 |
goto error; |
| 3493 |
|
| 3494 |
accept_statement (ST_GENERIC); |
| 3495 |
seen_comps = true; |
| 3496 |
break; |
| 3497 |
|
| 3498 |
case ST_FINAL: |
| 3499 |
if (!gfc_notify_std (GFC_STD_F2003, "FINAL procedure declaration" |
| 3500 |
" at %C")) |
| 3501 |
goto error; |
| 3502 |
|
| 3503 |
accept_statement (ST_FINAL); |
| 3504 |
seen_comps = true; |
| 3505 |
break; |
| 3506 |
|
| 3507 |
case ST_END_TYPE: |
| 3508 |
to_finish = true; |
| 3509 |
|
| 3510 |
if (!seen_comps |
| 3511 |
&& (!gfc_notify_std(GFC_STD_F2008, "Derived type definition " |
| 3512 |
"at %C with empty CONTAINS section"))) |
| 3513 |
goto error; |
| 3514 |
|
| 3515 |
/* ST_END_TYPE is accepted by parse_derived after return. */ |
| 3516 |
break; |
| 3517 |
|
| 3518 |
case ST_PRIVATE: |
| 3519 |
if (!gfc_find_state (COMP_MODULE)) |
| 3520 |
{ |
| 3521 |
gfc_error ("PRIVATE statement in TYPE at %C must be inside " |
| 3522 |
"a MODULE"); |
| 3523 |
goto error; |
| 3524 |
} |
| 3525 |
|
| 3526 |
if (seen_comps) |
| 3527 |
{ |
| 3528 |
gfc_error ("PRIVATE statement at %C must precede procedure" |
| 3529 |
" bindings"); |
| 3530 |
goto error; |
| 3531 |
} |
| 3532 |
|
| 3533 |
if (seen_private) |
| 3534 |
{ |
| 3535 |
gfc_error ("Duplicate PRIVATE statement at %C"); |
| 3536 |
goto error; |
| 3537 |
} |
| 3538 |
|
| 3539 |
accept_statement (ST_PRIVATE); |
| 3540 |
gfc_typebound_default_access = ACCESS_PRIVATE; |
| 3541 |
seen_private = true; |
| 3542 |
break; |
| 3543 |
|
| 3544 |
case ST_SEQUENCE: |
| 3545 |
gfc_error ("SEQUENCE statement at %C must precede CONTAINS"); |
| 3546 |
goto error; |
| 3547 |
|
| 3548 |
case ST_CONTAINS: |
| 3549 |
gfc_error ("Already inside a CONTAINS block at %C"); |
| 3550 |
goto error; |
| 3551 |
|
| 3552 |
default: |
| 3553 |
unexpected_statement (st); |
| 3554 |
break; |
| 3555 |
} |
| 3556 |
|
| 3557 |
continue; |
| 3558 |
|
| 3559 |
error: |
| 3560 |
error_flag = true; |
| 3561 |
reject_statement (); |
| 3562 |
} |
| 3563 |
|
| 3564 |
pop_state (); |
| 3565 |
gcc_assert (gfc_current_state () == COMP_DERIVED); |
| 3566 |
|
| 3567 |
return error_flag; |
| 3568 |
} |
| 3569 |
|
| 3570 |
|
| 3571 |
/* Set attributes for the parent symbol based on the attributes of a component |
| 3572 |
and raise errors if conflicting attributes are found for the component. */ |
| 3573 |
|
| 3574 |
static void |
| 3575 |
check_component (gfc_symbol *sym, gfc_component *c, gfc_component **lockp, |
| 3576 |
gfc_component **eventp) |
| 3577 |
{ |
| 3578 |
bool coarray, lock_type, event_type, allocatable, pointer; |
| 3579 |
coarray = lock_type = event_type = allocatable = pointer = false; |
| 3580 |
gfc_component *lock_comp = NULL, *event_comp = NULL; |
| 3581 |
|
| 3582 |
if (lockp) lock_comp = *lockp; |
| 3583 |
if (eventp) event_comp = *eventp; |
| 3584 |
|
| 3585 |
/* Look for allocatable components. */ |
| 3586 |
if (c->attr.allocatable |
| 3587 |
|| (c->ts.type == BT_CLASS && c->attr.class_ok |
| 3588 |
&& CLASS_DATA (c)->attr.allocatable) |
| 3589 |
|| (c->ts.type == BT_DERIVED && !c->attr.pointer |
| 3590 |
&& c->ts.u.derived->attr.alloc_comp)) |
| 3591 |
{ |
| 3592 |
allocatable = true; |
| 3593 |
sym->attr.alloc_comp = 1; |
| 3594 |
} |
| 3595 |
|
| 3596 |
/* Look for pointer components. */ |
| 3597 |
if (c->attr.pointer |
| 3598 |
|| (c->ts.type == BT_CLASS && c->attr.class_ok |
| 3599 |
&& CLASS_DATA (c)->attr.class_pointer) |
| 3600 |
|| (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.pointer_comp)) |
| 3601 |
{ |
| 3602 |
pointer = true; |
| 3603 |
sym->attr.pointer_comp = 1; |
| 3604 |
} |
| 3605 |
|
| 3606 |
/* Look for procedure pointer components. */ |
| 3607 |
if (c->attr.proc_pointer |
| 3608 |
|| (c->ts.type == BT_DERIVED |
| 3609 |
&& c->ts.u.derived->attr.proc_pointer_comp)) |
| 3610 |
sym->attr.proc_pointer_comp = 1; |
| 3611 |
|
| 3612 |
/* Looking for coarray components. */ |
| 3613 |
if (c->attr.codimension |
| 3614 |
|| (c->ts.type == BT_CLASS && c->attr.class_ok |
| 3615 |
&& CLASS_DATA (c)->attr.codimension)) |
| 3616 |
{ |
| 3617 |
coarray = true; |
| 3618 |
sym->attr.coarray_comp = 1; |
| 3619 |
} |
| 3620 |
|
| 3621 |
if (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.coarray_comp |
| 3622 |
&& !c->attr.pointer) |
| 3623 |
{ |
| 3624 |
coarray = true; |
| 3625 |
sym->attr.coarray_comp = 1; |
| 3626 |
} |
| 3627 |
|
| 3628 |
/* Looking for lock_type components. */ |
| 3629 |
if ((c->ts.type == BT_DERIVED |
| 3630 |
&& c->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV |
| 3631 |
&& c->ts.u.derived->intmod_sym_id == ISOFORTRAN_LOCK_TYPE) |
| 3632 |
|| (c->ts.type == BT_CLASS && c->attr.class_ok |
| 3633 |
&& CLASS_DATA (c)->ts.u.derived->from_intmod |
| 3634 |
== INTMOD_ISO_FORTRAN_ENV |
| 3635 |
&& CLASS_DATA (c)->ts.u.derived->intmod_sym_id |
| 3636 |
== ISOFORTRAN_LOCK_TYPE) |
| 3637 |
|| (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.lock_comp |
| 3638 |
&& !allocatable && !pointer)) |
| 3639 |
{ |
| 3640 |
lock_type = 1; |
| 3641 |
lock_comp = c; |
| 3642 |
sym->attr.lock_comp = 1; |
| 3643 |
} |
| 3644 |
|
| 3645 |
/* Looking for event_type components. */ |
| 3646 |
if ((c->ts.type == BT_DERIVED |
| 3647 |
&& c->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV |
| 3648 |
&& c->ts.u.derived->intmod_sym_id == ISOFORTRAN_EVENT_TYPE) |
| 3649 |
|| (c->ts.type == BT_CLASS && c->attr.class_ok |
| 3650 |
&& CLASS_DATA (c)->ts.u.derived->from_intmod |
| 3651 |
== INTMOD_ISO_FORTRAN_ENV |
| 3652 |
&& CLASS_DATA (c)->ts.u.derived->intmod_sym_id |
| 3653 |
== ISOFORTRAN_EVENT_TYPE) |
| 3654 |
|| (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.event_comp |
| 3655 |
&& !allocatable && !pointer)) |
| 3656 |
{ |
| 3657 |
event_type = 1; |
| 3658 |
event_comp = c; |
| 3659 |
sym->attr.event_comp = 1; |
| 3660 |
} |
| 3661 |
|
| 3662 |
/* Check for F2008, C1302 - and recall that pointers may not be coarrays |
| 3663 |
(5.3.14) and that subobjects of coarray are coarray themselves (2.4.7), |
| 3664 |
unless there are nondirect [allocatable or pointer] components |
| 3665 |
involved (cf. 1.3.33.1 and 1.3.33.3). */ |
| 3666 |
|
| 3667 |
if (pointer && !coarray && lock_type) |
| 3668 |
gfc_error ("Component %s at %L of type LOCK_TYPE must have a " |
| 3669 |
"codimension or be a subcomponent of a coarray, " |
| 3670 |
"which is not possible as the component has the " |
| 3671 |
"pointer attribute", c->name, &c->loc); |
| 3672 |
else if (pointer && !coarray && c->ts.type == BT_DERIVED |
| 3673 |
&& c->ts.u.derived->attr.lock_comp) |
| 3674 |
gfc_error ("Pointer component %s at %L has a noncoarray subcomponent " |
| 3675 |
"of type LOCK_TYPE, which must have a codimension or be a " |
| 3676 |
"subcomponent of a coarray", c->name, &c->loc); |
| 3677 |
|
| 3678 |
if (lock_type && allocatable && !coarray && c->ts.type == BT_DERIVED |
| 3679 |
&& c->ts.u.derived->attr.lock_comp) |
| 3680 |
gfc_error ("Allocatable component %s at %L must have a codimension as " |
| 3681 |
"it has a noncoarray subcomponent of type LOCK_TYPE", |
| 3682 |
c->name, &c->loc); |
| 3683 |
|
| 3684 |
if (sym->attr.coarray_comp && !coarray && lock_type) |
| 3685 |
gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with " |
| 3686 |
"subcomponent of type LOCK_TYPE must have a codimension or " |
| 3687 |
"be a subcomponent of a coarray. (Variables of type %s may " |
| 3688 |
"not have a codimension as already a coarray " |
| 3689 |
"subcomponent exists)", c->name, &c->loc, sym->name); |
| 3690 |
|
| 3691 |
if (sym->attr.lock_comp && coarray && !lock_type) |
| 3692 |
gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with " |
| 3693 |
"subcomponent of type LOCK_TYPE must have a codimension or " |
| 3694 |
"be a subcomponent of a coarray. (Variables of type %s may " |
| 3695 |
"not have a codimension as %s at %L has a codimension or a " |
| 3696 |
"coarray subcomponent)", lock_comp->name, &lock_comp->loc, |
| 3697 |
sym->name, c->name, &c->loc); |
| 3698 |
|
| 3699 |
/* Similarly for EVENT TYPE. */ |
| 3700 |
|
| 3701 |
if (pointer && !coarray && event_type) |
| 3702 |
gfc_error ("Component %s at %L of type EVENT_TYPE must have a " |
| 3703 |
"codimension or be a subcomponent of a coarray, " |
| 3704 |
"which is not possible as the component has the " |
| 3705 |
"pointer attribute", c->name, &c->loc); |
| 3706 |
else if (pointer && !coarray && c->ts.type == BT_DERIVED |
| 3707 |
&& c->ts.u.derived->attr.event_comp) |
| 3708 |
gfc_error ("Pointer component %s at %L has a noncoarray subcomponent " |
| 3709 |
"of type EVENT_TYPE, which must have a codimension or be a " |
| 3710 |
"subcomponent of a coarray", c->name, &c->loc); |
| 3711 |
|
| 3712 |
if (event_type && allocatable && !coarray) |
| 3713 |
gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have " |
| 3714 |
"a codimension", c->name, &c->loc); |
| 3715 |
else if (event_type && allocatable && c->ts.type == BT_DERIVED |
| 3716 |
&& c->ts.u.derived->attr.event_comp) |
| 3717 |
gfc_error ("Allocatable component %s at %L must have a codimension as " |
| 3718 |
"it has a noncoarray subcomponent of type EVENT_TYPE", |
| 3719 |
c->name, &c->loc); |
| 3720 |
|
| 3721 |
if (sym->attr.coarray_comp && !coarray && event_type) |
| 3722 |
gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with " |
| 3723 |
"subcomponent of type EVENT_TYPE must have a codimension or " |
| 3724 |
"be a subcomponent of a coarray. (Variables of type %s may " |
| 3725 |
"not have a codimension as already a coarray " |
| 3726 |
"subcomponent exists)", c->name, &c->loc, sym->name); |
| 3727 |
|
| 3728 |
if (sym->attr.event_comp && coarray && !event_type) |
| 3729 |
gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with " |
| 3730 |
"subcomponent of type EVENT_TYPE must have a codimension or " |
| 3731 |
"be a subcomponent of a coarray. (Variables of type %s may " |
| 3732 |
"not have a codimension as %s at %L has a codimension or a " |
| 3733 |
"coarray subcomponent)", event_comp->name, &event_comp->loc, |
| 3734 |
sym->name, c->name, &c->loc); |
| 3735 |
|
| 3736 |
/* Look for private components. */ |
| 3737 |
if (sym->component_access == ACCESS_PRIVATE |
| 3738 |
|| c->attr.access == ACCESS_PRIVATE |
| 3739 |
|| (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.private_comp)) |
| 3740 |
sym->attr.private_comp = 1; |
| 3741 |
|
| 3742 |
if (lockp) *lockp = lock_comp; |
| 3743 |
if (eventp) *eventp = event_comp; |
| 3744 |
} |
| 3745 |
|
| 3746 |
|
| 3747 |
static void parse_struct_map (gfc_statement); |
| 3748 |
|
| 3749 |
/* Parse a union component definition within a structure definition. */ |
| 3750 |
|
| 3751 |
static void |
| 3752 |
parse_union (void) |
| 3753 |
{ |
| 3754 |
int compiling; |
| 3755 |
gfc_statement st; |
| 3756 |
gfc_state_data s; |
| 3757 |
gfc_component *c, *lock_comp = NULL, *event_comp = NULL; |
| 3758 |
gfc_symbol *un; |
| 3759 |
|
| 3760 |
accept_statement(ST_UNION); |
| 3761 |
push_state (&s, COMP_UNION, gfc_new_block); |
| 3762 |
un = gfc_new_block; |
| 3763 |
|
| 3764 |
compiling = 1; |
| 3765 |
|
| 3766 |
while (compiling) |
| 3767 |
{ |
| 3768 |
st = next_statement (); |
| 3769 |
/* Only MAP declarations valid within a union. */ |
| 3770 |
switch (st) |
| 3771 |
{ |
| 3772 |
case ST_NONE: |
| 3773 |
unexpected_eof (); |
| 3774 |
|
| 3775 |
case ST_MAP: |
| 3776 |
accept_statement (ST_MAP); |
| 3777 |
parse_struct_map (ST_MAP); |
| 3778 |
/* Add a component to the union for each map. */ |
| 3779 |
if (!gfc_add_component (un, gfc_new_block->name, &c)) |
| 3780 |
{ |
| 3781 |
gfc_internal_error ("failed to create map component '%s'", |
| 3782 |
gfc_new_block->name); |
| 3783 |
reject_statement (); |
| 3784 |
return; |
| 3785 |
} |
| 3786 |
c->ts.type = BT_DERIVED; |
| 3787 |
c->ts.u.derived = gfc_new_block; |
| 3788 |
/* Normally components get their initialization expressions when they |
| 3789 |
are created in decl.cc (build_struct) so we can look through the |
| 3790 |
flat component list for initializers during resolution. Unions and |
| 3791 |
maps create components along with their type definitions so we |
| 3792 |
have to generate initializers here. */ |
| 3793 |
c->initializer = gfc_default_initializer (&c->ts); |
| 3794 |
break; |
| 3795 |
|
| 3796 |
case ST_END_UNION: |
| 3797 |
compiling = 0; |
| 3798 |
accept_statement (ST_END_UNION); |
| 3799 |
break; |
| 3800 |
|
| 3801 |
default: |
| 3802 |
unexpected_statement (st); |
| 3803 |
break; |
| 3804 |
} |
| 3805 |
} |
| 3806 |
|
| 3807 |
for (c = un->components; c; c = c->next) |
| 3808 |
check_component (un, c, &lock_comp, &event_comp); |
| 3809 |
|
| 3810 |
/* Add the union as a component in its parent structure. */ |
| 3811 |
pop_state (); |
| 3812 |
if (!gfc_add_component (gfc_current_block (), un->name, &c)) |
| 3813 |
{ |
| 3814 |
gfc_internal_error ("failed to create union component '%s'", un->name); |
| 3815 |
reject_statement (); |
| 3816 |
return; |
| 3817 |
} |
| 3818 |
c->ts.type = BT_UNION; |
| 3819 |
c->ts.u.derived = un; |
| 3820 |
c->initializer = gfc_default_initializer (&c->ts); |
| 3821 |
|
| 3822 |
un->attr.zero_comp = un->components == NULL; |
| 3823 |
} |
| 3824 |
|
| 3825 |
|
| 3826 |
/* Parse a STRUCTURE or MAP. */ |
| 3827 |
|
| 3828 |
static void |
| 3829 |
parse_struct_map (gfc_statement block) |
| 3830 |
{ |
| 3831 |
int compiling_type; |
| 3832 |
gfc_statement st; |
| 3833 |
gfc_state_data s; |
| 3834 |
gfc_symbol *sym; |
| 3835 |
gfc_component *c, *lock_comp = NULL, *event_comp = NULL; |
| 3836 |
gfc_compile_state comp; |
| 3837 |
gfc_statement ends; |
| 3838 |
|
| 3839 |
if (block == ST_STRUCTURE_DECL) |
| 3840 |
{ |
| 3841 |
comp = COMP_STRUCTURE; |
| 3842 |
ends = ST_END_STRUCTURE; |
| 3843 |
} |
| 3844 |
else |
| 3845 |
{ |
| 3846 |
gcc_assert (block == ST_MAP); |
| 3847 |
comp = COMP_MAP; |
| 3848 |
ends = ST_END_MAP; |
| 3849 |
} |
| 3850 |
|
| 3851 |
accept_statement(block); |
| 3852 |
push_state (&s, comp, gfc_new_block); |
| 3853 |
|
| 3854 |
gfc_new_block->component_access = ACCESS_PUBLIC; |
| 3855 |
compiling_type = 1; |
| 3856 |
|
| 3857 |
while (compiling_type) |
| 3858 |
{ |
| 3859 |
st = next_statement (); |
| 3860 |
switch (st) |
| 3861 |
{ |
| 3862 |
case ST_NONE: |
| 3863 |
unexpected_eof (); |
| 3864 |
|
| 3865 |
/* Nested structure declarations will be captured as ST_DATA_DECL. */ |
| 3866 |
case ST_STRUCTURE_DECL: |
| 3867 |
/* Let a more specific error make it to decode_statement(). */ |
| 3868 |
if (gfc_error_check () == 0) |
| 3869 |
gfc_error ("Syntax error in nested structure declaration at %C"); |
| 3870 |
reject_statement (); |
| 3871 |
/* Skip the rest of this statement. */ |
| 3872 |
gfc_error_recovery (); |
| 3873 |
break; |
| 3874 |
|
| 3875 |
case ST_UNION: |
| 3876 |
accept_statement (ST_UNION); |
| 3877 |
parse_union (); |
| 3878 |
break; |
| 3879 |
|
| 3880 |
case ST_DATA_DECL: |
| 3881 |
/* The data declaration was a nested/ad-hoc STRUCTURE field. */ |
| 3882 |
accept_statement (ST_DATA_DECL); |
| 3883 |
if (gfc_new_block && gfc_new_block != gfc_current_block () |
| 3884 |
&& gfc_new_block->attr.flavor == FL_STRUCT) |
| 3885 |
parse_struct_map (ST_STRUCTURE_DECL); |
| 3886 |
break; |
| 3887 |
|
| 3888 |
case ST_END_STRUCTURE: |
| 3889 |
case ST_END_MAP: |
| 3890 |
if (st == ends) |
| 3891 |
{ |
| 3892 |
accept_statement (st); |
| 3893 |
compiling_type = 0; |
| 3894 |
} |
| 3895 |
else |
| 3896 |
unexpected_statement (st); |
| 3897 |
break; |
| 3898 |
|
| 3899 |
default: |
| 3900 |
unexpected_statement (st); |
| 3901 |
break; |
| 3902 |
} |
| 3903 |
} |
| 3904 |
|
| 3905 |
/* Validate each component. */ |
| 3906 |
sym = gfc_current_block (); |
| 3907 |
for (c = sym->components; c; c = c->next) |
| 3908 |
check_component (sym, c, &lock_comp, &event_comp); |
| 3909 |
|
| 3910 |
sym->attr.zero_comp = (sym->components == NULL); |
| 3911 |
|
| 3912 |
/* Allow parse_union to find this structure to add to its list of maps. */ |
| 3913 |
if (block == ST_MAP) |
| 3914 |
gfc_new_block = gfc_current_block (); |
| 3915 |
|
| 3916 |
pop_state (); |
| 3917 |
} |
| 3918 |
|
| 3919 |
|
| 3920 |
/* Parse a derived type. */ |
| 3921 |
|
| 3922 |
static void |
| 3923 |
parse_derived (void) |
| 3924 |
{ |
| 3925 |
int compiling_type, seen_private, seen_sequence, seen_component; |
| 3926 |
gfc_statement st; |
| 3927 |
gfc_state_data s; |
| 3928 |
gfc_symbol *sym; |
| 3929 |
gfc_component *c, *lock_comp = NULL, *event_comp = NULL; |
| 3930 |
|
| 3931 |
accept_statement (ST_DERIVED_DECL); |
| 3932 |
push_state (&s, COMP_DERIVED, gfc_new_block); |
| 3933 |
|
| 3934 |
gfc_new_block->component_access = ACCESS_PUBLIC; |
| 3935 |
seen_private = 0; |
| 3936 |
seen_sequence = 0; |
| 3937 |
seen_component = 0; |
| 3938 |
|
| 3939 |
compiling_type = 1; |
| 3940 |
|
| 3941 |
while (compiling_type) |
| 3942 |
{ |
| 3943 |
st = next_statement (); |
| 3944 |
switch (st) |
| 3945 |
{ |
| 3946 |
case ST_NONE: |
| 3947 |
unexpected_eof (); |
| 3948 |
|
| 3949 |
case ST_DATA_DECL: |
| 3950 |
case ST_PROCEDURE: |
| 3951 |
accept_statement (st); |
| 3952 |
seen_component = 1; |
| 3953 |
break; |
| 3954 |
|
| 3955 |
case ST_FINAL: |
| 3956 |
gfc_error ("FINAL declaration at %C must be inside CONTAINS"); |
| 3957 |
break; |
| 3958 |
|
| 3959 |
case ST_END_TYPE: |
| 3960 |
endType: |
| 3961 |
compiling_type = 0; |
| 3962 |
|
| 3963 |
if (!seen_component) |
| 3964 |
gfc_notify_std (GFC_STD_F2003, "Derived type " |
| 3965 |
"definition at %C without components"); |
| 3966 |
|
| 3967 |
accept_statement (ST_END_TYPE); |
| 3968 |
break; |
| 3969 |
|
| 3970 |
case ST_PRIVATE: |
| 3971 |
if (!gfc_find_state (COMP_MODULE)) |
| 3972 |
{ |
| 3973 |
gfc_error ("PRIVATE statement in TYPE at %C must be inside " |
| 3974 |
"a MODULE"); |
| 3975 |
break; |
| 3976 |
} |
| 3977 |
|
| 3978 |
if (seen_component) |
| 3979 |
{ |
| 3980 |
gfc_error ("PRIVATE statement at %C must precede " |
| 3981 |
"structure components"); |
| 3982 |
break; |
| 3983 |
} |
| 3984 |
|
| 3985 |
if (seen_private) |
| 3986 |
gfc_error ("Duplicate PRIVATE statement at %C"); |
| 3987 |
|
| 3988 |
s.sym->component_access = ACCESS_PRIVATE; |
| 3989 |
|
| 3990 |
accept_statement (ST_PRIVATE); |
| 3991 |
seen_private = 1; |
| 3992 |
break; |
| 3993 |
|
| 3994 |
case ST_SEQUENCE: |
| 3995 |
if (seen_component) |
| 3996 |
{ |
| 3997 |
gfc_error ("SEQUENCE statement at %C must precede " |
| 3998 |
"structure components"); |
| 3999 |
break; |
| 4000 |
} |
| 4001 |
|
| 4002 |
if (gfc_current_block ()->attr.sequence) |
| 4003 |
gfc_warning (0, "SEQUENCE attribute at %C already specified in " |
| 4004 |
"TYPE statement"); |
| 4005 |
|
| 4006 |
if (seen_sequence) |
| 4007 |
{ |
| 4008 |
gfc_error ("Duplicate SEQUENCE statement at %C"); |
| 4009 |
} |
| 4010 |
|
| 4011 |
seen_sequence = 1; |
| 4012 |
gfc_add_sequence (&gfc_current_block ()->attr, |
| 4013 |
gfc_current_block ()->name, NULL); |
| 4014 |
break; |
| 4015 |
|
| 4016 |
case ST_CONTAINS: |
| 4017 |
gfc_notify_std (GFC_STD_F2003, |
| 4018 |
"CONTAINS block in derived type" |
| 4019 |
" definition at %C"); |
| 4020 |
|
| 4021 |
accept_statement (ST_CONTAINS); |
| 4022 |
parse_derived_contains (); |
| 4023 |
goto endType; |
| 4024 |
|
| 4025 |
default: |
| 4026 |
unexpected_statement (st); |
| 4027 |
break; |
| 4028 |
} |
| 4029 |
} |
| 4030 |
|
| 4031 |
/* need to verify that all fields of the derived type are |
| 4032 |
* interoperable with C if the type is declared to be bind(c) |
| 4033 |
*/ |
| 4034 |
sym = gfc_current_block (); |
| 4035 |
for (c = sym->components; c; c = c->next) |
| 4036 |
check_component (sym, c, &lock_comp, &event_comp); |
| 4037 |
|
| 4038 |
if (!seen_component) |
| 4039 |
sym->attr.zero_comp = 1; |
| 4040 |
|
| 4041 |
pop_state (); |
| 4042 |
} |
| 4043 |
|
| 4044 |
|
| 4045 |
/* Parse an ENUM. */ |
| 4046 |
|
| 4047 |
static void |
| 4048 |
parse_enum (void) |
| 4049 |
{ |
| 4050 |
gfc_statement st; |
| 4051 |
int compiling_enum; |
| 4052 |
gfc_state_data s; |
| 4053 |
int seen_enumerator = 0; |
| 4054 |
|
| 4055 |
push_state (&s, COMP_ENUM, gfc_new_block); |
| 4056 |
|
| 4057 |
compiling_enum = 1; |
| 4058 |
|
| 4059 |
while (compiling_enum) |
| 4060 |
{ |
| 4061 |
st = next_statement (); |
| 4062 |
switch (st) |
| 4063 |
{ |
| 4064 |
case ST_NONE: |
| 4065 |
unexpected_eof (); |
| 4066 |
break; |
| 4067 |
|
| 4068 |
case ST_ENUMERATOR: |
| 4069 |
seen_enumerator = 1; |
| 4070 |
accept_statement (st); |
| 4071 |
break; |
| 4072 |
|
| 4073 |
case ST_END_ENUM: |
| 4074 |
compiling_enum = 0; |
| 4075 |
if (!seen_enumerator) |
| 4076 |
gfc_error ("ENUM declaration at %C has no ENUMERATORS"); |
| 4077 |
accept_statement (st); |
| 4078 |
break; |
| 4079 |
|
| 4080 |
default: |
| 4081 |
gfc_free_enum_history (); |
| 4082 |
unexpected_statement (st); |
| 4083 |
break; |
| 4084 |
} |
| 4085 |
} |
| 4086 |
pop_state (); |
| 4087 |
} |
| 4088 |
|
| 4089 |
|
| 4090 |
/* Parse an interface. We must be able to deal with the possibility |
| 4091 |
of recursive interfaces. The parse_spec() subroutine is mutually |
| 4092 |
recursive with parse_interface(). */ |
| 4093 |
|
| 4094 |
static gfc_statement parse_spec (gfc_statement); |
| 4095 |
|
| 4096 |
static void |
| 4097 |
parse_interface (void) |
| 4098 |
{ |
| 4099 |
gfc_compile_state new_state = COMP_NONE, current_state; |
| 4100 |
gfc_symbol *prog_unit, *sym; |
| 4101 |
gfc_interface_info save; |
| 4102 |
gfc_state_data s1, s2; |
| 4103 |
gfc_statement st; |
| 4104 |
|
| 4105 |
accept_statement (ST_INTERFACE); |
| 4106 |
|
| 4107 |
current_interface.ns = gfc_current_ns; |
| 4108 |
save = current_interface; |
| 4109 |
|
| 4110 |
sym = (current_interface.type == INTERFACE_GENERIC |
| 4111 |
|| current_interface.type == INTERFACE_USER_OP) |
| 4112 |
? gfc_new_block : NULL; |
| 4113 |
|
| 4114 |
push_state (&s1, COMP_INTERFACE, sym); |
| 4115 |
current_state = COMP_NONE; |
| 4116 |
|
| 4117 |
loop: |
| 4118 |
gfc_current_ns = gfc_get_namespace (current_interface.ns, 0); |
| 4119 |
|
| 4120 |
st = next_statement (); |
| 4121 |
switch (st) |
| 4122 |
{ |
| 4123 |
case ST_NONE: |
| 4124 |
unexpected_eof (); |
| 4125 |
|
| 4126 |
case ST_SUBROUTINE: |
| 4127 |
case ST_FUNCTION: |
| 4128 |
if (st == ST_SUBROUTINE) |
| 4129 |
new_state = COMP_SUBROUTINE; |
| 4130 |
else if (st == ST_FUNCTION) |
| 4131 |
new_state = COMP_FUNCTION; |
| 4132 |
if (gfc_new_block->attr.pointer) |
| 4133 |
{ |
| 4134 |
gfc_new_block->attr.pointer = 0; |
| 4135 |
gfc_new_block->attr.proc_pointer = 1; |
| 4136 |
} |
| 4137 |
if (!gfc_add_explicit_interface (gfc_new_block, IFSRC_IFBODY, |
| 4138 |
gfc_new_block->formal, NULL)) |
| 4139 |
{ |
| 4140 |
reject_statement (); |
| 4141 |
gfc_free_namespace (gfc_current_ns); |
| 4142 |
goto loop; |
| 4143 |
} |
| 4144 |
/* F2008 C1210 forbids the IMPORT statement in module procedure |
| 4145 |
interface bodies and the flag is set to import symbols. */ |
| 4146 |
if (gfc_new_block->attr.module_procedure) |
| 4147 |
gfc_current_ns->has_import_set = 1; |
| 4148 |
break; |
| 4149 |
|
| 4150 |
case ST_PROCEDURE: |
| 4151 |
case ST_MODULE_PROC: /* The module procedure matcher makes |
| 4152 |
sure the context is correct. */ |
| 4153 |
accept_statement (st); |
| 4154 |
gfc_free_namespace (gfc_current_ns); |
| 4155 |
goto loop; |
| 4156 |
|
| 4157 |
case ST_END_INTERFACE: |
| 4158 |
gfc_free_namespace (gfc_current_ns); |
| 4159 |
gfc_current_ns = current_interface.ns; |
| 4160 |
goto done; |
| 4161 |
|
| 4162 |
default: |
| 4163 |
gfc_error ("Unexpected %s statement in INTERFACE block at %C", |
| 4164 |
gfc_ascii_statement (st)); |
| 4165 |
current_interface = save; |
| 4166 |
reject_statement (); |
| 4167 |
gfc_free_namespace (gfc_current_ns); |
| 4168 |
goto loop; |
| 4169 |
} |
| 4170 |
|
| 4171 |
|
| 4172 |
/* Make sure that the generic name has the right attribute. */ |
| 4173 |
if (current_interface.type == INTERFACE_GENERIC |
| 4174 |
&& current_state == COMP_NONE) |
| 4175 |
{ |
| 4176 |
if (new_state == COMP_FUNCTION && sym) |
| 4177 |
gfc_add_function (&sym->attr, sym->name, NULL); |
| 4178 |
else if (new_state == COMP_SUBROUTINE && sym) |
| 4179 |
gfc_add_subroutine (&sym->attr, sym->name, NULL); |
| 4180 |
|
| 4181 |
current_state = new_state; |
| 4182 |
} |
| 4183 |
|
| 4184 |
if (current_interface.type == INTERFACE_ABSTRACT) |
| 4185 |
{ |
| 4186 |
gfc_add_abstract (&gfc_new_block->attr, &gfc_current_locus); |
| 4187 |
if (gfc_is_intrinsic_typename (gfc_new_block->name)) |
| 4188 |
gfc_error ("Name %qs of ABSTRACT INTERFACE at %C " |
| 4189 |
"cannot be the same as an intrinsic type", |
| 4190 |
gfc_new_block->name); |
| 4191 |
} |
| 4192 |
|
| 4193 |
push_state (&s2, new_state, gfc_new_block); |
| 4194 |
accept_statement (st); |
| 4195 |
prog_unit = gfc_new_block; |
| 4196 |
prog_unit->formal_ns = gfc_current_ns; |
| 4197 |
|
| 4198 |
decl: |
| 4199 |
/* Read data declaration statements. */ |
| 4200 |
st = parse_spec (ST_NONE); |
| 4201 |
in_specification_block = true; |
| 4202 |
|
| 4203 |
/* Since the interface block does not permit an IMPLICIT statement, |
| 4204 |
the default type for the function or the result must be taken |
| 4205 |
from the formal namespace. */ |
| 4206 |
if (new_state == COMP_FUNCTION) |
| 4207 |
{ |
| 4208 |
if (prog_unit->result == prog_unit |
| 4209 |
&& prog_unit->ts.type == BT_UNKNOWN) |
| 4210 |
gfc_set_default_type (prog_unit, 1, prog_unit->formal_ns); |
| 4211 |
else if (prog_unit->result != prog_unit |
| 4212 |
&& prog_unit->result->ts.type == BT_UNKNOWN) |
| 4213 |
gfc_set_default_type (prog_unit->result, 1, |
| 4214 |
prog_unit->formal_ns); |
| 4215 |
} |
| 4216 |
|
| 4217 |
if (st != ST_END_SUBROUTINE && st != ST_END_FUNCTION) |
| 4218 |
{ |
| 4219 |
gfc_error ("Unexpected %s statement at %C in INTERFACE body", |
| 4220 |
gfc_ascii_statement (st)); |
| 4221 |
reject_statement (); |
| 4222 |
goto decl; |
| 4223 |
} |
| 4224 |
|
| 4225 |
/* Add EXTERNAL attribute to function or subroutine. */ |
| 4226 |
if (current_interface.type != INTERFACE_ABSTRACT && !prog_unit->attr.dummy) |
| 4227 |
gfc_add_external (&prog_unit->attr, &gfc_current_locus); |
| 4228 |
|
| 4229 |
current_interface = save; |
| 4230 |
gfc_add_interface (prog_unit); |
| 4231 |
pop_state (); |
| 4232 |
|
| 4233 |
if (current_interface.ns |
| 4234 |
&& current_interface.ns->proc_name |
| 4235 |
&& strcmp (current_interface.ns->proc_name->name, |
| 4236 |
prog_unit->name) == 0) |
| 4237 |
gfc_error ("INTERFACE procedure %qs at %L has the same name as the " |
| 4238 |
"enclosing procedure", prog_unit->name, |
| 4239 |
¤t_interface.ns->proc_name->declared_at); |
| 4240 |
|
| 4241 |
goto loop; |
| 4242 |
|
| 4243 |
done: |
| 4244 |
pop_state (); |
| 4245 |
} |
| 4246 |
|
| 4247 |
|
| 4248 |
/* Associate function characteristics by going back to the function |
| 4249 |
declaration and rematching the prefix. */ |
| 4250 |
|
| 4251 |
static match |
| 4252 |
match_deferred_characteristics (gfc_typespec * ts) |
| 4253 |
{ |
| 4254 |
locus loc; |
| 4255 |
match m = MATCH_ERROR; |
| 4256 |
char name[GFC_MAX_SYMBOL_LEN + 1]; |
| 4257 |
|
| 4258 |
loc = gfc_current_locus; |
| 4259 |
|
| 4260 |
gfc_current_locus = gfc_current_block ()->declared_at; |
| 4261 |
|
| 4262 |
gfc_clear_error (); |
| 4263 |
gfc_buffer_error (true); |
| 4264 |
m = gfc_match_prefix (ts); |
| 4265 |
gfc_buffer_error (false); |
| 4266 |
|
| 4267 |
if (ts->type == BT_DERIVED || ts->type == BT_CLASS) |
| 4268 |
{ |
| 4269 |
ts->kind = 0; |
| 4270 |
|
| 4271 |
if (!ts->u.derived) |
| 4272 |
m = MATCH_ERROR; |
| 4273 |
} |
| 4274 |
|
| 4275 |
/* Only permit one go at the characteristic association. */ |
| 4276 |
if (ts->kind == -1) |
| 4277 |
ts->kind = 0; |
| 4278 |
|
| 4279 |
/* Set the function locus correctly. If we have not found the |
| 4280 |
function name, there is an error. */ |
| 4281 |
if (m == MATCH_YES |
| 4282 |
&& gfc_match ("function% %n", name) == MATCH_YES |
| 4283 |
&& strcmp (name, gfc_current_block ()->name) == 0) |
| 4284 |
{ |
| 4285 |
gfc_current_block ()->declared_at = gfc_current_locus; |
| 4286 |
gfc_commit_symbols (); |
| 4287 |
} |
| 4288 |
else |
| 4289 |
{ |
| 4290 |
gfc_error_check (); |
| 4291 |
gfc_undo_symbols (); |
| 4292 |
} |
| 4293 |
|
| 4294 |
gfc_current_locus =loc; |
| 4295 |
return m; |
| 4296 |
} |
| 4297 |
|
| 4298 |
|
| 4299 |
/* Check specification-expressions in the function result of the currently |
| 4300 |
parsed block and ensure they are typed (give an IMPLICIT type if necessary). |
| 4301 |
For return types specified in a FUNCTION prefix, the IMPLICIT rules of the |
| 4302 |
scope are not yet parsed so this has to be delayed up to parse_spec. */ |
| 4303 |
|
| 4304 |
static bool |
| 4305 |
check_function_result_typed (void) |
| 4306 |
{ |
| 4307 |
gfc_typespec ts; |
| 4308 |
|
| 4309 |
gcc_assert (gfc_current_state () == COMP_FUNCTION); |
| 4310 |
|
| 4311 |
if (!gfc_current_ns->proc_name->result) |
| 4312 |
return true; |
| 4313 |
|
| 4314 |
ts = gfc_current_ns->proc_name->result->ts; |
| 4315 |
|
| 4316 |
/* Check type-parameters, at the moment only CHARACTER lengths possible. */ |
| 4317 |
/* TODO: Extend when KIND type parameters are implemented. */ |
| 4318 |
if (ts.type == BT_CHARACTER && ts.u.cl && ts.u.cl->length) |
| 4319 |
{ |
| 4320 |
/* Reject invalid type of specification expression for length. */ |
| 4321 |
if (ts.u.cl->length->ts.type != BT_INTEGER) |
| 4322 |
return false; |
| 4323 |
|
| 4324 |
gfc_expr_check_typed (ts.u.cl->length, gfc_current_ns, true); |
| 4325 |
} |
| 4326 |
|
| 4327 |
return true; |
| 4328 |
} |
| 4329 |
|
| 4330 |
|
| 4331 |
/* Parse a set of specification statements. Returns the statement |
| 4332 |
that doesn't fit. */ |
| 4333 |
|
| 4334 |
static gfc_statement |
| 4335 |
parse_spec (gfc_statement st) |
| 4336 |
{ |
| 4337 |
st_state ss; |
| 4338 |
bool function_result_typed = false; |
| 4339 |
bool bad_characteristic = false; |
| 4340 |
gfc_typespec *ts; |
| 4341 |
|
| 4342 |
in_specification_block = true; |
| 4343 |
|
| 4344 |
verify_st_order (&ss, ST_NONE, false); |
| 4345 |
if (st == ST_NONE) |
| 4346 |
st = next_statement (); |
| 4347 |
|
| 4348 |
/* If we are not inside a function or don't have a result specified so far, |
| 4349 |
do nothing special about it. */ |
| 4350 |
if (gfc_current_state () != COMP_FUNCTION) |
| 4351 |
function_result_typed = true; |
| 4352 |
else |
| 4353 |
{ |
| 4354 |
gfc_symbol* proc = gfc_current_ns->proc_name; |
| 4355 |
gcc_assert (proc); |
| 4356 |
|
| 4357 |
if (proc->result && proc->result->ts.type == BT_UNKNOWN) |
| 4358 |
function_result_typed = true; |
| 4359 |
} |
| 4360 |
|
| 4361 |
loop: |
| 4362 |
|
| 4363 |
/* If we're inside a BLOCK construct, some statements are disallowed. |
| 4364 |
Check this here. Attribute declaration statements like INTENT, OPTIONAL |
| 4365 |
or VALUE are also disallowed, but they don't have a particular ST_* |
| 4366 |
key so we have to check for them individually in their matcher routine. */ |
| 4367 |
if (gfc_current_state () == COMP_BLOCK) |
| 4368 |
switch (st) |
| 4369 |
{ |
| 4370 |
case ST_IMPLICIT: |
| 4371 |
case ST_IMPLICIT_NONE: |
| 4372 |
case ST_NAMELIST: |
| 4373 |
case ST_COMMON: |
| 4374 |
case ST_EQUIVALENCE: |
| 4375 |
case ST_STATEMENT_FUNCTION: |
| 4376 |
gfc_error ("%s statement is not allowed inside of BLOCK at %C", |
| 4377 |
gfc_ascii_statement (st)); |
| 4378 |
reject_statement (); |
| 4379 |
break; |
| 4380 |
|
| 4381 |
default: |
| 4382 |
break; |
| 4383 |
} |
| 4384 |
else if (gfc_current_state () == COMP_BLOCK_DATA) |
| 4385 |
/* Fortran 2008, C1116. */ |
| 4386 |
switch (st) |
| 4387 |
{ |
| 4388 |
case ST_ATTR_DECL: |
| 4389 |
case ST_COMMON: |
| 4390 |
case ST_DATA: |
| 4391 |
case ST_DATA_DECL: |
| 4392 |
case ST_DERIVED_DECL: |
| 4393 |
case ST_END_BLOCK_DATA: |
| 4394 |
case ST_EQUIVALENCE: |
| 4395 |
case ST_IMPLICIT: |
| 4396 |
case ST_IMPLICIT_NONE: |
| 4397 |
case ST_OMP_THREADPRIVATE: |
| 4398 |
case ST_PARAMETER: |
| 4399 |
case ST_STRUCTURE_DECL: |
| 4400 |
case ST_TYPE: |
| 4401 |
case ST_USE: |
| 4402 |
break; |
| 4403 |
|
| 4404 |
case ST_NONE: |
| 4405 |
break; |
| 4406 |
|
| 4407 |
default: |
| 4408 |
gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C", |
| 4409 |
gfc_ascii_statement (st)); |
| 4410 |
reject_statement (); |
| 4411 |
break; |
| 4412 |
} |
| 4413 |
|
| 4414 |
/* If we find a statement that cannot be followed by an IMPLICIT statement |
| 4415 |
(and thus we can expect to see none any further), type the function result |
| 4416 |
if it has not yet been typed. Be careful not to give the END statement |
| 4417 |
to verify_st_order! */ |
| 4418 |
if (!function_result_typed && st != ST_GET_FCN_CHARACTERISTICS) |
| 4419 |
{ |
| 4420 |
bool verify_now = false; |
| 4421 |
|
| 4422 |
if (st == ST_END_FUNCTION || st == ST_CONTAINS) |
| 4423 |
verify_now = true; |
| 4424 |
else |
| 4425 |
{ |
| 4426 |
st_state dummyss; |
| 4427 |
verify_st_order (&dummyss, ST_NONE, false); |
| 4428 |
verify_st_order (&dummyss, st, false); |
| 4429 |
|
| 4430 |
if (!verify_st_order (&dummyss, ST_IMPLICIT, true)) |
| 4431 |
verify_now = true; |
| 4432 |
} |
| 4433 |
|
| 4434 |
if (verify_now) |
| 4435 |
function_result_typed = check_function_result_typed (); |
| 4436 |
} |
| 4437 |
|
| 4438 |
switch (st) |
| 4439 |
{ |
| 4440 |
case ST_NONE: |
| 4441 |
unexpected_eof (); |
| 4442 |
|
| 4443 |
case ST_IMPLICIT_NONE: |
| 4444 |
case ST_IMPLICIT: |
| 4445 |
if (!function_result_typed) |
| 4446 |
function_result_typed = check_function_result_typed (); |
| 4447 |
goto declSt; |
| 4448 |
|
| 4449 |
case ST_FORMAT: |
| 4450 |
case ST_ENTRY: |
| 4451 |
case ST_DATA: /* Not allowed in interfaces */ |
| 4452 |
if (gfc_current_state () == COMP_INTERFACE) |
| 4453 |
break; |
| 4454 |
|
| 4455 |
/* Fall through */ |
| 4456 |
|
| 4457 |
case ST_USE: |
| 4458 |
case ST_IMPORT: |
| 4459 |
case ST_PARAMETER: |
| 4460 |
case ST_PUBLIC: |
| 4461 |
case ST_PRIVATE: |
| 4462 |
case ST_STRUCTURE_DECL: |
| 4463 |
case ST_DERIVED_DECL: |
| 4464 |
case_decl: |
| 4465 |
case_omp_decl: |
| 4466 |
declSt: |
| 4467 |
if (!verify_st_order (&ss, st, false)) |
| 4468 |
{ |
| 4469 |
reject_statement (); |
| 4470 |
st = next_statement (); |
| 4471 |
goto loop; |
| 4472 |
} |
| 4473 |
|
| 4474 |
switch (st) |
| 4475 |
{ |
| 4476 |
case ST_INTERFACE: |
| 4477 |
parse_interface (); |
| 4478 |
break; |
| 4479 |
|
| 4480 |
case ST_STRUCTURE_DECL: |
| 4481 |
parse_struct_map (ST_STRUCTURE_DECL); |
| 4482 |
break; |
| 4483 |
|
| 4484 |
case ST_DERIVED_DECL: |
| 4485 |
parse_derived (); |
| 4486 |
break; |
| 4487 |
|
| 4488 |
case ST_PUBLIC: |
| 4489 |
case ST_PRIVATE: |
| 4490 |
if (gfc_current_state () != COMP_MODULE) |
| 4491 |
{ |
| 4492 |
gfc_error ("%s statement must appear in a MODULE", |
| 4493 |
gfc_ascii_statement (st)); |
| 4494 |
reject_statement (); |
| 4495 |
break; |
| 4496 |
} |
| 4497 |
|
| 4498 |
if (gfc_current_ns->default_access != ACCESS_UNKNOWN) |
| 4499 |
{ |
| 4500 |
gfc_error ("%s statement at %C follows another accessibility " |
| 4501 |
"specification", gfc_ascii_statement (st)); |
| 4502 |
reject_statement (); |
| 4503 |
break; |
| 4504 |
} |
| 4505 |
|
| 4506 |
gfc_current_ns->default_access = (st == ST_PUBLIC) |
| 4507 |
? ACCESS_PUBLIC : ACCESS_PRIVATE; |
| 4508 |
|
| 4509 |
break; |
| 4510 |
|
| 4511 |
case ST_STATEMENT_FUNCTION: |
| 4512 |
if (gfc_current_state () == COMP_MODULE |
| 4513 |
|| gfc_current_state () == COMP_SUBMODULE) |
| 4514 |
{ |
| 4515 |
unexpected_statement (st); |
| 4516 |
break; |
| 4517 |
} |
| 4518 |
|
| 4519 |
default: |
| 4520 |
break; |
| 4521 |
} |
| 4522 |
|
| 4523 |
accept_statement (st); |
| 4524 |
st = next_statement (); |
| 4525 |
goto loop; |
| 4526 |
|
| 4527 |
case ST_ENUM: |
| 4528 |
accept_statement (st); |
| 4529 |
parse_enum(); |
| 4530 |
st = next_statement (); |
| 4531 |
goto loop; |
| 4532 |
|
| 4533 |
case ST_GET_FCN_CHARACTERISTICS: |
| 4534 |
/* This statement triggers the association of a function's result |
| 4535 |
characteristics. */ |
| 4536 |
ts = &gfc_current_block ()->result->ts; |
| 4537 |
if (match_deferred_characteristics (ts) != MATCH_YES) |
| 4538 |
bad_characteristic = true; |
| 4539 |
|
| 4540 |
st = next_statement (); |
| 4541 |
goto loop; |
| 4542 |
|
| 4543 |
default: |
| 4544 |
break; |
| 4545 |
} |
| 4546 |
|
| 4547 |
/* If match_deferred_characteristics failed, then there is an error. */ |
| 4548 |
if (bad_characteristic) |
| 4549 |
{ |
| 4550 |
ts = &gfc_current_block ()->result->ts; |
| 4551 |
if (ts->type != BT_DERIVED && ts->type != BT_CLASS) |
| 4552 |
gfc_error ("Bad kind expression for function %qs at %L", |
| 4553 |
gfc_current_block ()->name, |
| 4554 |
&gfc_current_block ()->declared_at); |
| 4555 |
else |
| 4556 |
gfc_error ("The type for function %qs at %L is not accessible", |
| 4557 |
gfc_current_block ()->name, |
| 4558 |
&gfc_current_block ()->declared_at); |
| 4559 |
|
| 4560 |
gfc_current_block ()->ts.kind = 0; |
| 4561 |
/* Keep the derived type; if it's bad, it will be discovered later. */ |
| 4562 |
if (!(ts->type == BT_DERIVED && ts->u.derived)) |
| 4563 |
ts->type = BT_UNKNOWN; |
| 4564 |
} |
| 4565 |
|
| 4566 |
in_specification_block = false; |
| 4567 |
|
| 4568 |
return st; |
| 4569 |
} |
| 4570 |
|
| 4571 |
|
| 4572 |
/* Parse a WHERE block, (not a simple WHERE statement). */ |
| 4573 |
|
| 4574 |
static void |
| 4575 |
parse_where_block (void) |
| 4576 |
{ |
| 4577 |
int seen_empty_else; |
| 4578 |
gfc_code *top, *d; |
| 4579 |
gfc_state_data s; |
| 4580 |
gfc_statement st; |
| 4581 |
|
| 4582 |
accept_statement (ST_WHERE_BLOCK); |
| 4583 |
top = gfc_state_stack->tail; |
| 4584 |
|
| 4585 |
push_state (&s, COMP_WHERE, gfc_new_block); |
| 4586 |
|
| 4587 |
d = add_statement (); |
| 4588 |
d->expr1 = top->expr1; |
| 4589 |
d->op = EXEC_WHERE; |
| 4590 |
|
| 4591 |
top->expr1 = NULL; |
| 4592 |
top->block = d; |
| 4593 |
|
| 4594 |
seen_empty_else = 0; |
| 4595 |
|
| 4596 |
do |
| 4597 |
{ |
| 4598 |
st = next_statement (); |
| 4599 |
switch (st) |
| 4600 |
{ |
| 4601 |
case ST_NONE: |
| 4602 |
unexpected_eof (); |
| 4603 |
|
| 4604 |
case ST_WHERE_BLOCK: |
| 4605 |
parse_where_block (); |
| 4606 |
break; |
| 4607 |
|
| 4608 |
case ST_ASSIGNMENT: |
| 4609 |
case ST_WHERE: |
| 4610 |
accept_statement (st); |
| 4611 |
break; |
| 4612 |
|
| 4613 |
case ST_ELSEWHERE: |
| 4614 |
if (seen_empty_else) |
| 4615 |
{ |
| 4616 |
gfc_error ("ELSEWHERE statement at %C follows previous " |
| 4617 |
"unmasked ELSEWHERE"); |
| 4618 |
reject_statement (); |
| 4619 |
break; |
| 4620 |
} |
| 4621 |
|
| 4622 |
if (new_st.expr1 == NULL) |
| 4623 |
seen_empty_else = 1; |
| 4624 |
|
| 4625 |
d = new_level (gfc_state_stack->head); |
| 4626 |
d->op = EXEC_WHERE; |
| 4627 |
d->expr1 = new_st.expr1; |
| 4628 |
|
| 4629 |
accept_statement (st); |
| 4630 |
|
| 4631 |
break; |
| 4632 |
|
| 4633 |
case ST_END_WHERE: |
| 4634 |
accept_statement (st); |
| 4635 |
break; |
| 4636 |
|
| 4637 |
default: |
| 4638 |
gfc_error ("Unexpected %s statement in WHERE block at %C", |
| 4639 |
gfc_ascii_statement (st)); |
| 4640 |
reject_statement (); |
| 4641 |
break; |
| 4642 |
} |
| 4643 |
} |
| 4644 |
while (st != ST_END_WHERE); |
| 4645 |
|
| 4646 |
pop_state (); |
| 4647 |
} |
| 4648 |
|
| 4649 |
|
| 4650 |
/* Parse a FORALL block (not a simple FORALL statement). */ |
| 4651 |
|
| 4652 |
static void |
| 4653 |
parse_forall_block (void) |
| 4654 |
{ |
| 4655 |
gfc_code *top, *d; |
| 4656 |
gfc_state_data s; |
| 4657 |
gfc_statement st; |
| 4658 |
|
| 4659 |
accept_statement (ST_FORALL_BLOCK); |
| 4660 |
top = gfc_state_stack->tail; |
| 4661 |
|
| 4662 |
push_state (&s, COMP_FORALL, gfc_new_block); |
| 4663 |
|
| 4664 |
d = add_statement (); |
| 4665 |
d->op = EXEC_FORALL; |
| 4666 |
top->block = d; |
| 4667 |
|
| 4668 |
do |
| 4669 |
{ |
| 4670 |
st = next_statement (); |
| 4671 |
switch (st) |
| 4672 |
{ |
| 4673 |
|
| 4674 |
case ST_ASSIGNMENT: |
| 4675 |
case ST_POINTER_ASSIGNMENT: |
| 4676 |
case ST_WHERE: |
| 4677 |
case ST_FORALL: |
| 4678 |
accept_statement (st); |
| 4679 |
break; |
| 4680 |
|
| 4681 |
case ST_WHERE_BLOCK: |
| 4682 |
parse_where_block (); |
| 4683 |
break; |
| 4684 |
|
| 4685 |
case ST_FORALL_BLOCK: |
| 4686 |
parse_forall_block (); |
| 4687 |
break; |
| 4688 |
|
| 4689 |
case ST_END_FORALL: |
| 4690 |
accept_statement (st); |
| 4691 |
break; |
| 4692 |
|
| 4693 |
case ST_NONE: |
| 4694 |
unexpected_eof (); |
| 4695 |
|
| 4696 |
default: |
| 4697 |
gfc_error ("Unexpected %s statement in FORALL block at %C", |
| 4698 |
gfc_ascii_statement (st)); |
| 4699 |
|
| 4700 |
reject_statement (); |
| 4701 |
break; |
| 4702 |
} |
| 4703 |
} |
| 4704 |
while (st != ST_END_FORALL); |
| 4705 |
|
| 4706 |
pop_state (); |
| 4707 |
} |
| 4708 |
|
| 4709 |
|
| 4710 |
static gfc_statement parse_executable (gfc_statement); |
| 4711 |
|
| 4712 |
/* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */ |
| 4713 |
|
| 4714 |
static void |
| 4715 |
parse_if_block (void) |
| 4716 |
{ |
| 4717 |
gfc_code *top, *d; |
| 4718 |
gfc_statement st; |
| 4719 |
locus else_locus; |
| 4720 |
gfc_state_data s; |
| 4721 |
int seen_else; |
| 4722 |
|
| 4723 |
seen_else = 0; |
| 4724 |
accept_statement (ST_IF_BLOCK); |
| 4725 |
|
| 4726 |
top = gfc_state_stack->tail; |
| 4727 |
push_state (&s, COMP_IF, gfc_new_block); |
| 4728 |
|
| 4729 |
new_st.op = EXEC_IF; |
| 4730 |
d = add_statement (); |
| 4731 |
|
| 4732 |
d->expr1 = top->expr1; |
| 4733 |
top->expr1 = NULL; |
| 4734 |
top->block = d; |
| 4735 |
|
| 4736 |
do |
| 4737 |
{ |
| 4738 |
st = parse_executable (ST_NONE); |
| 4739 |
|
| 4740 |
switch (st) |
| 4741 |
{ |
| 4742 |
case ST_NONE: |
| 4743 |
unexpected_eof (); |
| 4744 |
|
| 4745 |
case ST_ELSEIF: |
| 4746 |
if (seen_else) |
| 4747 |
{ |
| 4748 |
gfc_error ("ELSE IF statement at %C cannot follow ELSE " |
| 4749 |
"statement at %L", &else_locus); |
| 4750 |
|
| 4751 |
reject_statement (); |
| 4752 |
break; |
| 4753 |
} |
| 4754 |
|
| 4755 |
d = new_level (gfc_state_stack->head); |
| 4756 |
d->op = EXEC_IF; |
| 4757 |
d->expr1 = new_st.expr1; |
| 4758 |
|
| 4759 |
accept_statement (st); |
| 4760 |
|
| 4761 |
break; |
| 4762 |
|
| 4763 |
case ST_ELSE: |
| 4764 |
if (seen_else) |
| 4765 |
{ |
| 4766 |
gfc_error ("Duplicate ELSE statements at %L and %C", |
| 4767 |
&else_locus); |
| 4768 |
reject_statement (); |
| 4769 |
break; |
| 4770 |
} |
| 4771 |
|
| 4772 |
seen_else = 1; |
| 4773 |
else_locus = gfc_current_locus; |
| 4774 |
|
| 4775 |
d = new_level (gfc_state_stack->head); |
| 4776 |
d->op = EXEC_IF; |
| 4777 |
|
| 4778 |
accept_statement (st); |
| 4779 |
|
| 4780 |
break; |
| 4781 |
|
| 4782 |
case ST_ENDIF: |
| 4783 |
break; |
| 4784 |
|
| 4785 |
default: |
| 4786 |
unexpected_statement (st); |
| 4787 |
break; |
| 4788 |
} |
| 4789 |
} |
| 4790 |
while (st != ST_ENDIF); |
| 4791 |
|
| 4792 |
pop_state (); |
| 4793 |
accept_statement (st); |
| 4794 |
} |
| 4795 |
|
| 4796 |
|
| 4797 |
/* Parse a SELECT block. */ |
| 4798 |
|
| 4799 |
static void |
| 4800 |
parse_select_block (void) |
| 4801 |
{ |
| 4802 |
gfc_statement st; |
| 4803 |
gfc_code *cp; |
| 4804 |
gfc_state_data s; |
| 4805 |
|
| 4806 |
accept_statement (ST_SELECT_CASE); |
| 4807 |
|
| 4808 |
cp = gfc_state_stack->tail; |
| 4809 |
push_state (&s, COMP_SELECT, gfc_new_block); |
| 4810 |
|
| 4811 |
/* Make sure that the next statement is a CASE or END SELECT. */ |
| 4812 |
for (;;) |
| 4813 |
{ |
| 4814 |
st = next_statement (); |
| 4815 |
if (st == ST_NONE) |
| 4816 |
unexpected_eof (); |
| 4817 |
if (st == ST_END_SELECT) |
| 4818 |
{ |
| 4819 |
/* Empty SELECT CASE is OK. */ |
| 4820 |
accept_statement (st); |
| 4821 |
pop_state (); |
| 4822 |
return; |
| 4823 |
} |
| 4824 |
if (st == ST_CASE) |
| 4825 |
break; |
| 4826 |
|
| 4827 |
gfc_error ("Expected a CASE or END SELECT statement following SELECT " |
| 4828 |
"CASE at %C"); |
| 4829 |
|
| 4830 |
reject_statement (); |
| 4831 |
} |
| 4832 |
|
| 4833 |
/* At this point, we've got a nonempty select block. */ |
| 4834 |
cp = new_level (cp); |
| 4835 |
*cp = new_st; |
| 4836 |
|
| 4837 |
accept_statement (st); |
| 4838 |
|
| 4839 |
do |
| 4840 |
{ |
| 4841 |
st = parse_executable (ST_NONE); |
| 4842 |
switch (st) |
| 4843 |
{ |
| 4844 |
case ST_NONE: |
| 4845 |
unexpected_eof (); |
| 4846 |
|
| 4847 |
case ST_CASE: |
| 4848 |
cp = new_level (gfc_state_stack->head); |
| 4849 |
*cp = new_st; |
| 4850 |
gfc_clear_new_st (); |
| 4851 |
|
| 4852 |
accept_statement (st); |
| 4853 |
/* Fall through */ |
| 4854 |
|
| 4855 |
case ST_END_SELECT: |
| 4856 |
break; |
| 4857 |
|
| 4858 |
/* Can't have an executable statement because of |
| 4859 |
parse_executable(). */ |
| 4860 |
default: |
| 4861 |
unexpected_statement (st); |
| 4862 |
break; |
| 4863 |
} |
| 4864 |
} |
| 4865 |
while (st != ST_END_SELECT); |
| 4866 |
|
| 4867 |
pop_state (); |
| 4868 |
accept_statement (st); |
| 4869 |
} |
| 4870 |
|
| 4871 |
|
| 4872 |
/* Pop the current selector from the SELECT TYPE stack. */ |
| 4873 |
|
| 4874 |
static void |
| 4875 |
select_type_pop (void) |
| 4876 |
{ |
| 4877 |
gfc_select_type_stack *old = select_type_stack; |
| 4878 |
select_type_stack = old->prev; |
| 4879 |
free (old); |
| 4880 |
} |
| 4881 |
|
| 4882 |
|
| 4883 |
/* Parse a SELECT TYPE construct (F03:R821). */ |
| 4884 |
|
| 4885 |
static void |
| 4886 |
parse_select_type_block (void) |
| 4887 |
{ |
| 4888 |
gfc_statement st; |
| 4889 |
gfc_code *cp; |
| 4890 |
gfc_state_data s; |
| 4891 |
|
| 4892 |
gfc_current_ns = new_st.ext.block.ns; |
| 4893 |
accept_statement (ST_SELECT_TYPE); |
| 4894 |
|
| 4895 |
cp = gfc_state_stack->tail; |
| 4896 |
push_state (&s, COMP_SELECT_TYPE, gfc_new_block); |
| 4897 |
|
| 4898 |
/* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT |
| 4899 |
or END SELECT. */ |
| 4900 |
for (;;) |
| 4901 |
{ |
| 4902 |
st = next_statement (); |
| 4903 |
if (st == ST_NONE) |
| 4904 |
unexpected_eof (); |
| 4905 |
if (st == ST_END_SELECT) |
| 4906 |
/* Empty SELECT CASE is OK. */ |
| 4907 |
goto done; |
| 4908 |
if (st == ST_TYPE_IS || st == ST_CLASS_IS) |
| 4909 |
break; |
| 4910 |
|
| 4911 |
gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement " |
| 4912 |
"following SELECT TYPE at %C"); |
| 4913 |
|
| 4914 |
reject_statement (); |
| 4915 |
} |
| 4916 |
|
| 4917 |
/* At this point, we've got a nonempty select block. */ |
| 4918 |
cp = new_level (cp); |
| 4919 |
*cp = new_st; |
| 4920 |
|
| 4921 |
accept_statement (st); |
| 4922 |
|
| 4923 |
do |
| 4924 |
{ |
| 4925 |
st = parse_executable (ST_NONE); |
| 4926 |
switch (st) |
| 4927 |
{ |
| 4928 |
case ST_NONE: |
| 4929 |
unexpected_eof (); |
| 4930 |
|
| 4931 |
case ST_TYPE_IS: |
| 4932 |
case ST_CLASS_IS: |
| 4933 |
cp = new_level (gfc_state_stack->head); |
| 4934 |
*cp = new_st; |
| 4935 |
gfc_clear_new_st (); |
| 4936 |
|
| 4937 |
accept_statement (st); |
| 4938 |
/* Fall through */ |
| 4939 |
|
| 4940 |
case ST_END_SELECT: |
| 4941 |
break; |
| 4942 |
|
| 4943 |
/* Can't have an executable statement because of |
| 4944 |
parse_executable(). */ |
| 4945 |
default: |
| 4946 |
unexpected_statement (st); |
| 4947 |
break; |
| 4948 |
} |
| 4949 |
} |
| 4950 |
while (st != ST_END_SELECT); |
| 4951 |
|
| 4952 |
done: |
| 4953 |
pop_state (); |
| 4954 |
accept_statement (st); |
| 4955 |
gfc_current_ns = gfc_current_ns->parent; |
| 4956 |
select_type_pop (); |
| 4957 |
} |
| 4958 |
|
| 4959 |
|
| 4960 |
/* Parse a SELECT RANK construct. */ |
| 4961 |
|
| 4962 |
static void |
| 4963 |
parse_select_rank_block (void) |
| 4964 |
{ |
| 4965 |
gfc_statement st; |
| 4966 |
gfc_code *cp; |
| 4967 |
gfc_state_data s; |
| 4968 |
|
| 4969 |
gfc_current_ns = new_st.ext.block.ns; |
| 4970 |
accept_statement (ST_SELECT_RANK); |
| 4971 |
|
| 4972 |
cp = gfc_state_stack->tail; |
| 4973 |
push_state (&s, COMP_SELECT_RANK, gfc_new_block); |
| 4974 |
|
| 4975 |
/* Make sure that the next statement is a RANK IS or RANK DEFAULT. */ |
| 4976 |
for (;;) |
| 4977 |
{ |
| 4978 |
st = next_statement (); |
| 4979 |
if (st == ST_NONE) |
| 4980 |
unexpected_eof (); |
| 4981 |
if (st == ST_END_SELECT) |
| 4982 |
/* Empty SELECT CASE is OK. */ |
| 4983 |
goto done; |
| 4984 |
if (st == ST_RANK) |
| 4985 |
break; |
| 4986 |
|
| 4987 |
gfc_error ("Expected RANK or RANK DEFAULT " |
| 4988 |
"following SELECT RANK at %C"); |
| 4989 |
|
| 4990 |
reject_statement (); |
| 4991 |
} |
| 4992 |
|
| 4993 |
/* At this point, we've got a nonempty select block. */ |
| 4994 |
cp = new_level (cp); |
| 4995 |
*cp = new_st; |
| 4996 |
|
| 4997 |
accept_statement (st); |
| 4998 |
|
| 4999 |
do |
| 5000 |
{ |
| 5001 |
st = parse_executable (ST_NONE); |
| 5002 |
switch (st) |
| 5003 |
{ |
| 5004 |
case ST_NONE: |
| 5005 |
unexpected_eof (); |
| 5006 |
|
| 5007 |
case ST_RANK: |
| 5008 |
cp = new_level (gfc_state_stack->head); |
| 5009 |
*cp = new_st; |
| 5010 |
gfc_clear_new_st (); |
| 5011 |
|
| 5012 |
accept_statement (st); |
| 5013 |
/* Fall through */ |
| 5014 |
|
| 5015 |
case ST_END_SELECT: |
| 5016 |
break; |
| 5017 |
|
| 5018 |
/* Can't have an executable statement because of |
| 5019 |
parse_executable(). */ |
| 5020 |
default: |
| 5021 |
unexpected_statement (st); |
| 5022 |
break; |
| 5023 |
} |
| 5024 |
} |
| 5025 |
while (st != ST_END_SELECT); |
| 5026 |
|
| 5027 |
done: |
| 5028 |
pop_state (); |
| 5029 |
accept_statement (st); |
| 5030 |
gfc_current_ns = gfc_current_ns->parent; |
| 5031 |
select_type_pop (); |
| 5032 |
} |
| 5033 |
|
| 5034 |
|
| 5035 |
/* Given a symbol, make sure it is not an iteration variable for a DO |
| 5036 |
statement. This subroutine is called when the symbol is seen in a |
| 5037 |
context that causes it to become redefined. If the symbol is an |
| 5038 |
iterator, we generate an error message and return nonzero. */ |
| 5039 |
|
| 5040 |
bool |
| 5041 |
gfc_check_do_variable (gfc_symtree *st) |
| 5042 |
{ |
| 5043 |
gfc_state_data *s; |
| 5044 |
|
| 5045 |
if (!st) |
| 5046 |
return 0; |
| 5047 |
|
| 5048 |
for (s=gfc_state_stack; s; s = s->previous) |
| 5049 |
if (s->do_variable == st) |
| 5050 |
{ |
| 5051 |
gfc_error_now ("Variable %qs at %C cannot be redefined inside " |
| 5052 |
"loop beginning at %L", st->name, &s->head->loc); |
| 5053 |
return 1; |
| 5054 |
} |
| 5055 |
|
| 5056 |
return 0; |
| 5057 |
} |
| 5058 |
|
| 5059 |
|
| 5060 |
/* Checks to see if the current statement label closes an enddo. |
| 5061 |
Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues |
| 5062 |
an error) if it incorrectly closes an ENDDO. */ |
| 5063 |
|
| 5064 |
static int |
| 5065 |
check_do_closure (void) |
| 5066 |
{ |
| 5067 |
gfc_state_data *p; |
| 5068 |
|
| 5069 |
if (gfc_statement_label == NULL) |
| 5070 |
return 0; |
| 5071 |
|
| 5072 |
for (p = gfc_state_stack; p; p = p->previous) |
| 5073 |
if (p->state == COMP_DO || p->state == COMP_DO_CONCURRENT) |
| 5074 |
break; |
| 5075 |
|
| 5076 |
if (p == NULL) |
| 5077 |
return 0; /* No loops to close */ |
| 5078 |
|
| 5079 |
if (p->ext.end_do_label == gfc_statement_label) |
| 5080 |
{ |
| 5081 |
if (p == gfc_state_stack) |
| 5082 |
return 1; |
| 5083 |
|
| 5084 |
gfc_error ("End of nonblock DO statement at %C is within another block"); |
| 5085 |
return 2; |
| 5086 |
} |
| 5087 |
|
| 5088 |
/* At this point, the label doesn't terminate the innermost loop. |
| 5089 |
Make sure it doesn't terminate another one. */ |
| 5090 |
for (; p; p = p->previous) |
| 5091 |
if ((p->state == COMP_DO || p->state == COMP_DO_CONCURRENT) |
| 5092 |
&& p->ext.end_do_label == gfc_statement_label) |
| 5093 |
{ |
| 5094 |
gfc_error ("End of nonblock DO statement at %C is interwoven " |
| 5095 |
"with another DO loop"); |
| 5096 |
return 2; |
| 5097 |
} |
| 5098 |
|
| 5099 |
return 0; |
| 5100 |
} |
| 5101 |
|
| 5102 |
|
| 5103 |
/* Parse a series of contained program units. */ |
| 5104 |
|
| 5105 |
static void parse_progunit (gfc_statement); |
| 5106 |
|
| 5107 |
|
| 5108 |
/* Parse a CRITICAL block. */ |
| 5109 |
|
| 5110 |
static void |
| 5111 |
parse_critical_block (void) |
| 5112 |
{ |
| 5113 |
gfc_code *top, *d; |
| 5114 |
gfc_state_data s, *sd; |
| 5115 |
gfc_statement st; |
| 5116 |
|
| 5117 |
for (sd = gfc_state_stack; sd; sd = sd->previous) |
| 5118 |
if (sd->state == COMP_OMP_STRUCTURED_BLOCK) |
| 5119 |
gfc_error_now (is_oacc (sd) |
| 5120 |
? G_("CRITICAL block inside of OpenACC region at %C") |
| 5121 |
: G_("CRITICAL block inside of OpenMP region at %C")); |
| 5122 |
|
| 5123 |
s.ext.end_do_label = new_st.label1; |
| 5124 |
|
| 5125 |
accept_statement (ST_CRITICAL); |
| 5126 |
top = gfc_state_stack->tail; |
| 5127 |
|
| 5128 |
push_state (&s, COMP_CRITICAL, gfc_new_block); |
| 5129 |
|
| 5130 |
d = add_statement (); |
| 5131 |
d->op = EXEC_CRITICAL; |
| 5132 |
top->block = d; |
| 5133 |
|
| 5134 |
do |
| 5135 |
{ |
| 5136 |
st = parse_executable (ST_NONE); |
| 5137 |
|
| 5138 |
switch (st) |
| 5139 |
{ |
| 5140 |
case ST_NONE: |
| 5141 |
unexpected_eof (); |
| 5142 |
break; |
| 5143 |
|
| 5144 |
case ST_END_CRITICAL: |
| 5145 |
if (s.ext.end_do_label != NULL |
| 5146 |
&& s.ext.end_do_label != gfc_statement_label) |
| 5147 |
gfc_error_now ("Statement label in END CRITICAL at %C does not " |
| 5148 |
"match CRITICAL label"); |
| 5149 |
|
| 5150 |
if (gfc_statement_label != NULL) |
| 5151 |
{ |
| 5152 |
new_st.op = EXEC_NOP; |
| 5153 |
add_statement (); |
| 5154 |
} |
| 5155 |
break; |
| 5156 |
|
| 5157 |
default: |
| 5158 |
unexpected_statement (st); |
| 5159 |
break; |
| 5160 |
} |
| 5161 |
} |
| 5162 |
while (st != ST_END_CRITICAL); |
| 5163 |
|
| 5164 |
pop_state (); |
| 5165 |
accept_statement (st); |
| 5166 |
} |
| 5167 |
|
| 5168 |
|
| 5169 |
/* Set up the local namespace for a BLOCK construct. */ |
| 5170 |
|
| 5171 |
gfc_namespace* |
| 5172 |
gfc_build_block_ns (gfc_namespace *parent_ns) |
| 5173 |
{ |
| 5174 |
gfc_namespace* my_ns; |
| 5175 |
static int numblock = 1; |
| 5176 |
|
| 5177 |
my_ns = gfc_get_namespace (parent_ns, 1); |
| 5178 |
my_ns->construct_entities = 1; |
| 5179 |
|
| 5180 |
/* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct |
| 5181 |
code generation (so it must not be NULL). |
| 5182 |
We set its recursive argument if our container procedure is recursive, so |
| 5183 |
that local variables are accordingly placed on the stack when it |
| 5184 |
will be necessary. */ |
| 5185 |
if (gfc_new_block) |
| 5186 |
my_ns->proc_name = gfc_new_block; |
| 5187 |
else |
| 5188 |
{ |
| 5189 |
bool t; |
| 5190 |
char buffer[20]; /* Enough to hold "block@2147483648\n". */ |
| 5191 |
|
| 5192 |
snprintf(buffer, sizeof(buffer), "block@%d", numblock++); |
| 5193 |
gfc_get_symbol (buffer, my_ns, &my_ns->proc_name); |
| 5194 |
t = gfc_add_flavor (&my_ns->proc_name->attr, FL_LABEL, |
| 5195 |
my_ns->proc_name->name, NULL); |
| 5196 |
gcc_assert (t); |
| 5197 |
gfc_commit_symbol (my_ns->proc_name); |
| 5198 |
} |
| 5199 |
|
| 5200 |
if (parent_ns->proc_name) |
| 5201 |
my_ns->proc_name->attr.recursive = parent_ns->proc_name->attr.recursive; |
| 5202 |
|
| 5203 |
return my_ns; |
| 5204 |
} |
| 5205 |
|
| 5206 |
|
| 5207 |
/* Parse a BLOCK construct. */ |
| 5208 |
|
| 5209 |
static void |
| 5210 |
parse_block_construct (void) |
| 5211 |
{ |
| 5212 |
gfc_namespace* my_ns; |
| 5213 |
gfc_namespace* my_parent; |
| 5214 |
gfc_state_data s; |
| 5215 |
|
| 5216 |
gfc_notify_std (GFC_STD_F2008, "BLOCK construct at %C"); |
| 5217 |
|
| 5218 |
my_ns = gfc_build_block_ns (gfc_current_ns); |
| 5219 |
|
| 5220 |
new_st.op = EXEC_BLOCK; |
| 5221 |
new_st.ext.block.ns = my_ns; |
| 5222 |
new_st.ext.block.assoc = NULL; |
| 5223 |
accept_statement (ST_BLOCK); |
| 5224 |
|
| 5225 |
push_state (&s, COMP_BLOCK, my_ns->proc_name); |
| 5226 |
gfc_current_ns = my_ns; |
| 5227 |
my_parent = my_ns->parent; |
| 5228 |
|
| 5229 |
parse_progunit (ST_NONE); |
| 5230 |
|
| 5231 |
/* Don't depend on the value of gfc_current_ns; it might have been |
| 5232 |
reset if the block had errors and was cleaned up. */ |
| 5233 |
gfc_current_ns = my_parent; |
| 5234 |
|
| 5235 |
pop_state (); |
| 5236 |
} |
| 5237 |
|
| 5238 |
|
| 5239 |
/* Parse an ASSOCIATE construct. This is essentially a BLOCK construct |
| 5240 |
behind the scenes with compiler-generated variables. */ |
| 5241 |
|
| 5242 |
static void |
| 5243 |
parse_associate (void) |
| 5244 |
{ |
| 5245 |
gfc_namespace* my_ns; |
| 5246 |
gfc_state_data s; |
| 5247 |
gfc_statement st; |
| 5248 |
gfc_association_list* a; |
| 5249 |
gfc_array_spec *as; |
| 5250 |
|
| 5251 |
gfc_notify_std (GFC_STD_F2003, "ASSOCIATE construct at %C"); |
| 5252 |
|
| 5253 |
my_ns = gfc_build_block_ns (gfc_current_ns); |
| 5254 |
|
| 5255 |
new_st.op = EXEC_BLOCK; |
| 5256 |
new_st.ext.block.ns = my_ns; |
| 5257 |
gcc_assert (new_st.ext.block.assoc); |
| 5258 |
|
| 5259 |
/* Add all associate-names as BLOCK variables. Creating them is enough |
| 5260 |
for now, they'll get their values during trans-* phase. */ |
| 5261 |
gfc_current_ns = my_ns; |
| 5262 |
for (a = new_st.ext.block.assoc; a; a = a->next) |
| 5263 |
{ |
| 5264 |
gfc_symbol *sym, *tsym; |
| 5265 |
gfc_expr *target; |
| 5266 |
int rank, corank; |
| 5267 |
|
| 5268 |
if (gfc_get_sym_tree (a->name, NULL, &a->st, false)) |
| 5269 |
gcc_unreachable (); |
| 5270 |
|
| 5271 |
sym = a->st->n.sym; |
| 5272 |
sym->attr.flavor = FL_VARIABLE; |
| 5273 |
sym->assoc = a; |
| 5274 |
sym->declared_at = a->where; |
| 5275 |
gfc_set_sym_referenced (sym); |
| 5276 |
|
| 5277 |
/* If the selector is a inferred type then the associate_name had better |
| 5278 |
be as well. Use array references, if present, to identify it as an |
| 5279 |
array. */ |
| 5280 |
if (IS_INFERRED_TYPE (a->target)) |
| 5281 |
{ |
| 5282 |
sym->assoc->inferred_type = 1; |
| 5283 |
for (gfc_ref *r = a->target->ref; r; r = r->next) |
| 5284 |
if (r->type == REF_ARRAY) |
| 5285 |
sym->attr.dimension = 1; |
| 5286 |
} |
| 5287 |
|
| 5288 |
/* Initialize the typespec. It is not available in all cases, |
| 5289 |
however, as it may only be set on the target during resolution. |
| 5290 |
Still, sometimes it helps to have it right now -- especially |
| 5291 |
for parsing component references on the associate-name |
| 5292 |
in case of association to a derived-type. */ |
| 5293 |
sym->ts = a->target->ts; |
| 5294 |
target = a->target; |
| 5295 |
|
| 5296 |
/* Don’t share the character length information between associate |
| 5297 |
variable and target if the length is not a compile-time constant, |
| 5298 |
as we don’t want to touch some other character length variable when |
| 5299 |
we try to initialize the associate variable’s character length |
| 5300 |
variable. |
| 5301 |
We do it here rather than later so that expressions referencing the |
| 5302 |
associate variable will automatically have the correctly setup length |
| 5303 |
information. If we did it at resolution stage the expressions would |
| 5304 |
use the original length information, and the variable a new different |
| 5305 |
one, but only the latter one would be correctly initialized at |
| 5306 |
translation stage, and the former one would need some additional setup |
| 5307 |
there. */ |
| 5308 |
if (sym->ts.type == BT_CHARACTER |
| 5309 |
&& sym->ts.u.cl |
| 5310 |
&& !(sym->ts.u.cl->length |
| 5311 |
&& sym->ts.u.cl->length->expr_type == EXPR_CONSTANT)) |
| 5312 |
sym->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); |
| 5313 |
|
| 5314 |
/* If the function has been parsed, go straight to the result to |
| 5315 |
obtain the expression rank. */ |
| 5316 |
if (target->expr_type == EXPR_FUNCTION |
| 5317 |
&& target->symtree |
| 5318 |
&& target->symtree->n.sym) |
| 5319 |
{ |
| 5320 |
tsym = target->symtree->n.sym; |
| 5321 |
if (!tsym->result) |
| 5322 |
tsym->result = tsym; |
| 5323 |
sym->ts = tsym->result->ts; |
| 5324 |
if (sym->ts.type == BT_CLASS) |
| 5325 |
{ |
| 5326 |
if (CLASS_DATA (sym)->as) |
| 5327 |
{ |
| 5328 |
target->rank = CLASS_DATA (sym)->as->rank; |
| 5329 |
target->corank = CLASS_DATA (sym)->as->corank; |
| 5330 |
} |
| 5331 |
sym->attr.class_ok = 1; |
| 5332 |
} |
| 5333 |
else |
| 5334 |
{ |
| 5335 |
target->rank = tsym->result->as ? tsym->result->as->rank : 0; |
| 5336 |
target->corank = tsym->result->as ? tsym->result->as->corank : 0; |
| 5337 |
} |
| 5338 |
} |
| 5339 |
|
| 5340 |
/* Check if the target expression is array valued. This cannot be done |
| 5341 |
by calling gfc_resolve_expr because the context is unavailable. |
| 5342 |
However, the references can be resolved and the rank of the target |
| 5343 |
expression set. */ |
| 5344 |
if (!sym->assoc->inferred_type |
| 5345 |
&& target->ref && gfc_resolve_ref (target) |
| 5346 |
&& target->expr_type != EXPR_ARRAY |
| 5347 |
&& target->expr_type != EXPR_COMPCALL) |
| 5348 |
gfc_expression_rank (target); |
| 5349 |
|
| 5350 |
/* Determine whether or not function expressions with unknown type are |
| 5351 |
structure constructors. If so, the function result can be converted |
| 5352 |
to be a derived type. */ |
| 5353 |
if (target->expr_type == EXPR_FUNCTION |
| 5354 |
&& target->ts.type == BT_UNKNOWN) |
| 5355 |
{ |
| 5356 |
gfc_symbol *derived; |
| 5357 |
/* The derived type has a leading uppercase character. */ |
| 5358 |
gfc_find_symbol (gfc_dt_upper_string (target->symtree->name), |
| 5359 |
my_ns->parent, 1, &derived); |
| 5360 |
if (derived && derived->attr.flavor == FL_DERIVED) |
| 5361 |
{ |
| 5362 |
sym->ts.type = BT_DERIVED; |
| 5363 |
sym->ts.u.derived = derived; |
| 5364 |
sym->assoc->inferred_type = 0; |
| 5365 |
} |
| 5366 |
} |
| 5367 |
|
| 5368 |
rank = target->rank; |
| 5369 |
corank = target->corank; |
| 5370 |
/* Fixup cases where the ranks are mismatched. */ |
| 5371 |
if (sym->ts.type == BT_CLASS && CLASS_DATA (sym)) |
| 5372 |
{ |
| 5373 |
if ((!CLASS_DATA (sym)->as && (rank != 0 || corank != 0)) |
| 5374 |
|| (CLASS_DATA (sym)->as |
| 5375 |
&& (CLASS_DATA (sym)->as->rank != rank |
| 5376 |
|| CLASS_DATA (sym)->as->corank != corank)) |
| 5377 |
|| rank == -1) |
| 5378 |
{ |
| 5379 |
/* Don't just (re-)set the attr and as in the sym.ts, |
| 5380 |
because this modifies the target's attr and as. Copy the |
| 5381 |
data and do a build_class_symbol. */ |
| 5382 |
symbol_attribute attr = CLASS_DATA (target)->attr; |
| 5383 |
gfc_typespec type; |
| 5384 |
if (rank == -1 && a->ar) |
| 5385 |
{ |
| 5386 |
as = gfc_get_array_spec (); |
| 5387 |
as->rank = a->ar->dimen; |
| 5388 |
as->corank = 0; |
| 5389 |
as->type = AS_DEFERRED; |
| 5390 |
attr.dimension = rank ? 1 : 0; |
| 5391 |
attr.codimension = as->corank ? 1 : 0; |
| 5392 |
sym->assoc->variable = true; |
| 5393 |
} |
| 5394 |
else if (rank || corank) |
| 5395 |
{ |
| 5396 |
as = gfc_get_array_spec (); |
| 5397 |
as->type = AS_DEFERRED; |
| 5398 |
as->rank = rank; |
| 5399 |
as->corank = corank; |
| 5400 |
attr.dimension = rank ? 1 : 0; |
| 5401 |
attr.codimension = corank ? 1 : 0; |
| 5402 |
} |
| 5403 |
else |
| 5404 |
{ |
| 5405 |
as = NULL; |
| 5406 |
attr.dimension = attr.codimension = 0; |
| 5407 |
} |
| 5408 |
attr.class_ok = 0; |
| 5409 |
attr.associate_var = 1; |
| 5410 |
type = CLASS_DATA (sym)->ts; |
| 5411 |
if (!gfc_build_class_symbol (&type, &attr, &as)) |
| 5412 |
gcc_unreachable (); |
| 5413 |
sym->ts = type; |
| 5414 |
sym->ts.type = BT_CLASS; |
| 5415 |
sym->attr.class_ok = 1; |
| 5416 |
} |
| 5417 |
else |
| 5418 |
sym->attr.class_ok = 1; |
| 5419 |
} |
| 5420 |
else if (rank == -1 && a->ar) |
| 5421 |
{ |
| 5422 |
sym->as = gfc_get_array_spec (); |
| 5423 |
sym->as->rank = a->ar->dimen; |
| 5424 |
sym->as->corank = a->ar->codimen; |
| 5425 |
sym->as->type = AS_DEFERRED; |
| 5426 |
sym->attr.dimension = 1; |
| 5427 |
sym->attr.codimension = sym->as->corank ? 1 : 0; |
| 5428 |
sym->attr.pointer = 1; |
| 5429 |
} |
| 5430 |
else if ((!sym->as && (rank != 0 || corank != 0)) |
| 5431 |
|| (sym->as |
| 5432 |
&& (sym->as->rank != rank || sym->as->corank != corank))) |
| 5433 |
{ |
| 5434 |
as = gfc_get_array_spec (); |
| 5435 |
as->type = AS_DEFERRED; |
| 5436 |
as->rank = rank; |
| 5437 |
as->corank = corank; |
| 5438 |
sym->as = as; |
| 5439 |
if (rank) |
| 5440 |
sym->attr.dimension = 1; |
| 5441 |
if (corank) |
| 5442 |
{ |
| 5443 |
as->cotype = AS_ASSUMED_SHAPE; |
| 5444 |
sym->attr.codimension = 1; |
| 5445 |
} |
| 5446 |
} |
| 5447 |
gfc_commit_symbols (); |
| 5448 |
} |
| 5449 |
|
| 5450 |
accept_statement (ST_ASSOCIATE); |
| 5451 |
push_state (&s, COMP_ASSOCIATE, my_ns->proc_name); |
| 5452 |
|
| 5453 |
loop: |
| 5454 |
st = parse_executable (ST_NONE); |
| 5455 |
switch (st) |
| 5456 |
{ |
| 5457 |
case ST_NONE: |
| 5458 |
unexpected_eof (); |
| 5459 |
|
| 5460 |
case_end: |
| 5461 |
accept_statement (st); |
| 5462 |
my_ns->code = gfc_state_stack->head; |
| 5463 |
break; |
| 5464 |
|
| 5465 |
default: |
| 5466 |
unexpected_statement (st); |
| 5467 |
goto loop; |
| 5468 |
} |
| 5469 |
|
| 5470 |
gfc_current_ns = gfc_current_ns->parent; |
| 5471 |
pop_state (); |
| 5472 |
} |
| 5473 |
|
| 5474 |
|
| 5475 |
/* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are |
| 5476 |
handled inside of parse_executable(), because they aren't really |
| 5477 |
loop statements. */ |
| 5478 |
|
| 5479 |
static void |
| 5480 |
parse_do_block (void) |
| 5481 |
{ |
| 5482 |
gfc_statement st; |
| 5483 |
gfc_code *top; |
| 5484 |
gfc_state_data s; |
| 5485 |
gfc_symtree *stree; |
| 5486 |
gfc_exec_op do_op; |
| 5487 |
|
| 5488 |
do_op = new_st.op; |
| 5489 |
s.ext.end_do_label = new_st.label1; |
| 5490 |
|
| 5491 |
if (do_op == EXEC_DO_CONCURRENT) |
| 5492 |
{ |
| 5493 |
gfc_forall_iterator *fa; |
| 5494 |
for (fa = new_st.ext.concur.forall_iterator; fa; fa = fa->next) |
| 5495 |
{ |
| 5496 |
/* Apply unroll only to innermost loop (first control |
| 5497 |
variable). */ |
| 5498 |
if (directive_unroll != -1) |
| 5499 |
{ |
| 5500 |
fa->annot.unroll = directive_unroll; |
| 5501 |
directive_unroll = -1; |
| 5502 |
} |
| 5503 |
if (directive_ivdep) |
| 5504 |
fa->annot.ivdep = directive_ivdep; |
| 5505 |
if (directive_vector) |
| 5506 |
fa->annot.vector = directive_vector; |
| 5507 |
if (directive_novector) |
| 5508 |
fa->annot.novector = directive_novector; |
| 5509 |
} |
| 5510 |
directive_ivdep = false; |
| 5511 |
directive_vector = false; |
| 5512 |
directive_novector = false; |
| 5513 |
stree = NULL; |
| 5514 |
} |
| 5515 |
else if (new_st.ext.iterator != NULL) |
| 5516 |
{ |
| 5517 |
stree = new_st.ext.iterator->var->symtree; |
| 5518 |
if (directive_unroll != -1) |
| 5519 |
{ |
| 5520 |
new_st.ext.iterator->annot.unroll = directive_unroll; |
| 5521 |
directive_unroll = -1; |
| 5522 |
} |
| 5523 |
if (directive_ivdep) |
| 5524 |
{ |
| 5525 |
new_st.ext.iterator->annot.ivdep = directive_ivdep; |
| 5526 |
directive_ivdep = false; |
| 5527 |
} |
| 5528 |
if (directive_vector) |
| 5529 |
{ |
| 5530 |
new_st.ext.iterator->annot.vector = directive_vector; |
| 5531 |
directive_vector = false; |
| 5532 |
} |
| 5533 |
if (directive_novector) |
| 5534 |
{ |
| 5535 |
new_st.ext.iterator->annot.novector = directive_novector; |
| 5536 |
directive_novector = false; |
| 5537 |
} |
| 5538 |
} |
| 5539 |
else |
| 5540 |
stree = NULL; |
| 5541 |
|
| 5542 |
accept_statement (ST_DO); |
| 5543 |
|
| 5544 |
top = gfc_state_stack->tail; |
| 5545 |
push_state (&s, do_op == EXEC_DO_CONCURRENT ? COMP_DO_CONCURRENT : COMP_DO, |
| 5546 |
gfc_new_block); |
| 5547 |
|
| 5548 |
s.do_variable = stree; |
| 5549 |
|
| 5550 |
top->block = new_level (top); |
| 5551 |
top->block->op = EXEC_DO; |
| 5552 |
|
| 5553 |
loop: |
| 5554 |
st = parse_executable (ST_NONE); |
| 5555 |
|
| 5556 |
switch (st) |
| 5557 |
{ |
| 5558 |
case ST_NONE: |
| 5559 |
unexpected_eof (); |
| 5560 |
|
| 5561 |
case ST_ENDDO: |
| 5562 |
if (s.ext.end_do_label != NULL |
| 5563 |
&& s.ext.end_do_label != gfc_statement_label) |
| 5564 |
gfc_error_now ("Statement label in ENDDO at %C doesn't match " |
| 5565 |
"DO label"); |
| 5566 |
|
| 5567 |
if (gfc_statement_label != NULL) |
| 5568 |
{ |
| 5569 |
new_st.op = EXEC_NOP; |
| 5570 |
add_statement (); |
| 5571 |
} |
| 5572 |
break; |
| 5573 |
|
| 5574 |
case ST_IMPLIED_ENDDO: |
| 5575 |
/* If the do-stmt of this DO construct has a do-construct-name, |
| 5576 |
the corresponding end-do must be an end-do-stmt (with a matching |
| 5577 |
name, but in that case we must have seen ST_ENDDO first). |
| 5578 |
We only complain about this in pedantic mode. */ |
| 5579 |
if (gfc_current_block () != NULL) |
| 5580 |
gfc_error_now ("Named block DO at %L requires matching ENDDO name", |
| 5581 |
&gfc_current_block()->declared_at); |
| 5582 |
|
| 5583 |
break; |
| 5584 |
|
| 5585 |
default: |
| 5586 |
unexpected_statement (st); |
| 5587 |
goto loop; |
| 5588 |
} |
| 5589 |
|
| 5590 |
pop_state (); |
| 5591 |
accept_statement (st); |
| 5592 |
} |
| 5593 |
|
| 5594 |
/* Get the corresponding ending statement type for the OpenMP directive |
| 5595 |
OMP_ST. If it does not have one, return ST_NONE. */ |
| 5596 |
|
| 5597 |
gfc_statement |
| 5598 |
gfc_omp_end_stmt (gfc_statement omp_st, |
| 5599 |
bool omp_do_p, bool omp_structured_p) |
| 5600 |
{ |
| 5601 |
if (omp_do_p) |
| 5602 |
{ |
| 5603 |
switch (omp_st) |
| 5604 |
{ |
| 5605 |
case ST_OMP_DISTRIBUTE: return ST_OMP_END_DISTRIBUTE; |
| 5606 |
case ST_OMP_DISTRIBUTE_PARALLEL_DO: |
| 5607 |
return ST_OMP_END_DISTRIBUTE_PARALLEL_DO; |
| 5608 |
case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 5609 |
return ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD; |
| 5610 |
case ST_OMP_DISTRIBUTE_SIMD: |
| 5611 |
return ST_OMP_END_DISTRIBUTE_SIMD; |
| 5612 |
case ST_OMP_DO: return ST_OMP_END_DO; |
| 5613 |
case ST_OMP_DO_SIMD: return ST_OMP_END_DO_SIMD; |
| 5614 |
case ST_OMP_LOOP: return ST_OMP_END_LOOP; |
| 5615 |
case ST_OMP_PARALLEL_DO: return ST_OMP_END_PARALLEL_DO; |
| 5616 |
case ST_OMP_PARALLEL_DO_SIMD: |
| 5617 |
return ST_OMP_END_PARALLEL_DO_SIMD; |
| 5618 |
case ST_OMP_PARALLEL_LOOP: |
| 5619 |
return ST_OMP_END_PARALLEL_LOOP; |
| 5620 |
case ST_OMP_SIMD: return ST_OMP_END_SIMD; |
| 5621 |
case ST_OMP_TARGET_PARALLEL_DO: |
| 5622 |
return ST_OMP_END_TARGET_PARALLEL_DO; |
| 5623 |
case ST_OMP_TARGET_PARALLEL_DO_SIMD: |
| 5624 |
return ST_OMP_END_TARGET_PARALLEL_DO_SIMD; |
| 5625 |
case ST_OMP_TARGET_PARALLEL_LOOP: |
| 5626 |
return ST_OMP_END_TARGET_PARALLEL_LOOP; |
| 5627 |
case ST_OMP_TARGET_SIMD: return ST_OMP_END_TARGET_SIMD; |
| 5628 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE: |
| 5629 |
return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE; |
| 5630 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 5631 |
return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO; |
| 5632 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 5633 |
return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD; |
| 5634 |
case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: |
| 5635 |
return ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD; |
| 5636 |
case ST_OMP_TARGET_TEAMS_LOOP: |
| 5637 |
return ST_OMP_END_TARGET_TEAMS_LOOP; |
| 5638 |
case ST_OMP_TASKLOOP: return ST_OMP_END_TASKLOOP; |
| 5639 |
case ST_OMP_TASKLOOP_SIMD: return ST_OMP_END_TASKLOOP_SIMD; |
| 5640 |
case ST_OMP_MASKED_TASKLOOP: return ST_OMP_END_MASKED_TASKLOOP; |
| 5641 |
case ST_OMP_MASKED_TASKLOOP_SIMD: |
| 5642 |
return ST_OMP_END_MASKED_TASKLOOP_SIMD; |
| 5643 |
case ST_OMP_MASTER_TASKLOOP: return ST_OMP_END_MASTER_TASKLOOP; |
| 5644 |
case ST_OMP_MASTER_TASKLOOP_SIMD: |
| 5645 |
return ST_OMP_END_MASTER_TASKLOOP_SIMD; |
| 5646 |
case ST_OMP_PARALLEL_MASKED_TASKLOOP: |
| 5647 |
return ST_OMP_END_PARALLEL_MASKED_TASKLOOP; |
| 5648 |
case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: |
| 5649 |
return ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD; |
| 5650 |
case ST_OMP_PARALLEL_MASTER_TASKLOOP: |
| 5651 |
return ST_OMP_END_PARALLEL_MASTER_TASKLOOP; |
| 5652 |
case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: |
| 5653 |
return ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD; |
| 5654 |
case ST_OMP_TEAMS_DISTRIBUTE: |
| 5655 |
return ST_OMP_END_TEAMS_DISTRIBUTE; |
| 5656 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 5657 |
return ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO; |
| 5658 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 5659 |
return ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD; |
| 5660 |
case ST_OMP_TEAMS_DISTRIBUTE_SIMD: |
| 5661 |
return ST_OMP_END_TEAMS_DISTRIBUTE_SIMD; |
| 5662 |
case ST_OMP_TEAMS_LOOP: |
| 5663 |
return ST_OMP_END_TEAMS_LOOP; |
| 5664 |
case ST_OMP_TILE: |
| 5665 |
return ST_OMP_END_TILE; |
| 5666 |
case ST_OMP_UNROLL: |
| 5667 |
return ST_OMP_END_UNROLL; |
| 5668 |
default: |
| 5669 |
break; |
| 5670 |
} |
| 5671 |
} |
| 5672 |
|
| 5673 |
if (omp_structured_p) |
| 5674 |
{ |
| 5675 |
switch (omp_st) |
| 5676 |
{ |
| 5677 |
case ST_OMP_ALLOCATORS: |
| 5678 |
return ST_OMP_END_ALLOCATORS; |
| 5679 |
case ST_OMP_ASSUME: |
| 5680 |
return ST_OMP_END_ASSUME; |
| 5681 |
case ST_OMP_ATOMIC: |
| 5682 |
return ST_OMP_END_ATOMIC; |
| 5683 |
case ST_OMP_DISPATCH: |
| 5684 |
return ST_OMP_END_DISPATCH; |
| 5685 |
case ST_OMP_PARALLEL: |
| 5686 |
return ST_OMP_END_PARALLEL; |
| 5687 |
case ST_OMP_PARALLEL_MASKED: |
| 5688 |
return ST_OMP_END_PARALLEL_MASKED; |
| 5689 |
case ST_OMP_PARALLEL_MASTER: |
| 5690 |
return ST_OMP_END_PARALLEL_MASTER; |
| 5691 |
case ST_OMP_PARALLEL_SECTIONS: |
| 5692 |
return ST_OMP_END_PARALLEL_SECTIONS; |
| 5693 |
case ST_OMP_SCOPE: |
| 5694 |
return ST_OMP_END_SCOPE; |
| 5695 |
case ST_OMP_SECTIONS: |
| 5696 |
return ST_OMP_END_SECTIONS; |
| 5697 |
case ST_OMP_ORDERED: |
| 5698 |
return ST_OMP_END_ORDERED; |
| 5699 |
case ST_OMP_CRITICAL: |
| 5700 |
return ST_OMP_END_CRITICAL; |
| 5701 |
case ST_OMP_MASKED: |
| 5702 |
return ST_OMP_END_MASKED; |
| 5703 |
case ST_OMP_MASTER: |
| 5704 |
return ST_OMP_END_MASTER; |
| 5705 |
case ST_OMP_SINGLE: |
| 5706 |
return ST_OMP_END_SINGLE; |
| 5707 |
case ST_OMP_TARGET: |
| 5708 |
return ST_OMP_END_TARGET; |
| 5709 |
case ST_OMP_TARGET_DATA: |
| 5710 |
return ST_OMP_END_TARGET_DATA; |
| 5711 |
case ST_OMP_TARGET_PARALLEL: |
| 5712 |
return ST_OMP_END_TARGET_PARALLEL; |
| 5713 |
case ST_OMP_TARGET_TEAMS: |
| 5714 |
return ST_OMP_END_TARGET_TEAMS; |
| 5715 |
case ST_OMP_TASK: |
| 5716 |
return ST_OMP_END_TASK; |
| 5717 |
case ST_OMP_TASKGROUP: |
| 5718 |
return ST_OMP_END_TASKGROUP; |
| 5719 |
case ST_OMP_TEAMS: |
| 5720 |
return ST_OMP_END_TEAMS; |
| 5721 |
case ST_OMP_TEAMS_DISTRIBUTE: |
| 5722 |
return ST_OMP_END_TEAMS_DISTRIBUTE; |
| 5723 |
case ST_OMP_DISTRIBUTE: |
| 5724 |
return ST_OMP_END_DISTRIBUTE; |
| 5725 |
case ST_OMP_WORKSHARE: |
| 5726 |
return ST_OMP_END_WORKSHARE; |
| 5727 |
case ST_OMP_PARALLEL_WORKSHARE: |
| 5728 |
return ST_OMP_END_PARALLEL_WORKSHARE; |
| 5729 |
case ST_OMP_BEGIN_METADIRECTIVE: |
| 5730 |
return ST_OMP_END_METADIRECTIVE; |
| 5731 |
default: |
| 5732 |
break; |
| 5733 |
} |
| 5734 |
} |
| 5735 |
|
| 5736 |
return ST_NONE; |
| 5737 |
} |
| 5738 |
|
| 5739 |
/* Parse the statements of OpenMP do/parallel do. */ |
| 5740 |
|
| 5741 |
static gfc_statement |
| 5742 |
parse_omp_do (gfc_statement omp_st, int nested) |
| 5743 |
{ |
| 5744 |
gfc_statement st; |
| 5745 |
gfc_code *cp, *np; |
| 5746 |
gfc_state_data s; |
| 5747 |
|
| 5748 |
accept_statement (omp_st); |
| 5749 |
|
| 5750 |
cp = gfc_state_stack->tail; |
| 5751 |
push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL); |
| 5752 |
np = new_level (cp); |
| 5753 |
np->op = cp->op; |
| 5754 |
np->block = NULL; |
| 5755 |
|
| 5756 |
for (;;) |
| 5757 |
{ |
| 5758 |
st = next_statement (); |
| 5759 |
if (st == ST_NONE) |
| 5760 |
unexpected_eof (); |
| 5761 |
else if (st == ST_DO) |
| 5762 |
break; |
| 5763 |
else if (st == ST_OMP_UNROLL || st == ST_OMP_TILE) |
| 5764 |
{ |
| 5765 |
st = parse_omp_do (st, nested + 1); |
| 5766 |
if (st == ST_IMPLIED_ENDDO) |
| 5767 |
return st; |
| 5768 |
goto do_end; |
| 5769 |
} |
| 5770 |
else |
| 5771 |
unexpected_statement (st); |
| 5772 |
} |
| 5773 |
|
| 5774 |
parse_do_block (); |
| 5775 |
for (; nested; --nested) |
| 5776 |
pop_state (); |
| 5777 |
if (gfc_statement_label != NULL |
| 5778 |
&& gfc_state_stack->previous != NULL |
| 5779 |
&& gfc_state_stack->previous->state == COMP_DO |
| 5780 |
&& gfc_state_stack->previous->ext.end_do_label == gfc_statement_label) |
| 5781 |
{ |
| 5782 |
/* In |
| 5783 |
DO 100 I=1,10 |
| 5784 |
!$OMP DO |
| 5785 |
DO J=1,10 |
| 5786 |
... |
| 5787 |
100 CONTINUE |
| 5788 |
there should be no !$OMP END DO. */ |
| 5789 |
pop_state (); |
| 5790 |
return ST_IMPLIED_ENDDO; |
| 5791 |
} |
| 5792 |
|
| 5793 |
check_do_closure (); |
| 5794 |
pop_state (); |
| 5795 |
|
| 5796 |
st = next_statement (); |
| 5797 |
do_end: |
| 5798 |
gfc_statement omp_end_st = gfc_omp_end_stmt (omp_st, true, false); |
| 5799 |
if (omp_st == ST_NONE) |
| 5800 |
gcc_unreachable (); |
| 5801 |
|
| 5802 |
/* If handling a metadirective variant, treat 'omp end metadirective' |
| 5803 |
as the expected end statement for the current construct. */ |
| 5804 |
if (gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE) |
| 5805 |
{ |
| 5806 |
if (st == ST_OMP_END_METADIRECTIVE) |
| 5807 |
st = omp_end_st; |
| 5808 |
else |
| 5809 |
{ |
| 5810 |
/* We have found some extra statements between the loop |
| 5811 |
and the "end metadirective" which is required in a |
| 5812 |
"begin metadirective" construct, or perhaps the |
| 5813 |
"end metadirective" is missing entirely. */ |
| 5814 |
gfc_error_now ("Expected OMP END METADIRECTIVE at %C"); |
| 5815 |
return st; |
| 5816 |
} |
| 5817 |
} |
| 5818 |
|
| 5819 |
if (st == omp_end_st) |
| 5820 |
{ |
| 5821 |
if (new_st.op == EXEC_OMP_END_NOWAIT) |
| 5822 |
{ |
| 5823 |
if (cp->ext.omp_clauses->nowait && new_st.ext.omp_bool) |
| 5824 |
gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C", |
| 5825 |
gfc_ascii_statement (omp_st), |
| 5826 |
gfc_ascii_statement (omp_end_st)); |
| 5827 |
cp->ext.omp_clauses->nowait |= new_st.ext.omp_bool; |
| 5828 |
} |
| 5829 |
else |
| 5830 |
gcc_assert (new_st.op == EXEC_NOP); |
| 5831 |
gfc_clear_new_st (); |
| 5832 |
gfc_commit_symbols (); |
| 5833 |
gfc_warning_check (); |
| 5834 |
st = next_statement (); |
| 5835 |
} |
| 5836 |
return st; |
| 5837 |
} |
| 5838 |
|
| 5839 |
|
| 5840 |
/* Parse the statements of OpenMP atomic directive. */ |
| 5841 |
|
| 5842 |
static gfc_statement |
| 5843 |
parse_omp_oacc_atomic (bool omp_p) |
| 5844 |
{ |
| 5845 |
gfc_statement st, st_atomic, st_end_atomic; |
| 5846 |
gfc_code *cp, *np; |
| 5847 |
gfc_state_data s; |
| 5848 |
int count; |
| 5849 |
|
| 5850 |
if (omp_p) |
| 5851 |
{ |
| 5852 |
st_atomic = ST_OMP_ATOMIC; |
| 5853 |
if (gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE) |
| 5854 |
st_end_atomic = ST_OMP_END_METADIRECTIVE; |
| 5855 |
else |
| 5856 |
st_end_atomic = ST_OMP_END_ATOMIC; |
| 5857 |
} |
| 5858 |
else |
| 5859 |
{ |
| 5860 |
st_atomic = ST_OACC_ATOMIC; |
| 5861 |
st_end_atomic = ST_OACC_END_ATOMIC; |
| 5862 |
} |
| 5863 |
accept_statement (st_atomic); |
| 5864 |
|
| 5865 |
cp = gfc_state_stack->tail; |
| 5866 |
push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL); |
| 5867 |
np = new_level (cp); |
| 5868 |
np->op = cp->op; |
| 5869 |
np->block = NULL; |
| 5870 |
np->ext.omp_clauses = cp->ext.omp_clauses; |
| 5871 |
cp->ext.omp_clauses = NULL; |
| 5872 |
count = 1 + np->ext.omp_clauses->capture; |
| 5873 |
|
| 5874 |
while (count) |
| 5875 |
{ |
| 5876 |
st = next_statement (); |
| 5877 |
if (st == ST_NONE) |
| 5878 |
unexpected_eof (); |
| 5879 |
else if (np->ext.omp_clauses->compare |
| 5880 |
&& (st == ST_SIMPLE_IF || st == ST_IF_BLOCK)) |
| 5881 |
{ |
| 5882 |
count--; |
| 5883 |
if (st == ST_IF_BLOCK) |
| 5884 |
{ |
| 5885 |
parse_if_block (); |
| 5886 |
/* With else (or elseif). */ |
| 5887 |
if (gfc_state_stack->tail->block->block) |
| 5888 |
count--; |
| 5889 |
} |
| 5890 |
accept_statement (st); |
| 5891 |
} |
| 5892 |
else if (st == ST_ASSIGNMENT |
| 5893 |
&& (!np->ext.omp_clauses->compare |
| 5894 |
|| np->ext.omp_clauses->capture)) |
| 5895 |
{ |
| 5896 |
accept_statement (st); |
| 5897 |
count--; |
| 5898 |
} |
| 5899 |
else |
| 5900 |
unexpected_statement (st); |
| 5901 |
} |
| 5902 |
|
| 5903 |
pop_state (); |
| 5904 |
|
| 5905 |
st = next_statement (); |
| 5906 |
if (st == st_end_atomic) |
| 5907 |
{ |
| 5908 |
gfc_clear_new_st (); |
| 5909 |
gfc_commit_symbols (); |
| 5910 |
gfc_warning_check (); |
| 5911 |
st = next_statement (); |
| 5912 |
} |
| 5913 |
return st; |
| 5914 |
} |
| 5915 |
|
| 5916 |
|
| 5917 |
/* Parse the statements of an OpenACC structured block. */ |
| 5918 |
|
| 5919 |
static void |
| 5920 |
parse_oacc_structured_block (gfc_statement acc_st) |
| 5921 |
{ |
| 5922 |
gfc_statement st, acc_end_st; |
| 5923 |
gfc_code *cp, *np; |
| 5924 |
gfc_state_data s, *sd; |
| 5925 |
|
| 5926 |
for (sd = gfc_state_stack; sd; sd = sd->previous) |
| 5927 |
if (sd->state == COMP_CRITICAL) |
| 5928 |
gfc_error_now ("OpenACC directive inside of CRITICAL block at %C"); |
| 5929 |
|
| 5930 |
accept_statement (acc_st); |
| 5931 |
|
| 5932 |
cp = gfc_state_stack->tail; |
| 5933 |
push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL); |
| 5934 |
np = new_level (cp); |
| 5935 |
np->op = cp->op; |
| 5936 |
np->block = NULL; |
| 5937 |
switch (acc_st) |
| 5938 |
{ |
| 5939 |
case ST_OACC_PARALLEL: |
| 5940 |
acc_end_st = ST_OACC_END_PARALLEL; |
| 5941 |
break; |
| 5942 |
case ST_OACC_KERNELS: |
| 5943 |
acc_end_st = ST_OACC_END_KERNELS; |
| 5944 |
break; |
| 5945 |
case ST_OACC_SERIAL: |
| 5946 |
acc_end_st = ST_OACC_END_SERIAL; |
| 5947 |
break; |
| 5948 |
case ST_OACC_DATA: |
| 5949 |
acc_end_st = ST_OACC_END_DATA; |
| 5950 |
break; |
| 5951 |
case ST_OACC_HOST_DATA: |
| 5952 |
acc_end_st = ST_OACC_END_HOST_DATA; |
| 5953 |
break; |
| 5954 |
default: |
| 5955 |
gcc_unreachable (); |
| 5956 |
} |
| 5957 |
|
| 5958 |
do |
| 5959 |
{ |
| 5960 |
st = parse_executable (ST_NONE); |
| 5961 |
if (st == ST_NONE) |
| 5962 |
unexpected_eof (); |
| 5963 |
else if (st != acc_end_st) |
| 5964 |
{ |
| 5965 |
gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st)); |
| 5966 |
reject_statement (); |
| 5967 |
} |
| 5968 |
} |
| 5969 |
while (st != acc_end_st); |
| 5970 |
|
| 5971 |
gcc_assert (new_st.op == EXEC_NOP); |
| 5972 |
|
| 5973 |
gfc_clear_new_st (); |
| 5974 |
gfc_commit_symbols (); |
| 5975 |
gfc_warning_check (); |
| 5976 |
pop_state (); |
| 5977 |
} |
| 5978 |
|
| 5979 |
/* Parse the statements of OpenACC 'loop', or combined compute 'loop'. */ |
| 5980 |
|
| 5981 |
static gfc_statement |
| 5982 |
parse_oacc_loop (gfc_statement acc_st) |
| 5983 |
{ |
| 5984 |
gfc_statement st; |
| 5985 |
gfc_code *cp, *np; |
| 5986 |
gfc_state_data s, *sd; |
| 5987 |
|
| 5988 |
for (sd = gfc_state_stack; sd; sd = sd->previous) |
| 5989 |
if (sd->state == COMP_CRITICAL) |
| 5990 |
gfc_error_now ("OpenACC directive inside of CRITICAL block at %C"); |
| 5991 |
|
| 5992 |
accept_statement (acc_st); |
| 5993 |
|
| 5994 |
cp = gfc_state_stack->tail; |
| 5995 |
push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL); |
| 5996 |
np = new_level (cp); |
| 5997 |
np->op = cp->op; |
| 5998 |
np->block = NULL; |
| 5999 |
|
| 6000 |
for (;;) |
| 6001 |
{ |
| 6002 |
st = next_statement (); |
| 6003 |
if (st == ST_NONE) |
| 6004 |
unexpected_eof (); |
| 6005 |
else if (st == ST_DO) |
| 6006 |
break; |
| 6007 |
else |
| 6008 |
{ |
| 6009 |
gfc_error ("Expected DO loop at %C"); |
| 6010 |
reject_statement (); |
| 6011 |
} |
| 6012 |
} |
| 6013 |
|
| 6014 |
parse_do_block (); |
| 6015 |
if (gfc_statement_label != NULL |
| 6016 |
&& gfc_state_stack->previous != NULL |
| 6017 |
&& gfc_state_stack->previous->state == COMP_DO |
| 6018 |
&& gfc_state_stack->previous->ext.end_do_label == gfc_statement_label) |
| 6019 |
{ |
| 6020 |
pop_state (); |
| 6021 |
return ST_IMPLIED_ENDDO; |
| 6022 |
} |
| 6023 |
|
| 6024 |
check_do_closure (); |
| 6025 |
pop_state (); |
| 6026 |
|
| 6027 |
st = next_statement (); |
| 6028 |
if (st == ST_OACC_END_LOOP) |
| 6029 |
gfc_warning (0, "Redundant !$ACC END LOOP at %C"); |
| 6030 |
if ((acc_st == ST_OACC_PARALLEL_LOOP && st == ST_OACC_END_PARALLEL_LOOP) || |
| 6031 |
(acc_st == ST_OACC_KERNELS_LOOP && st == ST_OACC_END_KERNELS_LOOP) || |
| 6032 |
(acc_st == ST_OACC_SERIAL_LOOP && st == ST_OACC_END_SERIAL_LOOP) || |
| 6033 |
(acc_st == ST_OACC_LOOP && st == ST_OACC_END_LOOP)) |
| 6034 |
{ |
| 6035 |
gcc_assert (new_st.op == EXEC_NOP); |
| 6036 |
gfc_clear_new_st (); |
| 6037 |
gfc_commit_symbols (); |
| 6038 |
gfc_warning_check (); |
| 6039 |
st = next_statement (); |
| 6040 |
} |
| 6041 |
return st; |
| 6042 |
} |
| 6043 |
|
| 6044 |
|
| 6045 |
/* Parse an OpenMP allocate block, including optional ALLOCATORS |
| 6046 |
end directive. */ |
| 6047 |
|
| 6048 |
static gfc_statement |
| 6049 |
parse_openmp_allocate_block (gfc_statement omp_st) |
| 6050 |
{ |
| 6051 |
gfc_statement st; |
| 6052 |
gfc_code *cp, *np; |
| 6053 |
gfc_state_data s; |
| 6054 |
bool empty_list = false; |
| 6055 |
locus empty_list_loc; |
| 6056 |
gfc_omp_namelist *n_first = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]; |
| 6057 |
|
| 6058 |
if (omp_st == ST_OMP_ALLOCATE_EXEC |
| 6059 |
&& new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym == NULL) |
| 6060 |
{ |
| 6061 |
empty_list = true; |
| 6062 |
empty_list_loc = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->where; |
| 6063 |
} |
| 6064 |
|
| 6065 |
accept_statement (omp_st); |
| 6066 |
|
| 6067 |
cp = gfc_state_stack->tail; |
| 6068 |
push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL); |
| 6069 |
np = new_level (cp); |
| 6070 |
np->op = cp->op; |
| 6071 |
np->block = NULL; |
| 6072 |
|
| 6073 |
st = next_statement (); |
| 6074 |
while (omp_st == ST_OMP_ALLOCATE_EXEC && st == ST_OMP_ALLOCATE_EXEC) |
| 6075 |
{ |
| 6076 |
if (empty_list && !new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym) |
| 6077 |
{ |
| 6078 |
locus *loc = &new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->where; |
| 6079 |
gfc_error_now ("%s statements at %L and %L have both no list item but" |
| 6080 |
" only one may", gfc_ascii_statement (st), |
| 6081 |
&empty_list_loc, loc); |
| 6082 |
empty_list = false; |
| 6083 |
} |
| 6084 |
if (!new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->sym) |
| 6085 |
{ |
| 6086 |
empty_list = true; |
| 6087 |
empty_list_loc = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]->where; |
| 6088 |
} |
| 6089 |
for ( ; n_first->next; n_first = n_first->next) |
| 6090 |
; |
| 6091 |
n_first->next = new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE]; |
| 6092 |
new_st.ext.omp_clauses->lists[OMP_LIST_ALLOCATE] = NULL; |
| 6093 |
gfc_free_omp_clauses (new_st.ext.omp_clauses); |
| 6094 |
|
| 6095 |
accept_statement (ST_NONE); |
| 6096 |
st = next_statement (); |
| 6097 |
} |
| 6098 |
if (st != ST_ALLOCATE && omp_st == ST_OMP_ALLOCATE_EXEC) |
| 6099 |
gfc_error_now ("Unexpected %s at %C; expected ALLOCATE or %s statement", |
| 6100 |
gfc_ascii_statement (st), gfc_ascii_statement (omp_st)); |
| 6101 |
else if (st != ST_ALLOCATE) |
| 6102 |
gfc_error_now ("Unexpected %s at %C; expected ALLOCATE statement after %s", |
| 6103 |
gfc_ascii_statement (st), gfc_ascii_statement (omp_st)); |
| 6104 |
accept_statement (st); |
| 6105 |
pop_state (); |
| 6106 |
st = next_statement (); |
| 6107 |
if (omp_st == ST_OMP_ALLOCATORS |
| 6108 |
&& (st == ST_OMP_END_ALLOCATORS |
| 6109 |
|| (st == ST_OMP_END_METADIRECTIVE |
| 6110 |
&& gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE))) |
| 6111 |
{ |
| 6112 |
accept_statement (st); |
| 6113 |
st = next_statement (); |
| 6114 |
} |
| 6115 |
return st; |
| 6116 |
} |
| 6117 |
|
| 6118 |
|
| 6119 |
/* Parse the statements of an OpenMP structured block. */ |
| 6120 |
|
| 6121 |
static gfc_statement |
| 6122 |
parse_omp_structured_block (gfc_statement omp_st, bool workshare_stmts_only) |
| 6123 |
{ |
| 6124 |
gfc_statement st, omp_end_st, first_st; |
| 6125 |
gfc_code *cp, *np; |
| 6126 |
gfc_state_data s, s2; |
| 6127 |
|
| 6128 |
accept_statement (omp_st); |
| 6129 |
|
| 6130 |
cp = gfc_state_stack->tail; |
| 6131 |
push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL); |
| 6132 |
np = new_level (cp); |
| 6133 |
np->op = cp->op; |
| 6134 |
np->block = NULL; |
| 6135 |
|
| 6136 |
omp_end_st = gfc_omp_end_stmt (omp_st, false, true); |
| 6137 |
if (omp_end_st == ST_NONE) |
| 6138 |
gcc_unreachable (); |
| 6139 |
|
| 6140 |
/* If handling a metadirective variant, treat 'omp end metadirective' |
| 6141 |
as the expected end statement for the current construct. */ |
| 6142 |
if (gfc_state_stack->previous != NULL |
| 6143 |
&& gfc_state_stack->previous->state == COMP_OMP_BEGIN_METADIRECTIVE) |
| 6144 |
omp_end_st = ST_OMP_END_METADIRECTIVE; |
| 6145 |
|
| 6146 |
bool block_construct = false; |
| 6147 |
gfc_namespace *my_ns = NULL; |
| 6148 |
gfc_namespace *my_parent = NULL; |
| 6149 |
|
| 6150 |
first_st = st = next_statement (); |
| 6151 |
|
| 6152 |
if (st == ST_BLOCK) |
| 6153 |
{ |
| 6154 |
/* Adjust state to a strictly-structured block, now that we found that |
| 6155 |
the body starts with a BLOCK construct. */ |
| 6156 |
s.state = COMP_OMP_STRICTLY_STRUCTURED_BLOCK; |
| 6157 |
|
| 6158 |
block_construct = true; |
| 6159 |
gfc_notify_std (GFC_STD_F2008, "BLOCK construct at %C"); |
| 6160 |
|
| 6161 |
my_ns = gfc_build_block_ns (gfc_current_ns); |
| 6162 |
new_st.op = EXEC_BLOCK; |
| 6163 |
new_st.ext.block.ns = my_ns; |
| 6164 |
new_st.ext.block.assoc = NULL; |
| 6165 |
accept_statement (ST_BLOCK); |
| 6166 |
|
| 6167 |
push_state (&s2, COMP_BLOCK, my_ns->proc_name); |
| 6168 |
gfc_current_ns = my_ns; |
| 6169 |
my_parent = my_ns->parent; |
| 6170 |
if (omp_st == ST_OMP_SECTIONS |
| 6171 |
|| omp_st == ST_OMP_PARALLEL_SECTIONS) |
| 6172 |
{ |
| 6173 |
np = new_level (cp); |
| 6174 |
np->op = cp->op; |
| 6175 |
} |
| 6176 |
|
| 6177 |
first_st = next_statement (); |
| 6178 |
st = parse_spec (first_st); |
| 6179 |
} |
| 6180 |
|
| 6181 |
if (omp_end_st == ST_OMP_END_TARGET) |
| 6182 |
switch (first_st) |
| 6183 |
{ |
| 6184 |
case ST_OMP_TEAMS: |
| 6185 |
case ST_OMP_TEAMS_DISTRIBUTE: |
| 6186 |
case ST_OMP_TEAMS_DISTRIBUTE_SIMD: |
| 6187 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: |
| 6188 |
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: |
| 6189 |
case ST_OMP_TEAMS_LOOP: |
| 6190 |
case ST_OMP_METADIRECTIVE: |
| 6191 |
case ST_OMP_BEGIN_METADIRECTIVE: |
| 6192 |
{ |
| 6193 |
gfc_state_data *stk = gfc_state_stack->previous; |
| 6194 |
if (stk->state == COMP_OMP_STRICTLY_STRUCTURED_BLOCK) |
| 6195 |
stk = stk->previous; |
| 6196 |
stk->tail->ext.omp_clauses->target_first_st_is_teams_or_meta = true; |
| 6197 |
break; |
| 6198 |
} |
| 6199 |
default: |
| 6200 |
break; |
| 6201 |
} |
| 6202 |
|
| 6203 |
do |
| 6204 |
{ |
| 6205 |
if (workshare_stmts_only) |
| 6206 |
{ |
| 6207 |
/* Inside of !$omp workshare, only |
| 6208 |
scalar assignments |
| 6209 |
array assignments |
| 6210 |
where statements and constructs |
| 6211 |
forall statements and constructs |
| 6212 |
!$omp atomic |
| 6213 |
!$omp critical |
| 6214 |
!$omp parallel |
| 6215 |
are allowed. For !$omp critical these |
| 6216 |
restrictions apply recursively. */ |
| 6217 |
bool cycle = true; |
| 6218 |
|
| 6219 |
for (;;) |
| 6220 |
{ |
| 6221 |
switch (st) |
| 6222 |
{ |
| 6223 |
case ST_NONE: |
| 6224 |
unexpected_eof (); |
| 6225 |
|
| 6226 |
case ST_ASSIGNMENT: |
| 6227 |
case ST_WHERE: |
| 6228 |
case ST_FORALL: |
| 6229 |
accept_statement (st); |
| 6230 |
break; |
| 6231 |
|
| 6232 |
case ST_WHERE_BLOCK: |
| 6233 |
parse_where_block (); |
| 6234 |
break; |
| 6235 |
|
| 6236 |
case ST_FORALL_BLOCK: |
| 6237 |
parse_forall_block (); |
| 6238 |
break; |
| 6239 |
|
| 6240 |
case ST_OMP_ALLOCATE_EXEC: |
| 6241 |
case ST_OMP_ALLOCATORS: |
| 6242 |
st = parse_openmp_allocate_block (st); |
| 6243 |
continue; |
| 6244 |
|
| 6245 |
case ST_OMP_ASSUME: |
| 6246 |
case ST_OMP_PARALLEL: |
| 6247 |
case ST_OMP_PARALLEL_MASKED: |
| 6248 |
case ST_OMP_PARALLEL_MASTER: |
| 6249 |
case ST_OMP_PARALLEL_SECTIONS: |
| 6250 |
st = parse_omp_structured_block (st, false); |
| 6251 |
continue; |
| 6252 |
|
| 6253 |
case ST_OMP_PARALLEL_WORKSHARE: |
| 6254 |
case ST_OMP_CRITICAL: |
| 6255 |
st = parse_omp_structured_block (st, true); |
| 6256 |
continue; |
| 6257 |
|
| 6258 |
case ST_OMP_PARALLEL_DO: |
| 6259 |
case ST_OMP_PARALLEL_DO_SIMD: |
| 6260 |
st = parse_omp_do (st, 0); |
| 6261 |
continue; |
| 6262 |
|
| 6263 |
case ST_OMP_ATOMIC: |
| 6264 |
st = parse_omp_oacc_atomic (true); |
| 6265 |
continue; |
| 6266 |
|
| 6267 |
default: |
| 6268 |
cycle = false; |
| 6269 |
break; |
| 6270 |
} |
| 6271 |
|
| 6272 |
if (!cycle) |
| 6273 |
break; |
| 6274 |
|
| 6275 |
st = next_statement (); |
| 6276 |
} |
| 6277 |
} |
| 6278 |
else |
| 6279 |
st = parse_executable (st); |
| 6280 |
if (st == ST_NONE) |
| 6281 |
unexpected_eof (); |
| 6282 |
else if (st == ST_OMP_SECTION |
| 6283 |
&& (omp_st == ST_OMP_SECTIONS |
| 6284 |
|| omp_st == ST_OMP_PARALLEL_SECTIONS)) |
| 6285 |
{ |
| 6286 |
np = new_level (np); |
| 6287 |
np->op = cp->op; |
| 6288 |
np->block = NULL; |
| 6289 |
st = next_statement (); |
| 6290 |
} |
| 6291 |
else if (block_construct && st == ST_END_BLOCK) |
| 6292 |
{ |
| 6293 |
accept_statement (st); |
| 6294 |
gfc_current_ns->code = gfc_state_stack->head; |
| 6295 |
gfc_current_ns = my_parent; |
| 6296 |
pop_state (); /* Inner BLOCK */ |
| 6297 |
pop_state (); /* Outer COMP_OMP_STRICTLY_STRUCTURED_BLOCK */ |
| 6298 |
|
| 6299 |
st = next_statement (); |
| 6300 |
if (st == omp_end_st) |
| 6301 |
{ |
| 6302 |
accept_statement (st); |
| 6303 |
st = next_statement (); |
| 6304 |
} |
| 6305 |
else if (omp_end_st == ST_OMP_END_METADIRECTIVE) |
| 6306 |
{ |
| 6307 |
/* We have found some extra statements between the END BLOCK |
| 6308 |
and the "end metadirective" which is required in a |
| 6309 |
"begin metadirective" construct, or perhaps the |
| 6310 |
"end metadirective" is missing entirely. */ |
| 6311 |
gfc_error_now ("Expected OMP END METADIRECTIVE at %C"); |
| 6312 |
} |
| 6313 |
return st; |
| 6314 |
} |
| 6315 |
else if (st != omp_end_st || block_construct) |
| 6316 |
{ |
| 6317 |
unexpected_statement (st); |
| 6318 |
st = next_statement (); |
| 6319 |
} |
| 6320 |
} |
| 6321 |
while (st != omp_end_st); |
| 6322 |
|
| 6323 |
switch (new_st.op) |
| 6324 |
{ |
| 6325 |
case EXEC_OMP_END_NOWAIT: |
| 6326 |
if (cp->ext.omp_clauses->nowait && new_st.ext.omp_bool) |
| 6327 |
gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C", |
| 6328 |
gfc_ascii_statement (omp_st), |
| 6329 |
gfc_ascii_statement (omp_end_st)); |
| 6330 |
cp->ext.omp_clauses->nowait |= new_st.ext.omp_bool; |
| 6331 |
break; |
| 6332 |
case EXEC_OMP_END_CRITICAL: |
| 6333 |
if (((cp->ext.omp_clauses->critical_name == NULL) |
| 6334 |
^ (new_st.ext.omp_name == NULL)) |
| 6335 |
|| (new_st.ext.omp_name != NULL |
| 6336 |
&& strcmp (cp->ext.omp_clauses->critical_name, |
| 6337 |
new_st.ext.omp_name) != 0)) |
| 6338 |
gfc_error ("Name after !$omp critical and !$omp end critical does " |
| 6339 |
"not match at %C"); |
| 6340 |
free (CONST_CAST (char *, new_st.ext.omp_name)); |
| 6341 |
new_st.ext.omp_name = NULL; |
| 6342 |
break; |
| 6343 |
case EXEC_OMP_END_SINGLE: |
| 6344 |
if (cp->ext.omp_clauses->nowait && new_st.ext.omp_clauses->nowait) |
| 6345 |
gfc_error_now ("Duplicated NOWAIT clause on %s and %s at %C", |
| 6346 |
gfc_ascii_statement (omp_st), |
| 6347 |
gfc_ascii_statement (omp_end_st)); |
| 6348 |
cp->ext.omp_clauses->nowait |= new_st.ext.omp_clauses->nowait; |
| 6349 |
if (cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE]) |
| 6350 |
{ |
| 6351 |
gfc_omp_namelist *nl; |
| 6352 |
for (nl = cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE]; |
| 6353 |
nl->next; nl = nl->next) |
| 6354 |
; |
| 6355 |
nl->next = new_st.ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE]; |
| 6356 |
} |
| 6357 |
else |
| 6358 |
cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE] |
| 6359 |
= new_st.ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE]; |
| 6360 |
new_st.ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE] = NULL; |
| 6361 |
gfc_free_omp_clauses (new_st.ext.omp_clauses); |
| 6362 |
break; |
| 6363 |
case EXEC_NOP: |
| 6364 |
break; |
| 6365 |
default: |
| 6366 |
gcc_unreachable (); |
| 6367 |
} |
| 6368 |
|
| 6369 |
gfc_clear_new_st (); |
| 6370 |
gfc_commit_symbols (); |
| 6371 |
gfc_warning_check (); |
| 6372 |
pop_state (); |
| 6373 |
st = next_statement (); |
| 6374 |
return st; |
| 6375 |
} |
| 6376 |
|
| 6377 |
static gfc_statement |
| 6378 |
parse_omp_dispatch (void) |
| 6379 |
{ |
| 6380 |
gfc_statement st; |
| 6381 |
gfc_code *cp, *np; |
| 6382 |
gfc_state_data s; |
| 6383 |
|
| 6384 |
accept_statement (ST_OMP_DISPATCH); |
| 6385 |
|
| 6386 |
cp = gfc_state_stack->tail; |
| 6387 |
push_state (&s, COMP_OMP_STRUCTURED_BLOCK, NULL); |
| 6388 |
np = new_level (cp); |
| 6389 |
np->op = cp->op; |
| 6390 |
np->block = NULL; |
| 6391 |
|
| 6392 |
st = next_statement (); |
| 6393 |
if (st == ST_NONE) |
| 6394 |
{ |
| 6395 |
pop_state (); |
| 6396 |
return st; |
| 6397 |
} |
| 6398 |
if (st == ST_CALL || st == ST_ASSIGNMENT) |
| 6399 |
accept_statement (st); |
| 6400 |
else |
| 6401 |
{ |
| 6402 |
gfc_error ("%<OMP DISPATCH%> directive must be followed by a procedure " |
| 6403 |
"call with optional assignment at %C"); |
| 6404 |
reject_statement (); |
| 6405 |
} |
| 6406 |
pop_state (); |
| 6407 |
st = next_statement (); |
| 6408 |
if (st == ST_OMP_END_DISPATCH |
| 6409 |
|| (st == ST_OMP_END_METADIRECTIVE |
| 6410 |
&& gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE)) |
| 6411 |
{ |
| 6412 |
if (cp->ext.omp_clauses->nowait && new_st.ext.omp_bool) |
| 6413 |
gfc_error_now ("Duplicated NOWAIT clause on !$OMP DISPATCH and !$OMP " |
| 6414 |
"END DISPATCH at %C"); |
| 6415 |
cp->ext.omp_clauses->nowait |= new_st.ext.omp_bool; |
| 6416 |
accept_statement (st); |
| 6417 |
st = next_statement (); |
| 6418 |
} |
| 6419 |
return st; |
| 6420 |
} |
| 6421 |
|
| 6422 |
static gfc_statement |
| 6423 |
parse_omp_metadirective_body (gfc_statement omp_st) |
| 6424 |
{ |
| 6425 |
gfc_omp_variant *variant |
| 6426 |
= new_st.ext.omp_variants; |
| 6427 |
locus body_locus = gfc_current_locus; |
| 6428 |
bool saw_error = false; |
| 6429 |
|
| 6430 |
accept_statement (omp_st); |
| 6431 |
|
| 6432 |
gfc_statement next_st = ST_NONE; |
| 6433 |
locus next_loc; |
| 6434 |
|
| 6435 |
while (variant) |
| 6436 |
{ |
| 6437 |
gfc_current_locus = body_locus; |
| 6438 |
gfc_state_data s; |
| 6439 |
bool workshare_p |
| 6440 |
= (variant->stmt == ST_OMP_WORKSHARE |
| 6441 |
|| variant->stmt == ST_OMP_PARALLEL_WORKSHARE); |
| 6442 |
enum gfc_compile_state new_state |
| 6443 |
= (omp_st == ST_OMP_METADIRECTIVE |
| 6444 |
? COMP_OMP_METADIRECTIVE : COMP_OMP_BEGIN_METADIRECTIVE); |
| 6445 |
|
| 6446 |
new_st = *variant->code; |
| 6447 |
push_state (&s, new_state, NULL); |
| 6448 |
|
| 6449 |
gfc_statement st; |
| 6450 |
bool old_in_metadirective_body = gfc_in_omp_metadirective_body; |
| 6451 |
gfc_in_omp_metadirective_body = true; |
| 6452 |
|
| 6453 |
gfc_omp_metadirective_region_count++; |
| 6454 |
switch (variant->stmt) |
| 6455 |
{ |
| 6456 |
case_omp_structured_block: |
| 6457 |
st = parse_omp_structured_block (variant->stmt, workshare_p); |
| 6458 |
break; |
| 6459 |
case_omp_do: |
| 6460 |
st = parse_omp_do (variant->stmt, 0); |
| 6461 |
/* TODO: Does st == ST_IMPLIED_ENDDO need special handling? */ |
| 6462 |
break; |
| 6463 |
case ST_OMP_ALLOCATORS: |
| 6464 |
st = parse_openmp_allocate_block (variant->stmt); |
| 6465 |
break; |
| 6466 |
case ST_OMP_ATOMIC: |
| 6467 |
st = parse_omp_oacc_atomic (true); |
| 6468 |
break; |
| 6469 |
case ST_OMP_DISPATCH: |
| 6470 |
st = parse_omp_dispatch (); |
| 6471 |
break; |
| 6472 |
default: |
| 6473 |
accept_statement (variant->stmt); |
| 6474 |
st = parse_executable (next_statement ()); |
| 6475 |
break; |
| 6476 |
} |
| 6477 |
|
| 6478 |
if (gfc_state_stack->state == COMP_OMP_METADIRECTIVE |
| 6479 |
&& startswith (gfc_ascii_statement (st), "!$OMP END ")) |
| 6480 |
{ |
| 6481 |
for (gfc_state_data *p = gfc_state_stack; p; p = p->previous) |
| 6482 |
if (p->state == COMP_OMP_STRUCTURED_BLOCK |
| 6483 |
|| p->state == COMP_OMP_BEGIN_METADIRECTIVE) |
| 6484 |
goto finish; |
| 6485 |
gfc_error ("Unexpected %s statement in OMP METADIRECTIVE " |
| 6486 |
"block at %C", |
| 6487 |
gfc_ascii_statement (st)); |
| 6488 |
reject_statement (); |
| 6489 |
st = next_statement (); |
| 6490 |
} |
| 6491 |
|
| 6492 |
finish: |
| 6493 |
|
| 6494 |
/* Sanity-check that each variant finishes parsing at the same place. */ |
| 6495 |
if (next_st == ST_NONE) |
| 6496 |
{ |
| 6497 |
next_st = st; |
| 6498 |
next_loc = gfc_current_locus; |
| 6499 |
} |
| 6500 |
else if (st != next_st |
| 6501 |
|| next_loc.nextc != gfc_current_locus.nextc |
| 6502 |
|| next_loc.u.lb != gfc_current_locus.u.lb) |
| 6503 |
{ |
| 6504 |
saw_error = true; |
| 6505 |
next_st = st; |
| 6506 |
next_loc = gfc_current_locus; |
| 6507 |
} |
| 6508 |
|
| 6509 |
gfc_in_omp_metadirective_body = old_in_metadirective_body; |
| 6510 |
|
| 6511 |
if (gfc_state_stack->head) |
| 6512 |
*variant->code = *gfc_state_stack->head; |
| 6513 |
pop_state (); |
| 6514 |
|
| 6515 |
gfc_commit_symbols (); |
| 6516 |
gfc_warning_check (); |
| 6517 |
if (variant->next) |
| 6518 |
gfc_clear_new_st (); |
| 6519 |
|
| 6520 |
variant = variant->next; |
| 6521 |
} |
| 6522 |
|
| 6523 |
if (saw_error) |
| 6524 |
{ |
| 6525 |
if (omp_st == ST_OMP_METADIRECTIVE) |
| 6526 |
gfc_error_now ("Variants in a metadirective at %L have " |
| 6527 |
"different associations; " |
| 6528 |
"consider using a BLOCK construct " |
| 6529 |
"or BEGIN/END METADIRECTIVE", &body_locus); |
| 6530 |
else |
| 6531 |
gfc_error_now ("Variants in a metadirective at %L have " |
| 6532 |
"different associations; " |
| 6533 |
"consider using a BLOCK construct", &body_locus); |
| 6534 |
} |
| 6535 |
|
| 6536 |
return next_st; |
| 6537 |
} |
| 6538 |
|
| 6539 |
/* Accept a series of executable statements. We return the first |
| 6540 |
statement that doesn't fit to the caller. Any block statements are |
| 6541 |
passed on to the correct handler, which usually passes the buck |
| 6542 |
right back here. */ |
| 6543 |
|
| 6544 |
static gfc_statement |
| 6545 |
parse_executable (gfc_statement st) |
| 6546 |
{ |
| 6547 |
int close_flag; |
| 6548 |
bool one_stmt_p = false; |
| 6549 |
in_exec_part = true; |
| 6550 |
|
| 6551 |
if (st == ST_NONE) |
| 6552 |
st = next_statement (); |
| 6553 |
|
| 6554 |
for (;;) |
| 6555 |
{ |
| 6556 |
/* Only parse one statement for the form of metadirective without |
| 6557 |
an explicit begin..end. */ |
| 6558 |
if (gfc_state_stack->state == COMP_OMP_METADIRECTIVE && one_stmt_p) |
| 6559 |
return st; |
| 6560 |
one_stmt_p = true; |
| 6561 |
|
| 6562 |
close_flag = check_do_closure (); |
| 6563 |
if (close_flag) |
| 6564 |
switch (st) |
| 6565 |
{ |
| 6566 |
case ST_GOTO: |
| 6567 |
case ST_END_PROGRAM: |
| 6568 |
case ST_RETURN: |
| 6569 |
case ST_EXIT: |
| 6570 |
case ST_END_FUNCTION: |
| 6571 |
case ST_CYCLE: |
| 6572 |
case ST_PAUSE: |
| 6573 |
case ST_STOP: |
| 6574 |
case ST_ERROR_STOP: |
| 6575 |
case ST_END_SUBROUTINE: |
| 6576 |
|
| 6577 |
case ST_DO: |
| 6578 |
case ST_FORALL: |
| 6579 |
case ST_WHERE: |
| 6580 |
case ST_SELECT_CASE: |
| 6581 |
gfc_error ("%s statement at %C cannot terminate a non-block " |
| 6582 |
"DO loop", gfc_ascii_statement (st)); |
| 6583 |
break; |
| 6584 |
|
| 6585 |
default: |
| 6586 |
break; |
| 6587 |
} |
| 6588 |
|
| 6589 |
switch (st) |
| 6590 |
{ |
| 6591 |
case ST_NONE: |
| 6592 |
unexpected_eof (); |
| 6593 |
|
| 6594 |
case ST_DATA: |
| 6595 |
gfc_notify_std (GFC_STD_F95_OBS, "DATA statement at %C after the " |
| 6596 |
"first executable statement"); |
| 6597 |
/* Fall through. */ |
| 6598 |
|
| 6599 |
case ST_FORMAT: |
| 6600 |
case ST_ENTRY: |
| 6601 |
case_executable: |
| 6602 |
accept_statement (st); |
| 6603 |
if (close_flag == 1) |
| 6604 |
return ST_IMPLIED_ENDDO; |
| 6605 |
break; |
| 6606 |
|
| 6607 |
case ST_BLOCK: |
| 6608 |
parse_block_construct (); |
| 6609 |
break; |
| 6610 |
|
| 6611 |
case ST_ASSOCIATE: |
| 6612 |
parse_associate (); |
| 6613 |
break; |
| 6614 |
|
| 6615 |
case ST_IF_BLOCK: |
| 6616 |
parse_if_block (); |
| 6617 |
break; |
| 6618 |
|
| 6619 |
case ST_SELECT_CASE: |
| 6620 |
parse_select_block (); |
| 6621 |
break; |
| 6622 |
|
| 6623 |
case ST_SELECT_TYPE: |
| 6624 |
parse_select_type_block (); |
| 6625 |
break; |
| 6626 |
|
| 6627 |
case ST_SELECT_RANK: |
| 6628 |
parse_select_rank_block (); |
| 6629 |
break; |
| 6630 |
|
| 6631 |
case ST_DO: |
| 6632 |
parse_do_block (); |
| 6633 |
if (check_do_closure () == 1) |
| 6634 |
return ST_IMPLIED_ENDDO; |
| 6635 |
break; |
| 6636 |
|
| 6637 |
case ST_CRITICAL: |
| 6638 |
parse_critical_block (); |
| 6639 |
break; |
| 6640 |
|
| 6641 |
case ST_WHERE_BLOCK: |
| 6642 |
parse_where_block (); |
| 6643 |
break; |
| 6644 |
|
| 6645 |
case ST_FORALL_BLOCK: |
| 6646 |
parse_forall_block (); |
| 6647 |
break; |
| 6648 |
|
| 6649 |
case ST_OACC_PARALLEL_LOOP: |
| 6650 |
case ST_OACC_KERNELS_LOOP: |
| 6651 |
case ST_OACC_SERIAL_LOOP: |
| 6652 |
case ST_OACC_LOOP: |
| 6653 |
st = parse_oacc_loop (st); |
| 6654 |
if (st == ST_IMPLIED_ENDDO) |
| 6655 |
return st; |
| 6656 |
continue; |
| 6657 |
|
| 6658 |
case ST_OACC_PARALLEL: |
| 6659 |
case ST_OACC_KERNELS: |
| 6660 |
case ST_OACC_SERIAL: |
| 6661 |
case ST_OACC_DATA: |
| 6662 |
case ST_OACC_HOST_DATA: |
| 6663 |
parse_oacc_structured_block (st); |
| 6664 |
break; |
| 6665 |
|
| 6666 |
case ST_OMP_ALLOCATE_EXEC: |
| 6667 |
case ST_OMP_ALLOCATORS: |
| 6668 |
st = parse_openmp_allocate_block (st); |
| 6669 |
continue; |
| 6670 |
|
| 6671 |
case_omp_structured_block: |
| 6672 |
st = parse_omp_structured_block (st, |
| 6673 |
st == ST_OMP_WORKSHARE |
| 6674 |
|| st == ST_OMP_PARALLEL_WORKSHARE); |
| 6675 |
continue; |
| 6676 |
|
| 6677 |
case_omp_do: |
| 6678 |
st = parse_omp_do (st, 0); |
| 6679 |
if (st == ST_IMPLIED_ENDDO) |
| 6680 |
return st; |
| 6681 |
continue; |
| 6682 |
|
| 6683 |
case ST_OACC_ATOMIC: |
| 6684 |
st = parse_omp_oacc_atomic (false); |
| 6685 |
continue; |
| 6686 |
|
| 6687 |
case ST_OMP_ATOMIC: |
| 6688 |
st = parse_omp_oacc_atomic (true); |
| 6689 |
continue; |
| 6690 |
|
| 6691 |
case ST_OMP_DISPATCH: |
| 6692 |
st = parse_omp_dispatch (); |
| 6693 |
continue; |
| 6694 |
|
| 6695 |
case ST_OMP_METADIRECTIVE: |
| 6696 |
case ST_OMP_BEGIN_METADIRECTIVE: |
| 6697 |
st = parse_omp_metadirective_body (st); |
| 6698 |
continue; |
| 6699 |
|
| 6700 |
case ST_OMP_END_METADIRECTIVE: |
| 6701 |
if (gfc_state_stack->state == COMP_OMP_BEGIN_METADIRECTIVE) |
| 6702 |
return next_statement (); |
| 6703 |
else |
| 6704 |
return st; |
| 6705 |
|
| 6706 |
default: |
| 6707 |
return st; |
| 6708 |
} |
| 6709 |
|
| 6710 |
if (directive_unroll != -1) |
| 6711 |
gfc_error ("%<GCC unroll%> directive not at the start of a loop at %C"); |
| 6712 |
|
| 6713 |
if (directive_ivdep) |
| 6714 |
gfc_error ("%<GCC ivdep%> directive not at the start of a loop at %C"); |
| 6715 |
|
| 6716 |
if (directive_vector) |
| 6717 |
gfc_error ("%<GCC vector%> directive not at the start of a loop at %C"); |
| 6718 |
|
| 6719 |
if (directive_novector) |
| 6720 |
gfc_error ("%<GCC novector%> " |
| 6721 |
"directive not at the start of a loop at %C"); |
| 6722 |
|
| 6723 |
st = next_statement (); |
| 6724 |
} |
| 6725 |
} |
| 6726 |
|
| 6727 |
|
| 6728 |
/* Update statement function formal argument lists that reference OLD_SYM |
| 6729 |
to point to NEW_SYM instead. This prevents use-after-free when |
| 6730 |
gfc_fixup_sibling_symbols replaces and frees a symbol that is also |
| 6731 |
used as a statement function dummy argument (PR95879). */ |
| 6732 |
|
| 6733 |
static void |
| 6734 |
fixup_st_func_formals (gfc_symtree *st, gfc_symbol *old_sym, |
| 6735 |
gfc_symbol *new_sym) |
| 6736 |
{ |
| 6737 |
if (st == NULL) |
| 6738 |
return; |
| 6739 |
|
| 6740 |
fixup_st_func_formals (st->left, old_sym, new_sym); |
| 6741 |
fixup_st_func_formals (st->right, old_sym, new_sym); |
| 6742 |
|
| 6743 |
if (st->n.sym && st->n.sym->attr.proc == PROC_ST_FUNCTION) |
| 6744 |
for (gfc_formal_arglist *fa = st->n.sym->formal; fa; fa = fa->next) |
| 6745 |
if (fa->sym == old_sym) |
| 6746 |
fa->sym = new_sym; |
| 6747 |
} |
| 6748 |
|
| 6749 |
|
| 6750 |
/* Fix the symbols for sibling functions. These are incorrectly added to |
| 6751 |
the child namespace as the parser didn't know about this procedure. */ |
| 6752 |
|
| 6753 |
static void |
| 6754 |
gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings) |
| 6755 |
{ |
| 6756 |
gfc_namespace *ns; |
| 6757 |
gfc_symtree *st; |
| 6758 |
gfc_symbol *old_sym; |
| 6759 |
|
| 6760 |
for (ns = siblings; ns; ns = ns->sibling) |
| 6761 |
{ |
| 6762 |
st = gfc_find_symtree (ns->sym_root, sym->name); |
| 6763 |
|
| 6764 |
if (!st || (st->n.sym->attr.dummy && ns == st->n.sym->ns)) |
| 6765 |
goto fixup_contained; |
| 6766 |
|
| 6767 |
if ((st->n.sym->attr.flavor == FL_DERIVED |
| 6768 |
&& sym->attr.generic && sym->attr.function) |
| 6769 |
||(sym->attr.flavor == FL_DERIVED |
| 6770 |
&& st->n.sym->attr.generic && st->n.sym->attr.function)) |
| 6771 |
goto fixup_contained; |
| 6772 |
|
| 6773 |
old_sym = st->n.sym; |
| 6774 |
if (old_sym->ns == ns |
| 6775 |
&& !old_sym->attr.contained |
| 6776 |
|
| 6777 |
/* By 14.6.1.3, host association should be excluded |
| 6778 |
for the following. */ |
| 6779 |
&& !(old_sym->attr.external |
| 6780 |
|| (old_sym->ts.type != BT_UNKNOWN |
| 6781 |
&& !old_sym->attr.implicit_type) |
| 6782 |
|| old_sym->attr.flavor == FL_PARAMETER |
| 6783 |
|| old_sym->attr.use_assoc |
| 6784 |
|| old_sym->attr.in_common |
| 6785 |
|| old_sym->attr.in_equivalence |
| 6786 |
|| old_sym->attr.data |
| 6787 |
|| old_sym->attr.dummy |
| 6788 |
|| old_sym->attr.result |
| 6789 |
|| old_sym->attr.dimension |
| 6790 |
|| old_sym->attr.allocatable |
| 6791 |
|| old_sym->attr.intrinsic |
| 6792 |
|| old_sym->attr.generic |
| 6793 |
|| old_sym->attr.flavor == FL_NAMELIST |
| 6794 |
|| old_sym->attr.flavor == FL_LABEL |
| 6795 |
|| old_sym->attr.proc == PROC_ST_FUNCTION)) |
| 6796 |
{ |
| 6797 |
/* Replace it with the symbol from the parent namespace. */ |
| 6798 |
st->n.sym = sym; |
| 6799 |
sym->refs++; |
| 6800 |
|
| 6801 |
/* Update statement function formal argument lists that still |
| 6802 |
reference old_sym before releasing it (PR95879). */ |
| 6803 |
fixup_st_func_formals (ns->sym_root, old_sym, sym); |
| 6804 |
|
| 6805 |
|
| 6806 |
gfc_release_symbol (old_sym); |
| 6807 |
} |
| 6808 |
|
| 6809 |
fixup_contained: |
| 6810 |
/* Do the same for any contained procedures. */ |
| 6811 |
gfc_fixup_sibling_symbols (sym, ns->contained); |
| 6812 |
} |
| 6813 |
} |
| 6814 |
|
| 6815 |
static void |
| 6816 |
parse_contained (int module) |
| 6817 |
{ |
| 6818 |
gfc_namespace *ns, *parent_ns, *tmp; |
| 6819 |
gfc_state_data s1, s2; |
| 6820 |
gfc_statement st; |
| 6821 |
gfc_symbol *sym; |
| 6822 |
gfc_entry_list *el; |
| 6823 |
locus old_loc; |
| 6824 |
int contains_statements = 0; |
| 6825 |
int seen_error = 0; |
| 6826 |
|
| 6827 |
push_state (&s1, COMP_CONTAINS, NULL); |
| 6828 |
parent_ns = gfc_current_ns; |
| 6829 |
|
| 6830 |
do |
| 6831 |
{ |
| 6832 |
gfc_current_ns = gfc_get_namespace (parent_ns, 1); |
| 6833 |
|
| 6834 |
gfc_current_ns->sibling = parent_ns->contained; |
| 6835 |
parent_ns->contained = gfc_current_ns; |
| 6836 |
|
| 6837 |
next: |
| 6838 |
/* Process the next available statement. We come here if we got an error |
| 6839 |
and rejected the last statement. */ |
| 6840 |
old_loc = gfc_current_locus; |
| 6841 |
st = next_statement (); |
| 6842 |
|
| 6843 |
switch (st) |
| 6844 |
{ |
| 6845 |
case ST_NONE: |
| 6846 |
unexpected_eof (); |
| 6847 |
|
| 6848 |
case ST_FUNCTION: |
| 6849 |
case ST_SUBROUTINE: |
| 6850 |
contains_statements = 1; |
| 6851 |
accept_statement (st); |
| 6852 |
|
| 6853 |
push_state (&s2, |
| 6854 |
(st == ST_FUNCTION) ? COMP_FUNCTION : COMP_SUBROUTINE, |
| 6855 |
gfc_new_block); |
| 6856 |
|
| 6857 |
/* For internal procedures, create/update the symbol in the |
| 6858 |
parent namespace. */ |
| 6859 |
|
| 6860 |
if (!module) |
| 6861 |
{ |
| 6862 |
if (gfc_get_symbol (gfc_new_block->name, parent_ns, &sym)) |
| 6863 |
gfc_error ("Contained procedure %qs at %C is already " |
| 6864 |
"ambiguous", gfc_new_block->name); |
| 6865 |
else |
| 6866 |
{ |
| 6867 |
if (gfc_add_procedure (&sym->attr, PROC_INTERNAL, |
| 6868 |
sym->name, |
| 6869 |
&gfc_new_block->declared_at)) |
| 6870 |
{ |
| 6871 |
if (st == ST_FUNCTION) |
| 6872 |
gfc_add_function (&sym->attr, sym->name, |
| 6873 |
&gfc_new_block->declared_at); |
| 6874 |
else |
| 6875 |
gfc_add_subroutine (&sym->attr, sym->name, |
| 6876 |
&gfc_new_block->declared_at); |
| 6877 |
} |
| 6878 |
} |
| 6879 |
|
| 6880 |
gfc_commit_symbols (); |
| 6881 |
} |
| 6882 |
else |
| 6883 |
sym = gfc_new_block; |
| 6884 |
|
| 6885 |
/* Mark this as a contained function, so it isn't replaced |
| 6886 |
by other module functions. */ |
| 6887 |
sym->attr.contained = 1; |
| 6888 |
|
| 6889 |
/* Set implicit_pure so that it can be reset if any of the |
| 6890 |
tests for purity fail. This is used for some optimisation |
| 6891 |
during translation. */ |
| 6892 |
if (!sym->attr.pure) |
| 6893 |
sym->attr.implicit_pure = 1; |
| 6894 |
|
| 6895 |
parse_progunit (ST_NONE); |
| 6896 |
|
| 6897 |
/* Fix up any sibling functions that refer to this one. */ |
| 6898 |
gfc_fixup_sibling_symbols (sym, gfc_current_ns); |
| 6899 |
/* Or refer to any of its alternate entry points. */ |
| 6900 |
for (el = gfc_current_ns->entries; el; el = el->next) |
| 6901 |
gfc_fixup_sibling_symbols (el->sym, gfc_current_ns); |
| 6902 |
|
| 6903 |
gfc_current_ns->code = s2.head; |
| 6904 |
gfc_current_ns = parent_ns; |
| 6905 |
|
| 6906 |
pop_state (); |
| 6907 |
break; |
| 6908 |
|
| 6909 |
/* These statements are associated with the end of the host unit. */ |
| 6910 |
case ST_END_FUNCTION: |
| 6911 |
case ST_END_MODULE: |
| 6912 |
case ST_END_SUBMODULE: |
| 6913 |
case ST_END_PROGRAM: |
| 6914 |
case ST_END_SUBROUTINE: |
| 6915 |
accept_statement (st); |
| 6916 |
gfc_current_ns->code = s1.head; |
| 6917 |
break; |
| 6918 |
|
| 6919 |
default: |
| 6920 |
gfc_error ("Unexpected %s statement in CONTAINS section at %C", |
| 6921 |
gfc_ascii_statement (st)); |
| 6922 |
reject_statement (); |
| 6923 |
seen_error = 1; |
| 6924 |
goto next; |
| 6925 |
break; |
| 6926 |
} |
| 6927 |
} |
| 6928 |
while (st != ST_END_FUNCTION && st != ST_END_SUBROUTINE |
| 6929 |
&& st != ST_END_MODULE && st != ST_END_SUBMODULE |
| 6930 |
&& st != ST_END_PROGRAM); |
| 6931 |
|
| 6932 |
/* The first namespace in the list is guaranteed to not have |
| 6933 |
anything (worthwhile) in it. */ |
| 6934 |
tmp = gfc_current_ns; |
| 6935 |
gfc_current_ns = parent_ns; |
| 6936 |
if (seen_error && tmp->refs > 1) |
| 6937 |
gfc_free_namespace (tmp); |
| 6938 |
|
| 6939 |
ns = gfc_current_ns->contained; |
| 6940 |
gfc_current_ns->contained = ns->sibling; |
| 6941 |
gfc_free_namespace (ns); |
| 6942 |
|
| 6943 |
pop_state (); |
| 6944 |
if (!contains_statements) |
| 6945 |
gfc_notify_std (GFC_STD_F2008, "CONTAINS statement without " |
| 6946 |
"FUNCTION or SUBROUTINE statement at %L", &old_loc); |
| 6947 |
} |
| 6948 |
|
| 6949 |
|
| 6950 |
/* The result variable in a MODULE PROCEDURE needs to be created and |
| 6951 |
its characteristics copied from the interface since it is neither |
| 6952 |
declared in the procedure declaration nor in the specification |
| 6953 |
part. */ |
| 6954 |
|
| 6955 |
static void |
| 6956 |
get_modproc_result (void) |
| 6957 |
{ |
| 6958 |
gfc_symbol *proc; |
| 6959 |
if (gfc_state_stack->previous |
| 6960 |
&& gfc_state_stack->previous->state == COMP_CONTAINS |
| 6961 |
&& gfc_state_stack->previous->previous->state == COMP_SUBMODULE) |
| 6962 |
{ |
| 6963 |
proc = gfc_current_ns->proc_name ? gfc_current_ns->proc_name : NULL; |
| 6964 |
if (proc != NULL |
| 6965 |
&& proc->attr.function |
| 6966 |
&& proc->tlink |
| 6967 |
&& proc->tlink->result |
| 6968 |
&& proc->tlink->result != proc->tlink) |
| 6969 |
{ |
| 6970 |
gfc_copy_dummy_sym (&proc->result, proc->tlink->result, 1); |
| 6971 |
gfc_set_sym_referenced (proc->result); |
| 6972 |
proc->result->attr.if_source = IFSRC_DECL; |
| 6973 |
gfc_commit_symbol (proc->result); |
| 6974 |
} |
| 6975 |
} |
| 6976 |
} |
| 6977 |
|
| 6978 |
|
| 6979 |
/* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */ |
| 6980 |
|
| 6981 |
static void |
| 6982 |
parse_progunit (gfc_statement st) |
| 6983 |
{ |
| 6984 |
gfc_state_data *p; |
| 6985 |
int n; |
| 6986 |
|
| 6987 |
gfc_adjust_builtins (); |
| 6988 |
|
| 6989 |
if (gfc_new_block |
| 6990 |
&& gfc_new_block->abr_modproc_decl |
| 6991 |
&& gfc_new_block->attr.function) |
| 6992 |
get_modproc_result (); |
| 6993 |
|
| 6994 |
st = parse_spec (st); |
| 6995 |
switch (st) |
| 6996 |
{ |
| 6997 |
case ST_NONE: |
| 6998 |
unexpected_eof (); |
| 6999 |
|
| 7000 |
case ST_CONTAINS: |
| 7001 |
/* This is not allowed within BLOCK! */ |
| 7002 |
if (gfc_current_state () != COMP_BLOCK) |
| 7003 |
goto contains; |
| 7004 |
break; |
| 7005 |
|
| 7006 |
case_end: |
| 7007 |
accept_statement (st); |
| 7008 |
goto done; |
| 7009 |
|
| 7010 |
default: |
| 7011 |
break; |
| 7012 |
} |
| 7013 |
|
| 7014 |
if (gfc_current_state () == COMP_FUNCTION) |
| 7015 |
gfc_check_function_type (gfc_current_ns); |
| 7016 |
|
| 7017 |
loop: |
| 7018 |
for (;;) |
| 7019 |
{ |
| 7020 |
st = parse_executable (st); |
| 7021 |
|
| 7022 |
switch (st) |
| 7023 |
{ |
| 7024 |
case ST_NONE: |
| 7025 |
unexpected_eof (); |
| 7026 |
|
| 7027 |
case ST_CONTAINS: |
| 7028 |
/* This is not allowed within BLOCK! */ |
| 7029 |
if (gfc_current_state () != COMP_BLOCK) |
| 7030 |
goto contains; |
| 7031 |
break; |
| 7032 |
|
| 7033 |
case_end: |
| 7034 |
accept_statement (st); |
| 7035 |
goto done; |
| 7036 |
|
| 7037 |
default: |
| 7038 |
break; |
| 7039 |
} |
| 7040 |
|
| 7041 |
unexpected_statement (st); |
| 7042 |
reject_statement (); |
| 7043 |
st = next_statement (); |
| 7044 |
} |
| 7045 |
|
| 7046 |
contains: |
| 7047 |
n = 0; |
| 7048 |
|
| 7049 |
for (p = gfc_state_stack; p; p = p->previous) |
| 7050 |
if (p->state == COMP_CONTAINS) |
| 7051 |
n++; |
| 7052 |
|
| 7053 |
if (gfc_find_state (COMP_MODULE) == true |
| 7054 |
|| gfc_find_state (COMP_SUBMODULE) == true) |
| 7055 |
n--; |
| 7056 |
|
| 7057 |
if (n > 0) |
| 7058 |
{ |
| 7059 |
gfc_error ("CONTAINS statement at %C is already in a contained " |
| 7060 |
"program unit"); |
| 7061 |
reject_statement (); |
| 7062 |
st = next_statement (); |
| 7063 |
goto loop; |
| 7064 |
} |
| 7065 |
|
| 7066 |
parse_contained (0); |
| 7067 |
|
| 7068 |
done: |
| 7069 |
gfc_current_ns->code = gfc_state_stack->head; |
| 7070 |
} |
| 7071 |
|
| 7072 |
|
| 7073 |
/* Come here to complain about a global symbol already in use as |
| 7074 |
something else. */ |
| 7075 |
|
| 7076 |
void |
| 7077 |
gfc_global_used (gfc_gsymbol *sym, locus *where) |
| 7078 |
{ |
| 7079 |
const char *name; |
| 7080 |
|
| 7081 |
if (where == NULL) |
| 7082 |
where = &gfc_current_locus; |
| 7083 |
|
| 7084 |
switch(sym->type) |
| 7085 |
{ |
| 7086 |
case GSYM_PROGRAM: |
| 7087 |
name = "PROGRAM"; |
| 7088 |
break; |
| 7089 |
case GSYM_FUNCTION: |
| 7090 |
name = "FUNCTION"; |
| 7091 |
break; |
| 7092 |
case GSYM_SUBROUTINE: |
| 7093 |
name = "SUBROUTINE"; |
| 7094 |
break; |
| 7095 |
case GSYM_COMMON: |
| 7096 |
name = "COMMON"; |
| 7097 |
break; |
| 7098 |
case GSYM_BLOCK_DATA: |
| 7099 |
name = "BLOCK DATA"; |
| 7100 |
break; |
| 7101 |
case GSYM_MODULE: |
| 7102 |
name = "MODULE"; |
| 7103 |
break; |
| 7104 |
default: |
| 7105 |
name = NULL; |
| 7106 |
} |
| 7107 |
|
| 7108 |
if (name) |
| 7109 |
{ |
| 7110 |
if (sym->binding_label) |
| 7111 |
gfc_error ("Global binding name %qs at %L is already being used " |
| 7112 |
"as a %s at %L", sym->binding_label, where, name, |
| 7113 |
&sym->where); |
| 7114 |
else |
| 7115 |
gfc_error ("Global name %qs at %L is already being used as " |
| 7116 |
"a %s at %L", sym->name, where, name, &sym->where); |
| 7117 |
} |
| 7118 |
else |
| 7119 |
{ |
| 7120 |
if (sym->binding_label) |
| 7121 |
gfc_error ("Global binding name %qs at %L is already being used " |
| 7122 |
"at %L", sym->binding_label, where, &sym->where); |
| 7123 |
else |
| 7124 |
gfc_error ("Global name %qs at %L is already being used at %L", |
| 7125 |
sym->name, where, &sym->where); |
| 7126 |
} |
| 7127 |
} |
| 7128 |
|
| 7129 |
|
| 7130 |
/* Parse a block data program unit. */ |
| 7131 |
|
| 7132 |
static void |
| 7133 |
parse_block_data (void) |
| 7134 |
{ |
| 7135 |
gfc_statement st; |
| 7136 |
static locus blank_locus; |
| 7137 |
static int blank_block=0; |
| 7138 |
gfc_gsymbol *s; |
| 7139 |
|
| 7140 |
gfc_current_ns->proc_name = gfc_new_block; |
| 7141 |
gfc_current_ns->is_block_data = 1; |
| 7142 |
|
| 7143 |
if (gfc_new_block == NULL) |
| 7144 |
{ |
| 7145 |
if (blank_block) |
| 7146 |
gfc_error ("Blank BLOCK DATA at %C conflicts with " |
| 7147 |
"prior BLOCK DATA at %L", &blank_locus); |
| 7148 |
else |
| 7149 |
{ |
| 7150 |
blank_block = 1; |
| 7151 |
blank_locus = gfc_current_locus; |
| 7152 |
} |
| 7153 |
} |
| 7154 |
else |
| 7155 |
{ |
| 7156 |
s = gfc_get_gsymbol (gfc_new_block->name, false); |
| 7157 |
if (s->defined |
| 7158 |
|| (s->type != GSYM_UNKNOWN && s->type != GSYM_BLOCK_DATA)) |
| 7159 |
gfc_global_used (s, &gfc_new_block->declared_at); |
| 7160 |
else |
| 7161 |
{ |
| 7162 |
s->type = GSYM_BLOCK_DATA; |
| 7163 |
s->where = gfc_new_block->declared_at; |
| 7164 |
s->defined = 1; |
| 7165 |
} |
| 7166 |
} |
| 7167 |
|
| 7168 |
st = parse_spec (ST_NONE); |
| 7169 |
|
| 7170 |
while (st != ST_END_BLOCK_DATA) |
| 7171 |
{ |
| 7172 |
gfc_error ("Unexpected %s statement in BLOCK DATA at %C", |
| 7173 |
gfc_ascii_statement (st)); |
| 7174 |
reject_statement (); |
| 7175 |
st = next_statement (); |
| 7176 |
} |
| 7177 |
} |
| 7178 |
|
| 7179 |
|
| 7180 |
/* Following the association of the ancestor (sub)module symbols, they |
| 7181 |
must be set host rather than use associated and all must be public. |
| 7182 |
They are flagged up by 'used_in_submodule' so that they can be set |
| 7183 |
DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the |
| 7184 |
linker chokes on multiple symbol definitions. */ |
| 7185 |
|
| 7186 |
static void |
| 7187 |
set_syms_host_assoc (gfc_symbol *sym) |
| 7188 |
{ |
| 7189 |
gfc_component *c; |
| 7190 |
const char dot[2] = "."; |
| 7191 |
/* Symbols take the form module.submodule_ or module.name_. */ |
| 7192 |
char parent1[2 * GFC_MAX_SYMBOL_LEN + 2]; |
| 7193 |
char parent2[2 * GFC_MAX_SYMBOL_LEN + 2]; |
| 7194 |
|
| 7195 |
if (sym == NULL) |
| 7196 |
return; |
| 7197 |
|
| 7198 |
if (sym->attr.module_procedure) |
| 7199 |
sym->attr.external = 0; |
| 7200 |
|
| 7201 |
sym->attr.use_assoc = 0; |
| 7202 |
sym->attr.host_assoc = 1; |
| 7203 |
sym->attr.used_in_submodule =1; |
| 7204 |
|
| 7205 |
if (sym->attr.flavor == FL_DERIVED) |
| 7206 |
{ |
| 7207 |
/* Derived types with PRIVATE components that are declared in |
| 7208 |
modules other than the parent module must not be changed to be |
| 7209 |
PUBLIC. The 'use-assoc' attribute must be reset so that the |
| 7210 |
test in symbol.cc(gfc_find_component) works correctly. This is |
| 7211 |
not necessary for PRIVATE symbols since they are not read from |
| 7212 |
the module. */ |
| 7213 |
memset(parent1, '\0', sizeof(parent1)); |
| 7214 |
memset(parent2, '\0', sizeof(parent2)); |
| 7215 |
strcpy (parent1, gfc_new_block->name); |
| 7216 |
strcpy (parent2, sym->module); |
| 7217 |
if (strcmp (strtok (parent1, dot), strtok (parent2, dot)) == 0) |
| 7218 |
{ |
| 7219 |
for (c = sym->components; c; c = c->next) |
| 7220 |
c->attr.access = ACCESS_PUBLIC; |
| 7221 |
} |
| 7222 |
else |
| 7223 |
{ |
| 7224 |
sym->attr.use_assoc = 1; |
| 7225 |
sym->attr.host_assoc = 0; |
| 7226 |
} |
| 7227 |
} |
| 7228 |
} |
| 7229 |
|
| 7230 |
/* Parse a module subprogram. */ |
| 7231 |
|
| 7232 |
static void |
| 7233 |
parse_module (void) |
| 7234 |
{ |
| 7235 |
gfc_statement st; |
| 7236 |
gfc_gsymbol *s; |
| 7237 |
|
| 7238 |
s = gfc_get_gsymbol (gfc_new_block->name, false); |
| 7239 |
if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_MODULE)) |
| 7240 |
gfc_global_used (s, &gfc_new_block->declared_at); |
| 7241 |
else |
| 7242 |
{ |
| 7243 |
s->type = GSYM_MODULE; |
| 7244 |
s->where = gfc_new_block->declared_at; |
| 7245 |
s->defined = 1; |
| 7246 |
} |
| 7247 |
|
| 7248 |
/* Something is nulling the module_list after this point. This is good |
| 7249 |
since it allows us to 'USE' the parent modules that the submodule |
| 7250 |
inherits and to set (most) of the symbols as host associated. */ |
| 7251 |
if (gfc_current_state () == COMP_SUBMODULE) |
| 7252 |
{ |
| 7253 |
use_modules (); |
| 7254 |
gfc_traverse_ns (gfc_current_ns, set_syms_host_assoc); |
| 7255 |
} |
| 7256 |
|
| 7257 |
st = parse_spec (ST_NONE); |
| 7258 |
|
| 7259 |
loop: |
| 7260 |
switch (st) |
| 7261 |
{ |
| 7262 |
case ST_NONE: |
| 7263 |
unexpected_eof (); |
| 7264 |
|
| 7265 |
case ST_CONTAINS: |
| 7266 |
parse_contained (1); |
| 7267 |
break; |
| 7268 |
|
| 7269 |
case ST_END_MODULE: |
| 7270 |
case ST_END_SUBMODULE: |
| 7271 |
accept_statement (st); |
| 7272 |
break; |
| 7273 |
|
| 7274 |
default: |
| 7275 |
gfc_error ("Unexpected %s statement in MODULE at %C", |
| 7276 |
gfc_ascii_statement (st)); |
| 7277 |
reject_statement (); |
| 7278 |
st = next_statement (); |
| 7279 |
goto loop; |
| 7280 |
} |
| 7281 |
s->ns = gfc_current_ns; |
| 7282 |
} |
| 7283 |
|
| 7284 |
|
| 7285 |
/* Add a procedure name to the global symbol table. */ |
| 7286 |
|
| 7287 |
static void |
| 7288 |
add_global_procedure (bool sub) |
| 7289 |
{ |
| 7290 |
gfc_gsymbol *s; |
| 7291 |
|
| 7292 |
/* Only in Fortran 2003: For procedures with a binding label also the Fortran |
| 7293 |
name is a global identifier. */ |
| 7294 |
if (!gfc_new_block->binding_label || gfc_notification_std (GFC_STD_F2008)) |
| 7295 |
{ |
| 7296 |
s = gfc_get_gsymbol (gfc_new_block->name, false); |
| 7297 |
|
| 7298 |
if (s->defined |
| 7299 |
|| (s->type != GSYM_UNKNOWN |
| 7300 |
&& s->type != (sub ? GSYM_SUBROUTINE : GSYM_FUNCTION))) |
| 7301 |
{ |
| 7302 |
gfc_global_used (s, &gfc_new_block->declared_at); |
| 7303 |
/* Silence follow-up errors. */ |
| 7304 |
gfc_new_block->binding_label = NULL; |
| 7305 |
} |
| 7306 |
else |
| 7307 |
{ |
| 7308 |
s->type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION; |
| 7309 |
s->sym_name = gfc_new_block->name; |
| 7310 |
s->where = gfc_new_block->declared_at; |
| 7311 |
s->defined = 1; |
| 7312 |
s->ns = gfc_current_ns; |
| 7313 |
} |
| 7314 |
} |
| 7315 |
|
| 7316 |
/* Don't add the symbol multiple times. */ |
| 7317 |
if (gfc_new_block->binding_label |
| 7318 |
&& (!gfc_notification_std (GFC_STD_F2008) |
| 7319 |
|| strcmp (gfc_new_block->name, gfc_new_block->binding_label) != 0)) |
| 7320 |
{ |
| 7321 |
s = gfc_get_gsymbol (gfc_new_block->binding_label, true); |
| 7322 |
|
| 7323 |
if (s->defined |
| 7324 |
|| (s->type != GSYM_UNKNOWN |
| 7325 |
&& s->type != (sub ? GSYM_SUBROUTINE : GSYM_FUNCTION))) |
| 7326 |
{ |
| 7327 |
gfc_global_used (s, &gfc_new_block->declared_at); |
| 7328 |
/* Silence follow-up errors. */ |
| 7329 |
gfc_new_block->binding_label = NULL; |
| 7330 |
} |
| 7331 |
else |
| 7332 |
{ |
| 7333 |
s->type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION; |
| 7334 |
s->sym_name = gfc_new_block->name; |
| 7335 |
s->binding_label = gfc_new_block->binding_label; |
| 7336 |
s->where = gfc_new_block->declared_at; |
| 7337 |
s->defined = 1; |
| 7338 |
s->ns = gfc_current_ns; |
| 7339 |
} |
| 7340 |
} |
| 7341 |
} |
| 7342 |
|
| 7343 |
|
| 7344 |
/* Add a program to the global symbol table. */ |
| 7345 |
|
| 7346 |
static void |
| 7347 |
add_global_program (void) |
| 7348 |
{ |
| 7349 |
gfc_gsymbol *s; |
| 7350 |
|
| 7351 |
if (gfc_new_block == NULL) |
| 7352 |
return; |
| 7353 |
s = gfc_get_gsymbol (gfc_new_block->name, false); |
| 7354 |
|
| 7355 |
if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_PROGRAM)) |
| 7356 |
gfc_global_used (s, &gfc_new_block->declared_at); |
| 7357 |
else |
| 7358 |
{ |
| 7359 |
s->type = GSYM_PROGRAM; |
| 7360 |
s->where = gfc_new_block->declared_at; |
| 7361 |
s->defined = 1; |
| 7362 |
s->ns = gfc_current_ns; |
| 7363 |
} |
| 7364 |
} |
| 7365 |
|
| 7366 |
/* Rewrite expression where needed. |
| 7367 |
- Currently this is done for co-indexed expressions only. |
| 7368 |
*/ |
| 7369 |
static void |
| 7370 |
rewrite_expr_tree (gfc_namespace *gfc_global_ns_list) |
| 7371 |
{ |
| 7372 |
for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns; |
| 7373 |
gfc_current_ns = gfc_current_ns->sibling) |
| 7374 |
gfc_coarray_rewrite (gfc_current_ns); |
| 7375 |
} |
| 7376 |
|
| 7377 |
/* Resolve all the program units. */ |
| 7378 |
static void |
| 7379 |
resolve_all_program_units (gfc_namespace *gfc_global_ns_list) |
| 7380 |
{ |
| 7381 |
gfc_derived_types = NULL; |
| 7382 |
gfc_current_ns = gfc_global_ns_list; |
| 7383 |
for (; gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling) |
| 7384 |
{ |
| 7385 |
if (gfc_current_ns->proc_name |
| 7386 |
&& gfc_current_ns->proc_name->attr.flavor == FL_MODULE) |
| 7387 |
continue; /* Already resolved. */ |
| 7388 |
|
| 7389 |
if (gfc_current_ns->proc_name) |
| 7390 |
gfc_current_locus = gfc_current_ns->proc_name->declared_at; |
| 7391 |
gfc_resolve (gfc_current_ns); |
| 7392 |
gfc_current_ns->derived_types = gfc_derived_types; |
| 7393 |
gfc_derived_types = NULL; |
| 7394 |
} |
| 7395 |
} |
| 7396 |
|
| 7397 |
|
| 7398 |
static void |
| 7399 |
clean_up_modules (gfc_gsymbol *&gsym) |
| 7400 |
{ |
| 7401 |
if (gsym == NULL) |
| 7402 |
return; |
| 7403 |
|
| 7404 |
clean_up_modules (gsym->left); |
| 7405 |
clean_up_modules (gsym->right); |
| 7406 |
|
| 7407 |
if (gsym->type != GSYM_MODULE) |
| 7408 |
return; |
| 7409 |
|
| 7410 |
if (gsym->ns) |
| 7411 |
{ |
| 7412 |
gfc_current_ns = gsym->ns; |
| 7413 |
gfc_derived_types = gfc_current_ns->derived_types; |
| 7414 |
gfc_done_2 (); |
| 7415 |
gsym->ns = NULL; |
| 7416 |
} |
| 7417 |
free (gsym); |
| 7418 |
gsym = NULL; |
| 7419 |
} |
| 7420 |
|
| 7421 |
|
| 7422 |
/* Translate all the program units. This could be in a different order |
| 7423 |
to resolution if there are forward references in the file. */ |
| 7424 |
static void |
| 7425 |
translate_all_program_units (gfc_namespace *gfc_global_ns_list) |
| 7426 |
{ |
| 7427 |
int errors; |
| 7428 |
|
| 7429 |
gfc_current_ns = gfc_global_ns_list; |
| 7430 |
gfc_get_errors (NULL, &errors); |
| 7431 |
|
| 7432 |
/* We first translate all modules to make sure that later parts |
| 7433 |
of the program can use the decl. Then we translate the nonmodules. */ |
| 7434 |
|
| 7435 |
for (; !errors && gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling) |
| 7436 |
{ |
| 7437 |
if (!gfc_current_ns->proc_name |
| 7438 |
|| gfc_current_ns->proc_name->attr.flavor != FL_MODULE) |
| 7439 |
continue; |
| 7440 |
|
| 7441 |
gfc_current_locus = gfc_current_ns->proc_name->declared_at; |
| 7442 |
gfc_derived_types = gfc_current_ns->derived_types; |
| 7443 |
gfc_generate_module_code (gfc_current_ns); |
| 7444 |
gfc_current_ns->translated = 1; |
| 7445 |
} |
| 7446 |
|
| 7447 |
gfc_current_ns = gfc_global_ns_list; |
| 7448 |
for (; !errors && gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling) |
| 7449 |
{ |
| 7450 |
if (gfc_current_ns->proc_name |
| 7451 |
&& gfc_current_ns->proc_name->attr.flavor == FL_MODULE) |
| 7452 |
continue; |
| 7453 |
|
| 7454 |
gfc_current_locus = gfc_current_ns->proc_name->declared_at; |
| 7455 |
gfc_derived_types = gfc_current_ns->derived_types; |
| 7456 |
gfc_generate_code (gfc_current_ns); |
| 7457 |
gfc_current_ns->translated = 1; |
| 7458 |
} |
| 7459 |
|
| 7460 |
/* Clean up all the namespaces after translation. */ |
| 7461 |
gfc_current_ns = gfc_global_ns_list; |
| 7462 |
for (;gfc_current_ns;) |
| 7463 |
{ |
| 7464 |
gfc_namespace *ns; |
| 7465 |
|
| 7466 |
if (gfc_current_ns->proc_name |
| 7467 |
&& gfc_current_ns->proc_name->attr.flavor == FL_MODULE) |
| 7468 |
{ |
| 7469 |
gfc_current_ns = gfc_current_ns->sibling; |
| 7470 |
continue; |
| 7471 |
} |
| 7472 |
|
| 7473 |
ns = gfc_current_ns->sibling; |
| 7474 |
gfc_derived_types = gfc_current_ns->derived_types; |
| 7475 |
gfc_done_2 (); |
| 7476 |
gfc_current_ns = ns; |
| 7477 |
} |
| 7478 |
|
| 7479 |
clean_up_modules (gfc_gsym_root); |
| 7480 |
} |
| 7481 |
|
| 7482 |
|
| 7483 |
/* Top level parser. */ |
| 7484 |
|
| 7485 |
bool |
| 7486 |
gfc_parse_file (void) |
| 7487 |
{ |
| 7488 |
int seen_program, errors_before, errors; |
| 7489 |
gfc_state_data top, s; |
| 7490 |
gfc_statement st; |
| 7491 |
locus prog_locus; |
| 7492 |
gfc_namespace *next; |
| 7493 |
|
| 7494 |
gfc_start_source_files (); |
| 7495 |
|
| 7496 |
top.state = COMP_NONE; |
| 7497 |
top.sym = NULL; |
| 7498 |
top.previous = NULL; |
| 7499 |
top.head = top.tail = NULL; |
| 7500 |
top.do_variable = NULL; |
| 7501 |
|
| 7502 |
gfc_state_stack = ⊤ |
| 7503 |
|
| 7504 |
gfc_clear_new_st (); |
| 7505 |
|
| 7506 |
gfc_statement_label = NULL; |
| 7507 |
|
| 7508 |
gfc_omp_metadirective_region_count = 0; |
| 7509 |
gfc_in_omp_metadirective_body = false; |
| 7510 |
gfc_matching_omp_context_selector = false; |
| 7511 |
|
| 7512 |
if (setjmp (eof_buf)) |
| 7513 |
return false; /* Come here on unexpected EOF */ |
| 7514 |
|
| 7515 |
/* Prepare the global namespace that will contain the |
| 7516 |
program units. */ |
| 7517 |
gfc_global_ns_list = next = NULL; |
| 7518 |
|
| 7519 |
seen_program = 0; |
| 7520 |
errors_before = 0; |
| 7521 |
|
| 7522 |
/* Exit early for empty files. */ |
| 7523 |
if (gfc_at_eof ()) |
| 7524 |
goto done; |
| 7525 |
|
| 7526 |
in_specification_block = true; |
| 7527 |
loop: |
| 7528 |
gfc_init_2 (); |
| 7529 |
st = next_statement (); |
| 7530 |
switch (st) |
| 7531 |
{ |
| 7532 |
case ST_NONE: |
| 7533 |
gfc_done_2 (); |
| 7534 |
goto done; |
| 7535 |
|
| 7536 |
case ST_PROGRAM: |
| 7537 |
if (seen_program) |
| 7538 |
goto duplicate_main; |
| 7539 |
seen_program = 1; |
| 7540 |
prog_locus = gfc_current_locus; |
| 7541 |
|
| 7542 |
push_state (&s, COMP_PROGRAM, gfc_new_block); |
| 7543 |
main_program_symbol (gfc_current_ns, gfc_new_block->name); |
| 7544 |
accept_statement (st); |
| 7545 |
add_global_program (); |
| 7546 |
parse_progunit (ST_NONE); |
| 7547 |
goto prog_units; |
| 7548 |
|
| 7549 |
case ST_SUBROUTINE: |
| 7550 |
add_global_procedure (true); |
| 7551 |
push_state (&s, COMP_SUBROUTINE, gfc_new_block); |
| 7552 |
accept_statement (st); |
| 7553 |
parse_progunit (ST_NONE); |
| 7554 |
goto prog_units; |
| 7555 |
|
| 7556 |
case ST_FUNCTION: |
| 7557 |
add_global_procedure (false); |
| 7558 |
push_state (&s, COMP_FUNCTION, gfc_new_block); |
| 7559 |
accept_statement (st); |
| 7560 |
parse_progunit (ST_NONE); |
| 7561 |
goto prog_units; |
| 7562 |
|
| 7563 |
case ST_BLOCK_DATA: |
| 7564 |
push_state (&s, COMP_BLOCK_DATA, gfc_new_block); |
| 7565 |
accept_statement (st); |
| 7566 |
parse_block_data (); |
| 7567 |
break; |
| 7568 |
|
| 7569 |
case ST_MODULE: |
| 7570 |
push_state (&s, COMP_MODULE, gfc_new_block); |
| 7571 |
accept_statement (st); |
| 7572 |
|
| 7573 |
gfc_get_errors (NULL, &errors_before); |
| 7574 |
parse_module (); |
| 7575 |
break; |
| 7576 |
|
| 7577 |
case ST_SUBMODULE: |
| 7578 |
push_state (&s, COMP_SUBMODULE, gfc_new_block); |
| 7579 |
accept_statement (st); |
| 7580 |
|
| 7581 |
gfc_get_errors (NULL, &errors_before); |
| 7582 |
parse_module (); |
| 7583 |
break; |
| 7584 |
|
| 7585 |
/* Anything else starts a nameless main program block. */ |
| 7586 |
default: |
| 7587 |
if (seen_program) |
| 7588 |
goto duplicate_main; |
| 7589 |
seen_program = 1; |
| 7590 |
prog_locus = gfc_current_locus; |
| 7591 |
|
| 7592 |
push_state (&s, COMP_PROGRAM, gfc_new_block); |
| 7593 |
main_program_symbol (gfc_current_ns, "MAIN__"); |
| 7594 |
parse_progunit (st); |
| 7595 |
goto prog_units; |
| 7596 |
} |
| 7597 |
|
| 7598 |
/* Handle the non-program units. */ |
| 7599 |
gfc_current_ns->code = s.head; |
| 7600 |
|
| 7601 |
gfc_resolve (gfc_current_ns); |
| 7602 |
|
| 7603 |
/* Fix the implicit_pure attribute for those procedures who should |
| 7604 |
not have it. */ |
| 7605 |
while (gfc_fix_implicit_pure (gfc_current_ns)) |
| 7606 |
; |
| 7607 |
|
| 7608 |
/* Dump the parse tree if requested. */ |
| 7609 |
if (flag_dump_fortran_original) |
| 7610 |
gfc_dump_parse_tree (gfc_current_ns, stdout); |
| 7611 |
|
| 7612 |
gfc_get_errors (NULL, &errors); |
| 7613 |
if (s.state == COMP_MODULE || s.state == COMP_SUBMODULE) |
| 7614 |
{ |
| 7615 |
gfc_dump_module (s.sym->name, errors_before == errors); |
| 7616 |
gfc_current_ns->derived_types = gfc_derived_types; |
| 7617 |
gfc_derived_types = NULL; |
| 7618 |
goto prog_units; |
| 7619 |
} |
| 7620 |
else |
| 7621 |
{ |
| 7622 |
if (errors == 0) |
| 7623 |
gfc_generate_code (gfc_current_ns); |
| 7624 |
pop_state (); |
| 7625 |
gfc_done_2 (); |
| 7626 |
} |
| 7627 |
|
| 7628 |
goto loop; |
| 7629 |
|
| 7630 |
prog_units: |
| 7631 |
/* The main program and non-contained procedures are put |
| 7632 |
in the global namespace list, so that they can be processed |
| 7633 |
later and all their interfaces resolved. */ |
| 7634 |
gfc_current_ns->code = s.head; |
| 7635 |
if (next) |
| 7636 |
{ |
| 7637 |
for (; next->sibling; next = next->sibling) |
| 7638 |
; |
| 7639 |
next->sibling = gfc_current_ns; |
| 7640 |
} |
| 7641 |
else |
| 7642 |
gfc_global_ns_list = gfc_current_ns; |
| 7643 |
|
| 7644 |
next = gfc_current_ns; |
| 7645 |
|
| 7646 |
pop_state (); |
| 7647 |
goto loop; |
| 7648 |
|
| 7649 |
done: |
| 7650 |
/* Do the resolution. */ |
| 7651 |
resolve_all_program_units (gfc_global_ns_list); |
| 7652 |
|
| 7653 |
if (flag_coarray == GFC_FCOARRAY_LIB) |
| 7654 |
rewrite_expr_tree (gfc_global_ns_list); |
| 7655 |
|
| 7656 |
/* Go through all top-level namespaces and unset the implicit_pure |
| 7657 |
attribute for any procedures that call something not pure or |
| 7658 |
implicit_pure. Because the a procedure marked as not implicit_pure |
| 7659 |
in one sweep may be called by another routine, we repeat this |
| 7660 |
process until there are no more changes. */ |
| 7661 |
bool changed; |
| 7662 |
do |
| 7663 |
{ |
| 7664 |
changed = false; |
| 7665 |
for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns; |
| 7666 |
gfc_current_ns = gfc_current_ns->sibling) |
| 7667 |
{ |
| 7668 |
if (gfc_fix_implicit_pure (gfc_current_ns)) |
| 7669 |
changed = true; |
| 7670 |
} |
| 7671 |
} |
| 7672 |
while (changed); |
| 7673 |
|
| 7674 |
/* Fixup for external procedures and resolve 'omp requires'. */ |
| 7675 |
int omp_requires; |
| 7676 |
bool omp_target_seen; |
| 7677 |
omp_requires = 0; |
| 7678 |
omp_target_seen = false; |
| 7679 |
for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns; |
| 7680 |
gfc_current_ns = gfc_current_ns->sibling) |
| 7681 |
{ |
| 7682 |
omp_requires |= gfc_current_ns->omp_requires; |
| 7683 |
omp_target_seen |= gfc_current_ns->omp_target_seen; |
| 7684 |
gfc_check_externals (gfc_current_ns); |
| 7685 |
} |
| 7686 |
for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns; |
| 7687 |
gfc_current_ns = gfc_current_ns->sibling) |
| 7688 |
gfc_check_omp_requires (gfc_current_ns, omp_requires); |
| 7689 |
|
| 7690 |
/* Populate omp_requires_mask (needed for resolving OpenMP |
| 7691 |
metadirectives and declare variant). */ |
| 7692 |
switch (omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK) |
| 7693 |
{ |
| 7694 |
case OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST: |
| 7695 |
omp_requires_mask |
| 7696 |
= (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_SEQ_CST); |
| 7697 |
break; |
| 7698 |
case OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL: |
| 7699 |
omp_requires_mask |
| 7700 |
= (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_ACQ_REL); |
| 7701 |
break; |
| 7702 |
case OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE: |
| 7703 |
omp_requires_mask |
| 7704 |
= (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_ACQUIRE); |
| 7705 |
break; |
| 7706 |
case OMP_REQ_ATOMIC_MEM_ORDER_RELAXED: |
| 7707 |
omp_requires_mask |
| 7708 |
= (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_RELAXED); |
| 7709 |
break; |
| 7710 |
case OMP_REQ_ATOMIC_MEM_ORDER_RELEASE: |
| 7711 |
omp_requires_mask |
| 7712 |
= (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_RELEASE); |
| 7713 |
break; |
| 7714 |
} |
| 7715 |
|
| 7716 |
if (omp_target_seen) |
| 7717 |
omp_requires_mask = (enum omp_requires) (omp_requires_mask |
| 7718 |
| OMP_REQUIRES_TARGET_USED); |
| 7719 |
if (omp_requires & OMP_REQ_REVERSE_OFFLOAD) |
| 7720 |
omp_requires_mask = (enum omp_requires) (omp_requires_mask |
| 7721 |
| OMP_REQUIRES_REVERSE_OFFLOAD); |
| 7722 |
if (omp_requires & OMP_REQ_UNIFIED_ADDRESS) |
| 7723 |
omp_requires_mask = (enum omp_requires) (omp_requires_mask |
| 7724 |
| OMP_REQUIRES_UNIFIED_ADDRESS); |
| 7725 |
if (omp_requires & OMP_REQ_UNIFIED_SHARED_MEMORY) |
| 7726 |
omp_requires_mask |
| 7727 |
= (enum omp_requires) (omp_requires_mask |
| 7728 |
| OMP_REQUIRES_UNIFIED_SHARED_MEMORY); |
| 7729 |
if (omp_requires & OMP_REQ_SELF_MAPS) |
| 7730 |
omp_requires_mask |
| 7731 |
= (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_SELF_MAPS); |
| 7732 |
if (omp_requires & OMP_REQ_DYNAMIC_ALLOCATORS) |
| 7733 |
omp_requires_mask = (enum omp_requires) (omp_requires_mask |
| 7734 |
| OMP_REQUIRES_DYNAMIC_ALLOCATORS); |
| 7735 |
/* Do the parse tree dump. */ |
| 7736 |
gfc_current_ns = flag_dump_fortran_original ? gfc_global_ns_list : NULL; |
| 7737 |
|
| 7738 |
for (; gfc_current_ns; gfc_current_ns = gfc_current_ns->sibling) |
| 7739 |
if (!gfc_current_ns->proc_name |
| 7740 |
|| gfc_current_ns->proc_name->attr.flavor != FL_MODULE) |
| 7741 |
{ |
| 7742 |
gfc_dump_parse_tree (gfc_current_ns, stdout); |
| 7743 |
fputs ("------------------------------------------\n\n", stdout); |
| 7744 |
} |
| 7745 |
|
| 7746 |
/* Dump C prototypes. */ |
| 7747 |
if (flag_c_prototypes || flag_c_prototypes_external) |
| 7748 |
{ |
| 7749 |
fprintf (stdout, |
| 7750 |
"#include <stddef.h>\n" |
| 7751 |
"#ifdef __cplusplus\n" |
| 7752 |
"#include <complex>\n" |
| 7753 |
"#define __GFORTRAN_FLOAT_COMPLEX std::complex<float>\n" |
| 7754 |
"#define __GFORTRAN_DOUBLE_COMPLEX std::complex<double>\n" |
| 7755 |
"#define __GFORTRAN_LONG_DOUBLE_COMPLEX std::complex<long double>\n" |
| 7756 |
"extern \"C\" {\n" |
| 7757 |
"#else\n" |
| 7758 |
"#define __GFORTRAN_FLOAT_COMPLEX float _Complex\n" |
| 7759 |
"#define __GFORTRAN_DOUBLE_COMPLEX double _Complex\n" |
| 7760 |
"#define __GFORTRAN_LONG_DOUBLE_COMPLEX long double _Complex\n" |
| 7761 |
"#endif\n\n"); |
| 7762 |
} |
| 7763 |
|
| 7764 |
/* First dump BIND(C) prototypes. */ |
| 7765 |
if (flag_c_prototypes) |
| 7766 |
gfc_dump_c_prototypes (stdout); |
| 7767 |
|
| 7768 |
/* Dump external prototypes. */ |
| 7769 |
if (flag_c_prototypes_external) |
| 7770 |
gfc_dump_external_c_prototypes (stdout); |
| 7771 |
|
| 7772 |
if (flag_c_prototypes || flag_c_prototypes_external) |
| 7773 |
fprintf (stdout, "\n#ifdef __cplusplus\n}\n#endif\n"); |
| 7774 |
|
| 7775 |
/* Do the translation. */ |
| 7776 |
translate_all_program_units (gfc_global_ns_list); |
| 7777 |
|
| 7778 |
/* Dump the global symbol ist. We only do this here because part |
| 7779 |
of it is generated after mangling the identifiers in |
| 7780 |
trans-decl.cc. */ |
| 7781 |
|
| 7782 |
if (flag_dump_fortran_global) |
| 7783 |
gfc_dump_global_symbols (stdout); |
| 7784 |
|
| 7785 |
gfc_end_source_files (); |
| 7786 |
return true; |
| 7787 |
|
| 7788 |
duplicate_main: |
| 7789 |
/* If we see a duplicate main program, shut down. If the second |
| 7790 |
instance is an implied main program, i.e. data decls or executable |
| 7791 |
statements, we're in for lots of errors. */ |
| 7792 |
gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus); |
| 7793 |
reject_statement (); |
| 7794 |
gfc_done_2 (); |
| 7795 |
return true; |
| 7796 |
} |
| 7797 |
|
| 7798 |
/* Return true if this state data represents an OpenACC region. */ |
| 7799 |
bool |
| 7800 |
is_oacc (gfc_state_data *sd) |
| 7801 |
{ |
| 7802 |
switch (sd->construct->op) |
| 7803 |
{ |
| 7804 |
case EXEC_OACC_PARALLEL_LOOP: |
| 7805 |
case EXEC_OACC_PARALLEL: |
| 7806 |
case EXEC_OACC_KERNELS_LOOP: |
| 7807 |
case EXEC_OACC_KERNELS: |
| 7808 |
case EXEC_OACC_SERIAL_LOOP: |
| 7809 |
case EXEC_OACC_SERIAL: |
| 7810 |
case EXEC_OACC_DATA: |
| 7811 |
case EXEC_OACC_HOST_DATA: |
| 7812 |
case EXEC_OACC_LOOP: |
| 7813 |
case EXEC_OACC_UPDATE: |
| 7814 |
case EXEC_OACC_WAIT: |
| 7815 |
case EXEC_OACC_CACHE: |
| 7816 |
case EXEC_OACC_ENTER_DATA: |
| 7817 |
case EXEC_OACC_EXIT_DATA: |
| 7818 |
case EXEC_OACC_ATOMIC: |
| 7819 |
case EXEC_OACC_ROUTINE: |
| 7820 |
return true; |
| 7821 |
|
| 7822 |
default: |
| 7823 |
return false; |
| 7824 |
} |
| 7825 |
} |
| 7826 |
|
| 7827 |
/* Return true if ST is a declarative OpenMP statement. */ |
| 7828 |
bool |
| 7829 |
is_omp_declarative_stmt (gfc_statement st) |
| 7830 |
{ |
| 7831 |
switch (st) |
| 7832 |
{ |
| 7833 |
case_omp_decl: |
| 7834 |
return true; |
| 7835 |
default: |
| 7836 |
return false; |
| 7837 |
} |
| 7838 |
} |