This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


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

Updated again: Make demangler table driven


Resubmitted yet again, I missed adding the spaces in two spots. Also add
space after function, before "==".

============

Resubmitted previous patch with spaces between function names and after
commas in parameter lists.

============

This patch makes the demangler be table driver so it is easier to add
new demangler styles. Basically the code is lifted from gdb which is
already table driven. Once this is checked in, gdb can remove its
version and simply depend on libiberty to handle picking the style and
not have to worry about when new styles are added. This is done in
preperation to adding support for demangling Ada, Java, and Compaq C++
and the ability to control the style of demangling in all binutil tools
that do demangling: ld, nm, objdump, gprof, etc.



Fri Apr 14 16:51:59 EDT 2000  Kenneth Block  <block@zk3.dec.com>
        * libiberty/cplus-dem.c
        (libiberty_demanglers): new table for demangle styles
        (cplus_demangle_set_style): New function for setting style
        (cplus_demangle_name_to_style): New function to translate name
        * include/demangle.h
        (libiberty_demanglers): new table for different styles
        (cplus_demangle_set_style): New function for setting style
        (cplus_demangle_name_to_style): New function to translate name


*** include/demangle.h.orig	Fri Apr 14 15:09:50 2000
--- include/demangle.h	Fri Apr 14 15:45:43 2000
***************
*** 78,83 ****
--- 78,94 ----
  #define HP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_HP)
  #define EDG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG)
  
+ /*
+  * Provide information about the available demangle styles. This code is
+  * pulled from gdb into libiberty because it is useful to binutils also.
+  */
+ extern struct demangler_engine
+ {
+   char *demangling_style_name;
+   enum demangling_styles demangling_style;
+   char *demangling_style_doc;
+ } libiberty_demanglers[];
+ 
  extern char *
  cplus_demangle PARAMS ((const char *mangled, int options));
  
***************
*** 92,95 ****
--- 103,111 ----
  extern void
  set_cplus_marker_for_demangling PARAMS ((int ch));
  
+ extern enum demangling_styles 
+ cplus_demangle_set_style PARAMS ((enum demangling_styles style));
+ 
+ extern enum demangling_styles 
+ cplus_demangle_name_to_style PARAMS ((const char *name));
  #endif	/* DEMANGLE_H */
*** libiberty/cplus-dem.c.orig	Tue Feb 22 11:14:35 2000
--- libiberty/cplus-dem.c	Mon Apr 17 12:08:19 2000
***************
*** 252,257 ****
--- 252,300 ----
    tk_real
  } type_kind_t;
  
+ struct demangler_engine libiberty_demanglers[] =
+ {
+   {
+     AUTO_DEMANGLING_STYLE_STRING,
+       auto_demangling,
+       "Automatic selection based on executable"
+   }
+   ,
+   {
+     GNU_DEMANGLING_STYLE_STRING,
+       gnu_demangling,
+       "GNU (g++) style demangling"
+   }
+   ,
+   {
+     LUCID_DEMANGLING_STYLE_STRING,
+       lucid_demangling,
+       "Lucid (lcc) style demangling"
+   }
+   ,
+   {
+     ARM_DEMANGLING_STYLE_STRING,
+       arm_demangling,
+       "ARM style demangling"
+   }
+   ,
+   {
+     HP_DEMANGLING_STYLE_STRING,
+       hp_demangling,
+       "HP (aCC) style demangling"
+   }
+   ,
+   {
+     EDG_DEMANGLING_STYLE_STRING,
+       edg_demangling,
+       "EDG style demangling"
+   }
+   ,
+   {
+     NULL, unknown_demangling, NULL
+   }
+ };
+ 
  #define STRING_EMPTY(str)	((str) -> b == (str) -> p)
  #define PREPEND_BLANK(str)	{if (!STRING_EMPTY(str)) \
      string_prepend(str, " ");}
***************
*** 758,763 ****
--- 801,842 ----
    return (0);
  }
  
+ /* Add a routine to set the demangling style to be sure it is valid and
+    allow for any demangler initialization that maybe necessary. */
+ enum demangling_styles cplus_demangle_set_style (style)
+      enum demangling_styles style;
+ {
+   struct demangler_engine *demangler = libiberty_demanglers; 
+ 
+   while (demangler->demangling_style != unknown_demangling) {
+     if (style == demangler->demangling_style) {
+       current_demangling_style = style;
+       return current_demangling_style;
+     }
+     demangler++;
+   }
+ 
+   return unknown_demangling;
+ }
+ 
+ /* Do string name to style translation */
+ 
+ enum demangling_styles cplus_demangle_name_to_style (name)
+      const char *name;
+ {
+   struct demangler_engine *demangler = libiberty_demanglers; 
+ 
+   while (demangler->demangling_style != unknown_demangling) {
+     if (strcmp (name, demangler->demangling_style_name) == 0)
+       return demangler->demangling_style;
+     
+     demangler++;
+   }
+ 
+   return unknown_demangling;
+ }
+ 
+ 
  /* char *cplus_demangle (const char *mangled, int options)
  
     If MANGLED is a mangled function name produced by GNU C++, then
***************
*** 4421,4426 ****
--- 4500,4524 ----
      }
  }
  
+ static void 
+ print_demangler_list (stream)
+      FILE *stream;
+ {
+   struct demangler_engine *demangler; 
+ 
+   fprintf (stream, "{%s", libiberty_demanglers->demangling_style_name);
+   
+   demangler = libiberty_demanglers+1;
+   while (demangler->demangling_style != unknown_demangling) {
+    fprintf (stream, ",%s", demangler->demangling_style_name);
+    demangler++;
+   }
+ 
+   fprintf (stream, "}");
+ }
+   
+   
+ 
  static void
  usage (stream, status)
       FILE *stream;
***************
*** 4427,4436 ****
       int status;
  {
    fprintf (stream, "\
! Usage: %s [-_] [-n] [-s {gnu,lucid,arm,hp,edg}] [--strip-underscores]\n\
!        [--no-strip-underscores] [--format={gnu,lucid,arm,hp,edg}]\n\
!       [--help] [--version] [arg...]\n",
  	   program_name);
    exit (status);
  }
  
--- 4525,4545 ----
       int status;
  {
    fprintf (stream, "\
! Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores] \n",
  	   program_name);
+ 
+   fprintf (stream, "\
+        [-s ");
+   print_demangler_list (stream);
+   fprintf (stream, "]\n");
+ 
+   fprintf (stream, "\
+        [--format ");
+   print_demangler_list (stream);
+   fprintf (stream, "]\n");
+ 
+   fprintf (stream, "\
+        [--help] [--version] [arg...]\n");
    exit (status);
  }
  
***************
*** 4553,4584 ****
  	  flags |= DMGL_JAVA;
  	  break;
  	case 's':
! 	  if (strcmp (optarg, "gnu") == 0)
  	    {
- 	      current_demangling_style = gnu_demangling;
- 	    }
- 	  else if (strcmp (optarg, "lucid") == 0)
- 	    {
- 	      current_demangling_style = lucid_demangling;
- 	    }
- 	  else if (strcmp (optarg, "arm") == 0)
- 	    {
- 	      current_demangling_style = arm_demangling;
- 	    }
- 	  else if (strcmp (optarg, "hp") == 0)
- 	    {
- 	      current_demangling_style = hp_demangling;
- 	    }
-           else if (strcmp (optarg, "edg") == 0)
-             {
-               current_demangling_style = edg_demangling;
-             }
- 	  else
- 	    {
  	      fprintf (stderr, "%s: unknown demangling style `%s'\n",
  		       program_name, optarg);
  	      return (1);
  	    }
  	  break;
  	}
      }
--- 4662,4680 ----
  	  flags |= DMGL_JAVA;
  	  break;
  	case 's':
! 	  {
! 	    enum demangling_styles style;
! 
! 	    style = cplus_demangle_name_to_style (optarg);
! 	    if (style == unknown_demangling)
  	    {
  	      fprintf (stderr, "%s: unknown demangling style `%s'\n",
  		       program_name, optarg);
  	      return (1);
  	    }
+ 	    else
+ 	      cplus_demangle_set_style (style);
+ 	  }
  	  break;
  	}
      }
begin:vcard 
n:Block;Kenneth
x-mozilla-html:FALSE
org:CTG C/C++ Compiler
version:2.1
email;internet:block@zk3.dec.com
adr;quoted-printable:;;110 Spit Brook Road=0D=0AM/S ZKO3-2/W02;Nashua;NH;03062;USA
x-mozilla-cpt:;0
tel;work:603-884-2819
fn:Kenneth Block
end:vcard

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