[RFC/RFA] Cleaner handling of character entities ?

Joel Brobecker brobecker@adacore.com
Mon Dec 24 08:00:00 GMT 2007


This is an old patch that, for some reason, I forgot to commit:

> So, Joel, I think that a patch along the lines of that changelog entry
> above is probably the way to go,

So I took the opportunity to add some comments, and do a minor
reformatting...

2007-12-24  Joel Brobecker  <brobecker@adacore.com>

        * dwarf2read.c (read_base_type): Set code to TYPE_CODE_CHAR
        for char and unsigned char types of Ada compilation units.
        * ada-lang.c (ada_is_character_type): Always return true if
        the type code is TYPE_CODE_CHAR.

Tested on x86-linux with DWARF and stabs. Checked in.

You also said:

> you may want to audit uses of TYPE_CODE_INT and TYPE_CODE_CHAR in
> backends or else calling Ada procedures which take chars may not work
> well.
> [Sounds like a new testcase, doesn't it?]

That's a good idea. I will write one ASAP.

Incidentally, that reminded me of a recent change that Daniel made
regarding handling of (unsigned?) characters. Perhaps one day we
won't have to set TYPE_CODE_CHAR only for Ada and M2...

-- 
Joel
-------------- next part --------------
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.243
diff -u -p -r1.243 dwarf2read.c
--- dwarf2read.c	22 Dec 2007 20:58:30 -0000	1.243
+++ dwarf2read.c	24 Dec 2007 04:35:03 -0000
@@ -5007,11 +5007,11 @@ read_base_type (struct die_info *die, st
 	type_flags |= TYPE_FLAG_UNSIGNED;
 	break;
       case DW_ATE_signed_char:
-	if (cu->language == language_m2)
+	if (cu->language == language_ada && cu->language == language_m2)
 	  code = TYPE_CODE_CHAR;
 	break;
       case DW_ATE_unsigned_char:
-	if (cu->language == language_m2)
+	if (cu->language == language_ada && cu->language == language_m2)
 	  code = TYPE_CODE_CHAR;
 	type_flags |= TYPE_FLAG_UNSIGNED;
 	break;
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.110
diff -u -p -r1.110 ada-lang.c
--- ada-lang.c	21 Dec 2007 11:50:11 -0000	1.110
+++ ada-lang.c	24 Dec 2007 04:35:28 -0000
@@ -7286,15 +7286,22 @@ value_val_atr (struct type *type, struct
 int
 ada_is_character_type (struct type *type)
 {
-  const char *name = ada_type_name (type);
-  return
-    name != NULL
-    && (TYPE_CODE (type) == TYPE_CODE_CHAR
-        || TYPE_CODE (type) == TYPE_CODE_INT
-        || TYPE_CODE (type) == TYPE_CODE_RANGE)
-    && (strcmp (name, "character") == 0
-        || strcmp (name, "wide_character") == 0
-        || strcmp (name, "unsigned char") == 0);
+  const char *name;
+
+  /* If the type code says it's a character, then assume it really is,
+     and don't check any further.  */
+  if (TYPE_CODE (type) == TYPE_CODE_CHAR)
+    return 1;
+  
+  /* Otherwise, assume it's a character type iff it is a discrete type
+     with a known character type name.  */
+  name = ada_type_name (type);
+  return (name != NULL
+          && (TYPE_CODE (type) == TYPE_CODE_INT
+              || TYPE_CODE (type) == TYPE_CODE_RANGE)
+          && (strcmp (name, "character") == 0
+              || strcmp (name, "wide_character") == 0
+              || strcmp (name, "unsigned char") == 0));
 }
 
 /* True if TYPE appears to be an Ada string type.  */


More information about the Gdb-patches mailing list