OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [fortran/] [iresolve.c] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.