OSDN Git Service

* runtime/select.c: Moved content to select_inc.c. Include it.
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 18 May 2008 12:00:20 +0000 (12:00 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 18 May 2008 12:00:20 +0000 (12:00 +0000)
        Add macros for different character types.
        * runtime/select_inc.c: New file.
        * runtime/convert_char.c: New file.
        * intrinsics/pack_generic.c (pack_char4, pack_s_char4): New
        functions.
        * intrinsics/transpose_generic.c (transpose_char4): New function.
        * intrinsics/spread_generic.c (spread_char4, spread_char4_scalar):
        New functions.
        * intrinsics/unpack_generic.c (unpack1_char4, unpack0_char4):
        New functions.
        * intrinsics/reshape_generic.c (reshape_char): Use
        gfc_charlen_type as type for length variables.
        (reshape_char4): New function.
        * gfortran.map (GFORTRAN_1.1): Add _gfortran_select_string_char4,
        _gfortran_convert_char1_to_char4, _gfortran_convert_char4_to_char1,
        _gfortran_transpose_char4, _gfortran_spread_char4,
        _gfortran_spread_char4_scalar, _gfortran_reshape_char4,
        _gfortran_pack_char4, _gfortran_pack_s_char4,
        _gfortran_unpack0_char4 and _gfortran_unpack1_char4.
        * Makefile.am: Add runtime/convert_char.c.
        * Makefile.in: Regenerate.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135496 138bc75d-0d04-0410-961f-82ee72b054a4

12 files changed:
libgfortran/ChangeLog
libgfortran/Makefile.am
libgfortran/Makefile.in
libgfortran/gfortran.map
libgfortran/intrinsics/pack_generic.c
libgfortran/intrinsics/reshape_generic.c
libgfortran/intrinsics/spread_generic.c
libgfortran/intrinsics/transpose_generic.c
libgfortran/intrinsics/unpack_generic.c
libgfortran/runtime/convert_char.c [new file with mode: 0644]
libgfortran/runtime/select.c
libgfortran/runtime/select_inc.c [new file with mode: 0644]

index cc61470..a384e6a 100644 (file)
@@ -1,3 +1,28 @@
+2008-05-18  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       * runtime/select.c: Moved content to select_inc.c. Include it. 
+       Add macros for different character types.
+       * runtime/select_inc.c: New file.
+       * runtime/convert_char.c: New file.
+       * intrinsics/pack_generic.c (pack_char4, pack_s_char4): New
+       functions.
+       * intrinsics/transpose_generic.c (transpose_char4): New function.
+       * intrinsics/spread_generic.c (spread_char4, spread_char4_scalar):
+       New functions.
+       * intrinsics/unpack_generic.c (unpack1_char4, unpack0_char4): 
+       New functions.
+       * intrinsics/reshape_generic.c (reshape_char): Use
+       gfc_charlen_type as type for length variables.
+       (reshape_char4): New function.
+       * gfortran.map (GFORTRAN_1.1): Add _gfortran_select_string_char4,
+       _gfortran_convert_char1_to_char4, _gfortran_convert_char4_to_char1,
+       _gfortran_transpose_char4, _gfortran_spread_char4,
+       _gfortran_spread_char4_scalar, _gfortran_reshape_char4,
+       _gfortran_pack_char4, _gfortran_pack_s_char4,
+       _gfortran_unpack0_char4 and _gfortran_unpack1_char4.
+       * Makefile.am: Add runtime/convert_char.c.
+       * Makefile.in: Regenerate.
+
 2008-05-17  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        * io/list_read.c (list_formatted_read_scalar):  Declare
index ed7ad21..65a307a 100644 (file)
@@ -118,6 +118,7 @@ runtime/in_unpack_generic.c
 gfor_src= \
 runtime/backtrace.c \
 runtime/compile_options.c \
+runtime/convert_char.c \
 runtime/environ.c \
 runtime/error.c \
 runtime/fpu.c \
index 1db3991..594d228 100644 (file)
@@ -79,15 +79,15 @@ toolexeclibLTLIBRARIES_INSTALL = $(INSTALL)
 LTLIBRARIES = $(myexeclib_LTLIBRARIES) $(toolexeclib_LTLIBRARIES)
 libgfortran_la_LIBADD =
 am__libgfortran_la_SOURCES_DIST = runtime/backtrace.c \
-       runtime/compile_options.c runtime/environ.c runtime/error.c \
-       runtime/fpu.c runtime/main.c runtime/memory.c runtime/pause.c \
-       runtime/stop.c runtime/string.c runtime/select.c \
-       $(srcdir)/generated/all_l1.c $(srcdir)/generated/all_l2.c \
-       $(srcdir)/generated/all_l4.c $(srcdir)/generated/all_l8.c \
-       $(srcdir)/generated/all_l16.c $(srcdir)/generated/any_l1.c \
-       $(srcdir)/generated/any_l2.c $(srcdir)/generated/any_l4.c \
-       $(srcdir)/generated/any_l8.c $(srcdir)/generated/any_l16.c \
-       $(srcdir)/generated/count_1_l.c \
+       runtime/compile_options.c runtime/convert_char.c \
+       runtime/environ.c runtime/error.c runtime/fpu.c runtime/main.c \
+       runtime/memory.c runtime/pause.c runtime/stop.c \
+       runtime/string.c runtime/select.c $(srcdir)/generated/all_l1.c \
+       $(srcdir)/generated/all_l2.c $(srcdir)/generated/all_l4.c \
+       $(srcdir)/generated/all_l8.c $(srcdir)/generated/all_l16.c \
+       $(srcdir)/generated/any_l1.c $(srcdir)/generated/any_l2.c \
+       $(srcdir)/generated/any_l4.c $(srcdir)/generated/any_l8.c \
+       $(srcdir)/generated/any_l16.c $(srcdir)/generated/count_1_l.c \
        $(srcdir)/generated/count_2_l.c \
        $(srcdir)/generated/count_4_l.c \
        $(srcdir)/generated/count_8_l.c \
@@ -567,8 +567,9 @@ am__libgfortran_la_SOURCES_DIST = runtime/backtrace.c \
        $(srcdir)/generated/misc_specifics.F90 intrinsics/dprod_r8.f90 \
        intrinsics/f2c_specifics.F90 libgfortran_c.c $(filter-out \
        %.c,$(prereq_SRC))
-am__objects_1 = backtrace.lo compile_options.lo environ.lo error.lo \
-       fpu.lo main.lo memory.lo pause.lo stop.lo string.lo select.lo
+am__objects_1 = backtrace.lo compile_options.lo convert_char.lo \
+       environ.lo error.lo fpu.lo main.lo memory.lo pause.lo stop.lo \
+       string.lo select.lo
 am__objects_2 = all_l1.lo all_l2.lo all_l4.lo all_l8.lo all_l16.lo
 am__objects_3 = any_l1.lo any_l2.lo any_l4.lo any_l8.lo any_l16.lo
 am__objects_4 = count_1_l.lo count_2_l.lo count_4_l.lo count_8_l.lo \
@@ -1017,6 +1018,7 @@ runtime/in_unpack_generic.c
 gfor_src = \
 runtime/backtrace.c \
 runtime/compile_options.c \
+runtime/convert_char.c \
 runtime/environ.c \
 runtime/error.c \
 runtime/fpu.c \
@@ -1761,6 +1763,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clock.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/close.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/compile_options.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/convert_char.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/count_16_l.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/count_1_l.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/count_2_l.Plo@am__quote@
@@ -2620,6 +2623,13 @@ compile_options.lo: runtime/compile_options.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o compile_options.lo `test -f 'runtime/compile_options.c' || echo '$(srcdir)/'`runtime/compile_options.c
 
+convert_char.lo: runtime/convert_char.c
+@am__fastdepCC_TRUE@   if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT convert_char.lo -MD -MP -MF "$(DEPDIR)/convert_char.Tpo" -c -o convert_char.lo `test -f 'runtime/convert_char.c' || echo '$(srcdir)/'`runtime/convert_char.c; \
+@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/convert_char.Tpo" "$(DEPDIR)/convert_char.Plo"; else rm -f "$(DEPDIR)/convert_char.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='runtime/convert_char.c' object='convert_char.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o convert_char.lo `test -f 'runtime/convert_char.c' || echo '$(srcdir)/'`runtime/convert_char.c
+
 environ.lo: runtime/environ.c
 @am__fastdepCC_TRUE@   if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT environ.lo -MD -MP -MF "$(DEPDIR)/environ.Tpo" -c -o environ.lo `test -f 'runtime/environ.c' || echo '$(srcdir)/'`runtime/environ.c; \
 @am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/environ.Tpo" "$(DEPDIR)/environ.Plo"; else rm -f "$(DEPDIR)/environ.Tpo"; exit 1; fi
index bd51d80..deac160 100644 (file)
@@ -1049,6 +1049,17 @@ GFORTRAN_1.1 {
     _gfortran_string_scan_char4;
     _gfortran_string_trim_char4;
     _gfortran_string_verify_char4;
+    _gfortran_select_string_char4;
+    _gfortran_convert_char1_to_char4;
+    _gfortran_convert_char4_to_char1;
+    _gfortran_transpose_char4;
+    _gfortran_spread_char4;
+    _gfortran_spread_char4_scalar;
+    _gfortran_reshape_char4;
+    _gfortran_pack_char4;
+    _gfortran_pack_s_char4;
+    _gfortran_unpack0_char4;
+    _gfortran_unpack1_char4;
 } GFORTRAN_1.0; 
 
 F2C_1.0 {
index bb4abae..8f1e08c 100644 (file)
@@ -457,6 +457,7 @@ pack (gfc_array_char *ret, const gfc_array_char *array,
   pack_internal (ret, array, mask, vector, size);
 }
 
+
 extern void pack_char (gfc_array_char *, GFC_INTEGER_4, const gfc_array_char *,
                       const gfc_array_l1 *, const gfc_array_char *,
                       GFC_INTEGER_4, GFC_INTEGER_4);
@@ -472,6 +473,23 @@ pack_char (gfc_array_char *ret,
   pack_internal (ret, array, mask, vector, array_length);
 }
 
+
+extern void pack_char4 (gfc_array_char *, GFC_INTEGER_4, const gfc_array_char *,
+                       const gfc_array_l1 *, const gfc_array_char *,
+                       GFC_INTEGER_4, GFC_INTEGER_4);
+export_proto(pack_char4);
+
+void
+pack_char4 (gfc_array_char *ret,
+           GFC_INTEGER_4 ret_length __attribute__((unused)),
+           const gfc_array_char *array, const gfc_array_l1 *mask,
+           const gfc_array_char *vector, GFC_INTEGER_4 array_length,
+           GFC_INTEGER_4 vector_length __attribute__((unused)))
+{
+  pack_internal (ret, array, mask, vector, array_length * sizeof (gfc_char4_t));
+}
+
+
 static void
 pack_s_internal (gfc_array_char *ret, const gfc_array_char *array,
                 const GFC_LOGICAL_4 *mask, const gfc_array_char *vector,
@@ -641,6 +659,7 @@ pack_s (gfc_array_char *ret, const gfc_array_char *array,
   pack_s_internal (ret, array, mask, vector, GFC_DESCRIPTOR_SIZE (array));
 }
 
+
 extern void pack_s_char (gfc_array_char *ret, GFC_INTEGER_4,
                         const gfc_array_char *array, const GFC_LOGICAL_4 *,
                         const gfc_array_char *, GFC_INTEGER_4,
@@ -656,3 +675,21 @@ pack_s_char (gfc_array_char *ret,
 {
   pack_s_internal (ret, array, mask, vector, array_length);
 }
+
+
+extern void pack_s_char4 (gfc_array_char *ret, GFC_INTEGER_4,
+                         const gfc_array_char *array, const GFC_LOGICAL_4 *,
+                         const gfc_array_char *, GFC_INTEGER_4,
+                         GFC_INTEGER_4);
+export_proto(pack_s_char4);
+
+void
+pack_s_char4 (gfc_array_char *ret,
+             GFC_INTEGER_4 ret_length __attribute__((unused)),
+             const gfc_array_char *array, const GFC_LOGICAL_4 *mask,
+             const gfc_array_char *vector, GFC_INTEGER_4 array_length,
+             GFC_INTEGER_4 vector_length __attribute__((unused)))
+{
+  pack_s_internal (ret, array, mask, vector,
+                  array_length * sizeof (gfc_char4_t));
+}
index e28ed69..ad82351 100644 (file)
@@ -298,16 +298,33 @@ reshape (parray *ret, parray *source, shape_type *shape, parray *pad,
                    GFC_DESCRIPTOR_SIZE (source));
 }
 
-extern void reshape_char (parray *, GFC_INTEGER_4, parray *, shape_type *,
-                         parray *, shape_type *, GFC_INTEGER_4,
-                         GFC_INTEGER_4);
+
+extern void reshape_char (parray *, gfc_charlen_type, parray *, shape_type *,
+                         parray *, shape_type *, gfc_charlen_type,
+                         gfc_charlen_type);
 export_proto(reshape_char);
 
 void
-reshape_char (parray *ret, GFC_INTEGER_4 ret_length __attribute__((unused)),
+reshape_char (parray *ret, gfc_charlen_type ret_length __attribute__((unused)),
              parray *source, shape_type *shape, parray *pad,
-             shape_type *order, GFC_INTEGER_4 source_length,
-             GFC_INTEGER_4 pad_length __attribute__((unused)))
+             shape_type *order, gfc_charlen_type source_length,
+             gfc_charlen_type pad_length __attribute__((unused)))
 {
   reshape_internal (ret, source, shape, pad, order, source_length);
 }
+
+
+extern void reshape_char4 (parray *, gfc_charlen_type, parray *, shape_type *,
+                          parray *, shape_type *, gfc_charlen_type,
+                          gfc_charlen_type);
+export_proto(reshape_char4);
+
+void
+reshape_char4 (parray *ret, gfc_charlen_type ret_length __attribute__((unused)),
+              parray *source, shape_type *shape, parray *pad,
+              shape_type *order, gfc_charlen_type source_length,
+              gfc_charlen_type pad_length __attribute__((unused)))
+{
+  reshape_internal (ret, source, shape, pad, order,
+                   source_length * sizeof (gfc_char4_t));
+}
index e37b6e1..68ea6b1 100644 (file)
@@ -408,6 +408,7 @@ spread (gfc_array_char *ret, const gfc_array_char *source,
   spread_internal (ret, source, along, pncopies, GFC_DESCRIPTOR_SIZE (source));
 }
 
+
 extern void spread_char (gfc_array_char *, GFC_INTEGER_4,
                         const gfc_array_char *, const index_type *,
                         const index_type *, GFC_INTEGER_4);
@@ -422,6 +423,23 @@ spread_char (gfc_array_char *ret,
   spread_internal (ret, source, along, pncopies, source_length);
 }
 
+
+extern void spread_char4 (gfc_array_char *, GFC_INTEGER_4,
+                         const gfc_array_char *, const index_type *,
+                         const index_type *, GFC_INTEGER_4);
+export_proto(spread_char4);
+
+void
+spread_char4 (gfc_array_char *ret,
+             GFC_INTEGER_4 ret_length __attribute__((unused)),
+             const gfc_array_char *source, const index_type *along,
+             const index_type *pncopies, GFC_INTEGER_4 source_length)
+{
+  spread_internal (ret, source, along, pncopies,
+                  source_length * sizeof (gfc_char4_t));
+}
+
+
 /* The following are the prototypes for the versions of spread with a
    scalar source.  */
 
@@ -584,3 +602,21 @@ spread_char_scalar (gfc_array_char *ret,
   spread_internal_scalar (ret, source, along, pncopies, source_length);
 }
 
+
+extern void spread_char4_scalar (gfc_array_char *, GFC_INTEGER_4,
+                                const char *, const index_type *,
+                                const index_type *, GFC_INTEGER_4);
+export_proto(spread_char4_scalar);
+
+void
+spread_char4_scalar (gfc_array_char *ret,
+                    GFC_INTEGER_4 ret_length __attribute__((unused)),
+                    const char *source, const index_type *along,
+                    const index_type *pncopies, GFC_INTEGER_4 source_length)
+{
+  if (!ret->dtype)
+    runtime_error ("return array missing descriptor in spread()");
+  spread_internal_scalar (ret, source, along, pncopies,
+                         source_length * sizeof (gfc_char4_t));
+}
+
index 97b9713..5b1929c 100644 (file)
@@ -94,6 +94,7 @@ transpose_internal (gfc_array_char *ret, gfc_array_char *source,
     }
 }
 
+
 extern void transpose (gfc_array_char *, gfc_array_char *);
 export_proto(transpose);
 
@@ -103,6 +104,7 @@ transpose (gfc_array_char *ret, gfc_array_char *source)
   transpose_internal (ret, source, GFC_DESCRIPTOR_SIZE (source));
 }
 
+
 extern void transpose_char (gfc_array_char *, GFC_INTEGER_4,
                            gfc_array_char *, GFC_INTEGER_4);
 export_proto(transpose_char);
@@ -114,3 +116,16 @@ transpose_char (gfc_array_char *ret,
 {
   transpose_internal (ret, source, source_length);
 }
+
+
+extern void transpose_char4 (gfc_array_char *, GFC_INTEGER_4,
+                            gfc_array_char *, GFC_INTEGER_4);
+export_proto(transpose_char4);
+
+void
+transpose_char4 (gfc_array_char *ret,
+                GFC_INTEGER_4 ret_length __attribute__((unused)),
+                gfc_array_char *source, GFC_INTEGER_4 source_length)
+{
+  transpose_internal (ret, source, source_length * sizeof (gfc_char4_t));
+}
index 82607bd..86cef67 100644 (file)
@@ -335,6 +335,7 @@ unpack1 (gfc_array_char *ret, const gfc_array_char *vector,
                   GFC_DESCRIPTOR_SIZE (field));
 }
 
+
 extern void unpack1_char (gfc_array_char *, GFC_INTEGER_4,
                          const gfc_array_char *, const gfc_array_l1 *,
                          const gfc_array_char *, GFC_INTEGER_4,
@@ -351,6 +352,26 @@ unpack1_char (gfc_array_char *ret,
   unpack_internal (ret, vector, mask, field, vector_length, field_length);
 }
 
+
+extern void unpack1_char4 (gfc_array_char *, GFC_INTEGER_4,
+                          const gfc_array_char *, const gfc_array_l1 *,
+                          const gfc_array_char *, GFC_INTEGER_4,
+                          GFC_INTEGER_4);
+export_proto(unpack1_char4);
+
+void
+unpack1_char4 (gfc_array_char *ret,
+              GFC_INTEGER_4 ret_length __attribute__((unused)),
+              const gfc_array_char *vector, const gfc_array_l1 *mask,
+              const gfc_array_char *field, GFC_INTEGER_4 vector_length,
+              GFC_INTEGER_4 field_length)
+{
+  unpack_internal (ret, vector, mask, field,
+                  vector_length * sizeof (gfc_char4_t),
+                  field_length * sizeof (gfc_char4_t));
+}
+
+
 extern void unpack0 (gfc_array_char *, const gfc_array_char *,
                     const gfc_array_l1 *, char *);
 export_proto(unpack0);
@@ -500,6 +521,7 @@ unpack0 (gfc_array_char *ret, const gfc_array_char *vector,
   unpack_internal (ret, vector, mask, &tmp, GFC_DESCRIPTOR_SIZE (vector), 0);
 }
 
+
 extern void unpack0_char (gfc_array_char *, GFC_INTEGER_4,
                          const gfc_array_char *, const gfc_array_l1 *,
                          char *, GFC_INTEGER_4, GFC_INTEGER_4);
@@ -519,3 +541,25 @@ unpack0_char (gfc_array_char *ret,
   tmp.data = field;
   unpack_internal (ret, vector, mask, &tmp, vector_length, 0);
 }
+
+
+extern void unpack0_char4 (gfc_array_char *, GFC_INTEGER_4,
+                          const gfc_array_char *, const gfc_array_l1 *,
+                          char *, GFC_INTEGER_4, GFC_INTEGER_4);
+export_proto(unpack0_char4);
+
+void
+unpack0_char4 (gfc_array_char *ret,
+              GFC_INTEGER_4 ret_length __attribute__((unused)),
+              const gfc_array_char *vector, const gfc_array_l1 *mask,
+              char *field, GFC_INTEGER_4 vector_length,
+              GFC_INTEGER_4 field_length __attribute__((unused)))
+{
+  gfc_array_char tmp;
+
+  memset (&tmp, 0, sizeof (tmp));
+  tmp.dtype = 0;
+  tmp.data = field;
+  unpack_internal (ret, vector, mask, &tmp,
+                  vector_length * sizeof (gfc_char4_t), 0);
+}
diff --git a/libgfortran/runtime/convert_char.c b/libgfortran/runtime/convert_char.c
new file mode 100644 (file)
index 0000000..aa500bb
--- /dev/null
@@ -0,0 +1,74 @@
+/* Runtime conversion of strings from one character kind to another.
+   Copyright 2008 Free Software Foundation, Inc.
+
+This file is part of the GNU Fortran runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file.  (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING.  If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+#include "libgfortran.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+
+extern void convert_char1_to_char4 (gfc_char4_t **, gfc_charlen_type,
+                                   const unsigned char *);
+export_proto(convert_char1_to_char4);
+
+extern void convert_char4_to_char1 (unsigned char **, gfc_charlen_type,
+                                   const gfc_char4_t *);
+export_proto(convert_char4_to_char1);
+
+
+void
+convert_char1_to_char4 (gfc_char4_t **dst, gfc_charlen_type len,
+                       const unsigned char *src)
+{
+  gfc_charlen_type i, l;
+
+  l = len > 0 ? len : 0;
+  *dst = get_mem ((l + 1) * sizeof (gfc_char4_t));
+
+  for (i = 0; i < l; i++)
+    (*dst)[i] = src[i];
+
+  (*dst)[l] = '\0';
+}
+
+
+void
+convert_char4_to_char1 (unsigned char **dst, gfc_charlen_type len,
+                       const gfc_char4_t *src)
+{
+  gfc_charlen_type i, l;
+
+  l = len > 0 ? len : 0;
+  *dst = get_mem ((l + 1) * sizeof (unsigned char));
+
+  for (i = 0; i < l; i++)
+    (*dst)[i] = src[i];
+
+  (*dst)[l] = '\0';
+}
index 44c3532..688acfc 100644 (file)
@@ -1,12 +1,12 @@
 /* Implement the SELECT statement for character variables.
-   Contributed by Andy Vaught
+   Copyright 2008 Free Software Foundation, Inc.
 
-This file is part of the GNU Fortran 95 runtime library (libgfortran).
+This file is part of the GNU Fortran runtime library (libgfortran).
 
-Libgfortran is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
 
 In addition to the permissions in the GNU General Public License, the
 Free Software Foundation gives you unlimited permission to link the
@@ -22,116 +22,31 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with libgfortran; see the file COPYING.  If not, write to
-the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING.  If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 Boston, MA 02110-1301, USA.  */
 
-#include "libgfortran.h"
-
-typedef struct
-{
-  char *low;
-  int low_len;
-  char *high;
-  int high_len;
-  int address;
-}
-select_struct;
-
-extern int select_string (select_struct *table, int table_len,
-                         const char *selector, int selector_len);
-export_proto(select_string);
-
-
-/* select_string()-- Given a selector string and a table of
- * select_struct structures, return the address to jump to. */
-
-int
-select_string (select_struct *table, int table_len, const char *selector,
-              int selector_len)
-{
-  select_struct *t;
-  int i, low, high, mid;
-  int default_jump = -1;
-
-  if (table_len == 0)
-    return -1;
-
-  /* Record the default address if present */
-
-  if (table->low == NULL && table->high == NULL)
-    {
-      default_jump = table->address;
 
-      table++;
-      table_len--;
-      if (table_len == 0)
-        return default_jump;
-    }
-
-  /* Try the high and low bounds if present. */
-
-  if (table->low == NULL)
-    {
-      if (compare_string (table->high_len, table->high,
-                               selector_len, selector) >= 0)
-        return table->address;
-
-      table++;
-      table_len--;
-      if (table_len == 0)
-        return default_jump;
-    }
-
-  t = table + table_len - 1;
-
-  if (t->high == NULL)
-    {
-      if (compare_string (t->low_len, t->low,
-                               selector_len, selector) <= 0)
-        return t->address;
-
-      table_len--;
-      if (table_len == 0)
-        return default_jump;
-    }
-
-  /* At this point, the only table entries are bounded entries.  Find
-     the right entry with a binary chop. */
-
-  low = -1;
-  high = table_len;
+#include "libgfortran.h"
 
-  while (low + 1 < high)
-    {
-      mid = (low + high) / 2;
 
-      t = table + mid;
-      i = compare_string (t->low_len, t->low, selector_len, selector);
+/* The string selection function is defined using a few generic macros
+   in select_inc.c, so we avoid code duplication between the various
+   character type kinds.  */
 
-      if (i == 0)
-        return t->address;
+#undef  CHARTYPE
+#define CHARTYPE char
+#undef  SUFFIX
+#define SUFFIX(x) x
 
-      if (i < 0)
-        low = mid;
-      else
-        high = mid;
-    }
+#include "select_inc.c"
 
-  /* The string now lies between the low indeces of the now-adjacent
-     high and low entries.  Because it is less than the low entry of
-     'high', it can't be that one.  If low is still -1, then no
-     entries match.  Otherwise, we have to check the high entry of
-     'low'. */
 
-  if (low == -1)
-    return default_jump;
+#undef  CHARTYPE
+#define CHARTYPE gfc_char4_t
+#undef  SUFFIX
+#define SUFFIX(x) x ## _char4
 
-  t = table + low;
-  if (compare_string (selector_len, selector,
-                           t->high_len, t->high) <= 0)
-    return t->address;
+#include "select_inc.c"
 
-  return default_jump;
-}
diff --git a/libgfortran/runtime/select_inc.c b/libgfortran/runtime/select_inc.c
new file mode 100644 (file)
index 0000000..81a8dab
--- /dev/null
@@ -0,0 +1,139 @@
+/* Implement the SELECT statement for character variables.
+   Copyright 2008 Free Software Foundation, Inc.
+
+This file is part of the GNU Fortran runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file.  (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with libgfortran; see the file COPYING.  If not, write to
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+
+#define select_string SUFFIX(select_string)
+#define select_struct SUFFIX(select_struct)
+#define compare_string SUFFIX(compare_string)
+
+typedef struct
+{
+  CHARTYPE *low;
+  gfc_charlen_type low_len;
+  CHARTYPE *high;
+  gfc_charlen_type high_len;
+  int address;
+}
+select_struct;
+
+extern int select_string (select_struct *table, int table_len,
+                         const CHARTYPE *selector,
+                         gfc_charlen_type selector_len);
+export_proto(select_string);
+
+
+/* select_string()-- Given a selector string and a table of
+ * select_struct structures, return the address to jump to. */
+
+int
+select_string (select_struct *table, int table_len, const CHARTYPE *selector,
+              gfc_charlen_type selector_len)
+{
+  select_struct *t;
+  int i, low, high, mid;
+  int default_jump = -1;
+
+  if (table_len == 0)
+    return -1;
+
+  /* Record the default address if present */
+
+  if (table->low == NULL && table->high == NULL)
+    {
+      default_jump = table->address;
+
+      table++;
+      table_len--;
+      if (table_len == 0)
+        return default_jump;
+    }
+
+  /* Try the high and low bounds if present. */
+
+  if (table->low == NULL)
+    {
+      if (compare_string (table->high_len, table->high,
+                         selector_len, selector) >= 0)
+        return table->address;
+
+      table++;
+      table_len--;
+      if (table_len == 0)
+        return default_jump;
+    }
+
+  t = table + table_len - 1;
+
+  if (t->high == NULL)
+    {
+      if (compare_string (t->low_len, t->low, selector_len, selector) <= 0)
+        return t->address;
+
+      table_len--;
+      if (table_len == 0)
+        return default_jump;
+    }
+
+  /* At this point, the only table entries are bounded entries.  Find
+     the right entry with a binary chop. */
+
+  low = -1;
+  high = table_len;
+
+  while (low + 1 < high)
+    {
+      mid = (low + high) / 2;
+
+      t = table + mid;
+      i = compare_string (t->low_len, t->low, selector_len, selector);
+
+      if (i == 0)
+        return t->address;
+
+      if (i < 0)
+        low = mid;
+      else
+        high = mid;
+    }
+
+  /* The string now lies between the low indeces of the now-adjacent
+     high and low entries.  Because it is less than the low entry of
+     'high', it can't be that one.  If low is still -1, then no
+     entries match.  Otherwise, we have to check the high entry of
+     'low'. */
+
+  if (low == -1)
+    return default_jump;
+
+  t = table + low;
+  if (compare_string (selector_len, selector, t->high_len, t->high) <= 0)
+    return t->address;
+
+  return default_jump;
+}