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 /* Namespace 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_5s
605 const char *name, int elemental, int actual_ok, bt type, int kind,
606 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
607 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
608 void (*resolve)(gfc_code *),
609 const char* a1, bt type1, int kind1, int optional1,
610 const char* a2, bt type2, int kind2, int optional2,
611 const char* a3, bt type3, int kind3, int optional3,
612 const char* a4, bt type4, int kind4, int optional4,
613 const char* a5, bt type5, int kind5, int optional5)
623 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
624 a1, type1, kind1, optional1,
625 a2, type2, kind2, optional2,
626 a3, type3, kind3, optional3,
627 a4, type4, kind4, optional4,
628 a5, type5, kind5, optional5,
633 /* Locate an intrinsic symbol given a base pointer, number of elements
634 in the table and a pointer to a name. Returns the NULL pointer if
635 a name is not found. */
637 static gfc_intrinsic_sym *
638 find_sym (gfc_intrinsic_sym * start, int n, const char *name)
643 if (strcmp (name, start->name) == 0)
654 /* Given a name, find a function in the intrinsic function table.
655 Returns NULL if not found. */
658 gfc_find_function (const char *name)
661 return find_sym (functions, nfunc, name);
665 /* Given a name, find a function in the intrinsic subroutine table.
666 Returns NULL if not found. */
668 static gfc_intrinsic_sym *
669 find_subroutine (const char *name)
672 return find_sym (subroutines, nsub, name);
676 /* Given a string, figure out if it is the name of a generic intrinsic
680 gfc_generic_intrinsic (const char *name)
682 gfc_intrinsic_sym *sym;
684 sym = gfc_find_function (name);
685 return (sym == NULL) ? 0 : sym->generic;
689 /* Given a string, figure out if it is the name of a specific
690 intrinsic function or not. */
693 gfc_specific_intrinsic (const char *name)
695 gfc_intrinsic_sym *sym;
697 sym = gfc_find_function (name);
698 return (sym == NULL) ? 0 : sym->specific;
702 /* Given a string, figure out if it is the name of an intrinsic
703 subroutine or function. There are no generic intrinsic
704 subroutines, they are all specific. */
707 gfc_intrinsic_name (const char *name, int subroutine_flag)
710 return subroutine_flag ?
711 find_subroutine (name) != NULL : gfc_find_function (name) != NULL;
715 /* Collect a set of intrinsic functions into a generic collection.
716 The first argument is the name of the generic function, which is
717 also the name of a specific function. The rest of the specifics
718 currently in the table are placed into the list of specific
719 functions associated with that generic. */
722 make_generic (const char *name, gfc_generic_isym_id generic_id)
724 gfc_intrinsic_sym *g;
726 if (sizing != SZ_NOTHING)
729 g = gfc_find_function (name);
731 gfc_internal_error ("make_generic(): Can't find generic symbol '%s'",
736 g->generic_id = generic_id;
737 if ((g + 1)->name[0] != '\0')
738 g->specific_head = g + 1;
741 while (g->name[0] != '\0')
745 g->generic_id = generic_id;
754 /* Create a duplicate intrinsic function entry for the current
755 function, the only difference being the alternate name. Note that
756 we use argument lists more than once, but all argument lists are
757 freed as a single block. */
760 make_alias (const char *name)
774 next_sym[0] = next_sym[-1];
775 strcpy (next_sym->name, name);
785 /* Add intrinsic functions. */
791 /* Argument names as in the standard (to be used as argument keywords). */
793 *a = "a", *f = "field", *pt = "pointer", *tg = "target",
794 *b = "b", *m = "matrix", *ma = "matrix_a", *mb = "matrix_b",
795 *c = "c", *n = "ncopies", *pos = "pos", *bck = "back",
796 *i = "i", *v = "vector", *va = "vector_a", *vb = "vector_b",
797 *j = "j", *a1 = "a1", *fs = "fsource", *ts = "tsource",
798 *l = "l", *a2 = "a2", *mo = "mold", *ord = "order",
799 *p = "p", *ar = "array", *shp = "shape", *src = "source",
800 *r = "r", *bd = "boundary", *pad = "pad", *set = "set",
801 *s = "s", *dm = "dim", *kind = "kind", *msk = "mask",
802 *x = "x", *sh = "shift", *stg = "string", *ssg = "substring",
803 *y = "y", *sz = "size", *sta = "string_a", *stb = "string_b",
804 *z = "z", *ln = "len";
806 int di, dr, dd, dl, dc, dz, ii;
808 di = gfc_default_integer_kind;
809 dr = gfc_default_real_kind;
810 dd = gfc_default_double_kind;
811 dl = gfc_default_logical_kind;
812 dc = gfc_default_character_kind;
813 dz = gfc_default_complex_kind;
814 ii = gfc_index_integer_kind;
816 add_sym_1 ("abs", 1, 1, BT_REAL, dr,
817 gfc_check_abs, gfc_simplify_abs, gfc_resolve_abs,
820 add_sym_1 ("iabs", 1, 1, BT_INTEGER, di,
821 NULL, gfc_simplify_abs, gfc_resolve_abs,
822 a, BT_INTEGER, di, 0);
824 add_sym_1 ("dabs", 1, 1, BT_REAL, dd,
825 NULL, gfc_simplify_abs, gfc_resolve_abs, a, BT_REAL, dd, 0);
827 add_sym_1 ("cabs", 1, 1, BT_REAL, dr,
828 NULL, gfc_simplify_abs, gfc_resolve_abs,
829 a, BT_COMPLEX, dz, 0);
831 add_sym_1 ("zabs", 1, 1, BT_REAL, dd, NULL, gfc_simplify_abs, gfc_resolve_abs, a, BT_COMPLEX, dd, 0); /* Extension */
833 make_alias ("cdabs");
835 make_generic ("abs", GFC_ISYM_ABS);
837 add_sym_1 ("achar", 1, 1, BT_CHARACTER, dc,
838 NULL, gfc_simplify_achar, NULL, i, BT_INTEGER, di, 0);
840 make_generic ("achar", GFC_ISYM_ACHAR);
842 add_sym_1 ("acos", 1, 1, BT_REAL, dr,
843 NULL, gfc_simplify_acos, gfc_resolve_acos,
846 add_sym_1 ("dacos", 1, 1, BT_REAL, dd,
847 NULL, gfc_simplify_acos, gfc_resolve_acos,
850 make_generic ("acos", GFC_ISYM_ACOS);
852 add_sym_1 ("adjustl", 1, 1, BT_CHARACTER, dc,
853 NULL, gfc_simplify_adjustl, NULL, stg, BT_CHARACTER, dc, 0);
855 make_generic ("adjustl", GFC_ISYM_ADJUSTL);
857 add_sym_1 ("adjustr", 1, 1, BT_CHARACTER, dc,
858 NULL, gfc_simplify_adjustr, NULL, stg, BT_CHARACTER, dc, 0);
860 make_generic ("adjustr", GFC_ISYM_ADJUSTR);
862 add_sym_1 ("aimag", 1, 1, BT_REAL, dr,
863 NULL, gfc_simplify_aimag, gfc_resolve_aimag,
864 z, BT_COMPLEX, dz, 0);
866 add_sym_1 ("dimag", 1, 1, BT_REAL, dd, NULL, gfc_simplify_aimag, gfc_resolve_aimag, z, BT_COMPLEX, dd, 0); /* Extension */
868 make_generic ("aimag", GFC_ISYM_AIMAG);
870 add_sym_2 ("aint", 1, 1, BT_REAL, dr,
871 gfc_check_a_xkind, gfc_simplify_aint, gfc_resolve_aint,
872 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
874 add_sym_1 ("dint", 1, 1, BT_REAL, dd,
875 NULL, gfc_simplify_dint, gfc_resolve_dint,
878 make_generic ("aint", GFC_ISYM_AINT);
880 add_sym_2 ("all", 0, 1, BT_UNKNOWN, 0,
881 gfc_check_all_any, NULL, gfc_resolve_all,
882 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
884 make_generic ("all", GFC_ISYM_ALL);
886 add_sym_1 ("allocated", 0, 1, BT_LOGICAL, dl,
887 gfc_check_allocated, NULL, NULL, ar, BT_UNKNOWN, 0, 0);
889 make_generic ("allocated", GFC_ISYM_ALLOCATED);
891 add_sym_2 ("anint", 1, 1, BT_REAL, dr,
892 gfc_check_a_xkind, gfc_simplify_anint, gfc_resolve_anint,
893 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
895 add_sym_1 ("dnint", 1, 1, BT_REAL, dd,
896 NULL, gfc_simplify_dnint, gfc_resolve_dnint,
899 make_generic ("anint", GFC_ISYM_ANINT);
901 add_sym_2 ("any", 0, 1, BT_UNKNOWN, 0,
902 gfc_check_all_any, NULL, gfc_resolve_any,
903 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
905 make_generic ("any", GFC_ISYM_ANY);
907 add_sym_1 ("asin", 1, 1, BT_REAL, dr,
908 NULL, gfc_simplify_asin, gfc_resolve_asin,
911 add_sym_1 ("dasin", 1, 1, BT_REAL, dd,
912 NULL, gfc_simplify_asin, gfc_resolve_asin,
915 make_generic ("asin", GFC_ISYM_ASIN);
917 add_sym_2 ("associated", 0, 1, BT_LOGICAL, dl,
918 gfc_check_associated, NULL, NULL,
919 pt, BT_UNKNOWN, 0, 0, tg, BT_UNKNOWN, 0, 1);
921 make_generic ("associated", GFC_ISYM_ASSOCIATED);
923 add_sym_1 ("atan", 1, 1, BT_REAL, dr,
924 NULL, gfc_simplify_atan, gfc_resolve_atan,
927 add_sym_1 ("datan", 1, 1, BT_REAL, dd,
928 NULL, gfc_simplify_atan, gfc_resolve_atan,
931 make_generic ("atan", GFC_ISYM_ATAN);
933 add_sym_2 ("atan2", 1, 1, BT_REAL, dr,
934 gfc_check_atan2, gfc_simplify_atan2, gfc_resolve_atan2,
935 y, BT_REAL, dr, 0, x, BT_REAL, dr, 0);
937 add_sym_2 ("datan2", 1, 1, BT_REAL, dd,
938 NULL, gfc_simplify_atan2, gfc_resolve_atan2,
939 y, BT_REAL, dd, 0, x, BT_REAL, dd, 0);
941 make_generic ("atan2", GFC_ISYM_ATAN2);
943 /* Bessel and Neumann functions for G77 compatibility. */
945 add_sym_1 ("besj0", 1, 0, BT_REAL, dr,
946 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
949 add_sym_1 ("dbesj0", 1, 0, BT_REAL, dd,
950 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
953 make_generic ("besj0", GFC_ISYM_J0);
955 add_sym_1 ("besj1", 1, 0, BT_REAL, dr,
956 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
959 add_sym_1 ("dbesj1", 1, 0, BT_REAL, dd,
960 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
963 make_generic ("besj1", GFC_ISYM_J1);
965 add_sym_2 ("besjn", 1, 0, BT_REAL, dr,
966 gfc_check_besn, NULL, gfc_resolve_besn, n, BT_INTEGER, di, 1,
969 add_sym_2 ("dbesjn", 1, 0, BT_REAL, dd,
970 gfc_check_besn, NULL, gfc_resolve_besn, n, BT_INTEGER, di, 1,
973 make_generic ("besjn", GFC_ISYM_JN);
975 add_sym_1 ("besy0", 1, 0, BT_REAL, dr,
976 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
979 add_sym_1 ("dbesy0", 1, 0, BT_REAL, dd,
980 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
983 make_generic ("besy0", GFC_ISYM_Y0);
985 add_sym_1 ("besy1", 1, 0, BT_REAL, dr,
986 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
989 add_sym_1 ("dbesy1", 1, 0, BT_REAL, dd,
990 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
993 make_generic ("besy1", GFC_ISYM_Y1);
995 add_sym_2 ("besyn", 1, 0, BT_REAL, dr,
996 gfc_check_besn, NULL, gfc_resolve_besn, n, BT_INTEGER, di, 1,
999 add_sym_2 ("dbesyn", 1, 0, BT_REAL, dd,
1000 gfc_check_besn, NULL, gfc_resolve_besn, n, BT_INTEGER, di, 1,
1003 make_generic ("besyn", GFC_ISYM_YN);
1005 add_sym_1 ("bit_size", 0, 1, BT_INTEGER, di,
1006 gfc_check_i, gfc_simplify_bit_size, NULL,
1007 i, BT_INTEGER, di, 0);
1009 make_generic ("bit_size", GFC_ISYM_NONE);
1011 add_sym_2 ("btest", 1, 1, BT_LOGICAL, dl,
1012 gfc_check_btest, gfc_simplify_btest, gfc_resolve_btest,
1013 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1015 make_generic ("btest", GFC_ISYM_BTEST);
1017 add_sym_2 ("ceiling", 1, 1, BT_INTEGER, di,
1018 gfc_check_a_ikind, gfc_simplify_ceiling, gfc_resolve_ceiling,
1019 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1021 make_generic ("ceiling", GFC_ISYM_CEILING);
1023 add_sym_2 ("char", 1, 0, BT_CHARACTER, dc,
1024 gfc_check_char, gfc_simplify_char, gfc_resolve_char,
1025 i, BT_INTEGER, di, 0, kind, BT_INTEGER, di, 1);
1027 make_generic ("char", GFC_ISYM_CHAR);
1029 add_sym_3 ("cmplx", 1, 1, BT_COMPLEX, dz,
1030 gfc_check_cmplx, gfc_simplify_cmplx, gfc_resolve_cmplx,
1031 x, BT_UNKNOWN, dr, 0, y, BT_UNKNOWN, dr, 1,
1032 kind, BT_INTEGER, di, 1);
1034 make_generic ("cmplx", GFC_ISYM_CMPLX);
1036 /* Making dcmplx a specific of cmplx causes cmplx to return a double
1037 complex instead of the default complex. */
1039 add_sym_2 ("dcmplx", 1, 1, BT_COMPLEX, dd,
1040 gfc_check_dcmplx, gfc_simplify_dcmplx, gfc_resolve_dcmplx,
1041 x, BT_REAL, dd, 0, y, BT_REAL, dd, 1); /* Extension */
1043 make_generic ("dcmplx", GFC_ISYM_CMPLX);
1045 add_sym_1 ("conjg", 1, 1, BT_COMPLEX, dz,
1046 NULL, gfc_simplify_conjg, gfc_resolve_conjg,
1047 z, BT_COMPLEX, dz, 0);
1049 add_sym_1 ("dconjg", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_conjg, gfc_resolve_conjg, z, BT_COMPLEX, dd, 0); /* Extension */
1051 make_generic ("conjg", GFC_ISYM_CONJG);
1053 add_sym_1 ("cos", 1, 1, BT_REAL, dr,
1054 NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_REAL, dr, 0);
1056 add_sym_1 ("dcos", 1, 1, BT_REAL, dd,
1057 NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_REAL, dd, 0);
1059 add_sym_1 ("ccos", 1, 1, BT_COMPLEX, dz,
1060 NULL, gfc_simplify_cos, gfc_resolve_cos,
1061 x, BT_COMPLEX, dz, 0);
1063 add_sym_1 ("zcos", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_COMPLEX, dd, 0); /* Extension */
1065 make_alias ("cdcos");
1067 make_generic ("cos", GFC_ISYM_COS);
1069 add_sym_1 ("cosh", 1, 1, BT_REAL, dr,
1070 NULL, gfc_simplify_cosh, gfc_resolve_cosh,
1073 add_sym_1 ("dcosh", 1, 1, BT_REAL, dd,
1074 NULL, gfc_simplify_cosh, gfc_resolve_cosh,
1077 make_generic ("cosh", GFC_ISYM_COSH);
1079 add_sym_2 ("count", 0, 1, BT_INTEGER, di,
1080 gfc_check_count, NULL, gfc_resolve_count,
1081 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
1083 make_generic ("count", GFC_ISYM_COUNT);
1085 add_sym_3 ("cshift", 0, 1, BT_REAL, dr,
1086 gfc_check_cshift, NULL, gfc_resolve_cshift,
1087 ar, BT_REAL, dr, 0, sh, BT_INTEGER, di, 0,
1088 dm, BT_INTEGER, ii, 1);
1090 make_generic ("cshift", GFC_ISYM_CSHIFT);
1092 add_sym_1 ("dble", 1, 1, BT_REAL, dd,
1093 gfc_check_dble, gfc_simplify_dble, gfc_resolve_dble,
1096 make_alias ("dfloat");
1098 make_generic ("dble", GFC_ISYM_DBLE);
1100 add_sym_1 ("digits", 0, 1, BT_INTEGER, di,
1101 gfc_check_digits, gfc_simplify_digits, NULL,
1102 x, BT_UNKNOWN, dr, 0);
1104 make_generic ("digits", GFC_ISYM_NONE);
1106 add_sym_2 ("dim", 1, 1, BT_REAL, dr,
1107 gfc_check_a_p, gfc_simplify_dim, gfc_resolve_dim,
1108 x, BT_UNKNOWN, dr, 0, y, BT_UNKNOWN, dr, 0);
1110 add_sym_2 ("idim", 1, 1, BT_INTEGER, di,
1111 NULL, gfc_simplify_dim, gfc_resolve_dim,
1112 x, BT_INTEGER, di, 0, y, BT_INTEGER, di, 0);
1114 add_sym_2 ("ddim", 1, 1, BT_REAL, dd,
1115 NULL, gfc_simplify_dim, gfc_resolve_dim,
1116 x, BT_REAL, dd, 0, y, BT_REAL, dd, 0);
1118 make_generic ("dim", GFC_ISYM_DIM);
1120 add_sym_2 ("dot_product", 0, 1, BT_UNKNOWN, 0,
1121 gfc_check_dot_product, NULL, gfc_resolve_dot_product,
1122 va, BT_REAL, dr, 0, vb, BT_REAL, dr, 0);
1124 make_generic ("dot_product", GFC_ISYM_DOT_PRODUCT);
1126 add_sym_2 ("dprod", 1, 1, BT_REAL, dd,
1127 NULL, gfc_simplify_dprod, gfc_resolve_dprod,
1128 x, BT_REAL, dr, 0, y, BT_REAL, dr, 0);
1130 make_generic ("dprod", GFC_ISYM_DPROD);
1132 add_sym_1 ("dreal", 1, 0, BT_REAL, dd, NULL, NULL, NULL, a, BT_COMPLEX, dd, 0); /* Extension */
1134 make_generic ("dreal", GFC_ISYM_REAL);
1136 add_sym_4 ("eoshift", 0, 1, BT_REAL, dr,
1137 gfc_check_eoshift, NULL, gfc_resolve_eoshift,
1138 ar, BT_REAL, dr, 0, sh, BT_INTEGER, ii, 0,
1139 bd, BT_REAL, dr, 1, dm, BT_INTEGER, ii, 1);
1141 make_generic ("eoshift", GFC_ISYM_EOSHIFT);
1143 add_sym_1 ("epsilon", 0, 1, BT_REAL, dr,
1144 gfc_check_x, gfc_simplify_epsilon, NULL,
1147 make_generic ("epsilon", GFC_ISYM_NONE);
1149 /* G77 compatibility for the ERF() and ERFC() functions. */
1150 add_sym_1 ("erf", 1, 0, BT_REAL, dr,
1151 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1154 add_sym_1 ("derf", 1, 0, BT_REAL, dd,
1155 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1158 make_generic ("erf", GFC_ISYM_ERF);
1160 add_sym_1 ("erfc", 1, 0, BT_REAL, dr,
1161 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1164 add_sym_1 ("derfc", 1, 0, BT_REAL, dd,
1165 gfc_check_g77_math1, NULL, gfc_resolve_g77_math1,
1168 make_generic ("erfc", GFC_ISYM_ERFC);
1170 /* G77 compatibility */
1171 add_sym_1 ("etime", 0, 1, BT_REAL, 4,
1172 gfc_check_etime, NULL, NULL,
1175 make_alias ("dtime");
1177 make_generic ("etime", GFC_ISYM_ETIME);
1180 add_sym_1 ("exp", 1, 1, BT_REAL, dr,
1181 NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_REAL, dr, 0);
1183 add_sym_1 ("dexp", 1, 1, BT_REAL, dd,
1184 NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_REAL, dd, 0);
1186 add_sym_1 ("cexp", 1, 1, BT_COMPLEX, dz,
1187 NULL, gfc_simplify_exp, gfc_resolve_exp,
1188 x, BT_COMPLEX, dz, 0);
1190 add_sym_1 ("zexp", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_COMPLEX, dd, 0); /* Extension */
1192 make_alias ("cdexp");
1194 make_generic ("exp", GFC_ISYM_EXP);
1196 add_sym_1 ("exponent", 1, 1, BT_INTEGER, di,
1197 gfc_check_x, gfc_simplify_exponent, gfc_resolve_exponent,
1200 make_generic ("exponent", GFC_ISYM_EXPONENT);
1202 add_sym_2 ("floor", 1, 1, BT_INTEGER, di,
1203 gfc_check_a_ikind, gfc_simplify_floor, gfc_resolve_floor,
1204 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1206 make_generic ("floor", GFC_ISYM_FLOOR);
1208 add_sym_1 ("fraction", 1, 1, BT_REAL, dr,
1209 gfc_check_x, gfc_simplify_fraction, gfc_resolve_fraction,
1212 make_generic ("fraction", GFC_ISYM_FRACTION);
1214 /* Unix IDs (g77 compatibility) */
1215 add_sym_1 ("getcwd", 0, 1, BT_INTEGER, di, NULL, NULL, gfc_resolve_getcwd,
1216 c, BT_CHARACTER, dc, 0);
1217 make_generic ("getcwd", GFC_ISYM_GETCWD);
1219 add_sym_0 ("getgid", 1, 0, BT_INTEGER, di, NULL, NULL, gfc_resolve_getgid);
1220 make_generic ("getgid", GFC_ISYM_GETGID);
1222 add_sym_0 ("getpid", 1, 0, BT_INTEGER, di, NULL, NULL, gfc_resolve_getpid);
1223 make_generic ("getpid", GFC_ISYM_GETPID);
1225 add_sym_0 ("getuid", 1, 0, BT_INTEGER, di, NULL, NULL, gfc_resolve_getuid);
1226 make_generic ("getuid", GFC_ISYM_GETUID);
1228 add_sym_1 ("huge", 0, 1, BT_REAL, dr,
1229 gfc_check_huge, gfc_simplify_huge, NULL,
1230 x, BT_UNKNOWN, dr, 0);
1232 make_generic ("huge", GFC_ISYM_NONE);
1234 add_sym_1 ("iachar", 1, 1, BT_INTEGER, di,
1235 NULL, gfc_simplify_iachar, NULL, c, BT_CHARACTER, dc, 0);
1237 make_generic ("iachar", GFC_ISYM_IACHAR);
1239 add_sym_2 ("iand", 1, 1, BT_INTEGER, di,
1240 gfc_check_iand, gfc_simplify_iand, gfc_resolve_iand,
1241 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1243 make_generic ("iand", GFC_ISYM_IAND);
1245 add_sym_0 ("iargc", 1, 1, BT_INTEGER, di, NULL, NULL, NULL); /* Extension, takes no arguments */
1246 make_generic ("iargc", GFC_ISYM_IARGC);
1248 add_sym_0 ("command_argument_count", 1, 1, BT_INTEGER, di, NULL, NULL, NULL);
1249 make_generic ("command_argument_count", GFC_ISYM_COMMAND_ARGUMENT_COUNT);
1251 add_sym_2 ("ibclr", 1, 1, BT_INTEGER, di,
1252 gfc_check_ibclr, gfc_simplify_ibclr, gfc_resolve_ibclr,
1253 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1255 make_generic ("ibclr", GFC_ISYM_IBCLR);
1257 add_sym_3 ("ibits", 1, 1, BT_INTEGER, di,
1258 gfc_check_ibits, gfc_simplify_ibits, gfc_resolve_ibits,
1259 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0,
1260 ln, BT_INTEGER, di, 0);
1262 make_generic ("ibits", GFC_ISYM_IBITS);
1264 add_sym_2 ("ibset", 1, 1, BT_INTEGER, di,
1265 gfc_check_ibset, gfc_simplify_ibset, gfc_resolve_ibset,
1266 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1268 make_generic ("ibset", GFC_ISYM_IBSET);
1270 add_sym_1 ("ichar", 1, 0, BT_INTEGER, di,
1271 NULL, gfc_simplify_ichar, gfc_resolve_ichar,
1272 c, BT_CHARACTER, dc, 0);
1274 make_generic ("ichar", GFC_ISYM_ICHAR);
1276 add_sym_2 ("ieor", 1, 1, BT_INTEGER, di,
1277 gfc_check_ieor, gfc_simplify_ieor, gfc_resolve_ieor,
1278 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1280 make_generic ("ieor", GFC_ISYM_IEOR);
1282 add_sym_3 ("index", 1, 1, BT_INTEGER, di,
1283 gfc_check_index, gfc_simplify_index, NULL,
1284 stg, BT_CHARACTER, dc, 0, ssg, BT_CHARACTER, dc, 0,
1285 bck, BT_LOGICAL, dl, 1);
1287 make_generic ("index", GFC_ISYM_INDEX);
1289 add_sym_2 ("int", 1, 1, BT_INTEGER, di,
1290 gfc_check_int, gfc_simplify_int, gfc_resolve_int,
1291 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1293 add_sym_1 ("ifix", 1, 0, BT_INTEGER, di,
1294 NULL, gfc_simplify_ifix, NULL, a, BT_REAL, dr, 0);
1296 add_sym_1 ("idint", 1, 0, BT_INTEGER, di,
1297 NULL, gfc_simplify_idint, NULL, a, BT_REAL, dd, 0);
1299 make_generic ("int", GFC_ISYM_INT);
1301 add_sym_2 ("ior", 1, 1, BT_INTEGER, di,
1302 gfc_check_ior, gfc_simplify_ior, gfc_resolve_ior,
1303 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1305 make_generic ("ior", GFC_ISYM_IOR);
1307 /* The following function is for G77 compatibility. */
1308 add_sym_1 ("irand", 0, 1, BT_INTEGER, 4,
1309 gfc_check_irand, NULL, NULL,
1310 i, BT_INTEGER, 4, 0);
1312 make_generic ("irand", GFC_ISYM_IRAND);
1314 add_sym_2 ("ishft", 1, 1, BT_INTEGER, di,
1315 gfc_check_ishft, gfc_simplify_ishft, gfc_resolve_ishft,
1316 i, BT_INTEGER, di, 0, sh, BT_INTEGER, di, 0);
1318 make_generic ("ishft", GFC_ISYM_ISHFT);
1320 add_sym_3 ("ishftc", 1, 1, BT_INTEGER, di,
1321 gfc_check_ishftc, gfc_simplify_ishftc, gfc_resolve_ishftc,
1322 i, BT_INTEGER, di, 0, sh, BT_INTEGER, di, 0,
1323 sz, BT_INTEGER, di, 1);
1325 make_generic ("ishftc", GFC_ISYM_ISHFTC);
1327 add_sym_1 ("kind", 0, 1, BT_INTEGER, di,
1328 gfc_check_kind, gfc_simplify_kind, NULL, x, BT_REAL, dr, 0);
1330 make_generic ("kind", GFC_ISYM_NONE);
1332 add_sym_2 ("lbound", 0, 1, BT_INTEGER, di,
1333 gfc_check_lbound, gfc_simplify_lbound, gfc_resolve_lbound,
1334 ar, BT_REAL, dr, 0, dm, BT_INTEGER, di, 1);
1336 make_generic ("lbound", GFC_ISYM_LBOUND);
1338 add_sym_1 ("len", 0, 1, BT_INTEGER, di,
1339 NULL, gfc_simplify_len, gfc_resolve_len,
1340 stg, BT_CHARACTER, dc, 0);
1342 make_generic ("len", GFC_ISYM_LEN);
1344 add_sym_1 ("len_trim", 1, 1, BT_INTEGER, di,
1345 NULL, gfc_simplify_len_trim, gfc_resolve_len_trim,
1346 stg, BT_CHARACTER, dc, 0);
1348 make_generic ("len_trim", GFC_ISYM_LEN_TRIM);
1350 add_sym_2 ("lge", 1, 0, BT_LOGICAL, dl,
1351 NULL, gfc_simplify_lge, NULL,
1352 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1354 make_generic ("lge", GFC_ISYM_LGE);
1356 add_sym_2 ("lgt", 1, 0, BT_LOGICAL, dl,
1357 NULL, gfc_simplify_lgt, NULL,
1358 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1360 make_generic ("lgt", GFC_ISYM_LGT);
1362 add_sym_2 ("lle", 1, 0, BT_LOGICAL, dl,
1363 NULL, gfc_simplify_lle, NULL,
1364 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1366 make_generic ("lle", GFC_ISYM_LLE);
1368 add_sym_2 ("llt", 1, 0, BT_LOGICAL, dl,
1369 NULL, gfc_simplify_llt, NULL,
1370 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1372 make_generic ("llt", GFC_ISYM_LLT);
1374 add_sym_1 ("log", 1, 1, BT_REAL, dr,
1375 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dr, 0);
1377 add_sym_1 ("alog", 1, 1, BT_REAL, dr,
1378 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dr, 0);
1380 add_sym_1 ("dlog", 1, 1, BT_REAL, dd,
1381 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dd, 0);
1383 add_sym_1 ("clog", 1, 1, BT_COMPLEX, dz,
1384 NULL, gfc_simplify_log, gfc_resolve_log,
1385 x, BT_COMPLEX, dz, 0);
1387 add_sym_1 ("zlog", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_log, gfc_resolve_log, x, BT_COMPLEX, dd, 0); /* Extension */
1389 make_alias ("cdlog");
1391 make_generic ("log", GFC_ISYM_LOG);
1393 add_sym_1 ("log10", 1, 1, BT_REAL, dr,
1394 NULL, gfc_simplify_log10, gfc_resolve_log10,
1397 add_sym_1 ("alog10", 1, 1, BT_REAL, dr,
1398 NULL, gfc_simplify_log10, gfc_resolve_log10,
1401 add_sym_1 ("dlog10", 1, 1, BT_REAL, dd,
1402 NULL, gfc_simplify_log10, gfc_resolve_log10,
1405 make_generic ("log10", GFC_ISYM_LOG10);
1407 add_sym_2 ("logical", 0, 1, BT_LOGICAL, dl,
1408 gfc_check_logical, gfc_simplify_logical, gfc_resolve_logical,
1409 l, BT_LOGICAL, dl, 0, kind, BT_INTEGER, di, 1);
1411 make_generic ("logical", GFC_ISYM_LOGICAL);
1413 add_sym_2 ("matmul", 0, 1, BT_REAL, dr,
1414 gfc_check_matmul, NULL, gfc_resolve_matmul,
1415 ma, BT_REAL, dr, 0, mb, BT_REAL, dr, 0);
1417 make_generic ("matmul", GFC_ISYM_MATMUL);
1419 /* Note: amax0 is equivalent to real(max), max1 is equivalent to
1420 int(max). The max function must take at least two arguments. */
1422 add_sym_1m ("max", 1, 0, BT_UNKNOWN, 0,
1423 gfc_check_min_max, gfc_simplify_max, gfc_resolve_max,
1424 a1, BT_UNKNOWN, dr, 0, a2, BT_UNKNOWN, dr, 0);
1426 add_sym_1m ("max0", 1, 0, BT_INTEGER, di,
1427 gfc_check_min_max_integer, gfc_simplify_max, NULL,
1428 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1430 add_sym_1m ("amax0", 1, 0, BT_REAL, dr,
1431 gfc_check_min_max_integer, gfc_simplify_max, NULL,
1432 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1434 add_sym_1m ("amax1", 1, 0, BT_REAL, dr,
1435 gfc_check_min_max_real, gfc_simplify_max, NULL,
1436 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1438 add_sym_1m ("max1", 1, 0, BT_INTEGER, di,
1439 gfc_check_min_max_real, gfc_simplify_max, NULL,
1440 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1442 add_sym_1m ("dmax1", 1, 0, BT_REAL, dd,
1443 gfc_check_min_max_double, gfc_simplify_max, NULL,
1444 a1, BT_REAL, dd, 0, a2, BT_REAL, dd, 0);
1446 make_generic ("max", GFC_ISYM_MAX);
1448 add_sym_1 ("maxexponent", 0, 1, BT_INTEGER, di,
1449 gfc_check_x, gfc_simplify_maxexponent, NULL,
1450 x, BT_UNKNOWN, dr, 0);
1452 make_generic ("maxexponent", GFC_ISYM_NONE);
1454 add_sym_3ml ("maxloc", 0, 1, BT_INTEGER, di,
1455 gfc_check_minloc_maxloc, NULL, gfc_resolve_maxloc,
1456 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1457 msk, BT_LOGICAL, dl, 1);
1459 make_generic ("maxloc", GFC_ISYM_MAXLOC);
1461 add_sym_3red ("maxval", 0, 1, BT_REAL, dr,
1462 gfc_check_minval_maxval, NULL, gfc_resolve_maxval,
1463 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1464 msk, BT_LOGICAL, dl, 1);
1466 make_generic ("maxval", GFC_ISYM_MAXVAL);
1468 add_sym_3 ("merge", 1, 1, BT_REAL, dr,
1469 gfc_check_merge, NULL, gfc_resolve_merge,
1470 ts, BT_REAL, dr, 0, fs, BT_REAL, dr, 0,
1471 msk, BT_LOGICAL, dl, 0);
1473 make_generic ("merge", GFC_ISYM_MERGE);
1475 /* Note: amin0 is equivalent to real(min), min1 is equivalent to int(min). */
1477 add_sym_1m ("min", 1, 0, BT_UNKNOWN, 0,
1478 gfc_check_min_max, gfc_simplify_min, gfc_resolve_min,
1479 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1481 add_sym_1m ("min0", 1, 0, BT_INTEGER, di,
1482 gfc_check_min_max_integer, gfc_simplify_min, NULL,
1483 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1485 add_sym_1m ("amin0", 1, 0, BT_REAL, dr,
1486 gfc_check_min_max_integer, gfc_simplify_min, NULL,
1487 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1489 add_sym_1m ("amin1", 1, 0, BT_REAL, dr,
1490 gfc_check_min_max_real, gfc_simplify_min, NULL,
1491 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1493 add_sym_1m ("min1", 1, 0, BT_INTEGER, di,
1494 gfc_check_min_max_real, gfc_simplify_min, NULL,
1495 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1497 add_sym_1m ("dmin1", 1, 0, BT_REAL, dd,
1498 gfc_check_min_max_double, gfc_simplify_min, NULL,
1499 a1, BT_REAL, dd, 0, a2, BT_REAL, dd, 0);
1501 make_generic ("min", GFC_ISYM_MIN);
1503 add_sym_1 ("minexponent", 0, 1, BT_INTEGER, di,
1504 gfc_check_x, gfc_simplify_minexponent, NULL,
1505 x, BT_UNKNOWN, dr, 0);
1507 make_generic ("minexponent", GFC_ISYM_NONE);
1509 add_sym_3ml ("minloc", 0, 1, BT_INTEGER, di,
1510 gfc_check_minloc_maxloc, NULL, gfc_resolve_minloc,
1511 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1512 msk, BT_LOGICAL, dl, 1);
1514 make_generic ("minloc", GFC_ISYM_MINLOC);
1516 add_sym_3red ("minval", 0, 1, BT_REAL, dr,
1517 gfc_check_minval_maxval, NULL, gfc_resolve_minval,
1518 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1519 msk, BT_LOGICAL, dl, 1);
1521 make_generic ("minval", GFC_ISYM_MINVAL);
1523 add_sym_2 ("mod", 1, 1, BT_INTEGER, di,
1524 gfc_check_a_p, gfc_simplify_mod, gfc_resolve_mod,
1525 a, BT_INTEGER, di, 0, p, BT_INTEGER, di, 0);
1527 add_sym_2 ("amod", 1, 1, BT_REAL, dr,
1528 NULL, gfc_simplify_mod, gfc_resolve_mod,
1529 a, BT_REAL, dr, 0, p, BT_REAL, dr, 0);
1531 add_sym_2 ("dmod", 1, 1, BT_REAL, dd,
1532 NULL, gfc_simplify_mod, gfc_resolve_mod,
1533 a, BT_REAL, dd, 0, p, BT_REAL, dd, 0);
1535 make_generic ("mod", GFC_ISYM_MOD);
1537 add_sym_2 ("modulo", 1, 1, BT_REAL, di,
1538 gfc_check_a_p, gfc_simplify_modulo, gfc_resolve_modulo,
1539 a, BT_REAL, di, 0, p, BT_REAL, di, 0);
1541 make_generic ("modulo", GFC_ISYM_MODULO);
1543 add_sym_2 ("nearest", 1, 1, BT_REAL, dr,
1544 gfc_check_nearest, gfc_simplify_nearest, gfc_resolve_nearest,
1545 x, BT_REAL, dr, 0, s, BT_REAL, dr, 0);
1547 make_generic ("nearest", GFC_ISYM_NEAREST);
1549 add_sym_2 ("nint", 1, 1, BT_INTEGER, di,
1550 gfc_check_a_ikind, gfc_simplify_nint, gfc_resolve_nint,
1551 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1553 add_sym_1 ("idnint", 1, 1, BT_INTEGER, di,
1554 gfc_check_idnint, gfc_simplify_idnint, gfc_resolve_idnint,
1557 make_generic ("nint", GFC_ISYM_NINT);
1559 add_sym_1 ("not", 1, 1, BT_INTEGER, di,
1560 gfc_check_i, gfc_simplify_not, gfc_resolve_not,
1561 i, BT_INTEGER, di, 0);
1563 make_generic ("not", GFC_ISYM_NOT);
1565 add_sym_1 ("null", 0, 1, BT_INTEGER, di,
1566 gfc_check_null, gfc_simplify_null, NULL,
1567 mo, BT_INTEGER, di, 1);
1569 make_generic ("null", GFC_ISYM_NONE);
1571 add_sym_3 ("pack", 0, 1, BT_REAL, dr,
1572 gfc_check_pack, NULL, gfc_resolve_pack,
1573 ar, BT_REAL, dr, 0, msk, BT_LOGICAL, dl, 0,
1576 make_generic ("pack", GFC_ISYM_PACK);
1578 add_sym_1 ("precision", 0, 1, BT_INTEGER, di,
1579 gfc_check_precision, gfc_simplify_precision, NULL,
1580 x, BT_UNKNOWN, 0, 0);
1582 make_generic ("precision", GFC_ISYM_NONE);
1584 add_sym_1 ("present", 0, 1, BT_LOGICAL, dl,
1585 gfc_check_present, NULL, NULL, a, BT_REAL, dr, 0);
1587 make_generic ("present", GFC_ISYM_PRESENT);
1589 add_sym_3red ("product", 0, 1, BT_REAL, dr,
1590 gfc_check_product_sum, NULL, gfc_resolve_product,
1591 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1592 msk, BT_LOGICAL, dl, 1);
1594 make_generic ("product", GFC_ISYM_PRODUCT);
1596 add_sym_1 ("radix", 0, 1, BT_INTEGER, di,
1597 gfc_check_radix, gfc_simplify_radix, NULL,
1598 x, BT_UNKNOWN, 0, 0);
1600 make_generic ("radix", GFC_ISYM_NONE);
1602 /* The following function is for G77 compatibility. */
1603 add_sym_1 ("rand", 0, 1, BT_REAL, 4,
1604 gfc_check_rand, NULL, NULL,
1605 i, BT_INTEGER, 4, 0);
1607 /* Compatibility with HP FORTRAN 77/iX Reference. Note, rand() and
1608 ran() use slightly different shoddy multiplicative congruential
1612 make_generic ("rand", GFC_ISYM_RAND);
1614 add_sym_1 ("range", 0, 1, BT_INTEGER, di,
1615 gfc_check_range, gfc_simplify_range, NULL,
1618 make_generic ("range", GFC_ISYM_NONE);
1620 add_sym_2 ("real", 1, 0, BT_REAL, dr,
1621 gfc_check_real, gfc_simplify_real, gfc_resolve_real,
1622 a, BT_UNKNOWN, dr, 0, kind, BT_INTEGER, di, 1);
1624 add_sym_1 ("float", 1, 0, BT_REAL, dr,
1625 NULL, gfc_simplify_float, NULL, a, BT_INTEGER, di, 0);
1627 add_sym_1 ("sngl", 1, 0, BT_REAL, dr,
1628 NULL, gfc_simplify_sngl, NULL, a, BT_REAL, dd, 0);
1630 make_generic ("real", GFC_ISYM_REAL);
1632 add_sym_2 ("repeat", 0, 1, BT_CHARACTER, dc,
1633 gfc_check_repeat, gfc_simplify_repeat, gfc_resolve_repeat,
1634 stg, BT_CHARACTER, dc, 0, n, BT_INTEGER, di, 0);
1636 make_generic ("repeat", GFC_ISYM_REPEAT);
1638 add_sym_4 ("reshape", 0, 1, BT_REAL, dr,
1639 gfc_check_reshape, gfc_simplify_reshape, gfc_resolve_reshape,
1640 src, BT_REAL, dr, 0, shp, BT_INTEGER, ii, 0,
1641 pad, BT_REAL, dr, 1, ord, BT_INTEGER, ii, 1);
1643 make_generic ("reshape", GFC_ISYM_RESHAPE);
1645 add_sym_1 ("rrspacing", 1, 1, BT_REAL, dr,
1646 gfc_check_x, gfc_simplify_rrspacing, gfc_resolve_rrspacing,
1649 make_generic ("rrspacing", GFC_ISYM_RRSPACING);
1651 add_sym_2 ("scale", 1, 1, BT_REAL, dr,
1652 gfc_check_scale, gfc_simplify_scale, gfc_resolve_scale,
1653 x, BT_REAL, dr, 0, i, BT_INTEGER, di, 0);
1655 make_generic ("scale", GFC_ISYM_SCALE);
1657 add_sym_3 ("scan", 1, 1, BT_INTEGER, di,
1658 gfc_check_scan, gfc_simplify_scan, gfc_resolve_scan,
1659 stg, BT_CHARACTER, dc, 0, set, BT_CHARACTER, dc, 0,
1660 bck, BT_LOGICAL, dl, 1);
1662 make_generic ("scan", GFC_ISYM_SCAN);
1664 /* Added for G77 compatibility garbage. */
1665 add_sym_0 ("second", 0, 1, BT_REAL, 4, NULL, NULL, NULL);
1667 make_generic ("second", GFC_ISYM_SECOND);
1669 add_sym_1 ("selected_int_kind", 0, 1, BT_INTEGER, di,
1670 NULL, gfc_simplify_selected_int_kind, NULL,
1671 r, BT_INTEGER, di, 0);
1673 make_generic ("selected_int_kind", GFC_ISYM_SI_KIND);
1675 add_sym_2 ("selected_real_kind", 0, 1, BT_INTEGER, di,
1676 gfc_check_selected_real_kind, gfc_simplify_selected_real_kind,
1677 NULL, p, BT_INTEGER, di, 1, r, BT_INTEGER, di, 1);
1679 make_generic ("selected_real_kind", GFC_ISYM_SR_KIND);
1681 add_sym_2 ("set_exponent", 1, 1, BT_REAL, dr,
1682 gfc_check_set_exponent, gfc_simplify_set_exponent,
1683 gfc_resolve_set_exponent,
1684 x, BT_REAL, dr, 0, i, BT_INTEGER, di, 0);
1686 make_generic ("set_exponent", GFC_ISYM_SET_EXPONENT);
1688 add_sym_1 ("shape", 0, 1, BT_INTEGER, di,
1689 gfc_check_shape, gfc_simplify_shape, gfc_resolve_shape,
1690 src, BT_REAL, dr, 0);
1692 make_generic ("shape", GFC_ISYM_SHAPE);
1694 add_sym_2 ("sign", 1, 1, BT_REAL, dr,
1695 gfc_check_sign, gfc_simplify_sign, gfc_resolve_sign,
1696 a, BT_REAL, dr, 0, b, BT_REAL, dr, 0);
1698 add_sym_2 ("isign", 1, 1, BT_INTEGER, di,
1699 NULL, gfc_simplify_sign, gfc_resolve_sign,
1700 a, BT_INTEGER, di, 0, b, BT_INTEGER, di, 0);
1702 add_sym_2 ("dsign", 1, 1, BT_REAL, dd,
1703 NULL, gfc_simplify_sign, gfc_resolve_sign,
1704 a, BT_REAL, dd, 0, b, BT_REAL, dd, 0);
1706 make_generic ("sign", GFC_ISYM_SIGN);
1708 add_sym_1 ("sin", 1, 1, BT_REAL, dr,
1709 NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_REAL, dr, 0);
1711 add_sym_1 ("dsin", 1, 1, BT_REAL, dd,
1712 NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_REAL, dd, 0);
1714 add_sym_1 ("csin", 1, 1, BT_COMPLEX, dz,
1715 NULL, gfc_simplify_sin, gfc_resolve_sin,
1716 x, BT_COMPLEX, dz, 0);
1718 add_sym_1 ("zsin", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_COMPLEX, dd, 0); /* Extension */
1720 make_alias ("cdsin");
1722 make_generic ("sin", GFC_ISYM_SIN);
1724 add_sym_1 ("sinh", 1, 1, BT_REAL, dr,
1725 NULL, gfc_simplify_sinh, gfc_resolve_sinh,
1728 add_sym_1 ("dsinh", 1, 1, BT_REAL, dd,
1729 NULL, gfc_simplify_sinh, gfc_resolve_sinh,
1732 make_generic ("sinh", GFC_ISYM_SINH);
1734 add_sym_2 ("size", 0, 1, BT_INTEGER, di,
1735 gfc_check_size, gfc_simplify_size, NULL,
1736 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1);
1738 make_generic ("size", GFC_ISYM_SIZE);
1740 add_sym_1 ("spacing", 1, 1, BT_REAL, dr,
1741 gfc_check_x, gfc_simplify_spacing, gfc_resolve_spacing,
1744 make_generic ("spacing", GFC_ISYM_SPACING);
1746 add_sym_3 ("spread", 0, 1, BT_REAL, dr,
1747 gfc_check_spread, NULL, gfc_resolve_spread,
1748 src, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 0,
1749 n, BT_INTEGER, di, 0);
1751 make_generic ("spread", GFC_ISYM_SPREAD);
1753 add_sym_1 ("sqrt", 1, 1, BT_REAL, dr,
1754 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1757 add_sym_1 ("dsqrt", 1, 1, BT_REAL, dd,
1758 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1761 add_sym_1 ("csqrt", 1, 1, BT_COMPLEX, dz,
1762 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1763 x, BT_COMPLEX, dz, 0);
1765 add_sym_1 ("zsqrt", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_sqrt, gfc_resolve_sqrt, x, BT_COMPLEX, dd, 0); /* Extension */
1767 make_alias ("cdsqrt");
1769 make_generic ("sqrt", GFC_ISYM_SQRT);
1771 add_sym_3red ("sum", 0, 1, BT_UNKNOWN, 0,
1772 gfc_check_product_sum, NULL, gfc_resolve_sum,
1773 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1774 msk, BT_LOGICAL, dl, 1);
1776 make_generic ("sum", GFC_ISYM_SUM);
1778 add_sym_1 ("system", 1, 1, BT_INTEGER, di, NULL, NULL, NULL,
1779 c, BT_CHARACTER, dc, 0);
1780 make_generic ("system", GFC_ISYM_SYSTEM);
1782 add_sym_1 ("tan", 1, 1, BT_REAL, dr,
1783 NULL, gfc_simplify_tan, gfc_resolve_tan, x, BT_REAL, dr, 0);
1785 add_sym_1 ("dtan", 1, 1, BT_REAL, dd,
1786 NULL, gfc_simplify_tan, gfc_resolve_tan, x, BT_REAL, dd, 0);
1788 make_generic ("tan", GFC_ISYM_TAN);
1790 add_sym_1 ("tanh", 1, 1, BT_REAL, dr,
1791 NULL, gfc_simplify_tanh, gfc_resolve_tanh,
1794 add_sym_1 ("dtanh", 1, 1, BT_REAL, dd,
1795 NULL, gfc_simplify_tanh, gfc_resolve_tanh,
1798 make_generic ("tanh", GFC_ISYM_TANH);
1800 add_sym_1 ("tiny", 0, 1, BT_REAL, dr,
1801 gfc_check_x, gfc_simplify_tiny, NULL, x, BT_REAL, dr, 0);
1803 make_generic ("tiny", GFC_ISYM_NONE);
1805 add_sym_3 ("transfer", 0, 1, BT_REAL, dr,
1806 gfc_check_transfer, NULL, gfc_resolve_transfer,
1807 src, BT_REAL, dr, 0, mo, BT_REAL, dr, 0,
1808 sz, BT_INTEGER, di, 1);
1810 make_generic ("transfer", GFC_ISYM_TRANSFER);
1812 add_sym_1 ("transpose", 0, 1, BT_REAL, dr,
1813 gfc_check_transpose, NULL, gfc_resolve_transpose,
1816 make_generic ("transpose", GFC_ISYM_TRANSPOSE);
1818 add_sym_1 ("trim", 0, 1, BT_CHARACTER, dc,
1819 gfc_check_trim, gfc_simplify_trim, gfc_resolve_trim,
1820 stg, BT_CHARACTER, dc, 0);
1822 make_generic ("trim", GFC_ISYM_TRIM);
1824 add_sym_2 ("ubound", 0, 1, BT_INTEGER, di,
1825 gfc_check_ubound, gfc_simplify_ubound, gfc_resolve_ubound,
1826 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1);
1828 make_generic ("ubound", GFC_ISYM_UBOUND);
1830 add_sym_3 ("unpack", 0, 1, BT_REAL, dr,
1831 gfc_check_unpack, NULL, gfc_resolve_unpack,
1832 v, BT_REAL, dr, 0, msk, BT_LOGICAL, dl, 0,
1835 make_generic ("unpack", GFC_ISYM_UNPACK);
1837 add_sym_3 ("verify", 1, 1, BT_INTEGER, di,
1838 gfc_check_verify, gfc_simplify_verify, gfc_resolve_verify,
1839 stg, BT_CHARACTER, dc, 0, set, BT_CHARACTER, dc, 0,
1840 bck, BT_LOGICAL, dl, 1);
1842 make_generic ("verify", GFC_ISYM_VERIFY);
1849 /* Add intrinsic subroutines. */
1852 add_subroutines (void)
1854 /* Argument names as in the standard (to be used as argument keywords). */
1856 *h = "harvest", *dt = "date", *vl = "values", *pt = "put",
1857 *c = "count", *tm = "time", *tp = "topos", *gt = "get",
1858 *t = "to", *zn = "zone", *fp = "frompos", *cm = "count_max",
1859 *f = "from", *sz = "size", *ln = "len", *cr = "count_rate",
1860 *com = "command", *length = "length", *st = "status",
1861 *val = "value", *num = "number", *name = "name",
1862 *trim_name = "trim_name";
1866 di = gfc_default_integer_kind;
1867 dr = gfc_default_real_kind;
1868 dc = gfc_default_character_kind;
1869 dl = gfc_default_logical_kind;
1871 add_sym_0s ("abort", 1, NULL);
1873 add_sym_1s ("cpu_time", 0, 1, BT_UNKNOWN, 0,
1874 gfc_check_cpu_time, NULL, gfc_resolve_cpu_time,
1875 tm, BT_REAL, dr, 0);
1877 /* More G77 compatibility garbage. */
1878 add_sym_1s ("second", 0, 1, BT_UNKNOWN, 0,
1879 gfc_check_second_sub, NULL, gfc_resolve_second_sub,
1880 tm, BT_REAL, dr, 0);
1882 add_sym_4s ("date_and_time", 0, 1, BT_UNKNOWN, 0,
1883 gfc_check_date_and_time, NULL, NULL,
1884 dt, BT_CHARACTER, dc, 1, tm, BT_CHARACTER, dc, 1,
1885 zn, BT_CHARACTER, dc, 1, vl, BT_INTEGER, di, 1);
1887 /* More G77 compatibility garbage. */
1888 add_sym_2s ("etime", 0, 1, BT_UNKNOWN, 0,
1889 gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
1890 vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
1892 add_sym_2s ("dtime", 0, 1, BT_UNKNOWN, 0,
1893 gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
1894 vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
1896 add_sym_2s ("getcwd", 0, 1, BT_UNKNOWN, 0,
1897 gfc_check_getcwd_sub, NULL, gfc_resolve_getcwd_sub,
1898 c, BT_CHARACTER, dc, 0,
1899 st, BT_INTEGER, di, 1);
1901 add_sym_2s ("getenv", 0, 1, BT_UNKNOWN, 0,
1903 name, BT_CHARACTER, dc, 0,
1904 val, BT_CHARACTER, dc, 0);
1906 add_sym_2s ("getarg", 0, 1, BT_UNKNOWN, 0,
1907 NULL, NULL, gfc_resolve_getarg,
1908 c, BT_INTEGER, di, 0, vl, BT_CHARACTER, dc, 0);
1911 /* F2003 commandline routines. */
1913 add_sym_3s ("get_command", 0, 1, BT_UNKNOWN, 0,
1914 NULL, NULL, gfc_resolve_get_command,
1915 com, BT_CHARACTER, dc, 1,
1916 length, BT_INTEGER, di, 1,
1917 st, BT_INTEGER, di, 1);
1919 add_sym_4s ("get_command_argument", 0, 1, BT_UNKNOWN, 0,
1920 NULL, NULL, gfc_resolve_get_command_argument,
1921 num, BT_INTEGER, di, 0,
1922 val, BT_CHARACTER, dc, 1,
1923 length, BT_INTEGER, di, 1,
1924 st, BT_INTEGER, di, 1);
1927 /* F2003 subroutine to get environment variables. */
1929 add_sym_5s ("get_environment_variable", 0, 1, BT_UNKNOWN, 0,
1930 NULL, NULL, gfc_resolve_get_environment_variable,
1931 name, BT_CHARACTER, dc, 0,
1932 val, BT_CHARACTER, dc, 1,
1933 length, BT_INTEGER, di, 1,
1934 st, BT_INTEGER, di, 1,
1935 trim_name, BT_LOGICAL, dl, 1);
1938 add_sym_5s ("mvbits", 1, 1, BT_UNKNOWN, 0,
1939 gfc_check_mvbits, gfc_simplify_mvbits, gfc_resolve_mvbits,
1940 f, BT_INTEGER, di, 0, fp, BT_INTEGER, di, 0,
1941 ln, BT_INTEGER, di, 0, t, BT_INTEGER, di, 0,
1942 tp, BT_INTEGER, di, 0);
1944 add_sym_1s ("random_number", 0, 1, BT_UNKNOWN, 0,
1945 gfc_check_random_number, NULL, gfc_resolve_random_number,
1948 add_sym_3s ("random_seed", 0, 1, BT_UNKNOWN, 0,
1949 gfc_check_random_seed, NULL, NULL,
1950 sz, BT_INTEGER, di, 1, pt, BT_INTEGER, di, 1,
1951 gt, BT_INTEGER, di, 1);
1953 /* More G77 compatibility garbage. */
1954 add_sym_1s ("srand", 0, 1, BT_UNKNOWN, di,
1955 gfc_check_srand, NULL, gfc_resolve_srand,
1956 c, BT_INTEGER, 4, 0);
1958 add_sym_2s ("system", 0, 1, BT_UNKNOWN, 0,
1959 NULL, NULL, gfc_resolve_system_sub,
1960 c, BT_CHARACTER, dc, 0,
1961 st, BT_INTEGER, di, 1);
1963 add_sym_3s ("system_clock", 0, 1, BT_UNKNOWN, 0,
1964 gfc_check_system_clock, NULL, gfc_resolve_system_clock,
1965 c, BT_INTEGER, di, 1, cr, BT_INTEGER, di, 1,
1966 cm, BT_INTEGER, di, 1);
1970 /* Add a function to the list of conversion symbols. */
1973 add_conv (bt from_type, int from_kind, bt to_type, int to_kind,
1974 gfc_expr * (*simplify) (gfc_expr *, bt, int))
1977 gfc_typespec from, to;
1978 gfc_intrinsic_sym *sym;
1980 if (sizing == SZ_CONVS)
1986 gfc_clear_ts (&from);
1987 from.type = from_type;
1988 from.kind = from_kind;
1994 sym = conversion + nconv;
1996 strcpy (sym->name, conv_name (&from, &to));
1997 strcpy (sym->lib_name, sym->name);
1998 sym->simplify.cc = simplify;
2001 sym->generic_id = GFC_ISYM_CONVERSION;
2007 /* Create gfc_intrinsic_sym nodes for all intrinsic conversion
2008 functions by looping over the kind tables. */
2011 add_conversions (void)
2015 /* Integer-Integer conversions. */
2016 for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
2017 for (j = 0; gfc_integer_kinds[j].kind != 0; j++)
2022 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
2023 BT_INTEGER, gfc_integer_kinds[j].kind, gfc_convert_constant);
2026 /* Integer-Real/Complex conversions. */
2027 for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
2028 for (j = 0; gfc_real_kinds[j].kind != 0; j++)
2030 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
2031 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
2033 add_conv (BT_REAL, gfc_real_kinds[j].kind,
2034 BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant);
2036 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
2037 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
2039 add_conv (BT_COMPLEX, gfc_real_kinds[j].kind,
2040 BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant);
2043 /* Real/Complex - Real/Complex conversions. */
2044 for (i = 0; gfc_real_kinds[i].kind != 0; i++)
2045 for (j = 0; gfc_real_kinds[j].kind != 0; j++)
2049 add_conv (BT_REAL, gfc_real_kinds[i].kind,
2050 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
2052 add_conv (BT_COMPLEX, gfc_real_kinds[i].kind,
2053 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
2056 add_conv (BT_REAL, gfc_real_kinds[i].kind,
2057 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
2059 add_conv (BT_COMPLEX, gfc_real_kinds[i].kind,
2060 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
2063 /* Logical/Logical kind conversion. */
2064 for (i = 0; gfc_logical_kinds[i].kind; i++)
2065 for (j = 0; gfc_logical_kinds[j].kind; j++)
2070 add_conv (BT_LOGICAL, gfc_logical_kinds[i].kind,
2071 BT_LOGICAL, gfc_logical_kinds[j].kind, gfc_convert_constant);
2076 /* Initialize the table of intrinsics. */
2078 gfc_intrinsic_init_1 (void)
2082 nargs = nfunc = nsub = nconv = 0;
2084 /* Create a namespace to hold the resolved intrinsic symbols. */
2085 gfc_intrinsic_namespace = gfc_get_namespace (NULL);
2094 functions = gfc_getmem (sizeof (gfc_intrinsic_sym) * (nfunc + nsub)
2095 + sizeof (gfc_intrinsic_arg) * nargs);
2097 next_sym = functions;
2098 subroutines = functions + nfunc;
2100 conversion = gfc_getmem (sizeof (gfc_intrinsic_sym) * nconv);
2102 next_arg = ((gfc_intrinsic_arg *) (subroutines + nsub)) - 1;
2104 sizing = SZ_NOTHING;
2111 /* Set the pure flag. All intrinsic functions are pure, and
2112 intrinsic subroutines are pure if they are elemental. */
2114 for (i = 0; i < nfunc; i++)
2115 functions[i].pure = 1;
2117 for (i = 0; i < nsub; i++)
2118 subroutines[i].pure = subroutines[i].elemental;
2123 gfc_intrinsic_done_1 (void)
2125 gfc_free (functions);
2126 gfc_free (conversion);
2127 gfc_free_namespace (gfc_intrinsic_namespace);
2131 /******** Subroutines to check intrinsic interfaces ***********/
2133 /* Given a formal argument list, remove any NULL arguments that may
2134 have been left behind by a sort against some formal argument list. */
2137 remove_nullargs (gfc_actual_arglist ** ap)
2139 gfc_actual_arglist *head, *tail, *next;
2143 for (head = *ap; head; head = next)
2147 if (head->expr == NULL)
2150 gfc_free_actual_arglist (head);
2169 /* Given an actual arglist and a formal arglist, sort the actual
2170 arglist so that its arguments are in a one-to-one correspondence
2171 with the format arglist. Arguments that are not present are given
2172 a blank gfc_actual_arglist structure. If something is obviously
2173 wrong (say, a missing required argument) we abort sorting and
2177 sort_actual (const char *name, gfc_actual_arglist ** ap,
2178 gfc_intrinsic_arg * formal, locus * where)
2181 gfc_actual_arglist *actual, *a;
2182 gfc_intrinsic_arg *f;
2184 remove_nullargs (ap);
2187 for (f = formal; f; f = f->next)
2193 if (f == NULL && a == NULL) /* No arguments */
2197 { /* Put the nonkeyword arguments in a 1:1 correspondence */
2203 if (a->name[0] != '\0')
2215 gfc_error ("Too many arguments in call to '%s' at %L", name, where);
2219 /* Associate the remaining actual arguments, all of which have
2220 to be keyword arguments. */
2221 for (; a; a = a->next)
2223 for (f = formal; f; f = f->next)
2224 if (strcmp (a->name, f->name) == 0)
2229 gfc_error ("Can't find keyword named '%s' in call to '%s' at %L",
2230 a->name, name, where);
2234 if (f->actual != NULL)
2236 gfc_error ("Argument '%s' is appears twice in call to '%s' at %L",
2237 f->name, name, where);
2245 /* At this point, all unmatched formal args must be optional. */
2246 for (f = formal; f; f = f->next)
2248 if (f->actual == NULL && f->optional == 0)
2250 gfc_error ("Missing actual argument '%s' in call to '%s' at %L",
2251 f->name, name, where);
2257 /* Using the formal argument list, string the actual argument list
2258 together in a way that corresponds with the formal list. */
2261 for (f = formal; f; f = f->next)
2263 if (f->actual == NULL)
2265 a = gfc_get_actual_arglist ();
2266 a->missing_arg_type = f->ts.type;
2278 actual->next = NULL; /* End the sorted argument list. */
2284 /* Compare an actual argument list with an intrinsic's formal argument
2285 list. The lists are checked for agreement of type. We don't check
2286 for arrayness here. */
2289 check_arglist (gfc_actual_arglist ** ap, gfc_intrinsic_sym * sym,
2292 gfc_actual_arglist *actual;
2293 gfc_intrinsic_arg *formal;
2296 formal = sym->formal;
2300 for (; formal; formal = formal->next, actual = actual->next, i++)
2302 if (actual->expr == NULL)
2305 if (!gfc_compare_types (&formal->ts, &actual->expr->ts))
2309 ("Type of argument '%s' in call to '%s' at %L should be "
2310 "%s, not %s", gfc_current_intrinsic_arg[i],
2311 gfc_current_intrinsic, &actual->expr->where,
2312 gfc_typename (&formal->ts), gfc_typename (&actual->expr->ts));
2321 /* Given a pointer to an intrinsic symbol and an expression node that
2322 represent the function call to that subroutine, figure out the type
2323 of the result. This may involve calling a resolution subroutine. */
2326 resolve_intrinsic (gfc_intrinsic_sym * specific, gfc_expr * e)
2328 gfc_expr *a1, *a2, *a3, *a4, *a5;
2329 gfc_actual_arglist *arg;
2331 if (specific->resolve.f1 == NULL)
2333 if (e->value.function.name == NULL)
2334 e->value.function.name = specific->lib_name;
2336 if (e->ts.type == BT_UNKNOWN)
2337 e->ts = specific->ts;
2341 arg = e->value.function.actual;
2343 /* Special case hacks for MIN and MAX. */
2344 if (specific->resolve.f1m == gfc_resolve_max
2345 || specific->resolve.f1m == gfc_resolve_min)
2347 (*specific->resolve.f1m) (e, arg);
2353 (*specific->resolve.f0) (e);
2362 (*specific->resolve.f1) (e, a1);
2371 (*specific->resolve.f2) (e, a1, a2);
2380 (*specific->resolve.f3) (e, a1, a2, a3);
2389 (*specific->resolve.f4) (e, a1, a2, a3, a4);
2398 (*specific->resolve.f5) (e, a1, a2, a3, a4, a5);
2402 gfc_internal_error ("resolve_intrinsic(): Too many args for intrinsic");
2406 /* Given an intrinsic symbol node and an expression node, call the
2407 simplification function (if there is one), perhaps replacing the
2408 expression with something simpler. We return FAILURE on an error
2409 of the simplification, SUCCESS if the simplification worked, even
2410 if nothing has changed in the expression itself. */
2413 do_simplify (gfc_intrinsic_sym * specific, gfc_expr * e)
2415 gfc_expr *result, *a1, *a2, *a3, *a4, *a5;
2416 gfc_actual_arglist *arg;
2418 /* Max and min require special handling due to the variable number
2420 if (specific->simplify.f1 == gfc_simplify_min)
2422 result = gfc_simplify_min (e);
2426 if (specific->simplify.f1 == gfc_simplify_max)
2428 result = gfc_simplify_max (e);
2432 if (specific->simplify.f1 == NULL)
2438 arg = e->value.function.actual;
2442 result = (*specific->simplify.f0) ();
2449 if (specific->simplify.cc == gfc_convert_constant)
2451 result = gfc_convert_constant (a1, specific->ts.type, specific->ts.kind);
2455 /* TODO: Warn if -pedantic and initialization expression and arg
2456 types not integer or character */
2459 result = (*specific->simplify.f1) (a1);
2466 result = (*specific->simplify.f2) (a1, a2);
2473 result = (*specific->simplify.f3) (a1, a2, a3);
2480 result = (*specific->simplify.f4) (a1, a2, a3, a4);
2487 result = (*specific->simplify.f5) (a1, a2, a3, a4, a5);
2490 ("do_simplify(): Too many args for intrinsic");
2497 if (result == &gfc_bad_expr)
2501 resolve_intrinsic (specific, e); /* Must call at run-time */
2504 result->where = e->where;
2505 gfc_replace_expr (e, result);
2512 /* Initialize the gfc_current_intrinsic_arg[] array for the benefit of
2513 error messages. This subroutine returns FAILURE if a subroutine
2514 has more than MAX_INTRINSIC_ARGS, in which case the actual argument
2515 list cannot match any intrinsic. */
2518 init_arglist (gfc_intrinsic_sym * isym)
2520 gfc_intrinsic_arg *formal;
2523 gfc_current_intrinsic = isym->name;
2526 for (formal = isym->formal; formal; formal = formal->next)
2528 if (i >= MAX_INTRINSIC_ARGS)
2529 gfc_internal_error ("init_arglist(): too many arguments");
2530 gfc_current_intrinsic_arg[i++] = formal->name;
2535 /* Given a pointer to an intrinsic symbol and an expression consisting
2536 of a function call, see if the function call is consistent with the
2537 intrinsic's formal argument list. Return SUCCESS if the expression
2538 and intrinsic match, FAILURE otherwise. */
2541 check_specific (gfc_intrinsic_sym * specific, gfc_expr * expr, int error_flag)
2543 gfc_actual_arglist *arg, **ap;
2547 ap = &expr->value.function.actual;
2549 init_arglist (specific);
2551 /* Don't attempt to sort the argument list for min or max. */
2552 if (specific->check.f1m == gfc_check_min_max
2553 || specific->check.f1m == gfc_check_min_max_integer
2554 || specific->check.f1m == gfc_check_min_max_real
2555 || specific->check.f1m == gfc_check_min_max_double)
2556 return (*specific->check.f1m) (*ap);
2558 if (sort_actual (specific->name, ap, specific->formal,
2559 &expr->where) == FAILURE)
2562 if (specific->check.f3ml == gfc_check_minloc_maxloc)
2563 /* This is special because we might have to reorder the argument
2565 t = gfc_check_minloc_maxloc (*ap);
2566 else if (specific->check.f3red == gfc_check_minval_maxval)
2567 /* This is also special because we also might have to reorder the
2569 t = gfc_check_minval_maxval (*ap);
2570 else if (specific->check.f3red == gfc_check_product_sum)
2571 /* Same here. The difference to the previous case is that we allow a
2572 general numeric type. */
2573 t = gfc_check_product_sum (*ap);
2576 if (specific->check.f1 == NULL)
2578 t = check_arglist (ap, specific, error_flag);
2580 expr->ts = specific->ts;
2583 t = do_check (specific, *ap);
2586 /* Check ranks for elemental intrinsics. */
2587 if (t == SUCCESS && specific->elemental)
2590 for (arg = expr->value.function.actual; arg; arg = arg->next)
2592 if (arg->expr == NULL || arg->expr->rank == 0)
2596 r = arg->expr->rank;
2600 if (arg->expr->rank != r)
2603 ("Ranks of arguments to elemental intrinsic '%s' differ "
2604 "at %L", specific->name, &arg->expr->where);
2611 remove_nullargs (ap);
2617 /* See if an intrinsic is one of the intrinsics we evaluate
2621 gfc_init_expr_extensions (gfc_intrinsic_sym *isym)
2623 /* FIXME: This should be moved into the intrinsic definitions. */
2624 static const char * const init_expr_extensions[] = {
2625 "digits", "epsilon", "huge", "kind", "maxexponent", "minexponent",
2626 "precision", "present", "radix", "range", "selected_real_kind",
2632 for (i = 0; init_expr_extensions[i]; i++)
2633 if (strcmp (init_expr_extensions[i], isym->name) == 0)
2640 /* See if a function call corresponds to an intrinsic function call.
2643 MATCH_YES if the call corresponds to an intrinsic, simplification
2644 is done if possible.
2646 MATCH_NO if the call does not correspond to an intrinsic
2648 MATCH_ERROR if the call corresponds to an intrinsic but there was an
2649 error during the simplification process.
2651 The error_flag parameter enables an error reporting. */
2654 gfc_intrinsic_func_interface (gfc_expr * expr, int error_flag)
2656 gfc_intrinsic_sym *isym, *specific;
2657 gfc_actual_arglist *actual;
2661 if (expr->value.function.isym != NULL)
2662 return (do_simplify (expr->value.function.isym, expr) == FAILURE)
2663 ? MATCH_ERROR : MATCH_YES;
2665 gfc_suppress_error = !error_flag;
2668 for (actual = expr->value.function.actual; actual; actual = actual->next)
2669 if (actual->expr != NULL)
2670 flag |= (actual->expr->ts.type != BT_INTEGER
2671 && actual->expr->ts.type != BT_CHARACTER);
2673 name = expr->symtree->n.sym->name;
2675 isym = specific = gfc_find_function (name);
2678 gfc_suppress_error = 0;
2682 gfc_current_intrinsic_where = &expr->where;
2684 /* Bypass the generic list for min and max. */
2685 if (isym->check.f1m == gfc_check_min_max)
2687 init_arglist (isym);
2689 if (gfc_check_min_max (expr->value.function.actual) == SUCCESS)
2692 gfc_suppress_error = 0;
2696 /* If the function is generic, check all of its specific
2697 incarnations. If the generic name is also a specific, we check
2698 that name last, so that any error message will correspond to the
2700 gfc_suppress_error = 1;
2704 for (specific = isym->specific_head; specific;
2705 specific = specific->next)
2707 if (specific == isym)
2709 if (check_specific (specific, expr, 0) == SUCCESS)
2714 gfc_suppress_error = !error_flag;
2716 if (check_specific (isym, expr, error_flag) == FAILURE)
2718 gfc_suppress_error = 0;
2725 expr->value.function.isym = specific;
2726 gfc_intrinsic_symbol (expr->symtree->n.sym);
2728 if (do_simplify (specific, expr) == FAILURE)
2730 gfc_suppress_error = 0;
2734 /* TODO: We should probably only allow elemental functions here. */
2735 flag |= (expr->ts.type != BT_INTEGER && expr->ts.type != BT_CHARACTER);
2737 gfc_suppress_error = 0;
2738 if (pedantic && gfc_init_expr
2739 && flag && gfc_init_expr_extensions (specific))
2741 if (gfc_notify_std (GFC_STD_GNU, "Extension: Evaluation of "
2742 "nonstandard initialization expression at %L", &expr->where)
2753 /* See if a CALL statement corresponds to an intrinsic subroutine.
2754 Returns MATCH_YES if the subroutine corresponds to an intrinsic,
2755 MATCH_NO if not, and MATCH_ERROR if there was an error (but did
2759 gfc_intrinsic_sub_interface (gfc_code * c, int error_flag)
2761 gfc_intrinsic_sym *isym;
2764 name = c->symtree->n.sym->name;
2766 isym = find_subroutine (name);
2770 gfc_suppress_error = !error_flag;
2772 init_arglist (isym);
2774 if (sort_actual (name, &c->ext.actual, isym->formal, &c->loc) == FAILURE)
2777 if (isym->check.f1 != NULL)
2779 if (do_check (isym, c->ext.actual) == FAILURE)
2784 if (check_arglist (&c->ext.actual, isym, 1) == FAILURE)
2788 /* The subroutine corresponds to an intrinsic. Allow errors to be
2789 seen at this point. */
2790 gfc_suppress_error = 0;
2792 if (isym->resolve.s1 != NULL)
2793 isym->resolve.s1 (c);
2795 c->resolved_sym = gfc_get_intrinsic_sub_symbol (isym->lib_name);
2797 if (gfc_pure (NULL) && !isym->elemental)
2799 gfc_error ("Subroutine call to intrinsic '%s' at %L is not PURE", name,
2807 gfc_suppress_error = 0;
2812 /* Call gfc_convert_type() with warning enabled. */
2815 gfc_convert_type (gfc_expr * expr, gfc_typespec * ts, int eflag)
2817 return gfc_convert_type_warn (expr, ts, eflag, 1);
2821 /* Try to convert an expression (in place) from one type to another.
2822 'eflag' controls the behavior on error.
2824 The possible values are:
2826 1 Generate a gfc_error()
2827 2 Generate a gfc_internal_error().
2829 'wflag' controls the warning related to conversion. */
2832 gfc_convert_type_warn (gfc_expr * expr, gfc_typespec * ts, int eflag,
2835 gfc_intrinsic_sym *sym;
2836 gfc_typespec from_ts;
2841 from_ts = expr->ts; /* expr->ts gets clobbered */
2843 if (ts->type == BT_UNKNOWN)
2846 /* NULL and zero size arrays get their type here. */
2847 if (expr->expr_type == EXPR_NULL
2848 || (expr->expr_type == EXPR_ARRAY
2849 && expr->value.constructor == NULL))
2851 /* Sometimes the RHS acquire the type. */
2856 if (expr->ts.type == BT_UNKNOWN)
2859 if (expr->ts.type == BT_DERIVED
2860 && ts->type == BT_DERIVED
2861 && gfc_compare_types (&expr->ts, ts))
2864 sym = find_conv (&expr->ts, ts);
2868 /* At this point, a conversion is necessary. A warning may be needed. */
2869 if (wflag && gfc_option.warn_conversion)
2870 gfc_warning_now ("Conversion from %s to %s at %L",
2871 gfc_typename (&from_ts), gfc_typename (ts), &expr->where);
2873 /* Insert a pre-resolved function call to the right function. */
2874 old_where = expr->where;
2876 new = gfc_get_expr ();
2879 new = gfc_build_conversion (new);
2880 new->value.function.name = sym->lib_name;
2881 new->value.function.isym = sym;
2882 new->where = old_where;
2890 if (gfc_is_constant_expr (expr->value.function.actual->expr)
2891 && do_simplify (sym, expr) == FAILURE)
2896 return FAILURE; /* Error already generated in do_simplify() */
2904 gfc_error ("Can't convert %s to %s at %L",
2905 gfc_typename (&from_ts), gfc_typename (ts), &expr->where);
2909 gfc_internal_error ("Can't convert %s to %s at %L",
2910 gfc_typename (&from_ts), gfc_typename (ts),