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;
162 t = (*specific->check.f1) (a1);
169 t = (*specific->check.f2) (a1, a2);
176 t = (*specific->check.f3) (a1, a2, a3);
183 t = (*specific->check.f4) (a1, a2, a3, a4);
190 t = (*specific->check.f5) (a1, a2, a3, a4, a5);
193 gfc_internal_error ("do_check(): too many args");
204 /*********** Subroutines to build the intrinsic list ****************/
206 /* Add a single intrinsic symbol to the current list.
209 char * name of function
210 int whether function is elemental
211 int If the function can be used as an actual argument
212 bt return type of function
213 int kind of return type of function
214 check pointer to check function
215 simplify pointer to simplification function
216 resolve pointer to resolution function
218 Optional arguments come in multiples of four:
219 char * name of argument
222 int arg optional flag (1=optional, 0=required)
224 The sequence is terminated by a NULL name.
226 TODO: Are checks on actual_ok implemented elsewhere, or is that just
230 add_sym (const char *name, int elemental, int actual_ok ATTRIBUTE_UNUSED,
231 bt type, int kind, gfc_check_f check, gfc_simplify_f simplify,
232 gfc_resolve_f resolve, ...)
235 int optional, first_flag;
249 strcpy (next_sym->name, name);
251 strcpy (next_sym->lib_name, "_gfortran_");
252 strcat (next_sym->lib_name, name);
254 next_sym->elemental = elemental;
255 next_sym->ts.type = type;
256 next_sym->ts.kind = kind;
257 next_sym->simplify = simplify;
258 next_sym->check = check;
259 next_sym->resolve = resolve;
260 next_sym->specific = 0;
261 next_sym->generic = 0;
265 gfc_internal_error ("add_sym(): Bad sizing mode");
268 va_start (argp, resolve);
274 name = va_arg (argp, char *);
278 type = (bt) va_arg (argp, int);
279 kind = va_arg (argp, int);
280 optional = va_arg (argp, int);
282 if (sizing != SZ_NOTHING)
289 next_sym->formal = next_arg;
291 (next_arg - 1)->next = next_arg;
295 strcpy (next_arg->name, name);
296 next_arg->ts.type = type;
297 next_arg->ts.kind = kind;
298 next_arg->optional = optional;
308 static void add_sym_0 (const char *name, int elemental, int actual_ok, bt type,
310 try (*check)(gfc_expr *),
311 gfc_expr *(*simplify)(gfc_expr *),
312 void (*resolve)(gfc_expr *,gfc_expr *)
322 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
327 static void add_sym_1 (const char *name, int elemental, int actual_ok, bt type,
329 try (*check)(gfc_expr *),
330 gfc_expr *(*simplify)(gfc_expr *),
331 void (*resolve)(gfc_expr *,gfc_expr *),
332 const char* a1, bt type1, int kind1, int optional1
342 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
343 a1, type1, kind1, optional1,
349 add_sym_0s (const char * name, int actual_ok,
350 void (*resolve)(gfc_code *))
360 add_sym (name, 1, actual_ok, BT_UNKNOWN, 0, cf, sf, rf,
365 static void add_sym_1s (const char *name, int elemental, int actual_ok, bt type,
367 try (*check)(gfc_expr *),
368 gfc_expr *(*simplify)(gfc_expr *),
369 void (*resolve)(gfc_code *),
370 const char* a1, bt type1, int kind1, int optional1
380 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
381 a1, type1, kind1, optional1,
386 static void add_sym_1m (const char *name, int elemental, int actual_ok, bt type,
388 try (*check)(gfc_actual_arglist *),
389 gfc_expr *(*simplify)(gfc_expr *),
390 void (*resolve)(gfc_expr *,gfc_actual_arglist *),
391 const char* a1, bt type1, int kind1, int optional1,
392 const char* a2, bt type2, int kind2, int optional2
402 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
403 a1, type1, kind1, optional1,
404 a2, type2, kind2, optional2,
409 static void add_sym_2 (const char *name, int elemental, int actual_ok, bt type,
411 try (*check)(gfc_expr *,gfc_expr *),
412 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *),
413 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *),
414 const char* a1, bt type1, int kind1, int optional1,
415 const char* a2, bt type2, int kind2, int optional2
425 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
426 a1, type1, kind1, optional1,
427 a2, type2, kind2, optional2,
432 /* Add the name of an intrinsic subroutine with two arguments to the list
433 of intrinsic names. */
435 static void add_sym_2s (const char *name, int elemental, int actual_ok, bt type,
437 try (*check)(gfc_expr *,gfc_expr *),
438 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *),
439 void (*resolve)(gfc_code *),
440 const char* a1, bt type1, int kind1, int optional1,
441 const char* a2, bt type2, int kind2, int optional2
451 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
452 a1, type1, kind1, optional1,
453 a2, type2, kind2, optional2,
458 static void add_sym_3 (const char *name, int elemental, int actual_ok, bt type,
460 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *),
461 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
462 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
463 const char* a1, bt type1, int kind1, int optional1,
464 const char* a2, bt type2, int kind2, int optional2,
465 const char* a3, bt type3, int kind3, int optional3
475 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
476 a1, type1, kind1, optional1,
477 a2, type2, kind2, optional2,
478 a3, type3, kind3, optional3,
482 /* MINLOC and MAXLOC get special treatment because their argument
483 might have to be reordered. */
485 static void add_sym_3ml (const char *name, int elemental,
486 int actual_ok, bt type, int kind,
487 try (*check)(gfc_actual_arglist *),
488 gfc_expr*(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
489 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
490 const char* a1, bt type1, int kind1, int optional1,
491 const char* a2, bt type2, int kind2, int optional2,
492 const char* a3, bt type3, int kind3, int optional3
502 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
503 a1, type1, kind1, optional1,
504 a2, type2, kind2, optional2,
505 a3, type3, kind3, optional3,
509 /* Add the name of an intrinsic subroutine with three arguments to the list
510 of intrinsic names. */
512 static void add_sym_3s (const char *name, int elemental, int actual_ok, bt type,
514 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *),
515 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
516 void (*resolve)(gfc_code *),
517 const char* a1, bt type1, int kind1, int optional1,
518 const char* a2, bt type2, int kind2, int optional2,
519 const char* a3, bt type3, int kind3, int optional3
529 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
530 a1, type1, kind1, optional1,
531 a2, type2, kind2, optional2,
532 a3, type3, kind3, optional3,
537 static void add_sym_4 (const char *name, int elemental, int actual_ok, bt type,
539 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
540 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
541 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
542 const char* a1, bt type1, int kind1, int optional1,
543 const char* a2, bt type2, int kind2, int optional2,
544 const char* a3, bt type3, int kind3, int optional3,
545 const char* a4, bt type4, int kind4, int optional4
555 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
556 a1, type1, kind1, optional1,
557 a2, type2, kind2, optional2,
558 a3, type3, kind3, optional3,
559 a4, type4, kind4, optional4,
564 static void add_sym_5 (const char *name, int elemental, int actual_ok, bt type,
566 try (*check)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
567 gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
568 void (*resolve)(gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *,gfc_expr *),
569 const char* a1, bt type1, int kind1, int optional1,
570 const char* a2, bt type2, int kind2, int optional2,
571 const char* a3, bt type3, int kind3, int optional3,
572 const char* a4, bt type4, int kind4, int optional4,
573 const char* a5, bt type5, int kind5, int optional5
583 add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
584 a1, type1, kind1, optional1,
585 a2, type2, kind2, optional2,
586 a3, type3, kind3, optional3,
587 a4, type4, kind4, optional4,
588 a5, type5, kind5, optional5,
593 /* Locate an intrinsic symbol given a base pointer, number of elements
594 in the table and a pointer to a name. Returns the NULL pointer if
595 a name is not found. */
597 static gfc_intrinsic_sym *
598 find_sym (gfc_intrinsic_sym * start, int n, const char *name)
603 if (strcmp (name, start->name) == 0)
614 /* Given a name, find a function in the intrinsic function table.
615 Returns NULL if not found. */
618 gfc_find_function (const char *name)
621 return find_sym (functions, nfunc, name);
625 /* Given a name, find a function in the intrinsic subroutine table.
626 Returns NULL if not found. */
628 static gfc_intrinsic_sym *
629 find_subroutine (const char *name)
632 return find_sym (subroutines, nsub, name);
636 /* Given a string, figure out if it is the name of a generic intrinsic
640 gfc_generic_intrinsic (const char *name)
642 gfc_intrinsic_sym *sym;
644 sym = gfc_find_function (name);
645 return (sym == NULL) ? 0 : sym->generic;
649 /* Given a string, figure out if it is the name of a specific
650 intrinsic function or not. */
653 gfc_specific_intrinsic (const char *name)
655 gfc_intrinsic_sym *sym;
657 sym = gfc_find_function (name);
658 return (sym == NULL) ? 0 : sym->specific;
662 /* Given a string, figure out if it is the name of an intrinsic
663 subroutine or function. There are no generic intrinsic
664 subroutines, they are all specific. */
667 gfc_intrinsic_name (const char *name, int subroutine_flag)
670 return subroutine_flag ?
671 find_subroutine (name) != NULL : gfc_find_function (name) != NULL;
675 /* Collect a set of intrinsic functions into a generic collection.
676 The first argument is the name of the generic function, which is
677 also the name of a specific function. The rest of the specifics
678 currently in the table are placed into the list of specific
679 functions associated with that generic. */
682 make_generic (const char *name, gfc_generic_isym_id generic_id)
684 gfc_intrinsic_sym *g;
686 if (sizing != SZ_NOTHING)
689 g = gfc_find_function (name);
691 gfc_internal_error ("make_generic(): Can't find generic symbol '%s'",
696 g->generic_id = generic_id;
697 if ((g + 1)->name[0] != '\0')
698 g->specific_head = g + 1;
701 while (g->name[0] != '\0')
705 g->generic_id = generic_id;
714 /* Create a duplicate intrinsic function entry for the current
715 function, the only difference being the alternate name. Note that
716 we use argument lists more than once, but all argument lists are
717 freed as a single block. */
720 make_alias (const char *name)
734 next_sym[0] = next_sym[-1];
735 strcpy (next_sym->name, name);
745 /* Add intrinsic functions. */
751 /* Argument names as in the standard (to be used as argument keywords). */
753 *a = "a", *f = "field", *pt = "pointer", *tg = "target",
754 *b = "b", *m = "matrix", *ma = "matrix_a", *mb = "matrix_b",
755 *c = "c", *n = "ncopies", *pos = "pos", *bck = "back",
756 *i = "i", *v = "vector", *va = "vector_a", *vb = "vector_b",
757 *j = "j", *a1 = "a1", *fs = "fsource", *ts = "tsource",
758 *l = "l", *a2 = "a2", *mo = "mold", *ord = "order",
759 *p = "p", *ar = "array", *shp = "shape", *src = "source",
760 *r = "r", *bd = "boundary", *pad = "pad", *set = "set",
761 *s = "s", *dm = "dim", *kind = "kind", *msk = "mask",
762 *x = "x", *sh = "shift", *stg = "string", *ssg = "substring",
763 *y = "y", *sz = "size", *sta = "string_a", *stb = "string_b",
764 *z = "z", *ln = "len";
766 int di, dr, dd, dl, dc, dz, ii;
768 di = gfc_default_integer_kind ();
769 dr = gfc_default_real_kind ();
770 dd = gfc_default_double_kind ();
771 dl = gfc_default_logical_kind ();
772 dc = gfc_default_character_kind ();
773 dz = gfc_default_complex_kind ();
774 ii = gfc_index_integer_kind;
776 add_sym_1 ("abs", 1, 1, BT_REAL, dr,
777 gfc_check_abs, gfc_simplify_abs, gfc_resolve_abs,
780 add_sym_1 ("iabs", 1, 1, BT_INTEGER, di,
781 NULL, gfc_simplify_abs, gfc_resolve_abs,
782 a, BT_INTEGER, di, 0);
784 add_sym_1 ("dabs", 1, 1, BT_REAL, dd,
785 NULL, gfc_simplify_abs, gfc_resolve_abs, a, BT_REAL, dd, 0);
787 add_sym_1 ("cabs", 1, 1, BT_REAL, dr,
788 NULL, gfc_simplify_abs, gfc_resolve_abs,
789 a, BT_COMPLEX, dz, 0);
791 add_sym_1 ("zabs", 1, 1, BT_REAL, dd, NULL, gfc_simplify_abs, gfc_resolve_abs, a, BT_COMPLEX, dd, 0); /* Extension */
793 make_alias ("cdabs");
795 make_generic ("abs", GFC_ISYM_ABS);
797 add_sym_1 ("achar", 1, 1, BT_CHARACTER, dc,
798 NULL, gfc_simplify_achar, NULL, i, BT_INTEGER, di, 0);
800 make_generic ("achar", GFC_ISYM_ACHAR);
802 add_sym_1 ("acos", 1, 1, BT_REAL, dr,
803 NULL, gfc_simplify_acos, gfc_resolve_acos,
806 add_sym_1 ("dacos", 1, 1, BT_REAL, dd,
807 NULL, gfc_simplify_acos, gfc_resolve_acos,
810 make_generic ("acos", GFC_ISYM_ACOS);
812 add_sym_1 ("adjustl", 1, 1, BT_CHARACTER, dc,
813 NULL, gfc_simplify_adjustl, NULL, stg, BT_CHARACTER, dc, 0);
815 make_generic ("adjustl", GFC_ISYM_ADJUSTL);
817 add_sym_1 ("adjustr", 1, 1, BT_CHARACTER, dc,
818 NULL, gfc_simplify_adjustr, NULL, stg, BT_CHARACTER, dc, 0);
820 make_generic ("adjustr", GFC_ISYM_ADJUSTR);
822 add_sym_1 ("aimag", 1, 1, BT_REAL, dr,
823 NULL, gfc_simplify_aimag, gfc_resolve_aimag,
824 z, BT_COMPLEX, dz, 0);
826 add_sym_1 ("dimag", 1, 1, BT_REAL, dd, NULL, gfc_simplify_aimag, gfc_resolve_aimag, z, BT_COMPLEX, dd, 0); /* Extension */
828 make_generic ("aimag", GFC_ISYM_AIMAG);
830 add_sym_2 ("aint", 1, 1, BT_REAL, dr,
831 gfc_check_a_xkind, gfc_simplify_aint, gfc_resolve_aint,
832 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
834 add_sym_1 ("dint", 1, 1, BT_REAL, dd,
835 NULL, gfc_simplify_dint, gfc_resolve_dint,
838 make_generic ("aint", GFC_ISYM_AINT);
840 add_sym_2 ("all", 0, 1, BT_UNKNOWN, 0,
841 gfc_check_all_any, NULL, gfc_resolve_all,
842 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
844 make_generic ("all", GFC_ISYM_ALL);
846 add_sym_1 ("allocated", 0, 1, BT_LOGICAL, dl,
847 gfc_check_allocated, NULL, NULL, ar, BT_UNKNOWN, 0, 0);
849 make_generic ("allocated", GFC_ISYM_ALLOCATED);
851 add_sym_2 ("anint", 1, 1, BT_REAL, dr,
852 gfc_check_a_xkind, gfc_simplify_anint, gfc_resolve_anint,
853 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
855 add_sym_1 ("dnint", 1, 1, BT_REAL, dd,
856 NULL, gfc_simplify_dnint, gfc_resolve_dnint,
859 make_generic ("anint", GFC_ISYM_ANINT);
861 add_sym_2 ("any", 0, 1, BT_UNKNOWN, 0,
862 gfc_check_all_any, NULL, gfc_resolve_any,
863 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
865 make_generic ("any", GFC_ISYM_ANY);
867 add_sym_1 ("asin", 1, 1, BT_REAL, dr,
868 NULL, gfc_simplify_asin, gfc_resolve_asin,
871 add_sym_1 ("dasin", 1, 1, BT_REAL, dd,
872 NULL, gfc_simplify_asin, gfc_resolve_asin,
875 make_generic ("asin", GFC_ISYM_ASIN);
877 add_sym_2 ("associated", 0, 1, BT_LOGICAL, dl,
878 gfc_check_associated, NULL, NULL,
879 pt, BT_UNKNOWN, 0, 0, tg, BT_UNKNOWN, 0, 1);
881 make_generic ("associated", GFC_ISYM_ASSOCIATED);
883 add_sym_1 ("atan", 1, 1, BT_REAL, dr,
884 NULL, gfc_simplify_atan, gfc_resolve_atan,
887 add_sym_1 ("datan", 1, 1, BT_REAL, dd,
888 NULL, gfc_simplify_atan, gfc_resolve_atan,
891 make_generic ("atan", GFC_ISYM_ATAN);
893 add_sym_2 ("atan2", 1, 1, BT_REAL, dr,
894 NULL, gfc_simplify_atan2, gfc_resolve_atan2,
895 y, BT_REAL, dr, 0, x, BT_REAL, dr, 0);
897 add_sym_2 ("datan2", 1, 1, BT_REAL, dd,
898 NULL, gfc_simplify_atan2, gfc_resolve_atan2,
899 y, BT_REAL, dd, 0, x, BT_REAL, dd, 0);
901 make_generic ("atan2", GFC_ISYM_ATAN2);
903 add_sym_1 ("bit_size", 0, 1, BT_INTEGER, di,
904 gfc_check_i, gfc_simplify_bit_size, NULL,
905 i, BT_INTEGER, di, 0);
907 make_generic ("bit_size", GFC_ISYM_NONE);
909 add_sym_2 ("btest", 1, 1, BT_LOGICAL, dl,
910 gfc_check_btest, gfc_simplify_btest, gfc_resolve_btest,
911 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
913 make_generic ("btest", GFC_ISYM_BTEST);
915 add_sym_2 ("ceiling", 1, 1, BT_INTEGER, di,
916 gfc_check_a_ikind, gfc_simplify_ceiling, gfc_resolve_ceiling,
917 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
919 make_generic ("ceiling", GFC_ISYM_CEILING);
921 add_sym_2 ("char", 1, 0, BT_CHARACTER, dc,
922 gfc_check_char, gfc_simplify_char, gfc_resolve_char,
923 i, BT_INTEGER, di, 0, kind, BT_INTEGER, di, 1);
925 make_generic ("char", GFC_ISYM_CHAR);
927 add_sym_3 ("cmplx", 1, 1, BT_COMPLEX, dz,
928 gfc_check_cmplx, gfc_simplify_cmplx, gfc_resolve_cmplx,
929 x, BT_UNKNOWN, dr, 0, y, BT_UNKNOWN, dr, 1,
930 kind, BT_INTEGER, di, 1);
932 make_generic ("cmplx", GFC_ISYM_CMPLX);
934 /* Making dcmplx a specific of cmplx causes cmplx to return a double
935 complex instead of the default complex. */
937 add_sym_2 ("dcmplx", 1, 1, BT_COMPLEX, dd,
938 gfc_check_dcmplx, gfc_simplify_dcmplx, gfc_resolve_dcmplx,
939 x, BT_REAL, dd, 0, y, BT_REAL, dd, 1); /* Extension */
941 make_generic ("dcmplx", GFC_ISYM_CMPLX);
943 add_sym_1 ("conjg", 1, 1, BT_COMPLEX, dz,
944 NULL, gfc_simplify_conjg, gfc_resolve_conjg,
945 z, BT_COMPLEX, dz, 0);
947 add_sym_1 ("dconjg", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_conjg, gfc_resolve_conjg, z, BT_COMPLEX, dd, 0); /* Extension */
949 make_generic ("conjg", GFC_ISYM_CONJG);
951 add_sym_1 ("cos", 1, 1, BT_REAL, dr,
952 NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_REAL, dr, 0);
954 add_sym_1 ("dcos", 1, 1, BT_REAL, dd,
955 NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_REAL, dd, 0);
957 add_sym_1 ("ccos", 1, 1, BT_COMPLEX, dz,
958 NULL, gfc_simplify_cos, gfc_resolve_cos,
959 x, BT_COMPLEX, dz, 0);
961 add_sym_1 ("zcos", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_cos, gfc_resolve_cos, x, BT_COMPLEX, dd, 0); /* Extension */
963 make_alias ("cdcos");
965 make_generic ("cos", GFC_ISYM_COS);
967 add_sym_1 ("cosh", 1, 1, BT_REAL, dr,
968 NULL, gfc_simplify_cosh, gfc_resolve_cosh,
971 add_sym_1 ("dcosh", 1, 1, BT_REAL, dd,
972 NULL, gfc_simplify_cosh, gfc_resolve_cosh,
975 make_generic ("cosh", GFC_ISYM_COSH);
977 add_sym_2 ("count", 0, 1, BT_INTEGER, di,
978 gfc_check_count, NULL, gfc_resolve_count,
979 msk, BT_LOGICAL, dl, 0, dm, BT_INTEGER, ii, 1);
981 make_generic ("count", GFC_ISYM_COUNT);
983 add_sym_3 ("cshift", 0, 1, BT_REAL, dr,
984 gfc_check_cshift, NULL, gfc_resolve_cshift,
985 ar, BT_REAL, dr, 0, sh, BT_INTEGER, di, 0,
986 dm, BT_INTEGER, ii, 1);
988 make_generic ("cshift", GFC_ISYM_CSHIFT);
990 add_sym_1 ("dble", 1, 1, BT_REAL, dd,
991 gfc_check_dble, gfc_simplify_dble, gfc_resolve_dble,
994 make_generic ("dble", GFC_ISYM_DBLE);
996 add_sym_1 ("digits", 0, 1, BT_INTEGER, di,
997 gfc_check_digits, gfc_simplify_digits, NULL,
998 x, BT_UNKNOWN, dr, 0);
1000 make_generic ("digits", GFC_ISYM_NONE);
1002 add_sym_2 ("dim", 1, 1, BT_REAL, dr,
1003 gfc_check_a_p, gfc_simplify_dim, gfc_resolve_dim,
1004 x, BT_UNKNOWN, dr, 0, y, BT_UNKNOWN, dr, 0);
1006 add_sym_2 ("idim", 1, 1, BT_INTEGER, di,
1007 NULL, gfc_simplify_dim, gfc_resolve_dim,
1008 x, BT_INTEGER, di, 0, y, BT_INTEGER, di, 0);
1010 add_sym_2 ("ddim", 1, 1, BT_REAL, dd,
1011 NULL, gfc_simplify_dim, gfc_resolve_dim,
1012 x, BT_REAL, dd, 0, y, BT_REAL, dd, 0);
1014 make_generic ("dim", GFC_ISYM_DIM);
1016 add_sym_2 ("dot_product", 0, 1, BT_UNKNOWN, 0,
1017 gfc_check_dot_product, NULL, gfc_resolve_dot_product,
1018 va, BT_REAL, dr, 0, vb, BT_REAL, dr, 0);
1020 make_generic ("dot_product", GFC_ISYM_DOT_PRODUCT);
1022 add_sym_2 ("dprod", 1, 1, BT_REAL, dd,
1023 NULL, gfc_simplify_dprod, gfc_resolve_dprod,
1024 x, BT_REAL, dr, 0, y, BT_REAL, dr, 0);
1026 make_generic ("dprod", GFC_ISYM_DPROD);
1028 add_sym_1 ("dreal", 1, 0, BT_REAL, dd, NULL, NULL, NULL, a, BT_COMPLEX, dd, 0); /* Extension */
1030 make_generic ("dreal", GFC_ISYM_REAL);
1032 add_sym_4 ("eoshift", 0, 1, BT_REAL, dr,
1033 gfc_check_eoshift, NULL, gfc_resolve_eoshift,
1034 ar, BT_REAL, dr, 0, sh, BT_INTEGER, ii, 0,
1035 bd, BT_REAL, dr, 1, dm, BT_INTEGER, ii, 1);
1037 make_generic ("eoshift", GFC_ISYM_EOSHIFT);
1039 add_sym_1 ("epsilon", 0, 1, BT_REAL, dr,
1040 gfc_check_x, gfc_simplify_epsilon, NULL,
1043 make_generic ("epsilon", GFC_ISYM_NONE);
1045 /* G77 compatibility */
1046 add_sym_1 ("etime", 0, 1, BT_REAL, 4,
1047 gfc_check_etime, NULL, NULL,
1050 make_alias ("dtime");
1052 make_generic ("etime", GFC_ISYM_ETIME);
1055 add_sym_1 ("exp", 1, 1, BT_REAL, dr,
1056 NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_REAL, dr, 0);
1058 add_sym_1 ("dexp", 1, 1, BT_REAL, dd,
1059 NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_REAL, dd, 0);
1061 add_sym_1 ("cexp", 1, 1, BT_COMPLEX, dz,
1062 NULL, gfc_simplify_exp, gfc_resolve_exp,
1063 x, BT_COMPLEX, dz, 0);
1065 add_sym_1 ("zexp", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_COMPLEX, dd, 0); /* Extension */
1067 make_alias ("cdexp");
1069 make_generic ("exp", GFC_ISYM_EXP);
1071 add_sym_1 ("exponent", 1, 1, BT_INTEGER, di,
1072 gfc_check_x, gfc_simplify_exponent, gfc_resolve_exponent,
1075 make_generic ("exponent", GFC_ISYM_EXPONENT);
1077 add_sym_2 ("floor", 1, 1, BT_INTEGER, di,
1078 gfc_check_a_ikind, gfc_simplify_floor, gfc_resolve_floor,
1079 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1081 make_generic ("floor", GFC_ISYM_FLOOR);
1083 add_sym_1 ("fraction", 1, 1, BT_REAL, dr,
1084 gfc_check_x, gfc_simplify_fraction, gfc_resolve_fraction,
1087 make_generic ("fraction", GFC_ISYM_FRACTION);
1089 add_sym_1 ("huge", 0, 1, BT_REAL, dr,
1090 gfc_check_huge, gfc_simplify_huge, NULL,
1091 x, BT_UNKNOWN, dr, 0);
1093 make_generic ("huge", GFC_ISYM_NONE);
1095 add_sym_1 ("iachar", 1, 1, BT_INTEGER, di,
1096 NULL, gfc_simplify_iachar, NULL, c, BT_CHARACTER, dc, 0);
1098 make_generic ("iachar", GFC_ISYM_IACHAR);
1100 add_sym_2 ("iand", 1, 1, BT_INTEGER, di,
1101 gfc_check_iand, gfc_simplify_iand, gfc_resolve_iand,
1102 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1104 make_generic ("iand", GFC_ISYM_IAND);
1106 add_sym_0 ("iargc", 1, 1, BT_INTEGER, di, NULL, NULL, NULL); /* Extension, takes no arguments */
1108 add_sym_2 ("ibclr", 1, 1, BT_INTEGER, di,
1109 gfc_check_ibclr, gfc_simplify_ibclr, gfc_resolve_ibclr,
1110 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1112 make_generic ("ibclr", GFC_ISYM_IBCLR);
1114 add_sym_3 ("ibits", 1, 1, BT_INTEGER, di,
1115 gfc_check_ibits, gfc_simplify_ibits, gfc_resolve_ibits,
1116 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0,
1117 ln, BT_INTEGER, di, 0);
1119 make_generic ("ibits", GFC_ISYM_IBITS);
1121 add_sym_2 ("ibset", 1, 1, BT_INTEGER, di,
1122 gfc_check_ibset, gfc_simplify_ibset, gfc_resolve_ibset,
1123 i, BT_INTEGER, di, 0, pos, BT_INTEGER, di, 0);
1125 make_generic ("ibset", GFC_ISYM_IBSET);
1127 add_sym_1 ("ichar", 1, 0, BT_INTEGER, di,
1128 NULL, gfc_simplify_ichar, gfc_resolve_ichar,
1129 c, BT_CHARACTER, dc, 0);
1131 make_generic ("ichar", GFC_ISYM_ICHAR);
1133 add_sym_2 ("ieor", 1, 1, BT_INTEGER, di,
1134 gfc_check_ieor, gfc_simplify_ieor, gfc_resolve_ieor,
1135 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1137 make_generic ("ieor", GFC_ISYM_IEOR);
1139 add_sym_3 ("index", 1, 1, BT_INTEGER, di,
1140 gfc_check_index, gfc_simplify_index, NULL,
1141 stg, BT_CHARACTER, dc, 0, ssg, BT_CHARACTER, dc, 0,
1142 bck, BT_LOGICAL, dl, 1);
1144 make_generic ("index", GFC_ISYM_INDEX);
1146 add_sym_2 ("int", 1, 1, BT_INTEGER, di,
1147 gfc_check_int, gfc_simplify_int, gfc_resolve_int,
1148 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1150 add_sym_1 ("ifix", 1, 0, BT_INTEGER, di,
1151 NULL, gfc_simplify_ifix, NULL, a, BT_REAL, dr, 0);
1153 add_sym_1 ("idint", 1, 0, BT_INTEGER, di,
1154 NULL, gfc_simplify_idint, NULL, a, BT_REAL, dd, 0);
1156 make_generic ("int", GFC_ISYM_INT);
1158 add_sym_2 ("ior", 1, 1, BT_INTEGER, di,
1159 gfc_check_ior, gfc_simplify_ior, gfc_resolve_ior,
1160 i, BT_INTEGER, di, 0, j, BT_INTEGER, di, 0);
1162 make_generic ("ior", GFC_ISYM_IOR);
1164 /* The following function is for G77 compatibility. */
1165 add_sym_1 ("irand", 0, 1, BT_INTEGER, 4,
1166 gfc_check_irand, NULL, NULL,
1167 i, BT_INTEGER, 4, 0);
1169 make_generic ("irand", GFC_ISYM_IRAND);
1171 add_sym_2 ("ishft", 1, 1, BT_INTEGER, di,
1172 gfc_check_ishft, gfc_simplify_ishft, gfc_resolve_ishft,
1173 i, BT_INTEGER, di, 0, sh, BT_INTEGER, di, 0);
1175 make_generic ("ishft", GFC_ISYM_ISHFT);
1177 add_sym_3 ("ishftc", 1, 1, BT_INTEGER, di,
1178 gfc_check_ishftc, gfc_simplify_ishftc, gfc_resolve_ishftc,
1179 i, BT_INTEGER, di, 0, sh, BT_INTEGER, di, 0,
1180 sz, BT_INTEGER, di, 1);
1182 make_generic ("ishftc", GFC_ISYM_ISHFTC);
1184 add_sym_1 ("kind", 0, 1, BT_INTEGER, di,
1185 gfc_check_kind, gfc_simplify_kind, NULL, x, BT_REAL, dr, 0);
1187 make_generic ("kind", GFC_ISYM_NONE);
1189 add_sym_2 ("lbound", 0, 1, BT_INTEGER, di,
1190 gfc_check_lbound, gfc_simplify_lbound, gfc_resolve_lbound,
1191 ar, BT_REAL, dr, 0, dm, BT_INTEGER, di, 1);
1193 make_generic ("lbound", GFC_ISYM_LBOUND);
1195 add_sym_1 ("len", 0, 1, BT_INTEGER, di,
1196 NULL, gfc_simplify_len, gfc_resolve_len,
1197 stg, BT_CHARACTER, dc, 0);
1199 make_generic ("len", GFC_ISYM_LEN);
1201 add_sym_1 ("len_trim", 1, 1, BT_INTEGER, di,
1202 NULL, gfc_simplify_len_trim, gfc_resolve_len_trim,
1203 stg, BT_CHARACTER, dc, 0);
1205 make_generic ("len_trim", GFC_ISYM_LEN_TRIM);
1207 add_sym_2 ("lge", 1, 0, BT_LOGICAL, dl,
1208 NULL, gfc_simplify_lge, NULL,
1209 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1211 make_generic ("lge", GFC_ISYM_LGE);
1213 add_sym_2 ("lgt", 1, 0, BT_LOGICAL, dl,
1214 NULL, gfc_simplify_lgt, NULL,
1215 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1217 make_generic ("lgt", GFC_ISYM_LGT);
1219 add_sym_2 ("lle", 1, 0, BT_LOGICAL, dl,
1220 NULL, gfc_simplify_lle, NULL,
1221 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1223 make_generic ("lle", GFC_ISYM_LLE);
1225 add_sym_2 ("llt", 1, 0, BT_LOGICAL, dl,
1226 NULL, gfc_simplify_llt, NULL,
1227 sta, BT_CHARACTER, dc, 0, stb, BT_CHARACTER, dc, 0);
1229 make_generic ("llt", GFC_ISYM_LLT);
1231 add_sym_1 ("log", 1, 1, BT_REAL, dr,
1232 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dr, 0);
1234 add_sym_1 ("alog", 1, 1, BT_REAL, dr,
1235 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dr, 0);
1237 add_sym_1 ("dlog", 1, 1, BT_REAL, dd,
1238 NULL, gfc_simplify_log, gfc_resolve_log, x, BT_REAL, dd, 0);
1240 add_sym_1 ("clog", 1, 1, BT_COMPLEX, dz,
1241 NULL, gfc_simplify_log, gfc_resolve_log,
1242 x, BT_COMPLEX, dz, 0);
1244 add_sym_1 ("zlog", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_log, gfc_resolve_log, x, BT_COMPLEX, dd, 0); /* Extension */
1246 make_alias ("cdlog");
1248 make_generic ("log", GFC_ISYM_LOG);
1250 add_sym_1 ("log10", 1, 1, BT_REAL, dr,
1251 NULL, gfc_simplify_log10, gfc_resolve_log10,
1254 add_sym_1 ("alog10", 1, 1, BT_REAL, dr,
1255 NULL, gfc_simplify_log10, gfc_resolve_log10,
1258 add_sym_1 ("dlog10", 1, 1, BT_REAL, dd,
1259 NULL, gfc_simplify_log10, gfc_resolve_log10,
1262 make_generic ("log10", GFC_ISYM_LOG10);
1264 add_sym_2 ("logical", 0, 1, BT_LOGICAL, dl,
1265 gfc_check_logical, gfc_simplify_logical, gfc_resolve_logical,
1266 l, BT_LOGICAL, dl, 0, kind, BT_INTEGER, di, 1);
1268 make_generic ("logical", GFC_ISYM_LOGICAL);
1270 add_sym_2 ("matmul", 0, 1, BT_REAL, dr,
1271 gfc_check_matmul, NULL, gfc_resolve_matmul,
1272 ma, BT_REAL, dr, 0, mb, BT_REAL, dr, 0);
1274 make_generic ("matmul", GFC_ISYM_MATMUL);
1276 /* Note: amax0 is equivalent to real(max), max1 is equivalent to
1277 int(max). The max function must take at least two arguments. */
1279 add_sym_1m ("max", 1, 0, BT_UNKNOWN, 0,
1280 gfc_check_min_max, gfc_simplify_max, gfc_resolve_max,
1281 a1, BT_UNKNOWN, dr, 0, a2, BT_UNKNOWN, dr, 0);
1283 add_sym_1m ("max0", 1, 0, BT_INTEGER, di,
1284 gfc_check_min_max_integer, gfc_simplify_max, NULL,
1285 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1287 add_sym_1m ("amax0", 1, 0, BT_REAL, dr,
1288 gfc_check_min_max_integer, gfc_simplify_max, NULL,
1289 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1291 add_sym_1m ("amax1", 1, 0, BT_REAL, dr,
1292 gfc_check_min_max_real, gfc_simplify_max, NULL,
1293 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1295 add_sym_1m ("max1", 1, 0, BT_INTEGER, di,
1296 gfc_check_min_max_real, gfc_simplify_max, NULL,
1297 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1299 add_sym_1m ("dmax1", 1, 0, BT_REAL, dd,
1300 gfc_check_min_max_double, gfc_simplify_max, NULL,
1301 a1, BT_REAL, dd, 0, a2, BT_REAL, dd, 0);
1303 make_generic ("max", GFC_ISYM_MAX);
1305 add_sym_1 ("maxexponent", 0, 1, BT_INTEGER, di,
1306 gfc_check_x, gfc_simplify_maxexponent, NULL,
1307 x, BT_UNKNOWN, dr, 0);
1309 make_generic ("maxexponent", GFC_ISYM_NONE);
1311 add_sym_3ml ("maxloc", 0, 1, BT_INTEGER, di,
1312 gfc_check_minloc_maxloc, NULL, gfc_resolve_maxloc,
1313 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1314 msk, BT_LOGICAL, dl, 1);
1316 make_generic ("maxloc", GFC_ISYM_MAXLOC);
1318 add_sym_3 ("maxval", 0, 1, BT_REAL, dr,
1319 gfc_check_minval_maxval, NULL, gfc_resolve_maxval,
1320 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1321 msk, BT_LOGICAL, dl, 1);
1323 make_generic ("maxval", GFC_ISYM_MAXVAL);
1325 add_sym_3 ("merge", 1, 1, BT_REAL, dr,
1326 gfc_check_merge, NULL, gfc_resolve_merge,
1327 ts, BT_REAL, dr, 0, fs, BT_REAL, dr, 0,
1328 msk, BT_LOGICAL, dl, 0);
1330 make_generic ("merge", GFC_ISYM_MERGE);
1332 /* Note: amin0 is equivalent to real(min), min1 is equivalent to int(min). */
1334 add_sym_1m ("min", 1, 0, BT_UNKNOWN, 0,
1335 gfc_check_min_max, gfc_simplify_min, gfc_resolve_min,
1336 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1338 add_sym_1m ("min0", 1, 0, BT_INTEGER, di,
1339 gfc_check_min_max_integer, gfc_simplify_min, NULL,
1340 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1342 add_sym_1m ("amin0", 1, 0, BT_REAL, dr,
1343 gfc_check_min_max_integer, gfc_simplify_min, NULL,
1344 a1, BT_INTEGER, di, 0, a2, BT_INTEGER, di, 0);
1346 add_sym_1m ("amin1", 1, 0, BT_REAL, dr,
1347 gfc_check_min_max_real, gfc_simplify_min, NULL,
1348 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1350 add_sym_1m ("min1", 1, 0, BT_INTEGER, di,
1351 gfc_check_min_max_real, gfc_simplify_min, NULL,
1352 a1, BT_REAL, dr, 0, a2, BT_REAL, dr, 0);
1354 add_sym_1m ("dmin1", 1, 0, BT_REAL, dd,
1355 gfc_check_min_max_double, gfc_simplify_min, NULL,
1356 a1, BT_REAL, dd, 0, a2, BT_REAL, dd, 0);
1358 make_generic ("min", GFC_ISYM_MIN);
1360 add_sym_1 ("minexponent", 0, 1, BT_INTEGER, di,
1361 gfc_check_x, gfc_simplify_minexponent, NULL,
1362 x, BT_UNKNOWN, dr, 0);
1364 make_generic ("minexponent", GFC_ISYM_NONE);
1366 add_sym_3ml ("minloc", 0, 1, BT_INTEGER, di,
1367 gfc_check_minloc_maxloc, NULL, gfc_resolve_minloc,
1368 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1369 msk, BT_LOGICAL, dl, 1);
1371 make_generic ("minloc", GFC_ISYM_MINLOC);
1373 add_sym_3 ("minval", 0, 1, BT_REAL, dr,
1374 gfc_check_minval_maxval, NULL, gfc_resolve_minval,
1375 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1376 msk, BT_LOGICAL, dl, 1);
1378 make_generic ("minval", GFC_ISYM_MINVAL);
1380 add_sym_2 ("mod", 1, 1, BT_INTEGER, di,
1381 gfc_check_a_p, gfc_simplify_mod, gfc_resolve_mod,
1382 a, BT_INTEGER, di, 0, p, BT_INTEGER, di, 0);
1384 add_sym_2 ("amod", 1, 1, BT_REAL, dr,
1385 NULL, gfc_simplify_mod, gfc_resolve_mod,
1386 a, BT_REAL, dr, 0, p, BT_REAL, dr, 0);
1388 add_sym_2 ("dmod", 1, 1, BT_REAL, dd,
1389 NULL, gfc_simplify_mod, gfc_resolve_mod,
1390 a, BT_REAL, dd, 0, p, BT_REAL, dd, 0);
1392 make_generic ("mod", GFC_ISYM_MOD);
1394 add_sym_2 ("modulo", 1, 1, BT_REAL, di,
1395 gfc_check_a_p, gfc_simplify_modulo, gfc_resolve_modulo,
1396 a, BT_REAL, di, 0, p, BT_REAL, di, 0);
1398 make_generic ("modulo", GFC_ISYM_MODULO);
1400 add_sym_2 ("nearest", 1, 1, BT_REAL, dr,
1401 gfc_check_nearest, gfc_simplify_nearest, gfc_resolve_nearest,
1402 x, BT_REAL, dr, 0, s, BT_REAL, dr, 0);
1404 make_generic ("nearest", GFC_ISYM_NEAREST);
1406 add_sym_2 ("nint", 1, 1, BT_INTEGER, di,
1407 gfc_check_a_ikind, gfc_simplify_nint, gfc_resolve_nint,
1408 a, BT_REAL, dr, 0, kind, BT_INTEGER, di, 1);
1410 add_sym_1 ("idnint", 1, 1, BT_INTEGER, di,
1411 gfc_check_idnint, gfc_simplify_idnint, gfc_resolve_idnint,
1414 make_generic ("nint", GFC_ISYM_NINT);
1416 add_sym_1 ("not", 1, 1, BT_INTEGER, di,
1417 gfc_check_i, gfc_simplify_not, gfc_resolve_not,
1418 i, BT_INTEGER, di, 0);
1420 make_generic ("not", GFC_ISYM_NOT);
1422 add_sym_1 ("null", 0, 1, BT_INTEGER, di,
1423 gfc_check_null, gfc_simplify_null, NULL,
1424 mo, BT_INTEGER, di, 1);
1426 make_generic ("null", GFC_ISYM_NONE);
1428 add_sym_3 ("pack", 0, 1, BT_REAL, dr,
1429 gfc_check_pack, NULL, gfc_resolve_pack,
1430 ar, BT_REAL, dr, 0, msk, BT_LOGICAL, dl, 0,
1433 make_generic ("pack", GFC_ISYM_PACK);
1435 add_sym_1 ("precision", 0, 1, BT_INTEGER, di,
1436 gfc_check_precision, gfc_simplify_precision, NULL,
1437 x, BT_UNKNOWN, 0, 0);
1439 make_generic ("precision", GFC_ISYM_NONE);
1441 add_sym_1 ("present", 0, 1, BT_LOGICAL, dl,
1442 gfc_check_present, NULL, NULL, a, BT_REAL, dr, 0);
1444 make_generic ("present", GFC_ISYM_PRESENT);
1446 add_sym_3 ("product", 0, 1, BT_REAL, dr,
1447 gfc_check_product, NULL, gfc_resolve_product,
1448 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1449 msk, BT_LOGICAL, dl, 1);
1451 make_generic ("product", GFC_ISYM_PRODUCT);
1453 add_sym_1 ("radix", 0, 1, BT_INTEGER, di,
1454 gfc_check_radix, gfc_simplify_radix, NULL,
1455 x, BT_UNKNOWN, 0, 0);
1457 make_generic ("radix", GFC_ISYM_NONE);
1459 /* The following function is for G77 compatibility. */
1460 add_sym_1 ("rand", 0, 1, BT_REAL, 4,
1461 gfc_check_rand, NULL, NULL,
1462 i, BT_INTEGER, 4, 0);
1464 make_generic ("rand", GFC_ISYM_RAND);
1466 add_sym_1 ("range", 0, 1, BT_INTEGER, di,
1467 gfc_check_range, gfc_simplify_range, NULL,
1470 make_generic ("range", GFC_ISYM_NONE);
1472 add_sym_2 ("real", 1, 0, BT_REAL, dr,
1473 gfc_check_real, gfc_simplify_real, gfc_resolve_real,
1474 a, BT_UNKNOWN, dr, 0, kind, BT_INTEGER, di, 1);
1476 add_sym_1 ("float", 1, 0, BT_REAL, dr,
1477 NULL, gfc_simplify_float, NULL, a, BT_INTEGER, di, 0);
1479 add_sym_1 ("sngl", 1, 0, BT_REAL, dr,
1480 NULL, gfc_simplify_sngl, NULL, a, BT_REAL, dd, 0);
1482 make_generic ("real", GFC_ISYM_REAL);
1484 add_sym_2 ("repeat", 0, 1, BT_CHARACTER, dc,
1485 gfc_check_repeat, gfc_simplify_repeat, gfc_resolve_repeat,
1486 stg, BT_CHARACTER, dc, 0, n, BT_INTEGER, di, 0);
1488 make_generic ("repeat", GFC_ISYM_REPEAT);
1490 add_sym_4 ("reshape", 0, 1, BT_REAL, dr,
1491 gfc_check_reshape, gfc_simplify_reshape, gfc_resolve_reshape,
1492 src, BT_REAL, dr, 0, shp, BT_INTEGER, ii, 0,
1493 pad, BT_REAL, dr, 1, ord, BT_INTEGER, ii, 1);
1495 make_generic ("reshape", GFC_ISYM_RESHAPE);
1497 add_sym_1 ("rrspacing", 1, 1, BT_REAL, dr,
1498 gfc_check_x, gfc_simplify_rrspacing, gfc_resolve_rrspacing,
1501 make_generic ("rrspacing", GFC_ISYM_RRSPACING);
1503 add_sym_2 ("scale", 1, 1, BT_REAL, dr,
1504 gfc_check_scale, gfc_simplify_scale, gfc_resolve_scale,
1505 x, BT_REAL, dr, 0, i, BT_INTEGER, di, 0);
1507 make_generic ("scale", GFC_ISYM_SCALE);
1509 add_sym_3 ("scan", 1, 1, BT_INTEGER, di,
1510 gfc_check_scan, gfc_simplify_scan, gfc_resolve_scan,
1511 stg, BT_CHARACTER, dc, 0, set, BT_CHARACTER, dc, 0,
1512 bck, BT_LOGICAL, dl, 1);
1514 make_generic ("scan", GFC_ISYM_SCAN);
1516 /* Added for G77 compatibility garbage. */
1517 add_sym_0 ("second", 0, 1, BT_REAL, 4, NULL, NULL, NULL);
1519 make_generic ("second", GFC_ISYM_SECOND);
1521 add_sym_1 ("selected_int_kind", 0, 1, BT_INTEGER, di,
1522 NULL, gfc_simplify_selected_int_kind, NULL,
1523 r, BT_INTEGER, di, 0);
1525 make_generic ("selected_int_kind", GFC_ISYM_SI_KIND);
1527 add_sym_2 ("selected_real_kind", 0, 1, BT_INTEGER, di,
1528 gfc_check_selected_real_kind, gfc_simplify_selected_real_kind,
1529 NULL, p, BT_INTEGER, di, 1, r, BT_INTEGER, di, 1);
1531 make_generic ("selected_real_kind", GFC_ISYM_SR_KIND);
1533 add_sym_2 ("set_exponent", 1, 1, BT_REAL, dr,
1534 gfc_check_set_exponent, gfc_simplify_set_exponent,
1535 gfc_resolve_set_exponent,
1536 x, BT_REAL, dr, 0, i, BT_INTEGER, di, 0);
1538 make_generic ("set_exponent", GFC_ISYM_SET_EXPONENT);
1540 add_sym_1 ("shape", 0, 1, BT_INTEGER, di,
1541 gfc_check_shape, gfc_simplify_shape, gfc_resolve_shape,
1542 src, BT_REAL, dr, 0);
1544 make_generic ("shape", GFC_ISYM_SHAPE);
1546 add_sym_2 ("sign", 1, 1, BT_REAL, dr,
1547 gfc_check_sign, gfc_simplify_sign, gfc_resolve_sign,
1548 a, BT_REAL, dr, 0, b, BT_REAL, dr, 0);
1550 add_sym_2 ("isign", 1, 1, BT_INTEGER, di,
1551 NULL, gfc_simplify_sign, gfc_resolve_sign,
1552 a, BT_INTEGER, di, 0, b, BT_INTEGER, di, 0);
1554 add_sym_2 ("dsign", 1, 1, BT_REAL, dd,
1555 NULL, gfc_simplify_sign, gfc_resolve_sign,
1556 a, BT_REAL, dd, 0, b, BT_REAL, dd, 0);
1558 make_generic ("sign", GFC_ISYM_SIGN);
1560 add_sym_1 ("sin", 1, 1, BT_REAL, dr,
1561 NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_REAL, dr, 0);
1563 add_sym_1 ("dsin", 1, 1, BT_REAL, dd,
1564 NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_REAL, dd, 0);
1566 add_sym_1 ("csin", 1, 1, BT_COMPLEX, dz,
1567 NULL, gfc_simplify_sin, gfc_resolve_sin,
1568 x, BT_COMPLEX, dz, 0);
1570 add_sym_1 ("zsin", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_sin, gfc_resolve_sin, x, BT_COMPLEX, dd, 0); /* Extension */
1572 make_alias ("cdsin");
1574 make_generic ("sin", GFC_ISYM_SIN);
1576 add_sym_1 ("sinh", 1, 1, BT_REAL, dr,
1577 NULL, gfc_simplify_sinh, gfc_resolve_sinh,
1580 add_sym_1 ("dsinh", 1, 1, BT_REAL, dd,
1581 NULL, gfc_simplify_sinh, gfc_resolve_sinh,
1584 make_generic ("sinh", GFC_ISYM_SINH);
1586 add_sym_2 ("size", 0, 1, BT_INTEGER, di,
1587 gfc_check_size, gfc_simplify_size, NULL,
1588 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1);
1590 make_generic ("size", GFC_ISYM_SIZE);
1592 add_sym_1 ("spacing", 1, 1, BT_REAL, dr,
1593 gfc_check_x, gfc_simplify_spacing, gfc_resolve_spacing,
1596 make_generic ("spacing", GFC_ISYM_SPACING);
1598 add_sym_3 ("spread", 0, 1, BT_REAL, dr,
1599 gfc_check_spread, NULL, gfc_resolve_spread,
1600 src, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 0,
1601 n, BT_INTEGER, di, 0);
1603 make_generic ("spread", GFC_ISYM_SPREAD);
1605 add_sym_1 ("sqrt", 1, 1, BT_REAL, dr,
1606 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1609 add_sym_1 ("dsqrt", 1, 1, BT_REAL, dd,
1610 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1613 add_sym_1 ("csqrt", 1, 1, BT_COMPLEX, dz,
1614 NULL, gfc_simplify_sqrt, gfc_resolve_sqrt,
1615 x, BT_COMPLEX, dz, 0);
1617 add_sym_1 ("zsqrt", 1, 1, BT_COMPLEX, dd, NULL, gfc_simplify_sqrt, gfc_resolve_sqrt, x, BT_COMPLEX, dd, 0); /* Extension */
1619 make_alias ("cdsqrt");
1621 make_generic ("sqrt", GFC_ISYM_SQRT);
1623 add_sym_3 ("sum", 0, 1, BT_UNKNOWN, 0,
1624 gfc_check_sum, NULL, gfc_resolve_sum,
1625 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1,
1626 msk, BT_LOGICAL, dl, 1);
1628 make_generic ("sum", GFC_ISYM_SUM);
1630 add_sym_1 ("tan", 1, 1, BT_REAL, dr,
1631 NULL, gfc_simplify_tan, gfc_resolve_tan, x, BT_REAL, dr, 0);
1633 add_sym_1 ("dtan", 1, 1, BT_REAL, dd,
1634 NULL, gfc_simplify_tan, gfc_resolve_tan, x, BT_REAL, dd, 0);
1636 make_generic ("tan", GFC_ISYM_TAN);
1638 add_sym_1 ("tanh", 1, 1, BT_REAL, dr,
1639 NULL, gfc_simplify_tanh, gfc_resolve_tanh,
1642 add_sym_1 ("dtanh", 1, 1, BT_REAL, dd,
1643 NULL, gfc_simplify_tanh, gfc_resolve_tanh,
1646 make_generic ("tanh", GFC_ISYM_TANH);
1648 add_sym_1 ("tiny", 0, 1, BT_REAL, dr,
1649 gfc_check_x, gfc_simplify_tiny, NULL, x, BT_REAL, dr, 0);
1651 make_generic ("tiny", GFC_ISYM_NONE);
1653 add_sym_3 ("transfer", 0, 1, BT_REAL, dr,
1654 gfc_check_transfer, NULL, gfc_resolve_transfer,
1655 src, BT_REAL, dr, 0, mo, BT_REAL, dr, 0,
1656 sz, BT_INTEGER, di, 1);
1658 make_generic ("transfer", GFC_ISYM_TRANSFER);
1660 add_sym_1 ("transpose", 0, 1, BT_REAL, dr,
1661 gfc_check_transpose, NULL, gfc_resolve_transpose,
1664 make_generic ("transpose", GFC_ISYM_TRANSPOSE);
1666 add_sym_1 ("trim", 0, 1, BT_CHARACTER, dc,
1667 gfc_check_trim, gfc_simplify_trim, gfc_resolve_trim,
1668 stg, BT_CHARACTER, dc, 0);
1670 make_generic ("trim", GFC_ISYM_TRIM);
1672 add_sym_2 ("ubound", 0, 1, BT_INTEGER, di,
1673 gfc_check_ubound, gfc_simplify_ubound, gfc_resolve_ubound,
1674 ar, BT_REAL, dr, 0, dm, BT_INTEGER, ii, 1);
1676 make_generic ("ubound", GFC_ISYM_UBOUND);
1678 add_sym_3 ("unpack", 0, 1, BT_REAL, dr,
1679 gfc_check_unpack, NULL, gfc_resolve_unpack,
1680 v, BT_REAL, dr, 0, msk, BT_LOGICAL, dl, 0,
1683 make_generic ("unpack", GFC_ISYM_UNPACK);
1685 add_sym_3 ("verify", 1, 1, BT_INTEGER, di,
1686 gfc_check_verify, gfc_simplify_verify, gfc_resolve_verify,
1687 stg, BT_CHARACTER, dc, 0, set, BT_CHARACTER, dc, 0,
1688 bck, BT_LOGICAL, dl, 1);
1690 make_generic ("verify", GFC_ISYM_VERIFY);
1697 /* Add intrinsic subroutines. */
1700 add_subroutines (void)
1702 /* Argument names as in the standard (to be used as argument keywords). */
1704 *h = "harvest", *dt = "date", *vl = "values", *pt = "put",
1705 *c = "count", *tm = "time", *tp = "topos", *gt = "get",
1706 *t = "to", *zn = "zone", *fp = "frompos", *cm = "count_max",
1707 *f = "from", *sz = "size", *ln = "len", *cr = "count_rate";
1711 di = gfc_default_integer_kind ();
1712 dr = gfc_default_real_kind ();
1713 dc = gfc_default_character_kind ();
1715 add_sym_0s ("abort", 1, NULL);
1717 add_sym_1s ("cpu_time", 0, 1, BT_UNKNOWN, 0,
1718 gfc_check_cpu_time, NULL, gfc_resolve_cpu_time,
1719 tm, BT_REAL, dr, 0);
1721 /* More G77 compatibility garbage. */
1722 add_sym_1s ("second", 0, 1, BT_UNKNOWN, 0,
1723 gfc_check_second_sub, NULL, gfc_resolve_second_sub,
1724 tm, BT_REAL, dr, 0);
1726 add_sym_4 ("date_and_time", 0, 1, BT_UNKNOWN, 0,
1727 gfc_check_date_and_time, NULL, NULL,
1728 dt, BT_CHARACTER, dc, 1, tm, BT_CHARACTER, dc, 1,
1729 zn, BT_CHARACTER, dc, 1, vl, BT_INTEGER, di, 1);
1731 /* More G77 compatibility garbage. */
1732 add_sym_2s ("etime", 0, 1, BT_UNKNOWN, 0,
1733 gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
1734 vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
1736 add_sym_2s ("dtime", 0, 1, BT_UNKNOWN, 0,
1737 gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
1738 vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
1740 add_sym_2 ("getarg", 0, 1, BT_UNKNOWN, 0,
1742 c, BT_INTEGER, di, 0, vl, BT_CHARACTER, dc, 0);
1745 add_sym_5 ("mvbits", 1, 1, BT_UNKNOWN, 0,
1746 gfc_check_mvbits, gfc_simplify_mvbits, NULL,
1747 f, BT_INTEGER, di, 0, fp, BT_INTEGER, di, 0,
1748 ln, BT_INTEGER, di, 0, t, BT_INTEGER, di, 0,
1749 tp, BT_INTEGER, di, 0);
1751 add_sym_1s ("random_number", 0, 1, BT_UNKNOWN, 0,
1752 gfc_check_random_number, NULL, gfc_resolve_random_number,
1755 add_sym_3s ("random_seed", 0, 1, BT_UNKNOWN, 0,
1756 gfc_check_random_seed, NULL, NULL,
1757 sz, BT_INTEGER, di, 1, pt, BT_INTEGER, di, 1,
1758 gt, BT_INTEGER, di, 1);
1760 /* More G77 compatibility garbage. */
1761 add_sym_1s ("srand", 0, 1, BT_UNKNOWN, di,
1762 gfc_check_srand, NULL, gfc_resolve_srand,
1763 c, BT_INTEGER, 4, 0);
1765 add_sym_3s ("system_clock", 0, 1, BT_UNKNOWN, 0,
1766 gfc_check_system_clock, NULL, gfc_resolve_system_clock,
1767 c, BT_INTEGER, di, 1, cr, BT_INTEGER, di, 1,
1768 cm, BT_INTEGER, di, 1);
1772 /* Add a function to the list of conversion symbols. */
1775 add_conv (bt from_type, int from_kind, bt to_type, int to_kind,
1776 gfc_expr * (*simplify) (gfc_expr *, bt, int))
1779 gfc_typespec from, to;
1780 gfc_intrinsic_sym *sym;
1782 if (sizing == SZ_CONVS)
1788 gfc_clear_ts (&from);
1789 from.type = from_type;
1790 from.kind = from_kind;
1796 sym = conversion + nconv;
1798 strcpy (sym->name, conv_name (&from, &to));
1799 strcpy (sym->lib_name, sym->name);
1800 sym->simplify.cc = simplify;
1803 sym->generic_id = GFC_ISYM_CONVERSION;
1809 /* Create gfc_intrinsic_sym nodes for all intrinsic conversion
1810 functions by looping over the kind tables. */
1813 add_conversions (void)
1817 /* Integer-Integer conversions. */
1818 for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
1819 for (j = 0; gfc_integer_kinds[j].kind != 0; j++)
1824 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
1825 BT_INTEGER, gfc_integer_kinds[j].kind, gfc_convert_constant);
1828 /* Integer-Real/Complex conversions. */
1829 for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
1830 for (j = 0; gfc_real_kinds[j].kind != 0; j++)
1832 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
1833 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
1835 add_conv (BT_REAL, gfc_real_kinds[j].kind,
1836 BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant);
1838 add_conv (BT_INTEGER, gfc_integer_kinds[i].kind,
1839 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
1841 add_conv (BT_COMPLEX, gfc_real_kinds[j].kind,
1842 BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant);
1845 /* Real/Complex - Real/Complex conversions. */
1846 for (i = 0; gfc_real_kinds[i].kind != 0; i++)
1847 for (j = 0; gfc_real_kinds[j].kind != 0; j++)
1851 add_conv (BT_REAL, gfc_real_kinds[i].kind,
1852 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
1854 add_conv (BT_COMPLEX, gfc_real_kinds[i].kind,
1855 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
1858 add_conv (BT_REAL, gfc_real_kinds[i].kind,
1859 BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant);
1861 add_conv (BT_COMPLEX, gfc_real_kinds[i].kind,
1862 BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant);
1865 /* Logical/Logical kind conversion. */
1866 for (i = 0; gfc_logical_kinds[i].kind; i++)
1867 for (j = 0; gfc_logical_kinds[j].kind; j++)
1872 add_conv (BT_LOGICAL, gfc_logical_kinds[i].kind,
1873 BT_LOGICAL, gfc_logical_kinds[j].kind, gfc_convert_constant);
1878 /* Initialize the table of intrinsics. */
1880 gfc_intrinsic_init_1 (void)
1884 nargs = nfunc = nsub = nconv = 0;
1886 /* Create a namespace to hold the resolved intrinsic symbols. */
1887 gfc_intrinsic_namespace = gfc_get_namespace (NULL);
1896 functions = gfc_getmem (sizeof (gfc_intrinsic_sym) * (nfunc + nsub)
1897 + sizeof (gfc_intrinsic_arg) * nargs);
1899 next_sym = functions;
1900 subroutines = functions + nfunc;
1902 conversion = gfc_getmem (sizeof (gfc_intrinsic_sym) * nconv);
1904 next_arg = ((gfc_intrinsic_arg *) (subroutines + nsub)) - 1;
1906 sizing = SZ_NOTHING;
1913 /* Set the pure flag. All intrinsic functions are pure, and
1914 intrinsic subroutines are pure if they are elemental. */
1916 for (i = 0; i < nfunc; i++)
1917 functions[i].pure = 1;
1919 for (i = 0; i < nsub; i++)
1920 subroutines[i].pure = subroutines[i].elemental;
1925 gfc_intrinsic_done_1 (void)
1927 gfc_free (functions);
1928 gfc_free (conversion);
1929 gfc_free_namespace (gfc_intrinsic_namespace);
1933 /******** Subroutines to check intrinsic interfaces ***********/
1935 /* Given a formal argument list, remove any NULL arguments that may
1936 have been left behind by a sort against some formal argument list. */
1939 remove_nullargs (gfc_actual_arglist ** ap)
1941 gfc_actual_arglist *head, *tail, *next;
1945 for (head = *ap; head; head = next)
1949 if (head->expr == NULL)
1952 gfc_free_actual_arglist (head);
1971 /* Given an actual arglist and a formal arglist, sort the actual
1972 arglist so that its arguments are in a one-to-one correspondence
1973 with the format arglist. Arguments that are not present are given
1974 a blank gfc_actual_arglist structure. If something is obviously
1975 wrong (say, a missing required argument) we abort sorting and
1979 sort_actual (const char *name, gfc_actual_arglist ** ap,
1980 gfc_intrinsic_arg * formal, locus * where)
1983 gfc_actual_arglist *actual, *a;
1984 gfc_intrinsic_arg *f;
1986 remove_nullargs (ap);
1989 for (f = formal; f; f = f->next)
1995 if (f == NULL && a == NULL) /* No arguments */
1999 { /* Put the nonkeyword arguments in a 1:1 correspondence */
2005 if (a->name[0] != '\0')
2017 gfc_error ("Too many arguments in call to '%s' at %L", name, where);
2021 /* Associate the remaining actual arguments, all of which have
2022 to be keyword arguments. */
2023 for (; a; a = a->next)
2025 for (f = formal; f; f = f->next)
2026 if (strcmp (a->name, f->name) == 0)
2031 gfc_error ("Can't find keyword named '%s' in call to '%s' at %L",
2032 a->name, name, where);
2036 if (f->actual != NULL)
2038 gfc_error ("Argument '%s' is appears twice in call to '%s' at %L",
2039 f->name, name, where);
2047 /* At this point, all unmatched formal args must be optional. */
2048 for (f = formal; f; f = f->next)
2050 if (f->actual == NULL && f->optional == 0)
2052 gfc_error ("Missing actual argument '%s' in call to '%s' at %L",
2053 f->name, name, where);
2059 /* Using the formal argument list, string the actual argument list
2060 together in a way that corresponds with the formal list. */
2063 for (f = formal; f; f = f->next)
2065 if (f->actual == NULL)
2067 a = gfc_get_actual_arglist ();
2068 a->missing_arg_type = f->ts.type;
2080 actual->next = NULL; /* End the sorted argument list. */
2086 /* Compare an actual argument list with an intrinsic's formal argument
2087 list. The lists are checked for agreement of type. We don't check
2088 for arrayness here. */
2091 check_arglist (gfc_actual_arglist ** ap, gfc_intrinsic_sym * sym,
2094 gfc_actual_arglist *actual;
2095 gfc_intrinsic_arg *formal;
2098 formal = sym->formal;
2102 for (; formal; formal = formal->next, actual = actual->next, i++)
2104 if (actual->expr == NULL)
2107 if (!gfc_compare_types (&formal->ts, &actual->expr->ts))
2111 ("Type of argument '%s' in call to '%s' at %L should be "
2112 "%s, not %s", gfc_current_intrinsic_arg[i],
2113 gfc_current_intrinsic, &actual->expr->where,
2114 gfc_typename (&formal->ts), gfc_typename (&actual->expr->ts));
2123 /* Given a pointer to an intrinsic symbol and an expression node that
2124 represent the function call to that subroutine, figure out the type
2125 of the result. This may involve calling a resolution subroutine. */
2128 resolve_intrinsic (gfc_intrinsic_sym * specific, gfc_expr * e)
2130 gfc_expr *a1, *a2, *a3, *a4, *a5;
2131 gfc_actual_arglist *arg;
2133 if (specific->resolve.f1 == NULL)
2135 if (e->value.function.name == NULL)
2136 e->value.function.name = specific->lib_name;
2138 if (e->ts.type == BT_UNKNOWN)
2139 e->ts = specific->ts;
2143 arg = e->value.function.actual;
2145 /* At present only the iargc extension intrinsic takes no arguments,
2146 and it doesn't need a resolution function, but this is here for
2150 (*specific->resolve.f0) (e);
2154 /* Special case hacks for MIN and MAX. */
2155 if (specific->resolve.f1m == gfc_resolve_max
2156 || specific->resolve.f1m == gfc_resolve_min)
2158 (*specific->resolve.f1m) (e, arg);
2167 (*specific->resolve.f1) (e, a1);
2176 (*specific->resolve.f2) (e, a1, a2);
2185 (*specific->resolve.f3) (e, a1, a2, a3);
2194 (*specific->resolve.f4) (e, a1, a2, a3, a4);
2203 (*specific->resolve.f5) (e, a1, a2, a3, a4, a5);
2207 gfc_internal_error ("resolve_intrinsic(): Too many args for intrinsic");
2211 /* Given an intrinsic symbol node and an expression node, call the
2212 simplification function (if there is one), perhaps replacing the
2213 expression with something simpler. We return FAILURE on an error
2214 of the simplification, SUCCESS if the simplification worked, even
2215 if nothing has changed in the expression itself. */
2218 do_simplify (gfc_intrinsic_sym * specific, gfc_expr * e)
2220 gfc_expr *result, *a1, *a2, *a3, *a4, *a5;
2221 gfc_actual_arglist *arg;
2223 /* Max and min require special handling due to the variable number
2225 if (specific->simplify.f1 == gfc_simplify_min)
2227 result = gfc_simplify_min (e);
2231 if (specific->simplify.f1 == gfc_simplify_max)
2233 result = gfc_simplify_max (e);
2237 if (specific->simplify.f1 == NULL)
2243 arg = e->value.function.actual;
2248 if (specific->simplify.cc == gfc_convert_constant)
2250 result = gfc_convert_constant (a1, specific->ts.type, specific->ts.kind);
2254 /* TODO: Warn if -pedantic and initialization expression and arg
2255 types not integer or character */
2258 result = (*specific->simplify.f1) (a1);
2265 result = (*specific->simplify.f2) (a1, a2);
2272 result = (*specific->simplify.f3) (a1, a2, a3);
2279 result = (*specific->simplify.f4) (a1, a2, a3, a4);
2286 result = (*specific->simplify.f5) (a1, a2, a3, a4, a5);
2289 ("do_simplify(): Too many args for intrinsic");
2296 if (result == &gfc_bad_expr)
2300 resolve_intrinsic (specific, e); /* Must call at run-time */
2303 result->where = e->where;
2304 gfc_replace_expr (e, result);
2311 /* Initialize the gfc_current_intrinsic_arg[] array for the benefit of
2312 error messages. This subroutine returns FAILURE if a subroutine
2313 has more than MAX_INTRINSIC_ARGS, in which case the actual argument
2314 list cannot match any intrinsic. */
2317 init_arglist (gfc_intrinsic_sym * isym)
2319 gfc_intrinsic_arg *formal;
2322 gfc_current_intrinsic = isym->name;
2325 for (formal = isym->formal; formal; formal = formal->next)
2327 if (i >= MAX_INTRINSIC_ARGS)
2328 gfc_internal_error ("init_arglist(): too many arguments");
2329 gfc_current_intrinsic_arg[i++] = formal->name;
2334 /* Given a pointer to an intrinsic symbol and an expression consisting
2335 of a function call, see if the function call is consistent with the
2336 intrinsic's formal argument list. Return SUCCESS if the expression
2337 and intrinsic match, FAILURE otherwise. */
2340 check_specific (gfc_intrinsic_sym * specific, gfc_expr * expr, int error_flag)
2342 gfc_actual_arglist *arg, **ap;
2346 ap = &expr->value.function.actual;
2348 init_arglist (specific);
2350 /* Don't attempt to sort the argument list for min or max. */
2351 if (specific->check.f1m == gfc_check_min_max
2352 || specific->check.f1m == gfc_check_min_max_integer
2353 || specific->check.f1m == gfc_check_min_max_real
2354 || specific->check.f1m == gfc_check_min_max_double)
2355 return (*specific->check.f1m) (*ap);
2357 if (sort_actual (specific->name, ap, specific->formal,
2358 &expr->where) == FAILURE)
2361 if (specific->check.f3ml != gfc_check_minloc_maxloc)
2363 if (specific->check.f1 == NULL)
2365 t = check_arglist (ap, specific, error_flag);
2367 expr->ts = specific->ts;
2370 t = do_check (specific, *ap);
2373 /* This is special because we might have to reorder the argument
2375 t = gfc_check_minloc_maxloc (*ap);
2377 /* Check ranks for elemental intrinsics. */
2378 if (t == SUCCESS && specific->elemental)
2381 for (arg = expr->value.function.actual; arg; arg = arg->next)
2383 if (arg->expr == NULL || arg->expr->rank == 0)
2387 r = arg->expr->rank;
2391 if (arg->expr->rank != r)
2394 ("Ranks of arguments to elemental intrinsic '%s' differ "
2395 "at %L", specific->name, &arg->expr->where);
2402 remove_nullargs (ap);
2408 /* See if an intrinsic is one of the intrinsics we evaluate
2412 gfc_init_expr_extensions (gfc_intrinsic_sym *isym)
2414 /* FIXME: This should be moved into the intrinsic definitions. */
2415 static const char * const init_expr_extensions[] = {
2416 "digits", "epsilon", "huge", "kind", "maxexponent", "minexponent",
2417 "precision", "present", "radix", "range", "selected_real_kind",
2423 for (i = 0; init_expr_extensions[i]; i++)
2424 if (strcmp (init_expr_extensions[i], isym->name) == 0)
2431 /* See if a function call corresponds to an intrinsic function call.
2434 MATCH_YES if the call corresponds to an intrinsic, simplification
2435 is done if possible.
2437 MATCH_NO if the call does not correspond to an intrinsic
2439 MATCH_ERROR if the call corresponds to an intrinsic but there was an
2440 error during the simplification process.
2442 The error_flag parameter enables an error reporting. */
2445 gfc_intrinsic_func_interface (gfc_expr * expr, int error_flag)
2447 gfc_intrinsic_sym *isym, *specific;
2448 gfc_actual_arglist *actual;
2452 if (expr->value.function.isym != NULL)
2453 return (do_simplify (expr->value.function.isym, expr) == FAILURE)
2454 ? MATCH_ERROR : MATCH_YES;
2456 gfc_suppress_error = !error_flag;
2459 for (actual = expr->value.function.actual; actual; actual = actual->next)
2460 if (actual->expr != NULL)
2461 flag |= (actual->expr->ts.type != BT_INTEGER
2462 && actual->expr->ts.type != BT_CHARACTER);
2464 name = expr->symtree->n.sym->name;
2466 isym = specific = gfc_find_function (name);
2469 gfc_suppress_error = 0;
2473 gfc_current_intrinsic_where = &expr->where;
2475 /* Bypass the generic list for min and max. */
2476 if (isym->check.f1m == gfc_check_min_max)
2478 init_arglist (isym);
2480 if (gfc_check_min_max (expr->value.function.actual) == SUCCESS)
2483 gfc_suppress_error = 0;
2487 /* If the function is generic, check all of its specific
2488 incarnations. If the generic name is also a specific, we check
2489 that name last, so that any error message will correspond to the
2491 gfc_suppress_error = 1;
2495 for (specific = isym->specific_head; specific;
2496 specific = specific->next)
2498 if (specific == isym)
2500 if (check_specific (specific, expr, 0) == SUCCESS)
2505 gfc_suppress_error = !error_flag;
2507 if (check_specific (isym, expr, error_flag) == FAILURE)
2509 gfc_suppress_error = 0;
2516 expr->value.function.isym = specific;
2517 gfc_intrinsic_symbol (expr->symtree->n.sym);
2519 if (do_simplify (specific, expr) == FAILURE)
2521 gfc_suppress_error = 0;
2525 /* TODO: We should probably only allow elemental functions here. */
2526 flag |= (expr->ts.type != BT_INTEGER && expr->ts.type != BT_CHARACTER);
2528 gfc_suppress_error = 0;
2529 if (pedantic && gfc_init_expr
2530 && flag && gfc_init_expr_extensions (specific))
2532 if (gfc_notify_std (GFC_STD_GNU, "Extension: Evaluation of "
2533 "nonstandard initialization expression at %L", &expr->where)
2544 /* See if a CALL statement corresponds to an intrinsic subroutine.
2545 Returns MATCH_YES if the subroutine corresponds to an intrinsic,
2546 MATCH_NO if not, and MATCH_ERROR if there was an error (but did
2550 gfc_intrinsic_sub_interface (gfc_code * c, int error_flag)
2552 gfc_intrinsic_sym *isym;
2555 name = c->symtree->n.sym->name;
2557 isym = find_subroutine (name);
2561 gfc_suppress_error = !error_flag;
2563 init_arglist (isym);
2565 if (sort_actual (name, &c->ext.actual, isym->formal, &c->loc) == FAILURE)
2568 if (isym->check.f1 != NULL)
2570 if (do_check (isym, c->ext.actual) == FAILURE)
2575 if (check_arglist (&c->ext.actual, isym, 1) == FAILURE)
2579 /* The subroutine corresponds to an intrinsic. Allow errors to be
2580 seen at this point. */
2581 gfc_suppress_error = 0;
2583 if (isym->resolve.s1 != NULL)
2584 isym->resolve.s1 (c);
2586 c->resolved_sym = gfc_get_intrinsic_sub_symbol (isym->lib_name);
2588 if (gfc_pure (NULL) && !isym->elemental)
2590 gfc_error ("Subroutine call to intrinsic '%s' at %L is not PURE", name,
2598 gfc_suppress_error = 0;
2603 /* Call gfc_convert_type() with warning enabled. */
2606 gfc_convert_type (gfc_expr * expr, gfc_typespec * ts, int eflag)
2608 return gfc_convert_type_warn (expr, ts, eflag, 1);
2612 /* Try to convert an expression (in place) from one type to another.
2613 'eflag' controls the behavior on error.
2615 The possible values are:
2617 1 Generate a gfc_error()
2618 2 Generate a gfc_internal_error().
2620 'wflag' controls the warning related to conversion. */
2623 gfc_convert_type_warn (gfc_expr * expr, gfc_typespec * ts, int eflag,
2626 gfc_intrinsic_sym *sym;
2627 gfc_typespec from_ts;
2632 from_ts = expr->ts; /* expr->ts gets clobbered */
2634 if (ts->type == BT_UNKNOWN)
2637 /* NULL and zero size arrays get their type here. */
2638 if (expr->expr_type == EXPR_NULL
2639 || (expr->expr_type == EXPR_ARRAY
2640 && expr->value.constructor == NULL))
2642 /* Sometimes the RHS acquire the type. */
2647 if (expr->ts.type == BT_UNKNOWN)
2650 if (expr->ts.type == BT_DERIVED
2651 && ts->type == BT_DERIVED
2652 && gfc_compare_types (&expr->ts, ts))
2655 sym = find_conv (&expr->ts, ts);
2659 /* At this point, a conversion is necessary. A warning may be needed. */
2660 if (wflag && gfc_option.warn_conversion)
2661 gfc_warning_now ("Conversion from %s to %s at %L",
2662 gfc_typename (&from_ts), gfc_typename (ts), &expr->where);
2664 /* Insert a pre-resolved function call to the right function. */
2665 old_where = expr->where;
2667 new = gfc_get_expr ();
2670 new = gfc_build_conversion (new);
2671 new->value.function.name = sym->lib_name;
2672 new->value.function.isym = sym;
2673 new->where = old_where;
2681 if (gfc_is_constant_expr (expr->value.function.actual->expr)
2682 && do_simplify (sym, expr) == FAILURE)
2687 return FAILURE; /* Error already generated in do_simplify() */
2695 gfc_error ("Can't convert %s to %s at %L",
2696 gfc_typename (&from_ts), gfc_typename (ts), &expr->where);
2700 gfc_internal_error ("Can't convert %s to %s at %L",
2701 gfc_typename (&from_ts), gfc_typename (ts),