Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Richard Earnshaw <rearnsha@arm.com>
To: Klee Dienes <klee@apple.com>
Cc: gdb-patches@sources.redhat.com, Richard.Earnshaw@arm.com
Subject: Re: [RFA] New function type_code_name.
Date: Thu, 12 Dec 2002 09:12:00 -0000	[thread overview]
Message-ID: <200212121105.gBCB52308429@pc960.cambridge.arm.com> (raw)
In-Reply-To: Your message of "Wed, 11 Dec 2002 19:21:55 EST." <B87A936F-0D67-11D7-9BDD-00039396EEB8@apple.com>


klee@apple.com said:
> This patch moves the type-printing code from recursive_dump_type()
> into  the new function type_code_name().  It's handy when one wants to
> use  the type code of a type in debugging or warning/error messages.


>         * gdbtypes.h (type_code_name): Add prototype.
>         * gdbtypes.c (type_code_name): New function.  Returns a
>         constant string containing the ASCII name of the type code.
>         (recursive_dump_type): Use type_code_name.



Hmm, I think this could be much cleaner if we considered moving towards 
GCC's model of having a gdbtype.def file which defined the type the 
strings together.  We could then build up an array of strings that is kept 
in sync with the enum definition.  Something like

gdbtype.def:

DEF_TYPE (TYPE_CODE_INT, "TYPE_CODE_INT", anything else needed by all 
types)

DEF_TYPE (TYPE_CODE_TYPEDEF, "TYPE_CODE_TYPEDEF", ...)

etc

then to use it, do

#define DEF_TYPE(X,Y,Z) X,

enum type_code {
#include "gdbtype.def"
  TYPE_CODE_NUM_TYPES
};

#undef DEF_TYPE

#define DEF_TYPE(X,Y,Z) Y,
const char char *const type_code_names[] = {
#include "gdbtype.def"
};

You can then look up the type name simply with

	if (type_code_number < TYPE_CODE_NUM_TYPES)
	  type_name = type_code_names[type_code_number];
	else
	  type_name = "INVALID TYPE";

and adding a new type (should we need to) is trivial.


R.




  reply	other threads:[~2002-12-12 11:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-11 17:41 Klee Dienes
2002-12-12  9:12 ` Richard Earnshaw [this message]
2002-12-14  2:32 ` Daniel Jacobowitz
2003-01-03 21:11 ` Elena Zannoni
2003-01-03 21:35   ` Andrew Cagney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200212121105.gBCB52308429@pc960.cambridge.arm.com \
    --to=rearnsha@arm.com \
    --cc=Richard.Earnshaw@arm.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=klee@apple.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox