| 1 |
/* Intrinsic function resolution. |
| 2 |
Copyright (C) 2000-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Andy Vaught & Katherine Holcomb |
| 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 |
|
| 22 |
/* Assign name and types to intrinsic procedures. For functions, the |
| 23 |
first argument to a resolution function is an expression pointer to |
| 24 |
the original function node and the rest are pointers to the |
| 25 |
arguments of the function call. For subroutines, a pointer to the |
| 26 |
code node is passed. The result type and library subroutine name |
| 27 |
are generally set according to the function arguments. */ |
| 28 |
|
| 29 |
#include "config.h" |
| 30 |
#include "system.h" |
| 31 |
#include "coretypes.h" |
| 32 |
#include "tree.h" |
| 33 |
#include "gfortran.h" |
| 34 |
#include "stringpool.h" |
| 35 |
#include "intrinsic.h" |
| 36 |
#include "constructor.h" |
| 37 |
#include "arith.h" |
| 38 |
#include "trans.h" |
| 39 |
|
| 40 |
/* Given printf-like arguments, return a stable version of the result string. |
| 41 |
|
| 42 |
We already have a working, optimized string hashing table in the form of |
| 43 |
the identifier table. Reusing this table is likely not to be wasted, |
| 44 |
since if the function name makes it to the gimple output of the frontend, |
| 45 |
we'll have to create the identifier anyway. */ |
| 46 |
|
| 47 |
const char * |
| 48 |
gfc_get_string (const char *format, ...) |
| 49 |
{ |
| 50 |
/* Provide sufficient space for "_F.caf_token__symbol.symbol_MOD_symbol". */ |
| 51 |
char temp_name[15 + 2*GFC_MAX_SYMBOL_LEN + 5 + GFC_MAX_SYMBOL_LEN + 1]; |
| 52 |
const char *str; |
| 53 |
va_list ap; |
| 54 |
tree ident; |
| 55 |
|
| 56 |
/* Handle common case without vsnprintf and temporary buffer. */ |
| 57 |
if (format[0] == '%' && format[1] == 's' && format[2] == '\0') |
| 58 |
{ |
| 59 |
va_start (ap, format); |
| 60 |
str = va_arg (ap, const char *); |
| 61 |
va_end (ap); |
| 62 |
} |
| 63 |
else |
| 64 |
{ |
| 65 |
int ret; |
| 66 |
va_start (ap, format); |
| 67 |
ret = vsnprintf (temp_name, sizeof (temp_name), format, ap); |
| 68 |
va_end (ap); |
| 69 |
if (ret < 1 || ret >= (int) sizeof (temp_name)) /* Reject truncation. */ |
| 70 |
gfc_internal_error ("identifier overflow: %d", ret); |
| 71 |
temp_name[sizeof (temp_name) - 1] = 0; |
| 72 |
str = temp_name; |
| 73 |
} |
| 74 |
|
| 75 |
ident = get_identifier (str); |
| 76 |
return IDENTIFIER_POINTER (ident); |
| 77 |
} |
| 78 |
|
| 79 |
/* MERGE and SPREAD need to have source charlen's present for passing |
| 80 |
to the result expression. */ |
| 81 |
static void |
| 82 |
check_charlen_present (gfc_expr *source) |
| 83 |
{ |
| 84 |
if (source->ts.u.cl == NULL) |
| 85 |
source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); |
| 86 |
|
| 87 |
if (source->expr_type == EXPR_CONSTANT) |
| 88 |
{ |
| 89 |
source->ts.u.cl->length |
| 90 |
= gfc_get_int_expr (gfc_charlen_int_kind, NULL, |
| 91 |
source->value.character.length); |
| 92 |
source->rank = 0; |
| 93 |
} |
| 94 |
else if (source->expr_type == EXPR_ARRAY) |
| 95 |
{ |
| 96 |
gfc_constructor *c = gfc_constructor_first (source->value.constructor); |
| 97 |
if (c) |
| 98 |
source->ts.u.cl->length |
| 99 |
= gfc_get_int_expr (gfc_charlen_int_kind, NULL, |
| 100 |
c->expr->value.character.length); |
| 101 |
if (source->ts.u.cl->length == NULL) |
| 102 |
gfc_internal_error ("check_charlen_present(): length not set"); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
static gfc_intrinsic_sym * |
| 107 |
copy_intrinsic_sym (const gfc_intrinsic_sym *src) |
| 108 |
{ |
| 109 |
gfc_intrinsic_sym *copy = XCNEW (gfc_intrinsic_sym); |
| 110 |
gfc_intrinsic_arg *head = NULL; |
| 111 |
gfc_intrinsic_arg **tail = &head; |
| 112 |
|
| 113 |
*copy = *src; |
| 114 |
for (const gfc_intrinsic_arg *arg = src->formal; arg; arg = arg->next) |
| 115 |
{ |
| 116 |
*tail = XCNEW (gfc_intrinsic_arg); |
| 117 |
**tail = *arg; |
| 118 |
(*tail)->next = NULL; |
| 119 |
tail = &(*tail)->next; |
| 120 |
} |
| 121 |
copy->formal = head; |
| 122 |
return copy; |
| 123 |
} |
| 124 |
|
| 125 |
/* Helper function for resolving the "mask" argument. */ |
| 126 |
|
| 127 |
static void |
| 128 |
resolve_mask_arg (gfc_expr *mask) |
| 129 |
{ |
| 130 |
|
| 131 |
gfc_typespec ts; |
| 132 |
gfc_clear_ts (&ts); |
| 133 |
|
| 134 |
if (mask->rank == 0) |
| 135 |
{ |
| 136 |
/* For the scalar case, coerce the mask to kind=4 unconditionally |
| 137 |
(because this is the only kind we have a library function |
| 138 |
for). */ |
| 139 |
|
| 140 |
if (mask->ts.kind != 4) |
| 141 |
{ |
| 142 |
ts.type = BT_LOGICAL; |
| 143 |
ts.kind = 4; |
| 144 |
gfc_convert_type (mask, &ts, 2); |
| 145 |
} |
| 146 |
} |
| 147 |
else |
| 148 |
{ |
| 149 |
/* In the library, we access the mask with a GFC_LOGICAL_1 |
| 150 |
argument. No need to waste memory if we are about to create |
| 151 |
a temporary array. */ |
| 152 |
if (mask->expr_type == EXPR_OP && mask->ts.kind != 1) |
| 153 |
{ |
| 154 |
ts.type = BT_LOGICAL; |
| 155 |
ts.kind = 1; |
| 156 |
gfc_convert_type_warn (mask, &ts, 2, 0); |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
static void |
| 163 |
resolve_bound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind, |
| 164 |
const char *name, bool coarray) |
| 165 |
{ |
| 166 |
f->ts.type = BT_INTEGER; |
| 167 |
if (kind) |
| 168 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 169 |
else |
| 170 |
f->ts.kind = gfc_default_integer_kind; |
| 171 |
|
| 172 |
if (dim == NULL) |
| 173 |
{ |
| 174 |
if (array->rank != -1) |
| 175 |
{ |
| 176 |
/* Assume f->rank gives the size of the shape, because there is no |
| 177 |
other way to determine the size. */ |
| 178 |
if (!f->shape || f->rank != 1) |
| 179 |
{ |
| 180 |
if (f->shape) |
| 181 |
gfc_free_shape (&f->shape, f->rank); |
| 182 |
f->shape = gfc_get_shape (1); |
| 183 |
} |
| 184 |
mpz_init_set_ui (f->shape[0], coarray ? array->corank : array->rank); |
| 185 |
} |
| 186 |
/* Applying bound to a coarray always results in a regular array. */ |
| 187 |
f->rank = 1; |
| 188 |
f->corank = 0; |
| 189 |
} |
| 190 |
|
| 191 |
f->value.function.name = gfc_get_string ("%s", name); |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
static void |
| 196 |
resolve_transformational (const char *name, gfc_expr *f, gfc_expr *array, |
| 197 |
gfc_expr *dim, gfc_expr *mask, |
| 198 |
bool use_integer = false) |
| 199 |
{ |
| 200 |
const char *prefix; |
| 201 |
bt type; |
| 202 |
|
| 203 |
f->ts = array->ts; |
| 204 |
|
| 205 |
if (mask) |
| 206 |
{ |
| 207 |
if (mask->rank == 0) |
| 208 |
prefix = "s"; |
| 209 |
else |
| 210 |
prefix = "m"; |
| 211 |
|
| 212 |
resolve_mask_arg (mask); |
| 213 |
} |
| 214 |
else |
| 215 |
prefix = ""; |
| 216 |
|
| 217 |
if (dim != NULL) |
| 218 |
{ |
| 219 |
f->rank = array->rank - 1; |
| 220 |
f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim); |
| 221 |
gfc_resolve_dim_arg (dim); |
| 222 |
} |
| 223 |
|
| 224 |
/* For those intrinsic like SUM where we use the integer version |
| 225 |
actually uses unsigned, but we call it as the integer |
| 226 |
version. */ |
| 227 |
|
| 228 |
if (use_integer && array->ts.type == BT_UNSIGNED) |
| 229 |
type = BT_INTEGER; |
| 230 |
else |
| 231 |
type = array->ts.type; |
| 232 |
|
| 233 |
f->value.function.name |
| 234 |
= gfc_get_string (PREFIX ("%s%s_%c%d"), prefix, name, |
| 235 |
gfc_type_letter (type), |
| 236 |
gfc_type_abi_kind (&array->ts)); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
/********************** Resolution functions **********************/ |
| 241 |
|
| 242 |
|
| 243 |
void |
| 244 |
gfc_resolve_abs (gfc_expr *f, gfc_expr *a) |
| 245 |
{ |
| 246 |
f->ts = a->ts; |
| 247 |
if (f->ts.type == BT_COMPLEX) |
| 248 |
f->ts.type = BT_REAL; |
| 249 |
|
| 250 |
f->value.function.name |
| 251 |
= gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), |
| 252 |
gfc_type_abi_kind (&a->ts)); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
void |
| 257 |
gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED, |
| 258 |
gfc_expr *mode ATTRIBUTE_UNUSED) |
| 259 |
{ |
| 260 |
f->ts.type = BT_INTEGER; |
| 261 |
f->ts.kind = gfc_c_int_kind; |
| 262 |
f->value.function.name = PREFIX ("access_func"); |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
void |
| 267 |
gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string) |
| 268 |
{ |
| 269 |
f->ts.type = BT_CHARACTER; |
| 270 |
f->ts.kind = string->ts.kind; |
| 271 |
if (string->ts.deferred) |
| 272 |
f->ts = string->ts; |
| 273 |
else if (string->ts.u.cl) |
| 274 |
f->ts.u.cl = gfc_new_charlen (gfc_current_ns, string->ts.u.cl); |
| 275 |
|
| 276 |
f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
void |
| 281 |
gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string) |
| 282 |
{ |
| 283 |
f->ts.type = BT_CHARACTER; |
| 284 |
f->ts.kind = string->ts.kind; |
| 285 |
if (string->ts.deferred) |
| 286 |
f->ts = string->ts; |
| 287 |
else if (string->ts.u.cl) |
| 288 |
f->ts.u.cl = gfc_new_charlen (gfc_current_ns, string->ts.u.cl); |
| 289 |
|
| 290 |
f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind); |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
static void |
| 295 |
gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind, |
| 296 |
bool is_achar) |
| 297 |
{ |
| 298 |
f->ts.type = BT_CHARACTER; |
| 299 |
f->ts.kind = (kind == NULL) |
| 300 |
? gfc_default_character_kind : mpz_get_si (kind->value.integer); |
| 301 |
f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); |
| 302 |
f->ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind, NULL, 1); |
| 303 |
|
| 304 |
f->value.function.name |
| 305 |
= gfc_get_string ("__%schar_%d_%c%d", is_achar ? "a" : "", f->ts.kind, |
| 306 |
gfc_type_letter (x->ts.type), |
| 307 |
gfc_type_abi_kind (&x->ts)); |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
void |
| 312 |
gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind) |
| 313 |
{ |
| 314 |
gfc_resolve_char_achar (f, x, kind, true); |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
void |
| 319 |
gfc_resolve_acos (gfc_expr *f, gfc_expr *x) |
| 320 |
{ |
| 321 |
f->ts = x->ts; |
| 322 |
f->value.function.name |
| 323 |
= gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), |
| 324 |
gfc_type_abi_kind (&x->ts)); |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
void |
| 329 |
gfc_resolve_acosh (gfc_expr *f, gfc_expr *x) |
| 330 |
{ |
| 331 |
f->ts = x->ts; |
| 332 |
f->value.function.name |
| 333 |
= gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type), |
| 334 |
gfc_type_abi_kind (&x->ts)); |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
void |
| 339 |
gfc_resolve_aimag (gfc_expr *f, gfc_expr *x) |
| 340 |
{ |
| 341 |
f->ts.type = BT_REAL; |
| 342 |
f->ts.kind = x->ts.kind; |
| 343 |
f->value.function.name |
| 344 |
= gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type), |
| 345 |
gfc_type_abi_kind (&x->ts)); |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
void |
| 350 |
gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
| 351 |
{ |
| 352 |
f->ts.type = i->ts.type; |
| 353 |
f->ts.kind = gfc_kind_max (i, j); |
| 354 |
|
| 355 |
if (i->ts.kind != j->ts.kind) |
| 356 |
{ |
| 357 |
if (i->ts.kind == gfc_kind_max (i, j)) |
| 358 |
gfc_convert_type (j, &i->ts, 2); |
| 359 |
else |
| 360 |
gfc_convert_type (i, &j->ts, 2); |
| 361 |
} |
| 362 |
|
| 363 |
f->value.function.name |
| 364 |
= gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), |
| 365 |
gfc_type_abi_kind (&f->ts)); |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
void |
| 370 |
gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 371 |
{ |
| 372 |
gfc_typespec ts; |
| 373 |
gfc_clear_ts (&ts); |
| 374 |
|
| 375 |
f->ts.type = a->ts.type; |
| 376 |
f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer); |
| 377 |
|
| 378 |
if (a->ts.kind != f->ts.kind) |
| 379 |
{ |
| 380 |
ts.type = f->ts.type; |
| 381 |
ts.kind = f->ts.kind; |
| 382 |
gfc_convert_type (a, &ts, 2); |
| 383 |
} |
| 384 |
/* The resolved name is only used for specific intrinsics where |
| 385 |
the return kind is the same as the arg kind. */ |
| 386 |
f->value.function.name |
| 387 |
= gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), |
| 388 |
gfc_type_abi_kind (&a->ts)); |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
void |
| 393 |
gfc_resolve_dint (gfc_expr *f, gfc_expr *a) |
| 394 |
{ |
| 395 |
gfc_resolve_aint (f, a, NULL); |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
void |
| 400 |
gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim) |
| 401 |
{ |
| 402 |
f->ts = mask->ts; |
| 403 |
|
| 404 |
if (dim != NULL) |
| 405 |
{ |
| 406 |
gfc_resolve_dim_arg (dim); |
| 407 |
f->rank = mask->rank - 1; |
| 408 |
f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim); |
| 409 |
} |
| 410 |
|
| 411 |
f->value.function.name |
| 412 |
= gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type), |
| 413 |
gfc_type_abi_kind (&mask->ts)); |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
void |
| 418 |
gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 419 |
{ |
| 420 |
gfc_typespec ts; |
| 421 |
gfc_clear_ts (&ts); |
| 422 |
|
| 423 |
f->ts.type = a->ts.type; |
| 424 |
f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer); |
| 425 |
|
| 426 |
if (a->ts.kind != f->ts.kind) |
| 427 |
{ |
| 428 |
ts.type = f->ts.type; |
| 429 |
ts.kind = f->ts.kind; |
| 430 |
gfc_convert_type (a, &ts, 2); |
| 431 |
} |
| 432 |
|
| 433 |
/* The resolved name is only used for specific intrinsics where |
| 434 |
the return kind is the same as the arg kind. */ |
| 435 |
f->value.function.name |
| 436 |
= gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type), |
| 437 |
gfc_type_abi_kind (&a->ts)); |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
void |
| 442 |
gfc_resolve_dnint (gfc_expr *f, gfc_expr *a) |
| 443 |
{ |
| 444 |
gfc_resolve_anint (f, a, NULL); |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
void |
| 449 |
gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim) |
| 450 |
{ |
| 451 |
f->ts = mask->ts; |
| 452 |
|
| 453 |
if (dim != NULL) |
| 454 |
{ |
| 455 |
gfc_resolve_dim_arg (dim); |
| 456 |
f->rank = mask->rank - 1; |
| 457 |
f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim); |
| 458 |
} |
| 459 |
|
| 460 |
f->value.function.name |
| 461 |
= gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type), |
| 462 |
gfc_type_abi_kind (&mask->ts)); |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
void |
| 467 |
gfc_resolve_asin (gfc_expr *f, gfc_expr *x) |
| 468 |
{ |
| 469 |
f->ts = x->ts; |
| 470 |
f->value.function.name |
| 471 |
= gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), |
| 472 |
gfc_type_abi_kind (&x->ts)); |
| 473 |
} |
| 474 |
|
| 475 |
void |
| 476 |
gfc_resolve_asinh (gfc_expr *f, gfc_expr *x) |
| 477 |
{ |
| 478 |
f->ts = x->ts; |
| 479 |
f->value.function.name |
| 480 |
= gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type), |
| 481 |
gfc_type_abi_kind (&x->ts)); |
| 482 |
} |
| 483 |
|
| 484 |
void |
| 485 |
gfc_resolve_atan (gfc_expr *f, gfc_expr *x) |
| 486 |
{ |
| 487 |
f->ts = x->ts; |
| 488 |
f->value.function.name |
| 489 |
= gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), |
| 490 |
gfc_type_abi_kind (&x->ts)); |
| 491 |
} |
| 492 |
|
| 493 |
void |
| 494 |
gfc_resolve_atanh (gfc_expr *f, gfc_expr *x) |
| 495 |
{ |
| 496 |
f->ts = x->ts; |
| 497 |
f->value.function.name |
| 498 |
= gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type), |
| 499 |
gfc_type_abi_kind (&x->ts)); |
| 500 |
} |
| 501 |
|
| 502 |
void |
| 503 |
gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED) |
| 504 |
{ |
| 505 |
f->ts = x->ts; |
| 506 |
f->value.function.name |
| 507 |
= gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type), |
| 508 |
gfc_type_abi_kind (&x->ts)); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
/* Resolve the BESYN and BESJN intrinsics. */ |
| 513 |
|
| 514 |
void |
| 515 |
gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x) |
| 516 |
{ |
| 517 |
gfc_typespec ts; |
| 518 |
gfc_clear_ts (&ts); |
| 519 |
|
| 520 |
f->ts = x->ts; |
| 521 |
if (n->ts.kind != gfc_c_int_kind) |
| 522 |
{ |
| 523 |
ts.type = BT_INTEGER; |
| 524 |
ts.kind = gfc_c_int_kind; |
| 525 |
gfc_convert_type (n, &ts, 2); |
| 526 |
} |
| 527 |
f->value.function.name = gfc_get_string ("<intrinsic>"); |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
void |
| 532 |
gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x) |
| 533 |
{ |
| 534 |
gfc_typespec ts; |
| 535 |
gfc_clear_ts (&ts); |
| 536 |
|
| 537 |
f->ts = x->ts; |
| 538 |
f->rank = 1; |
| 539 |
if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT) |
| 540 |
{ |
| 541 |
f->shape = gfc_get_shape (1); |
| 542 |
mpz_init (f->shape[0]); |
| 543 |
mpz_sub (f->shape[0], n2->value.integer, n1->value.integer); |
| 544 |
mpz_add_ui (f->shape[0], f->shape[0], 1); |
| 545 |
} |
| 546 |
|
| 547 |
if (n1->ts.kind != gfc_c_int_kind) |
| 548 |
{ |
| 549 |
ts.type = BT_INTEGER; |
| 550 |
ts.kind = gfc_c_int_kind; |
| 551 |
gfc_convert_type (n1, &ts, 2); |
| 552 |
} |
| 553 |
|
| 554 |
if (n2->ts.kind != gfc_c_int_kind) |
| 555 |
{ |
| 556 |
ts.type = BT_INTEGER; |
| 557 |
ts.kind = gfc_c_int_kind; |
| 558 |
gfc_convert_type (n2, &ts, 2); |
| 559 |
} |
| 560 |
|
| 561 |
if (f->value.function.isym->id == GFC_ISYM_JN2) |
| 562 |
f->value.function.name = gfc_get_string (PREFIX ("bessel_jn_r%d"), |
| 563 |
gfc_type_abi_kind (&f->ts)); |
| 564 |
else |
| 565 |
f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"), |
| 566 |
gfc_type_abi_kind (&f->ts)); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
void |
| 571 |
gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos) |
| 572 |
{ |
| 573 |
f->ts.type = BT_LOGICAL; |
| 574 |
f->ts.kind = gfc_default_logical_kind; |
| 575 |
f->value.function.name |
| 576 |
= gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind); |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
void |
| 581 |
gfc_resolve_c_loc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED) |
| 582 |
{ |
| 583 |
f->ts = f->value.function.isym->ts; |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
void |
| 588 |
gfc_resolve_c_funloc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED) |
| 589 |
{ |
| 590 |
f->ts = f->value.function.isym->ts; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
void |
| 595 |
gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 596 |
{ |
| 597 |
f->ts.type = BT_INTEGER; |
| 598 |
f->ts.kind = (kind == NULL) |
| 599 |
? gfc_default_integer_kind : mpz_get_si (kind->value.integer); |
| 600 |
f->value.function.name |
| 601 |
= gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind, |
| 602 |
gfc_type_letter (a->ts.type), |
| 603 |
gfc_type_abi_kind (&a->ts)); |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
void |
| 608 |
gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 609 |
{ |
| 610 |
gfc_resolve_char_achar (f, a, kind, false); |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
void |
| 615 |
gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED) |
| 616 |
{ |
| 617 |
f->ts.type = BT_INTEGER; |
| 618 |
f->ts.kind = gfc_default_integer_kind; |
| 619 |
f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind); |
| 620 |
} |
| 621 |
|
| 622 |
|
| 623 |
void |
| 624 |
gfc_resolve_chdir_sub (gfc_code *c) |
| 625 |
{ |
| 626 |
const char *name; |
| 627 |
int kind; |
| 628 |
|
| 629 |
if (c->ext.actual->next->expr != NULL) |
| 630 |
kind = c->ext.actual->next->expr->ts.kind; |
| 631 |
else |
| 632 |
kind = gfc_default_integer_kind; |
| 633 |
|
| 634 |
name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind); |
| 635 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
void |
| 640 |
gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED, |
| 641 |
gfc_expr *mode ATTRIBUTE_UNUSED) |
| 642 |
{ |
| 643 |
f->ts.type = BT_INTEGER; |
| 644 |
f->ts.kind = gfc_c_int_kind; |
| 645 |
f->value.function.name = PREFIX ("chmod_func"); |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
void |
| 650 |
gfc_resolve_chmod_sub (gfc_code *c) |
| 651 |
{ |
| 652 |
const char *name; |
| 653 |
int kind; |
| 654 |
|
| 655 |
if (c->ext.actual->next->next->expr != NULL) |
| 656 |
kind = c->ext.actual->next->next->expr->ts.kind; |
| 657 |
else |
| 658 |
kind = gfc_default_integer_kind; |
| 659 |
|
| 660 |
name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind); |
| 661 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
void |
| 666 |
gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind) |
| 667 |
{ |
| 668 |
f->ts.type = BT_COMPLEX; |
| 669 |
f->ts.kind = (kind == NULL) |
| 670 |
? gfc_default_real_kind : mpz_get_si (kind->value.integer); |
| 671 |
|
| 672 |
if (y == NULL) |
| 673 |
f->value.function.name |
| 674 |
= gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind, |
| 675 |
gfc_type_letter (x->ts.type), |
| 676 |
gfc_type_abi_kind (&x->ts)); |
| 677 |
else |
| 678 |
f->value.function.name |
| 679 |
= gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind, |
| 680 |
gfc_type_letter (x->ts.type), |
| 681 |
gfc_type_abi_kind (&x->ts), |
| 682 |
gfc_type_letter (y->ts.type), |
| 683 |
gfc_type_abi_kind (&y->ts)); |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
void |
| 688 |
gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y) |
| 689 |
{ |
| 690 |
gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL, |
| 691 |
gfc_default_double_kind)); |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
void |
| 696 |
gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y) |
| 697 |
{ |
| 698 |
int kind; |
| 699 |
|
| 700 |
if (x->ts.type == BT_INTEGER) |
| 701 |
{ |
| 702 |
if (y->ts.type == BT_INTEGER) |
| 703 |
kind = gfc_default_real_kind; |
| 704 |
else |
| 705 |
kind = y->ts.kind; |
| 706 |
} |
| 707 |
else |
| 708 |
{ |
| 709 |
if (y->ts.type == BT_REAL) |
| 710 |
kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind; |
| 711 |
else |
| 712 |
kind = x->ts.kind; |
| 713 |
} |
| 714 |
|
| 715 |
f->ts.type = BT_COMPLEX; |
| 716 |
f->ts.kind = kind; |
| 717 |
f->value.function.name |
| 718 |
= gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind, |
| 719 |
gfc_type_letter (x->ts.type), |
| 720 |
gfc_type_abi_kind (&x->ts), |
| 721 |
gfc_type_letter (y->ts.type), |
| 722 |
gfc_type_abi_kind (&y->ts)); |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
void |
| 727 |
gfc_resolve_conjg (gfc_expr *f, gfc_expr *x) |
| 728 |
{ |
| 729 |
f->ts = x->ts; |
| 730 |
f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind); |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
void |
| 735 |
gfc_resolve_cos (gfc_expr *f, gfc_expr *x) |
| 736 |
{ |
| 737 |
f->ts = x->ts; |
| 738 |
f->value.function.name |
| 739 |
= gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), |
| 740 |
gfc_type_abi_kind (&x->ts)); |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
void |
| 745 |
gfc_resolve_cosh (gfc_expr *f, gfc_expr *x) |
| 746 |
{ |
| 747 |
f->ts = x->ts; |
| 748 |
f->value.function.name |
| 749 |
= gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), |
| 750 |
gfc_type_abi_kind (&x->ts)); |
| 751 |
} |
| 752 |
|
| 753 |
|
| 754 |
void |
| 755 |
gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind) |
| 756 |
{ |
| 757 |
f->ts.type = BT_INTEGER; |
| 758 |
if (kind) |
| 759 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 760 |
else |
| 761 |
f->ts.kind = gfc_default_integer_kind; |
| 762 |
|
| 763 |
if (dim != NULL) |
| 764 |
{ |
| 765 |
f->rank = mask->rank - 1; |
| 766 |
gfc_resolve_dim_arg (dim); |
| 767 |
f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim); |
| 768 |
} |
| 769 |
|
| 770 |
resolve_mask_arg (mask); |
| 771 |
|
| 772 |
f->value.function.name |
| 773 |
= gfc_get_string (PREFIX ("count_%d_%c"), gfc_type_abi_kind (&f->ts), |
| 774 |
gfc_type_letter (mask->ts.type)); |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
void |
| 779 |
gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift, |
| 780 |
gfc_expr *dim) |
| 781 |
{ |
| 782 |
int n, m; |
| 783 |
|
| 784 |
if (array->ts.type == BT_CHARACTER && array->ref) |
| 785 |
gfc_resolve_substring_charlen (array); |
| 786 |
|
| 787 |
f->ts = array->ts; |
| 788 |
f->rank = array->rank; |
| 789 |
f->corank = array->corank; |
| 790 |
f->shape = gfc_copy_shape (array->shape, array->rank); |
| 791 |
|
| 792 |
if (shift->rank > 0) |
| 793 |
n = 1; |
| 794 |
else |
| 795 |
n = 0; |
| 796 |
|
| 797 |
/* If dim kind is greater than default integer we need to use the larger. */ |
| 798 |
m = gfc_default_integer_kind; |
| 799 |
if (dim != NULL) |
| 800 |
m = m < dim->ts.kind ? dim->ts.kind : m; |
| 801 |
|
| 802 |
/* Convert shift to at least m, so we don't need |
| 803 |
kind=1 and kind=2 versions of the library functions. */ |
| 804 |
if (shift->ts.kind < m) |
| 805 |
{ |
| 806 |
gfc_typespec ts; |
| 807 |
gfc_clear_ts (&ts); |
| 808 |
ts.type = BT_INTEGER; |
| 809 |
ts.kind = m; |
| 810 |
gfc_convert_type_warn (shift, &ts, 2, 0); |
| 811 |
} |
| 812 |
|
| 813 |
if (dim != NULL) |
| 814 |
{ |
| 815 |
if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL |
| 816 |
&& dim->symtree->n.sym->attr.optional) |
| 817 |
{ |
| 818 |
/* Mark this for later setting the type in gfc_conv_missing_dummy. */ |
| 819 |
dim->representation.length = shift->ts.kind; |
| 820 |
} |
| 821 |
else |
| 822 |
{ |
| 823 |
gfc_resolve_dim_arg (dim); |
| 824 |
/* Convert dim to shift's kind to reduce variations. */ |
| 825 |
if (dim->ts.kind != shift->ts.kind) |
| 826 |
gfc_convert_type_warn (dim, &shift->ts, 2, 0); |
| 827 |
} |
| 828 |
} |
| 829 |
|
| 830 |
if (array->ts.type == BT_CHARACTER) |
| 831 |
{ |
| 832 |
if (array->ts.kind == gfc_default_character_kind) |
| 833 |
f->value.function.name |
| 834 |
= gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind); |
| 835 |
else |
| 836 |
f->value.function.name |
| 837 |
= gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind, |
| 838 |
array->ts.kind); |
| 839 |
} |
| 840 |
else |
| 841 |
f->value.function.name |
| 842 |
= gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind); |
| 843 |
} |
| 844 |
|
| 845 |
|
| 846 |
void |
| 847 |
gfc_resolve_ctime (gfc_expr *f, gfc_expr *time) |
| 848 |
{ |
| 849 |
gfc_typespec ts; |
| 850 |
gfc_clear_ts (&ts); |
| 851 |
|
| 852 |
f->ts.type = BT_CHARACTER; |
| 853 |
f->ts.kind = gfc_default_character_kind; |
| 854 |
|
| 855 |
/* ctime TIME argument is a INTEGER(KIND=8), says the doc */ |
| 856 |
if (time->ts.kind != 8) |
| 857 |
{ |
| 858 |
ts.type = BT_INTEGER; |
| 859 |
ts.kind = 8; |
| 860 |
ts.u.derived = NULL; |
| 861 |
ts.u.cl = NULL; |
| 862 |
gfc_convert_type (time, &ts, 2); |
| 863 |
} |
| 864 |
|
| 865 |
f->value.function.name = gfc_get_string (PREFIX ("ctime")); |
| 866 |
} |
| 867 |
|
| 868 |
|
| 869 |
void |
| 870 |
gfc_resolve_dble (gfc_expr *f, gfc_expr *a) |
| 871 |
{ |
| 872 |
f->ts.type = BT_REAL; |
| 873 |
f->ts.kind = gfc_default_double_kind; |
| 874 |
f->value.function.name |
| 875 |
= gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), |
| 876 |
gfc_type_abi_kind (&a->ts)); |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
void |
| 881 |
gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p) |
| 882 |
{ |
| 883 |
f->ts.type = a->ts.type; |
| 884 |
if (p != NULL) |
| 885 |
f->ts.kind = gfc_kind_max (a,p); |
| 886 |
else |
| 887 |
f->ts.kind = a->ts.kind; |
| 888 |
|
| 889 |
if (p != NULL && a->ts.kind != p->ts.kind) |
| 890 |
{ |
| 891 |
if (a->ts.kind == gfc_kind_max (a,p)) |
| 892 |
gfc_convert_type (p, &a->ts, 2); |
| 893 |
else |
| 894 |
gfc_convert_type (a, &p->ts, 2); |
| 895 |
} |
| 896 |
|
| 897 |
f->value.function.name |
| 898 |
= gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), |
| 899 |
gfc_type_abi_kind (&f->ts)); |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
void |
| 904 |
gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b) |
| 905 |
{ |
| 906 |
gfc_expr temp; |
| 907 |
|
| 908 |
temp.expr_type = EXPR_OP; |
| 909 |
gfc_clear_ts (&temp.ts); |
| 910 |
temp.value.op.op = INTRINSIC_NONE; |
| 911 |
temp.value.op.op1 = a; |
| 912 |
temp.value.op.op2 = b; |
| 913 |
gfc_type_convert_binary (&temp, 1); |
| 914 |
f->ts = temp.ts; |
| 915 |
f->value.function.name |
| 916 |
= gfc_get_string (PREFIX ("dot_product_%c%d"), |
| 917 |
gfc_type_letter (f->ts.type), |
| 918 |
gfc_type_abi_kind (&f->ts)); |
| 919 |
} |
| 920 |
|
| 921 |
|
| 922 |
void |
| 923 |
gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED, |
| 924 |
gfc_expr *b ATTRIBUTE_UNUSED) |
| 925 |
{ |
| 926 |
f->ts.kind = gfc_default_double_kind; |
| 927 |
f->ts.type = BT_REAL; |
| 928 |
f->value.function.name = gfc_get_string ("__dprod_r%d", |
| 929 |
gfc_type_abi_kind (&f->ts)); |
| 930 |
} |
| 931 |
|
| 932 |
|
| 933 |
void |
| 934 |
gfc_resolve_dshift (gfc_expr *f, gfc_expr *i, gfc_expr *j ATTRIBUTE_UNUSED, |
| 935 |
gfc_expr *shift ATTRIBUTE_UNUSED) |
| 936 |
{ |
| 937 |
char c = i->ts.type == BT_INTEGER ? 'i' : 'u'; |
| 938 |
|
| 939 |
f->ts = i->ts; |
| 940 |
if (f->value.function.isym->id == GFC_ISYM_DSHIFTL) |
| 941 |
f->value.function.name = gfc_get_string ("dshiftl_%c%d", c, f->ts.kind); |
| 942 |
else if (f->value.function.isym->id == GFC_ISYM_DSHIFTR) |
| 943 |
f->value.function.name = gfc_get_string ("dshiftr_%c%d", c, f->ts.kind); |
| 944 |
else |
| 945 |
gcc_unreachable (); |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
void |
| 950 |
gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift, |
| 951 |
gfc_expr *boundary, gfc_expr *dim) |
| 952 |
{ |
| 953 |
int n, m; |
| 954 |
|
| 955 |
if (array->ts.type == BT_CHARACTER && array->ref) |
| 956 |
gfc_resolve_substring_charlen (array); |
| 957 |
|
| 958 |
f->ts = array->ts; |
| 959 |
f->rank = array->rank; |
| 960 |
f->corank = array->corank; |
| 961 |
f->shape = gfc_copy_shape (array->shape, array->rank); |
| 962 |
|
| 963 |
n = 0; |
| 964 |
if (shift->rank > 0) |
| 965 |
n = n | 1; |
| 966 |
if (boundary && boundary->rank > 0) |
| 967 |
n = n | 2; |
| 968 |
|
| 969 |
/* If dim kind is greater than default integer we need to use the larger. */ |
| 970 |
m = gfc_default_integer_kind; |
| 971 |
if (dim != NULL) |
| 972 |
m = m < dim->ts.kind ? dim->ts.kind : m; |
| 973 |
|
| 974 |
/* Convert shift to at least m, so we don't need |
| 975 |
kind=1 and kind=2 versions of the library functions. */ |
| 976 |
if (shift->ts.kind < m) |
| 977 |
{ |
| 978 |
gfc_typespec ts; |
| 979 |
gfc_clear_ts (&ts); |
| 980 |
ts.type = BT_INTEGER; |
| 981 |
ts.kind = m; |
| 982 |
gfc_convert_type_warn (shift, &ts, 2, 0); |
| 983 |
} |
| 984 |
|
| 985 |
if (dim != NULL) |
| 986 |
{ |
| 987 |
if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL |
| 988 |
&& dim->symtree->n.sym->attr.optional) |
| 989 |
{ |
| 990 |
/* Mark this for later setting the type in gfc_conv_missing_dummy. */ |
| 991 |
dim->representation.length = shift->ts.kind; |
| 992 |
} |
| 993 |
else |
| 994 |
{ |
| 995 |
gfc_resolve_dim_arg (dim); |
| 996 |
/* Convert dim to shift's kind to reduce variations. */ |
| 997 |
if (dim->ts.kind != shift->ts.kind) |
| 998 |
gfc_convert_type_warn (dim, &shift->ts, 2, 0); |
| 999 |
} |
| 1000 |
} |
| 1001 |
|
| 1002 |
if (array->ts.type == BT_CHARACTER) |
| 1003 |
{ |
| 1004 |
if (array->ts.kind == gfc_default_character_kind) |
| 1005 |
f->value.function.name |
| 1006 |
= gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind); |
| 1007 |
else |
| 1008 |
f->value.function.name |
| 1009 |
= gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind, |
| 1010 |
array->ts.kind); |
| 1011 |
} |
| 1012 |
else |
| 1013 |
f->value.function.name |
| 1014 |
= gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind); |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
void |
| 1019 |
gfc_resolve_exp (gfc_expr *f, gfc_expr *x) |
| 1020 |
{ |
| 1021 |
f->ts = x->ts; |
| 1022 |
f->value.function.name |
| 1023 |
= gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), |
| 1024 |
gfc_type_abi_kind (&x->ts)); |
| 1025 |
} |
| 1026 |
|
| 1027 |
|
| 1028 |
void |
| 1029 |
gfc_resolve_exponent (gfc_expr *f, gfc_expr *x) |
| 1030 |
{ |
| 1031 |
f->ts.type = BT_INTEGER; |
| 1032 |
f->ts.kind = gfc_default_integer_kind; |
| 1033 |
f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind); |
| 1034 |
} |
| 1035 |
|
| 1036 |
|
| 1037 |
/* Resolve the EXTENDS_TYPE_OF intrinsic function. */ |
| 1038 |
|
| 1039 |
void |
| 1040 |
gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo) |
| 1041 |
{ |
| 1042 |
gfc_symbol *vtab; |
| 1043 |
gfc_symtree *st; |
| 1044 |
|
| 1045 |
/* Prevent double resolution. */ |
| 1046 |
if (f->ts.type == BT_LOGICAL) |
| 1047 |
return; |
| 1048 |
|
| 1049 |
/* Replace the first argument with the corresponding vtab. */ |
| 1050 |
if (a->ts.type == BT_CLASS) |
| 1051 |
gfc_add_vptr_component (a); |
| 1052 |
else if (a->ts.type == BT_DERIVED) |
| 1053 |
{ |
| 1054 |
locus where; |
| 1055 |
|
| 1056 |
vtab = gfc_find_derived_vtab (a->ts.u.derived); |
| 1057 |
/* Clear the old expr. */ |
| 1058 |
gfc_free_ref_list (a->ref); |
| 1059 |
where = a->where; |
| 1060 |
memset (a, '\0', sizeof (gfc_expr)); |
| 1061 |
/* Construct a new one. */ |
| 1062 |
a->expr_type = EXPR_VARIABLE; |
| 1063 |
st = gfc_find_symtree (vtab->ns->sym_root, vtab->name); |
| 1064 |
a->symtree = st; |
| 1065 |
a->ts = vtab->ts; |
| 1066 |
a->where = where; |
| 1067 |
} |
| 1068 |
|
| 1069 |
/* Replace the second argument with the corresponding vtab. */ |
| 1070 |
if (mo->ts.type == BT_CLASS) |
| 1071 |
gfc_add_vptr_component (mo); |
| 1072 |
else if (mo->ts.type == BT_DERIVED) |
| 1073 |
{ |
| 1074 |
locus where; |
| 1075 |
|
| 1076 |
vtab = gfc_find_derived_vtab (mo->ts.u.derived); |
| 1077 |
/* Clear the old expr. */ |
| 1078 |
where = mo->where; |
| 1079 |
gfc_free_ref_list (mo->ref); |
| 1080 |
memset (mo, '\0', sizeof (gfc_expr)); |
| 1081 |
/* Construct a new one. */ |
| 1082 |
mo->expr_type = EXPR_VARIABLE; |
| 1083 |
st = gfc_find_symtree (vtab->ns->sym_root, vtab->name); |
| 1084 |
mo->symtree = st; |
| 1085 |
mo->ts = vtab->ts; |
| 1086 |
mo->where = where; |
| 1087 |
} |
| 1088 |
|
| 1089 |
f->ts.type = BT_LOGICAL; |
| 1090 |
f->ts.kind = 4; |
| 1091 |
|
| 1092 |
f->value.function.isym->formal->ts = a->ts; |
| 1093 |
f->value.function.isym->formal->next->ts = mo->ts; |
| 1094 |
|
| 1095 |
/* Call library function. */ |
| 1096 |
f->value.function.name = gfc_get_string (PREFIX ("is_extension_of")); |
| 1097 |
} |
| 1098 |
|
| 1099 |
|
| 1100 |
void |
| 1101 |
gfc_resolve_fdate (gfc_expr *f) |
| 1102 |
{ |
| 1103 |
f->ts.type = BT_CHARACTER; |
| 1104 |
f->ts.kind = gfc_default_character_kind; |
| 1105 |
f->value.function.name = gfc_get_string (PREFIX ("fdate")); |
| 1106 |
} |
| 1107 |
|
| 1108 |
|
| 1109 |
void |
| 1110 |
gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 1111 |
{ |
| 1112 |
f->ts.type = BT_INTEGER; |
| 1113 |
f->ts.kind = (kind == NULL) |
| 1114 |
? gfc_default_integer_kind : mpz_get_si (kind->value.integer); |
| 1115 |
f->value.function.name |
| 1116 |
= gfc_get_string ("__floor%d_%c%d", f->ts.kind, |
| 1117 |
gfc_type_letter (a->ts.type), |
| 1118 |
gfc_type_abi_kind (&a->ts)); |
| 1119 |
} |
| 1120 |
|
| 1121 |
|
| 1122 |
void |
| 1123 |
gfc_resolve_fnum (gfc_expr *f, gfc_expr *n) |
| 1124 |
{ |
| 1125 |
f->ts.type = BT_INTEGER; |
| 1126 |
f->ts.kind = gfc_default_integer_kind; |
| 1127 |
if (n->ts.kind != f->ts.kind) |
| 1128 |
gfc_convert_type (n, &f->ts, 2); |
| 1129 |
f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind); |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
void |
| 1134 |
gfc_resolve_fraction (gfc_expr *f, gfc_expr *x) |
| 1135 |
{ |
| 1136 |
f->ts = x->ts; |
| 1137 |
f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind); |
| 1138 |
} |
| 1139 |
|
| 1140 |
|
| 1141 |
/* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */ |
| 1142 |
|
| 1143 |
void |
| 1144 |
gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x) |
| 1145 |
{ |
| 1146 |
f->ts = x->ts; |
| 1147 |
f->value.function.name = gfc_get_string ("<intrinsic>"); |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
void |
| 1152 |
gfc_resolve_gamma (gfc_expr *f, gfc_expr *x) |
| 1153 |
{ |
| 1154 |
f->ts = x->ts; |
| 1155 |
f->value.function.name |
| 1156 |
= gfc_get_string ("__tgamma_%d", x->ts.kind); |
| 1157 |
} |
| 1158 |
|
| 1159 |
|
| 1160 |
void |
| 1161 |
gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED) |
| 1162 |
{ |
| 1163 |
f->ts.type = BT_INTEGER; |
| 1164 |
f->ts.kind = 4; |
| 1165 |
f->value.function.name = gfc_get_string (PREFIX ("getcwd")); |
| 1166 |
} |
| 1167 |
|
| 1168 |
|
| 1169 |
void |
| 1170 |
gfc_resolve_getgid (gfc_expr *f) |
| 1171 |
{ |
| 1172 |
f->ts.type = BT_INTEGER; |
| 1173 |
f->ts.kind = 4; |
| 1174 |
f->value.function.name = gfc_get_string (PREFIX ("getgid")); |
| 1175 |
} |
| 1176 |
|
| 1177 |
|
| 1178 |
void |
| 1179 |
gfc_resolve_getpid (gfc_expr *f) |
| 1180 |
{ |
| 1181 |
f->ts.type = BT_INTEGER; |
| 1182 |
f->ts.kind = 4; |
| 1183 |
f->value.function.name = gfc_get_string (PREFIX ("getpid")); |
| 1184 |
} |
| 1185 |
|
| 1186 |
|
| 1187 |
void |
| 1188 |
gfc_resolve_getuid (gfc_expr *f) |
| 1189 |
{ |
| 1190 |
f->ts.type = BT_INTEGER; |
| 1191 |
f->ts.kind = 4; |
| 1192 |
f->value.function.name = gfc_get_string (PREFIX ("getuid")); |
| 1193 |
} |
| 1194 |
|
| 1195 |
|
| 1196 |
void |
| 1197 |
gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED) |
| 1198 |
{ |
| 1199 |
f->ts.type = BT_INTEGER; |
| 1200 |
f->ts.kind = 4; |
| 1201 |
f->value.function.name = gfc_get_string (PREFIX ("hostnm")); |
| 1202 |
} |
| 1203 |
|
| 1204 |
|
| 1205 |
void |
| 1206 |
gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED) |
| 1207 |
{ |
| 1208 |
f->ts = x->ts; |
| 1209 |
f->value.function.name = gfc_get_string ("__hypot_r%d", |
| 1210 |
gfc_type_abi_kind (&x->ts)); |
| 1211 |
} |
| 1212 |
|
| 1213 |
|
| 1214 |
void |
| 1215 |
gfc_resolve_iall (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask) |
| 1216 |
{ |
| 1217 |
resolve_transformational ("iall", f, array, dim, mask, true); |
| 1218 |
} |
| 1219 |
|
| 1220 |
|
| 1221 |
void |
| 1222 |
gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
| 1223 |
{ |
| 1224 |
/* If the kind of i and j are different, then g77 cross-promoted the |
| 1225 |
kinds to the largest value. The Fortran 95 standard requires the |
| 1226 |
kinds to match. */ |
| 1227 |
|
| 1228 |
if (i->ts.kind != j->ts.kind) |
| 1229 |
{ |
| 1230 |
if (i->ts.kind == gfc_kind_max (i, j)) |
| 1231 |
gfc_convert_type (j, &i->ts, 2); |
| 1232 |
else |
| 1233 |
gfc_convert_type (i, &j->ts, 2); |
| 1234 |
} |
| 1235 |
|
| 1236 |
f->ts = i->ts; |
| 1237 |
const char *name = i->ts.kind == BT_UNSIGNED ? "__iand_m_%d" : "__iand_%d"; |
| 1238 |
f->value.function.name = gfc_get_string (name, i->ts.kind); |
| 1239 |
} |
| 1240 |
|
| 1241 |
|
| 1242 |
void |
| 1243 |
gfc_resolve_iany (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask) |
| 1244 |
{ |
| 1245 |
resolve_transformational ("iany", f, array, dim, mask, true); |
| 1246 |
} |
| 1247 |
|
| 1248 |
|
| 1249 |
void |
| 1250 |
gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED) |
| 1251 |
{ |
| 1252 |
f->ts = i->ts; |
| 1253 |
const char *name = i->ts.kind == BT_UNSIGNED ? "__ibclr_m_%d" : "__ibclr_%d"; |
| 1254 |
f->value.function.name = gfc_get_string (name, i->ts.kind); |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
void |
| 1259 |
gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED, |
| 1260 |
gfc_expr *len ATTRIBUTE_UNUSED) |
| 1261 |
{ |
| 1262 |
f->ts = i->ts; |
| 1263 |
const char *name = i->ts.kind == BT_UNSIGNED ? "__ibits_m_%d" : "__ibits_%d"; |
| 1264 |
f->value.function.name = gfc_get_string (name, i->ts.kind); |
| 1265 |
} |
| 1266 |
|
| 1267 |
|
| 1268 |
void |
| 1269 |
gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED) |
| 1270 |
{ |
| 1271 |
f->ts = i->ts; |
| 1272 |
const char *name = i->ts.kind == BT_UNSIGNED ? "__ibset_m_%d" : "__ibset_%d"; |
| 1273 |
f->value.function.name = gfc_get_string (name, i->ts.kind); |
| 1274 |
} |
| 1275 |
|
| 1276 |
|
| 1277 |
void |
| 1278 |
gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind) |
| 1279 |
{ |
| 1280 |
f->ts.type = BT_INTEGER; |
| 1281 |
if (kind) |
| 1282 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 1283 |
else |
| 1284 |
f->ts.kind = gfc_default_integer_kind; |
| 1285 |
f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind); |
| 1286 |
} |
| 1287 |
|
| 1288 |
|
| 1289 |
void |
| 1290 |
gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind) |
| 1291 |
{ |
| 1292 |
f->ts.type = BT_INTEGER; |
| 1293 |
if (kind) |
| 1294 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 1295 |
else |
| 1296 |
f->ts.kind = gfc_default_integer_kind; |
| 1297 |
f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind); |
| 1298 |
} |
| 1299 |
|
| 1300 |
|
| 1301 |
void |
| 1302 |
gfc_resolve_idnint (gfc_expr *f, gfc_expr *a) |
| 1303 |
{ |
| 1304 |
gfc_resolve_nint (f, a, NULL); |
| 1305 |
} |
| 1306 |
|
| 1307 |
|
| 1308 |
void |
| 1309 |
gfc_resolve_ierrno (gfc_expr *f) |
| 1310 |
{ |
| 1311 |
f->ts.type = BT_INTEGER; |
| 1312 |
f->ts.kind = gfc_default_integer_kind; |
| 1313 |
f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind); |
| 1314 |
} |
| 1315 |
|
| 1316 |
|
| 1317 |
void |
| 1318 |
gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
| 1319 |
{ |
| 1320 |
/* If the kind of i and j are different, then g77 cross-promoted the |
| 1321 |
kinds to the largest value. The Fortran 95 standard requires the |
| 1322 |
kinds to match. */ |
| 1323 |
|
| 1324 |
if (i->ts.kind != j->ts.kind) |
| 1325 |
{ |
| 1326 |
if (i->ts.kind == gfc_kind_max (i, j)) |
| 1327 |
gfc_convert_type (j, &i->ts, 2); |
| 1328 |
else |
| 1329 |
gfc_convert_type (i, &j->ts, 2); |
| 1330 |
} |
| 1331 |
|
| 1332 |
const char *name = i->ts.kind == BT_UNSIGNED ? "__ieor_m_%d" : "__ieor_%d"; |
| 1333 |
f->ts = i->ts; |
| 1334 |
f->value.function.name = gfc_get_string (name, i->ts.kind); |
| 1335 |
} |
| 1336 |
|
| 1337 |
|
| 1338 |
void |
| 1339 |
gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
| 1340 |
{ |
| 1341 |
/* If the kind of i and j are different, then g77 cross-promoted the |
| 1342 |
kinds to the largest value. The Fortran 95 standard requires the |
| 1343 |
kinds to match. */ |
| 1344 |
|
| 1345 |
if (i->ts.kind != j->ts.kind) |
| 1346 |
{ |
| 1347 |
if (i->ts.kind == gfc_kind_max (i, j)) |
| 1348 |
gfc_convert_type (j, &i->ts, 2); |
| 1349 |
else |
| 1350 |
gfc_convert_type (i, &j->ts, 2); |
| 1351 |
} |
| 1352 |
|
| 1353 |
const char *name = i->ts.kind == BT_UNSIGNED ? "__ior_m_%d" : "__ior_%d"; |
| 1354 |
f->ts = i->ts; |
| 1355 |
f->value.function.name = gfc_get_string (name, i->ts.kind); |
| 1356 |
} |
| 1357 |
|
| 1358 |
|
| 1359 |
void |
| 1360 |
gfc_resolve_index_func (gfc_expr *f, gfc_expr *str, |
| 1361 |
gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back, |
| 1362 |
gfc_expr *kind) |
| 1363 |
{ |
| 1364 |
gfc_typespec ts; |
| 1365 |
gfc_clear_ts (&ts); |
| 1366 |
|
| 1367 |
f->ts.type = BT_INTEGER; |
| 1368 |
if (kind) |
| 1369 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 1370 |
else |
| 1371 |
f->ts.kind = gfc_default_integer_kind; |
| 1372 |
|
| 1373 |
if (back && back->ts.kind != gfc_default_integer_kind) |
| 1374 |
{ |
| 1375 |
ts.type = BT_LOGICAL; |
| 1376 |
ts.kind = gfc_default_integer_kind; |
| 1377 |
ts.u.derived = NULL; |
| 1378 |
ts.u.cl = NULL; |
| 1379 |
gfc_convert_type (back, &ts, 2); |
| 1380 |
} |
| 1381 |
|
| 1382 |
f->value.function.name |
| 1383 |
= gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind); |
| 1384 |
} |
| 1385 |
|
| 1386 |
|
| 1387 |
void |
| 1388 |
gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 1389 |
{ |
| 1390 |
f->ts.type = BT_INTEGER; |
| 1391 |
f->ts.kind = (kind == NULL) |
| 1392 |
? gfc_default_integer_kind : mpz_get_si (kind->value.integer); |
| 1393 |
f->value.function.name |
| 1394 |
= gfc_get_string ("__int_%d_%c%d", f->ts.kind, |
| 1395 |
gfc_type_letter (a->ts.type), |
| 1396 |
gfc_type_abi_kind (&a->ts)); |
| 1397 |
} |
| 1398 |
|
| 1399 |
void |
| 1400 |
gfc_resolve_uint (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 1401 |
{ |
| 1402 |
f->ts.type = BT_UNSIGNED; |
| 1403 |
f->ts.kind = (kind == NULL) |
| 1404 |
? gfc_default_integer_kind : mpz_get_si (kind->value.integer); |
| 1405 |
f->value.function.name |
| 1406 |
= gfc_get_string ("__uint_%d_%c%d", f->ts.kind, |
| 1407 |
gfc_type_letter (a->ts.type), |
| 1408 |
gfc_type_abi_kind (&a->ts)); |
| 1409 |
} |
| 1410 |
|
| 1411 |
|
| 1412 |
void |
| 1413 |
gfc_resolve_int2 (gfc_expr *f, gfc_expr *a) |
| 1414 |
{ |
| 1415 |
f->ts.type = BT_INTEGER; |
| 1416 |
f->ts.kind = 2; |
| 1417 |
f->value.function.name |
| 1418 |
= gfc_get_string ("__int_%d_%c%d", f->ts.kind, |
| 1419 |
gfc_type_letter (a->ts.type), |
| 1420 |
gfc_type_abi_kind (&a->ts)); |
| 1421 |
} |
| 1422 |
|
| 1423 |
|
| 1424 |
void |
| 1425 |
gfc_resolve_int8 (gfc_expr *f, gfc_expr *a) |
| 1426 |
{ |
| 1427 |
f->ts.type = BT_INTEGER; |
| 1428 |
f->ts.kind = 8; |
| 1429 |
f->value.function.name |
| 1430 |
= gfc_get_string ("__int_%d_%c%d", f->ts.kind, |
| 1431 |
gfc_type_letter (a->ts.type), |
| 1432 |
gfc_type_abi_kind (&a->ts)); |
| 1433 |
} |
| 1434 |
|
| 1435 |
|
| 1436 |
void |
| 1437 |
gfc_resolve_long (gfc_expr *f, gfc_expr *a) |
| 1438 |
{ |
| 1439 |
f->ts.type = BT_INTEGER; |
| 1440 |
f->ts.kind = 4; |
| 1441 |
f->value.function.name |
| 1442 |
= gfc_get_string ("__int_%d_%c%d", f->ts.kind, |
| 1443 |
gfc_type_letter (a->ts.type), |
| 1444 |
gfc_type_abi_kind (&a->ts)); |
| 1445 |
} |
| 1446 |
|
| 1447 |
|
| 1448 |
void |
| 1449 |
gfc_resolve_iparity (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask) |
| 1450 |
{ |
| 1451 |
resolve_transformational ("iparity", f, array, dim, mask, true); |
| 1452 |
} |
| 1453 |
|
| 1454 |
|
| 1455 |
void |
| 1456 |
gfc_resolve_isatty (gfc_expr *f, gfc_expr *u) |
| 1457 |
{ |
| 1458 |
gfc_typespec ts; |
| 1459 |
gfc_clear_ts (&ts); |
| 1460 |
|
| 1461 |
f->ts.type = BT_LOGICAL; |
| 1462 |
f->ts.kind = gfc_default_integer_kind; |
| 1463 |
if (u->ts.kind != gfc_c_int_kind) |
| 1464 |
{ |
| 1465 |
ts.type = BT_INTEGER; |
| 1466 |
ts.kind = gfc_c_int_kind; |
| 1467 |
ts.u.derived = NULL; |
| 1468 |
ts.u.cl = NULL; |
| 1469 |
gfc_convert_type (u, &ts, 2); |
| 1470 |
} |
| 1471 |
|
| 1472 |
f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind); |
| 1473 |
} |
| 1474 |
|
| 1475 |
|
| 1476 |
void |
| 1477 |
gfc_resolve_is_contiguous (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED) |
| 1478 |
{ |
| 1479 |
f->ts.type = BT_LOGICAL; |
| 1480 |
f->ts.kind = gfc_default_logical_kind; |
| 1481 |
f->value.function.name = gfc_get_string ("__is_contiguous"); |
| 1482 |
} |
| 1483 |
|
| 1484 |
|
| 1485 |
void |
| 1486 |
gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift) |
| 1487 |
{ |
| 1488 |
f->ts = i->ts; |
| 1489 |
f->value.function.name |
| 1490 |
= gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind); |
| 1491 |
} |
| 1492 |
|
| 1493 |
|
| 1494 |
void |
| 1495 |
gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift) |
| 1496 |
{ |
| 1497 |
f->ts = i->ts; |
| 1498 |
f->value.function.name |
| 1499 |
= gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind); |
| 1500 |
} |
| 1501 |
|
| 1502 |
|
| 1503 |
void |
| 1504 |
gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift) |
| 1505 |
{ |
| 1506 |
f->ts = i->ts; |
| 1507 |
f->value.function.name |
| 1508 |
= gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind); |
| 1509 |
} |
| 1510 |
|
| 1511 |
|
| 1512 |
void |
| 1513 |
gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size) |
| 1514 |
{ |
| 1515 |
int s_kind; |
| 1516 |
|
| 1517 |
s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind; |
| 1518 |
|
| 1519 |
f->ts = i->ts; |
| 1520 |
f->value.function.name |
| 1521 |
= gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind); |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
void |
| 1526 |
gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind) |
| 1527 |
{ |
| 1528 |
resolve_bound (f, array, dim, kind, "__lbound", false); |
| 1529 |
} |
| 1530 |
|
| 1531 |
|
| 1532 |
void |
| 1533 |
gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind) |
| 1534 |
{ |
| 1535 |
resolve_bound (f, array, dim, kind, "__lcobound", true); |
| 1536 |
} |
| 1537 |
|
| 1538 |
|
| 1539 |
void |
| 1540 |
gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind) |
| 1541 |
{ |
| 1542 |
f->ts.type = BT_INTEGER; |
| 1543 |
if (kind) |
| 1544 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 1545 |
else |
| 1546 |
f->ts.kind = gfc_default_integer_kind; |
| 1547 |
f->value.function.name |
| 1548 |
= gfc_get_string ("__len_%d_i%d", string->ts.kind, |
| 1549 |
gfc_default_integer_kind); |
| 1550 |
} |
| 1551 |
|
| 1552 |
|
| 1553 |
void |
| 1554 |
gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind) |
| 1555 |
{ |
| 1556 |
f->ts.type = BT_INTEGER; |
| 1557 |
if (kind) |
| 1558 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 1559 |
else |
| 1560 |
f->ts.kind = gfc_default_integer_kind; |
| 1561 |
f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind); |
| 1562 |
} |
| 1563 |
|
| 1564 |
|
| 1565 |
void |
| 1566 |
gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x) |
| 1567 |
{ |
| 1568 |
f->ts = x->ts; |
| 1569 |
f->value.function.name |
| 1570 |
= gfc_get_string ("__lgamma_%d", x->ts.kind); |
| 1571 |
} |
| 1572 |
|
| 1573 |
|
| 1574 |
void |
| 1575 |
gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED, |
| 1576 |
gfc_expr *p2 ATTRIBUTE_UNUSED) |
| 1577 |
{ |
| 1578 |
f->ts.type = BT_INTEGER; |
| 1579 |
f->ts.kind = gfc_default_integer_kind; |
| 1580 |
f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind); |
| 1581 |
} |
| 1582 |
|
| 1583 |
|
| 1584 |
void |
| 1585 |
gfc_resolve_loc (gfc_expr *f, gfc_expr *x) |
| 1586 |
{ |
| 1587 |
f->ts.type= BT_INTEGER; |
| 1588 |
f->ts.kind = gfc_index_integer_kind; |
| 1589 |
f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind); |
| 1590 |
} |
| 1591 |
|
| 1592 |
|
| 1593 |
void |
| 1594 |
gfc_resolve_log (gfc_expr *f, gfc_expr *x) |
| 1595 |
{ |
| 1596 |
f->ts = x->ts; |
| 1597 |
f->value.function.name |
| 1598 |
= gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), |
| 1599 |
gfc_type_abi_kind (&x->ts)); |
| 1600 |
} |
| 1601 |
|
| 1602 |
|
| 1603 |
void |
| 1604 |
gfc_resolve_log10 (gfc_expr *f, gfc_expr *x) |
| 1605 |
{ |
| 1606 |
f->ts = x->ts; |
| 1607 |
f->value.function.name |
| 1608 |
= gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type), |
| 1609 |
gfc_type_abi_kind (&x->ts)); |
| 1610 |
} |
| 1611 |
|
| 1612 |
|
| 1613 |
void |
| 1614 |
gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 1615 |
{ |
| 1616 |
f->ts.type = BT_LOGICAL; |
| 1617 |
f->ts.kind = (kind == NULL) |
| 1618 |
? gfc_default_logical_kind : mpz_get_si (kind->value.integer); |
| 1619 |
f->rank = a->rank; |
| 1620 |
f->corank = a->corank; |
| 1621 |
|
| 1622 |
f->value.function.name |
| 1623 |
= gfc_get_string ("__logical_%d_%c%d", f->ts.kind, |
| 1624 |
gfc_type_letter (a->ts.type), |
| 1625 |
gfc_type_abi_kind (&a->ts)); |
| 1626 |
} |
| 1627 |
|
| 1628 |
|
| 1629 |
void |
| 1630 |
gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b) |
| 1631 |
{ |
| 1632 |
gfc_expr temp; |
| 1633 |
bt type; |
| 1634 |
|
| 1635 |
if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL) |
| 1636 |
{ |
| 1637 |
f->ts.type = BT_LOGICAL; |
| 1638 |
f->ts.kind = gfc_default_logical_kind; |
| 1639 |
} |
| 1640 |
else |
| 1641 |
{ |
| 1642 |
temp.expr_type = EXPR_OP; |
| 1643 |
gfc_clear_ts (&temp.ts); |
| 1644 |
temp.value.op.op = INTRINSIC_NONE; |
| 1645 |
temp.value.op.op1 = a; |
| 1646 |
temp.value.op.op2 = b; |
| 1647 |
gfc_type_convert_binary (&temp, 1); |
| 1648 |
f->ts = temp.ts; |
| 1649 |
} |
| 1650 |
|
| 1651 |
f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1; |
| 1652 |
f->corank = a->corank; |
| 1653 |
|
| 1654 |
if (a->rank == 2 && b->rank == 2) |
| 1655 |
{ |
| 1656 |
if (a->shape && b->shape) |
| 1657 |
{ |
| 1658 |
f->shape = gfc_get_shape (f->rank); |
| 1659 |
mpz_init_set (f->shape[0], a->shape[0]); |
| 1660 |
mpz_init_set (f->shape[1], b->shape[1]); |
| 1661 |
} |
| 1662 |
} |
| 1663 |
else if (a->rank == 1) |
| 1664 |
{ |
| 1665 |
if (b->shape) |
| 1666 |
{ |
| 1667 |
f->shape = gfc_get_shape (f->rank); |
| 1668 |
mpz_init_set (f->shape[0], b->shape[1]); |
| 1669 |
} |
| 1670 |
} |
| 1671 |
else |
| 1672 |
{ |
| 1673 |
/* b->rank == 1 and a->rank == 2 here, all other cases have |
| 1674 |
been caught in check.cc. */ |
| 1675 |
if (a->shape) |
| 1676 |
{ |
| 1677 |
f->shape = gfc_get_shape (f->rank); |
| 1678 |
mpz_init_set (f->shape[0], a->shape[0]); |
| 1679 |
} |
| 1680 |
} |
| 1681 |
|
| 1682 |
/* We use the same library version of matmul for INTEGER and UNSIGNED, |
| 1683 |
which we call as the INTEGER version. */ |
| 1684 |
|
| 1685 |
if (f->ts.type == BT_UNSIGNED) |
| 1686 |
type = BT_INTEGER; |
| 1687 |
else |
| 1688 |
type = f->ts.type; |
| 1689 |
|
| 1690 |
f->value.function.name |
| 1691 |
= gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (type), |
| 1692 |
gfc_type_abi_kind (&f->ts)); |
| 1693 |
} |
| 1694 |
|
| 1695 |
|
| 1696 |
static void |
| 1697 |
gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args) |
| 1698 |
{ |
| 1699 |
gfc_actual_arglist *a; |
| 1700 |
|
| 1701 |
f->ts.type = args->expr->ts.type; |
| 1702 |
f->ts.kind = args->expr->ts.kind; |
| 1703 |
/* Find the largest type kind. */ |
| 1704 |
for (a = args->next; a; a = a->next) |
| 1705 |
{ |
| 1706 |
if (a->expr->ts.kind > f->ts.kind) |
| 1707 |
f->ts.kind = a->expr->ts.kind; |
| 1708 |
} |
| 1709 |
|
| 1710 |
/* Convert all parameters to the required kind. */ |
| 1711 |
for (a = args; a; a = a->next) |
| 1712 |
{ |
| 1713 |
if (a->expr->ts.kind != f->ts.kind) |
| 1714 |
gfc_convert_type (a->expr, &f->ts, 2); |
| 1715 |
} |
| 1716 |
|
| 1717 |
f->value.function.name |
| 1718 |
= gfc_get_string (name, gfc_type_letter (f->ts.type), |
| 1719 |
gfc_type_abi_kind (&f->ts)); |
| 1720 |
} |
| 1721 |
|
| 1722 |
|
| 1723 |
void |
| 1724 |
gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args) |
| 1725 |
{ |
| 1726 |
gfc_resolve_minmax ("__max_%c%d", f, args); |
| 1727 |
} |
| 1728 |
|
| 1729 |
/* The smallest kind for which a minloc and maxloc implementation exists. */ |
| 1730 |
|
| 1731 |
#define MINMAXLOC_MIN_KIND 4 |
| 1732 |
|
| 1733 |
void |
| 1734 |
gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
| 1735 |
gfc_expr *mask, gfc_expr *kind, gfc_expr *back) |
| 1736 |
{ |
| 1737 |
const char *name; |
| 1738 |
int i, j, idim; |
| 1739 |
int fkind; |
| 1740 |
int d_num; |
| 1741 |
|
| 1742 |
f->ts.type = BT_INTEGER; |
| 1743 |
|
| 1744 |
/* The library versions only exist for kinds 4, 8 and 16. For smaller kinds, |
| 1745 |
we do a type conversion further down. */ |
| 1746 |
if (kind) |
| 1747 |
fkind = mpz_get_si (kind->value.integer); |
| 1748 |
else |
| 1749 |
fkind = gfc_default_integer_kind; |
| 1750 |
|
| 1751 |
if (fkind < MINMAXLOC_MIN_KIND) |
| 1752 |
f->ts.kind = MINMAXLOC_MIN_KIND; |
| 1753 |
else |
| 1754 |
f->ts.kind = fkind; |
| 1755 |
|
| 1756 |
if (dim == NULL) |
| 1757 |
{ |
| 1758 |
f->rank = 1; |
| 1759 |
f->shape = gfc_get_shape (1); |
| 1760 |
mpz_init_set_si (f->shape[0], array->rank); |
| 1761 |
} |
| 1762 |
else |
| 1763 |
{ |
| 1764 |
f->rank = array->rank - 1; |
| 1765 |
gfc_resolve_dim_arg (dim); |
| 1766 |
if (array->shape && dim->expr_type == EXPR_CONSTANT) |
| 1767 |
{ |
| 1768 |
idim = (int) mpz_get_si (dim->value.integer); |
| 1769 |
f->shape = gfc_get_shape (f->rank); |
| 1770 |
for (i = 0, j = 0; i < f->rank; i++, j++) |
| 1771 |
{ |
| 1772 |
if (i == (idim - 1)) |
| 1773 |
j++; |
| 1774 |
mpz_init_set (f->shape[i], array->shape[j]); |
| 1775 |
} |
| 1776 |
} |
| 1777 |
} |
| 1778 |
|
| 1779 |
if (mask) |
| 1780 |
{ |
| 1781 |
if (mask->rank == 0) |
| 1782 |
name = "smaxloc"; |
| 1783 |
else |
| 1784 |
name = "mmaxloc"; |
| 1785 |
|
| 1786 |
resolve_mask_arg (mask); |
| 1787 |
} |
| 1788 |
else |
| 1789 |
name = "maxloc"; |
| 1790 |
|
| 1791 |
if (dim) |
| 1792 |
{ |
| 1793 |
if (array->ts.type != BT_CHARACTER || f->rank != 0) |
| 1794 |
d_num = 1; |
| 1795 |
else |
| 1796 |
d_num = 2; |
| 1797 |
} |
| 1798 |
else |
| 1799 |
d_num = 0; |
| 1800 |
|
| 1801 |
f->value.function.name |
| 1802 |
= gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, d_num, f->ts.kind, |
| 1803 |
gfc_type_letter (array->ts.type), |
| 1804 |
gfc_type_abi_kind (&array->ts)); |
| 1805 |
|
| 1806 |
if (kind) |
| 1807 |
fkind = mpz_get_si (kind->value.integer); |
| 1808 |
else |
| 1809 |
fkind = gfc_default_integer_kind; |
| 1810 |
|
| 1811 |
if (fkind != f->ts.kind) |
| 1812 |
{ |
| 1813 |
gfc_typespec ts; |
| 1814 |
gfc_clear_ts (&ts); |
| 1815 |
|
| 1816 |
ts.type = BT_INTEGER; |
| 1817 |
ts.kind = fkind; |
| 1818 |
gfc_convert_type_warn (f, &ts, 2, 0); |
| 1819 |
} |
| 1820 |
|
| 1821 |
if (back->ts.kind != gfc_logical_4_kind) |
| 1822 |
{ |
| 1823 |
gfc_typespec ts; |
| 1824 |
gfc_clear_ts (&ts); |
| 1825 |
ts.type = BT_LOGICAL; |
| 1826 |
ts.kind = gfc_logical_4_kind; |
| 1827 |
gfc_convert_type_warn (back, &ts, 2, 0); |
| 1828 |
} |
| 1829 |
} |
| 1830 |
|
| 1831 |
|
| 1832 |
void |
| 1833 |
gfc_resolve_findloc (gfc_expr *f, gfc_expr *array, gfc_expr *value, |
| 1834 |
gfc_expr *dim, gfc_expr *mask, gfc_expr *kind, |
| 1835 |
gfc_expr *back) |
| 1836 |
{ |
| 1837 |
const char *name; |
| 1838 |
int i, j, idim; |
| 1839 |
int fkind; |
| 1840 |
int d_num; |
| 1841 |
bt type; |
| 1842 |
|
| 1843 |
/* See at the end of the function for why this is necessary. */ |
| 1844 |
|
| 1845 |
if (f->do_not_resolve_again) |
| 1846 |
return; |
| 1847 |
|
| 1848 |
f->ts.type = BT_INTEGER; |
| 1849 |
|
| 1850 |
/* We have a single library version, which uses index_type. */ |
| 1851 |
|
| 1852 |
if (kind) |
| 1853 |
fkind = mpz_get_si (kind->value.integer); |
| 1854 |
else |
| 1855 |
fkind = gfc_default_integer_kind; |
| 1856 |
|
| 1857 |
f->ts.kind = gfc_index_integer_kind; |
| 1858 |
|
| 1859 |
/* Convert value. If array is not LOGICAL and value is, we already |
| 1860 |
issued an error earlier. */ |
| 1861 |
|
| 1862 |
if ((array->ts.type != value->ts.type && value->ts.type != BT_LOGICAL) |
| 1863 |
|| array->ts.kind != value->ts.kind) |
| 1864 |
gfc_convert_type_warn (value, &array->ts, 2, 0); |
| 1865 |
|
| 1866 |
if (dim == NULL) |
| 1867 |
{ |
| 1868 |
f->rank = 1; |
| 1869 |
f->shape = gfc_get_shape (1); |
| 1870 |
mpz_init_set_si (f->shape[0], array->rank); |
| 1871 |
} |
| 1872 |
else |
| 1873 |
{ |
| 1874 |
f->rank = array->rank - 1; |
| 1875 |
gfc_resolve_dim_arg (dim); |
| 1876 |
if (array->shape && dim->expr_type == EXPR_CONSTANT) |
| 1877 |
{ |
| 1878 |
idim = (int) mpz_get_si (dim->value.integer); |
| 1879 |
f->shape = gfc_get_shape (f->rank); |
| 1880 |
for (i = 0, j = 0; i < f->rank; i++, j++) |
| 1881 |
{ |
| 1882 |
if (i == (idim - 1)) |
| 1883 |
j++; |
| 1884 |
mpz_init_set (f->shape[i], array->shape[j]); |
| 1885 |
} |
| 1886 |
} |
| 1887 |
} |
| 1888 |
|
| 1889 |
if (mask) |
| 1890 |
{ |
| 1891 |
if (mask->rank == 0) |
| 1892 |
name = "sfindloc"; |
| 1893 |
else |
| 1894 |
name = "mfindloc"; |
| 1895 |
|
| 1896 |
resolve_mask_arg (mask); |
| 1897 |
} |
| 1898 |
else |
| 1899 |
name = "findloc"; |
| 1900 |
|
| 1901 |
if (dim) |
| 1902 |
{ |
| 1903 |
if (f->rank > 0) |
| 1904 |
d_num = 1; |
| 1905 |
else |
| 1906 |
d_num = 2; |
| 1907 |
} |
| 1908 |
else |
| 1909 |
d_num = 0; |
| 1910 |
|
| 1911 |
if (back->ts.kind != gfc_logical_4_kind) |
| 1912 |
{ |
| 1913 |
gfc_typespec ts; |
| 1914 |
gfc_clear_ts (&ts); |
| 1915 |
ts.type = BT_LOGICAL; |
| 1916 |
ts.kind = gfc_logical_4_kind; |
| 1917 |
gfc_convert_type_warn (back, &ts, 2, 0); |
| 1918 |
} |
| 1919 |
|
| 1920 |
/* Use the INTEGER library function for UNSIGNED. */ |
| 1921 |
if (array->ts.type != BT_UNSIGNED) |
| 1922 |
type = array->ts.type; |
| 1923 |
else |
| 1924 |
type = BT_INTEGER; |
| 1925 |
|
| 1926 |
f->value.function.name |
| 1927 |
= gfc_get_string (PREFIX ("%s%d_%c%d"), name, d_num, |
| 1928 |
gfc_type_letter (type, true), |
| 1929 |
gfc_type_abi_kind (&array->ts)); |
| 1930 |
|
| 1931 |
/* We only have a single library function, so we need to convert |
| 1932 |
here. If the function is resolved from within a convert |
| 1933 |
function generated on a previous round of resolution, endless |
| 1934 |
recursion could occur. Guard against that here. */ |
| 1935 |
|
| 1936 |
if (f->ts.kind != fkind) |
| 1937 |
{ |
| 1938 |
f->do_not_resolve_again = 1; |
| 1939 |
gfc_typespec ts; |
| 1940 |
gfc_clear_ts (&ts); |
| 1941 |
|
| 1942 |
ts.type = BT_INTEGER; |
| 1943 |
ts.kind = fkind; |
| 1944 |
gfc_convert_type_warn (f, &ts, 2, 0); |
| 1945 |
} |
| 1946 |
|
| 1947 |
} |
| 1948 |
|
| 1949 |
void |
| 1950 |
gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
| 1951 |
gfc_expr *mask) |
| 1952 |
{ |
| 1953 |
const char *name; |
| 1954 |
int i, j, idim; |
| 1955 |
|
| 1956 |
f->ts = array->ts; |
| 1957 |
|
| 1958 |
if (dim != NULL) |
| 1959 |
{ |
| 1960 |
f->rank = array->rank - 1; |
| 1961 |
gfc_resolve_dim_arg (dim); |
| 1962 |
|
| 1963 |
if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT) |
| 1964 |
{ |
| 1965 |
idim = (int) mpz_get_si (dim->value.integer); |
| 1966 |
f->shape = gfc_get_shape (f->rank); |
| 1967 |
for (i = 0, j = 0; i < f->rank; i++, j++) |
| 1968 |
{ |
| 1969 |
if (i == (idim - 1)) |
| 1970 |
j++; |
| 1971 |
mpz_init_set (f->shape[i], array->shape[j]); |
| 1972 |
} |
| 1973 |
} |
| 1974 |
} |
| 1975 |
|
| 1976 |
if (mask) |
| 1977 |
{ |
| 1978 |
if (mask->rank == 0) |
| 1979 |
name = "smaxval"; |
| 1980 |
else |
| 1981 |
name = "mmaxval"; |
| 1982 |
|
| 1983 |
resolve_mask_arg (mask); |
| 1984 |
} |
| 1985 |
else |
| 1986 |
name = "maxval"; |
| 1987 |
|
| 1988 |
if (array->ts.type != BT_CHARACTER) |
| 1989 |
f->value.function.name |
| 1990 |
= gfc_get_string (PREFIX ("%s_%c%d"), name, |
| 1991 |
gfc_type_letter (array->ts.type), |
| 1992 |
gfc_type_abi_kind (&array->ts)); |
| 1993 |
else |
| 1994 |
f->value.function.name |
| 1995 |
= gfc_get_string (PREFIX ("%s%d_%c%d"), name, f->rank != 0, |
| 1996 |
gfc_type_letter (array->ts.type), |
| 1997 |
gfc_type_abi_kind (&array->ts)); |
| 1998 |
} |
| 1999 |
|
| 2000 |
|
| 2001 |
void |
| 2002 |
gfc_resolve_mclock (gfc_expr *f) |
| 2003 |
{ |
| 2004 |
f->ts.type = BT_INTEGER; |
| 2005 |
f->ts.kind = 4; |
| 2006 |
f->value.function.name = PREFIX ("mclock"); |
| 2007 |
} |
| 2008 |
|
| 2009 |
|
| 2010 |
void |
| 2011 |
gfc_resolve_mclock8 (gfc_expr *f) |
| 2012 |
{ |
| 2013 |
f->ts.type = BT_INTEGER; |
| 2014 |
f->ts.kind = 8; |
| 2015 |
f->value.function.name = PREFIX ("mclock8"); |
| 2016 |
} |
| 2017 |
|
| 2018 |
|
| 2019 |
void |
| 2020 |
gfc_resolve_mask (gfc_expr *f, gfc_expr *i ATTRIBUTE_UNUSED, |
| 2021 |
gfc_expr *kind) |
| 2022 |
{ |
| 2023 |
f->ts.type = BT_INTEGER; |
| 2024 |
f->ts.kind = kind ? mpz_get_si (kind->value.integer) |
| 2025 |
: gfc_default_integer_kind; |
| 2026 |
|
| 2027 |
if (f->value.function.isym->id == GFC_ISYM_MASKL) |
| 2028 |
f->value.function.name = gfc_get_string ("__maskl_i%d", f->ts.kind); |
| 2029 |
else |
| 2030 |
f->value.function.name = gfc_get_string ("__maskr_i%d", f->ts.kind); |
| 2031 |
} |
| 2032 |
|
| 2033 |
void |
| 2034 |
gfc_resolve_umasklr (gfc_expr *f, gfc_expr *i ATTRIBUTE_UNUSED, |
| 2035 |
gfc_expr *kind) |
| 2036 |
{ |
| 2037 |
f->ts.type = BT_UNSIGNED; |
| 2038 |
f->ts.kind = kind ? mpz_get_si (kind->value.integer) |
| 2039 |
: gfc_default_unsigned_kind; |
| 2040 |
|
| 2041 |
if (f->value.function.isym->id == GFC_ISYM_UMASKL) |
| 2042 |
f->value.function.name = gfc_get_string ("__maskl_m%d", f->ts.kind); |
| 2043 |
else |
| 2044 |
f->value.function.name = gfc_get_string ("__maskr_m%d", f->ts.kind); |
| 2045 |
} |
| 2046 |
|
| 2047 |
|
| 2048 |
void |
| 2049 |
gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource, |
| 2050 |
gfc_expr *fsource ATTRIBUTE_UNUSED, |
| 2051 |
gfc_expr *mask ATTRIBUTE_UNUSED) |
| 2052 |
{ |
| 2053 |
if (tsource->ts.type == BT_CHARACTER && tsource->ref) |
| 2054 |
gfc_resolve_substring_charlen (tsource); |
| 2055 |
|
| 2056 |
if (fsource->ts.type == BT_CHARACTER && fsource->ref) |
| 2057 |
gfc_resolve_substring_charlen (fsource); |
| 2058 |
|
| 2059 |
if (tsource->ts.type == BT_CHARACTER) |
| 2060 |
check_charlen_present (tsource); |
| 2061 |
|
| 2062 |
f->ts = tsource->ts; |
| 2063 |
f->value.function.name |
| 2064 |
= gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type), |
| 2065 |
gfc_type_abi_kind (&tsource->ts)); |
| 2066 |
} |
| 2067 |
|
| 2068 |
|
| 2069 |
void |
| 2070 |
gfc_resolve_merge_bits (gfc_expr *f, gfc_expr *i, |
| 2071 |
gfc_expr *j ATTRIBUTE_UNUSED, |
| 2072 |
gfc_expr *mask ATTRIBUTE_UNUSED) |
| 2073 |
{ |
| 2074 |
f->ts = i->ts; |
| 2075 |
|
| 2076 |
f->value.function.name |
| 2077 |
= gfc_get_string ("__merge_bits_%c%d", gfc_type_letter (i->ts.type), |
| 2078 |
i->ts.kind); |
| 2079 |
} |
| 2080 |
|
| 2081 |
|
| 2082 |
void |
| 2083 |
gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args) |
| 2084 |
{ |
| 2085 |
gfc_resolve_minmax ("__min_%c%d", f, args); |
| 2086 |
} |
| 2087 |
|
| 2088 |
|
| 2089 |
void |
| 2090 |
gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
| 2091 |
gfc_expr *mask, gfc_expr *kind, gfc_expr *back) |
| 2092 |
{ |
| 2093 |
const char *name; |
| 2094 |
int i, j, idim; |
| 2095 |
int fkind; |
| 2096 |
int d_num; |
| 2097 |
|
| 2098 |
f->ts.type = BT_INTEGER; |
| 2099 |
|
| 2100 |
/* The library versions only exist for kinds 4, 8 and 16. For smaller kinds, |
| 2101 |
we do a type conversion further down. */ |
| 2102 |
if (kind) |
| 2103 |
fkind = mpz_get_si (kind->value.integer); |
| 2104 |
else |
| 2105 |
fkind = gfc_default_integer_kind; |
| 2106 |
|
| 2107 |
if (fkind < MINMAXLOC_MIN_KIND) |
| 2108 |
f->ts.kind = MINMAXLOC_MIN_KIND; |
| 2109 |
else |
| 2110 |
f->ts.kind = fkind; |
| 2111 |
|
| 2112 |
if (dim == NULL) |
| 2113 |
{ |
| 2114 |
f->rank = 1; |
| 2115 |
f->shape = gfc_get_shape (1); |
| 2116 |
mpz_init_set_si (f->shape[0], array->rank); |
| 2117 |
} |
| 2118 |
else |
| 2119 |
{ |
| 2120 |
f->rank = array->rank - 1; |
| 2121 |
gfc_resolve_dim_arg (dim); |
| 2122 |
if (array->shape && dim->expr_type == EXPR_CONSTANT) |
| 2123 |
{ |
| 2124 |
idim = (int) mpz_get_si (dim->value.integer); |
| 2125 |
f->shape = gfc_get_shape (f->rank); |
| 2126 |
for (i = 0, j = 0; i < f->rank; i++, j++) |
| 2127 |
{ |
| 2128 |
if (i == (idim - 1)) |
| 2129 |
j++; |
| 2130 |
mpz_init_set (f->shape[i], array->shape[j]); |
| 2131 |
} |
| 2132 |
} |
| 2133 |
} |
| 2134 |
|
| 2135 |
if (mask) |
| 2136 |
{ |
| 2137 |
if (mask->rank == 0) |
| 2138 |
name = "sminloc"; |
| 2139 |
else |
| 2140 |
name = "mminloc"; |
| 2141 |
|
| 2142 |
resolve_mask_arg (mask); |
| 2143 |
} |
| 2144 |
else |
| 2145 |
name = "minloc"; |
| 2146 |
|
| 2147 |
if (dim) |
| 2148 |
{ |
| 2149 |
if (array->ts.type != BT_CHARACTER || f->rank != 0) |
| 2150 |
d_num = 1; |
| 2151 |
else |
| 2152 |
d_num = 2; |
| 2153 |
} |
| 2154 |
else |
| 2155 |
d_num = 0; |
| 2156 |
|
| 2157 |
f->value.function.name |
| 2158 |
= gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, d_num, f->ts.kind, |
| 2159 |
gfc_type_letter (array->ts.type), |
| 2160 |
gfc_type_abi_kind (&array->ts)); |
| 2161 |
|
| 2162 |
if (fkind != f->ts.kind) |
| 2163 |
{ |
| 2164 |
gfc_typespec ts; |
| 2165 |
gfc_clear_ts (&ts); |
| 2166 |
|
| 2167 |
ts.type = BT_INTEGER; |
| 2168 |
ts.kind = fkind; |
| 2169 |
gfc_convert_type_warn (f, &ts, 2, 0); |
| 2170 |
} |
| 2171 |
|
| 2172 |
if (back->ts.kind != gfc_logical_4_kind) |
| 2173 |
{ |
| 2174 |
gfc_typespec ts; |
| 2175 |
gfc_clear_ts (&ts); |
| 2176 |
ts.type = BT_LOGICAL; |
| 2177 |
ts.kind = gfc_logical_4_kind; |
| 2178 |
gfc_convert_type_warn (back, &ts, 2, 0); |
| 2179 |
} |
| 2180 |
} |
| 2181 |
|
| 2182 |
|
| 2183 |
void |
| 2184 |
gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
| 2185 |
gfc_expr *mask) |
| 2186 |
{ |
| 2187 |
const char *name; |
| 2188 |
int i, j, idim; |
| 2189 |
|
| 2190 |
f->ts = array->ts; |
| 2191 |
|
| 2192 |
if (dim != NULL) |
| 2193 |
{ |
| 2194 |
f->rank = array->rank - 1; |
| 2195 |
gfc_resolve_dim_arg (dim); |
| 2196 |
|
| 2197 |
if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT) |
| 2198 |
{ |
| 2199 |
idim = (int) mpz_get_si (dim->value.integer); |
| 2200 |
f->shape = gfc_get_shape (f->rank); |
| 2201 |
for (i = 0, j = 0; i < f->rank; i++, j++) |
| 2202 |
{ |
| 2203 |
if (i == (idim - 1)) |
| 2204 |
j++; |
| 2205 |
mpz_init_set (f->shape[i], array->shape[j]); |
| 2206 |
} |
| 2207 |
} |
| 2208 |
} |
| 2209 |
|
| 2210 |
if (mask) |
| 2211 |
{ |
| 2212 |
if (mask->rank == 0) |
| 2213 |
name = "sminval"; |
| 2214 |
else |
| 2215 |
name = "mminval"; |
| 2216 |
|
| 2217 |
resolve_mask_arg (mask); |
| 2218 |
} |
| 2219 |
else |
| 2220 |
name = "minval"; |
| 2221 |
|
| 2222 |
if (array->ts.type != BT_CHARACTER) |
| 2223 |
f->value.function.name |
| 2224 |
= gfc_get_string (PREFIX ("%s_%c%d"), name, |
| 2225 |
gfc_type_letter (array->ts.type), |
| 2226 |
gfc_type_abi_kind (&array->ts)); |
| 2227 |
else |
| 2228 |
f->value.function.name |
| 2229 |
= gfc_get_string (PREFIX ("%s%d_%c%d"), name, f->rank != 0, |
| 2230 |
gfc_type_letter (array->ts.type), |
| 2231 |
gfc_type_abi_kind (&array->ts)); |
| 2232 |
} |
| 2233 |
|
| 2234 |
|
| 2235 |
void |
| 2236 |
gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p) |
| 2237 |
{ |
| 2238 |
f->ts.type = a->ts.type; |
| 2239 |
if (p != NULL) |
| 2240 |
f->ts.kind = gfc_kind_max (a,p); |
| 2241 |
else |
| 2242 |
f->ts.kind = a->ts.kind; |
| 2243 |
|
| 2244 |
if (p != NULL && a->ts.kind != p->ts.kind) |
| 2245 |
{ |
| 2246 |
if (a->ts.kind == gfc_kind_max (a,p)) |
| 2247 |
gfc_convert_type (p, &a->ts, 2); |
| 2248 |
else |
| 2249 |
gfc_convert_type (a, &p->ts, 2); |
| 2250 |
} |
| 2251 |
|
| 2252 |
f->value.function.name |
| 2253 |
= gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), |
| 2254 |
gfc_type_abi_kind (&f->ts)); |
| 2255 |
} |
| 2256 |
|
| 2257 |
|
| 2258 |
void |
| 2259 |
gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p) |
| 2260 |
{ |
| 2261 |
f->ts.type = a->ts.type; |
| 2262 |
if (p != NULL) |
| 2263 |
f->ts.kind = gfc_kind_max (a,p); |
| 2264 |
else |
| 2265 |
f->ts.kind = a->ts.kind; |
| 2266 |
|
| 2267 |
if (p != NULL && a->ts.kind != p->ts.kind) |
| 2268 |
{ |
| 2269 |
if (a->ts.kind == gfc_kind_max (a,p)) |
| 2270 |
gfc_convert_type (p, &a->ts, 2); |
| 2271 |
else |
| 2272 |
gfc_convert_type (a, &p->ts, 2); |
| 2273 |
} |
| 2274 |
|
| 2275 |
f->value.function.name |
| 2276 |
= gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type), |
| 2277 |
gfc_type_abi_kind (&f->ts)); |
| 2278 |
} |
| 2279 |
|
| 2280 |
void |
| 2281 |
gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p) |
| 2282 |
{ |
| 2283 |
if (p->ts.kind != a->ts.kind) |
| 2284 |
gfc_convert_type (p, &a->ts, 2); |
| 2285 |
|
| 2286 |
f->ts = a->ts; |
| 2287 |
f->value.function.name |
| 2288 |
= gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type), |
| 2289 |
gfc_type_abi_kind (&a->ts)); |
| 2290 |
} |
| 2291 |
|
| 2292 |
void |
| 2293 |
gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 2294 |
{ |
| 2295 |
f->ts.type = BT_INTEGER; |
| 2296 |
f->ts.kind = (kind == NULL) |
| 2297 |
? gfc_default_integer_kind : mpz_get_si (kind->value.integer); |
| 2298 |
f->value.function.name |
| 2299 |
= gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind); |
| 2300 |
} |
| 2301 |
|
| 2302 |
|
| 2303 |
void |
| 2304 |
gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim) |
| 2305 |
{ |
| 2306 |
resolve_transformational ("norm2", f, array, dim, NULL); |
| 2307 |
} |
| 2308 |
|
| 2309 |
|
| 2310 |
void |
| 2311 |
gfc_resolve_not (gfc_expr *f, gfc_expr *i) |
| 2312 |
{ |
| 2313 |
f->ts = i->ts; |
| 2314 |
const char *name = i->ts.kind == BT_UNSIGNED ? "__not_u_%d" : "__not_%d"; |
| 2315 |
f->value.function.name = gfc_get_string (name, i->ts.kind); |
| 2316 |
} |
| 2317 |
|
| 2318 |
|
| 2319 |
void |
| 2320 |
gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
| 2321 |
{ |
| 2322 |
f->ts.type = i->ts.type; |
| 2323 |
f->ts.kind = gfc_kind_max (i, j); |
| 2324 |
|
| 2325 |
if (i->ts.kind != j->ts.kind) |
| 2326 |
{ |
| 2327 |
if (i->ts.kind == gfc_kind_max (i, j)) |
| 2328 |
gfc_convert_type (j, &i->ts, 2); |
| 2329 |
else |
| 2330 |
gfc_convert_type (i, &j->ts, 2); |
| 2331 |
} |
| 2332 |
|
| 2333 |
f->value.function.name |
| 2334 |
= gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), |
| 2335 |
gfc_type_abi_kind (&f->ts)); |
| 2336 |
} |
| 2337 |
|
| 2338 |
|
| 2339 |
void |
| 2340 |
gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask, |
| 2341 |
gfc_expr *vector ATTRIBUTE_UNUSED) |
| 2342 |
{ |
| 2343 |
if (array->ts.type == BT_CHARACTER && array->ref) |
| 2344 |
gfc_resolve_substring_charlen (array); |
| 2345 |
|
| 2346 |
f->ts = array->ts; |
| 2347 |
f->rank = 1; |
| 2348 |
|
| 2349 |
resolve_mask_arg (mask); |
| 2350 |
|
| 2351 |
if (mask->rank != 0) |
| 2352 |
{ |
| 2353 |
if (array->ts.type == BT_CHARACTER) |
| 2354 |
f->value.function.name |
| 2355 |
= array->ts.kind == 1 ? PREFIX ("pack_char") |
| 2356 |
: gfc_get_string |
| 2357 |
(PREFIX ("pack_char%d"), |
| 2358 |
array->ts.kind); |
| 2359 |
else |
| 2360 |
f->value.function.name = PREFIX ("pack"); |
| 2361 |
} |
| 2362 |
else |
| 2363 |
{ |
| 2364 |
if (array->ts.type == BT_CHARACTER) |
| 2365 |
f->value.function.name |
| 2366 |
= array->ts.kind == 1 ? PREFIX ("pack_s_char") |
| 2367 |
: gfc_get_string |
| 2368 |
(PREFIX ("pack_s_char%d"), |
| 2369 |
array->ts.kind); |
| 2370 |
else |
| 2371 |
f->value.function.name = PREFIX ("pack_s"); |
| 2372 |
} |
| 2373 |
} |
| 2374 |
|
| 2375 |
|
| 2376 |
void |
| 2377 |
gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim) |
| 2378 |
{ |
| 2379 |
resolve_transformational ("parity", f, array, dim, NULL); |
| 2380 |
} |
| 2381 |
|
| 2382 |
|
| 2383 |
void |
| 2384 |
gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
| 2385 |
gfc_expr *mask) |
| 2386 |
{ |
| 2387 |
resolve_transformational ("product", f, array, dim, mask, true); |
| 2388 |
} |
| 2389 |
|
| 2390 |
|
| 2391 |
void |
| 2392 |
gfc_resolve_rank (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED) |
| 2393 |
{ |
| 2394 |
f->ts.type = BT_INTEGER; |
| 2395 |
f->ts.kind = gfc_default_integer_kind; |
| 2396 |
f->value.function.name = gfc_get_string ("__rank"); |
| 2397 |
} |
| 2398 |
|
| 2399 |
|
| 2400 |
void |
| 2401 |
gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
| 2402 |
{ |
| 2403 |
f->ts.type = BT_REAL; |
| 2404 |
|
| 2405 |
if (kind != NULL) |
| 2406 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 2407 |
else |
| 2408 |
f->ts.kind = (a->ts.type == BT_COMPLEX) |
| 2409 |
? a->ts.kind : gfc_default_real_kind; |
| 2410 |
|
| 2411 |
f->value.function.name |
| 2412 |
= gfc_get_string ("__real_%d_%c%d", f->ts.kind, |
| 2413 |
gfc_type_letter (a->ts.type), |
| 2414 |
gfc_type_abi_kind (&a->ts)); |
| 2415 |
} |
| 2416 |
|
| 2417 |
|
| 2418 |
void |
| 2419 |
gfc_resolve_realpart (gfc_expr *f, gfc_expr *a) |
| 2420 |
{ |
| 2421 |
f->ts.type = BT_REAL; |
| 2422 |
f->ts.kind = a->ts.kind; |
| 2423 |
f->value.function.name |
| 2424 |
= gfc_get_string ("__real_%d_%c%d", f->ts.kind, |
| 2425 |
gfc_type_letter (a->ts.type), |
| 2426 |
gfc_type_abi_kind (&a->ts)); |
| 2427 |
} |
| 2428 |
|
| 2429 |
|
| 2430 |
/* Generate a wrapper subroutine for the operation so that the library REDUCE |
| 2431 |
function can use pointer arithmetic for OPERATION and not be dependent on |
| 2432 |
knowledge of its type. */ |
| 2433 |
static gfc_symtree * |
| 2434 |
generate_reduce_op_wrapper (gfc_expr *op) |
| 2435 |
{ |
| 2436 |
gfc_symbol *operation = op->symtree->n.sym; |
| 2437 |
gfc_symbol *wrapper, *a, *b, *c; |
| 2438 |
gfc_symtree *st; |
| 2439 |
char tname[2 * GFC_MAX_SYMBOL_LEN + 2]; |
| 2440 |
char *name; |
| 2441 |
gfc_namespace *ns; |
| 2442 |
gfc_expr *e; |
| 2443 |
|
| 2444 |
/* Find the top-level namespace. */ |
| 2445 |
for (ns = gfc_current_ns; ns; ns = ns->parent) |
| 2446 |
if (!ns->parent) |
| 2447 |
break; |
| 2448 |
|
| 2449 |
sprintf (tname, "%s_%s", operation->name, |
| 2450 |
ns->proc_name ? ns->proc_name->name : "noname"); |
| 2451 |
name = xasprintf ("__reduce_wrapper_%s", tname); |
| 2452 |
|
| 2453 |
gfc_find_sym_tree (name, ns, 0, &st); |
| 2454 |
|
| 2455 |
if (st && !strcmp (name, st->name)) |
| 2456 |
{ |
| 2457 |
free (name); |
| 2458 |
return st; |
| 2459 |
} |
| 2460 |
|
| 2461 |
/* Create the wrapper namespace and contain it in 'ns'. */ |
| 2462 |
gfc_namespace *sub_ns = gfc_get_namespace (ns, 0); |
| 2463 |
sub_ns->sibling = ns->contained; |
| 2464 |
ns->contained = sub_ns; |
| 2465 |
sub_ns->resolved = 1; |
| 2466 |
|
| 2467 |
/* Set up procedure symbol. */ |
| 2468 |
gfc_get_symbol (name, ns, &wrapper); |
| 2469 |
sub_ns->proc_name = wrapper; |
| 2470 |
wrapper->attr.flavor = FL_PROCEDURE; |
| 2471 |
wrapper->attr.subroutine = 1; |
| 2472 |
wrapper->attr.artificial = 1; |
| 2473 |
wrapper->attr.if_source = IFSRC_DECL; |
| 2474 |
if (ns->proc_name->attr.flavor == FL_MODULE) |
| 2475 |
wrapper->module = ns->proc_name->name; |
| 2476 |
gfc_set_sym_referenced (wrapper); |
| 2477 |
|
| 2478 |
/* Set up formal argument for the argument 'a'. */ |
| 2479 |
gfc_get_symbol ("a", sub_ns, &a); |
| 2480 |
a->ts = operation->ts; |
| 2481 |
a->attr.flavor = FL_VARIABLE; |
| 2482 |
a->attr.dummy = 1; |
| 2483 |
a->attr.artificial = 1; |
| 2484 |
a->attr.intent = INTENT_IN; |
| 2485 |
wrapper->formal = gfc_get_formal_arglist (); |
| 2486 |
wrapper->formal->sym = a; |
| 2487 |
gfc_set_sym_referenced (a); |
| 2488 |
|
| 2489 |
/* Set up formal argument for the argument 'b'. This is optional. When |
| 2490 |
present, the wrapped function is called, otherwise 'a' is assigned |
| 2491 |
to 'c'. This way, deep copies are effected in the library. */ |
| 2492 |
gfc_get_symbol ("b", sub_ns, &b); |
| 2493 |
b->ts = operation->ts; |
| 2494 |
b->attr.flavor = FL_VARIABLE; |
| 2495 |
b->attr.dummy = 1; |
| 2496 |
b->attr.optional= 1; |
| 2497 |
b->attr.artificial = 1; |
| 2498 |
b->attr.intent = INTENT_IN; |
| 2499 |
wrapper->formal->next = gfc_get_formal_arglist (); |
| 2500 |
wrapper->formal->next->sym = b; |
| 2501 |
gfc_set_sym_referenced (b); |
| 2502 |
|
| 2503 |
/* Set up formal argument for the argument 'c'. */ |
| 2504 |
gfc_get_symbol ("c", sub_ns, &c); |
| 2505 |
c->ts = operation->ts; |
| 2506 |
c->attr.flavor = FL_VARIABLE; |
| 2507 |
c->attr.dummy = 1; |
| 2508 |
c->attr.artificial = 1; |
| 2509 |
c->attr.intent = INTENT_INOUT; |
| 2510 |
wrapper->formal->next->next = gfc_get_formal_arglist (); |
| 2511 |
wrapper->formal->next->next->sym = c; |
| 2512 |
gfc_set_sym_referenced (c); |
| 2513 |
|
| 2514 |
/* The only code is: |
| 2515 |
if (present (b)) |
| 2516 |
c = operation (a, b) |
| 2517 |
else |
| 2518 |
c = a |
| 2519 |
endif |
| 2520 |
A call with 'b' missing provides a convenient way for the library to do |
| 2521 |
an intrinsic assignment instead of a call to memcpy and, where allocatable |
| 2522 |
components are present, a deep copy. |
| 2523 |
|
| 2524 |
Code for if (present (b)) */ |
| 2525 |
sub_ns->code = gfc_get_code (EXEC_IF); |
| 2526 |
gfc_code *if_block = sub_ns->code; |
| 2527 |
if_block->block = gfc_get_code (EXEC_IF); |
| 2528 |
if_block->block->expr1 = gfc_get_expr (); |
| 2529 |
e = if_block->block->expr1; |
| 2530 |
e->expr_type = EXPR_FUNCTION; |
| 2531 |
e->where = gfc_current_locus; |
| 2532 |
gfc_get_sym_tree ("present", sub_ns, &e->symtree, false); |
| 2533 |
e->symtree->n.sym->attr.flavor = FL_PROCEDURE; |
| 2534 |
e->symtree->n.sym->attr.intrinsic = 1; |
| 2535 |
e->ts.type = BT_LOGICAL; |
| 2536 |
e->ts.kind = gfc_default_logical_kind; |
| 2537 |
e->value.function.isym = gfc_intrinsic_function_by_id (GFC_ISYM_PRESENT); |
| 2538 |
e->value.function.actual = gfc_get_actual_arglist (); |
| 2539 |
e->value.function.actual->expr = gfc_lval_expr_from_sym (b); |
| 2540 |
|
| 2541 |
/* Code for c = operation (a, b) */ |
| 2542 |
if_block->block->next = gfc_get_code (EXEC_ASSIGN); |
| 2543 |
if_block->block->next->expr1 = gfc_lval_expr_from_sym (c); |
| 2544 |
if_block->block->next->expr2 = gfc_get_expr (); |
| 2545 |
e = if_block->block->next->expr2; |
| 2546 |
e->expr_type = EXPR_FUNCTION; |
| 2547 |
e->where = gfc_current_locus; |
| 2548 |
if_block->block->next->expr2->ts = operation->ts; |
| 2549 |
gfc_get_sym_tree (operation->name, ns, &e->symtree, false); |
| 2550 |
e->value.function.esym = if_block->block->next->expr2->symtree->n.sym; |
| 2551 |
e->value.function.actual = gfc_get_actual_arglist (); |
| 2552 |
e->value.function.actual->expr = gfc_lval_expr_from_sym (a); |
| 2553 |
e->value.function.actual->next = gfc_get_actual_arglist (); |
| 2554 |
e->value.function.actual->next->expr = gfc_lval_expr_from_sym (b); |
| 2555 |
|
| 2556 |
if_block->block->block = gfc_get_code (EXEC_IF); |
| 2557 |
if_block->block->block->next = gfc_get_code (EXEC_ASSIGN); |
| 2558 |
if_block->block->block->next->expr1 = gfc_lval_expr_from_sym (c); |
| 2559 |
if_block->block->block->next->expr2 = gfc_lval_expr_from_sym (a); |
| 2560 |
|
| 2561 |
/* It is unexpected to have some symbols added at resolution. Commit the |
| 2562 |
changes in order to keep a clean state. */ |
| 2563 |
gfc_commit_symbol (if_block->block->expr1->symtree->n.sym); |
| 2564 |
gfc_commit_symbol (wrapper); |
| 2565 |
gfc_commit_symbol (a); |
| 2566 |
gfc_commit_symbol (b); |
| 2567 |
gfc_commit_symbol (c); |
| 2568 |
|
| 2569 |
gfc_find_sym_tree (name, ns, 0, &st); |
| 2570 |
free (name); |
| 2571 |
|
| 2572 |
return st; |
| 2573 |
} |
| 2574 |
|
| 2575 |
void |
| 2576 |
gfc_resolve_reduce (gfc_expr *f, gfc_expr *array, |
| 2577 |
gfc_expr *operation, |
| 2578 |
gfc_expr *dim, |
| 2579 |
gfc_expr *mask, |
| 2580 |
gfc_expr *identity ATTRIBUTE_UNUSED, |
| 2581 |
gfc_expr *ordered ATTRIBUTE_UNUSED) |
| 2582 |
{ |
| 2583 |
gfc_symtree *wrapper_symtree; |
| 2584 |
gfc_typespec ts; |
| 2585 |
|
| 2586 |
gfc_resolve_expr (array); |
| 2587 |
if (array->ts.type == BT_CHARACTER && array->ref) |
| 2588 |
gfc_resolve_substring_charlen (array); |
| 2589 |
|
| 2590 |
f->ts = array->ts; |
| 2591 |
|
| 2592 |
/* Replace 'operation' with its subroutine wrapper so that pointers may be |
| 2593 |
used throughout the library function. */ |
| 2594 |
wrapper_symtree = generate_reduce_op_wrapper (operation); |
| 2595 |
gcc_assert (wrapper_symtree && wrapper_symtree->n.sym); |
| 2596 |
operation->symtree = wrapper_symtree; |
| 2597 |
operation->ts = operation->symtree->n.sym->ts; |
| 2598 |
|
| 2599 |
/* The scalar library function converts the scalar result to a dimension |
| 2600 |
zero descriptor and then returns the data after the call. */ |
| 2601 |
if (f->ts.type == BT_CHARACTER) |
| 2602 |
{ |
| 2603 |
if (dim && array->rank > 1) |
| 2604 |
{ |
| 2605 |
f->value.function.name = gfc_get_string (PREFIX ("reduce_c")); |
| 2606 |
f->rank = array->rank - 1; |
| 2607 |
} |
| 2608 |
else |
| 2609 |
{ |
| 2610 |
f->value.function.name = gfc_get_string (PREFIX ("reduce_scalar_c")); |
| 2611 |
f->rank = 0; |
| 2612 |
} |
| 2613 |
} |
| 2614 |
else |
| 2615 |
{ |
| 2616 |
if (dim && array->rank > 1) |
| 2617 |
{ |
| 2618 |
f->value.function.name = gfc_get_string (PREFIX ("reduce")); |
| 2619 |
f->rank = array->rank - 1; |
| 2620 |
} |
| 2621 |
else |
| 2622 |
{ |
| 2623 |
f->value.function.name = gfc_get_string (PREFIX ("reduce_scalar")); |
| 2624 |
f->rank = 0; |
| 2625 |
} |
| 2626 |
} |
| 2627 |
|
| 2628 |
if (dim) |
| 2629 |
{ |
| 2630 |
ts = dim->ts; |
| 2631 |
ts.kind = 4; |
| 2632 |
gfc_convert_type_warn (dim, &ts, 1, 0); |
| 2633 |
} |
| 2634 |
|
| 2635 |
if (mask) |
| 2636 |
{ |
| 2637 |
ts = mask->ts; |
| 2638 |
ts.kind = 4; |
| 2639 |
gfc_convert_type_warn (mask, &ts, 1, 0); |
| 2640 |
} |
| 2641 |
} |
| 2642 |
|
| 2643 |
|
| 2644 |
void |
| 2645 |
gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED, |
| 2646 |
gfc_expr *p2 ATTRIBUTE_UNUSED) |
| 2647 |
{ |
| 2648 |
f->ts.type = BT_INTEGER; |
| 2649 |
f->ts.kind = gfc_default_integer_kind; |
| 2650 |
f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind); |
| 2651 |
} |
| 2652 |
|
| 2653 |
|
| 2654 |
void |
| 2655 |
gfc_resolve_repeat (gfc_expr *f, gfc_expr *string, |
| 2656 |
gfc_expr *ncopies) |
| 2657 |
{ |
| 2658 |
gfc_expr *tmp; |
| 2659 |
f->ts.type = BT_CHARACTER; |
| 2660 |
f->ts.kind = string->ts.kind; |
| 2661 |
f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind); |
| 2662 |
|
| 2663 |
/* If possible, generate a character length. */ |
| 2664 |
if (f->ts.u.cl == NULL) |
| 2665 |
f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); |
| 2666 |
|
| 2667 |
tmp = NULL; |
| 2668 |
if (string->expr_type == EXPR_CONSTANT) |
| 2669 |
{ |
| 2670 |
tmp = gfc_get_int_expr (gfc_charlen_int_kind, NULL, |
| 2671 |
string->value.character.length); |
| 2672 |
} |
| 2673 |
else if (string->ts.u.cl && string->ts.u.cl->length) |
| 2674 |
{ |
| 2675 |
tmp = gfc_copy_expr (string->ts.u.cl->length); |
| 2676 |
} |
| 2677 |
|
| 2678 |
if (tmp) |
| 2679 |
{ |
| 2680 |
/* Force-convert to gfc_charlen_int_kind before gfc_multiply. */ |
| 2681 |
gfc_expr *e = gfc_copy_expr (ncopies); |
| 2682 |
gfc_typespec ts = tmp->ts; |
| 2683 |
ts.kind = gfc_charlen_int_kind; |
| 2684 |
gfc_convert_type_warn (e, &ts, 2, 0); |
| 2685 |
gfc_convert_type_warn (tmp, &ts, 2, 0); |
| 2686 |
f->ts.u.cl->length = gfc_multiply (tmp, e); |
| 2687 |
} |
| 2688 |
} |
| 2689 |
|
| 2690 |
|
| 2691 |
void |
| 2692 |
gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape, |
| 2693 |
gfc_expr *pad ATTRIBUTE_UNUSED, |
| 2694 |
gfc_expr *order ATTRIBUTE_UNUSED) |
| 2695 |
{ |
| 2696 |
mpz_t rank; |
| 2697 |
int kind; |
| 2698 |
int i; |
| 2699 |
|
| 2700 |
if (source->ts.type == BT_CHARACTER && source->ref) |
| 2701 |
gfc_resolve_substring_charlen (source); |
| 2702 |
|
| 2703 |
f->ts = source->ts; |
| 2704 |
|
| 2705 |
gfc_array_size (shape, &rank); |
| 2706 |
f->rank = mpz_get_si (rank); |
| 2707 |
mpz_clear (rank); |
| 2708 |
switch (source->ts.type) |
| 2709 |
{ |
| 2710 |
case BT_COMPLEX: |
| 2711 |
case BT_REAL: |
| 2712 |
case BT_INTEGER: |
| 2713 |
case BT_LOGICAL: |
| 2714 |
case BT_CHARACTER: |
| 2715 |
kind = source->ts.kind; |
| 2716 |
break; |
| 2717 |
|
| 2718 |
default: |
| 2719 |
kind = 0; |
| 2720 |
break; |
| 2721 |
} |
| 2722 |
|
| 2723 |
switch (kind) |
| 2724 |
{ |
| 2725 |
case 4: |
| 2726 |
case 8: |
| 2727 |
case 10: |
| 2728 |
case 16: |
| 2729 |
if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL) |
| 2730 |
f->value.function.name |
| 2731 |
= gfc_get_string (PREFIX ("reshape_%c%d"), |
| 2732 |
gfc_type_letter (source->ts.type), |
| 2733 |
gfc_type_abi_kind (&source->ts)); |
| 2734 |
else if (source->ts.type == BT_CHARACTER) |
| 2735 |
f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"), |
| 2736 |
kind); |
| 2737 |
else |
| 2738 |
f->value.function.name |
| 2739 |
= gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind); |
| 2740 |
break; |
| 2741 |
|
| 2742 |
default: |
| 2743 |
f->value.function.name = (source->ts.type == BT_CHARACTER |
| 2744 |
? PREFIX ("reshape_char") : PREFIX ("reshape")); |
| 2745 |
break; |
| 2746 |
} |
| 2747 |
|
| 2748 |
if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_array_expr (shape)) |
| 2749 |
{ |
| 2750 |
gfc_constructor *c; |
| 2751 |
f->shape = gfc_get_shape (f->rank); |
| 2752 |
c = gfc_constructor_first (shape->value.constructor); |
| 2753 |
for (i = 0; i < f->rank; i++) |
| 2754 |
{ |
| 2755 |
mpz_init_set (f->shape[i], c->expr->value.integer); |
| 2756 |
c = gfc_constructor_next (c); |
| 2757 |
} |
| 2758 |
} |
| 2759 |
|
| 2760 |
/* Force-convert both SHAPE and ORDER to index_kind so that we don't need |
| 2761 |
so many runtime variations. */ |
| 2762 |
if (shape->ts.kind != gfc_index_integer_kind) |
| 2763 |
{ |
| 2764 |
gfc_typespec ts = shape->ts; |
| 2765 |
ts.kind = gfc_index_integer_kind; |
| 2766 |
gfc_convert_type_warn (shape, &ts, 2, 0); |
| 2767 |
} |
| 2768 |
if (order && order->ts.kind != gfc_index_integer_kind) |
| 2769 |
gfc_convert_type_warn (order, &shape->ts, 2, 0); |
| 2770 |
} |
| 2771 |
|
| 2772 |
|
| 2773 |
void |
| 2774 |
gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x) |
| 2775 |
{ |
| 2776 |
f->ts = x->ts; |
| 2777 |
f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind); |
| 2778 |
} |
| 2779 |
|
| 2780 |
void |
| 2781 |
gfc_resolve_fe_runtime_error (gfc_code *c) |
| 2782 |
{ |
| 2783 |
const char *name; |
| 2784 |
gfc_actual_arglist *a; |
| 2785 |
|
| 2786 |
name = gfc_get_string (PREFIX ("runtime_error")); |
| 2787 |
|
| 2788 |
for (a = c->ext.actual->next; a; a = a->next) |
| 2789 |
a->name = "%VAL"; |
| 2790 |
|
| 2791 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 2792 |
/* We set the backend_decl here because runtime_error is a |
| 2793 |
variadic function and we would use the wrong calling |
| 2794 |
convention otherwise. */ |
| 2795 |
c->resolved_sym->backend_decl = gfor_fndecl_runtime_error; |
| 2796 |
} |
| 2797 |
|
| 2798 |
void |
| 2799 |
gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED) |
| 2800 |
{ |
| 2801 |
f->ts = x->ts; |
| 2802 |
f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind); |
| 2803 |
} |
| 2804 |
|
| 2805 |
|
| 2806 |
void |
| 2807 |
gfc_resolve_scan (gfc_expr *f, gfc_expr *string, |
| 2808 |
gfc_expr *set ATTRIBUTE_UNUSED, |
| 2809 |
gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind) |
| 2810 |
{ |
| 2811 |
f->ts.type = BT_INTEGER; |
| 2812 |
if (kind) |
| 2813 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 2814 |
else |
| 2815 |
f->ts.kind = gfc_default_integer_kind; |
| 2816 |
f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind); |
| 2817 |
} |
| 2818 |
|
| 2819 |
|
| 2820 |
void |
| 2821 |
gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0) |
| 2822 |
{ |
| 2823 |
t1->ts = t0->ts; |
| 2824 |
t1->value.function.name = gfc_get_string (PREFIX ("secnds")); |
| 2825 |
} |
| 2826 |
|
| 2827 |
|
| 2828 |
void |
| 2829 |
gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, |
| 2830 |
gfc_expr *i ATTRIBUTE_UNUSED) |
| 2831 |
{ |
| 2832 |
f->ts = x->ts; |
| 2833 |
f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind); |
| 2834 |
} |
| 2835 |
|
| 2836 |
|
| 2837 |
void |
| 2838 |
gfc_resolve_shape (gfc_expr *f, gfc_expr *array, gfc_expr *kind) |
| 2839 |
{ |
| 2840 |
f->ts.type = BT_INTEGER; |
| 2841 |
|
| 2842 |
if (kind) |
| 2843 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 2844 |
else |
| 2845 |
f->ts.kind = gfc_default_integer_kind; |
| 2846 |
|
| 2847 |
f->rank = 1; |
| 2848 |
if (array->rank != -1) |
| 2849 |
{ |
| 2850 |
f->shape = gfc_get_shape (1); |
| 2851 |
mpz_init_set_ui (f->shape[0], array->rank); |
| 2852 |
} |
| 2853 |
|
| 2854 |
f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind); |
| 2855 |
} |
| 2856 |
|
| 2857 |
|
| 2858 |
void |
| 2859 |
gfc_resolve_shift (gfc_expr *f, gfc_expr *i, gfc_expr *shift ATTRIBUTE_UNUSED) |
| 2860 |
{ |
| 2861 |
f->ts = i->ts; |
| 2862 |
if (f->value.function.isym->id == GFC_ISYM_SHIFTA) |
| 2863 |
f->value.function.name = gfc_get_string ("shifta_i%d", f->ts.kind); |
| 2864 |
else if (f->value.function.isym->id == GFC_ISYM_SHIFTL) |
| 2865 |
f->value.function.name = gfc_get_string ("shiftl_i%d", f->ts.kind); |
| 2866 |
else if (f->value.function.isym->id == GFC_ISYM_SHIFTR) |
| 2867 |
f->value.function.name = gfc_get_string ("shiftr_i%d", f->ts.kind); |
| 2868 |
else |
| 2869 |
gcc_unreachable (); |
| 2870 |
} |
| 2871 |
|
| 2872 |
|
| 2873 |
void |
| 2874 |
gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED) |
| 2875 |
{ |
| 2876 |
f->ts = a->ts; |
| 2877 |
f->value.function.name |
| 2878 |
= gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), |
| 2879 |
gfc_type_abi_kind (&a->ts)); |
| 2880 |
} |
| 2881 |
|
| 2882 |
|
| 2883 |
void |
| 2884 |
gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler) |
| 2885 |
{ |
| 2886 |
f->ts.type = BT_INTEGER; |
| 2887 |
f->ts.kind = gfc_c_int_kind; |
| 2888 |
|
| 2889 |
/* handler can be either BT_INTEGER or BT_PROCEDURE */ |
| 2890 |
if (handler->ts.type == BT_INTEGER) |
| 2891 |
{ |
| 2892 |
if (handler->ts.kind != gfc_c_int_kind) |
| 2893 |
gfc_convert_type (handler, &f->ts, 2); |
| 2894 |
f->value.function.name = gfc_get_string (PREFIX ("signal_func_int")); |
| 2895 |
} |
| 2896 |
else |
| 2897 |
f->value.function.name = gfc_get_string (PREFIX ("signal_func")); |
| 2898 |
|
| 2899 |
if (number->ts.kind != gfc_c_int_kind) |
| 2900 |
gfc_convert_type (number, &f->ts, 2); |
| 2901 |
} |
| 2902 |
|
| 2903 |
|
| 2904 |
void |
| 2905 |
gfc_resolve_sin (gfc_expr *f, gfc_expr *x) |
| 2906 |
{ |
| 2907 |
f->ts = x->ts; |
| 2908 |
f->value.function.name |
| 2909 |
= gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), |
| 2910 |
gfc_type_abi_kind (&x->ts)); |
| 2911 |
} |
| 2912 |
|
| 2913 |
|
| 2914 |
void |
| 2915 |
gfc_resolve_sinh (gfc_expr *f, gfc_expr *x) |
| 2916 |
{ |
| 2917 |
f->ts = x->ts; |
| 2918 |
f->value.function.name |
| 2919 |
= gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), |
| 2920 |
gfc_type_abi_kind (&x->ts)); |
| 2921 |
} |
| 2922 |
|
| 2923 |
|
| 2924 |
void |
| 2925 |
gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED, |
| 2926 |
gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind) |
| 2927 |
{ |
| 2928 |
f->ts.type = BT_INTEGER; |
| 2929 |
if (kind) |
| 2930 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 2931 |
else |
| 2932 |
f->ts.kind = gfc_default_integer_kind; |
| 2933 |
} |
| 2934 |
|
| 2935 |
|
| 2936 |
void |
| 2937 |
gfc_resolve_stride (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED, |
| 2938 |
gfc_expr *dim ATTRIBUTE_UNUSED) |
| 2939 |
{ |
| 2940 |
f->ts.type = BT_INTEGER; |
| 2941 |
f->ts.kind = gfc_index_integer_kind; |
| 2942 |
} |
| 2943 |
|
| 2944 |
|
| 2945 |
void |
| 2946 |
gfc_resolve_spacing (gfc_expr *f, gfc_expr *x) |
| 2947 |
{ |
| 2948 |
f->ts = x->ts; |
| 2949 |
f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind); |
| 2950 |
} |
| 2951 |
|
| 2952 |
|
| 2953 |
void |
| 2954 |
gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim, |
| 2955 |
gfc_expr *ncopies) |
| 2956 |
{ |
| 2957 |
if (source->ts.type == BT_CHARACTER && source->ref) |
| 2958 |
gfc_resolve_substring_charlen (source); |
| 2959 |
|
| 2960 |
if (source->ts.type == BT_CHARACTER) |
| 2961 |
{ |
| 2962 |
check_charlen_present (source); |
| 2963 |
f->value.function.isym = copy_intrinsic_sym (f->value.function.isym); |
| 2964 |
f->value.function.isym->formal->ts = source->ts; |
| 2965 |
} |
| 2966 |
|
| 2967 |
f->ts = source->ts; |
| 2968 |
f->rank = source->rank + 1; |
| 2969 |
if (source->rank == 0) |
| 2970 |
{ |
| 2971 |
if (source->ts.type == BT_CHARACTER) |
| 2972 |
f->value.function.name |
| 2973 |
= source->ts.kind == 1 ? PREFIX ("spread_char_scalar") |
| 2974 |
: gfc_get_string |
| 2975 |
(PREFIX ("spread_char%d_scalar"), |
| 2976 |
source->ts.kind); |
| 2977 |
else |
| 2978 |
f->value.function.name = PREFIX ("spread_scalar"); |
| 2979 |
} |
| 2980 |
else |
| 2981 |
{ |
| 2982 |
if (source->ts.type == BT_CHARACTER) |
| 2983 |
f->value.function.name |
| 2984 |
= source->ts.kind == 1 ? PREFIX ("spread_char") |
| 2985 |
: gfc_get_string |
| 2986 |
(PREFIX ("spread_char%d"), |
| 2987 |
source->ts.kind); |
| 2988 |
else |
| 2989 |
f->value.function.name = PREFIX ("spread"); |
| 2990 |
} |
| 2991 |
|
| 2992 |
if (dim && gfc_is_constant_expr (dim) |
| 2993 |
&& ncopies && gfc_is_constant_expr (ncopies) && source->shape[0]) |
| 2994 |
{ |
| 2995 |
int i, idim; |
| 2996 |
idim = mpz_get_ui (dim->value.integer); |
| 2997 |
f->shape = gfc_get_shape (f->rank); |
| 2998 |
for (i = 0; i < (idim - 1); i++) |
| 2999 |
mpz_init_set (f->shape[i], source->shape[i]); |
| 3000 |
|
| 3001 |
mpz_init_set (f->shape[idim - 1], ncopies->value.integer); |
| 3002 |
|
| 3003 |
for (i = idim; i < f->rank ; i++) |
| 3004 |
mpz_init_set (f->shape[i], source->shape[i-1]); |
| 3005 |
} |
| 3006 |
|
| 3007 |
|
| 3008 |
gfc_resolve_dim_arg (dim); |
| 3009 |
gfc_resolve_index (ncopies, 1); |
| 3010 |
} |
| 3011 |
|
| 3012 |
|
| 3013 |
void |
| 3014 |
gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x) |
| 3015 |
{ |
| 3016 |
f->ts = x->ts; |
| 3017 |
f->value.function.name |
| 3018 |
= gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), |
| 3019 |
gfc_type_abi_kind (&x->ts)); |
| 3020 |
} |
| 3021 |
|
| 3022 |
|
| 3023 |
/* Resolve the g77 compatibility function STAT AND FSTAT. */ |
| 3024 |
|
| 3025 |
void |
| 3026 |
gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED, |
| 3027 |
gfc_expr *a ATTRIBUTE_UNUSED) |
| 3028 |
{ |
| 3029 |
f->ts.type = BT_INTEGER; |
| 3030 |
f->ts.kind = gfc_default_integer_kind; |
| 3031 |
f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind); |
| 3032 |
} |
| 3033 |
|
| 3034 |
|
| 3035 |
void |
| 3036 |
gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED, |
| 3037 |
gfc_expr *a ATTRIBUTE_UNUSED) |
| 3038 |
{ |
| 3039 |
f->ts.type = BT_INTEGER; |
| 3040 |
f->ts.kind = gfc_default_integer_kind; |
| 3041 |
f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind); |
| 3042 |
} |
| 3043 |
|
| 3044 |
|
| 3045 |
void |
| 3046 |
gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED) |
| 3047 |
{ |
| 3048 |
f->ts.type = BT_INTEGER; |
| 3049 |
f->ts.kind = gfc_default_integer_kind; |
| 3050 |
if (n->ts.kind != f->ts.kind) |
| 3051 |
gfc_convert_type (n, &f->ts, 2); |
| 3052 |
|
| 3053 |
f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind); |
| 3054 |
} |
| 3055 |
|
| 3056 |
|
| 3057 |
void |
| 3058 |
gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED) |
| 3059 |
{ |
| 3060 |
gfc_typespec ts; |
| 3061 |
gfc_clear_ts (&ts); |
| 3062 |
|
| 3063 |
f->ts.type = BT_INTEGER; |
| 3064 |
f->ts.kind = gfc_c_int_kind; |
| 3065 |
if (u->ts.kind != gfc_c_int_kind) |
| 3066 |
{ |
| 3067 |
ts.type = BT_INTEGER; |
| 3068 |
ts.kind = gfc_c_int_kind; |
| 3069 |
ts.u.derived = NULL; |
| 3070 |
ts.u.cl = NULL; |
| 3071 |
gfc_convert_type (u, &ts, 2); |
| 3072 |
} |
| 3073 |
|
| 3074 |
f->value.function.name = gfc_get_string (PREFIX ("fgetc")); |
| 3075 |
} |
| 3076 |
|
| 3077 |
|
| 3078 |
void |
| 3079 |
gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED) |
| 3080 |
{ |
| 3081 |
f->ts.type = BT_INTEGER; |
| 3082 |
f->ts.kind = gfc_c_int_kind; |
| 3083 |
f->value.function.name = gfc_get_string (PREFIX ("fget")); |
| 3084 |
} |
| 3085 |
|
| 3086 |
|
| 3087 |
void |
| 3088 |
gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED) |
| 3089 |
{ |
| 3090 |
gfc_typespec ts; |
| 3091 |
gfc_clear_ts (&ts); |
| 3092 |
|
| 3093 |
f->ts.type = BT_INTEGER; |
| 3094 |
f->ts.kind = gfc_c_int_kind; |
| 3095 |
if (u->ts.kind != gfc_c_int_kind) |
| 3096 |
{ |
| 3097 |
ts.type = BT_INTEGER; |
| 3098 |
ts.kind = gfc_c_int_kind; |
| 3099 |
ts.u.derived = NULL; |
| 3100 |
ts.u.cl = NULL; |
| 3101 |
gfc_convert_type (u, &ts, 2); |
| 3102 |
} |
| 3103 |
|
| 3104 |
f->value.function.name = gfc_get_string (PREFIX ("fputc")); |
| 3105 |
} |
| 3106 |
|
| 3107 |
|
| 3108 |
void |
| 3109 |
gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED) |
| 3110 |
{ |
| 3111 |
f->ts.type = BT_INTEGER; |
| 3112 |
f->ts.kind = gfc_c_int_kind; |
| 3113 |
f->value.function.name = gfc_get_string (PREFIX ("fput")); |
| 3114 |
} |
| 3115 |
|
| 3116 |
|
| 3117 |
void |
| 3118 |
gfc_resolve_ftell (gfc_expr *f, gfc_expr *u) |
| 3119 |
{ |
| 3120 |
gfc_typespec ts; |
| 3121 |
gfc_clear_ts (&ts); |
| 3122 |
|
| 3123 |
f->ts.type = BT_INTEGER; |
| 3124 |
f->ts.kind = gfc_intio_kind; |
| 3125 |
if (u->ts.kind != gfc_c_int_kind) |
| 3126 |
{ |
| 3127 |
ts.type = BT_INTEGER; |
| 3128 |
ts.kind = gfc_c_int_kind; |
| 3129 |
ts.u.derived = NULL; |
| 3130 |
ts.u.cl = NULL; |
| 3131 |
gfc_convert_type (u, &ts, 2); |
| 3132 |
} |
| 3133 |
|
| 3134 |
f->value.function.name = gfc_get_string (PREFIX ("ftell")); |
| 3135 |
} |
| 3136 |
|
| 3137 |
|
| 3138 |
void |
| 3139 |
gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED, |
| 3140 |
gfc_expr *kind) |
| 3141 |
{ |
| 3142 |
f->ts.type = BT_INTEGER; |
| 3143 |
if (kind) |
| 3144 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 3145 |
else |
| 3146 |
f->ts.kind = gfc_default_integer_kind; |
| 3147 |
} |
| 3148 |
|
| 3149 |
|
| 3150 |
void |
| 3151 |
gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask) |
| 3152 |
{ |
| 3153 |
resolve_transformational ("sum", f, array, dim, mask, true); |
| 3154 |
} |
| 3155 |
|
| 3156 |
|
| 3157 |
void |
| 3158 |
gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED, |
| 3159 |
gfc_expr *p2 ATTRIBUTE_UNUSED) |
| 3160 |
{ |
| 3161 |
f->ts.type = BT_INTEGER; |
| 3162 |
f->ts.kind = gfc_default_integer_kind; |
| 3163 |
f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind); |
| 3164 |
} |
| 3165 |
|
| 3166 |
|
| 3167 |
/* Resolve the g77 compatibility function SYSTEM. */ |
| 3168 |
|
| 3169 |
void |
| 3170 |
gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED) |
| 3171 |
{ |
| 3172 |
f->ts.type = BT_INTEGER; |
| 3173 |
f->ts.kind = 4; |
| 3174 |
f->value.function.name = gfc_get_string (PREFIX ("system")); |
| 3175 |
} |
| 3176 |
|
| 3177 |
|
| 3178 |
void |
| 3179 |
gfc_resolve_tan (gfc_expr *f, gfc_expr *x) |
| 3180 |
{ |
| 3181 |
f->ts = x->ts; |
| 3182 |
f->value.function.name |
| 3183 |
= gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), |
| 3184 |
gfc_type_abi_kind (&x->ts)); |
| 3185 |
} |
| 3186 |
|
| 3187 |
|
| 3188 |
void |
| 3189 |
gfc_resolve_tanh (gfc_expr *f, gfc_expr *x) |
| 3190 |
{ |
| 3191 |
f->ts = x->ts; |
| 3192 |
f->value.function.name |
| 3193 |
= gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), |
| 3194 |
gfc_type_abi_kind (&x->ts)); |
| 3195 |
} |
| 3196 |
|
| 3197 |
|
| 3198 |
/* Resolve failed_images (team, kind). */ |
| 3199 |
|
| 3200 |
void |
| 3201 |
gfc_resolve_failed_images (gfc_expr *f, gfc_expr *team ATTRIBUTE_UNUSED, |
| 3202 |
gfc_expr *kind) |
| 3203 |
{ |
| 3204 |
static char failed_images[] = "_gfortran_caf_failed_images"; |
| 3205 |
f->rank = 1; |
| 3206 |
f->ts.type = BT_INTEGER; |
| 3207 |
if (kind == NULL) |
| 3208 |
f->ts.kind = gfc_default_integer_kind; |
| 3209 |
else |
| 3210 |
gfc_extract_int (kind, &f->ts.kind); |
| 3211 |
f->value.function.name = failed_images; |
| 3212 |
} |
| 3213 |
|
| 3214 |
|
| 3215 |
/* Resolve image_status (image, team). */ |
| 3216 |
|
| 3217 |
void |
| 3218 |
gfc_resolve_image_status (gfc_expr *f, gfc_expr *image ATTRIBUTE_UNUSED, |
| 3219 |
gfc_expr *team ATTRIBUTE_UNUSED) |
| 3220 |
{ |
| 3221 |
static char image_status[] = "_gfortran_caf_image_status"; |
| 3222 |
f->ts.type = BT_INTEGER; |
| 3223 |
f->ts.kind = gfc_default_integer_kind; |
| 3224 |
f->value.function.name = image_status; |
| 3225 |
} |
| 3226 |
|
| 3227 |
|
| 3228 |
/* Resolve get_team (). */ |
| 3229 |
|
| 3230 |
void |
| 3231 |
gfc_resolve_get_team (gfc_expr *f, gfc_expr *level ATTRIBUTE_UNUSED) |
| 3232 |
{ |
| 3233 |
static char get_team[] = "_gfortran_caf_get_team"; |
| 3234 |
f->rank = 0; |
| 3235 |
f->ts.type = BT_INTEGER; |
| 3236 |
f->ts.kind = gfc_default_integer_kind; |
| 3237 |
f->value.function.name = get_team; |
| 3238 |
} |
| 3239 |
|
| 3240 |
|
| 3241 |
/* Resolve image_index (...). */ |
| 3242 |
|
| 3243 |
void |
| 3244 |
gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED, |
| 3245 |
gfc_expr *sub ATTRIBUTE_UNUSED) |
| 3246 |
{ |
| 3247 |
static char image_index[] = "__image_index"; |
| 3248 |
f->ts.type = BT_INTEGER; |
| 3249 |
f->ts.kind = gfc_default_integer_kind; |
| 3250 |
f->value.function.name = image_index; |
| 3251 |
} |
| 3252 |
|
| 3253 |
|
| 3254 |
/* Resolve stopped_images (team, kind). */ |
| 3255 |
|
| 3256 |
void |
| 3257 |
gfc_resolve_stopped_images (gfc_expr *f, gfc_expr *team ATTRIBUTE_UNUSED, |
| 3258 |
gfc_expr *kind) |
| 3259 |
{ |
| 3260 |
static char stopped_images[] = "_gfortran_caf_stopped_images"; |
| 3261 |
f->rank = 1; |
| 3262 |
f->ts.type = BT_INTEGER; |
| 3263 |
if (kind == NULL) |
| 3264 |
f->ts.kind = gfc_default_integer_kind; |
| 3265 |
else |
| 3266 |
gfc_extract_int (kind, &f->ts.kind); |
| 3267 |
f->value.function.name = stopped_images; |
| 3268 |
} |
| 3269 |
|
| 3270 |
|
| 3271 |
/* Resolve team_number (team). */ |
| 3272 |
|
| 3273 |
void |
| 3274 |
gfc_resolve_team_number (gfc_expr *f, gfc_expr *team ATTRIBUTE_UNUSED) |
| 3275 |
{ |
| 3276 |
static char team_number[] = "_gfortran_caf_team_number"; |
| 3277 |
f->rank = 0; |
| 3278 |
f->ts.type = BT_INTEGER; |
| 3279 |
f->ts.kind = gfc_default_integer_kind; |
| 3280 |
f->value.function.name = team_number; |
| 3281 |
} |
| 3282 |
|
| 3283 |
|
| 3284 |
void |
| 3285 |
gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
| 3286 |
gfc_expr *distance ATTRIBUTE_UNUSED) |
| 3287 |
{ |
| 3288 |
static char this_image[] = "__this_image"; |
| 3289 |
if (array && gfc_is_coarray (array)) |
| 3290 |
resolve_bound (f, array, dim, NULL, "__this_image", true); |
| 3291 |
else |
| 3292 |
{ |
| 3293 |
f->ts.type = BT_INTEGER; |
| 3294 |
f->ts.kind = gfc_default_integer_kind; |
| 3295 |
f->value.function.name = this_image; |
| 3296 |
} |
| 3297 |
} |
| 3298 |
|
| 3299 |
|
| 3300 |
void |
| 3301 |
gfc_resolve_time (gfc_expr *f) |
| 3302 |
{ |
| 3303 |
f->ts.type = BT_INTEGER; |
| 3304 |
f->ts.kind = 4; |
| 3305 |
f->value.function.name = gfc_get_string (PREFIX ("time_func")); |
| 3306 |
} |
| 3307 |
|
| 3308 |
|
| 3309 |
void |
| 3310 |
gfc_resolve_time8 (gfc_expr *f) |
| 3311 |
{ |
| 3312 |
f->ts.type = BT_INTEGER; |
| 3313 |
f->ts.kind = 8; |
| 3314 |
f->value.function.name = gfc_get_string (PREFIX ("time8_func")); |
| 3315 |
} |
| 3316 |
|
| 3317 |
|
| 3318 |
void |
| 3319 |
gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED, |
| 3320 |
gfc_expr *mold, gfc_expr *size) |
| 3321 |
{ |
| 3322 |
/* TODO: Make this do something meaningful. */ |
| 3323 |
static char transfer0[] = "__transfer0", transfer1[] = "__transfer1"; |
| 3324 |
|
| 3325 |
if (mold->ts.type == BT_CHARACTER |
| 3326 |
&& !mold->ts.u.cl->length |
| 3327 |
&& gfc_is_constant_expr (mold)) |
| 3328 |
{ |
| 3329 |
int len; |
| 3330 |
if (mold->expr_type == EXPR_CONSTANT) |
| 3331 |
{ |
| 3332 |
len = mold->value.character.length; |
| 3333 |
mold->ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind, |
| 3334 |
NULL, len); |
| 3335 |
} |
| 3336 |
else |
| 3337 |
{ |
| 3338 |
gfc_constructor *c = gfc_constructor_first (mold->value.constructor); |
| 3339 |
len = c->expr->value.character.length; |
| 3340 |
mold->ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind, |
| 3341 |
NULL, len); |
| 3342 |
} |
| 3343 |
} |
| 3344 |
|
| 3345 |
if (UNLIMITED_POLY (mold)) |
| 3346 |
gfc_error ("TODO: unlimited polymorphic MOLD in TRANSFER intrinsic at %L", |
| 3347 |
&mold->where); |
| 3348 |
|
| 3349 |
f->ts = mold->ts; |
| 3350 |
|
| 3351 |
if (size == NULL && mold->rank == 0) |
| 3352 |
{ |
| 3353 |
f->rank = 0; |
| 3354 |
f->value.function.name = transfer0; |
| 3355 |
} |
| 3356 |
else |
| 3357 |
{ |
| 3358 |
f->rank = 1; |
| 3359 |
f->value.function.name = transfer1; |
| 3360 |
if (size && gfc_is_constant_expr (size)) |
| 3361 |
{ |
| 3362 |
f->shape = gfc_get_shape (1); |
| 3363 |
mpz_init_set (f->shape[0], size->value.integer); |
| 3364 |
} |
| 3365 |
} |
| 3366 |
} |
| 3367 |
|
| 3368 |
|
| 3369 |
void |
| 3370 |
gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix) |
| 3371 |
{ |
| 3372 |
|
| 3373 |
if (matrix->ts.type == BT_CHARACTER && matrix->ref) |
| 3374 |
gfc_resolve_substring_charlen (matrix); |
| 3375 |
|
| 3376 |
f->ts = matrix->ts; |
| 3377 |
f->rank = 2; |
| 3378 |
if (matrix->shape) |
| 3379 |
{ |
| 3380 |
f->shape = gfc_get_shape (2); |
| 3381 |
mpz_init_set (f->shape[0], matrix->shape[1]); |
| 3382 |
mpz_init_set (f->shape[1], matrix->shape[0]); |
| 3383 |
} |
| 3384 |
|
| 3385 |
switch (matrix->ts.kind) |
| 3386 |
{ |
| 3387 |
case 4: |
| 3388 |
case 8: |
| 3389 |
case 10: |
| 3390 |
case 16: |
| 3391 |
switch (matrix->ts.type) |
| 3392 |
{ |
| 3393 |
case BT_REAL: |
| 3394 |
case BT_COMPLEX: |
| 3395 |
f->value.function.name |
| 3396 |
= gfc_get_string (PREFIX ("transpose_%c%d"), |
| 3397 |
gfc_type_letter (matrix->ts.type), |
| 3398 |
gfc_type_abi_kind (&matrix->ts)); |
| 3399 |
break; |
| 3400 |
|
| 3401 |
case BT_INTEGER: |
| 3402 |
case BT_LOGICAL: |
| 3403 |
/* Use the integer routines for real and logical cases. This |
| 3404 |
assumes they all have the same alignment requirements. */ |
| 3405 |
f->value.function.name |
| 3406 |
= gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind); |
| 3407 |
break; |
| 3408 |
|
| 3409 |
default: |
| 3410 |
if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4) |
| 3411 |
f->value.function.name = PREFIX ("transpose_char4"); |
| 3412 |
else |
| 3413 |
f->value.function.name = PREFIX ("transpose"); |
| 3414 |
break; |
| 3415 |
} |
| 3416 |
break; |
| 3417 |
|
| 3418 |
default: |
| 3419 |
f->value.function.name = (matrix->ts.type == BT_CHARACTER |
| 3420 |
? PREFIX ("transpose_char") |
| 3421 |
: PREFIX ("transpose")); |
| 3422 |
break; |
| 3423 |
} |
| 3424 |
} |
| 3425 |
|
| 3426 |
|
| 3427 |
void |
| 3428 |
gfc_resolve_trim (gfc_expr *f, gfc_expr *string) |
| 3429 |
{ |
| 3430 |
f->ts.type = BT_CHARACTER; |
| 3431 |
f->ts.kind = string->ts.kind; |
| 3432 |
f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind); |
| 3433 |
} |
| 3434 |
|
| 3435 |
|
| 3436 |
/* Resolve the degree trigonometric functions. This amounts to setting |
| 3437 |
the function return type-spec from its argument and building a |
| 3438 |
library function names of the form _gfortran_sind_r4. */ |
| 3439 |
|
| 3440 |
void |
| 3441 |
gfc_resolve_trigd (gfc_expr *f, gfc_expr *x) |
| 3442 |
{ |
| 3443 |
f->ts = x->ts; |
| 3444 |
f->value.function.name |
| 3445 |
= gfc_get_string (PREFIX ("%s_%c%d"), f->value.function.isym->name, |
| 3446 |
gfc_type_letter (x->ts.type), |
| 3447 |
gfc_type_abi_kind (&x->ts)); |
| 3448 |
} |
| 3449 |
|
| 3450 |
|
| 3451 |
void |
| 3452 |
gfc_resolve_trigd2 (gfc_expr *f, gfc_expr *y, gfc_expr *x) |
| 3453 |
{ |
| 3454 |
f->ts = y->ts; |
| 3455 |
f->value.function.name |
| 3456 |
= gfc_get_string (PREFIX ("%s_%d"), f->value.function.isym->name, |
| 3457 |
x->ts.kind); |
| 3458 |
} |
| 3459 |
|
| 3460 |
|
| 3461 |
void |
| 3462 |
gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind) |
| 3463 |
{ |
| 3464 |
resolve_bound (f, array, dim, kind, "__ubound", false); |
| 3465 |
} |
| 3466 |
|
| 3467 |
|
| 3468 |
void |
| 3469 |
gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind) |
| 3470 |
{ |
| 3471 |
resolve_bound (f, array, dim, kind, "__ucobound", true); |
| 3472 |
} |
| 3473 |
|
| 3474 |
|
| 3475 |
/* Resolve the g77 compatibility function UMASK. */ |
| 3476 |
|
| 3477 |
void |
| 3478 |
gfc_resolve_umask (gfc_expr *f, gfc_expr *n) |
| 3479 |
{ |
| 3480 |
f->ts.type = BT_INTEGER; |
| 3481 |
f->ts.kind = n->ts.kind; |
| 3482 |
f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind); |
| 3483 |
} |
| 3484 |
|
| 3485 |
|
| 3486 |
/* Resolve the g77 compatibility function UNLINK. */ |
| 3487 |
|
| 3488 |
void |
| 3489 |
gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED) |
| 3490 |
{ |
| 3491 |
f->ts.type = BT_INTEGER; |
| 3492 |
f->ts.kind = 4; |
| 3493 |
f->value.function.name = gfc_get_string (PREFIX ("unlink")); |
| 3494 |
} |
| 3495 |
|
| 3496 |
|
| 3497 |
void |
| 3498 |
gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit) |
| 3499 |
{ |
| 3500 |
gfc_typespec ts; |
| 3501 |
gfc_clear_ts (&ts); |
| 3502 |
|
| 3503 |
f->ts.type = BT_CHARACTER; |
| 3504 |
f->ts.kind = gfc_default_character_kind; |
| 3505 |
|
| 3506 |
if (unit->ts.kind != gfc_c_int_kind) |
| 3507 |
{ |
| 3508 |
ts.type = BT_INTEGER; |
| 3509 |
ts.kind = gfc_c_int_kind; |
| 3510 |
ts.u.derived = NULL; |
| 3511 |
ts.u.cl = NULL; |
| 3512 |
gfc_convert_type (unit, &ts, 2); |
| 3513 |
} |
| 3514 |
|
| 3515 |
f->value.function.name = gfc_get_string (PREFIX ("ttynam")); |
| 3516 |
} |
| 3517 |
|
| 3518 |
|
| 3519 |
void |
| 3520 |
gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask, |
| 3521 |
gfc_expr *field ATTRIBUTE_UNUSED) |
| 3522 |
{ |
| 3523 |
if (vector->ts.type == BT_CHARACTER && vector->ref) |
| 3524 |
gfc_resolve_substring_charlen (vector); |
| 3525 |
|
| 3526 |
f->ts = vector->ts; |
| 3527 |
f->rank = mask->rank; |
| 3528 |
resolve_mask_arg (mask); |
| 3529 |
|
| 3530 |
if (vector->ts.type == BT_CHARACTER) |
| 3531 |
{ |
| 3532 |
if (vector->ts.kind == 1) |
| 3533 |
f->value.function.name |
| 3534 |
= gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0); |
| 3535 |
else |
| 3536 |
f->value.function.name |
| 3537 |
= gfc_get_string (PREFIX ("unpack%d_char%d"), |
| 3538 |
field->rank > 0 ? 1 : 0, vector->ts.kind); |
| 3539 |
} |
| 3540 |
else |
| 3541 |
f->value.function.name |
| 3542 |
= gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0); |
| 3543 |
} |
| 3544 |
|
| 3545 |
|
| 3546 |
void |
| 3547 |
gfc_resolve_verify (gfc_expr *f, gfc_expr *string, |
| 3548 |
gfc_expr *set ATTRIBUTE_UNUSED, |
| 3549 |
gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind) |
| 3550 |
{ |
| 3551 |
f->ts.type = BT_INTEGER; |
| 3552 |
if (kind) |
| 3553 |
f->ts.kind = mpz_get_si (kind->value.integer); |
| 3554 |
else |
| 3555 |
f->ts.kind = gfc_default_integer_kind; |
| 3556 |
f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind); |
| 3557 |
} |
| 3558 |
|
| 3559 |
|
| 3560 |
void |
| 3561 |
gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
| 3562 |
{ |
| 3563 |
f->ts.type = i->ts.type; |
| 3564 |
f->ts.kind = gfc_kind_max (i, j); |
| 3565 |
|
| 3566 |
if (i->ts.kind != j->ts.kind) |
| 3567 |
{ |
| 3568 |
if (i->ts.kind == gfc_kind_max (i, j)) |
| 3569 |
gfc_convert_type (j, &i->ts, 2); |
| 3570 |
else |
| 3571 |
gfc_convert_type (i, &j->ts, 2); |
| 3572 |
} |
| 3573 |
|
| 3574 |
f->value.function.name |
| 3575 |
= gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), |
| 3576 |
gfc_type_abi_kind (&f->ts)); |
| 3577 |
} |
| 3578 |
|
| 3579 |
|
| 3580 |
/* Intrinsic subroutine resolution. */ |
| 3581 |
|
| 3582 |
void |
| 3583 |
gfc_resolve_alarm_sub (gfc_code *c) |
| 3584 |
{ |
| 3585 |
const char *name; |
| 3586 |
gfc_expr *seconds, *handler; |
| 3587 |
gfc_typespec ts; |
| 3588 |
gfc_clear_ts (&ts); |
| 3589 |
|
| 3590 |
seconds = c->ext.actual->expr; |
| 3591 |
handler = c->ext.actual->next->expr; |
| 3592 |
ts.type = BT_INTEGER; |
| 3593 |
ts.kind = gfc_c_int_kind; |
| 3594 |
|
| 3595 |
/* handler can be either BT_INTEGER or BT_PROCEDURE. |
| 3596 |
In all cases, the status argument is of default integer kind |
| 3597 |
(enforced in check.cc) so that the function suffix is fixed. */ |
| 3598 |
if (handler->ts.type == BT_INTEGER) |
| 3599 |
{ |
| 3600 |
if (handler->ts.kind != gfc_c_int_kind) |
| 3601 |
gfc_convert_type (handler, &ts, 2); |
| 3602 |
name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"), |
| 3603 |
gfc_default_integer_kind); |
| 3604 |
} |
| 3605 |
else |
| 3606 |
name = gfc_get_string (PREFIX ("alarm_sub_i%d"), |
| 3607 |
gfc_default_integer_kind); |
| 3608 |
|
| 3609 |
if (seconds->ts.kind != gfc_c_int_kind) |
| 3610 |
gfc_convert_type (seconds, &ts, 2); |
| 3611 |
|
| 3612 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3613 |
} |
| 3614 |
|
| 3615 |
void |
| 3616 |
gfc_resolve_cpu_time (gfc_code *c) |
| 3617 |
{ |
| 3618 |
const char *name; |
| 3619 |
name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind); |
| 3620 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3621 |
} |
| 3622 |
|
| 3623 |
|
| 3624 |
/* Create a formal arglist based on an actual one and set the INTENTs given. */ |
| 3625 |
|
| 3626 |
static gfc_formal_arglist* |
| 3627 |
create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints) |
| 3628 |
{ |
| 3629 |
gfc_formal_arglist* head; |
| 3630 |
gfc_formal_arglist* tail; |
| 3631 |
int i; |
| 3632 |
|
| 3633 |
if (!actual) |
| 3634 |
return NULL; |
| 3635 |
|
| 3636 |
head = tail = gfc_get_formal_arglist (); |
| 3637 |
for (i = 0; actual; actual = actual->next, tail = tail->next, ++i) |
| 3638 |
{ |
| 3639 |
gfc_symbol* sym; |
| 3640 |
|
| 3641 |
sym = gfc_new_symbol ("dummyarg", NULL); |
| 3642 |
sym->ts = actual->expr->ts; |
| 3643 |
|
| 3644 |
sym->attr.intent = ints[i]; |
| 3645 |
tail->sym = sym; |
| 3646 |
|
| 3647 |
if (actual->next) |
| 3648 |
tail->next = gfc_get_formal_arglist (); |
| 3649 |
} |
| 3650 |
|
| 3651 |
return head; |
| 3652 |
} |
| 3653 |
|
| 3654 |
|
| 3655 |
void |
| 3656 |
gfc_resolve_atomic_def (gfc_code *c) |
| 3657 |
{ |
| 3658 |
const char *name = "atomic_define"; |
| 3659 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3660 |
} |
| 3661 |
|
| 3662 |
|
| 3663 |
void |
| 3664 |
gfc_resolve_atomic_ref (gfc_code *c) |
| 3665 |
{ |
| 3666 |
const char *name = "atomic_ref"; |
| 3667 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3668 |
} |
| 3669 |
|
| 3670 |
void |
| 3671 |
gfc_resolve_event_query (gfc_code *c) |
| 3672 |
{ |
| 3673 |
const char *name = "event_query"; |
| 3674 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3675 |
} |
| 3676 |
|
| 3677 |
void |
| 3678 |
gfc_resolve_mvbits (gfc_code *c) |
| 3679 |
{ |
| 3680 |
static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN, |
| 3681 |
INTENT_INOUT, INTENT_IN}; |
| 3682 |
const char *name; |
| 3683 |
|
| 3684 |
/* TO and FROM are guaranteed to have the same kind parameter. */ |
| 3685 |
name = gfc_get_string (PREFIX ("mvbits_i%d"), |
| 3686 |
c->ext.actual->expr->ts.kind); |
| 3687 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3688 |
/* Mark as elemental subroutine as this does not happen automatically. */ |
| 3689 |
c->resolved_sym->attr.elemental = 1; |
| 3690 |
|
| 3691 |
/* Create a dummy formal arglist so the INTENTs are known later for purpose |
| 3692 |
of creating temporaries. */ |
| 3693 |
c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS); |
| 3694 |
} |
| 3695 |
|
| 3696 |
|
| 3697 |
/* Set up the call to RANDOM_INIT. */ |
| 3698 |
|
| 3699 |
void |
| 3700 |
gfc_resolve_random_init (gfc_code *c) |
| 3701 |
{ |
| 3702 |
const char *name; |
| 3703 |
name = gfc_get_string (PREFIX ("random_init")); |
| 3704 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3705 |
} |
| 3706 |
|
| 3707 |
|
| 3708 |
void |
| 3709 |
gfc_resolve_random_number (gfc_code *c) |
| 3710 |
{ |
| 3711 |
const char *name; |
| 3712 |
int kind; |
| 3713 |
char type; |
| 3714 |
|
| 3715 |
kind = gfc_type_abi_kind (&c->ext.actual->expr->ts); |
| 3716 |
type = gfc_type_letter (c->ext.actual->expr->ts.type); |
| 3717 |
if (c->ext.actual->expr->rank == 0) |
| 3718 |
name = gfc_get_string (PREFIX ("random_%c%d"), type, kind); |
| 3719 |
else |
| 3720 |
name = gfc_get_string (PREFIX ("arandom_%c%d"), type, kind); |
| 3721 |
|
| 3722 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3723 |
} |
| 3724 |
|
| 3725 |
|
| 3726 |
void |
| 3727 |
gfc_resolve_random_seed (gfc_code *c) |
| 3728 |
{ |
| 3729 |
const char *name; |
| 3730 |
|
| 3731 |
name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind); |
| 3732 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3733 |
} |
| 3734 |
|
| 3735 |
|
| 3736 |
void |
| 3737 |
gfc_resolve_rename_sub (gfc_code *c) |
| 3738 |
{ |
| 3739 |
const char *name; |
| 3740 |
int kind; |
| 3741 |
|
| 3742 |
/* Find the type of status. If not present use default integer kind. */ |
| 3743 |
if (c->ext.actual->next->next->expr != NULL) |
| 3744 |
kind = c->ext.actual->next->next->expr->ts.kind; |
| 3745 |
else |
| 3746 |
kind = gfc_default_integer_kind; |
| 3747 |
|
| 3748 |
name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind); |
| 3749 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3750 |
} |
| 3751 |
|
| 3752 |
|
| 3753 |
void |
| 3754 |
gfc_resolve_link_sub (gfc_code *c) |
| 3755 |
{ |
| 3756 |
const char *name; |
| 3757 |
int kind; |
| 3758 |
|
| 3759 |
if (c->ext.actual->next->next->expr != NULL) |
| 3760 |
kind = c->ext.actual->next->next->expr->ts.kind; |
| 3761 |
else |
| 3762 |
kind = gfc_default_integer_kind; |
| 3763 |
|
| 3764 |
name = gfc_get_string (PREFIX ("link_i%d_sub"), kind); |
| 3765 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3766 |
} |
| 3767 |
|
| 3768 |
|
| 3769 |
void |
| 3770 |
gfc_resolve_symlnk_sub (gfc_code *c) |
| 3771 |
{ |
| 3772 |
const char *name; |
| 3773 |
int kind; |
| 3774 |
|
| 3775 |
if (c->ext.actual->next->next->expr != NULL) |
| 3776 |
kind = c->ext.actual->next->next->expr->ts.kind; |
| 3777 |
else |
| 3778 |
kind = gfc_default_integer_kind; |
| 3779 |
|
| 3780 |
name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind); |
| 3781 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3782 |
} |
| 3783 |
|
| 3784 |
|
| 3785 |
/* G77 compatibility subroutines dtime() and etime(). */ |
| 3786 |
|
| 3787 |
void |
| 3788 |
gfc_resolve_dtime_sub (gfc_code *c) |
| 3789 |
{ |
| 3790 |
const char *name; |
| 3791 |
name = gfc_get_string (PREFIX ("dtime_sub")); |
| 3792 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3793 |
} |
| 3794 |
|
| 3795 |
void |
| 3796 |
gfc_resolve_etime_sub (gfc_code *c) |
| 3797 |
{ |
| 3798 |
const char *name; |
| 3799 |
name = gfc_get_string (PREFIX ("etime_sub")); |
| 3800 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3801 |
} |
| 3802 |
|
| 3803 |
|
| 3804 |
/* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */ |
| 3805 |
|
| 3806 |
void |
| 3807 |
gfc_resolve_itime (gfc_code *c) |
| 3808 |
{ |
| 3809 |
c->resolved_sym |
| 3810 |
= gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"), |
| 3811 |
gfc_default_integer_kind)); |
| 3812 |
} |
| 3813 |
|
| 3814 |
void |
| 3815 |
gfc_resolve_idate (gfc_code *c) |
| 3816 |
{ |
| 3817 |
c->resolved_sym |
| 3818 |
= gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"), |
| 3819 |
gfc_default_integer_kind)); |
| 3820 |
} |
| 3821 |
|
| 3822 |
void |
| 3823 |
gfc_resolve_ltime (gfc_code *c) |
| 3824 |
{ |
| 3825 |
c->resolved_sym |
| 3826 |
= gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"), |
| 3827 |
gfc_default_integer_kind)); |
| 3828 |
} |
| 3829 |
|
| 3830 |
void |
| 3831 |
gfc_resolve_gmtime (gfc_code *c) |
| 3832 |
{ |
| 3833 |
c->resolved_sym |
| 3834 |
= gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"), |
| 3835 |
gfc_default_integer_kind)); |
| 3836 |
} |
| 3837 |
|
| 3838 |
|
| 3839 |
/* G77 compatibility subroutine second(). */ |
| 3840 |
|
| 3841 |
void |
| 3842 |
gfc_resolve_second_sub (gfc_code *c) |
| 3843 |
{ |
| 3844 |
const char *name; |
| 3845 |
name = gfc_get_string (PREFIX ("second_sub")); |
| 3846 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3847 |
} |
| 3848 |
|
| 3849 |
|
| 3850 |
void |
| 3851 |
gfc_resolve_sleep_sub (gfc_code *c) |
| 3852 |
{ |
| 3853 |
const char *name; |
| 3854 |
int kind; |
| 3855 |
|
| 3856 |
if (c->ext.actual->expr != NULL) |
| 3857 |
kind = c->ext.actual->expr->ts.kind; |
| 3858 |
else |
| 3859 |
kind = gfc_default_integer_kind; |
| 3860 |
|
| 3861 |
name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind); |
| 3862 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3863 |
} |
| 3864 |
|
| 3865 |
|
| 3866 |
/* G77 compatibility function srand(). */ |
| 3867 |
|
| 3868 |
void |
| 3869 |
gfc_resolve_srand (gfc_code *c) |
| 3870 |
{ |
| 3871 |
const char *name; |
| 3872 |
name = gfc_get_string (PREFIX ("srand")); |
| 3873 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3874 |
} |
| 3875 |
|
| 3876 |
|
| 3877 |
/* Resolve the getarg intrinsic subroutine. */ |
| 3878 |
|
| 3879 |
void |
| 3880 |
gfc_resolve_getarg (gfc_code *c) |
| 3881 |
{ |
| 3882 |
const char *name; |
| 3883 |
|
| 3884 |
if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind) |
| 3885 |
{ |
| 3886 |
gfc_typespec ts; |
| 3887 |
gfc_clear_ts (&ts); |
| 3888 |
|
| 3889 |
ts.type = BT_INTEGER; |
| 3890 |
ts.kind = gfc_default_integer_kind; |
| 3891 |
|
| 3892 |
gfc_convert_type (c->ext.actual->expr, &ts, 2); |
| 3893 |
} |
| 3894 |
|
| 3895 |
name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind); |
| 3896 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3897 |
} |
| 3898 |
|
| 3899 |
|
| 3900 |
/* Resolve the getcwd intrinsic subroutine. */ |
| 3901 |
|
| 3902 |
void |
| 3903 |
gfc_resolve_getcwd_sub (gfc_code *c) |
| 3904 |
{ |
| 3905 |
const char *name; |
| 3906 |
int kind; |
| 3907 |
|
| 3908 |
if (c->ext.actual->next->expr != NULL) |
| 3909 |
kind = c->ext.actual->next->expr->ts.kind; |
| 3910 |
else |
| 3911 |
kind = gfc_default_integer_kind; |
| 3912 |
|
| 3913 |
name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind); |
| 3914 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3915 |
} |
| 3916 |
|
| 3917 |
|
| 3918 |
/* Resolve the get_command intrinsic subroutine. */ |
| 3919 |
|
| 3920 |
void |
| 3921 |
gfc_resolve_get_command (gfc_code *c) |
| 3922 |
{ |
| 3923 |
const char *name; |
| 3924 |
int kind; |
| 3925 |
kind = gfc_default_integer_kind; |
| 3926 |
name = gfc_get_string (PREFIX ("get_command_i%d"), kind); |
| 3927 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3928 |
} |
| 3929 |
|
| 3930 |
|
| 3931 |
/* Resolve the get_command_argument intrinsic subroutine. */ |
| 3932 |
|
| 3933 |
void |
| 3934 |
gfc_resolve_get_command_argument (gfc_code *c) |
| 3935 |
{ |
| 3936 |
const char *name; |
| 3937 |
int kind; |
| 3938 |
kind = gfc_default_integer_kind; |
| 3939 |
name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind); |
| 3940 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3941 |
} |
| 3942 |
|
| 3943 |
|
| 3944 |
/* Resolve the get_environment_variable intrinsic subroutine. */ |
| 3945 |
|
| 3946 |
void |
| 3947 |
gfc_resolve_get_environment_variable (gfc_code *code) |
| 3948 |
{ |
| 3949 |
const char *name; |
| 3950 |
int kind; |
| 3951 |
kind = gfc_default_integer_kind; |
| 3952 |
name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind); |
| 3953 |
code->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3954 |
} |
| 3955 |
|
| 3956 |
|
| 3957 |
void |
| 3958 |
gfc_resolve_signal_sub (gfc_code *c) |
| 3959 |
{ |
| 3960 |
const char *name; |
| 3961 |
gfc_expr *number, *handler, *status; |
| 3962 |
gfc_typespec ts; |
| 3963 |
gfc_clear_ts (&ts); |
| 3964 |
|
| 3965 |
number = c->ext.actual->expr; |
| 3966 |
handler = c->ext.actual->next->expr; |
| 3967 |
status = c->ext.actual->next->next->expr; |
| 3968 |
ts.type = BT_INTEGER; |
| 3969 |
ts.kind = gfc_c_int_kind; |
| 3970 |
|
| 3971 |
/* handler can be either BT_INTEGER or BT_PROCEDURE */ |
| 3972 |
if (handler->ts.type == BT_INTEGER) |
| 3973 |
{ |
| 3974 |
if (handler->ts.kind != gfc_c_int_kind) |
| 3975 |
gfc_convert_type (handler, &ts, 2); |
| 3976 |
name = gfc_get_string (PREFIX ("signal_sub_int")); |
| 3977 |
} |
| 3978 |
else |
| 3979 |
name = gfc_get_string (PREFIX ("signal_sub")); |
| 3980 |
|
| 3981 |
if (number->ts.kind != gfc_c_int_kind) |
| 3982 |
gfc_convert_type (number, &ts, 2); |
| 3983 |
if (status != NULL && status->ts.kind != gfc_c_int_kind) |
| 3984 |
gfc_convert_type (status, &ts, 2); |
| 3985 |
|
| 3986 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3987 |
} |
| 3988 |
|
| 3989 |
|
| 3990 |
/* Resolve the SYSTEM intrinsic subroutine. */ |
| 3991 |
|
| 3992 |
void |
| 3993 |
gfc_resolve_system_sub (gfc_code *c) |
| 3994 |
{ |
| 3995 |
const char *name; |
| 3996 |
name = gfc_get_string (PREFIX ("system_sub")); |
| 3997 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 3998 |
} |
| 3999 |
|
| 4000 |
|
| 4001 |
/* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */ |
| 4002 |
|
| 4003 |
void |
| 4004 |
gfc_resolve_system_clock (gfc_code *c) |
| 4005 |
{ |
| 4006 |
const char *name; |
| 4007 |
int kind; |
| 4008 |
gfc_expr *count = c->ext.actual->expr; |
| 4009 |
gfc_expr *count_max = c->ext.actual->next->next->expr; |
| 4010 |
|
| 4011 |
/* The INTEGER(8) version has higher precision, it is used if both COUNT |
| 4012 |
and COUNT_MAX can hold 64-bit values, or are absent. */ |
| 4013 |
if ((!count || count->ts.kind >= 8) |
| 4014 |
&& (!count_max || count_max->ts.kind >= 8)) |
| 4015 |
kind = 8; |
| 4016 |
else |
| 4017 |
kind = gfc_default_integer_kind; |
| 4018 |
|
| 4019 |
name = gfc_get_string (PREFIX ("system_clock_%d"), kind); |
| 4020 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4021 |
} |
| 4022 |
|
| 4023 |
|
| 4024 |
/* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */ |
| 4025 |
void |
| 4026 |
gfc_resolve_execute_command_line (gfc_code *c) |
| 4027 |
{ |
| 4028 |
const char *name; |
| 4029 |
name = gfc_get_string (PREFIX ("execute_command_line_i%d"), |
| 4030 |
gfc_default_integer_kind); |
| 4031 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4032 |
} |
| 4033 |
|
| 4034 |
|
| 4035 |
/* Resolve the EXIT intrinsic subroutine. */ |
| 4036 |
|
| 4037 |
void |
| 4038 |
gfc_resolve_exit (gfc_code *c) |
| 4039 |
{ |
| 4040 |
const char *name; |
| 4041 |
gfc_typespec ts; |
| 4042 |
gfc_expr *n; |
| 4043 |
gfc_clear_ts (&ts); |
| 4044 |
|
| 4045 |
/* The STATUS argument has to be of default kind. If it is not, |
| 4046 |
we convert it. */ |
| 4047 |
ts.type = BT_INTEGER; |
| 4048 |
ts.kind = gfc_default_integer_kind; |
| 4049 |
n = c->ext.actual->expr; |
| 4050 |
if (n != NULL && n->ts.kind != ts.kind) |
| 4051 |
gfc_convert_type (n, &ts, 2); |
| 4052 |
|
| 4053 |
name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind); |
| 4054 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4055 |
} |
| 4056 |
|
| 4057 |
|
| 4058 |
/* Resolve the FLUSH intrinsic subroutine. */ |
| 4059 |
|
| 4060 |
void |
| 4061 |
gfc_resolve_flush (gfc_code *c) |
| 4062 |
{ |
| 4063 |
const char *name; |
| 4064 |
gfc_typespec ts; |
| 4065 |
gfc_expr *n; |
| 4066 |
gfc_clear_ts (&ts); |
| 4067 |
|
| 4068 |
ts.type = BT_INTEGER; |
| 4069 |
ts.kind = gfc_default_integer_kind; |
| 4070 |
n = c->ext.actual->expr; |
| 4071 |
if (n != NULL && n->ts.kind != ts.kind) |
| 4072 |
gfc_convert_type (n, &ts, 2); |
| 4073 |
|
| 4074 |
name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind); |
| 4075 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4076 |
} |
| 4077 |
|
| 4078 |
|
| 4079 |
void |
| 4080 |
gfc_resolve_ctime_sub (gfc_code *c) |
| 4081 |
{ |
| 4082 |
gfc_typespec ts; |
| 4083 |
gfc_clear_ts (&ts); |
| 4084 |
|
| 4085 |
/* ctime TIME argument is a INTEGER(KIND=8), says the doc */ |
| 4086 |
if (c->ext.actual->expr->ts.kind != 8) |
| 4087 |
{ |
| 4088 |
ts.type = BT_INTEGER; |
| 4089 |
ts.kind = 8; |
| 4090 |
ts.u.derived = NULL; |
| 4091 |
ts.u.cl = NULL; |
| 4092 |
gfc_convert_type (c->ext.actual->expr, &ts, 2); |
| 4093 |
} |
| 4094 |
|
| 4095 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub")); |
| 4096 |
} |
| 4097 |
|
| 4098 |
|
| 4099 |
void |
| 4100 |
gfc_resolve_fdate_sub (gfc_code *c) |
| 4101 |
{ |
| 4102 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub")); |
| 4103 |
} |
| 4104 |
|
| 4105 |
|
| 4106 |
void |
| 4107 |
gfc_resolve_gerror (gfc_code *c) |
| 4108 |
{ |
| 4109 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror")); |
| 4110 |
} |
| 4111 |
|
| 4112 |
|
| 4113 |
void |
| 4114 |
gfc_resolve_getlog (gfc_code *c) |
| 4115 |
{ |
| 4116 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog")); |
| 4117 |
} |
| 4118 |
|
| 4119 |
|
| 4120 |
void |
| 4121 |
gfc_resolve_hostnm_sub (gfc_code *c) |
| 4122 |
{ |
| 4123 |
const char *name; |
| 4124 |
int kind; |
| 4125 |
|
| 4126 |
if (c->ext.actual->next->expr != NULL) |
| 4127 |
kind = c->ext.actual->next->expr->ts.kind; |
| 4128 |
else |
| 4129 |
kind = gfc_default_integer_kind; |
| 4130 |
|
| 4131 |
name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind); |
| 4132 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4133 |
} |
| 4134 |
|
| 4135 |
|
| 4136 |
void |
| 4137 |
gfc_resolve_perror (gfc_code *c) |
| 4138 |
{ |
| 4139 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub")); |
| 4140 |
} |
| 4141 |
|
| 4142 |
/* Resolve the STAT and FSTAT intrinsic subroutines. */ |
| 4143 |
|
| 4144 |
void |
| 4145 |
gfc_resolve_stat_sub (gfc_code *c) |
| 4146 |
{ |
| 4147 |
const char *name; |
| 4148 |
name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind); |
| 4149 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4150 |
} |
| 4151 |
|
| 4152 |
|
| 4153 |
void |
| 4154 |
gfc_resolve_lstat_sub (gfc_code *c) |
| 4155 |
{ |
| 4156 |
const char *name; |
| 4157 |
name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind); |
| 4158 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4159 |
} |
| 4160 |
|
| 4161 |
|
| 4162 |
void |
| 4163 |
gfc_resolve_fstat_sub (gfc_code *c) |
| 4164 |
{ |
| 4165 |
const char *name; |
| 4166 |
gfc_expr *u; |
| 4167 |
gfc_typespec *ts; |
| 4168 |
|
| 4169 |
u = c->ext.actual->expr; |
| 4170 |
ts = &c->ext.actual->next->expr->ts; |
| 4171 |
if (u->ts.kind != ts->kind) |
| 4172 |
gfc_convert_type (u, ts, 2); |
| 4173 |
name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind); |
| 4174 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4175 |
} |
| 4176 |
|
| 4177 |
|
| 4178 |
void |
| 4179 |
gfc_resolve_fgetc_sub (gfc_code *c) |
| 4180 |
{ |
| 4181 |
const char *name; |
| 4182 |
gfc_typespec ts; |
| 4183 |
gfc_expr *u, *st; |
| 4184 |
gfc_clear_ts (&ts); |
| 4185 |
|
| 4186 |
u = c->ext.actual->expr; |
| 4187 |
st = c->ext.actual->next->next->expr; |
| 4188 |
|
| 4189 |
if (u->ts.kind != gfc_c_int_kind) |
| 4190 |
{ |
| 4191 |
ts.type = BT_INTEGER; |
| 4192 |
ts.kind = gfc_c_int_kind; |
| 4193 |
ts.u.derived = NULL; |
| 4194 |
ts.u.cl = NULL; |
| 4195 |
gfc_convert_type (u, &ts, 2); |
| 4196 |
} |
| 4197 |
|
| 4198 |
if (st != NULL) |
| 4199 |
name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind); |
| 4200 |
else |
| 4201 |
name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind); |
| 4202 |
|
| 4203 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4204 |
} |
| 4205 |
|
| 4206 |
|
| 4207 |
void |
| 4208 |
gfc_resolve_fget_sub (gfc_code *c) |
| 4209 |
{ |
| 4210 |
const char *name; |
| 4211 |
gfc_expr *st; |
| 4212 |
|
| 4213 |
st = c->ext.actual->next->expr; |
| 4214 |
if (st != NULL) |
| 4215 |
name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind); |
| 4216 |
else |
| 4217 |
name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind); |
| 4218 |
|
| 4219 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4220 |
} |
| 4221 |
|
| 4222 |
|
| 4223 |
void |
| 4224 |
gfc_resolve_fputc_sub (gfc_code *c) |
| 4225 |
{ |
| 4226 |
const char *name; |
| 4227 |
gfc_typespec ts; |
| 4228 |
gfc_expr *u, *st; |
| 4229 |
gfc_clear_ts (&ts); |
| 4230 |
|
| 4231 |
u = c->ext.actual->expr; |
| 4232 |
st = c->ext.actual->next->next->expr; |
| 4233 |
|
| 4234 |
if (u->ts.kind != gfc_c_int_kind) |
| 4235 |
{ |
| 4236 |
ts.type = BT_INTEGER; |
| 4237 |
ts.kind = gfc_c_int_kind; |
| 4238 |
ts.u.derived = NULL; |
| 4239 |
ts.u.cl = NULL; |
| 4240 |
gfc_convert_type (u, &ts, 2); |
| 4241 |
} |
| 4242 |
|
| 4243 |
if (st != NULL) |
| 4244 |
name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind); |
| 4245 |
else |
| 4246 |
name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind); |
| 4247 |
|
| 4248 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4249 |
} |
| 4250 |
|
| 4251 |
|
| 4252 |
void |
| 4253 |
gfc_resolve_fput_sub (gfc_code *c) |
| 4254 |
{ |
| 4255 |
const char *name; |
| 4256 |
gfc_expr *st; |
| 4257 |
|
| 4258 |
st = c->ext.actual->next->expr; |
| 4259 |
if (st != NULL) |
| 4260 |
name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind); |
| 4261 |
else |
| 4262 |
name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind); |
| 4263 |
|
| 4264 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4265 |
} |
| 4266 |
|
| 4267 |
|
| 4268 |
void |
| 4269 |
gfc_resolve_fseek_sub (gfc_code *c) |
| 4270 |
{ |
| 4271 |
gfc_expr *unit; |
| 4272 |
gfc_expr *offset; |
| 4273 |
gfc_expr *whence; |
| 4274 |
gfc_typespec ts; |
| 4275 |
gfc_clear_ts (&ts); |
| 4276 |
|
| 4277 |
unit = c->ext.actual->expr; |
| 4278 |
offset = c->ext.actual->next->expr; |
| 4279 |
whence = c->ext.actual->next->next->expr; |
| 4280 |
|
| 4281 |
if (unit->ts.kind != gfc_c_int_kind) |
| 4282 |
{ |
| 4283 |
ts.type = BT_INTEGER; |
| 4284 |
ts.kind = gfc_c_int_kind; |
| 4285 |
ts.u.derived = NULL; |
| 4286 |
ts.u.cl = NULL; |
| 4287 |
gfc_convert_type (unit, &ts, 2); |
| 4288 |
} |
| 4289 |
|
| 4290 |
if (offset->ts.kind != gfc_intio_kind) |
| 4291 |
{ |
| 4292 |
ts.type = BT_INTEGER; |
| 4293 |
ts.kind = gfc_intio_kind; |
| 4294 |
ts.u.derived = NULL; |
| 4295 |
ts.u.cl = NULL; |
| 4296 |
gfc_convert_type (offset, &ts, 2); |
| 4297 |
} |
| 4298 |
|
| 4299 |
if (whence->ts.kind != gfc_c_int_kind) |
| 4300 |
{ |
| 4301 |
ts.type = BT_INTEGER; |
| 4302 |
ts.kind = gfc_c_int_kind; |
| 4303 |
ts.u.derived = NULL; |
| 4304 |
ts.u.cl = NULL; |
| 4305 |
gfc_convert_type (whence, &ts, 2); |
| 4306 |
} |
| 4307 |
|
| 4308 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub")); |
| 4309 |
} |
| 4310 |
|
| 4311 |
void |
| 4312 |
gfc_resolve_ftell_sub (gfc_code *c) |
| 4313 |
{ |
| 4314 |
const char *name; |
| 4315 |
gfc_expr *unit; |
| 4316 |
gfc_expr *offset; |
| 4317 |
gfc_typespec ts; |
| 4318 |
gfc_clear_ts (&ts); |
| 4319 |
|
| 4320 |
unit = c->ext.actual->expr; |
| 4321 |
offset = c->ext.actual->next->expr; |
| 4322 |
|
| 4323 |
if (unit->ts.kind != gfc_c_int_kind) |
| 4324 |
{ |
| 4325 |
ts.type = BT_INTEGER; |
| 4326 |
ts.kind = gfc_c_int_kind; |
| 4327 |
ts.u.derived = NULL; |
| 4328 |
ts.u.cl = NULL; |
| 4329 |
gfc_convert_type (unit, &ts, 2); |
| 4330 |
} |
| 4331 |
|
| 4332 |
name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind); |
| 4333 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4334 |
} |
| 4335 |
|
| 4336 |
|
| 4337 |
void |
| 4338 |
gfc_resolve_ttynam_sub (gfc_code *c) |
| 4339 |
{ |
| 4340 |
gfc_typespec ts; |
| 4341 |
gfc_clear_ts (&ts); |
| 4342 |
|
| 4343 |
if (c->ext.actual->expr->ts.kind != gfc_c_int_kind) |
| 4344 |
{ |
| 4345 |
ts.type = BT_INTEGER; |
| 4346 |
ts.kind = gfc_c_int_kind; |
| 4347 |
ts.u.derived = NULL; |
| 4348 |
ts.u.cl = NULL; |
| 4349 |
gfc_convert_type (c->ext.actual->expr, &ts, 2); |
| 4350 |
} |
| 4351 |
|
| 4352 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub")); |
| 4353 |
} |
| 4354 |
|
| 4355 |
|
| 4356 |
/* Resolve the UMASK intrinsic subroutine. */ |
| 4357 |
|
| 4358 |
void |
| 4359 |
gfc_resolve_umask_sub (gfc_code *c) |
| 4360 |
{ |
| 4361 |
const char *name; |
| 4362 |
int kind; |
| 4363 |
|
| 4364 |
if (c->ext.actual->next->expr != NULL) |
| 4365 |
kind = c->ext.actual->next->expr->ts.kind; |
| 4366 |
else |
| 4367 |
kind = gfc_default_integer_kind; |
| 4368 |
|
| 4369 |
name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind); |
| 4370 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4371 |
} |
| 4372 |
|
| 4373 |
/* Resolve the UNLINK intrinsic subroutine. */ |
| 4374 |
|
| 4375 |
void |
| 4376 |
gfc_resolve_unlink_sub (gfc_code *c) |
| 4377 |
{ |
| 4378 |
const char *name; |
| 4379 |
int kind; |
| 4380 |
|
| 4381 |
if (c->ext.actual->next->expr != NULL) |
| 4382 |
kind = c->ext.actual->next->expr->ts.kind; |
| 4383 |
else |
| 4384 |
kind = gfc_default_integer_kind; |
| 4385 |
|
| 4386 |
name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind); |
| 4387 |
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
| 4388 |
} |