diff options
author | pbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-09-20 12:37:44 +0000 |
---|---|---|
committer | pbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-09-20 12:37:44 +0000 |
commit | 2936336994947c3fad8b23ab28fddb9516abcc72 (patch) | |
tree | 9d6ee1043432823c951003a512d457698724da94 /libgfortran | |
parent | 4b62a7eab64445284667e13770bb950319afc89c (diff) |
* trans.h: Add declarations for gfor_fndecl_si_kind and
gfor_fndecl_sr_kind.
* trans-decl.c (g95_build_intrinsic_function_decls): Build them.
* trans-intrinsic.c (g95_conv_intrinsic_si_kind): New function.
(g95_conv_intrinsic_sr_kind): New function.
(g95_conv_intrinsic_function): Add SELECTED_INT_KIND and
SELECTED_REAL_KIND.
* intrinsics/selected_kind.f90: New file.
* Makefile.am: Add it.
* Makefile.in: regenerate.
* gfortran.fortran-torture/execute/intrisic_si_kind.f90: New test.
* gfortran.fortran-torture/execute/intrisic_sr_kind.f90: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/tree-ssa-20020619-branch@71604 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 10 | ||||
-rw-r--r-- | libgfortran/Makefile.am | 1 | ||||
-rw-r--r-- | libgfortran/Makefile.in | 14 | ||||
-rw-r--r-- | libgfortran/intrinsics/selected_kind.f90 | 90 |
4 files changed, 111 insertions, 4 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index f53df0c78f0..7622262af78 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2003-09-20 Kejia Zhao <kejia_zh@yahoo.com.cn> + + * intrinsics/selected_kind.f90: New file. + * Makefile.am: Add it. + * Makefile.in: regenerate. + 2003-09-19 Lars Segerlund <Lars.Segerlund@comsys.se> Paul Brook <paul@nowt.org> @@ -25,10 +31,10 @@ * libgfortran.h (xtoa, itoa): Parameter modified. * io/io.h (namelist_info): Declaration to support namelist I/O (st_parameter): Add namelist related component - (ionml, empty_internal_buffer, st_set_nml_var_int, + (ionml, empty_internal_buffer, st_set_nml_var_int, st_set_nml_var_float, st_set_nml_var_char, st_set_nml_var_complex, st_set_nml_var_log): Declaration - (set_integer, set_integer): Parameter changed + (set_integer, set_integer): Parameter changed * io/format.c (free_nodes): Fix annoying bug of lefting "deallocated" fnodes (parse_format_list): Fix bug about FMT_SLASH diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index fbfd35e5ab2..9fbb5e66b31 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -43,6 +43,7 @@ intrinsics/string_intrinsics.c \ intrinsics/random.c \ intrinsics/reshape_generic.c \ intrinsics/reshape_packed.c \ +intrinsics/selected_kind.f90 \ intrinsics/transpose_generic.c \ intrinsics/unpack_generic.c \ runtime/in_pack_generic.c \ diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in index 0a3de961b27..8e429211c43 100644 --- a/libgfortran/Makefile.in +++ b/libgfortran/Makefile.in @@ -171,6 +171,7 @@ intrinsics/string_intrinsics.c \ intrinsics/random.c \ intrinsics/reshape_generic.c \ intrinsics/reshape_packed.c \ +intrinsics/selected_kind.f90 \ intrinsics/transpose_generic.c \ intrinsics/unpack_generic.c \ runtime/in_pack_generic.c \ @@ -541,8 +542,8 @@ am__objects_25 = backspace.lo close.lo endfile.lo format.lo inquire.lo \ am__objects_26 = associated.lo abort.lo cpu_time.lo eoshift0.lo \ eoshift2.lo ishftc.lo pack_generic.lo size.lo spread_generic.lo \ string_intrinsics.lo random.lo reshape_generic.lo \ - reshape_packed.lo transpose_generic.lo unpack_generic.lo \ - in_pack_generic.lo in_unpack_generic.lo + reshape_packed.lo selected_kind.lo transpose_generic.lo \ + unpack_generic.lo in_pack_generic.lo in_unpack_generic.lo am__objects_27 = am__objects_28 = _abs_r4.lo _abs_r8.lo _exp_r4.lo _exp_r8.lo _exp_c4.lo \ _exp_c8.lo _log_r4.lo _log_r8.lo _log_c4.lo _log_c8.lo \ @@ -5399,6 +5400,15 @@ hyp_c8.lo: generated/hyp_c8.c .f90.lo: $(LTF77COMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$< +selected_kind.o: intrinsics/selected_kind.f90 + $(F77) $(AM_FFLAGS) $(FFLAGS) -c -o selected_kind.o `test -f 'intrinsics/selected_kind.f90' || echo '$(srcdir)/'`intrinsics/selected_kind.f90 + +selected_kind.obj: intrinsics/selected_kind.f90 + $(F77) $(AM_FFLAGS) $(FFLAGS) -c -o selected_kind.obj `if test -f 'intrinsics/selected_kind.f90'; then $(CYGPATH_W) 'intrinsics/selected_kind.f90'; else $(CYGPATH_W) '$(srcdir)/intrinsics/selected_kind.f90'; fi` + +selected_kind.lo: intrinsics/selected_kind.f90 + $(LIBTOOL) --mode=compile $(F77) $(AM_FFLAGS) $(FFLAGS) -c -o selected_kind.lo `test -f 'intrinsics/selected_kind.f90' || echo '$(srcdir)/'`intrinsics/selected_kind.f90 + _abs_r4.o: generated/_abs_r4.f90 $(F77) $(AM_FFLAGS) $(FFLAGS) -c -o _abs_r4.o `test -f 'generated/_abs_r4.f90' || echo '$(srcdir)/'`generated/_abs_r4.f90 diff --git a/libgfortran/intrinsics/selected_kind.f90 b/libgfortran/intrinsics/selected_kind.f90 new file mode 100644 index 00000000000..62d11c7f596 --- /dev/null +++ b/libgfortran/intrinsics/selected_kind.f90 @@ -0,0 +1,90 @@ +! Copyright 2003 Free Software Foundation, Inc. +! Contributed by Kejia Zhao <kejia_zh@yahoo.com.cn> +! +!This file is part of the GNU Fortran 95 runtime library (libgfor). +! +!GNU libgfor is free software; you can redistribute it and/or +!modify it under the terms of the GNU Lesser General Public +!License as published by the Free Software Foundation; either +!version 2.1 of the License, or (at your option) any later version. +! +!GNU libgfor is distributed in the hope that it will be useful, +!but WITHOUT ANY WARRANTY; without even the implied warranty of +!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +!GNU Lesser General Public License for more details. +! +!You should have received a copy of the GNU Lesser General Public +!License along with libgfor; see the file COPYING. If not, +!write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +!Boston, MA 02111-1307, USA. +! + +function selected_int_kind (r) + implicit none + integer, intent (in) :: r + integer :: selected_int_kind + integer :: i + ! Integer kind_range table + integer, parameter :: c = 4 + type :: int_info + integer :: kind + integer :: range + end type int_info + type (int_info), parameter :: int_infos (c) = & + (/int_info (1, range (0_1)), & + int_info (2, range (0_2)), & + int_info (4, range (0_4)), & + int_info (8, range (0_8))/) + + do i = 1, c + if (r <= int_infos (i) % range) then + selected_int_kind = int_infos (i) % kind + return + end if + end do + selected_int_kind = -1 + return +end function + +function selected_real_kind (p, r) + implicit none + integer, optional, intent (in) :: p, r + integer :: selected_real_kind + integer :: i, p2, r2 + logical :: found_p, found_r + ! Real kind_precision_range table + integer, parameter :: c = 2 + type :: real_info + integer :: kind + integer :: precision + integer :: range + end type real_info + type (real_info) :: real_infos (c) = & + (/real_info (4, precision (0.0_4), range (0.0_4)), & + real_info (8, precision (0.0_8), range (0.0_8))/) + + selected_real_kind = 0 + p2 = 0 + r2 = 0 + found_p = .false. + found_r = .false. + + if (present (p)) p2 = p + if (present (r)) r2 = r + + ! Assumes each type has a greater precision and range than previous one. + + do i = 1, c + if (p2 <= real_infos (i) % precision) found_p = .true. + if (r2 <= real_infos (i) % range) found_r = .true. + if (found_p .and. found_r) then + selected_real_kind = real_infos (i) % kind + return + end if + end do + + if (.not. (found_p)) selected_real_kind = selected_real_kind - 1 + if (.not. (found_r)) selected_real_kind = selected_real_kind - 2 + + return +end function |