This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: printing java `char' values


Tom Tromey wrote:
> 
> >>>>> "Michael" == Michael Snyder <msnyder@redhat.com> writes:
> 
> Michael> I recommend that you emulate what C does, and whenever you
> Michael> have a TYPE_CODE_INT whose length is the length of a char
> Michael> (which for Java appears to be two bytes), you look at the
> Michael> type_name and see if it is "char" -- in which case you print
> Michael> it as a char.
> 
> How does this look?

Yes, that's the idea.  I wouldn't even bother with the temp variable--
I would just call TYPE_CODE (type) twice.  It's a macro, and not
expensive to evaluate.  Then you don't need the brackets.

> 
> Index: ChangeLog
> from  Tom Tromey  <tromey@redhat.com>
> 
>         * jv-valprint.c (java_val_print): Handle `char' as a special case
>         of TYPE_CODE_INT.
> 
> Index: jv-valprint.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/jv-valprint.c,v
> retrieving revision 1.9
> diff -u -r1.9 jv-valprint.c
> --- jv-valprint.c 21 Oct 2001 01:57:42 -0000 1.9
> +++ jv-valprint.c 8 May 2002 22:41:22 -0000
> @@ -497,20 +499,21 @@
>        return i;
> 
>      case TYPE_CODE_CHAR:
> -      format = format ? format : output_format;
> -      if (format)
> -       print_scalar_formatted (valaddr, type, format, 0, stream);
> -      else
> -       LA_PRINT_CHAR ((int) unpack_long (type, valaddr), stream);
> -      break;
> -
>      case TYPE_CODE_INT:
>        /* Can't just call c_val_print because that print bytes as C chars. */
>        format = format ? format : output_format;
>        if (format)
>         print_scalar_formatted (valaddr, type, format, 0, stream);
>        else
> -       val_print_type_code_int (type, valaddr, stream);
> +       {
> +         enum type_code code = TYPE_CODE (type);
> +         if (code == TYPE_CODE_CHAR
> +             || (code == TYPE_CODE_INT && TYPE_LENGTH (type) == 2
> +                 && ! strcmp (TYPE_NAME (type), "char")))
> +           LA_PRINT_CHAR ((int) unpack_long (type, valaddr), stream);
> +         else
> +           val_print_type_code_int (type, valaddr, stream);
> +       }
>        break;
> 
>      case TYPE_CODE_STRUCT:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]