[COMMITTED] a68: rename invalid_char to replacement_char and add eof_char

Jose E. Marchesi jemarch@gnu.org
Fri Oct 31 22:22:59 GMT 2025


This commit renames invalid_char to the more appropriate
replacement_char, since this standard constant containts the Unicode
U+FFFD.

Also, a new standard constant eof_char gets introduced, whose value is
-1 and is returned by some of the POSIX prelude functions to denote
end of file.
---
 gcc/algol68/a68-low-prelude.cc                | 21 ++++++++++----
 gcc/algol68/a68-parser-prelude.cc             |  3 +-
 gcc/algol68/a68.h                             |  3 +-
 gcc/algol68/ga68.texi                         | 28 ++++++++++++-------
 .../algol68/compile/char-break-1.a68          |  2 +-
 .../execute/environment-enquiries-8.a68       |  2 +-
 libga68/ga68-posix.c                          | 16 ++++++-----
 7 files changed, 49 insertions(+), 26 deletions(-)

diff --git a/gcc/algol68/a68-low-prelude.cc b/gcc/algol68/a68-low-prelude.cc
index 944db198a83..727dfd4e8ea 100644
--- a/gcc/algol68/a68-low-prelude.cc
+++ b/gcc/algol68/a68-low-prelude.cc
@@ -1276,14 +1276,25 @@ a68_lower_flip (NODE_T *p ATTRIBUTE_UNUSED,
 }
 
 tree
-a68_lower_invalidchar (NODE_T *p ATTRIBUTE_UNUSED,
+a68_lower_eofchar (NODE_T *p ATTRIBUTE_UNUSED,
+		   LOW_CTX_T ctx ATTRIBUTE_UNUSED)
+{
+  static tree eofchar = NULL_TREE;
+
+  if (eofchar == NULL_TREE)
+    eofchar = build_int_cst (a68_char_type, -1);
+  return eofchar;
+}
+
+tree
+a68_lower_replacementchar (NODE_T *p ATTRIBUTE_UNUSED,
 		       LOW_CTX_T ctx ATTRIBUTE_UNUSED)
 {
-  static tree invalidchar = NULL_TREE;
+  static tree replacementchar = NULL_TREE;
 
-  if (invalidchar == NULL_TREE)
-    invalidchar = build_int_cst (a68_char_type, 0xfffd);
-  return invalidchar;
+  if (replacementchar == NULL_TREE)
+    replacementchar = build_int_cst (a68_char_type, 0xfffd);
+  return replacementchar;
 }
 
 tree
diff --git a/gcc/algol68/a68-parser-prelude.cc b/gcc/algol68/a68-parser-prelude.cc
index 46c61c2ee19..6af51f37b31 100644
--- a/gcc/algol68/a68-parser-prelude.cc
+++ b/gcc/algol68/a68-parser-prelude.cc
@@ -1327,7 +1327,8 @@ gnu_prelude (void)
   a68_idf (A68_EXT, "minreal", M_REAL, a68_lower_minreal);
   a68_idf (A68_EXT, "longminreal", M_LONG_REAL, a68_lower_minreal);
   a68_idf (A68_EXT, "longlongminreal", M_LONG_LONG_REAL, a68_lower_minreal);
-  a68_idf (A68_EXT, "invalidchar", M_CHAR, a68_lower_invalidchar);
+  a68_idf (A68_EXT, "eofchar", M_CHAR, a68_lower_eofchar);
+  a68_idf (A68_EXT, "replacementchar", M_CHAR, a68_lower_replacementchar);
   /* REAL procedures.  */
   m = A68_MCACHE (proc_real_real);
   a68_idf (A68_EXT, "log", m, a68_lower_log);
diff --git a/gcc/algol68/a68.h b/gcc/algol68/a68.h
index b6ab4ab67fa..e0e3cf3132d 100644
--- a/gcc/algol68/a68.h
+++ b/gcc/algol68/a68.h
@@ -959,7 +959,8 @@ tree a68_lower_flip (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_flop (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_errorchar (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_blank (NODE_T *p, LOW_CTX_T ctx);
-tree a68_lower_invalidchar (NODE_T *p, LOW_CTX_T ctx);
+tree a68_lower_eofchar (NODE_T *p, LOW_CTX_T ctx);
+tree a68_lower_replacementchar (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_intlengths (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_intshorths (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_bitslengths (NODE_T *p, LOW_CTX_T ctx);
diff --git a/gcc/algol68/ga68.texi b/gcc/algol68/ga68.texi
index d000e791e6d..59d8251f959 100644
--- a/gcc/algol68/ga68.texi
+++ b/gcc/algol68/ga68.texi
@@ -1668,8 +1668,8 @@ denotation, subject to the following restrictions:
 @item
 List of characters string breaks @code{'(...)} that contain more than
 one character code are not allowed in character denotations.  If the
-specified code point is not a valid Unicode character then the value
-of the denotation is @code{invalid char}.
+specified code point is not a valid Unicode character then a
+compilation error shall be raised.
 @end itemize
 
 @node Standard prelude
@@ -2636,8 +2636,14 @@ Positive infinity expressed in a real value.
 Negative infinity expressed in a real value.
 @end deftypevr
 
-@deftypevr Constant @B{char} {invalid char}
-A character that is unknown or unrepresentable in Unicode.
+@deftypevr Constant @B{char} {replacement char}
+A character that is unknown, unrecognizable or unrepresentable in
+Unicode.
+@end deftypevr
+
+@deftypevr Constant @B{char} {eof char}
+@B{char} value that doesn't denote an actual char, but an end-of-file
+situation.
 @end deftypevr
 
 @node Extended rows operators
@@ -2915,7 +2921,7 @@ involved.
 @deftypefn Procedure {} {putchar} {= (@B{char} c) @B{char}}
 Write the given character to the standard output.  This procedure
 yields @code{c} in case the character got successfully written, or
-@code{invalid char} otherwise.
+@code{eof char} otherwise.
 @end deftypefn
 
 @deftypefn Procedure {} {puts} {= (@B{string} str) @B{void}}
@@ -2924,8 +2930,8 @@ Write the given string to the standard output.
 
 @deftypefn Procedure {} {fputc} {= (@B{int} fd, @B{char} c) @B{int}}
 Write given character @code{c} to the file with descriptor @code{fd}.
-This procedure yields @code{c} on success, or @code{invalid char}
-on error.
+This procedure yields @code{c} on success, or @code{eof char} on
+error.
 @end deftypefn
 
 @deftypefn Procedure {} {fputs} {= (@B{int} fd, @B{string} str) @B{int}}
@@ -2939,7 +2945,7 @@ success, or 0 on error.
 @deftypefn Procedure {} {getchar} {= @B{char}}
 Read a character from the standard input.  This procedure yields the
 read character in case the character got successfully read, or
-@code{invalid char} otherwise.
+@code{eof char} otherwise.
 @end deftypefn
 
 @deftypefn Procedure {} {gets} {= (@B{int} n) @B{ref} @B{string}}
@@ -2953,8 +2959,10 @@ end of line is reached.
 
 @deftypefn Procedure {} {fgetc} {= (@B{int} fd) @B{int}}
 Read a character from the file with descriptor @code{fd}.  This
-procedure yields the read character in case the character got
-successfully read, or @code{invalid char} otherwise.
+procedure yields the read character in case a valid Unicode character
+got successfully read.  If an unrecognizable or unknown character is
+found then this procedure yields @code{replacement char}.  In case of
+end of file this procedure yields @code{eof char}.
 @end deftypefn
 
 @deftypefn Procedure {} {fgets} {= (@B{int} fd, @B{int} n) @B{ref} @B{string}}
diff --git a/gcc/testsuite/algol68/compile/char-break-1.a68 b/gcc/testsuite/algol68/compile/char-break-1.a68
index 8a43364919f..30308b3df4b 100644
--- a/gcc/testsuite/algol68/compile/char-break-1.a68
+++ b/gcc/testsuite/algol68/compile/char-break-1.a68
@@ -7,5 +7,5 @@ begin prio % = 9;
       assert (ABS %"'r" = 13);
       assert (%"'(  u0061)" = "a");
       assert (%"'(U00000061  )" = "a");
-      assert (%"'(u1234)" = invalid_char)
+      assert (%"'(u1234)" = replacement_char)
 end
diff --git a/gcc/testsuite/algol68/execute/environment-enquiries-8.a68 b/gcc/testsuite/algol68/execute/environment-enquiries-8.a68
index d464a49d990..8c2c904793d 100644
--- a/gcc/testsuite/algol68/execute/environment-enquiries-8.a68
+++ b/gcc/testsuite/algol68/execute/environment-enquiries-8.a68
@@ -2,5 +2,5 @@
 BEGIN ASSERT (flip = "T");
       ASSERT (flop = "F");
       ASSERT (error char = "*");
-      ASSERT (ABS invalid char = ABS 16rfffd)
+      ASSERT (ABS replacement char = ABS 16rfffd)
 END
diff --git a/libga68/ga68-posix.c b/libga68/ga68-posix.c
index abab89e4ae3..51c92f1cdfe 100644
--- a/libga68/ga68-posix.c
+++ b/libga68/ga68-posix.c
@@ -34,6 +34,8 @@
 
 #include "ga68.h"
 
+#define EOF_PSEUDO_CHARACTER -1
+
 /* Some Unicode code points used in this file.  */
 
 #define REPLACEMENT_CHARACTER 0xFFFD
@@ -208,11 +210,11 @@ _libga68_posixfputc (int fd, uint32_t c)
 
   int u8len = _libga68_u8_uctomb (u8, c, 6);
   if (u8len < 0)
-    return REPLACEMENT_CHARACTER;
+    return EOF_PSEUDO_CHARACTER;
 
   ssize_t ret = write (fd, &u8, u8len);
   if (ret == -1)
-    return REPLACEMENT_CHARACTER;
+    return EOF_PSEUDO_CHARACTER;
   else
     return c;
 }
@@ -241,7 +243,7 @@ _libga68_posixfgetc (int fd)
   /* Read first UTF-8 character.  This gives us the total length of the
      character.  */
   if (read (fd, &c, 1) != 1)
-    return REPLACEMENT_CHARACTER;
+    return EOF_PSEUDO_CHARACTER;
 
   if (c < 128)
     morechars = 0;
@@ -256,7 +258,7 @@ _libga68_posixfgetc (int fd)
   for (i = 0; i < morechars; ++i)
     {
       if (read (fd, &c, 1) != 1)
-	return REPLACEMENT_CHARACTER;
+	return EOF_PSEUDO_CHARACTER;
       u8c[i + 1] = c;
     }
 
@@ -293,7 +295,7 @@ _libga68_posixfgets (int fd, int nchars, size_t *len)
       do
 	{
 	  uc = _libga68_posixfgetc (fd);
-	  if (uc == REPLACEMENT_CHARACTER)
+	  if (uc == EOF_PSEUDO_CHARACTER)
 	    break;
 	  res[n++] = uc;
 	}
@@ -307,14 +309,14 @@ _libga68_posixfgets (int fd, int nchars, size_t *len)
       do
 	{
 	  uc = _libga68_posixfgetc (fd);
-	  if (uc != REPLACEMENT_CHARACTER)
+	  if (uc != EOF_PSEUDO_CHARACTER)
 	    {
 	      if (n % 80 == 0)
 		res = _libga68_realloc (res, n * 80 * sizeof (uint32_t) + 80 * sizeof (uint32_t));
 	      res[n++] = uc;
 	    }
 	}
-      while (uc != NEWLINE && uc != REPLACEMENT_CHARACTER);
+      while (uc != NEWLINE && uc != EOF_PSEUDO_CHARACTER);
       if (n > 0)
 	res = _libga68_realloc (res, n * 80 * sizeof (uint32_t));
     }
-- 
2.30.2



More information about the Algol68 mailing list