public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-charset: Add type argument to print- and emit-char APIs.
@ 2009-01-10  1:07 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2009-01-10  1:07 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-charset has been updated
       via  22fc6b9152aa37de270ed193ec2110091abcdc43 (commit)
       via  3efdf347920c6259c5b8d61d24a016677bc186be (commit)
      from  dee452204073d6bf0ceffd150dfaf3391be01bd2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 22fc6b9152aa37de270ed193ec2110091abcdc43
Author: Tom Tromey <tromey@redhat.com>
Date:   Fri Jan 9 18:06:57 2009 -0700

    Add type argument to print- and emit-char APIs.
    Implement printing of wide characters for C.
    Fix some UCN bugs.

commit 3efdf347920c6259c5b8d61d24a016677bc186be
Author: Tom Tromey <tromey@redhat.com>
Date:   Fri Jan 9 16:58:32 2009 -0700

    another macro tokenization bug fix

-----------------------------------------------------------------------

Summary of changes:
 gdb/ada-lang.c     |    4 +-
 gdb/ada-lang.h     |    4 +-
 gdb/ada-valprint.c |   21 ++--
 gdb/c-exp.y        |    2 +-
 gdb/c-lang.c       |  304 +++++++++++++++++++++++++++++-----------------------
 gdb/c-lang.h       |    2 +-
 gdb/c-valprint.c   |    6 +-
 gdb/f-lang.c       |   15 ++--
 gdb/f-valprint.c   |    2 +-
 gdb/jv-lang.c      |    5 +-
 gdb/jv-valprint.c  |    2 +-
 gdb/language.c     |   11 ++-
 gdb/language.h     |   13 ++-
 gdb/m2-lang.c      |   14 ++--
 gdb/m2-valprint.c  |    2 +-
 gdb/macroexp.c     |    2 +-
 gdb/objc-lang.c    |   10 +-
 gdb/p-lang.c       |    9 +-
 gdb/p-lang.h       |    2 +-
 gdb/p-valprint.c   |    2 +-
 gdb/printcmd.c     |    2 +-
 gdb/scm-lang.c     |    2 +-
 gdb/scm-lang.h     |    2 +-
 gdb/scm-valprint.c |    3 +-
 gdb/typeprint.c    |    2 +-
 gdb/valprint.c     |    7 +-
 gdb/valprint.h     |    4 +-
 27 files changed, 250 insertions(+), 204 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 71d99b0..1bd02a8 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11003,9 +11003,9 @@ ada_language_arch_info (struct gdbarch *gdbarch,
 /* Not really used, but needed in the ada_language_defn.  */
 
 static void
-emit_char (int c, struct ui_file *stream, int quoter)
+emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
 {
-  ada_emit_char (c, stream, quoter, 1);
+  ada_emit_char (c, type, stream, quoter, 1);
 }
 
 static int
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index b3e6454..fac027b 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -257,9 +257,9 @@ extern int ada_value_print (struct value *, struct ui_file *,
 
                                 /* Defined in ada-lang.c */
 
-extern void ada_emit_char (int, struct ui_file *, int, int);
+extern void ada_emit_char (int, struct type *, struct ui_file *, int, int);
 
-extern void ada_printchar (int, struct ui_file *);
+extern void ada_printchar (int, struct type *, struct ui_file *);
 
 extern void ada_printstr (struct ui_file *, struct type *, const gdb_byte *,
 			  unsigned int, int,
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 6aeaba5..3da58ea 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -269,7 +269,8 @@ printable_val_type (struct type *type, const gdb_byte *valaddr)
    (1 or 2) of the character.  */
 
 void
-ada_emit_char (int c, struct ui_file *stream, int quoter, int type_len)
+ada_emit_char (int c, struct type *type, struct ui_file *stream,
+	       int quoter, int type_len)
 {
   if (type_len != 2)
     type_len = 1;
@@ -366,10 +367,10 @@ ada_print_floating (const gdb_byte *valaddr, struct type *type,
 }
 
 void
-ada_printchar (int c, struct ui_file *stream)
+ada_printchar (int c, struct type *type, struct ui_file *stream)
 {
   fputs_filtered ("'", stream);
-  ada_emit_char (c, stream, '\'', 1);
+  ada_emit_char (c, type, stream, '\'', 1);
   fputs_filtered ("'", stream);
 }
 
@@ -411,7 +412,7 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
       break;
 
     case TYPE_CODE_CHAR:
-      LA_PRINT_CHAR ((unsigned char) val, stream);
+      LA_PRINT_CHAR ((unsigned char) val, type, stream);
       break;
 
     case TYPE_CODE_BOOL:
@@ -454,7 +455,7 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
  */
 
 static void
-printstr (struct ui_file *stream, const gdb_byte *string,
+printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
 	  unsigned int length, int force_ellipses, int type_len,
 	  const struct value_print_options *options)
 {
@@ -506,7 +507,7 @@ printstr (struct ui_file *stream, const gdb_byte *string,
 	      in_quotes = 0;
 	    }
 	  fputs_filtered ("'", stream);
-	  ada_emit_char (char_at (string, i, type_len), stream, '\'',
+	  ada_emit_char (char_at (string, i, type_len), elttype, stream, '\'',
 			 type_len);
 	  fputs_filtered ("'", stream);
 	  fprintf_filtered (stream, _(" <repeats %u times>"), reps);
@@ -524,7 +525,7 @@ printstr (struct ui_file *stream, const gdb_byte *string,
 		fputs_filtered ("\"", stream);
 	      in_quotes = 1;
 	    }
-	  ada_emit_char (char_at (string, i, type_len), stream, '"',
+	  ada_emit_char (char_at (string, i, type_len), elttype, stream, '"',
 			 type_len);
 	  things_printed += 1;
 	}
@@ -548,7 +549,7 @@ ada_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
 	      unsigned int length, int force_ellipses,
 	      const struct value_print_options *options)
 {
-  printstr (stream, string, length, force_ellipses, TYPE_LENGTH (type),
+  printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
 	    options);
 }
 
@@ -638,7 +639,7 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr,
           len = temp_len;
         }
 
-      printstr (stream, valaddr, len, 0, eltlen, options);
+      printstr (stream, elttype, valaddr, len, 0, eltlen, options);
       result = len;
     }
   else
@@ -818,7 +819,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
 		{
 		  fputs_filtered (" ", stream);
 		  ada_printchar ((unsigned char) unpack_long (type, valaddr),
-				 stream);
+				 type, stream);
 		}
 	    }
 	  return 0;
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 085c4dd..dad8416 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1505,7 +1505,7 @@ parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
 		    /* We look at TOKPTR[1] so that the following
 		       "continue" will do the right thing.  */
 		    if (!isxdigit (tokptr[1]))
-		      error ("Invalid UCN.");
+		      break;
 		    obstack_1grow (&tempbuf, tokptr[1]);
 		    ++tokptr;
 		  }
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 86c1b6d..73caf9e 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -39,114 +39,56 @@
 #include <wctype.h>
 
 extern void _initialize_c_language (void);
-static void c_emit_char (int c, struct ui_file * stream, int quoter);
 
-/* Print the character C on STREAM as part of the contents of a literal
-   string whose delimiter is QUOTER.  Note that that format for printing
-   characters and strings is language specific. */
-
-static void
-c_emit_char (int c, struct ui_file *stream, int quoter)
+static enum c_string_type
+classify_type (struct type *elttype, const char **encoding)
 {
-  struct obstack host_data;
-  char the_char = c;
-  struct cleanup *cleanups;
-
-  obstack_init (&host_data);
-  cleanups = make_cleanup_obstack_free (&host_data);
-
-  convert_between_encodings (target_charset (), host_charset (),
-			     &the_char, 1, &host_data, translit_char);
-
-  if (obstack_object_size (&host_data) == 1)
+  struct type *saved_type = elttype;
+  /* We do one or two passes -- one on ELTTYPE, and then maybe a
+     second one on a typedef target.  */
+  do
     {
-      char host_char = *(char *) obstack_base (&host_data);
+      char *name = TYPE_NAME (elttype);
 
-      if (host_char == '\\' || host_char == quoter)
-        fputs_filtered ("\\", stream);
-      if (isprint (host_char))
-	fprintf_filtered (stream, "%c", host_char);
-      else
+      if (TYPE_CODE (elttype) == TYPE_CODE_CHAR || !name)
 	{
-	  switch (host_char)
-	    {
-	    case HOST_ESCAPE_CHAR:
-	      fputs_filtered ("\\e", stream);
-	      break;
-	    case '\a':
-	      fputs_filtered ("\\a", stream);
-	      break;
-	    case '\b':
-	      fputs_filtered ("\\b", stream);
-	      break;
-	    case '\f':
-	      fputs_filtered ("\\f", stream);
-	      break;
-	    case '\n':
-	      fputs_filtered ("\\n", stream);
-	      break;
-	    case '\r':
-	      fputs_filtered ("\\r", stream);
-	      break;
-	    case '\t':
-	      fputs_filtered ("\\t", stream);
-	      break;
-	    case '\v':
-	      fputs_filtered ("\\v", stream);
-	      break;
-	    default:
-	      if (quoter == '"')
-		fprintf_filtered (stream, "\\%.3o", host_char);
-	      else
-		fprintf_filtered (stream, "\\%o", host_char);
-	      break;
-	    }
+	  *encoding = target_charset ();
+	  return C_CHAR;
 	}
-    }
-  else
-    {
-      obstack_1grow (&host_data, '\0');
-      fputs_filtered (obstack_base (&host_data), stream);
-    }
-}
-
-void
-c_printchar (int c, struct ui_file *stream)
-{
-  fputc_filtered ('\'', stream);
-  LA_EMIT_CHAR (c, stream, '\'');
-  fputc_filtered ('\'', stream);
-}
 
-static enum c_string_type
-classify_type (struct type *elttype, const char **encoding)
-{
-  if (elttype == language_string_char_type (current_language,
-					    current_gdbarch))
-    {
-      *encoding = target_charset ();
-      return C_CHAR;
-    }
+      if (!strcmp (name, "wchar_t"))
+	{
+	  *encoding = target_wide_charset ();
+	  return C_WIDE_CHAR;
+	}
 
-  if (elttype == lookup_typename ("wchar_t", NULL, 1))
-    {
-      *encoding = target_wide_charset ();
-      return C_WIDE_CHAR;
-    }
+      if (!strcmp (name, "char16_t"))
+	{
+	  /* FIXME: UCS-2 is not always correct.  */
+	  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+	    *encoding = "UCS-2BE";
+	  else
+	    *encoding = "UCS-2LE";
+	  return C_CHAR_16;
+	}
 
-  if (elttype == lookup_typename ("char16_t", NULL, 1))
-    {
-      *encoding = "UCS-2";
-      return C_CHAR_16;
-    }
+      if (!strcmp (name, "char32_t"))
+	{
+	  /* FIXME: UCS-4 is not always correct.  */
+	  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+	    *encoding = "UCS-4BE";
+	  else
+	    *encoding = "UCS-4LE";
+	  return C_CHAR_32;
+	}
 
-  if (elttype == lookup_typename ("char32_t", NULL, 1))
-    {
-      *encoding = "UCS-4";
-      return C_CHAR_32;
+      CHECK_TYPEDEF (elttype);
     }
+  while (elttype != saved_type);
 
-  internal_error (__FILE__, __LINE__, "how???");
+  /* Punt.  */
+  *encoding = target_charset ();
+  return C_CHAR;
 }
 
 static void
@@ -163,7 +105,8 @@ reset_state (struct obstack *output, mbstate_t *state)
 }
 
 static void
-print_wchar (wchar_t w, mbstate_t *state, struct obstack *output)
+print_wchar (wchar_t w, mbstate_t *state, struct obstack *output,
+	     int quoter)
 {
   if (iswprint (w))
     {
@@ -171,21 +114,130 @@ print_wchar (wchar_t w, mbstate_t *state, struct obstack *output)
       wchar_t inbuf[2];
       const wchar_t *s = inbuf;
 
+      if (w == btowc (quoter) || w == L'\\')
+	{
+	  reset_state (output, state);
+	  obstack_1grow (output, '\\');
+	}
       inbuf[0] = w;
       inbuf[1] = 0;
       wcsrtombs (buf, &s, MB_LEN_MAX, state);
       obstack_grow_str (output, buf);
     }
+  else if (w == btowc (HOST_ESCAPE_CHAR))
+    {
+      reset_state (output, state);
+      obstack_grow_str (output, "\\e");
+    }
   else
     {
-      /* FIXME: this is not right.  */
-      char buf[20];
       reset_state (output, state);
-      sprintf (buf, "\\u%04x", (int) w);
-      obstack_grow_str (output, buf);
+      switch (w)
+	{
+	case L'\a':
+	  obstack_grow_str (output, "\\a");
+	  break;
+	case L'\b':
+	  obstack_grow_str (output, "\\b");
+	  break;
+	case L'\f':
+	  obstack_grow_str (output, "\\f");
+	  break;
+	case L'\n':
+	  obstack_grow_str (output, "\\n");
+	  break;
+	case L'\r':
+	  obstack_grow_str (output, "\\r");
+	  break;
+	case L'\t':
+	  obstack_grow_str (output, "\\t");
+	  break;
+	case L'\v':
+	  obstack_grow_str (output, "\\v");
+	  break;
+	default:
+	  {
+	    /* FIXME: this is not right.  */
+	    char buf[20];
+	    sprintf (buf, "\\u%04x", (int) w);
+	    obstack_grow_str (output, buf);
+	  }
+	  break;
+	}
     }
 }
 
+/* Print the character C on STREAM as part of the contents of a literal
+   string whose delimiter is QUOTER.  Note that that format for printing
+   characters and strings is language specific. */
+
+static void
+c_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
+{
+  struct obstack host_wdata, output;
+  struct cleanup *cleanups;
+  const char *encoding;
+  gdb_byte *buf;
+  wchar_t *wchs;
+  int i;
+  mbstate_t state;
+
+  classify_type (type, &encoding);
+
+  buf = alloca (TYPE_LENGTH (type));
+  pack_long (buf, type, c);
+
+  obstack_init (&host_wdata);
+  cleanups = make_cleanup_obstack_free (&host_wdata);
+
+  obstack_init (&output);
+  make_cleanup_obstack_free (&output);
+
+  convert_between_encodings (encoding, "wchar_t",
+			     buf, TYPE_LENGTH (type),
+			     &host_wdata, translit_wchar);
+
+  memset (&state, 0, sizeof (state));
+  wchs = (wchar_t *) obstack_base (&host_wdata);
+  for (i = 0; i < obstack_object_size (&host_wdata); i += sizeof (wchar_t))
+    {
+      print_wchar (*wchs, &state, &output, quoter);
+      ++wchs;
+    }
+
+  obstack_1grow (&output, '\0');
+  fputs_filtered (obstack_base (&output), stream);
+
+  do_cleanups (cleanups);
+}
+
+void
+c_printchar (int c, struct type *type, struct ui_file *stream)
+{
+  enum c_string_type str_type;
+  const char *encoding;
+
+  str_type = classify_type (type, &encoding);
+  switch (str_type)
+    {
+    case C_CHAR:
+      break;
+    case C_WIDE_CHAR:
+      fputc_filtered ('L', stream);
+      break;
+    case C_CHAR_16:
+      fputc_filtered ('u', stream);
+      break;
+    case C_CHAR_32:
+      fputc_filtered ('U', stream);
+      break;
+    }
+
+  fputc_filtered ('\'', stream);
+  LA_EMIT_CHAR (c, type, stream, '\'');
+  fputc_filtered ('\'', stream);
+}
+
 /* Print the character string STRING, printing at most LENGTH characters.
    LENGTH is -1 if the string is nul terminated.  Each character is WIDTH bytes
    long.  Printing stops early if the number hits print_max; repeat counts are
@@ -306,7 +358,7 @@ c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
 		obstack_grow_str (&output, "\", ");
 	      in_quotes = 0;
 	    }
-	  print_wchar (current_char, &state, &output);
+	  print_wchar (current_char, &state, &output, 0);
 	  {
 	    char *s = xstrprintf (_(" <repeats %u times>"), reps);
 	    reset_state (&output, &state);
@@ -330,7 +382,7 @@ c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
 	    }
 	  /* We could be more efficient by noticing runs of printable
 	     characters.  */
-	  print_wchar (current_char, &state, &output);
+	  print_wchar (current_char, &state, &output, '"');
 	  ++things_printed;
 	}
     }
@@ -357,34 +409,16 @@ c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
 \f
 /* Evaluating C and C++ expressions.  */
 
-static void
-convert_ucn (char *p, struct obstack *output, int length)
+static char *
+convert_ucn (char *p, char *limit, const char *dest_charset,
+	     struct obstack *output, int length)
 {
   unsigned long result = 0;
   gdb_byte data[4];
   int i;
 
-  for (i = 0; i < length; ++i)
-    {
-      char c = p[i];
-      if (!isxdigit (c))
-	error ("blah");
-      result = (result << 4) + host_hex_value (c);
-    }
-
-  /* The standard permits $, @ and ` to be specified as UCNs.  We use
-     hex escapes so that this also works with EBCDIC hosts.  (Code
-     snippet from libcpp.) */
-  if ((result < 0xa0
-       && (result != 0x24 && result != 0x40 && result != 0x60))
-      || (result & 0x80000000)
-      || (result >= 0xD800 && result <= 0xDFFF))
-    {
-      char buffer[9];
-      memcpy (buffer, p, i);
-      buffer[i] = '\0';
-      error ("%s is not a valid universal character", buffer);
-    }
+  for (i = 0; i < length && p < limit && isxdigit (*p); ++i, ++p)
+    result = (result << 4) + host_hex_value (*p);
 
   for (i = 3; i >= 0; --i)
     {
@@ -392,8 +426,10 @@ convert_ucn (char *p, struct obstack *output, int length)
       result >>= 8;
     }
 
-  convert_between_encodings ("UCS-2BE", target_charset (), data, 4, output,


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-01-10  1:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-10  1:07 [SCM] archer-tromey-charset: Add type argument to print- and emit-char APIs tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).