1 /* Build up a list of intrinsic subroutines and functions for the
3 Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation,
5 Contributed by Andy Vaught & Katherine Holcomb
7 This file is part of GCC.
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
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
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
35 #include "intrinsic.h"
38 /* Nanespace to hold the resolved symbols for intrinsic subroutines. */
39 static gfc_namespace *gfc_intrinsic_namespace;
41 int gfc_init_expr = 0;
43 /* Pointers to a intrinsic function and its argument names being
46 char *gfc_current_intrinsic, *gfc_current_intrinsic_arg[MAX_INTRINSIC_ARGS];
47 locus *gfc_current_intrinsic_where;
49 static gfc_intrinsic_sym *functions, *subroutines, *conversion, *next_sym;
50 static gfc_intrinsic_arg *next_arg;
52 static int nfunc, nsub, nargs, nconv;
55 { SZ_NOTHING = 0, SZ_SUBS, SZ_FUNCS, SZ_CONVS }
59 /* Return a letter based on the passed type. Used to construct the
60 name of a type-dependent subroutine. */
63 gfc_type_letter (bt type)
94 /* Get a symbol for a resolved name. */
97 gfc_get_intrinsic_sub_symbol (const char * name)
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;
111 /* Return a pointer to the name of a conversion function given two
115 conv_name (gfc_typespec * from, gfc_typespec * to)
117 static char name[30];
119 sprintf (name, "__convert_%c%d_%c%d", gfc_type_letter (from->type),
120 from->kind, gfc_type_letter (to->type), to->kind);
126 /* Given a pair of typespecs, find the gfc_intrinsic_sym node that
127 corresponds to the conversion. Returns NULL if the conversion
130 static gfc_intrinsic_sym *
131 find_conv (gfc_typespec * from, gfc_typespec * to)
133 gfc_intrinsic_sym *sym;
137 target = conv_name (from, to);
140 for (i = 0; i < nconv; i++, sym++)
141 if (strcmp (target, sym->name) == 0)
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. */
153 do_check (gfc_intrinsic_sym * specific, gfc_actual_arglist * arg)
155 gfc_expr *a1, *a2, *a3, *a4, *a5;
158 return (*specific->check.f0) ();
163 return (*specific->check.f1) (a1);
168 return (*specific->check.f2) (a1, a2);
173 return (*specific->check.f3) (a1, a2, a3);
178 return (*specific->check.f4) (a1, a2, a3, a4);
183 return (*specific->check.f5) (a1, a2, a3, a4, a5);
185 gfc_internal_error ("do_check(): too many args");
189 /*********** Subroutines to build the intrinsic list ****************/
191 /* Add a single intrinsic symbol to the current list.
194 char * name of function
195 int whether function is elemental
196 int If the function can be used as an actual argument
197 bt return type of function
198 int kind of return type of function
199 check pointer to check function
200 simplify pointer to simplification function
201 resolve pointer to resolution function
203 Optional arguments come in multiples of four:
204 char * name of argument
207 int arg optional flag (1=optional, 0=required)
209 The sequence is terminated by a NULL name.
211 TODO: Are checks on actual_ok implemented elsewhere, or is that just
215 add_sym (const char *name, int elemental, int actual_ok ATTRIBUTE_UNUSED,
216 bt type, int kind, gfc_check_f check, gfc_simplify_f simplify,
217 gfc_resolve_f resolve, ...)
220 int optional, first_flag;
234 strcpy (next_sym->name, name);
236 strcpy (next_sym->lib_name, "_gfortran_");
237 strcat (next_sym->lib_name, name);
239 next_sym->elemental = elemental;
240 next_sym->ts.type = type;
241 next_sym->ts.kind = kind;
242 next_sym->simplify = simplify;
243 next_sym->check = check;
244 next_sym->resolve = resolve;
245 next_sym->specific = 0;
246 next_sym->generic = 0;
250 gfc_internal_error ("add_sym(): Bad sizing mode");
253 va_start (argp, resolve);
259 name = va_arg (argp, char *);
263 type = (bt) va_arg (argp, int);
264 kind = va_arg (argp, int);
265 optional = va_arg (argp, int);
267 if (sizing != SZ_NOTHING)
274 next_sym->formal = next_arg;
276 (next_arg - 1)->next = next_arg;
280 strcpy (next_arg->name, name);
281 next_arg->ts.type = type;
282 next_arg->ts.kind = kind;
283 next_arg->optional = optional;
293 static void add_sym_0 (const char *name, int elemental, int actual_ok, bt type,
296 gfc_expr *(*simplify)(void),
297 void (*resolve)(gfc_expr *)
307 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
312 static void add_sym_1 (const char *name, int elemental, int actual_ok, bt type,
314 try (*check)(gfc_expr *),
315 gfc_expr *(*simplify)(gfc_expr *),
316 void (*resolve)(gfc_expr *,gfc_expr *),
317 const char* a1, bt type1, int kind1, int optional1
327 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
328 a1, type1, kind1, optional1,
334 add_sym_0s (const char * name, int actual_ok,
335 void (*resolve)(gfc_code *))
345 add_sym (name, 1, actual_ok, BT_UNKNOWN, 0, cf, sf, rf,
350 static void add_sym_1s (const char *name, int elemental, int actual_ok, bt type,
352 try (*check)(gfc_expr *),
353 gfc_expr *(*simplify)(gfc_expr *),
354 void (*resolve)(gfc_code *),
355 const char* a1, bt type1, int kind1, int optional1
365 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
366 a1, type1, kind1, optional1,
371 static void add_sym_1m (const char *name, int elemental, int actual_ok, bt type,
373 try (*check)(gfc_actual_arglist *),
374 gfc_expr *(*simplify)(gfc_expr *),
375 void (*resolve)(gfc_expr *,gfc_actual_arglist *),
376 const char* a1, bt type1, int kind1, int optional1,
377 const char* a2, bt type2, int kind2, int optional2
387 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
388 a1, type1, kind1, optional1,
389 a2, type2, kind2, optional2,
394 static void add_sym_2 (const char *name, int elemental, int actual_ok, bt type,
396 try (*check)(gfc_expr *,gfc_expr *),
397 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *),
398 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *),
399 const char* a1, bt type1, int kind1, int optional1,
400 const char* a2, bt type2, int kind2, int optional2
410 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
411 a1, type1, kind1, optional1,
412 a2, type2, kind2, optional2,
417 /* Add the name of an intrinsic subroutine with two arguments to the list
418 of intrinsic names. */
420 static void add_sym_2s (const char *name, int elemental, int actual_ok, bt type,
422 try (*check)(gfc_expr *,gfc_expr *),
423 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *),
424 void (*resolve)(gfc_code *),
425 const char* a1, bt type1, int kind1, int optional1,
426 const char* a2, bt type2, int kind2, int optional2
436 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
437 a1, type1, kind1, optional1,
438 a2, type2, kind2, optional2,
443 static void add_sym_3 (const char *name, int elemental, int actual_ok, bt type,
445 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *),
446 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
447 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
448 const char* a1, bt type1, int kind1, int optional1,
449 const char* a2, bt type2, int kind2, int optional2,
450 const char* a3, bt type3, int kind3, int optional3
460 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
461 a1, type1, kind1, optional1,
462 a2, type2, kind2, optional2,
463 a3, type3, kind3, optional3,
467 /* MINLOC and MAXLOC get special treatment because their argument
468 might have to be reordered. */
470 static void add_sym_3ml (const char *name, int elemental,
471 int actual_ok, bt type, int kind,
472 try (*check)(gfc_actual_arglist *),
473 gfc_expr*(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
474 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
475 const char* a1, bt type1, int kind1, int optional1,
476 const char* a2, bt type2, int kind2, int optional2,
477 const char* a3, bt type3, int kind3, int optional3
487 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
488 a1, type1, kind1, optional1,
489 a2, type2, kind2, optional2,
490 a3, type3, kind3, optional3,
494 /* MINVAL, MAXVAL, PRODUCT, and SUM also get special treatment because
495 their argument also might have to be reordered. */
497 static void add_sym_3red (const char *name, int elemental,
498 int actual_ok, bt type, int kind,
499 try (*check)(gfc_actual_arglist *),
500 gfc_expr*(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
501 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
502 const char* a1, bt type1, int kind1, int optional1,
503 const char* a2, bt type2, int kind2, int optional2,
504 const char* a3, bt type3, int kind3, int optional3
514 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
515 a1, type1, kind1, optional1,
516 a2, type2, kind2, optional2,
517 a3, type3, kind3, optional3,
521 /* Add the name of an intrinsic subroutine with three arguments to the list
522 of intrinsic names. */
524 static void add_sym_3s (const char *name, int elemental, int actual_ok, bt type,
526 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *),
527 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
528 void (*resolve)(gfc_code *),
529 const char* a1, bt type1, int kind1, int optional1,
530 const char* a2, bt type2, int kind2, int optional2,
531 const char* a3, bt type3, int kind3, int optional3
541 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
542 a1, type1, kind1, optional1,
543 a2, type2, kind2, optional2,
544 a3, type3, kind3, optional3,
549 static void add_sym_4 (const char *name, int elemental, int actual_ok, bt type,
551 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
552 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
553 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
554 const char* a1, bt type1, int kind1, int optional1,
555 const char* a2, bt type2, int kind2, int optional2,
556 const char* a3, bt type3, int kind3, int optional3,
557 const char* a4, bt type4, int kind4, int optional4
567 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
568 a1, type1, kind1, optional1,
569 a2, type2, kind2, optional2,
570 a3, type3, kind3, optional3,
571 a4, type4, kind4, optional4,
576 static void add_sym_4s (const char *name, int elemental, int actual_ok,
578 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
579 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
580 void (*resolve)(gfc_code *),
581 const char* a1, bt type1, int kind1, int optional1,
582 const char* a2, bt type2, int kind2, int optional2,
583 const char* a3, bt type3, int kind3, int optional3,
584 const char* a4, bt type4, int kind4, int optional4)
594 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
595 a1, type1, kind1, optional1,
596 a2, type2, kind2, optional2,
597 a3, type3, kind3, optional3,
598 a4, type4, kind4, optional4,
603 static void add_sym_5 (const char *name, int elemental, int actual_ok, bt type,
605 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
606 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
607 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
608 const char* a1, bt type1, int kind1, int optional1,
609 const char* a2, bt type2, int kind2, int optional2,
610 const char* a3, bt type3, int kind3, int optional3,
611 const char* a4, bt type4, int kind4, int optional4,
612 const char* a5, bt type5, int kind5, int optional5
622 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
623 a1, type1, kind1, optional1,
624 a2, type2, kind2, optional2,
625 a3, type3, kind3, optional3,
626 a4, type4, kind4, optional4,
627 a5, type5, kind5, optional5,
632 static void add_sym_5s
634 const char *name, int elemental, int actual_ok, bt type, int kind,
635 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
636 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
637 void (*resolve)(gfc_code *),
638 const char* a1, bt type1, int kind1, int optional1,
639 const char* a2, bt type2, int kind2, int optional2,
640 const char* a3, bt type3, int kind3, int optional3,
641 const char* a4, bt type4, int kind4, int optional4,
642 const char* a5, bt type5, int kind5, int optional5)
652 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
653 a1, type1, kind1, optional1,
654 a2, type2, kind2, optional2,
655 a3, type3, kind3, optional3,
656 a4, type4, kind4, optional4,
657 a5, type5, kind5, optional5,
662 /* Locate an intrinsic symbol given a base pointer, number of elements
663 in the table and a pointer to a name. Returns the NULL pointer if
664 a name is not found. */
666 static gfc_intrinsic_sym *
667 find_sym (gfc_intrinsic_sym * start, int n, const char *name)
672 if (strcmp (name, start->name) == 0)
683 /* Given a name, find a function in the intrinsic function table.
684 Returns NULL if not found. */
687 gfc_find_function (const char *name)
690 return find_sym (functions, nfunc, name);
694 /* Given a name, find a function in the intrinsic subroutine table.
695 Returns NULL if not found. */
697 static gfc_intrinsic_sym *
698 find_subroutine (const char *name)
701 return find_sym (subroutines, nsub, name);
705 /* Given a string, figure out if it is the name of a generic intrinsic
709 gfc_generic_intrinsic (const char *name)
711 gfc_intrinsic_sym *sym;
713 sym = gfc_find_function (name);
714 return (sym == NULL) ? 0 : sym->generic;
718 /* Given a string, figure out if it is the name of a specific
719 intrinsic function or not. */
722 gfc_specific_intrinsic (const char *name)
724 gfc_intrinsic_sym *sym;
726 sym = gfc_find_function (name);
727 return (sym == NULL) ? 0 : sym->specific;
731 /* Given a string, figure out if it is the name of an intrinsic
732 subroutine or function. There are no generic intrinsic
733 subroutines, they are all specific. */
736 gfc_intrinsic_name (const char *name, int subroutine_flag)
739 return subroutine_flag ?
740 find_subroutine (name) != NULL : gfc_find_function (name) != NULL;
744 /* Collect a set of intrinsic functions into a generic collection.
745 The first argument is the name of the generic function, which is
746 also the name of a specific function. The rest of the specifics
747 currently in the table are placed into the list of specific
748 functions associated with that generic. */
751 make_generic (const char *name, gfc_generic_isym_id generic_id)
753 gfc_intrinsic_sym *g;
755 if (sizing != SZ_NOTHING)
758 g = gfc_find_function (name);
760 gfc_internal_error ("make_generic(): Can't find generic symbol '%s'",
765 g->generic_id = generic_id;
766 if ((g + 1)->name[0] != '\0')
767 g->specific_head = g + 1;
770 while (g->name[0] != '\0')
774 g->generic_id = generic_id;
783 /* Create a duplicate intrinsic function entry for the current
784 function, the only difference being the alternate name. Note that
785 we use argument lists more than once, but all argument lists are
786 freed as a single block. */
789 make_alias (const char *name)
803 next_sym[0] = next_sym[-1];
804 strcpy (next_sym->name, name);
814 /* Add intrinsic functions. */
820 /* Argument names as in the standard (to be used as argument keywords). */
822 *a = "a", *f = "field", *pt = "pointer", *tg = "target",
823 *b = "b", *m = "matrix", *ma = "matrix_a", *mb = "matrix_b",
824 *c = "c", *n = "ncopies", *pos = "pos", *bck = "back",
825 *i = "i", *v = "vector", *va = "vector_a", *vb = "vector_b",
826 *j = "j", *a1 = "a1", *fs = "fsource", *ts = "tsource",
827 *l = "l", *a2 = "a2", *mo = "mold", *ord = "order",
828 *p = "p", *ar = "array", *shp = "shape", *src = "source",
829 *r = "r", *bd = "boundary", *pad = "pad", *set = "set",
830 *s = "s", *dm = "dim", *kind = "kind", *msk = "mask",
831 *x = "x", *sh = "shift", *stg = "string", *ssg = "substring",
832 *y = "y", *sz = "size", *sta = "string_a", *stb = "string_b",
833 *z = "z", *ln = "len";
835 int di, dr, dd, dl, dc, dz, ii;
837 di = gfc_default_integer_kind;
838 dr = gfc_default_real_kind;
839 dd = gfc_default_double_kind;
840 dl = gfc_default_logical_kind;
841 dc = gfc_default_character_kind;
842 dz = gfc_default_complex_kind;
843 ii = gfc_index_integer_kind;
845 add_sym_1 ("abs", 1, 1, BT_REAL, dr,
846 gfc_check_abs, gfc_simplify_abs, gfc_resolve_abs,
849 add_sym_1 ("iabs", 1, 1, BT_INTEGER, di,
850 NULL, gfc_simplify_abs, gfc_resolve_abs,
851 a, BT_INTEGER, di, 0);
853 add_sym_1 ("dabs", 1, 1, BT_REAL, dd,
854 NULL, gfc_simplify_abs, gfc_resolve_abs, a, BT_REAL, dd, 0);
856 add_sym_1 ("cabs", 1, 1, BT_REAL, dr,
857 NULL, gfc_simplify_abs, gfc_resolve_abs,
858 a, BT_COMPLEX, dz, 0);
860 add_sym_1 ("zabs", 1, 1, BT_REAL, dd, NULL, gfc_simplify_abs, gfc_resolve_abs, a, BT_COMPLEX, dd, 0); /* Extension */
862 make_alias ("cdabs");
864 make_generic ("abs", GFC_ISYM_ABS);
866 add_sym_1 ("achar", 1, 1, BT_CHARACTER, dc,
867 NULL, gfc_simplify_achar, NULL, i, BT_INTEGER, di, 0);
869 make_generic ("achar", GFC_ISYM_ACHAR);
871 add_sym_1 ("acos", 1, 1, BT_REAL, dr,
872 NULL, gfc_simplify_acos, gfc_resolve_acos,
875 add_sym_1 ("dacos", 1, 1, BT_REAL, dd,
876 NULL, gfc_simplify_acos, gfc_resolve_acos,
879 make_generic ("acos", GFC_ISYM_ACOS);
881 add_sym_1 ("adjustl", 1, 1, BT_CHARACTER, dc,
882 NULL, gfc_simplify_adjustl, NULL, stg, BT_CHARACTER, dc, 0);
884 make_generic ("adjustl", GFC_ISYM_ADJUSTL);
886 add_sym_1 ("adjustr", 1, 1, BT_CHARACTER, dc,
887 NULL, gfc_simplify_adjustr, NULL, stg, BT_CHARACTER, dc, 0);
889 make_generic ("adjustr", GFC_ISYM_ADJUSTR);
891 add_sym_1 ("aimag", 1, 1, BT_REAL, dr,
892 NULL, gfc_simplify_aimag, gfc_resolve_aimag,
893 z, BT_COMPLEX, dz, 0);
895 add_sym_1 ("dimag", 1, 1, BT_REAL, dd, NULL, gfc_simplify_aimag, gfc_resolve_aimag, z, BT_COMPLEX, dd, 0); /* Extension */
897 make_generic ("aimag", GFC_ISYM_AIMAG);
899 add_sym_2 ("aint", 1, 1, BT_REAL, dr,
900 gfc_check_a_xkind, gfc_simplify_aint, gfc_resolve_aint,
901 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
903 add_sym_1 ("dint", 1, 1, BT_REAL, dd,
904 NULL, gfc_simplify_dint, gfc_resolve_dint,
907 make_generic ("aint", GFC_ISYM_AINT);
909 add_sym_2 ("all", 0, 1, BT_UNKNOWN, 0,
910 gfc_check_all_any, NULL, gfc_resolve_all,
911 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
913 make_generic ("all", GFC_ISYM_ALL);
915 add_sym_1 ("allocated", 0, 1, BT_LOGICAL, dl,
916 gfc_check_allocated, NULL, NULL, ar, BT_UNKNOWN, 0, 0);
918 make_generic ("allocated", GFC_ISYM_ALLOCATED);
920 add_sym_2 ("anint", 1, 1, BT_REAL, dr,
921 gfc_check_a_xkind, gfc_simplify_anint, gfc_resolve_anint,
922 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
924 add_sym_1 ("dnint", 1, 1, BT_REAL, dd,
925 NULL, gfc_simplify_dnint, gfc_resolve_dnint,
928 make_generic ("anint", GFC_ISYM_ANINT);
930 add_sym_2 ("any", 0, 1, BT_UNKNOWN, 0,
931 gfc_check_all_any, NULL, gfc_resolve_any,
932 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
934 make_generic ("any", GFC_ISYM_ANY);
936 add_sym_1 ("asin", 1, 1, BT_REAL, dr,
937 NULL, gfc_simplify_asin, gfc_resolve_asin,
940 add_sym_1 ("dasin", 1, 1, BT_REAL, dd,
941 NULL, gfc_simplify_asin, gfc_resolve_asin,
944 make_generic ("asin", GFC_ISYM_ASIN);
946 add_sym_2 ("associated", 0, 1, BT_LOGICAL, dl,
947 gfc_check_associated, NULL, NULL,
948 pt, BT_UNKNOWN, 0, 0, tg, BT_UNKNOWN, 0, 1);
950 make_generic ("associated", GFC_ISYM_ASSOCIATED);
952 add_sym_1 ("atan", 1, 1, BT_REAL, dr,
953 NULL, gfc_simplify_atan, gfc_resolve_atan,
956 add_sym_1 ("datan", 1, 1, BT_REAL, dd,
957 NULL, gfc_simplify_atan, gfc_resolve_atan,
960 make_generic ("atan", GFC_ISYM_ATAN);
962 add_sym_2 ("atan2", 1, 1, BT_REAL, dr,
963 gfc_check_atan2, gfc_simplify_atan2, gfc_resolve_atan2,
964 y, BT_REAL, dr, 0, x, BT_REAL, dr, 0);
966 add_sym_2 ("datan2", 1, 1, BT_REAL, dd,
967 NULL, gfc_simplify_atan2, gfc_resolve_atan2,
968 y, BT_REAL, dd, 0, x, BT_REAL, dd, 0);
970 make_generic ("atan2", GFC_ISYM_ATAN2);
972 /* Bessel and Neumann functions for G77 compatibility. */
974 add_sym_1 ("besj0", 1, 0, BT_REAL, dr,
975 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
978 add_sym_1 ("dbesj0", 1, 0, BT_REAL, dd,
979 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
982 make_generic ("besj0", GFC_ISYM_J0);
984 add_sym_1 ("besj1", 1, 0, BT_REAL, dr,
985 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
988 add_sym_1 ("dbesj1", 1, 0, BT_REAL, dd,
989 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
992 make_generic ("besj1", GFC_ISYM_J1);
994 add_sym_2 ("besjn", 1, 0, BT_REAL, dr,
995 gfc_check_besn, NULL, gfc_resolve_besn, n, BT_INTEGER, di, 1,
998 add_sym_2 ("dbesjn", 1, 0, BT_REAL, dd,
999 gfc_check_besn, NULL, gfc_resolve_besn, n, BT_INTEGER, di, 1,
1002 make_generic ("besjn", GFC_ISYM_JN);
1004 add_sym_1 ("besy0", 1, 0, BT_REAL, dr,
1005 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1008 add_sym_1 ("dbesy0", 1, 0, BT_REAL, dd,
1009 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1012 make_generic ("besy0", GFC_ISYM_Y0);
1014 add_sym_1 ("besy1", 1, 0, BT_REAL, dr,
1015 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1018 add_sym_1 ("dbesy1", 1, 0, BT_REAL, dd,
1019 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1022 make_generic ("besy1", GFC_ISYM_Y1);
1024 add_sym_2 ("besyn", 1, 0, BT_REAL, dr,
1025 gfc_check_besn, NULL, gfc_resolve_besn, n, BT_INTEGER, di, 1,
1028 add_sym_2 ("dbesyn", 1, 0, BT_REAL, dd,
1029 gfc_check_besn, NULL, gfc_resolve_besn, n, BT_INTEGER, di, 1,
1032 make_generic ("besyn", GFC_ISYM_YN);
1034 add_sym_1 ("bit_size", 0, 1, BT_INTEGER, di,
1035 gfc_check_i, gfc_simplify_bit_size, NULL,
1036 i, BT_INTEGER, di, 0);
1038 make_generic ("bit_size", GFC_ISYM_NONE);
1040 add_sym_2 ("btest", 1, 1, BT_LOGICAL, dl,
1041 gfc_check_btest, gfc_simplify_btest, gfc_resolve_btest,
1042 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1044 make_generic ("btest", GFC_ISYM_BTEST);
1046 add_sym_2 ("ceiling", 1, 1, BT_INTEGER, di,
1047 gfc_check_a_ikind, gfc_simplify_ceiling, gfc_resolve_ceiling,
1048 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1050 make_generic ("ceiling", GFC_ISYM_CEILING);
1052 add_sym_2 ("char", 1, 0, BT_CHARACTER, dc,
1053 gfc_check_char, gfc_simplify_char, gfc_resolve_char,
1054 i, BT_INTEGER, di, 0, kind, BT_INTEGER, di, 1);
1056 make_generic ("char", GFC_ISYM_CHAR);
1058 add_sym_3 ("cmplx", 1, 1, BT_COMPLEX, dz,
1059 gfc_check_cmplx, gfc_simplify_cmplx, gfc_resolve_cmplx,
1060 x, BT_UNKNOWN, dr, 0, y, BT_UNKNOWN, dr, 1,
1061 kind, BT_INTEGER, di, 1);
1063 make_generic ("cmplx", GFC_ISYM_CMPLX);
1065 /* Making dcmplx a specific of cmplx causes cmplx to return a double
1066 complex instead of the default complex. */
1068 add_sym_2 ("dcmplx", 1, 1, BT_COMPLEX, dd,
1069 gfc_check_dcmplx, gfc_simplify_dcmplx, gfc_resolve_dcmplx,
1070 x, BT_REAL, dd, 0, y, BT_REAL, dd, 1); /* Extension */
1072 make_generic ("dcmplx", GFC_ISYM_CMPLX);
1074 add_sym_1 ("conjg", 1, 1, BT_COMPLEX, dz,
1075 NULL, gfc_simplify_conjg, gfc_resolve_conjg,
1076 z, BT_COMPLEX, dz, 0);
1078 add_sym_1 ("dconjg", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_conjg, gfc_resolve_conjg, z, BT_COMPLEX, dd, 0); /* Extension */
1080 make_generic ("conjg", GFC_ISYM_CONJG);
1082 add_sym_1 ("cos", 1, 1, BT_REAL, dr,
1083 NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_REAL, dr, 0);
1085 add_sym_1 ("dcos", 1, 1, BT_REAL, dd,
1086 NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_REAL, dd, 0);
1088 add_sym_1 ("ccos", 1, 1, BT_COMPLEX, dz,
1089 NULL, gfc_simplify_cos, gfc_resolve_cos,
1090 x, BT_COMPLEX, dz, 0);
1092 add_sym_1 ("zcos", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_COMPLEX, dd, 0); /* Extension */
1094 make_alias ("cdcos");
1096 make_generic ("cos", GFC_ISYM_COS);
1098 add_sym_1 ("cosh", 1, 1, BT_REAL, dr,
1099 NULL, gfc_simplify_cosh, gfc_resolve_cosh,
1102 add_sym_1 ("dcosh", 1, 1, BT_REAL, dd,
1103 NULL, gfc_simplify_cosh, gfc_resolve_cosh,
1106 make_generic ("cosh", GFC_ISYM_COSH);
1108 add_sym_2 ("count", 0, 1, BT_INTEGER, di,
1109 gfc_check_count, NULL, gfc_resolve_count,
1110 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
1112 make_generic ("count", GFC_ISYM_COUNT);
1114 add_sym_3 ("cshift", 0, 1, BT_REAL, dr,
1115 gfc_check_cshift, NULL, gfc_resolve_cshift,
1116 ar, BT_REAL, dr, 0, sh, BT_INTEGER, di, 0,
1117 dm, BT_INTEGER, ii, 1);
1119 make_generic ("cshift", GFC_ISYM_CSHIFT);
1121 add_sym_1 ("dble", 1, 1, BT_REAL, dd,
1122 gfc_check_dble, gfc_simplify_dble, gfc_resolve_dble,
1125 make_alias ("dfloat");
1127 make_generic ("dble", GFC_ISYM_DBLE);
1129 add_sym_1 ("digits", 0, 1, BT_INTEGER, di,
1130 gfc_check_digits, gfc_simplify_digits, NULL,
1131 x, BT_UNKNOWN, dr, 0);
1133 make_generic ("digits", GFC_ISYM_NONE);
1135 add_sym_2 ("dim", 1, 1, BT_REAL, dr,
1136 gfc_check_a_p, gfc_simplify_dim, gfc_resolve_dim,
1137 x, BT_UNKNOWN, dr, 0, y, BT_UNKNOWN, dr, 0);
1139 add_sym_2 ("idim", 1, 1, BT_INTEGER, di,
1140 NULL, gfc_simplify_dim, gfc_resolve_dim,
1141 x, BT_INTEGER, di, 0, y, BT_INTEGER, di, 0);
1143 add_sym_2 ("ddim", 1, 1, BT_REAL, dd,
1144 NULL, gfc_simplify_dim, gfc_resolve_dim,
1145 x, BT_REAL, dd, 0, y, BT_REAL, dd, 0);
1147 make_generic ("dim", GFC_ISYM_DIM);
1149 add_sym_2 ("dot_product", 0, 1, BT_UNKNOWN, 0,
1150 gfc_check_dot_product, NULL, gfc_resolve_dot_product,
1151 va, BT_REAL, dr, 0, vb, BT_REAL, dr, 0);
1153 make_generic ("dot_product", GFC_ISYM_DOT_PRODUCT);
1155 add_sym_2 ("dprod", 1, 1, BT_REAL, dd,
1156 NULL, gfc_simplify_dprod, gfc_resolve_dprod,
1157 x, BT_REAL, dr, 0, y, BT_REAL, dr, 0);
1159 make_generic ("dprod", GFC_ISYM_DPROD);
1161 add_sym_1 ("dreal", 1, 0, BT_REAL, dd, NULL, NULL, NULL, a, BT_COMPLEX, dd, 0); /* Extension */
1163 make_generic ("dreal", GFC_ISYM_REAL);
1165 add_sym_4 ("eoshift", 0, 1, BT_REAL, dr,
1166 gfc_check_eoshift, NULL, gfc_resolve_eoshift,
1167 ar, BT_REAL, dr, 0, sh, BT_INTEGER, ii, 0,
1168 bd, BT_REAL, dr, 1, dm, BT_INTEGER, ii, 1);
1170 make_generic ("eoshift", GFC_ISYM_EOSHIFT);
1172 add_sym_1 ("epsilon", 0, 1, BT_REAL, dr,
1173 gfc_check_x, gfc_simplify_epsilon, NULL,
1176 make_generic ("epsilon", GFC_ISYM_NONE);
1178 /* G77 compatibility for the ERF() and ERFC() functions. */
1179 add_sym_1 ("erf", 1, 0, BT_REAL, dr,
1180 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1183 add_sym_1 ("derf", 1, 0, BT_REAL, dd,
1184 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1187 make_generic ("erf", GFC_ISYM_ERF);
1189 add_sym_1 ("erfc", 1, 0, BT_REAL, dr,
1190 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1193 add_sym_1 ("derfc", 1, 0, BT_REAL, dd,
1194 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1197 make_generic ("erfc", GFC_ISYM_ERFC);
1199 /* G77 compatibility */
1200 add_sym_1 ("etime", 0, 1, BT_REAL, 4,
1201 gfc_check_etime, NULL, NULL,
1204 make_alias ("dtime");
1206 make_generic ("etime", GFC_ISYM_ETIME);
1209 add_sym_1 ("exp", 1, 1, BT_REAL, dr,
1210 NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_REAL, dr, 0);
1212 add_sym_1 ("dexp", 1, 1, BT_REAL, dd,
1213 NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_REAL, dd, 0);
1215 add_sym_1 ("cexp", 1, 1, BT_COMPLEX, dz,
1216 NULL, gfc_simplify_exp, gfc_resolve_exp,
1217 x, BT_COMPLEX, dz, 0);
1219 add_sym_1 ("zexp", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_COMPLEX, dd, 0); /* Extension */
1221 make_alias ("cdexp");
1223 make_generic ("exp", GFC_ISYM_EXP);
1225 add_sym_1 ("exponent", 1, 1, BT_INTEGER, di,
1226 gfc_check_x, gfc_simplify_exponent, gfc_resolve_exponent,
1229 make_generic ("exponent", GFC_ISYM_EXPONENT);
1231 add_sym_2 ("floor", 1, 1, BT_INTEGER, di,
1232 gfc_check_a_ikind, gfc_simplify_floor, gfc_resolve_floor,
1233 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1235 make_generic ("floor", GFC_ISYM_FLOOR);
1237 add_sym_1 ("fraction", 1, 1, BT_REAL, dr,
1238 gfc_check_x, gfc_simplify_fraction, gfc_resolve_fraction,
1241 make_generic ("fraction", GFC_ISYM_FRACTION);
1243 /* Unix IDs (g77 compatibility) */
1244 add_sym_0 ("getgid", 1, 0, BT_INTEGER, di, NULL, NULL, gfc_resolve_getgid);
1245 make_generic ("getgid", GFC_ISYM_GETGID);
1247 add_sym_0 ("getpid", 1, 0, BT_INTEGER, di, NULL, NULL, gfc_resolve_getpid);
1248 make_generic ("getpid", GFC_ISYM_GETPID);
1250 add_sym_0 ("getuid", 1, 0, BT_INTEGER, di, NULL, NULL, gfc_resolve_getuid);
1251 make_generic ("getuid", GFC_ISYM_GETUID);
1253 add_sym_1 ("huge", 0, 1, BT_REAL, dr,
1254 gfc_check_huge, gfc_simplify_huge, NULL,
1255 x, BT_UNKNOWN, dr, 0);
1257 make_generic ("huge", GFC_ISYM_NONE);
1259 add_sym_1 ("iachar", 1, 1, BT_INTEGER, di,
1260 NULL, gfc_simplify_iachar, NULL, c, BT_CHARACTER, dc, 0);
1262 make_generic ("iachar", GFC_ISYM_IACHAR);
1264 add_sym_2 ("iand", 1, 1, BT_INTEGER, di,
1265 gfc_check_iand, gfc_simplify_iand, gfc_resolve_iand,
1266 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1268 make_generic ("iand", GFC_ISYM_IAND);
1270 add_sym_0 ("iargc", 1, 1, BT_INTEGER, di, NULL, NULL, NULL); /* Extension, takes no arguments */
1271 make_generic ("iargc", GFC_ISYM_IARGC);
1273 add_sym_0 ("command_argument_count", 1, 1, BT_INTEGER, di, NULL, NULL, NULL);
1274 make_generic ("command_argument_count", GFC_ISYM_COMMAND_ARGUMENT_COUNT);
1276 add_sym_2 ("ibclr", 1, 1, BT_INTEGER, di,
1277 gfc_check_ibclr, gfc_simplify_ibclr, gfc_resolve_ibclr,
1278 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1280 make_generic ("ibclr", GFC_ISYM_IBCLR);
1282 add_sym_3 ("ibits", 1, 1, BT_INTEGER, di,
1283 gfc_check_ibits, gfc_simplify_ibits, gfc_resolve_ibits,
1284 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0,
1285 ln, BT_INTEGER, di, 0);
1287 make_generic ("ibits", GFC_ISYM_IBITS);
1289 add_sym_2 ("ibset", 1, 1, BT_INTEGER, di,
1290 gfc_check_ibset, gfc_simplify_ibset, gfc_resolve_ibset,
1291 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1293 make_generic ("ibset", GFC_ISYM_IBSET);
1295 add_sym_1 ("ichar", 1, 0, BT_INTEGER, di,
1296 NULL, gfc_simplify_ichar, gfc_resolve_ichar,
1297 c, BT_CHARACTER, dc, 0);
1299 make_generic ("ichar", GFC_ISYM_ICHAR);
1301 add_sym_2 ("ieor", 1, 1, BT_INTEGER, di,
1302 gfc_check_ieor, gfc_simplify_ieor, gfc_resolve_ieor,
1303 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1305 make_generic ("ieor", GFC_ISYM_IEOR);
1307 add_sym_3 ("index", 1, 1, BT_INTEGER, di,
1308 gfc_check_index, gfc_simplify_index, NULL,
1309 stg, BT_CHARACTER, dc, 0, ssg, BT_CHARACTER, dc, 0,
1310 bck, BT_LOGICAL, dl, 1);
1312 make_generic ("index", GFC_ISYM_INDEX);
1314 add_sym_2 ("int", 1, 1, BT_INTEGER, di,
1315 gfc_check_int, gfc_simplify_int, gfc_resolve_int,
1316 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1318 add_sym_1 ("ifix", 1, 0, BT_INTEGER, di,
1319 NULL, gfc_simplify_ifix, NULL, a, BT_REAL, dr, 0);
1321 add_sym_1 ("idint", 1, 0, BT_INTEGER, di,
1322 NULL, gfc_simplify_idint, NULL, a, BT_REAL, dd, 0);
1324 make_generic ("int", GFC_ISYM_INT);
1326 add_sym_2 ("ior", 1, 1, BT_INTEGER, di,
1327 gfc_check_ior, gfc_simplify_ior, gfc_resolve_ior,
1328 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1330 make_generic ("ior", GFC_ISYM_IOR);
1332 /* The following function is for G77 compatibility. */
1333 add_sym_1 ("irand", 0, 1, BT_INTEGER, 4,
1334 gfc_check_irand, NULL, NULL,
1335 i, BT_INTEGER, 4, 0);
1337 make_generic ("irand", GFC_ISYM_IRAND);
1339 add_sym_2 ("ishft", 1, 1, BT_INTEGER, di,
1340 gfc_check_ishft, gfc_simplify_ishft, gfc_resolve_ishft,
1341 i, BT_INTEGER, di, 0, sh, BT_INTEGER, di, 0);
1343 make_generic ("ishft", GFC_ISYM_ISHFT);
1345 add_sym_3 ("ishftc", 1, 1, BT_INTEGER, di,
1346 gfc_check_ishftc, gfc_simplify_ishftc, gfc_resolve_ishftc,
1347 i, BT_INTEGER, di, 0, sh, BT_INTEGER, di, 0,
1348 sz, BT_INTEGER, di, 1);
1350 make_generic ("ishftc", GFC_ISYM_ISHFTC);
1352 add_sym_1 ("kind", 0, 1, BT_INTEGER, di,
1353 gfc_check_kind, gfc_simplify_kind, NULL, x, BT_REAL, dr, 0);
1355 make_generic ("kind", GFC_ISYM_NONE);
1357 add_sym_2 ("lbound", 0, 1, BT_INTEGER, di,
1358 gfc_check_lbound, gfc_simplify_lbound, gfc_resolve_lbound,
1359 ar, BT_REAL, dr, 0, dm, BT_INTEGER, di, 1);
1361 make_generic ("lbound", GFC_ISYM_LBOUND);
1363 add_sym_1 ("len", 0, 1, BT_INTEGER, di,
1364 NULL, gfc_simplify_len, gfc_resolve_len,
1365 stg, BT_CHARACTER, dc, 0);
1367 make_generic ("len", GFC_ISYM_LEN);
1369 add_sym_1 ("len_trim", 1, 1, BT_INTEGER, di,
1370 NULL, gfc_simplify_len_trim, gfc_resolve_len_trim,
1371 stg, BT_CHARACTER, dc, 0);
1373 make_generic ("len_trim", GFC_ISYM_LEN_TRIM);
1375 add_sym_2 ("lge", 1, 0, BT_LOGICAL, dl,
1376 NULL, gfc_simplify_lge, NULL,
1377 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1379 make_generic ("lge", GFC_ISYM_LGE);
1381 add_sym_2 ("lgt", 1, 0, BT_LOGICAL, dl,
1382 NULL, gfc_simplify_lgt, NULL,
1383 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1385 make_generic ("lgt", GFC_ISYM_LGT);
1387 add_sym_2 ("lle", 1, 0, BT_LOGICAL, dl,
1388 NULL, gfc_simplify_lle, NULL,
1389 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1391 make_generic ("lle", GFC_ISYM_LLE);
1393 add_sym_2 ("llt", 1, 0, BT_LOGICAL, dl,
1394 NULL, gfc_simplify_llt, NULL,
1395 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1397 make_generic ("llt", GFC_ISYM_LLT);
1399 add_sym_1 ("log", 1, 1, BT_REAL, dr,
1400 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dr, 0);
1402 add_sym_1 ("alog", 1, 1, BT_REAL, dr,
1403 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dr, 0);
1405 add_sym_1 ("dlog", 1, 1, BT_REAL, dd,
1406 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dd, 0);
1408 add_sym_1 ("clog", 1, 1, BT_COMPLEX, dz,
1409 NULL, gfc_simplify_log, gfc_resolve_log,
1410 x, BT_COMPLEX, dz, 0);
1412 add_sym_1 ("zlog", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_log, gfc_resolve_log, x, BT_COMPLEX, dd, 0); /* Extension */
1414 make_alias ("cdlog");
1416 make_generic ("log", GFC_ISYM_LOG);
1418 add_sym_1 ("log10", 1, 1, BT_REAL, dr,
1419 NULL, gfc_simplify_log10, gfc_resolve_log10,
1422 add_sym_1 ("alog10", 1, 1, BT_REAL, dr,
1423 NULL, gfc_simplify_log10, gfc_resolve_log10,
1426 add_sym_1 ("dlog10", 1, 1, BT_REAL, dd,
1427 NULL, gfc_simplify_log10, gfc_resolve_log10,
1430 make_generic ("log10", GFC_ISYM_LOG10);
1432 add_sym_2 ("logical", 0, 1, BT_LOGICAL, dl,
1433 gfc_check_logical, gfc_simplify_logical, gfc_resolve_logical,
1434 l, BT_LOGICAL, dl, 0, kind, BT_INTEGER, di, 1);
1436 make_generic ("logical", GFC_ISYM_LOGICAL);
1438 add_sym_2 ("matmul", 0, 1, BT_REAL, dr,
1439 gfc_check_matmul, NULL, gfc_resolve_matmul,
1440 ma, BT_REAL, dr, 0, mb, BT_REAL, dr, 0);
1442 make_generic ("matmul", GFC_ISYM_MATMUL);
1444 /* Note: amax0 is equivalent to real(max), max1 is equivalent to
1445 int(max). The max function must take at least two arguments. */
1447 add_sym_1m ("max", 1, 0, BT_UNKNOWN, 0,
1448 gfc_check_min_max, gfc_simplify_max, gfc_resolve_max,
1449 a1, BT_UNKNOWN, dr, 0, a2, BT_UNKNOWN, dr, 0);
1451 add_sym_1m ("max0", 1, 0, BT_INTEGER, di,
1452 gfc_check_min_max_integer, gfc_simplify_max, NULL,
1453 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1455 add_sym_1m ("amax0", 1, 0, BT_REAL, dr,
1456 gfc_check_min_max_integer, gfc_simplify_max, NULL,
1457 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1459 add_sym_1m ("amax1", 1, 0, BT_REAL, dr,
1460 gfc_check_min_max_real, gfc_simplify_max, NULL,
1461 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1463 add_sym_1m ("max1", 1, 0, BT_INTEGER, di,
1464 gfc_check_min_max_real, gfc_simplify_max, NULL,
1465 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1467 add_sym_1m ("dmax1", 1, 0, BT_REAL, dd,
1468 gfc_check_min_max_double, gfc_simplify_max, NULL,
1469 a1, BT_REAL, dd, 0, a2, BT_REAL, dd, 0);
1471 make_generic ("max", GFC_ISYM_MAX);
1473 add_sym_1 ("maxexponent", 0, 1, BT_INTEGER, di,
1474 gfc_check_x, gfc_simplify_maxexponent, NULL,
1475 x, BT_UNKNOWN, dr, 0);
1477 make_generic ("maxexponent", GFC_ISYM_NONE);
1479 add_sym_3ml ("maxloc", 0, 1, BT_INTEGER, di,
1480 gfc_check_minloc_maxloc, NULL, gfc_resolve_maxloc,
1481 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1482 msk, BT_LOGICAL, dl, 1);
1484 make_generic ("maxloc", GFC_ISYM_MAXLOC);
1486 add_sym_3red ("maxval", 0, 1, BT_REAL, dr,
1487 gfc_check_minval_maxval, NULL, gfc_resolve_maxval,
1488 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1489 msk, BT_LOGICAL, dl, 1);
1491 make_generic ("maxval", GFC_ISYM_MAXVAL);
1493 add_sym_3 ("merge", 1, 1, BT_REAL, dr,
1494 gfc_check_merge, NULL, gfc_resolve_merge,
1495 ts, BT_REAL, dr, 0, fs, BT_REAL, dr, 0,
1496 msk, BT_LOGICAL, dl, 0);
1498 make_generic ("merge", GFC_ISYM_MERGE);
1500 /* Note: amin0 is equivalent to real(min), min1 is equivalent to int(min). */
1502 add_sym_1m ("min", 1, 0, BT_UNKNOWN, 0,
1503 gfc_check_min_max, gfc_simplify_min, gfc_resolve_min,
1504 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1506 add_sym_1m ("min0", 1, 0, BT_INTEGER, di,
1507 gfc_check_min_max_integer, gfc_simplify_min, NULL,
1508 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1510 add_sym_1m ("amin0", 1, 0, BT_REAL, dr,
1511 gfc_check_min_max_integer, gfc_simplify_min, NULL,
1512 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1514 add_sym_1m ("amin1", 1, 0, BT_REAL, dr,
1515 gfc_check_min_max_real, gfc_simplify_min, NULL,
1516 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1518 add_sym_1m ("min1", 1, 0, BT_INTEGER, di,
1519 gfc_check_min_max_real, gfc_simplify_min, NULL,
1520 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1522 add_sym_1m ("dmin1", 1, 0, BT_REAL, dd,
1523 gfc_check_min_max_double, gfc_simplify_min, NULL,
1524 a1, BT_REAL, dd, 0, a2, BT_REAL, dd, 0);
1526 make_generic ("min", GFC_ISYM_MIN);
1528 add_sym_1 ("minexponent", 0, 1, BT_INTEGER, di,
1529 gfc_check_x, gfc_simplify_minexponent, NULL,
1530 x, BT_UNKNOWN, dr, 0);
1532 make_generic ("minexponent", GFC_ISYM_NONE);
1534 add_sym_3ml ("minloc", 0, 1, BT_INTEGER, di,
1535 gfc_check_minloc_maxloc, NULL, gfc_resolve_minloc,
1536 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1537 msk, BT_LOGICAL, dl, 1);
1539 make_generic ("minloc", GFC_ISYM_MINLOC);
1541 add_sym_3red ("minval", 0, 1, BT_REAL, dr,
1542 gfc_check_minval_maxval, NULL, gfc_resolve_minval,
1543 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1544 msk, BT_LOGICAL, dl, 1);
1546 make_generic ("minval", GFC_ISYM_MINVAL);
1548 add_sym_2 ("mod", 1, 1, BT_INTEGER, di,
1549 gfc_check_a_p, gfc_simplify_mod, gfc_resolve_mod,
1550 a, BT_INTEGER, di, 0, p, BT_INTEGER, di, 0);
1552 add_sym_2 ("amod", 1, 1, BT_REAL, dr,
1553 NULL, gfc_simplify_mod, gfc_resolve_mod,
1554 a, BT_REAL, dr, 0, p, BT_REAL, dr, 0);
1556 add_sym_2 ("dmod", 1, 1, BT_REAL, dd,
1557 NULL, gfc_simplify_mod, gfc_resolve_mod,
1558 a, BT_REAL, dd, 0, p, BT_REAL, dd, 0);
1560 make_generic ("mod", GFC_ISYM_MOD);
1562 add_sym_2 ("modulo", 1, 1, BT_REAL, di,
1563 gfc_check_a_p, gfc_simplify_modulo, gfc_resolve_modulo,
1564 a, BT_REAL, di, 0, p, BT_REAL, di, 0);
1566 make_generic ("modulo", GFC_ISYM_MODULO);
1568 add_sym_2 ("nearest", 1, 1, BT_REAL, dr,
1569 gfc_check_nearest, gfc_simplify_nearest, gfc_resolve_nearest,
1570 x, BT_REAL, dr, 0, s, BT_REAL, dr, 0);
1572 make_generic ("nearest", GFC_ISYM_NEAREST);
1574 add_sym_2 ("nint", 1, 1, BT_INTEGER, di,
1575 gfc_check_a_ikind, gfc_simplify_nint, gfc_resolve_nint,
1576 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1578 add_sym_1 ("idnint", 1, 1, BT_INTEGER, di,
1579 gfc_check_idnint, gfc_simplify_idnint, gfc_resolve_idnint,
1582 make_generic ("nint", GFC_ISYM_NINT);
1584 add_sym_1 ("not", 1, 1, BT_INTEGER, di,
1585 gfc_check_i, gfc_simplify_not, gfc_resolve_not,
1586 i, BT_INTEGER, di, 0);
1588 make_generic ("not", GFC_ISYM_NOT);
1590 add_sym_1 ("null", 0, 1, BT_INTEGER, di,
1591 gfc_check_null, gfc_simplify_null, NULL,
1592 mo, BT_INTEGER, di, 1);
1594 make_generic ("null", GFC_ISYM_NONE);
1596 add_sym_3 ("pack", 0, 1, BT_REAL, dr,
1597 gfc_check_pack, NULL, gfc_resolve_pack,
1598 ar, BT_REAL, dr, 0, msk, BT_LOGICAL, dl, 0,
1601 make_generic ("pack", GFC_ISYM_PACK);
1603 add_sym_1 ("precision", 0, 1, BT_INTEGER, di,
1604 gfc_check_precision, gfc_simplify_precision, NULL,
1605 x, BT_UNKNOWN, 0, 0);
1607 make_generic ("precision", GFC_ISYM_NONE);
1609 add_sym_1 ("present", 0, 1, BT_LOGICAL, dl,
1610 gfc_check_present, NULL, NULL, a, BT_REAL, dr, 0);
1612 make_generic ("present", GFC_ISYM_PRESENT);
1614 add_sym_3red ("product", 0, 1, BT_REAL, dr,
1615 gfc_check_product_sum, NULL, gfc_resolve_product,
1616 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1617 msk, BT_LOGICAL, dl, 1);
1619 make_generic ("product", GFC_ISYM_PRODUCT);
1621 add_sym_1 ("radix", 0, 1, BT_INTEGER, di,
1622 gfc_check_radix, gfc_simplify_radix, NULL,
1623 x, BT_UNKNOWN, 0, 0);
1625 make_generic ("radix", GFC_ISYM_NONE);
1627 /* The following function is for G77 compatibility. */
1628 add_sym_1 ("rand", 0, 1, BT_REAL, 4,
1629 gfc_check_rand, NULL, NULL,
1630 i, BT_INTEGER, 4, 0);
1632 /* Compatibility with HP FORTRAN 77/iX Reference. Note, rand() and
1633 ran() use slightly different shoddy multiplicative congruential
1637 make_generic ("rand", GFC_ISYM_RAND);
1639 add_sym_1 ("range", 0, 1, BT_INTEGER, di,
1640 gfc_check_range, gfc_simplify_range, NULL,
1643 make_generic ("range", GFC_ISYM_NONE);
1645 add_sym_2 ("real", 1, 0, BT_REAL, dr,
1646 gfc_check_real, gfc_simplify_real, gfc_resolve_real,
1647 a, BT_UNKNOWN, dr, 0, kind, BT_INTEGER, di, 1);
1649 add_sym_1 ("float", 1, 0, BT_REAL, dr,
1650 NULL, gfc_simplify_float, NULL, a, BT_INTEGER, di, 0);
1652 add_sym_1 ("sngl", 1, 0, BT_REAL, dr,
1653 NULL, gfc_simplify_sngl, NULL, a, BT_REAL, dd, 0);
1655 make_generic ("real", GFC_ISYM_REAL);
1657 add_sym_2 ("repeat", 0, 1, BT_CHARACTER, dc,
1658 gfc_check_repeat, gfc_simplify_repeat, gfc_resolve_repeat,
1659 stg, BT_CHARACTER, dc, 0, n, BT_INTEGER, di, 0);
1661 make_generic ("repeat", GFC_ISYM_REPEAT);
1663 add_sym_4 ("reshape", 0, 1, BT_REAL, dr,
1664 gfc_check_reshape, gfc_simplify_reshape, gfc_resolve_reshape,
1665 src, BT_REAL, dr, 0, shp, BT_INTEGER, ii, 0,
1666 pad, BT_REAL, dr, 1, ord, BT_INTEGER, ii, 1);
1668 make_generic ("reshape", GFC_ISYM_RESHAPE);
1670 add_sym_1 ("rrspacing", 1, 1, BT_REAL, dr,
1671 gfc_check_x, gfc_simplify_rrspacing, gfc_resolve_rrspacing,
1674 make_generic ("rrspacing", GFC_ISYM_RRSPACING);
1676 add_sym_2 ("scale", 1, 1, BT_REAL, dr,
1677 gfc_check_scale, gfc_simplify_scale, gfc_resolve_scale,
1678 x, BT_REAL, dr, 0, i, BT_INTEGER, di, 0);
1680 make_generic ("scale", GFC_ISYM_SCALE);
1682 add_sym_3 ("scan", 1, 1, BT_INTEGER, di,
1683 gfc_check_scan, gfc_simplify_scan, gfc_resolve_scan,
1684 stg, BT_CHARACTER, dc, 0, set, BT_CHARACTER, dc, 0,
1685 bck, BT_LOGICAL, dl, 1);
1687 make_generic ("scan", GFC_ISYM_SCAN);
1689 /* Added for G77 compatibility garbage. */
1690 add_sym_0 ("second", 0, 1, BT_REAL, 4, NULL, NULL, NULL);
1692 make_generic ("second", GFC_ISYM_SECOND);
1694 add_sym_1 ("selected_int_kind", 0, 1, BT_INTEGER, di,
1695 NULL, gfc_simplify_selected_int_kind, NULL,
1696 r, BT_INTEGER, di, 0);
1698 make_generic ("selected_int_kind", GFC_ISYM_SI_KIND);
1700 add_sym_2 ("selected_real_kind", 0, 1, BT_INTEGER, di,
1701 gfc_check_selected_real_kind, gfc_simplify_selected_real_kind,
1702 NULL, p, BT_INTEGER, di, 1, r, BT_INTEGER, di, 1);
1704 make_generic ("selected_real_kind", GFC_ISYM_SR_KIND);
1706 add_sym_2 ("set_exponent", 1, 1, BT_REAL, dr,
1707 gfc_check_set_exponent, gfc_simplify_set_exponent,
1708 gfc_resolve_set_exponent,
1709 x, BT_REAL, dr, 0, i, BT_INTEGER, di, 0);
1711 make_generic ("set_exponent", GFC_ISYM_SET_EXPONENT);
1713 add_sym_1 ("shape", 0, 1, BT_INTEGER, di,
1714 gfc_check_shape, gfc_simplify_shape, gfc_resolve_shape,
1715 src, BT_REAL, dr, 0);
1717 make_generic ("shape", GFC_ISYM_SHAPE);
1719 add_sym_2 ("sign", 1, 1, BT_REAL, dr,
1720 gfc_check_sign, gfc_simplify_sign, gfc_resolve_sign,
1721 a, BT_REAL, dr, 0, b, BT_REAL, dr, 0);
1723 add_sym_2 ("isign", 1, 1, BT_INTEGER, di,
1724 NULL, gfc_simplify_sign, gfc_resolve_sign,
1725 a, BT_INTEGER, di, 0, b, BT_INTEGER, di, 0);
1727 add_sym_2 ("dsign", 1, 1, BT_REAL, dd,
1728 NULL, gfc_simplify_sign, gfc_resolve_sign,
1729 a, BT_REAL, dd, 0, b, BT_REAL, dd, 0);
1731 make_generic ("sign", GFC_ISYM_SIGN);
1733 add_sym_1 ("sin", 1, 1, BT_REAL, dr,
1734 NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_REAL, dr, 0);
1736 add_sym_1 ("dsin", 1, 1, BT_REAL, dd,
1737 NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_REAL, dd, 0);
1739 add_sym_1 ("csin", 1, 1, BT_COMPLEX, dz,
1740 NULL, gfc_simplify_sin, gfc_resolve_sin,
1741 x, BT_COMPLEX, dz, 0);
1743 add_sym_1 ("zsin", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_COMPLEX, dd, 0); /* Extension */
1745 make_alias ("cdsin");
1747 make_generic ("sin", GFC_ISYM_SIN);
1749 add_sym_1 ("sinh", 1, 1, BT_REAL, dr,
1750 NULL, gfc_simplify_sinh, gfc_resolve_sinh,
1753 add_sym_1 ("dsinh", 1, 1, BT_REAL, dd,
1754 NULL, gfc_simplify_sinh, gfc_resolve_sinh,
1757 make_generic ("sinh", GFC_ISYM_SINH);
1759 add_sym_2 ("size", 0, 1, BT_INTEGER, di,
1760 gfc_check_size, gfc_simplify_size, NULL,
1761 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1);
1763 make_generic ("size", GFC_ISYM_SIZE);
1765 add_sym_1 ("spacing", 1, 1, BT_REAL, dr,
1766 gfc_check_x, gfc_simplify_spacing, gfc_resolve_spacing,
1769 make_generic ("spacing", GFC_ISYM_SPACING);
1771 add_sym_3 ("spread", 0, 1, BT_REAL, dr,
1772 gfc_check_spread, NULL, gfc_resolve_spread,
1773 src, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 0,
1774 n, BT_INTEGER, di, 0);
1776 make_generic ("spread", GFC_ISYM_SPREAD);
1778 add_sym_1 ("sqrt", 1, 1, BT_REAL, dr,
1779 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1782 add_sym_1 ("dsqrt", 1, 1, BT_REAL, dd,
1783 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1786 add_sym_1 ("csqrt", 1, 1, BT_COMPLEX, dz,
1787 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1788 x, BT_COMPLEX, dz, 0);
1790 add_sym_1 ("zsqrt", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_sqrt, gfc_resolve_sqrt, x, BT_COMPLEX, dd, 0); /* Extension */
1792 make_alias ("cdsqrt");
1794 make_generic ("sqrt", GFC_ISYM_SQRT);
1796 add_sym_3red ("sum", 0, 1, BT_UNKNOWN, 0,
1797 gfc_check_product_sum, NULL, gfc_resolve_sum,
1798 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1799 msk, BT_LOGICAL, dl, 1);
1801 make_generic ("sum", GFC_ISYM_SUM);
1803 add_sym_1 ("tan", 1, 1, BT_REAL, dr,
1804 NULL, gfc_simplify_tan, gfc_resolve_tan, x, BT_REAL, dr, 0);
1806 add_sym_1 ("dtan", 1, 1, BT_REAL, dd,
1807 NULL, gfc_simplify_tan, gfc_resolve_tan, x, BT_REAL, dd, 0);
1809 make_generic ("tan", GFC_ISYM_TAN);
1811 add_sym_1 ("tanh", 1, 1, BT_REAL, dr,
1812 NULL, gfc_simplify_tanh, gfc_resolve_tanh,
1815 add_sym_1 ("dtanh", 1, 1, BT_REAL, dd,
1816 NULL, gfc_simplify_tanh, gfc_resolve_tanh,
1819 make_generic ("tanh", GFC_ISYM_TANH);
1821 add_sym_1 ("tiny", 0, 1, BT_REAL, dr,
1822 gfc_check_x, gfc_simplify_tiny, NULL, x, BT_REAL, dr, 0);
1824 make_generic ("tiny", GFC_ISYM_NONE);
1826 add_sym_3 ("transfer", 0, 1, BT_REAL, dr,
1827 gfc_check_transfer, NULL, gfc_resolve_transfer,
1828 src, BT_REAL, dr, 0, mo, BT_REAL, dr, 0,
1829 sz, BT_INTEGER, di, 1);
1831 make_generic ("transfer", GFC_ISYM_TRANSFER);
1833 add_sym_1 ("transpose", 0, 1, BT_REAL, dr,
1834 gfc_check_transpose, NULL, gfc_resolve_transpose,
1837 make_generic ("transpose", GFC_ISYM_TRANSPOSE);
1839 add_sym_1 ("trim", 0, 1, BT_CHARACTER, dc,
1840 gfc_check_trim, gfc_simplify_trim, gfc_resolve_trim,
1841 stg, BT_CHARACTER, dc, 0);
1843 make_generic ("trim", GFC_ISYM_TRIM);
1845 add_sym_2 ("ubound", 0, 1, BT_INTEGER, di,
1846 gfc_check_ubound, gfc_simplify_ubound, gfc_resolve_ubound,
1847 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1);
1849 make_generic ("ubound", GFC_ISYM_UBOUND);
1851 add_sym_3 ("unpack", 0, 1, BT_REAL, dr,
1852 gfc_check_unpack, NULL, gfc_resolve_unpack,
1853 v, BT_REAL, dr, 0, msk, BT_LOGICAL, dl, 0,
1856 make_generic ("unpack", GFC_ISYM_UNPACK);
1858 add_sym_3 ("verify", 1, 1, BT_INTEGER, di,
1859 gfc_check_verify, gfc_simplify_verify, gfc_resolve_verify,
1860 stg, BT_CHARACTER, dc, 0, set, BT_CHARACTER, dc, 0,
1861 bck, BT_LOGICAL, dl, 1);
1863 make_generic ("verify", GFC_ISYM_VERIFY);
1870 /* Add intrinsic subroutines. */
1873 add_subroutines (void)
1875 /* Argument names as in the standard (to be used as argument keywords). */
1877 *h = "harvest", *dt = "date", *vl = "values", *pt = "put",
1878 *c = "count", *tm = "time", *tp = "topos", *gt = "get",
1879 *t = "to", *zn = "zone", *fp = "frompos", *cm = "count_max",
1880 *f = "from", *sz = "size", *ln = "len", *cr = "count_rate",
1881 *com = "command", *length = "length", *st = "status",
1882 *val = "value", *num = "number", *name = "name",
1883 *trim_name = "trim_name";
1887 di = gfc_default_integer_kind;
1888 dr = gfc_default_real_kind;
1889 dc = gfc_default_character_kind;
1890 dl = gfc_default_logical_kind;
1892 add_sym_0s ("abort", 1, NULL);
1894 add_sym_1s ("cpu_time", 0, 1, BT_UNKNOWN, 0,
1895 gfc_check_cpu_time, NULL, gfc_resolve_cpu_time,
1896 tm, BT_REAL, dr, 0);
1898 /* More G77 compatibility garbage. */
1899 add_sym_1s ("second", 0, 1, BT_UNKNOWN, 0,
1900 gfc_check_second_sub, NULL, gfc_resolve_second_sub,
1901 tm, BT_REAL, dr, 0);
1903 add_sym_4s ("date_and_time", 0, 1, BT_UNKNOWN, 0,
1904 gfc_check_date_and_time, NULL, NULL,
1905 dt, BT_CHARACTER, dc, 1, tm, BT_CHARACTER, dc, 1,
1906 zn, BT_CHARACTER, dc, 1, vl, BT_INTEGER, di, 1);
1908 /* More G77 compatibility garbage. */
1909 add_sym_2s ("etime", 0, 1, BT_UNKNOWN, 0,
1910 gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
1911 vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
1913 add_sym_2s ("dtime", 0, 1, BT_UNKNOWN, 0,
1914 gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
1915 vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
1917 add_sym_2s ("getenv", 0, 1, BT_UNKNOWN, 0,
1919 name, BT_CHARACTER, dc, 0,
1920 val, BT_CHARACTER, dc, 0);
1922 add_sym_2s ("getarg", 0, 1, BT_UNKNOWN, 0,
1923 NULL, NULL, gfc_resolve_getarg,
1924 c, BT_INTEGER, di, 0, vl, BT_CHARACTER, dc, 0);
1926 /* F2003 commandline routines. */
1928 add_sym_3s ("get_command", 0, 1, BT_UNKNOWN, 0,
1929 NULL, NULL, gfc_resolve_get_command,
1930 com, BT_CHARACTER, dc, 1,
1931 length, BT_INTEGER, di, 1,
1932 st, BT_INTEGER, di, 1);
1934 add_sym_4s ("get_command_argument", 0, 1, BT_UNKNOWN, 0,
1935 NULL, NULL, gfc_resolve_get_command_argument,
1936 num, BT_INTEGER, di, 0,
1937 val, BT_CHARACTER, dc, 1,
1938 length, BT_INTEGER, di, 1,
1939 st, BT_INTEGER, di, 1);
1942 /* F2003 subroutine to get environment variables. */
1944 add_sym_5s ("get_environment_variable", 0, 1, BT_UNKNOWN, 0,
1945 NULL, NULL, gfc_resolve_get_environment_variable,
1946 name, BT_CHARACTER, dc, 0,
1947 val, BT_CHARACTER, dc, 1,
1948 length, BT_INTEGER, di, 1,
1949 st, BT_INTEGER, di, 1,
1950 trim_name, BT_LOGICAL, dl, 1);
1953 /* This needs changing to add_sym_5s if it gets a resolution function. */
1954 add_sym_5 ("mvbits", 1, 1, BT_UNKNOWN, 0,
1955 gfc_check_mvbits, gfc_simplify_mvbits, NULL,
1956 f, BT_INTEGER, di, 0, fp, BT_INTEGER, di, 0,
1957 ln, BT_INTEGER, di, 0, t, BT_INTEGER, di, 0,
1958 tp, BT_INTEGER, di, 0);
1960 add_sym_1s ("random_number", 0, 1, BT_UNKNOWN, 0,
1961 gfc_check_random_number, NULL, gfc_resolve_random_number,
1964 add_sym_3s ("random_seed", 0, 1, BT_UNKNOWN, 0,
1965 gfc_check_random_seed, NULL, NULL,
1966 sz, BT_INTEGER, di, 1, pt, BT_INTEGER, di, 1,
1967 gt, BT_INTEGER, di, 1);
1969 /* More G77 compatibility garbage. */
1970 add_sym_1s ("srand", 0, 1, BT_UNKNOWN, di,
1971 gfc_check_srand, NULL, gfc_resolve_srand,
1972 c, BT_INTEGER, 4, 0);
1974 add_sym_3s ("system_clock", 0, 1, BT_UNKNOWN, 0,
1975 gfc_check_system_clock, NULL, gfc_resolve_system_clock,
1976 c, BT_INTEGER, di, 1, cr, BT_INTEGER, di, 1,
1977 cm, BT_INTEGER, di, 1);
1981 /* Add a function to the list of conversion symbols. */
1984 add_conv (bt from_type, int from_kind, bt to_type, int to_kind,
1985 gfc_expr * (*simplify) (gfc_expr *, bt, int))
1988 gfc_typespec from, to;
1989 gfc_intrinsic_sym *sym;
1991 if (sizing == SZ_CONVS)
1997 gfc_clear_ts (&from);
1998 from.type = from_type;
1999 from.kind = from_kind;
2005 sym = conversion + nconv;
2007 strcpy (sym->name, conv_name (&from, &to));
2008 strcpy (sym->lib_name, sym->name);
2009 sym->simplify.cc = simplify;
2012 sym->generic_id = GFC_ISYM_CONVERSION;
2018 /* Create gfc_intrinsic_sym nodes for all intrinsic conversion
2019 functions by looping over the kind tables. */
2022 add_conversions (void)
2026 /* Integer-Integer conversions. */
2027 for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
2028 for (j = 0; gfc_integer_kinds[j].kind != 0; j++)
2033 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
2034 BT_INTEGER, gfc_integer_kinds[j].kind, gfc_convert_constant);
2037 /* Integer-Real/Complex conversions. */
2038 for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
2039 for (j = 0; gfc_real_kinds[j].kind != 0; j++)
2041 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
2042 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
2044 add_conv (BT_REAL, gfc_real_kinds[j].kind,
2045 BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant);
2047 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
2048 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
2050 add_conv (BT_COMPLEX, gfc_real_kinds[j].kind,
2051 BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant);
2054 /* Real/Complex - Real/Complex conversions. */
2055 for (i = 0; gfc_real_kinds[i].kind != 0; i++)
2056 for (j = 0; gfc_real_kinds[j].kind != 0; j++)
2060 add_conv (BT_REAL, gfc_real_kinds[i].kind,
2061 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
2063 add_conv (BT_COMPLEX, gfc_real_kinds[i].kind,
2064 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
2067 add_conv (BT_REAL, gfc_real_kinds[i].kind,
2068 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
2070 add_conv (BT_COMPLEX, gfc_real_kinds[i].kind,
2071 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
2074 /* Logical/Logical kind conversion. */
2075 for (i = 0; gfc_logical_kinds[i].kind; i++)
2076 for (j = 0; gfc_logical_kinds[j].kind; j++)
2081 add_conv (BT_LOGICAL, gfc_logical_kinds[i].kind,
2082 BT_LOGICAL, gfc_logical_kinds[j].kind, gfc_convert_constant);
2087 /* Initialize the table of intrinsics. */
2089 gfc_intrinsic_init_1 (void)
2093 nargs = nfunc = nsub = nconv = 0;
2095 /* Create a namespace to hold the resolved intrinsic symbols. */
2096 gfc_intrinsic_namespace = gfc_get_namespace (NULL);
2105 functions = gfc_getmem (sizeof (gfc_intrinsic_sym) * (nfunc + nsub)
2106 + sizeof (gfc_intrinsic_arg) * nargs);
2108 next_sym = functions;
2109 subroutines = functions + nfunc;
2111 conversion = gfc_getmem (sizeof (gfc_intrinsic_sym) * nconv);
2113 next_arg = ((gfc_intrinsic_arg *) (subroutines + nsub)) - 1;
2115 sizing = SZ_NOTHING;
2122 /* Set the pure flag. All intrinsic functions are pure, and
2123 intrinsic subroutines are pure if they are elemental. */
2125 for (i = 0; i < nfunc; i++)
2126 functions[i].pure = 1;
2128 for (i = 0; i < nsub; i++)
2129 subroutines[i].pure = subroutines[i].elemental;
2134 gfc_intrinsic_done_1 (void)
2136 gfc_free (functions);
2137 gfc_free (conversion);
2138 gfc_free_namespace (gfc_intrinsic_namespace);
2142 /******** Subroutines to check intrinsic interfaces ***********/
2144 /* Given a formal argument list, remove any NULL arguments that may
2145 have been left behind by a sort against some formal argument list. */
2148 remove_nullargs (gfc_actual_arglist ** ap)
2150 gfc_actual_arglist *head, *tail, *next;
2154 for (head = *ap; head; head = next)
2158 if (head->expr == NULL)
2161 gfc_free_actual_arglist (head);
2180 /* Given an actual arglist and a formal arglist, sort the actual
2181 arglist so that its arguments are in a one-to-one correspondence
2182 with the format arglist. Arguments that are not present are given
2183 a blank gfc_actual_arglist structure. If something is obviously
2184 wrong (say, a missing required argument) we abort sorting and
2188 sort_actual (const char *name, gfc_actual_arglist ** ap,
2189 gfc_intrinsic_arg * formal, locus * where)
2192 gfc_actual_arglist *actual, *a;
2193 gfc_intrinsic_arg *f;
2195 remove_nullargs (ap);
2198 for (f = formal; f; f = f->next)
2204 if (f == NULL && a == NULL) /* No arguments */
2208 { /* Put the nonkeyword arguments in a 1:1 correspondence */
2214 if (a->name[0] != '\0')
2226 gfc_error ("Too many arguments in call to '%s' at %L", name, where);
2230 /* Associate the remaining actual arguments, all of which have
2231 to be keyword arguments. */
2232 for (; a; a = a->next)
2234 for (f = formal; f; f = f->next)
2235 if (strcmp (a->name, f->name) == 0)
2240 gfc_error ("Can't find keyword named '%s' in call to '%s' at %L",
2241 a->name, name, where);
2245 if (f->actual != NULL)
2247 gfc_error ("Argument '%s' is appears twice in call to '%s' at %L",
2248 f->name, name, where);
2256 /* At this point, all unmatched formal args must be optional. */
2257 for (f = formal; f; f = f->next)
2259 if (f->actual == NULL && f->optional == 0)
2261 gfc_error ("Missing actual argument '%s' in call to '%s' at %L",
2262 f->name, name, where);
2268 /* Using the formal argument list, string the actual argument list
2269 together in a way that corresponds with the formal list. */
2272 for (f = formal; f; f = f->next)
2274 if (f->actual == NULL)
2276 a = gfc_get_actual_arglist ();
2277 a->missing_arg_type = f->ts.type;
2289 actual->next = NULL; /* End the sorted argument list. */
2295 /* Compare an actual argument list with an intrinsic's formal argument
2296 list. The lists are checked for agreement of type. We don't check
2297 for arrayness here. */
2300 check_arglist (gfc_actual_arglist ** ap, gfc_intrinsic_sym * sym,
2303 gfc_actual_arglist *actual;
2304 gfc_intrinsic_arg *formal;
2307 formal = sym->formal;
2311 for (; formal; formal = formal->next, actual = actual->next, i++)
2313 if (actual->expr == NULL)
2316 if (!gfc_compare_types (&formal->ts, &actual->expr->ts))
2320 ("Type of argument '%s' in call to '%s' at %L should be "
2321 "%s, not %s", gfc_current_intrinsic_arg[i],
2322 gfc_current_intrinsic, &actual->expr->where,
2323 gfc_typename (&formal->ts), gfc_typename (&actual->expr->ts));
2332 /* Given a pointer to an intrinsic symbol and an expression node that
2333 represent the function call to that subroutine, figure out the type
2334 of the result. This may involve calling a resolution subroutine. */
2337 resolve_intrinsic (gfc_intrinsic_sym * specific, gfc_expr * e)
2339 gfc_expr *a1, *a2, *a3, *a4, *a5;
2340 gfc_actual_arglist *arg;
2342 if (specific->resolve.f1 == NULL)
2344 if (e->value.function.name == NULL)
2345 e->value.function.name = specific->lib_name;
2347 if (e->ts.type == BT_UNKNOWN)
2348 e->ts = specific->ts;
2352 arg = e->value.function.actual;
2354 /* Special case hacks for MIN and MAX. */
2355 if (specific->resolve.f1m == gfc_resolve_max
2356 || specific->resolve.f1m == gfc_resolve_min)
2358 (*specific->resolve.f1m) (e, arg);
2364 (*specific->resolve.f0) (e);
2373 (*specific->resolve.f1) (e, a1);
2382 (*specific->resolve.f2) (e, a1, a2);
2391 (*specific->resolve.f3) (e, a1, a2, a3);
2400 (*specific->resolve.f4) (e, a1, a2, a3, a4);
2409 (*specific->resolve.f5) (e, a1, a2, a3, a4, a5);
2413 gfc_internal_error ("resolve_intrinsic(): Too many args for intrinsic");
2417 /* Given an intrinsic symbol node and an expression node, call the
2418 simplification function (if there is one), perhaps replacing the
2419 expression with something simpler. We return FAILURE on an error
2420 of the simplification, SUCCESS if the simplification worked, even
2421 if nothing has changed in the expression itself. */
2424 do_simplify (gfc_intrinsic_sym * specific, gfc_expr * e)
2426 gfc_expr *result, *a1, *a2, *a3, *a4, *a5;
2427 gfc_actual_arglist *arg;
2429 /* Max and min require special handling due to the variable number
2431 if (specific->simplify.f1 == gfc_simplify_min)
2433 result = gfc_simplify_min (e);
2437 if (specific->simplify.f1 == gfc_simplify_max)
2439 result = gfc_simplify_max (e);
2443 if (specific->simplify.f1 == NULL)
2449 arg = e->value.function.actual;
2453 result = (*specific->simplify.f0) ();
2460 if (specific->simplify.cc == gfc_convert_constant)
2462 result = gfc_convert_constant (a1, specific->ts.type, specific->ts.kind);
2466 /* TODO: Warn if -pedantic and initialization expression and arg
2467 types not integer or character */
2470 result = (*specific->simplify.f1) (a1);
2477 result = (*specific->simplify.f2) (a1, a2);
2484 result = (*specific->simplify.f3) (a1, a2, a3);
2491 result = (*specific->simplify.f4) (a1, a2, a3, a4);
2498 result = (*specific->simplify.f5) (a1, a2, a3, a4, a5);
2501 ("do_simplify(): Too many args for intrinsic");
2508 if (result == &gfc_bad_expr)
2512 resolve_intrinsic (specific, e); /* Must call at run-time */
2515 result->where = e->where;
2516 gfc_replace_expr (e, result);
2523 /* Initialize the gfc_current_intrinsic_arg[] array for the benefit of
2524 error messages. This subroutine returns FAILURE if a subroutine
2525 has more than MAX_INTRINSIC_ARGS, in which case the actual argument
2526 list cannot match any intrinsic. */
2529 init_arglist (gfc_intrinsic_sym * isym)
2531 gfc_intrinsic_arg *formal;
2534 gfc_current_intrinsic = isym->name;
2537 for (formal = isym->formal; formal; formal = formal->next)
2539 if (i >= MAX_INTRINSIC_ARGS)
2540 gfc_internal_error ("init_arglist(): too many arguments");
2541 gfc_current_intrinsic_arg[i++] = formal->name;
2546 /* Given a pointer to an intrinsic symbol and an expression consisting
2547 of a function call, see if the function call is consistent with the
2548 intrinsic's formal argument list. Return SUCCESS if the expression
2549 and intrinsic match, FAILURE otherwise. */
2552 check_specific (gfc_intrinsic_sym * specific, gfc_expr * expr, int error_flag)
2554 gfc_actual_arglist *arg, **ap;
2558 ap = &expr->value.function.actual;
2560 init_arglist (specific);
2562 /* Don't attempt to sort the argument list for min or max. */
2563 if (specific->check.f1m == gfc_check_min_max
2564 || specific->check.f1m == gfc_check_min_max_integer
2565 || specific->check.f1m == gfc_check_min_max_real
2566 || specific->check.f1m == gfc_check_min_max_double)
2567 return (*specific->check.f1m) (*ap);
2569 if (sort_actual (specific->name, ap, specific->formal,
2570 &expr->where) == FAILURE)
2573 if (specific->check.f3ml == gfc_check_minloc_maxloc)
2574 /* This is special because we might have to reorder the argument
2576 t = gfc_check_minloc_maxloc (*ap);
2577 else if (specific->check.f3red == gfc_check_minval_maxval)
2578 /* This is also special because we also might have to reorder the
2580 t = gfc_check_minval_maxval (*ap);
2581 else if (specific->check.f3red == gfc_check_product_sum)
2582 /* Same here. The difference to the previous case is that we allow a
2583 general numeric type. */
2584 t = gfc_check_product_sum (*ap);
2587 if (specific->check.f1 == NULL)
2589 t = check_arglist (ap, specific, error_flag);
2591 expr->ts = specific->ts;
2594 t = do_check (specific, *ap);
2597 /* Check ranks for elemental intrinsics. */
2598 if (t == SUCCESS && specific->elemental)
2601 for (arg = expr->value.function.actual; arg; arg = arg->next)
2603 if (arg->expr == NULL || arg->expr->rank == 0)
2607 r = arg->expr->rank;
2611 if (arg->expr->rank != r)
2614 ("Ranks of arguments to elemental intrinsic '%s' differ "
2615 "at %L", specific->name, &arg->expr->where);
2622 remove_nullargs (ap);
2628 /* See if an intrinsic is one of the intrinsics we evaluate
2632 gfc_init_expr_extensions (gfc_intrinsic_sym *isym)
2634 /* FIXME: This should be moved into the intrinsic definitions. */
2635 static const char * const init_expr_extensions[] = {
2636 "digits", "epsilon", "huge", "kind", "maxexponent", "minexponent",
2637 "precision", "present", "radix", "range", "selected_real_kind",
2643 for (i = 0; init_expr_extensions[i]; i++)
2644 if (strcmp (init_expr_extensions[i], isym->name) == 0)
2651 /* See if a function call corresponds to an intrinsic function call.
2654 MATCH_YES if the call corresponds to an intrinsic, simplification
2655 is done if possible.
2657 MATCH_NO if the call does not correspond to an intrinsic
2659 MATCH_ERROR if the call corresponds to an intrinsic but there was an
2660 error during the simplification process.
2662 The error_flag parameter enables an error reporting. */
2665 gfc_intrinsic_func_interface (gfc_expr * expr, int error_flag)
2667 gfc_intrinsic_sym *isym, *specific;
2668 gfc_actual_arglist *actual;
2672 if (expr->value.function.isym != NULL)
2673 return (do_simplify (expr->value.function.isym, expr) == FAILURE)
2674 ? MATCH_ERROR : MATCH_YES;
2676 gfc_suppress_error = !error_flag;
2679 for (actual = expr->value.function.actual; actual; actual = actual->next)
2680 if (actual->expr != NULL)
2681 flag |= (actual->expr->ts.type != BT_INTEGER
2682 && actual->expr->ts.type != BT_CHARACTER);
2684 name = expr->symtree->n.sym->name;
2686 isym = specific = gfc_find_function (name);
2689 gfc_suppress_error = 0;
2693 gfc_current_intrinsic_where = &expr->where;
2695 /* Bypass the generic list for min and max. */
2696 if (isym->check.f1m == gfc_check_min_max)
2698 init_arglist (isym);
2700 if (gfc_check_min_max (expr->value.function.actual) == SUCCESS)
2703 gfc_suppress_error = 0;
2707 /* If the function is generic, check all of its specific
2708 incarnations. If the generic name is also a specific, we check
2709 that name last, so that any error message will correspond to the
2711 gfc_suppress_error = 1;
2715 for (specific = isym->specific_head; specific;
2716 specific = specific->next)
2718 if (specific == isym)
2720 if (check_specific (specific, expr, 0) == SUCCESS)
2725 gfc_suppress_error = !error_flag;
2727 if (check_specific (isym, expr, error_flag) == FAILURE)
2729 gfc_suppress_error = 0;
2736 expr->value.function.isym = specific;
2737 gfc_intrinsic_symbol (expr->symtree->n.sym);
2739 if (do_simplify (specific, expr) == FAILURE)
2741 gfc_suppress_error = 0;
2745 /* TODO: We should probably only allow elemental functions here. */
2746 flag |= (expr->ts.type != BT_INTEGER && expr->ts.type != BT_CHARACTER);
2748 gfc_suppress_error = 0;
2749 if (pedantic && gfc_init_expr
2750 && flag && gfc_init_expr_extensions (specific))
2752 if (gfc_notify_std (GFC_STD_GNU, "Extension: Evaluation of "
2753 "nonstandard initialization expression at %L", &expr->where)
2764 /* See if a CALL statement corresponds to an intrinsic subroutine.
2765 Returns MATCH_YES if the subroutine corresponds to an intrinsic,
2766 MATCH_NO if not, and MATCH_ERROR if there was an error (but did
2770 gfc_intrinsic_sub_interface (gfc_code * c, int error_flag)
2772 gfc_intrinsic_sym *isym;
2775 name = c->symtree->n.sym->name;
2777 isym = find_subroutine (name);
2781 gfc_suppress_error = !error_flag;
2783 init_arglist (isym);
2785 if (sort_actual (name, &c->ext.actual, isym->formal, &c->loc) == FAILURE)
2788 if (isym->check.f1 != NULL)
2790 if (do_check (isym, c->ext.actual) == FAILURE)
2795 if (check_arglist (&c->ext.actual, isym, 1) == FAILURE)
2799 /* The subroutine corresponds to an intrinsic. Allow errors to be
2800 seen at this point. */
2801 gfc_suppress_error = 0;
2803 if (isym->resolve.s1 != NULL)
2804 isym->resolve.s1 (c);
2806 c->resolved_sym = gfc_get_intrinsic_sub_symbol (isym->lib_name);
2808 if (gfc_pure (NULL) && !isym->elemental)
2810 gfc_error ("Subroutine call to intrinsic '%s' at %L is not PURE", name,
2818 gfc_suppress_error = 0;
2823 /* Call gfc_convert_type() with warning enabled. */
2826 gfc_convert_type (gfc_expr * expr, gfc_typespec * ts, int eflag)
2828 return gfc_convert_type_warn (expr, ts, eflag, 1);
2832 /* Try to convert an expression (in place) from one type to another.
2833 'eflag' controls the behavior on error.
2835 The possible values are:
2837 1 Generate a gfc_error()
2838 2 Generate a gfc_internal_error().
2840 'wflag' controls the warning related to conversion. */
2843 gfc_convert_type_warn (gfc_expr * expr, gfc_typespec * ts, int eflag,
2846 gfc_intrinsic_sym *sym;
2847 gfc_typespec from_ts;
2852 from_ts = expr->ts; /* expr->ts gets clobbered */
2854 if (ts->type == BT_UNKNOWN)
2857 /* NULL and zero size arrays get their type here. */
2858 if (expr->expr_type == EXPR_NULL
2859 || (expr->expr_type == EXPR_ARRAY
2860 && expr->value.constructor == NULL))
2862 /* Sometimes the RHS acquire the type. */
2867 if (expr->ts.type == BT_UNKNOWN)
2870 if (expr->ts.type == BT_DERIVED
2871 && ts->type == BT_DERIVED
2872 && gfc_compare_types (&expr->ts, ts))
2875 sym = find_conv (&expr->ts, ts);
2879 /* At this point, a conversion is necessary. A warning may be needed. */
2880 if (wflag && gfc_option.warn_conversion)
2881 gfc_warning_now ("Conversion from %s to %s at %L",
2882 gfc_typename (&from_ts), gfc_typename (ts), &expr->where);
2884 /* Insert a pre-resolved function call to the right function. */
2885 old_where = expr->where;
2887 new = gfc_get_expr ();
2890 new = gfc_build_conversion (new);
2891 new->value.function.name = sym->lib_name;
2892 new->value.function.isym = sym;
2893 new->where = old_where;
2901 if (gfc_is_constant_expr (expr->value.function.actual->expr)
2902 && do_simplify (sym, expr) == FAILURE)
2907 return FAILURE; /* Error already generated in do_simplify() */
2915 gfc_error ("Can't convert %s to %s at %L",
2916 gfc_typename (&from_ts), gfc_typename (ts), &expr->where);
2920 gfc_internal_error ("Can't convert %s to %s at %L",
2921 gfc_typename (&from_ts), gfc_typename (ts),