14014a007a6237e242ecd5b63c18267672660890
[gcc.git] / gcc / fortran / intrinsic.c
1 /* Build up a list of intrinsic subroutines and functions for the
2 name-resolution stage.
3 Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation,
4 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 2, 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 COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 02111-1307, USA. */
23
24
25 #include "config.h"
26 #include "system.h"
27 #include "flags.h"
28
29 #include <stdio.h>
30 #include <stdarg.h>
31 #include <string.h>
32 #include <gmp.h>
33
34 #include "gfortran.h"
35 #include "intrinsic.h"
36
37
38 /* Nanespace to hold the resolved symbols for intrinsic subroutines. */
39 static gfc_namespace *gfc_intrinsic_namespace;
40
41 int gfc_init_expr = 0;
42
43 /* Pointers to a intrinsic function and its argument names being
44 checked. */
45
46 char *gfc_current_intrinsic, *gfc_current_intrinsic_arg[MAX_INTRINSIC_ARGS];
47 locus *gfc_current_intrinsic_where;
48
49 static gfc_intrinsic_sym *functions, *subroutines, *conversion, *next_sym;
50 static gfc_intrinsic_arg *next_arg;
51
52 static int nfunc, nsub, nargs, nconv;
53
54 static enum
55 { SZ_NOTHING = 0, SZ_SUBS, SZ_FUNCS, SZ_CONVS }
56 sizing;
57
58
59 /* Return a letter based on the passed type. Used to construct the
60 name of a type-dependent subroutine. */
61
62 char
63 gfc_type_letter (bt type)
64 {
65 char c;
66
67 switch (type)
68 {
69 case BT_LOGICAL:
70 c = 'l';
71 break;
72 case BT_CHARACTER:
73 c = 's';
74 break;
75 case BT_INTEGER:
76 c = 'i';
77 break;
78 case BT_REAL:
79 c = 'r';
80 break;
81 case BT_COMPLEX:
82 c = 'c';
83 break;
84
85 default:
86 c = 'u';
87 break;
88 }
89
90 return c;
91 }
92
93
94 /* Get a symbol for a resolved name. */
95
96 gfc_symbol *
97 gfc_get_intrinsic_sub_symbol (const char * name)
98 {
99 gfc_symbol *sym;
100
101 gfc_get_symbol (name, gfc_intrinsic_namespace, &sym);
102 sym->attr.always_explicit = 1;
103 sym->attr.subroutine = 1;
104 sym->attr.flavor = FL_PROCEDURE;
105 sym->attr.proc = PROC_INTRINSIC;
106
107 return sym;
108 }
109
110
111 /* Return a pointer to the name of a conversion function given two
112 typespecs. */
113
114 static char *
115 conv_name (gfc_typespec * from, gfc_typespec * to)
116 {
117 static char name[30];
118
119 sprintf (name, "__convert_%c%d_%c%d", gfc_type_letter (from->type),
120 from->kind, gfc_type_letter (to->type), to->kind);
121
122 return name;
123 }
124
125
126 /* Given a pair of typespecs, find the gfc_intrinsic_sym node that
127 corresponds to the conversion. Returns NULL if the conversion
128 isn't found. */
129
130 static gfc_intrinsic_sym *
131 find_conv (gfc_typespec * from, gfc_typespec * to)
132 {
133 gfc_intrinsic_sym *sym;
134 char *target;
135 int i;
136
137 target = conv_name (from, to);
138 sym = conversion;
139
140 for (i = 0; i < nconv; i++, sym++)
141 if (strcmp (target, sym->name) == 0)
142 return sym;
143
144 return NULL;
145 }
146
147
148 /* Interface to the check functions. We break apart an argument list
149 and call the proper check function rather than forcing each
150 function to manipulate the argument list. */
151
152 static try
153 do_check (gfc_intrinsic_sym * specific, gfc_actual_arglist * arg)
154 {
155 gfc_expr *a1, *a2, *a3, *a4, *a5;
156 try t;
157
158 a1 = arg->expr;
159 arg = arg->next;
160
161 if (arg == NULL)
162 t = (*specific->check.f1) (a1);
163 else
164 {
165 a2 = arg->expr;
166 arg = arg->next;
167
168 if (arg == NULL)
169 t = (*specific->check.f2) (a1, a2);
170 else
171 {
172 a3 = arg->expr;
173 arg = arg->next;
174
175 if (arg == NULL)
176 t = (*specific->check.f3) (a1, a2, a3);
177 else
178 {
179 a4 = arg->expr;
180 arg = arg->next;
181
182 if (arg == NULL)
183 t = (*specific->check.f4) (a1, a2, a3, a4);
184 else
185 {
186 a5 = arg->expr;
187 arg = arg->next;
188
189 if (arg == NULL)
190 t = (*specific->check.f5) (a1, a2, a3, a4, a5);
191 else
192 {
193 gfc_internal_error ("do_check(): too many args");
194 }
195 }
196 }
197 }
198 }
199
200 return t;
201 }
202
203
204 /*********** Subroutines to build the intrinsic list ****************/
205
206 /* Add a single intrinsic symbol to the current list.
207
208 Argument list:
209 char * name of function
210 int whether function is elemental
211 int If the function can be used as an actual argument
212 bt return type of function
213 int kind of return type of function
214 check pointer to check function
215 simplify pointer to simplification function
216 resolve pointer to resolution function
217
218 Optional arguments come in multiples of four:
219 char * name of argument
220 bt type of argument
221 int kind of argument
222 int arg optional flag (1=optional, 0=required)
223
224 The sequence is terminated by a NULL name.
225
226 TODO: Are checks on actual_ok implemented elsewhere, or is that just
227 missing here? */
228
229 static void
230 add_sym (const char *name, int elemental, int actual_ok ATTRIBUTE_UNUSED,
231 bt type, int kind, gfc_check_f check, gfc_simplify_f simplify,
232 gfc_resolve_f resolve, ...)
233 {
234
235 int optional, first_flag;
236 va_list argp;
237
238 switch (sizing)
239 {
240 case SZ_SUBS:
241 nsub++;
242 break;
243
244 case SZ_FUNCS:
245 nfunc++;
246 break;
247
248 case SZ_NOTHING:
249 strcpy (next_sym->name, name);
250
251 strcpy (next_sym->lib_name, "_gfortran_");
252 strcat (next_sym->lib_name, name);
253
254 next_sym->elemental = elemental;
255 next_sym->ts.type = type;
256 next_sym->ts.kind = kind;
257 next_sym->simplify = simplify;
258 next_sym->check = check;
259 next_sym->resolve = resolve;
260 next_sym->specific = 0;
261 next_sym->generic = 0;
262 break;
263
264 default:
265 gfc_internal_error ("add_sym(): Bad sizing mode");
266 }
267
268 va_start (argp, resolve);
269
270 first_flag = 1;
271
272 for (;;)
273 {
274 name = va_arg (argp, char *);
275 if (name == NULL)
276 break;
277
278 type = (bt) va_arg (argp, int);
279 kind = va_arg (argp, int);
280 optional = va_arg (argp, int);
281
282 if (sizing != SZ_NOTHING)
283 nargs++;
284 else
285 {
286 next_arg++;
287
288 if (first_flag)
289 next_sym->formal = next_arg;
290 else
291 (next_arg - 1)->next = next_arg;
292
293 first_flag = 0;
294
295 strcpy (next_arg->name, name);
296 next_arg->ts.type = type;
297 next_arg->ts.kind = kind;
298 next_arg->optional = optional;
299 }
300 }
301
302 va_end (argp);
303
304 next_sym++;
305 }
306
307
308 static void add_sym_0 (const char *name, int elemental, int actual_ok, bt type,
309 int kind,
310 try (*check)(gfc_expr *),
311 gfc_expr *(*simplify)(gfc_expr *),
312 void (*resolve)(gfc_expr *,gfc_expr *)
313 ) {
314 gfc_simplify_f sf;
315 gfc_check_f cf;
316 gfc_resolve_f rf;
317
318 cf.f1 = check;
319 sf.f1 = simplify;
320 rf.f1 = resolve;
321
322 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
323 (void*)0);
324 }
325
326
327 static void add_sym_1 (const char *name, int elemental, int actual_ok, bt type,
328 int kind,
329 try (*check)(gfc_expr *),
330 gfc_expr *(*simplify)(gfc_expr *),
331 void (*resolve)(gfc_expr *,gfc_expr *),
332 const char* a1, bt type1, int kind1, int optional1
333 ) {
334 gfc_check_f cf;
335 gfc_simplify_f sf;
336 gfc_resolve_f rf;
337
338 cf.f1 = check;
339 sf.f1 = simplify;
340 rf.f1 = resolve;
341
342 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
343 a1, type1, kind1, optional1,
344 (void*)0);
345 }
346
347
348 static void
349 add_sym_0s (const char * name, int actual_ok,
350 void (*resolve)(gfc_code *))
351 {
352 gfc_check_f cf;
353 gfc_simplify_f sf;
354 gfc_resolve_f rf;
355
356 cf.f1 = NULL;
357 sf.f1 = NULL;
358 rf.s1 = resolve;
359
360 add_sym (name, 1, actual_ok, BT_UNKNOWN, 0, cf, sf, rf,
361 (void*)0);
362 }
363
364
365 static void add_sym_1s (const char *name, int elemental, int actual_ok, bt type,
366 int kind,
367 try (*check)(gfc_expr *),
368 gfc_expr *(*simplify)(gfc_expr *),
369 void (*resolve)(gfc_code *),
370 const char* a1, bt type1, int kind1, int optional1
371 ) {
372 gfc_check_f cf;
373 gfc_simplify_f sf;
374 gfc_resolve_f rf;
375
376 cf.f1 = check;
377 sf.f1 = simplify;
378 rf.s1 = resolve;
379
380 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
381 a1, type1, kind1, optional1,
382 (void*)0);
383 }
384
385
386 static void add_sym_1m (const char *name, int elemental, int actual_ok, bt type,
387 int kind,
388 try (*check)(gfc_actual_arglist *),
389 gfc_expr *(*simplify)(gfc_expr *),
390 void (*resolve)(gfc_expr *,gfc_actual_arglist *),
391 const char* a1, bt type1, int kind1, int optional1,
392 const char* a2, bt type2, int kind2, int optional2
393 ) {
394 gfc_check_f cf;
395 gfc_simplify_f sf;
396 gfc_resolve_f rf;
397
398 cf.f1m = check;
399 sf.f1 = simplify;
400 rf.f1m = resolve;
401
402 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
403 a1, type1, kind1, optional1,
404 a2, type2, kind2, optional2,
405 (void*)0);
406 }
407
408
409 static void add_sym_2 (const char *name, int elemental, int actual_ok, bt type,
410 int kind,
411 try (*check)(gfc_expr *,gfc_expr *),
412 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *),
413 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *),
414 const char* a1, bt type1, int kind1, int optional1,
415 const char* a2, bt type2, int kind2, int optional2
416 ) {
417 gfc_check_f cf;
418 gfc_simplify_f sf;
419 gfc_resolve_f rf;
420
421 cf.f2 = check;
422 sf.f2 = simplify;
423 rf.f2 = resolve;
424
425 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
426 a1, type1, kind1, optional1,
427 a2, type2, kind2, optional2,
428 (void*)0);
429 }
430
431
432 /* Add the name of an intrinsic subroutine with two arguments to the list
433 of intrinsic names. */
434
435 static void add_sym_2s (const char *name, int elemental, int actual_ok, bt type,
436 int kind,
437 try (*check)(gfc_expr *,gfc_expr *),
438 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *),
439 void (*resolve)(gfc_code *),
440 const char* a1, bt type1, int kind1, int optional1,
441 const char* a2, bt type2, int kind2, int optional2
442 ) {
443 gfc_check_f cf;
444 gfc_simplify_f sf;
445 gfc_resolve_f rf;
446
447 cf.f2 = check;
448 sf.f2 = simplify;
449 rf.s1 = resolve;
450
451 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
452 a1, type1, kind1, optional1,
453 a2, type2, kind2, optional2,
454 (void*)0);
455 }
456
457
458 static void add_sym_3 (const char *name, int elemental, int actual_ok, bt type,
459 int kind,
460 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *),
461 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
462 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
463 const char* a1, bt type1, int kind1, int optional1,
464 const char* a2, bt type2, int kind2, int optional2,
465 const char* a3, bt type3, int kind3, int optional3
466 ) {
467 gfc_check_f cf;
468 gfc_simplify_f sf;
469 gfc_resolve_f rf;
470
471 cf.f3 = check;
472 sf.f3 = simplify;
473 rf.f3 = resolve;
474
475 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
476 a1, type1, kind1, optional1,
477 a2, type2, kind2, optional2,
478 a3, type3, kind3, optional3,
479 (void*)0);
480 }
481
482 /* MINLOC and MAXLOC get special treatment because their argument
483 might have to be reordered. */
484
485 static void add_sym_3ml (const char *name, int elemental,
486 int actual_ok, bt type, int kind,
487 try (*check)(gfc_actual_arglist *),
488 gfc_expr*(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
489 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
490 const char* a1, bt type1, int kind1, int optional1,
491 const char* a2, bt type2, int kind2, int optional2,
492 const char* a3, bt type3, int kind3, int optional3
493 ) {
494 gfc_check_f cf;
495 gfc_simplify_f sf;
496 gfc_resolve_f rf;
497
498 cf.f3ml = check;
499 sf.f3 = simplify;
500 rf.f3 = resolve;
501
502 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
503 a1, type1, kind1, optional1,
504 a2, type2, kind2, optional2,
505 a3, type3, kind3, optional3,
506 (void*)0);
507 }
508
509 /* Add the name of an intrinsic subroutine with three arguments to the list
510 of intrinsic names. */
511
512 static void add_sym_3s (const char *name, int elemental, int actual_ok, bt type,
513 int kind,
514 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *),
515 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
516 void (*resolve)(gfc_code *),
517 const char* a1, bt type1, int kind1, int optional1,
518 const char* a2, bt type2, int kind2, int optional2,
519 const char* a3, bt type3, int kind3, int optional3
520 ) {
521 gfc_check_f cf;
522 gfc_simplify_f sf;
523 gfc_resolve_f rf;
524
525 cf.f3 = check;
526 sf.f3 = simplify;
527 rf.s1 = resolve;
528
529 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
530 a1, type1, kind1, optional1,
531 a2, type2, kind2, optional2,
532 a3, type3, kind3, optional3,
533 (void*)0);
534 }
535
536
537 static void add_sym_4 (const char *name, int elemental, int actual_ok, bt type,
538 int kind,
539 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
540 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
541 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
542 const char* a1, bt type1, int kind1, int optional1,
543 const char* a2, bt type2, int kind2, int optional2,
544 const char* a3, bt type3, int kind3, int optional3,
545 const char* a4, bt type4, int kind4, int optional4
546 ) {
547 gfc_check_f cf;
548 gfc_simplify_f sf;
549 gfc_resolve_f rf;
550
551 cf.f4 = check;
552 sf.f4 = simplify;
553 rf.f4 = resolve;
554
555 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
556 a1, type1, kind1, optional1,
557 a2, type2, kind2, optional2,
558 a3, type3, kind3, optional3,
559 a4, type4, kind4, optional4,
560 (void*)0);
561 }
562
563
564 static void add_sym_4s (const char *name, int elemental, int actual_ok,
565 bt type, int kind,
566 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
567 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
568 void (*resolve)(gfc_code *),
569 const char* a1, bt type1, int kind1, int optional1,
570 const char* a2, bt type2, int kind2, int optional2,
571 const char* a3, bt type3, int kind3, int optional3,
572 const char* a4, bt type4, int kind4, int optional4)
573 {
574 gfc_check_f cf;
575 gfc_simplify_f sf;
576 gfc_resolve_f rf;
577
578 cf.f4 = check;
579 sf.f4 = simplify;
580 rf.s1 = resolve;
581
582 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
583 a1, type1, kind1, optional1,
584 a2, type2, kind2, optional2,
585 a3, type3, kind3, optional3,
586 a4, type4, kind4, optional4,
587 (void*)0);
588 }
589
590
591 static void add_sym_5 (const char *name, int elemental, int actual_ok, bt type,
592 int kind,
593 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
594 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
595 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
596 const char* a1, bt type1, int kind1, int optional1,
597 const char* a2, bt type2, int kind2, int optional2,
598 const char* a3, bt type3, int kind3, int optional3,
599 const char* a4, bt type4, int kind4, int optional4,
600 const char* a5, bt type5, int kind5, int optional5
601 ) {
602 gfc_check_f cf;
603 gfc_simplify_f sf;
604 gfc_resolve_f rf;
605
606 cf.f5 = check;
607 sf.f5 = simplify;
608 rf.f5 = resolve;
609
610 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
611 a1, type1, kind1, optional1,
612 a2, type2, kind2, optional2,
613 a3, type3, kind3, optional3,
614 a4, type4, kind4, optional4,
615 a5, type5, kind5, optional5,
616 (void*)0);
617 }
618
619
620 static void add_sym_5s
621 (
622 const char *name, int elemental, int actual_ok, bt type, int kind,
623 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
624 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
625 void (*resolve)(gfc_code *),
626 const char* a1, bt type1, int kind1, int optional1,
627 const char* a2, bt type2, int kind2, int optional2,
628 const char* a3, bt type3, int kind3, int optional3,
629 const char* a4, bt type4, int kind4, int optional4,
630 const char* a5, bt type5, int kind5, int optional5)
631 {
632 gfc_check_f cf;
633 gfc_simplify_f sf;
634 gfc_resolve_f rf;
635
636 cf.f5 = check;
637 sf.f5 = simplify;
638 rf.s1 = resolve;
639
640 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
641 a1, type1, kind1, optional1,
642 a2, type2, kind2, optional2,
643 a3, type3, kind3, optional3,
644 a4, type4, kind4, optional4,
645 a5, type5, kind5, optional5,
646 (void*)0);
647 }
648
649
650 /* Locate an intrinsic symbol given a base pointer, number of elements
651 in the table and a pointer to a name. Returns the NULL pointer if
652 a name is not found. */
653
654 static gfc_intrinsic_sym *
655 find_sym (gfc_intrinsic_sym * start, int n, const char *name)
656 {
657
658 while (n > 0)
659 {
660 if (strcmp (name, start->name) == 0)
661 return start;
662
663 start++;
664 n--;
665 }
666
667 return NULL;
668 }
669
670
671 /* Given a name, find a function in the intrinsic function table.
672 Returns NULL if not found. */
673
674 gfc_intrinsic_sym *
675 gfc_find_function (const char *name)
676 {
677
678 return find_sym (functions, nfunc, name);
679 }
680
681
682 /* Given a name, find a function in the intrinsic subroutine table.
683 Returns NULL if not found. */
684
685 static gfc_intrinsic_sym *
686 find_subroutine (const char *name)
687 {
688
689 return find_sym (subroutines, nsub, name);
690 }
691
692
693 /* Given a string, figure out if it is the name of a generic intrinsic
694 function or not. */
695
696 int
697 gfc_generic_intrinsic (const char *name)
698 {
699 gfc_intrinsic_sym *sym;
700
701 sym = gfc_find_function (name);
702 return (sym == NULL) ? 0 : sym->generic;
703 }
704
705
706 /* Given a string, figure out if it is the name of a specific
707 intrinsic function or not. */
708
709 int
710 gfc_specific_intrinsic (const char *name)
711 {
712 gfc_intrinsic_sym *sym;
713
714 sym = gfc_find_function (name);
715 return (sym == NULL) ? 0 : sym->specific;
716 }
717
718
719 /* Given a string, figure out if it is the name of an intrinsic
720 subroutine or function. There are no generic intrinsic
721 subroutines, they are all specific. */
722
723 int
724 gfc_intrinsic_name (const char *name, int subroutine_flag)
725 {
726
727 return subroutine_flag ?
728 find_subroutine (name) != NULL : gfc_find_function (name) != NULL;
729 }
730
731
732 /* Collect a set of intrinsic functions into a generic collection.
733 The first argument is the name of the generic function, which is
734 also the name of a specific function. The rest of the specifics
735 currently in the table are placed into the list of specific
736 functions associated with that generic. */
737
738 static void
739 make_generic (const char *name, gfc_generic_isym_id generic_id)
740 {
741 gfc_intrinsic_sym *g;
742
743 if (sizing != SZ_NOTHING)
744 return;
745
746 g = gfc_find_function (name);
747 if (g == NULL)
748 gfc_internal_error ("make_generic(): Can't find generic symbol '%s'",
749 name);
750
751 g->generic = 1;
752 g->specific = 1;
753 g->generic_id = generic_id;
754 if ((g + 1)->name[0] != '\0')
755 g->specific_head = g + 1;
756 g++;
757
758 while (g->name[0] != '\0')
759 {
760 g->next = g + 1;
761 g->specific = 1;
762 g->generic_id = generic_id;
763 g++;
764 }
765
766 g--;
767 g->next = NULL;
768 }
769
770
771 /* Create a duplicate intrinsic function entry for the current
772 function, the only difference being the alternate name. Note that
773 we use argument lists more than once, but all argument lists are
774 freed as a single block. */
775
776 static void
777 make_alias (const char *name)
778 {
779
780 switch (sizing)
781 {
782 case SZ_FUNCS:
783 nfunc++;
784 break;
785
786 case SZ_SUBS:
787 nsub++;
788 break;
789
790 case SZ_NOTHING:
791 next_sym[0] = next_sym[-1];
792 strcpy (next_sym->name, name);
793 next_sym++;
794 break;
795
796 default:
797 break;
798 }
799 }
800
801
802 /* Add intrinsic functions. */
803
804 static void
805 add_functions (void)
806 {
807
808 /* Argument names as in the standard (to be used as argument keywords). */
809 const char
810 *a = "a", *f = "field", *pt = "pointer", *tg = "target",
811 *b = "b", *m = "matrix", *ma = "matrix_a", *mb = "matrix_b",
812 *c = "c", *n = "ncopies", *pos = "pos", *bck = "back",
813 *i = "i", *v = "vector", *va = "vector_a", *vb = "vector_b",
814 *j = "j", *a1 = "a1", *fs = "fsource", *ts = "tsource",
815 *l = "l", *a2 = "a2", *mo = "mold", *ord = "order",
816 *p = "p", *ar = "array", *shp = "shape", *src = "source",
817 *r = "r", *bd = "boundary", *pad = "pad", *set = "set",
818 *s = "s", *dm = "dim", *kind = "kind", *msk = "mask",
819 *x = "x", *sh = "shift", *stg = "string", *ssg = "substring",
820 *y = "y", *sz = "size", *sta = "string_a", *stb = "string_b",
821 *z = "z", *ln = "len";
822
823 int di, dr, dd, dl, dc, dz, ii;
824
825 di = gfc_default_integer_kind ();
826 dr = gfc_default_real_kind ();
827 dd = gfc_default_double_kind ();
828 dl = gfc_default_logical_kind ();
829 dc = gfc_default_character_kind ();
830 dz = gfc_default_complex_kind ();
831 ii = gfc_index_integer_kind;
832
833 add_sym_1 ("abs", 1, 1, BT_REAL, dr,
834 gfc_check_abs, gfc_simplify_abs, gfc_resolve_abs,
835 a, BT_REAL, dr, 0);
836
837 add_sym_1 ("iabs", 1, 1, BT_INTEGER, di,
838 NULL, gfc_simplify_abs, gfc_resolve_abs,
839 a, BT_INTEGER, di, 0);
840
841 add_sym_1 ("dabs", 1, 1, BT_REAL, dd,
842 NULL, gfc_simplify_abs, gfc_resolve_abs, a, BT_REAL, dd, 0);
843
844 add_sym_1 ("cabs", 1, 1, BT_REAL, dr,
845 NULL, gfc_simplify_abs, gfc_resolve_abs,
846 a, BT_COMPLEX, dz, 0);
847
848 add_sym_1 ("zabs", 1, 1, BT_REAL, dd, NULL, gfc_simplify_abs, gfc_resolve_abs, a, BT_COMPLEX, dd, 0); /* Extension */
849
850 make_alias ("cdabs");
851
852 make_generic ("abs", GFC_ISYM_ABS);
853
854 add_sym_1 ("achar", 1, 1, BT_CHARACTER, dc,
855 NULL, gfc_simplify_achar, NULL, i, BT_INTEGER, di, 0);
856
857 make_generic ("achar", GFC_ISYM_ACHAR);
858
859 add_sym_1 ("acos", 1, 1, BT_REAL, dr,
860 NULL, gfc_simplify_acos, gfc_resolve_acos,
861 x, BT_REAL, dr, 0);
862
863 add_sym_1 ("dacos", 1, 1, BT_REAL, dd,
864 NULL, gfc_simplify_acos, gfc_resolve_acos,
865 x, BT_REAL, dd, 0);
866
867 make_generic ("acos", GFC_ISYM_ACOS);
868
869 add_sym_1 ("adjustl", 1, 1, BT_CHARACTER, dc,
870 NULL, gfc_simplify_adjustl, NULL, stg, BT_CHARACTER, dc, 0);
871
872 make_generic ("adjustl", GFC_ISYM_ADJUSTL);
873
874 add_sym_1 ("adjustr", 1, 1, BT_CHARACTER, dc,
875 NULL, gfc_simplify_adjustr, NULL, stg, BT_CHARACTER, dc, 0);
876
877 make_generic ("adjustr", GFC_ISYM_ADJUSTR);
878
879 add_sym_1 ("aimag", 1, 1, BT_REAL, dr,
880 NULL, gfc_simplify_aimag, gfc_resolve_aimag,
881 z, BT_COMPLEX, dz, 0);
882
883 add_sym_1 ("dimag", 1, 1, BT_REAL, dd, NULL, gfc_simplify_aimag, gfc_resolve_aimag, z, BT_COMPLEX, dd, 0); /* Extension */
884
885 make_generic ("aimag", GFC_ISYM_AIMAG);
886
887 add_sym_2 ("aint", 1, 1, BT_REAL, dr,
888 gfc_check_a_xkind, gfc_simplify_aint, gfc_resolve_aint,
889 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
890
891 add_sym_1 ("dint", 1, 1, BT_REAL, dd,
892 NULL, gfc_simplify_dint, gfc_resolve_dint,
893 a, BT_REAL, dd, 0);
894
895 make_generic ("aint", GFC_ISYM_AINT);
896
897 add_sym_2 ("all", 0, 1, BT_UNKNOWN, 0,
898 gfc_check_all_any, NULL, gfc_resolve_all,
899 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
900
901 make_generic ("all", GFC_ISYM_ALL);
902
903 add_sym_1 ("allocated", 0, 1, BT_LOGICAL, dl,
904 gfc_check_allocated, NULL, NULL, ar, BT_UNKNOWN, 0, 0);
905
906 make_generic ("allocated", GFC_ISYM_ALLOCATED);
907
908 add_sym_2 ("anint", 1, 1, BT_REAL, dr,
909 gfc_check_a_xkind, gfc_simplify_anint, gfc_resolve_anint,
910 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
911
912 add_sym_1 ("dnint", 1, 1, BT_REAL, dd,
913 NULL, gfc_simplify_dnint, gfc_resolve_dnint,
914 a, BT_REAL, dd, 0);
915
916 make_generic ("anint", GFC_ISYM_ANINT);
917
918 add_sym_2 ("any", 0, 1, BT_UNKNOWN, 0,
919 gfc_check_all_any, NULL, gfc_resolve_any,
920 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
921
922 make_generic ("any", GFC_ISYM_ANY);
923
924 add_sym_1 ("asin", 1, 1, BT_REAL, dr,
925 NULL, gfc_simplify_asin, gfc_resolve_asin,
926 x, BT_REAL, dr, 0);
927
928 add_sym_1 ("dasin", 1, 1, BT_REAL, dd,
929 NULL, gfc_simplify_asin, gfc_resolve_asin,
930 x, BT_REAL, dd, 0);
931
932 make_generic ("asin", GFC_ISYM_ASIN);
933
934 add_sym_2 ("associated", 0, 1, BT_LOGICAL, dl,
935 gfc_check_associated, NULL, NULL,
936 pt, BT_UNKNOWN, 0, 0, tg, BT_UNKNOWN, 0, 1);
937
938 make_generic ("associated", GFC_ISYM_ASSOCIATED);
939
940 add_sym_1 ("atan", 1, 1, BT_REAL, dr,
941 NULL, gfc_simplify_atan, gfc_resolve_atan,
942 x, BT_REAL, dr, 0);
943
944 add_sym_1 ("datan", 1, 1, BT_REAL, dd,
945 NULL, gfc_simplify_atan, gfc_resolve_atan,
946 x, BT_REAL, dd, 0);
947
948 make_generic ("atan", GFC_ISYM_ATAN);
949
950 add_sym_2 ("atan2", 1, 1, BT_REAL, dr,
951 NULL, gfc_simplify_atan2, gfc_resolve_atan2,
952 y, BT_REAL, dr, 0, x, BT_REAL, dr, 0);
953
954 add_sym_2 ("datan2", 1, 1, BT_REAL, dd,
955 NULL, gfc_simplify_atan2, gfc_resolve_atan2,
956 y, BT_REAL, dd, 0, x, BT_REAL, dd, 0);
957
958 make_generic ("atan2", GFC_ISYM_ATAN2);
959
960 add_sym_1 ("bit_size", 0, 1, BT_INTEGER, di,
961 gfc_check_i, gfc_simplify_bit_size, NULL,
962 i, BT_INTEGER, di, 0);
963
964 make_generic ("bit_size", GFC_ISYM_NONE);
965
966 add_sym_2 ("btest", 1, 1, BT_LOGICAL, dl,
967 gfc_check_btest, gfc_simplify_btest, gfc_resolve_btest,
968 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
969
970 make_generic ("btest", GFC_ISYM_BTEST);
971
972 add_sym_2 ("ceiling", 1, 1, BT_INTEGER, di,
973 gfc_check_a_ikind, gfc_simplify_ceiling, gfc_resolve_ceiling,
974 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
975
976 make_generic ("ceiling", GFC_ISYM_CEILING);
977
978 add_sym_2 ("char", 1, 0, BT_CHARACTER, dc,
979 gfc_check_char, gfc_simplify_char, gfc_resolve_char,
980 i, BT_INTEGER, di, 0, kind, BT_INTEGER, di, 1);
981
982 make_generic ("char", GFC_ISYM_CHAR);
983
984 add_sym_3 ("cmplx", 1, 1, BT_COMPLEX, dz,
985 gfc_check_cmplx, gfc_simplify_cmplx, gfc_resolve_cmplx,
986 x, BT_UNKNOWN, dr, 0, y, BT_UNKNOWN, dr, 1,
987 kind, BT_INTEGER, di, 1);
988
989 make_generic ("cmplx", GFC_ISYM_CMPLX);
990
991 /* Making dcmplx a specific of cmplx causes cmplx to return a double
992 complex instead of the default complex. */
993
994 add_sym_2 ("dcmplx", 1, 1, BT_COMPLEX, dd,
995 gfc_check_dcmplx, gfc_simplify_dcmplx, gfc_resolve_dcmplx,
996 x, BT_REAL, dd, 0, y, BT_REAL, dd, 1); /* Extension */
997
998 make_generic ("dcmplx", GFC_ISYM_CMPLX);
999
1000 add_sym_1 ("conjg", 1, 1, BT_COMPLEX, dz,
1001 NULL, gfc_simplify_conjg, gfc_resolve_conjg,
1002 z, BT_COMPLEX, dz, 0);
1003
1004 add_sym_1 ("dconjg", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_conjg, gfc_resolve_conjg, z, BT_COMPLEX, dd, 0); /* Extension */
1005
1006 make_generic ("conjg", GFC_ISYM_CONJG);
1007
1008 add_sym_1 ("cos", 1, 1, BT_REAL, dr,
1009 NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_REAL, dr, 0);
1010
1011 add_sym_1 ("dcos", 1, 1, BT_REAL, dd,
1012 NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_REAL, dd, 0);
1013
1014 add_sym_1 ("ccos", 1, 1, BT_COMPLEX, dz,
1015 NULL, gfc_simplify_cos, gfc_resolve_cos,
1016 x, BT_COMPLEX, dz, 0);
1017
1018 add_sym_1 ("zcos", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_COMPLEX, dd, 0); /* Extension */
1019
1020 make_alias ("cdcos");
1021
1022 make_generic ("cos", GFC_ISYM_COS);
1023
1024 add_sym_1 ("cosh", 1, 1, BT_REAL, dr,
1025 NULL, gfc_simplify_cosh, gfc_resolve_cosh,
1026 x, BT_REAL, dr, 0);
1027
1028 add_sym_1 ("dcosh", 1, 1, BT_REAL, dd,
1029 NULL, gfc_simplify_cosh, gfc_resolve_cosh,
1030 x, BT_REAL, dd, 0);
1031
1032 make_generic ("cosh", GFC_ISYM_COSH);
1033
1034 add_sym_2 ("count", 0, 1, BT_INTEGER, di,
1035 gfc_check_count, NULL, gfc_resolve_count,
1036 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
1037
1038 make_generic ("count", GFC_ISYM_COUNT);
1039
1040 add_sym_3 ("cshift", 0, 1, BT_REAL, dr,
1041 gfc_check_cshift, NULL, gfc_resolve_cshift,
1042 ar, BT_REAL, dr, 0, sh, BT_INTEGER, di, 0,
1043 dm, BT_INTEGER, ii, 1);
1044
1045 make_generic ("cshift", GFC_ISYM_CSHIFT);
1046
1047 add_sym_1 ("dble", 1, 1, BT_REAL, dd,
1048 gfc_check_dble, gfc_simplify_dble, gfc_resolve_dble,
1049 a, BT_REAL, dr, 0);
1050
1051 make_alias ("dfloat");
1052
1053 make_generic ("dble", GFC_ISYM_DBLE);
1054
1055 add_sym_1 ("digits", 0, 1, BT_INTEGER, di,
1056 gfc_check_digits, gfc_simplify_digits, NULL,
1057 x, BT_UNKNOWN, dr, 0);
1058
1059 make_generic ("digits", GFC_ISYM_NONE);
1060
1061 add_sym_2 ("dim", 1, 1, BT_REAL, dr,
1062 gfc_check_a_p, gfc_simplify_dim, gfc_resolve_dim,
1063 x, BT_UNKNOWN, dr, 0, y, BT_UNKNOWN, dr, 0);
1064
1065 add_sym_2 ("idim", 1, 1, BT_INTEGER, di,
1066 NULL, gfc_simplify_dim, gfc_resolve_dim,
1067 x, BT_INTEGER, di, 0, y, BT_INTEGER, di, 0);
1068
1069 add_sym_2 ("ddim", 1, 1, BT_REAL, dd,
1070 NULL, gfc_simplify_dim, gfc_resolve_dim,
1071 x, BT_REAL, dd, 0, y, BT_REAL, dd, 0);
1072
1073 make_generic ("dim", GFC_ISYM_DIM);
1074
1075 add_sym_2 ("dot_product", 0, 1, BT_UNKNOWN, 0,
1076 gfc_check_dot_product, NULL, gfc_resolve_dot_product,
1077 va, BT_REAL, dr, 0, vb, BT_REAL, dr, 0);
1078
1079 make_generic ("dot_product", GFC_ISYM_DOT_PRODUCT);
1080
1081 add_sym_2 ("dprod", 1, 1, BT_REAL, dd,
1082 NULL, gfc_simplify_dprod, gfc_resolve_dprod,
1083 x, BT_REAL, dr, 0, y, BT_REAL, dr, 0);
1084
1085 make_generic ("dprod", GFC_ISYM_DPROD);
1086
1087 add_sym_1 ("dreal", 1, 0, BT_REAL, dd, NULL, NULL, NULL, a, BT_COMPLEX, dd, 0); /* Extension */
1088
1089 make_generic ("dreal", GFC_ISYM_REAL);
1090
1091 add_sym_4 ("eoshift", 0, 1, BT_REAL, dr,
1092 gfc_check_eoshift, NULL, gfc_resolve_eoshift,
1093 ar, BT_REAL, dr, 0, sh, BT_INTEGER, ii, 0,
1094 bd, BT_REAL, dr, 1, dm, BT_INTEGER, ii, 1);
1095
1096 make_generic ("eoshift", GFC_ISYM_EOSHIFT);
1097
1098 add_sym_1 ("epsilon", 0, 1, BT_REAL, dr,
1099 gfc_check_x, gfc_simplify_epsilon, NULL,
1100 x, BT_REAL, dr, 0);
1101
1102 make_generic ("epsilon", GFC_ISYM_NONE);
1103
1104 /* G77 compatibility */
1105 add_sym_1 ("etime", 0, 1, BT_REAL, 4,
1106 gfc_check_etime, NULL, NULL,
1107 x, BT_REAL, 4, 0);
1108
1109 make_alias ("dtime");
1110
1111 make_generic ("etime", GFC_ISYM_ETIME);
1112
1113
1114 add_sym_1 ("exp", 1, 1, BT_REAL, dr,
1115 NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_REAL, dr, 0);
1116
1117 add_sym_1 ("dexp", 1, 1, BT_REAL, dd,
1118 NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_REAL, dd, 0);
1119
1120 add_sym_1 ("cexp", 1, 1, BT_COMPLEX, dz,
1121 NULL, gfc_simplify_exp, gfc_resolve_exp,
1122 x, BT_COMPLEX, dz, 0);
1123
1124 add_sym_1 ("zexp", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_COMPLEX, dd, 0); /* Extension */
1125
1126 make_alias ("cdexp");
1127
1128 make_generic ("exp", GFC_ISYM_EXP);
1129
1130 add_sym_1 ("exponent", 1, 1, BT_INTEGER, di,
1131 gfc_check_x, gfc_simplify_exponent, gfc_resolve_exponent,
1132 x, BT_REAL, dr, 0);
1133
1134 make_generic ("exponent", GFC_ISYM_EXPONENT);
1135
1136 add_sym_2 ("floor", 1, 1, BT_INTEGER, di,
1137 gfc_check_a_ikind, gfc_simplify_floor, gfc_resolve_floor,
1138 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1139
1140 make_generic ("floor", GFC_ISYM_FLOOR);
1141
1142 add_sym_1 ("fraction", 1, 1, BT_REAL, dr,
1143 gfc_check_x, gfc_simplify_fraction, gfc_resolve_fraction,
1144 x, BT_REAL, dr, 0);
1145
1146 make_generic ("fraction", GFC_ISYM_FRACTION);
1147
1148 add_sym_1 ("huge", 0, 1, BT_REAL, dr,
1149 gfc_check_huge, gfc_simplify_huge, NULL,
1150 x, BT_UNKNOWN, dr, 0);
1151
1152 make_generic ("huge", GFC_ISYM_NONE);
1153
1154 add_sym_1 ("iachar", 1, 1, BT_INTEGER, di,
1155 NULL, gfc_simplify_iachar, NULL, c, BT_CHARACTER, dc, 0);
1156
1157 make_generic ("iachar", GFC_ISYM_IACHAR);
1158
1159 add_sym_2 ("iand", 1, 1, BT_INTEGER, di,
1160 gfc_check_iand, gfc_simplify_iand, gfc_resolve_iand,
1161 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1162
1163 make_generic ("iand", GFC_ISYM_IAND);
1164
1165 add_sym_0 ("iargc", 1, 1, BT_INTEGER, di, NULL, NULL, NULL); /* Extension, takes no arguments */
1166 make_generic ("iargc", GFC_ISYM_IARGC);
1167
1168 add_sym_0 ("command_argument_count", 1, 1, BT_INTEGER, di, NULL, NULL, NULL);
1169 make_generic ("command_argument_count", GFC_ISYM_COMMAND_ARGUMENT_COUNT);
1170
1171 add_sym_2 ("ibclr", 1, 1, BT_INTEGER, di,
1172 gfc_check_ibclr, gfc_simplify_ibclr, gfc_resolve_ibclr,
1173 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1174
1175 make_generic ("ibclr", GFC_ISYM_IBCLR);
1176
1177 add_sym_3 ("ibits", 1, 1, BT_INTEGER, di,
1178 gfc_check_ibits, gfc_simplify_ibits, gfc_resolve_ibits,
1179 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0,
1180 ln, BT_INTEGER, di, 0);
1181
1182 make_generic ("ibits", GFC_ISYM_IBITS);
1183
1184 add_sym_2 ("ibset", 1, 1, BT_INTEGER, di,
1185 gfc_check_ibset, gfc_simplify_ibset, gfc_resolve_ibset,
1186 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1187
1188 make_generic ("ibset", GFC_ISYM_IBSET);
1189
1190 add_sym_1 ("ichar", 1, 0, BT_INTEGER, di,
1191 NULL, gfc_simplify_ichar, gfc_resolve_ichar,
1192 c, BT_CHARACTER, dc, 0);
1193
1194 make_generic ("ichar", GFC_ISYM_ICHAR);
1195
1196 add_sym_2 ("ieor", 1, 1, BT_INTEGER, di,
1197 gfc_check_ieor, gfc_simplify_ieor, gfc_resolve_ieor,
1198 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1199
1200 make_generic ("ieor", GFC_ISYM_IEOR);
1201
1202 add_sym_3 ("index", 1, 1, BT_INTEGER, di,
1203 gfc_check_index, gfc_simplify_index, NULL,
1204 stg, BT_CHARACTER, dc, 0, ssg, BT_CHARACTER, dc, 0,
1205 bck, BT_LOGICAL, dl, 1);
1206
1207 make_generic ("index", GFC_ISYM_INDEX);
1208
1209 add_sym_2 ("int", 1, 1, BT_INTEGER, di,
1210 gfc_check_int, gfc_simplify_int, gfc_resolve_int,
1211 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1212
1213 add_sym_1 ("ifix", 1, 0, BT_INTEGER, di,
1214 NULL, gfc_simplify_ifix, NULL, a, BT_REAL, dr, 0);
1215
1216 add_sym_1 ("idint", 1, 0, BT_INTEGER, di,
1217 NULL, gfc_simplify_idint, NULL, a, BT_REAL, dd, 0);
1218
1219 make_generic ("int", GFC_ISYM_INT);
1220
1221 add_sym_2 ("ior", 1, 1, BT_INTEGER, di,
1222 gfc_check_ior, gfc_simplify_ior, gfc_resolve_ior,
1223 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1224
1225 make_generic ("ior", GFC_ISYM_IOR);
1226
1227 /* The following function is for G77 compatibility. */
1228 add_sym_1 ("irand", 0, 1, BT_INTEGER, 4,
1229 gfc_check_irand, NULL, NULL,
1230 i, BT_INTEGER, 4, 0);
1231
1232 make_generic ("irand", GFC_ISYM_IRAND);
1233
1234 add_sym_2 ("ishft", 1, 1, BT_INTEGER, di,
1235 gfc_check_ishft, gfc_simplify_ishft, gfc_resolve_ishft,
1236 i, BT_INTEGER, di, 0, sh, BT_INTEGER, di, 0);
1237
1238 make_generic ("ishft", GFC_ISYM_ISHFT);
1239
1240 add_sym_3 ("ishftc", 1, 1, BT_INTEGER, di,
1241 gfc_check_ishftc, gfc_simplify_ishftc, gfc_resolve_ishftc,
1242 i, BT_INTEGER, di, 0, sh, BT_INTEGER, di, 0,
1243 sz, BT_INTEGER, di, 1);
1244
1245 make_generic ("ishftc", GFC_ISYM_ISHFTC);
1246
1247 add_sym_1 ("kind", 0, 1, BT_INTEGER, di,
1248 gfc_check_kind, gfc_simplify_kind, NULL, x, BT_REAL, dr, 0);
1249
1250 make_generic ("kind", GFC_ISYM_NONE);
1251
1252 add_sym_2 ("lbound", 0, 1, BT_INTEGER, di,
1253 gfc_check_lbound, gfc_simplify_lbound, gfc_resolve_lbound,
1254 ar, BT_REAL, dr, 0, dm, BT_INTEGER, di, 1);
1255
1256 make_generic ("lbound", GFC_ISYM_LBOUND);
1257
1258 add_sym_1 ("len", 0, 1, BT_INTEGER, di,
1259 NULL, gfc_simplify_len, gfc_resolve_len,
1260 stg, BT_CHARACTER, dc, 0);
1261
1262 make_generic ("len", GFC_ISYM_LEN);
1263
1264 add_sym_1 ("len_trim", 1, 1, BT_INTEGER, di,
1265 NULL, gfc_simplify_len_trim, gfc_resolve_len_trim,
1266 stg, BT_CHARACTER, dc, 0);
1267
1268 make_generic ("len_trim", GFC_ISYM_LEN_TRIM);
1269
1270 add_sym_2 ("lge", 1, 0, BT_LOGICAL, dl,
1271 NULL, gfc_simplify_lge, NULL,
1272 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1273
1274 make_generic ("lge", GFC_ISYM_LGE);
1275
1276 add_sym_2 ("lgt", 1, 0, BT_LOGICAL, dl,
1277 NULL, gfc_simplify_lgt, NULL,
1278 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1279
1280 make_generic ("lgt", GFC_ISYM_LGT);
1281
1282 add_sym_2 ("lle", 1, 0, BT_LOGICAL, dl,
1283 NULL, gfc_simplify_lle, NULL,
1284 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1285
1286 make_generic ("lle", GFC_ISYM_LLE);
1287
1288 add_sym_2 ("llt", 1, 0, BT_LOGICAL, dl,
1289 NULL, gfc_simplify_llt, NULL,
1290 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1291
1292 make_generic ("llt", GFC_ISYM_LLT);
1293
1294 add_sym_1 ("log", 1, 1, BT_REAL, dr,
1295 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dr, 0);
1296
1297 add_sym_1 ("alog", 1, 1, BT_REAL, dr,
1298 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dr, 0);
1299
1300 add_sym_1 ("dlog", 1, 1, BT_REAL, dd,
1301 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dd, 0);
1302
1303 add_sym_1 ("clog", 1, 1, BT_COMPLEX, dz,
1304 NULL, gfc_simplify_log, gfc_resolve_log,
1305 x, BT_COMPLEX, dz, 0);
1306
1307 add_sym_1 ("zlog", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_log, gfc_resolve_log, x, BT_COMPLEX, dd, 0); /* Extension */
1308
1309 make_alias ("cdlog");
1310
1311 make_generic ("log", GFC_ISYM_LOG);
1312
1313 add_sym_1 ("log10", 1, 1, BT_REAL, dr,
1314 NULL, gfc_simplify_log10, gfc_resolve_log10,
1315 x, BT_REAL, dr, 0);
1316
1317 add_sym_1 ("alog10", 1, 1, BT_REAL, dr,
1318 NULL, gfc_simplify_log10, gfc_resolve_log10,
1319 x, BT_REAL, dr, 0);
1320
1321 add_sym_1 ("dlog10", 1, 1, BT_REAL, dd,
1322 NULL, gfc_simplify_log10, gfc_resolve_log10,
1323 x, BT_REAL, dd, 0);
1324
1325 make_generic ("log10", GFC_ISYM_LOG10);
1326
1327 add_sym_2 ("logical", 0, 1, BT_LOGICAL, dl,
1328 gfc_check_logical, gfc_simplify_logical, gfc_resolve_logical,
1329 l, BT_LOGICAL, dl, 0, kind, BT_INTEGER, di, 1);
1330
1331 make_generic ("logical", GFC_ISYM_LOGICAL);
1332
1333 add_sym_2 ("matmul", 0, 1, BT_REAL, dr,
1334 gfc_check_matmul, NULL, gfc_resolve_matmul,
1335 ma, BT_REAL, dr, 0, mb, BT_REAL, dr, 0);
1336
1337 make_generic ("matmul", GFC_ISYM_MATMUL);
1338
1339 /* Note: amax0 is equivalent to real(max), max1 is equivalent to
1340 int(max). The max function must take at least two arguments. */
1341
1342 add_sym_1m ("max", 1, 0, BT_UNKNOWN, 0,
1343 gfc_check_min_max, gfc_simplify_max, gfc_resolve_max,
1344 a1, BT_UNKNOWN, dr, 0, a2, BT_UNKNOWN, dr, 0);
1345
1346 add_sym_1m ("max0", 1, 0, BT_INTEGER, di,
1347 gfc_check_min_max_integer, gfc_simplify_max, NULL,
1348 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1349
1350 add_sym_1m ("amax0", 1, 0, BT_REAL, dr,
1351 gfc_check_min_max_integer, gfc_simplify_max, NULL,
1352 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1353
1354 add_sym_1m ("amax1", 1, 0, BT_REAL, dr,
1355 gfc_check_min_max_real, gfc_simplify_max, NULL,
1356 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1357
1358 add_sym_1m ("max1", 1, 0, BT_INTEGER, di,
1359 gfc_check_min_max_real, gfc_simplify_max, NULL,
1360 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1361
1362 add_sym_1m ("dmax1", 1, 0, BT_REAL, dd,
1363 gfc_check_min_max_double, gfc_simplify_max, NULL,
1364 a1, BT_REAL, dd, 0, a2, BT_REAL, dd, 0);
1365
1366 make_generic ("max", GFC_ISYM_MAX);
1367
1368 add_sym_1 ("maxexponent", 0, 1, BT_INTEGER, di,
1369 gfc_check_x, gfc_simplify_maxexponent, NULL,
1370 x, BT_UNKNOWN, dr, 0);
1371
1372 make_generic ("maxexponent", GFC_ISYM_NONE);
1373
1374 add_sym_3ml ("maxloc", 0, 1, BT_INTEGER, di,
1375 gfc_check_minloc_maxloc, NULL, gfc_resolve_maxloc,
1376 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1377 msk, BT_LOGICAL, dl, 1);
1378
1379 make_generic ("maxloc", GFC_ISYM_MAXLOC);
1380
1381 add_sym_3 ("maxval", 0, 1, BT_REAL, dr,
1382 gfc_check_minval_maxval, NULL, gfc_resolve_maxval,
1383 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1384 msk, BT_LOGICAL, dl, 1);
1385
1386 make_generic ("maxval", GFC_ISYM_MAXVAL);
1387
1388 add_sym_3 ("merge", 1, 1, BT_REAL, dr,
1389 gfc_check_merge, NULL, gfc_resolve_merge,
1390 ts, BT_REAL, dr, 0, fs, BT_REAL, dr, 0,
1391 msk, BT_LOGICAL, dl, 0);
1392
1393 make_generic ("merge", GFC_ISYM_MERGE);
1394
1395 /* Note: amin0 is equivalent to real(min), min1 is equivalent to int(min). */
1396
1397 add_sym_1m ("min", 1, 0, BT_UNKNOWN, 0,
1398 gfc_check_min_max, gfc_simplify_min, gfc_resolve_min,
1399 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1400
1401 add_sym_1m ("min0", 1, 0, BT_INTEGER, di,
1402 gfc_check_min_max_integer, gfc_simplify_min, NULL,
1403 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1404
1405 add_sym_1m ("amin0", 1, 0, BT_REAL, dr,
1406 gfc_check_min_max_integer, gfc_simplify_min, NULL,
1407 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1408
1409 add_sym_1m ("amin1", 1, 0, BT_REAL, dr,
1410 gfc_check_min_max_real, gfc_simplify_min, NULL,
1411 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1412
1413 add_sym_1m ("min1", 1, 0, BT_INTEGER, di,
1414 gfc_check_min_max_real, gfc_simplify_min, NULL,
1415 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1416
1417 add_sym_1m ("dmin1", 1, 0, BT_REAL, dd,
1418 gfc_check_min_max_double, gfc_simplify_min, NULL,
1419 a1, BT_REAL, dd, 0, a2, BT_REAL, dd, 0);
1420
1421 make_generic ("min", GFC_ISYM_MIN);
1422
1423 add_sym_1 ("minexponent", 0, 1, BT_INTEGER, di,
1424 gfc_check_x, gfc_simplify_minexponent, NULL,
1425 x, BT_UNKNOWN, dr, 0);
1426
1427 make_generic ("minexponent", GFC_ISYM_NONE);
1428
1429 add_sym_3ml ("minloc", 0, 1, BT_INTEGER, di,
1430 gfc_check_minloc_maxloc, NULL, gfc_resolve_minloc,
1431 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1432 msk, BT_LOGICAL, dl, 1);
1433
1434 make_generic ("minloc", GFC_ISYM_MINLOC);
1435
1436 add_sym_3 ("minval", 0, 1, BT_REAL, dr,
1437 gfc_check_minval_maxval, NULL, gfc_resolve_minval,
1438 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1439 msk, BT_LOGICAL, dl, 1);
1440
1441 make_generic ("minval", GFC_ISYM_MINVAL);
1442
1443 add_sym_2 ("mod", 1, 1, BT_INTEGER, di,
1444 gfc_check_a_p, gfc_simplify_mod, gfc_resolve_mod,
1445 a, BT_INTEGER, di, 0, p, BT_INTEGER, di, 0);
1446
1447 add_sym_2 ("amod", 1, 1, BT_REAL, dr,
1448 NULL, gfc_simplify_mod, gfc_resolve_mod,
1449 a, BT_REAL, dr, 0, p, BT_REAL, dr, 0);
1450
1451 add_sym_2 ("dmod", 1, 1, BT_REAL, dd,
1452 NULL, gfc_simplify_mod, gfc_resolve_mod,
1453 a, BT_REAL, dd, 0, p, BT_REAL, dd, 0);
1454
1455 make_generic ("mod", GFC_ISYM_MOD);
1456
1457 add_sym_2 ("modulo", 1, 1, BT_REAL, di,
1458 gfc_check_a_p, gfc_simplify_modulo, gfc_resolve_modulo,
1459 a, BT_REAL, di, 0, p, BT_REAL, di, 0);
1460
1461 make_generic ("modulo", GFC_ISYM_MODULO);
1462
1463 add_sym_2 ("nearest", 1, 1, BT_REAL, dr,
1464 gfc_check_nearest, gfc_simplify_nearest, gfc_resolve_nearest,
1465 x, BT_REAL, dr, 0, s, BT_REAL, dr, 0);
1466
1467 make_generic ("nearest", GFC_ISYM_NEAREST);
1468
1469 add_sym_2 ("nint", 1, 1, BT_INTEGER, di,
1470 gfc_check_a_ikind, gfc_simplify_nint, gfc_resolve_nint,
1471 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1472
1473 add_sym_1 ("idnint", 1, 1, BT_INTEGER, di,
1474 gfc_check_idnint, gfc_simplify_idnint, gfc_resolve_idnint,
1475 a, BT_REAL, dd, 0);
1476
1477 make_generic ("nint", GFC_ISYM_NINT);
1478
1479 add_sym_1 ("not", 1, 1, BT_INTEGER, di,
1480 gfc_check_i, gfc_simplify_not, gfc_resolve_not,
1481 i, BT_INTEGER, di, 0);
1482
1483 make_generic ("not", GFC_ISYM_NOT);
1484
1485 add_sym_1 ("null", 0, 1, BT_INTEGER, di,
1486 gfc_check_null, gfc_simplify_null, NULL,
1487 mo, BT_INTEGER, di, 1);
1488
1489 make_generic ("null", GFC_ISYM_NONE);
1490
1491 add_sym_3 ("pack", 0, 1, BT_REAL, dr,
1492 gfc_check_pack, NULL, gfc_resolve_pack,
1493 ar, BT_REAL, dr, 0, msk, BT_LOGICAL, dl, 0,
1494 v, BT_REAL, dr, 1);
1495
1496 make_generic ("pack", GFC_ISYM_PACK);
1497
1498 add_sym_1 ("precision", 0, 1, BT_INTEGER, di,
1499 gfc_check_precision, gfc_simplify_precision, NULL,
1500 x, BT_UNKNOWN, 0, 0);
1501
1502 make_generic ("precision", GFC_ISYM_NONE);
1503
1504 add_sym_1 ("present", 0, 1, BT_LOGICAL, dl,
1505 gfc_check_present, NULL, NULL, a, BT_REAL, dr, 0);
1506
1507 make_generic ("present", GFC_ISYM_PRESENT);
1508
1509 add_sym_3 ("product", 0, 1, BT_REAL, dr,
1510 gfc_check_product, NULL, gfc_resolve_product,
1511 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1512 msk, BT_LOGICAL, dl, 1);
1513
1514 make_generic ("product", GFC_ISYM_PRODUCT);
1515
1516 add_sym_1 ("radix", 0, 1, BT_INTEGER, di,
1517 gfc_check_radix, gfc_simplify_radix, NULL,
1518 x, BT_UNKNOWN, 0, 0);
1519
1520 make_generic ("radix", GFC_ISYM_NONE);
1521
1522 /* The following function is for G77 compatibility. */
1523 add_sym_1 ("rand", 0, 1, BT_REAL, 4,
1524 gfc_check_rand, NULL, NULL,
1525 i, BT_INTEGER, 4, 0);
1526
1527 /* Compatibility with HP FORTRAN 77/iX Reference. Note, rand() and
1528 ran() use slightly different shoddy multiplicative congruential
1529 PRNG. */
1530 make_alias ("ran");
1531
1532 make_generic ("rand", GFC_ISYM_RAND);
1533
1534 add_sym_1 ("range", 0, 1, BT_INTEGER, di,
1535 gfc_check_range, gfc_simplify_range, NULL,
1536 x, BT_REAL, dr, 0);
1537
1538 make_generic ("range", GFC_ISYM_NONE);
1539
1540 add_sym_2 ("real", 1, 0, BT_REAL, dr,
1541 gfc_check_real, gfc_simplify_real, gfc_resolve_real,
1542 a, BT_UNKNOWN, dr, 0, kind, BT_INTEGER, di, 1);
1543
1544 add_sym_1 ("float", 1, 0, BT_REAL, dr,
1545 NULL, gfc_simplify_float, NULL, a, BT_INTEGER, di, 0);
1546
1547 add_sym_1 ("sngl", 1, 0, BT_REAL, dr,
1548 NULL, gfc_simplify_sngl, NULL, a, BT_REAL, dd, 0);
1549
1550 make_generic ("real", GFC_ISYM_REAL);
1551
1552 add_sym_2 ("repeat", 0, 1, BT_CHARACTER, dc,
1553 gfc_check_repeat, gfc_simplify_repeat, gfc_resolve_repeat,
1554 stg, BT_CHARACTER, dc, 0, n, BT_INTEGER, di, 0);
1555
1556 make_generic ("repeat", GFC_ISYM_REPEAT);
1557
1558 add_sym_4 ("reshape", 0, 1, BT_REAL, dr,
1559 gfc_check_reshape, gfc_simplify_reshape, gfc_resolve_reshape,
1560 src, BT_REAL, dr, 0, shp, BT_INTEGER, ii, 0,
1561 pad, BT_REAL, dr, 1, ord, BT_INTEGER, ii, 1);
1562
1563 make_generic ("reshape", GFC_ISYM_RESHAPE);
1564
1565 add_sym_1 ("rrspacing", 1, 1, BT_REAL, dr,
1566 gfc_check_x, gfc_simplify_rrspacing, gfc_resolve_rrspacing,
1567 x, BT_REAL, dr, 0);
1568
1569 make_generic ("rrspacing", GFC_ISYM_RRSPACING);
1570
1571 add_sym_2 ("scale", 1, 1, BT_REAL, dr,
1572 gfc_check_scale, gfc_simplify_scale, gfc_resolve_scale,
1573 x, BT_REAL, dr, 0, i, BT_INTEGER, di, 0);
1574
1575 make_generic ("scale", GFC_ISYM_SCALE);
1576
1577 add_sym_3 ("scan", 1, 1, BT_INTEGER, di,
1578 gfc_check_scan, gfc_simplify_scan, gfc_resolve_scan,
1579 stg, BT_CHARACTER, dc, 0, set, BT_CHARACTER, dc, 0,
1580 bck, BT_LOGICAL, dl, 1);
1581
1582 make_generic ("scan", GFC_ISYM_SCAN);
1583
1584 /* Added for G77 compatibility garbage. */
1585 add_sym_0 ("second", 0, 1, BT_REAL, 4, NULL, NULL, NULL);
1586
1587 make_generic ("second", GFC_ISYM_SECOND);
1588
1589 add_sym_1 ("selected_int_kind", 0, 1, BT_INTEGER, di,
1590 NULL, gfc_simplify_selected_int_kind, NULL,
1591 r, BT_INTEGER, di, 0);
1592
1593 make_generic ("selected_int_kind", GFC_ISYM_SI_KIND);
1594
1595 add_sym_2 ("selected_real_kind", 0, 1, BT_INTEGER, di,
1596 gfc_check_selected_real_kind, gfc_simplify_selected_real_kind,
1597 NULL, p, BT_INTEGER, di, 1, r, BT_INTEGER, di, 1);
1598
1599 make_generic ("selected_real_kind", GFC_ISYM_SR_KIND);
1600
1601 add_sym_2 ("set_exponent", 1, 1, BT_REAL, dr,
1602 gfc_check_set_exponent, gfc_simplify_set_exponent,
1603 gfc_resolve_set_exponent,
1604 x, BT_REAL, dr, 0, i, BT_INTEGER, di, 0);
1605
1606 make_generic ("set_exponent", GFC_ISYM_SET_EXPONENT);
1607
1608 add_sym_1 ("shape", 0, 1, BT_INTEGER, di,
1609 gfc_check_shape, gfc_simplify_shape, gfc_resolve_shape,
1610 src, BT_REAL, dr, 0);
1611
1612 make_generic ("shape", GFC_ISYM_SHAPE);
1613
1614 add_sym_2 ("sign", 1, 1, BT_REAL, dr,
1615 gfc_check_sign, gfc_simplify_sign, gfc_resolve_sign,
1616 a, BT_REAL, dr, 0, b, BT_REAL, dr, 0);
1617
1618 add_sym_2 ("isign", 1, 1, BT_INTEGER, di,
1619 NULL, gfc_simplify_sign, gfc_resolve_sign,
1620 a, BT_INTEGER, di, 0, b, BT_INTEGER, di, 0);
1621
1622 add_sym_2 ("dsign", 1, 1, BT_REAL, dd,
1623 NULL, gfc_simplify_sign, gfc_resolve_sign,
1624 a, BT_REAL, dd, 0, b, BT_REAL, dd, 0);
1625
1626 make_generic ("sign", GFC_ISYM_SIGN);
1627
1628 add_sym_1 ("sin", 1, 1, BT_REAL, dr,
1629 NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_REAL, dr, 0);
1630
1631 add_sym_1 ("dsin", 1, 1, BT_REAL, dd,
1632 NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_REAL, dd, 0);
1633
1634 add_sym_1 ("csin", 1, 1, BT_COMPLEX, dz,
1635 NULL, gfc_simplify_sin, gfc_resolve_sin,
1636 x, BT_COMPLEX, dz, 0);
1637
1638 add_sym_1 ("zsin", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_COMPLEX, dd, 0); /* Extension */
1639
1640 make_alias ("cdsin");
1641
1642 make_generic ("sin", GFC_ISYM_SIN);
1643
1644 add_sym_1 ("sinh", 1, 1, BT_REAL, dr,
1645 NULL, gfc_simplify_sinh, gfc_resolve_sinh,
1646 x, BT_REAL, dr, 0);
1647
1648 add_sym_1 ("dsinh", 1, 1, BT_REAL, dd,
1649 NULL, gfc_simplify_sinh, gfc_resolve_sinh,
1650 x, BT_REAL, dd, 0);
1651
1652 make_generic ("sinh", GFC_ISYM_SINH);
1653
1654 add_sym_2 ("size", 0, 1, BT_INTEGER, di,
1655 gfc_check_size, gfc_simplify_size, NULL,
1656 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1);
1657
1658 make_generic ("size", GFC_ISYM_SIZE);
1659
1660 add_sym_1 ("spacing", 1, 1, BT_REAL, dr,
1661 gfc_check_x, gfc_simplify_spacing, gfc_resolve_spacing,
1662 x, BT_REAL, dr, 0);
1663
1664 make_generic ("spacing", GFC_ISYM_SPACING);
1665
1666 add_sym_3 ("spread", 0, 1, BT_REAL, dr,
1667 gfc_check_spread, NULL, gfc_resolve_spread,
1668 src, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 0,
1669 n, BT_INTEGER, di, 0);
1670
1671 make_generic ("spread", GFC_ISYM_SPREAD);
1672
1673 add_sym_1 ("sqrt", 1, 1, BT_REAL, dr,
1674 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1675 x, BT_REAL, dr, 0);
1676
1677 add_sym_1 ("dsqrt", 1, 1, BT_REAL, dd,
1678 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1679 x, BT_REAL, dd, 0);
1680
1681 add_sym_1 ("csqrt", 1, 1, BT_COMPLEX, dz,
1682 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1683 x, BT_COMPLEX, dz, 0);
1684
1685 add_sym_1 ("zsqrt", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_sqrt, gfc_resolve_sqrt, x, BT_COMPLEX, dd, 0); /* Extension */
1686
1687 make_alias ("cdsqrt");
1688
1689 make_generic ("sqrt", GFC_ISYM_SQRT);
1690
1691 add_sym_3 ("sum", 0, 1, BT_UNKNOWN, 0,
1692 gfc_check_sum, NULL, gfc_resolve_sum,
1693 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1694 msk, BT_LOGICAL, dl, 1);
1695
1696 make_generic ("sum", GFC_ISYM_SUM);
1697
1698 add_sym_1 ("tan", 1, 1, BT_REAL, dr,
1699 NULL, gfc_simplify_tan, gfc_resolve_tan, x, BT_REAL, dr, 0);
1700
1701 add_sym_1 ("dtan", 1, 1, BT_REAL, dd,
1702 NULL, gfc_simplify_tan, gfc_resolve_tan, x, BT_REAL, dd, 0);
1703
1704 make_generic ("tan", GFC_ISYM_TAN);
1705
1706 add_sym_1 ("tanh", 1, 1, BT_REAL, dr,
1707 NULL, gfc_simplify_tanh, gfc_resolve_tanh,
1708 x, BT_REAL, dr, 0);
1709
1710 add_sym_1 ("dtanh", 1, 1, BT_REAL, dd,
1711 NULL, gfc_simplify_tanh, gfc_resolve_tanh,
1712 x, BT_REAL, dd, 0);
1713
1714 make_generic ("tanh", GFC_ISYM_TANH);
1715
1716 add_sym_1 ("tiny", 0, 1, BT_REAL, dr,
1717 gfc_check_x, gfc_simplify_tiny, NULL, x, BT_REAL, dr, 0);
1718
1719 make_generic ("tiny", GFC_ISYM_NONE);
1720
1721 add_sym_3 ("transfer", 0, 1, BT_REAL, dr,
1722 gfc_check_transfer, NULL, gfc_resolve_transfer,
1723 src, BT_REAL, dr, 0, mo, BT_REAL, dr, 0,
1724 sz, BT_INTEGER, di, 1);
1725
1726 make_generic ("transfer", GFC_ISYM_TRANSFER);
1727
1728 add_sym_1 ("transpose", 0, 1, BT_REAL, dr,
1729 gfc_check_transpose, NULL, gfc_resolve_transpose,
1730 m, BT_REAL, dr, 0);
1731
1732 make_generic ("transpose", GFC_ISYM_TRANSPOSE);
1733
1734 add_sym_1 ("trim", 0, 1, BT_CHARACTER, dc,
1735 gfc_check_trim, gfc_simplify_trim, gfc_resolve_trim,
1736 stg, BT_CHARACTER, dc, 0);
1737
1738 make_generic ("trim", GFC_ISYM_TRIM);
1739
1740 add_sym_2 ("ubound", 0, 1, BT_INTEGER, di,
1741 gfc_check_ubound, gfc_simplify_ubound, gfc_resolve_ubound,
1742 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1);
1743
1744 make_generic ("ubound", GFC_ISYM_UBOUND);
1745
1746 add_sym_3 ("unpack", 0, 1, BT_REAL, dr,
1747 gfc_check_unpack, NULL, gfc_resolve_unpack,
1748 v, BT_REAL, dr, 0, msk, BT_LOGICAL, dl, 0,
1749 f, BT_REAL, dr, 0);
1750
1751 make_generic ("unpack", GFC_ISYM_UNPACK);
1752
1753 add_sym_3 ("verify", 1, 1, BT_INTEGER, di,
1754 gfc_check_verify, gfc_simplify_verify, gfc_resolve_verify,
1755 stg, BT_CHARACTER, dc, 0, set, BT_CHARACTER, dc, 0,
1756 bck, BT_LOGICAL, dl, 1);
1757
1758 make_generic ("verify", GFC_ISYM_VERIFY);
1759
1760
1761 }
1762
1763
1764
1765 /* Add intrinsic subroutines. */
1766
1767 static void
1768 add_subroutines (void)
1769 {
1770 /* Argument names as in the standard (to be used as argument keywords). */
1771 const char
1772 *h = "harvest", *dt = "date", *vl = "values", *pt = "put",
1773 *c = "count", *tm = "time", *tp = "topos", *gt = "get",
1774 *t = "to", *zn = "zone", *fp = "frompos", *cm = "count_max",
1775 *f = "from", *sz = "size", *ln = "len", *cr = "count_rate",
1776 *com = "command", *length = "length", *st = "status",
1777 *val = "value", *num = "number", *name = "name",
1778 *trim_name = "trim_name";
1779
1780 int di, dr, dc, dl;
1781
1782 di = gfc_default_integer_kind ();
1783 dr = gfc_default_real_kind ();
1784 dc = gfc_default_character_kind ();
1785 dl = gfc_default_logical_kind ();
1786
1787 add_sym_0s ("abort", 1, NULL);
1788
1789 add_sym_1s ("cpu_time", 0, 1, BT_UNKNOWN, 0,
1790 gfc_check_cpu_time, NULL, gfc_resolve_cpu_time,
1791 tm, BT_REAL, dr, 0);
1792
1793 /* More G77 compatibility garbage. */
1794 add_sym_1s ("second", 0, 1, BT_UNKNOWN, 0,
1795 gfc_check_second_sub, NULL, gfc_resolve_second_sub,
1796 tm, BT_REAL, dr, 0);
1797
1798 add_sym_4s ("date_and_time", 0, 1, BT_UNKNOWN, 0,
1799 gfc_check_date_and_time, NULL, NULL,
1800 dt, BT_CHARACTER, dc, 1, tm, BT_CHARACTER, dc, 1,
1801 zn, BT_CHARACTER, dc, 1, vl, BT_INTEGER, di, 1);
1802
1803 /* More G77 compatibility garbage. */
1804 add_sym_2s ("etime", 0, 1, BT_UNKNOWN, 0,
1805 gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
1806 vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
1807
1808 add_sym_2s ("dtime", 0, 1, BT_UNKNOWN, 0,
1809 gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
1810 vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
1811
1812 add_sym_2s ("getenv", 0, 1, BT_UNKNOWN, 0,
1813 NULL, NULL, NULL,
1814 name, BT_CHARACTER, dc, 0,
1815 val, BT_CHARACTER, dc, 0);
1816
1817 add_sym_2s ("getarg", 0, 1, BT_UNKNOWN, 0,
1818 NULL, NULL, gfc_resolve_getarg,
1819 c, BT_INTEGER, di, 0, vl, BT_CHARACTER, dc, 0);
1820
1821 /* F2003 commandline routines. */
1822
1823 add_sym_3s ("get_command", 0, 1, BT_UNKNOWN, 0,
1824 NULL, NULL, gfc_resolve_get_command,
1825 com, BT_CHARACTER, dc, 1,
1826 length, BT_INTEGER, di, 1,
1827 st, BT_INTEGER, di, 1);
1828
1829 add_sym_4s ("get_command_argument", 0, 1, BT_UNKNOWN, 0,
1830 NULL, NULL, gfc_resolve_get_command_argument,
1831 num, BT_INTEGER, di, 0,
1832 val, BT_CHARACTER, dc, 1,
1833 length, BT_INTEGER, di, 1,
1834 st, BT_INTEGER, di, 1);
1835
1836
1837 /* F2003 subroutine to get environment variables. */
1838
1839 add_sym_5s ("get_environment_variable", 0, 1, BT_UNKNOWN, 0,
1840 NULL, NULL, gfc_resolve_get_environment_variable,
1841 name, BT_CHARACTER, dc, 0,
1842 val, BT_CHARACTER, dc, 1,
1843 length, BT_INTEGER, di, 1,
1844 st, BT_INTEGER, di, 1,
1845 trim_name, BT_LOGICAL, dl, 1);
1846
1847
1848 /* This needs changing to add_sym_5s if it gets a resolution function. */
1849 add_sym_5 ("mvbits", 1, 1, BT_UNKNOWN, 0,
1850 gfc_check_mvbits, gfc_simplify_mvbits, NULL,
1851 f, BT_INTEGER, di, 0, fp, BT_INTEGER, di, 0,
1852 ln, BT_INTEGER, di, 0, t, BT_INTEGER, di, 0,
1853 tp, BT_INTEGER, di, 0);
1854
1855 add_sym_1s ("random_number", 0, 1, BT_UNKNOWN, 0,
1856 gfc_check_random_number, NULL, gfc_resolve_random_number,
1857 h, BT_REAL, dr, 0);
1858
1859 add_sym_3s ("random_seed", 0, 1, BT_UNKNOWN, 0,
1860 gfc_check_random_seed, NULL, NULL,
1861 sz, BT_INTEGER, di, 1, pt, BT_INTEGER, di, 1,
1862 gt, BT_INTEGER, di, 1);
1863
1864 /* More G77 compatibility garbage. */
1865 add_sym_1s ("srand", 0, 1, BT_UNKNOWN, di,
1866 gfc_check_srand, NULL, gfc_resolve_srand,
1867 c, BT_INTEGER, 4, 0);
1868
1869 add_sym_3s ("system_clock", 0, 1, BT_UNKNOWN, 0,
1870 gfc_check_system_clock, NULL, gfc_resolve_system_clock,
1871 c, BT_INTEGER, di, 1, cr, BT_INTEGER, di, 1,
1872 cm, BT_INTEGER, di, 1);
1873 }
1874
1875
1876 /* Add a function to the list of conversion symbols. */
1877
1878 static void
1879 add_conv (bt from_type, int from_kind, bt to_type, int to_kind,
1880 gfc_expr * (*simplify) (gfc_expr *, bt, int))
1881 {
1882
1883 gfc_typespec from, to;
1884 gfc_intrinsic_sym *sym;
1885
1886 if (sizing == SZ_CONVS)
1887 {
1888 nconv++;
1889 return;
1890 }
1891
1892 gfc_clear_ts (&from);
1893 from.type = from_type;
1894 from.kind = from_kind;
1895
1896 gfc_clear_ts (&to);
1897 to.type = to_type;
1898 to.kind = to_kind;
1899
1900 sym = conversion + nconv;
1901
1902 strcpy (sym->name, conv_name (&from, &to));
1903 strcpy (sym->lib_name, sym->name);
1904 sym->simplify.cc = simplify;
1905 sym->elemental = 1;
1906 sym->ts = to;
1907 sym->generic_id = GFC_ISYM_CONVERSION;
1908
1909 nconv++;
1910 }
1911
1912
1913 /* Create gfc_intrinsic_sym nodes for all intrinsic conversion
1914 functions by looping over the kind tables. */
1915
1916 static void
1917 add_conversions (void)
1918 {
1919 int i, j;
1920
1921 /* Integer-Integer conversions. */
1922 for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
1923 for (j = 0; gfc_integer_kinds[j].kind != 0; j++)
1924 {
1925 if (i == j)
1926 continue;
1927
1928 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
1929 BT_INTEGER, gfc_integer_kinds[j].kind, gfc_convert_constant);
1930 }
1931
1932 /* Integer-Real/Complex conversions. */
1933 for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
1934 for (j = 0; gfc_real_kinds[j].kind != 0; j++)
1935 {
1936 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
1937 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
1938
1939 add_conv (BT_REAL, gfc_real_kinds[j].kind,
1940 BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant);
1941
1942 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
1943 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
1944
1945 add_conv (BT_COMPLEX, gfc_real_kinds[j].kind,
1946 BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant);
1947 }
1948
1949 /* Real/Complex - Real/Complex conversions. */
1950 for (i = 0; gfc_real_kinds[i].kind != 0; i++)
1951 for (j = 0; gfc_real_kinds[j].kind != 0; j++)
1952 {
1953 if (i != j)
1954 {
1955 add_conv (BT_REAL, gfc_real_kinds[i].kind,
1956 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
1957
1958 add_conv (BT_COMPLEX, gfc_real_kinds[i].kind,
1959 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
1960 }
1961
1962 add_conv (BT_REAL, gfc_real_kinds[i].kind,
1963 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
1964
1965 add_conv (BT_COMPLEX, gfc_real_kinds[i].kind,
1966 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
1967 }
1968
1969 /* Logical/Logical kind conversion. */
1970 for (i = 0; gfc_logical_kinds[i].kind; i++)
1971 for (j = 0; gfc_logical_kinds[j].kind; j++)
1972 {
1973 if (i == j)
1974 continue;
1975
1976 add_conv (BT_LOGICAL, gfc_logical_kinds[i].kind,
1977 BT_LOGICAL, gfc_logical_kinds[j].kind, gfc_convert_constant);
1978 }
1979 }
1980
1981
1982 /* Initialize the table of intrinsics. */
1983 void
1984 gfc_intrinsic_init_1 (void)
1985 {
1986 int i;
1987
1988 nargs = nfunc = nsub = nconv = 0;
1989
1990 /* Create a namespace to hold the resolved intrinsic symbols. */
1991 gfc_intrinsic_namespace = gfc_get_namespace (NULL);
1992
1993 sizing = SZ_FUNCS;
1994 add_functions ();
1995 sizing = SZ_SUBS;
1996 add_subroutines ();
1997 sizing = SZ_CONVS;
1998 add_conversions ();
1999
2000 functions = gfc_getmem (sizeof (gfc_intrinsic_sym) * (nfunc + nsub)
2001 + sizeof (gfc_intrinsic_arg) * nargs);
2002
2003 next_sym = functions;
2004 subroutines = functions + nfunc;
2005
2006 conversion = gfc_getmem (sizeof (gfc_intrinsic_sym) * nconv);
2007
2008 next_arg = ((gfc_intrinsic_arg *) (subroutines + nsub)) - 1;
2009
2010 sizing = SZ_NOTHING;
2011 nconv = 0;
2012
2013 add_functions ();
2014 add_subroutines ();
2015 add_conversions ();
2016
2017 /* Set the pure flag. All intrinsic functions are pure, and
2018 intrinsic subroutines are pure if they are elemental. */
2019
2020 for (i = 0; i < nfunc; i++)
2021 functions[i].pure = 1;
2022
2023 for (i = 0; i < nsub; i++)
2024 subroutines[i].pure = subroutines[i].elemental;
2025 }
2026
2027
2028 void
2029 gfc_intrinsic_done_1 (void)
2030 {
2031 gfc_free (functions);
2032 gfc_free (conversion);
2033 gfc_free_namespace (gfc_intrinsic_namespace);
2034 }
2035
2036
2037 /******** Subroutines to check intrinsic interfaces ***********/
2038
2039 /* Given a formal argument list, remove any NULL arguments that may
2040 have been left behind by a sort against some formal argument list. */
2041
2042 static void
2043 remove_nullargs (gfc_actual_arglist ** ap)
2044 {
2045 gfc_actual_arglist *head, *tail, *next;
2046
2047 tail = NULL;
2048
2049 for (head = *ap; head; head = next)
2050 {
2051 next = head->next;
2052
2053 if (head->expr == NULL)
2054 {
2055 head->next = NULL;
2056 gfc_free_actual_arglist (head);
2057 }
2058 else
2059 {
2060 if (tail == NULL)
2061 *ap = head;
2062 else
2063 tail->next = head;
2064
2065 tail = head;
2066 tail->next = NULL;
2067 }
2068 }
2069
2070 if (tail == NULL)
2071 *ap = NULL;
2072 }
2073
2074
2075 /* Given an actual arglist and a formal arglist, sort the actual
2076 arglist so that its arguments are in a one-to-one correspondence
2077 with the format arglist. Arguments that are not present are given
2078 a blank gfc_actual_arglist structure. If something is obviously
2079 wrong (say, a missing required argument) we abort sorting and
2080 return FAILURE. */
2081
2082 static try
2083 sort_actual (const char *name, gfc_actual_arglist ** ap,
2084 gfc_intrinsic_arg * formal, locus * where)
2085 {
2086
2087 gfc_actual_arglist *actual, *a;
2088 gfc_intrinsic_arg *f;
2089
2090 remove_nullargs (ap);
2091 actual = *ap;
2092
2093 for (f = formal; f; f = f->next)
2094 f->actual = NULL;
2095
2096 f = formal;
2097 a = actual;
2098
2099 if (f == NULL && a == NULL) /* No arguments */
2100 return SUCCESS;
2101
2102 for (;;)
2103 { /* Put the nonkeyword arguments in a 1:1 correspondence */
2104 if (f == NULL)
2105 break;
2106 if (a == NULL)
2107 goto optional;
2108
2109 if (a->name[0] != '\0')
2110 goto keywords;
2111
2112 f->actual = a;
2113
2114 f = f->next;
2115 a = a->next;
2116 }
2117
2118 if (a == NULL)
2119 goto do_sort;
2120
2121 gfc_error ("Too many arguments in call to '%s' at %L", name, where);
2122 return FAILURE;
2123
2124 keywords:
2125 /* Associate the remaining actual arguments, all of which have
2126 to be keyword arguments. */
2127 for (; a; a = a->next)
2128 {
2129 for (f = formal; f; f = f->next)
2130 if (strcmp (a->name, f->name) == 0)
2131 break;
2132
2133 if (f == NULL)
2134 {
2135 gfc_error ("Can't find keyword named '%s' in call to '%s' at %L",
2136 a->name, name, where);
2137 return FAILURE;
2138 }
2139
2140 if (f->actual != NULL)
2141 {
2142 gfc_error ("Argument '%s' is appears twice in call to '%s' at %L",
2143 f->name, name, where);
2144 return FAILURE;
2145 }
2146
2147 f->actual = a;
2148 }
2149
2150 optional:
2151 /* At this point, all unmatched formal args must be optional. */
2152 for (f = formal; f; f = f->next)
2153 {
2154 if (f->actual == NULL && f->optional == 0)
2155 {
2156 gfc_error ("Missing actual argument '%s' in call to '%s' at %L",
2157 f->name, name, where);
2158 return FAILURE;
2159 }
2160 }
2161
2162 do_sort:
2163 /* Using the formal argument list, string the actual argument list
2164 together in a way that corresponds with the formal list. */
2165 actual = NULL;
2166
2167 for (f = formal; f; f = f->next)
2168 {
2169 if (f->actual == NULL)
2170 {
2171 a = gfc_get_actual_arglist ();
2172 a->missing_arg_type = f->ts.type;
2173 }
2174 else
2175 a = f->actual;
2176
2177 if (actual == NULL)
2178 *ap = a;
2179 else
2180 actual->next = a;
2181
2182 actual = a;
2183 }
2184 actual->next = NULL; /* End the sorted argument list. */
2185
2186 return SUCCESS;
2187 }
2188
2189
2190 /* Compare an actual argument list with an intrinsic's formal argument
2191 list. The lists are checked for agreement of type. We don't check
2192 for arrayness here. */
2193
2194 static try
2195 check_arglist (gfc_actual_arglist ** ap, gfc_intrinsic_sym * sym,
2196 int error_flag)
2197 {
2198 gfc_actual_arglist *actual;
2199 gfc_intrinsic_arg *formal;
2200 int i;
2201
2202 formal = sym->formal;
2203 actual = *ap;
2204
2205 i = 0;
2206 for (; formal; formal = formal->next, actual = actual->next, i++)
2207 {
2208 if (actual->expr == NULL)
2209 continue;
2210
2211 if (!gfc_compare_types (&formal->ts, &actual->expr->ts))
2212 {
2213 if (error_flag)
2214 gfc_error
2215 ("Type of argument '%s' in call to '%s' at %L should be "
2216 "%s, not %s", gfc_current_intrinsic_arg[i],
2217 gfc_current_intrinsic, &actual->expr->where,
2218 gfc_typename (&formal->ts), gfc_typename (&actual->expr->ts));
2219 return FAILURE;
2220 }
2221 }
2222
2223 return SUCCESS;
2224 }
2225
2226
2227 /* Given a pointer to an intrinsic symbol and an expression node that
2228 represent the function call to that subroutine, figure out the type
2229 of the result. This may involve calling a resolution subroutine. */
2230
2231 static void
2232 resolve_intrinsic (gfc_intrinsic_sym * specific, gfc_expr * e)
2233 {
2234 gfc_expr *a1, *a2, *a3, *a4, *a5;
2235 gfc_actual_arglist *arg;
2236
2237 if (specific->resolve.f1 == NULL)
2238 {
2239 if (e->value.function.name == NULL)
2240 e->value.function.name = specific->lib_name;
2241
2242 if (e->ts.type == BT_UNKNOWN)
2243 e->ts = specific->ts;
2244 return;
2245 }
2246
2247 arg = e->value.function.actual;
2248
2249 /* At present only the iargc extension intrinsic takes no arguments,
2250 and it doesn't need a resolution function, but this is here for
2251 generality. */
2252 if (arg == NULL)
2253 {
2254 (*specific->resolve.f0) (e);
2255 return;
2256 }
2257
2258 /* Special case hacks for MIN and MAX. */
2259 if (specific->resolve.f1m == gfc_resolve_max
2260 || specific->resolve.f1m == gfc_resolve_min)
2261 {
2262 (*specific->resolve.f1m) (e, arg);
2263 return;
2264 }
2265
2266 a1 = arg->expr;
2267 arg = arg->next;
2268
2269 if (arg == NULL)
2270 {
2271 (*specific->resolve.f1) (e, a1);
2272 return;
2273 }
2274
2275 a2 = arg->expr;
2276 arg = arg->next;
2277
2278 if (arg == NULL)
2279 {
2280 (*specific->resolve.f2) (e, a1, a2);
2281 return;
2282 }
2283
2284 a3 = arg->expr;
2285 arg = arg->next;
2286
2287 if (arg == NULL)
2288 {
2289 (*specific->resolve.f3) (e, a1, a2, a3);
2290 return;
2291 }
2292
2293 a4 = arg->expr;
2294 arg = arg->next;
2295
2296 if (arg == NULL)
2297 {
2298 (*specific->resolve.f4) (e, a1, a2, a3, a4);
2299 return;
2300 }
2301
2302 a5 = arg->expr;
2303 arg = arg->next;
2304
2305 if (arg == NULL)
2306 {
2307 (*specific->resolve.f5) (e, a1, a2, a3, a4, a5);
2308 return;
2309 }
2310
2311 gfc_internal_error ("resolve_intrinsic(): Too many args for intrinsic");
2312 }
2313
2314
2315 /* Given an intrinsic symbol node and an expression node, call the
2316 simplification function (if there is one), perhaps replacing the
2317 expression with something simpler. We return FAILURE on an error
2318 of the simplification, SUCCESS if the simplification worked, even
2319 if nothing has changed in the expression itself. */
2320
2321 static try
2322 do_simplify (gfc_intrinsic_sym * specific, gfc_expr * e)
2323 {
2324 gfc_expr *result, *a1, *a2, *a3, *a4, *a5;
2325 gfc_actual_arglist *arg;
2326
2327 /* Max and min require special handling due to the variable number
2328 of args. */
2329 if (specific->simplify.f1 == gfc_simplify_min)
2330 {
2331 result = gfc_simplify_min (e);
2332 goto finish;
2333 }
2334
2335 if (specific->simplify.f1 == gfc_simplify_max)
2336 {
2337 result = gfc_simplify_max (e);
2338 goto finish;
2339 }
2340
2341 if (specific->simplify.f1 == NULL)
2342 {
2343 result = NULL;
2344 goto finish;
2345 }
2346
2347 arg = e->value.function.actual;
2348
2349 a1 = arg->expr;
2350 arg = arg->next;
2351
2352 if (specific->simplify.cc == gfc_convert_constant)
2353 {
2354 result = gfc_convert_constant (a1, specific->ts.type, specific->ts.kind);
2355 goto finish;
2356 }
2357
2358 /* TODO: Warn if -pedantic and initialization expression and arg
2359 types not integer or character */
2360
2361 if (arg == NULL)
2362 result = (*specific->simplify.f1) (a1);
2363 else
2364 {
2365 a2 = arg->expr;
2366 arg = arg->next;
2367
2368 if (arg == NULL)
2369 result = (*specific->simplify.f2) (a1, a2);
2370 else
2371 {
2372 a3 = arg->expr;
2373 arg = arg->next;
2374
2375 if (arg == NULL)
2376 result = (*specific->simplify.f3) (a1, a2, a3);
2377 else
2378 {
2379 a4 = arg->expr;
2380 arg = arg->next;
2381
2382 if (arg == NULL)
2383 result = (*specific->simplify.f4) (a1, a2, a3, a4);
2384 else
2385 {
2386 a5 = arg->expr;
2387 arg = arg->next;
2388
2389 if (arg == NULL)
2390 result = (*specific->simplify.f5) (a1, a2, a3, a4, a5);
2391 else
2392 gfc_internal_error
2393 ("do_simplify(): Too many args for intrinsic");
2394 }
2395 }
2396 }
2397 }
2398
2399 finish:
2400 if (result == &gfc_bad_expr)
2401 return FAILURE;
2402
2403 if (result == NULL)
2404 resolve_intrinsic (specific, e); /* Must call at run-time */
2405 else
2406 {
2407 result->where = e->where;
2408 gfc_replace_expr (e, result);
2409 }
2410
2411 return SUCCESS;
2412 }
2413
2414
2415 /* Initialize the gfc_current_intrinsic_arg[] array for the benefit of
2416 error messages. This subroutine returns FAILURE if a subroutine
2417 has more than MAX_INTRINSIC_ARGS, in which case the actual argument
2418 list cannot match any intrinsic. */
2419
2420 static void
2421 init_arglist (gfc_intrinsic_sym * isym)
2422 {
2423 gfc_intrinsic_arg *formal;
2424 int i;
2425
2426 gfc_current_intrinsic = isym->name;
2427
2428 i = 0;
2429 for (formal = isym->formal; formal; formal = formal->next)
2430 {
2431 if (i >= MAX_INTRINSIC_ARGS)
2432 gfc_internal_error ("init_arglist(): too many arguments");
2433 gfc_current_intrinsic_arg[i++] = formal->name;
2434 }
2435 }
2436
2437
2438 /* Given a pointer to an intrinsic symbol and an expression consisting
2439 of a function call, see if the function call is consistent with the
2440 intrinsic's formal argument list. Return SUCCESS if the expression
2441 and intrinsic match, FAILURE otherwise. */
2442
2443 static try
2444 check_specific (gfc_intrinsic_sym * specific, gfc_expr * expr, int error_flag)
2445 {
2446 gfc_actual_arglist *arg, **ap;
2447 int r;
2448 try t;
2449
2450 ap = &expr->value.function.actual;
2451
2452 init_arglist (specific);
2453
2454 /* Don't attempt to sort the argument list for min or max. */
2455 if (specific->check.f1m == gfc_check_min_max
2456 || specific->check.f1m == gfc_check_min_max_integer
2457 || specific->check.f1m == gfc_check_min_max_real
2458 || specific->check.f1m == gfc_check_min_max_double)
2459 return (*specific->check.f1m) (*ap);
2460
2461 if (sort_actual (specific->name, ap, specific->formal,
2462 &expr->where) == FAILURE)
2463 return FAILURE;
2464
2465 if (specific->check.f3ml != gfc_check_minloc_maxloc)
2466 {
2467 if (specific->check.f1 == NULL)
2468 {
2469 t = check_arglist (ap, specific, error_flag);
2470 if (t == SUCCESS)
2471 expr->ts = specific->ts;
2472 }
2473 else
2474 t = do_check (specific, *ap);
2475 }
2476 else
2477 /* This is special because we might have to reorder the argument
2478 list. */
2479 t = gfc_check_minloc_maxloc (*ap);
2480
2481 /* Check ranks for elemental intrinsics. */
2482 if (t == SUCCESS && specific->elemental)
2483 {
2484 r = 0;
2485 for (arg = expr->value.function.actual; arg; arg = arg->next)
2486 {
2487 if (arg->expr == NULL || arg->expr->rank == 0)
2488 continue;
2489 if (r == 0)
2490 {
2491 r = arg->expr->rank;
2492 continue;
2493 }
2494
2495 if (arg->expr->rank != r)
2496 {
2497 gfc_error
2498 ("Ranks of arguments to elemental intrinsic '%s' differ "
2499 "at %L", specific->name, &arg->expr->where);
2500 return FAILURE;
2501 }
2502 }
2503 }
2504
2505 if (t == FAILURE)
2506 remove_nullargs (ap);
2507
2508 return t;
2509 }
2510
2511
2512 /* See if an intrinsic is one of the intrinsics we evaluate
2513 as an extension. */
2514
2515 static int
2516 gfc_init_expr_extensions (gfc_intrinsic_sym *isym)
2517 {
2518 /* FIXME: This should be moved into the intrinsic definitions. */
2519 static const char * const init_expr_extensions[] = {
2520 "digits", "epsilon", "huge", "kind", "maxexponent", "minexponent",
2521 "precision", "present", "radix", "range", "selected_real_kind",
2522 "tiny", NULL
2523 };
2524
2525 int i;
2526
2527 for (i = 0; init_expr_extensions[i]; i++)
2528 if (strcmp (init_expr_extensions[i], isym->name) == 0)
2529 return 0;
2530
2531 return 1;
2532 }
2533
2534
2535 /* See if a function call corresponds to an intrinsic function call.
2536 We return:
2537
2538 MATCH_YES if the call corresponds to an intrinsic, simplification
2539 is done if possible.
2540
2541 MATCH_NO if the call does not correspond to an intrinsic
2542
2543 MATCH_ERROR if the call corresponds to an intrinsic but there was an
2544 error during the simplification process.
2545
2546 The error_flag parameter enables an error reporting. */
2547
2548 match
2549 gfc_intrinsic_func_interface (gfc_expr * expr, int error_flag)
2550 {
2551 gfc_intrinsic_sym *isym, *specific;
2552 gfc_actual_arglist *actual;
2553 const char *name;
2554 int flag;
2555
2556 if (expr->value.function.isym != NULL)
2557 return (do_simplify (expr->value.function.isym, expr) == FAILURE)
2558 ? MATCH_ERROR : MATCH_YES;
2559
2560 gfc_suppress_error = !error_flag;
2561 flag = 0;
2562
2563 for (actual = expr->value.function.actual; actual; actual = actual->next)
2564 if (actual->expr != NULL)
2565 flag |= (actual->expr->ts.type != BT_INTEGER
2566 && actual->expr->ts.type != BT_CHARACTER);
2567
2568 name = expr->symtree->n.sym->name;
2569
2570 isym = specific = gfc_find_function (name);
2571 if (isym == NULL)
2572 {
2573 gfc_suppress_error = 0;
2574 return MATCH_NO;
2575 }
2576
2577 gfc_current_intrinsic_where = &expr->where;
2578
2579 /* Bypass the generic list for min and max. */
2580 if (isym->check.f1m == gfc_check_min_max)
2581 {
2582 init_arglist (isym);
2583
2584 if (gfc_check_min_max (expr->value.function.actual) == SUCCESS)
2585 goto got_specific;
2586
2587 gfc_suppress_error = 0;
2588 return MATCH_NO;
2589 }
2590
2591 /* If the function is generic, check all of its specific
2592 incarnations. If the generic name is also a specific, we check
2593 that name last, so that any error message will correspond to the
2594 specific. */
2595 gfc_suppress_error = 1;
2596
2597 if (isym->generic)
2598 {
2599 for (specific = isym->specific_head; specific;
2600 specific = specific->next)
2601 {
2602 if (specific == isym)
2603 continue;
2604 if (check_specific (specific, expr, 0) == SUCCESS)
2605 goto got_specific;
2606 }
2607 }
2608
2609 gfc_suppress_error = !error_flag;
2610
2611 if (check_specific (isym, expr, error_flag) == FAILURE)
2612 {
2613 gfc_suppress_error = 0;
2614 return MATCH_NO;
2615 }
2616
2617 specific = isym;
2618
2619 got_specific:
2620 expr->value.function.isym = specific;
2621 gfc_intrinsic_symbol (expr->symtree->n.sym);
2622
2623 if (do_simplify (specific, expr) == FAILURE)
2624 {
2625 gfc_suppress_error = 0;
2626 return MATCH_ERROR;
2627 }
2628
2629 /* TODO: We should probably only allow elemental functions here. */
2630 flag |= (expr->ts.type != BT_INTEGER && expr->ts.type != BT_CHARACTER);
2631
2632 gfc_suppress_error = 0;
2633 if (pedantic && gfc_init_expr
2634 && flag && gfc_init_expr_extensions (specific))
2635 {
2636 if (gfc_notify_std (GFC_STD_GNU, "Extension: Evaluation of "
2637 "nonstandard initialization expression at %L", &expr->where)
2638 == FAILURE)
2639 {
2640 return MATCH_ERROR;
2641 }
2642 }
2643
2644 return MATCH_YES;
2645 }
2646
2647
2648 /* See if a CALL statement corresponds to an intrinsic subroutine.
2649 Returns MATCH_YES if the subroutine corresponds to an intrinsic,
2650 MATCH_NO if not, and MATCH_ERROR if there was an error (but did
2651 correspond). */
2652
2653 match
2654 gfc_intrinsic_sub_interface (gfc_code * c, int error_flag)
2655 {
2656 gfc_intrinsic_sym *isym;
2657 const char *name;
2658
2659 name = c->symtree->n.sym->name;
2660
2661 isym = find_subroutine (name);
2662 if (isym == NULL)
2663 return MATCH_NO;
2664
2665 gfc_suppress_error = !error_flag;
2666
2667 init_arglist (isym);
2668
2669 if (sort_actual (name, &c->ext.actual, isym->formal, &c->loc) == FAILURE)
2670 goto fail;
2671
2672 if (isym->check.f1 != NULL)
2673 {
2674 if (do_check (isym, c->ext.actual) == FAILURE)
2675 goto fail;
2676 }
2677 else
2678 {
2679 if (check_arglist (&c->ext.actual, isym, 1) == FAILURE)
2680 goto fail;
2681 }
2682
2683 /* The subroutine corresponds to an intrinsic. Allow errors to be
2684 seen at this point. */
2685 gfc_suppress_error = 0;
2686
2687 if (isym->resolve.s1 != NULL)
2688 isym->resolve.s1 (c);
2689 else
2690 c->resolved_sym = gfc_get_intrinsic_sub_symbol (isym->lib_name);
2691
2692 if (gfc_pure (NULL) && !isym->elemental)
2693 {
2694 gfc_error ("Subroutine call to intrinsic '%s' at %L is not PURE", name,
2695 &c->loc);
2696 return MATCH_ERROR;
2697 }
2698
2699 return MATCH_YES;
2700
2701 fail:
2702 gfc_suppress_error = 0;
2703 return MATCH_NO;
2704 }
2705
2706
2707 /* Call gfc_convert_type() with warning enabled. */
2708
2709 try
2710 gfc_convert_type (gfc_expr * expr, gfc_typespec * ts, int eflag)
2711 {
2712 return gfc_convert_type_warn (expr, ts, eflag, 1);
2713 }
2714
2715
2716 /* Try to convert an expression (in place) from one type to another.
2717 'eflag' controls the behavior on error.
2718
2719 The possible values are:
2720
2721 1 Generate a gfc_error()
2722 2 Generate a gfc_internal_error().
2723
2724 'wflag' controls the warning related to conversion. */
2725
2726 try
2727 gfc_convert_type_warn (gfc_expr * expr, gfc_typespec * ts, int eflag,
2728 int wflag)
2729 {
2730 gfc_intrinsic_sym *sym;
2731 gfc_typespec from_ts;
2732 locus old_where;
2733 gfc_expr *new;
2734 int rank;
2735
2736 from_ts = expr->ts; /* expr->ts gets clobbered */
2737
2738 if (ts->type == BT_UNKNOWN)
2739 goto bad;
2740
2741 /* NULL and zero size arrays get their type here. */
2742 if (expr->expr_type == EXPR_NULL
2743 || (expr->expr_type == EXPR_ARRAY
2744 && expr->value.constructor == NULL))
2745 {
2746 /* Sometimes the RHS acquire the type. */
2747 expr->ts = *ts;
2748 return SUCCESS;
2749 }
2750
2751 if (expr->ts.type == BT_UNKNOWN)
2752 goto bad;
2753
2754 if (expr->ts.type == BT_DERIVED
2755 && ts->type == BT_DERIVED
2756 && gfc_compare_types (&expr->ts, ts))
2757 return SUCCESS;
2758
2759 sym = find_conv (&expr->ts, ts);
2760 if (sym == NULL)
2761 goto bad;
2762
2763 /* At this point, a conversion is necessary. A warning may be needed. */
2764 if (wflag && gfc_option.warn_conversion)
2765 gfc_warning_now ("Conversion from %s to %s at %L",
2766 gfc_typename (&from_ts), gfc_typename (ts), &expr->where);
2767
2768 /* Insert a pre-resolved function call to the right function. */
2769 old_where = expr->where;
2770 rank = expr->rank;
2771 new = gfc_get_expr ();
2772 *new = *expr;
2773
2774 new = gfc_build_conversion (new);
2775 new->value.function.name = sym->lib_name;
2776 new->value.function.isym = sym;
2777 new->where = old_where;
2778 new->rank = rank;
2779
2780 *expr = *new;
2781
2782 gfc_free (new);
2783 expr->ts = *ts;
2784
2785 if (gfc_is_constant_expr (expr->value.function.actual->expr)
2786 && do_simplify (sym, expr) == FAILURE)
2787 {
2788
2789 if (eflag == 2)
2790 goto bad;
2791 return FAILURE; /* Error already generated in do_simplify() */
2792 }
2793
2794 return SUCCESS;
2795
2796 bad:
2797 if (eflag == 1)
2798 {
2799 gfc_error ("Can't convert %s to %s at %L",
2800 gfc_typename (&from_ts), gfc_typename (ts), &expr->where);
2801 return FAILURE;
2802 }
2803
2804 gfc_internal_error ("Can't convert %s to %s at %L",
2805 gfc_typename (&from_ts), gfc_typename (ts),
2806 &expr->where);
2807 /* Not reached */
2808 }