This is the mail archive of the binutils@sources.redhat.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]

GNAT and Java demangler patches installed


I fixed issues with the ChangeLog entry and committed this to src and gcc.

I also doublechecked by searching the GCC mailing list and found
sufficient indications that there were no copyright issues with this
contribution.  Just in case.

brgds, H-P

---------- Forwarded message ----------
Date: 14 Nov 2000 11:43:20 -0500
From: Daniel Berlin <dberlin@redhat.com>
To: Hans-Peter Nilsson <hp@bitrange.com>
Subject: Please apply this

My write access is screwed up for the gcc repository right now.
Can you apply this to libiberty, please?

The guy has been waiting for over a month to get this patch in, it was
already approved.

Thanks,
Dan

2000-10-11  Kenneth Block <kenneth.block@compaq.com>

        * demangle.h : Add gnat and java demangle styles.
	* cplus_dem.c : Add gnat demangler. Add java to demangle style list.


*** libiberty/cplus-dem.c.orig	Wed Oct 11 18:05:18 2000
--- libiberty/cplus-dem.c	Wed Oct 11 18:05:56 2000
*************** char * realloc ();
*** 52,57 ****
--- 52,59 ----
  
  #include "libiberty.h"
  
+ static char *ada_demangle  PARAMS ((const char*, int));
+ 
  #define min(X,Y) (((X) < (Y)) ? (X) : (Y))
  
  /* A value at least one greater than the maximum number of characters
*************** struct demangler_engine libiberty_demang
*** 298,303 ****
--- 300,317 ----
    }
    ,
    {
+     JAVA_DEMANGLING_STYLE_STRING,
+     java_demangling,
+     "Java style demangling"
+   }
+   ,
+   {
+     GNAT_DEMANGLING_STYLE_STRING,
+     gnat_demangling,
+     "GNAT style demangling"
+   }
+   ,
+   {
      NULL, unknown_demangling, NULL
    }
  };
*************** cplus_demangle (mangled, options)
*** 900,910 ****
--- 914,1058 ----
    if (GNU_NEW_ABI_DEMANGLING)
      return cplus_demangle_new_abi (mangled);
  
+   if (GNAT_DEMANGLING)
+     return ada_demangle(mangled,options);
+ 
    ret = internal_cplus_demangle (work, mangled);
    squangle_mop_up (work);
    return (ret);
  }
  
+ 
+ /* Assuming *OLD_VECT points to an array of *SIZE objects of size
+    ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
+    updating *OLD_VECT and *SIZE as necessary. */
+ static void
+ DEFUN (grow_vect, (old_vect, size, min_size, element_size),
+        void** old_vect
+        AND size_t* size
+        AND size_t min_size
+        AND int element_size)
+ {
+   if (*size < min_size) {
+     *size *= 2;
+     if (*size < min_size)
+       *size = min_size;
+     *old_vect = xrealloc (*old_vect, *size * element_size);
+   }
+ }
+ 
+ /* Demangle ada names:
+    1. Discard final __{DIGIT}+ or ${DIGIT}+
+    2. Convert other instances of embedded "__" to `.'.
+    3. Discard leading _ada_.
+    4. Remove everything after first ___ if it is followed by
+    'X'.
+    5. Put symbols that should be suppressed in <...> brackets.
+    The resulting string is valid until the next call of ada_demangle.
+ */
+ static char *
+ DEFUN (ada_demangle, (mangled, style, option),
+        const char* mangled
+        AND int option ATTRIBUTE_UNUSED)
+ {
+   int i, j;
+   int len0;
+   const char* p;
+   char* demangled = NULL;
+   int at_start_name;
+   int changed;
+   char* demangling_buffer = NULL;
+   size_t demangling_buffer_size = 0;
+   
+   changed = 0;
+ 
+   if (strncmp (mangled, "_ada_", 5) == 0)
+     {
+       mangled += 5;
+       changed = 1;
+     }
+   
+   if (mangled[0] == '_' || mangled[0] == '<')
+     goto Suppress;
+   
+   p = strstr (mangled, "___");
+   if (p == NULL)
+     len0 = strlen (mangled);
+   else
+     {
+       if (p[3] == 'X')
+ 	{
+ 	  len0 = p - mangled;
+ 	  changed = 1;
+ 	}
+       else
+ 	goto Suppress;
+     }
+   
+   /* Make demangled big enough for possible expansion by operator name. */
+   grow_vect ((void**) &(demangling_buffer),
+ 	     &demangling_buffer_size,  2 * len0 + 1,
+ 	     sizeof (char));
+   demangled = demangling_buffer;
+   
+   if (isdigit (mangled[len0 - 1])) {
+     for (i = len0-2; i >= 0 && isdigit (mangled[i]); i -= 1)
+       ;
+     if (i > 1 && mangled[i] == '_' && mangled[i-1] == '_')
+       {
+ 	len0 = i - 1;
+ 	changed = 1;
+       }
+     else if (mangled[i] == '$')
+       {
+ 	len0 = i;
+ 	changed = 1;
+       }
+   }
+   
+   for (i = 0, j = 0; i < len0 && ! isalpha (mangled[i]); i += 1, j += 1)
+     demangled[j] = mangled[i];
+   
+   at_start_name = 1;
+   while (i < len0)
+     {
+       at_start_name = 0;
+       
+       if (i < len0-2 && mangled[i] == '_' && mangled[i+1] == '_')
+ 	{
+ 	  demangled[j] = '.';
+ 	  changed = at_start_name = 1;
+ 	  i += 2; j += 1;
+ 	}
+       else
+ 	{
+ 	  demangled[j] = mangled[i];
+ 	  i += 1;  j += 1;
+ 	}
+     }
+   demangled[j] = '\000';
+   
+   for (i = 0; demangled[i] != '\0'; i += 1)
+     if (isupper (demangled[i]) || demangled[i] == ' ')
+       goto Suppress;
+ 
+   if (! changed)
+     return NULL;
+   else
+     return demangled;
+   
+  Suppress:
+   grow_vect ((void**) &(demangling_buffer),
+ 	     &demangling_buffer_size,  strlen (mangled) + 3,
+ 	     sizeof (char));
+   demangled = demangling_buffer;
+   if (mangled[0] == '<')
+      strcpy (demangled, mangled);
+   else
+     sprintf (demangled, "<%s>", mangled);
+ 
+   return demangled;
+ }
  
  /* This function performs most of what cplus_demangle use to do, but
     to be able to demangle a name with a B, K or n code, we need to
*** include/demangle.h.orig	Wed Oct 11 17:10:07 2000
--- include/demangle.h	Wed Oct 11 17:09:16 2000
***************
*** 38,46 ****
                                              template arguments, etc. */
  #define DMGL_EDG	 (1 << 13)
  #define DMGL_GNU_NEW_ABI (1 << 14)
  
  /* If none of these are set, use 'current_demangling_style' as the default. */
! #define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_NEW_ABI)
  
  /* Enumeration of possible demangling styles.
  
--- 38,47 ----
                                              template arguments, etc. */
  #define DMGL_EDG	 (1 << 13)
  #define DMGL_GNU_NEW_ABI (1 << 14)
+ #define DMGL_GNAT	 (1 << 15)
  
  /* If none of these are set, use 'current_demangling_style' as the default. */
! #define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_NEW_ABI|DMGL_JAVA|DMGL_GNAT)
  
  /* Enumeration of possible demangling styles.
  
*************** extern enum demangling_styles
*** 59,65 ****
    arm_demangling = DMGL_ARM,
    hp_demangling = DMGL_HP,
    edg_demangling = DMGL_EDG,
!   gnu_new_abi_demangling = DMGL_GNU_NEW_ABI
  } current_demangling_style;
  
  /* Define string names for the various demangling styles. */
--- 60,68 ----
    arm_demangling = DMGL_ARM,
    hp_demangling = DMGL_HP,
    edg_demangling = DMGL_EDG,
!   gnu_new_abi_demangling = DMGL_GNU_NEW_ABI,
!   java_demangling = DMGL_JAVA,
!   gnat_demangling = DMGL_GNAT
  } current_demangling_style;
  
  /* Define string names for the various demangling styles. */
*************** extern enum demangling_styles
*** 71,76 ****
--- 74,81 ----
  #define HP_DEMANGLING_STYLE_STRING	      "hp"
  #define EDG_DEMANGLING_STYLE_STRING	      "edg"
  #define GNU_NEW_ABI_DEMANGLING_STYLE_STRING   "gnu-new-abi"
+ #define JAVA_DEMANGLING_STYLE_STRING          "java"
+ #define GNAT_DEMANGLING_STYLE_STRING          "gnat"
  
  /* Some macros to test what demangling style is active. */
  
*************** extern enum demangling_styles
*** 82,87 ****
--- 87,94 ----
  #define HP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_HP)
  #define EDG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG)
  #define GNU_NEW_ABI_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_NEW_ABI)
+ #define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
+ #define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
  
  /* Provide information about the available demangle styles. This code is
     pulled from gdb into libiberty because it is useful to binutils also.  */


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