This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

C++ PATCH: demangling of local names


This patch updates the demangling of local names to correspond to
changes in the mangling code, and fixes a couple of substitution bugs.

	* cp-demangle.c (demangle_name): Initialize template_p in local
	name case.  Don't re-add substitutions as candidates.
	(demangle_nested_name): Use <unqualified-name>.
	(demangle_prefix): Likewise.  Don't add template names as
	substitution candidates twice, or re-add a substitution or the
	last prefix component.
	(demangle_local_name): Adjust output format.



Index: cp-demangle.c
===================================================================
RCS file: /cvs/gcc/egcs/libiberty/cp-demangle.c,v
retrieving revision 1.15
diff -c -p -r1.15 cp-demangle.c
*** cp-demangle.c	2000/08/25 22:52:25	1.15
--- cp-demangle.c	2000/08/28 02:54:30
*************** demangle_name (dm, template_p)
*** 973,982 ****
       int *template_p;
  {
    int start = substitution_start (dm);
  
    DEMANGLE_TRACE ("name", dm);
  
!   switch (peek_char (dm))
      {
      case 'N':
        /* This is a <nested-name>.  */
--- 973,983 ----
       int *template_p;
  {
    int start = substitution_start (dm);
+   char peek = peek_char (dm);
  
    DEMANGLE_TRACE ("name", dm);
  
!   switch (peek)
      {
      case 'N':
        /* This is a <nested-name>.  */
*************** demangle_name (dm, template_p)
*** 985,990 ****
--- 986,992 ----
  
      case 'Z':
        RETURN_IF_ERROR (demangle_local_name (dm));
+       *template_p = 0;
        break;
  
      case 'S':
*************** demangle_name (dm, template_p)
*** 1005,1012 ****
  	 If so, then we just demangled an <unqualified-template-name>.  */
        if (peek_char (dm) == 'I') 
  	{
! 	  RETURN_IF_ERROR (substitution_add (dm, start, 0, 
! 					     NOT_TEMPLATE_PARM));
  	  RETURN_IF_ERROR (demangle_template_args (dm));
  	  *template_p = 1;
  	}
--- 1007,1017 ----
  	 If so, then we just demangled an <unqualified-template-name>.  */
        if (peek_char (dm) == 'I') 
  	{
! 	  /* The template name is a substitution candidate, unless it
!              was already a back-substitution.  */
! 	  if (peek != 'S')
! 	    RETURN_IF_ERROR (substitution_add (dm, start, 0, 
! 					       NOT_TEMPLATE_PARM));
  	  RETURN_IF_ERROR (demangle_template_args (dm));
  	  *template_p = 1;
  	}
*************** demangle_name (dm, template_p)
*** 1041,1047 ****
  
  /* Demangles and emits a <nested-name>. 
  
!     <nested-name>       ::= N [<CV-qualifiers>] <prefix> <component> E  */
  
  static status_t
  demangle_nested_name (dm, template_p)
--- 1046,1052 ----
  
  /* Demangles and emits a <nested-name>. 
  
!     <nested-name>     ::= N [<CV-qualifiers>] <prefix> <unqulified-name> E  */
  
  static status_t
  demangle_nested_name (dm, template_p)
*************** demangle_nested_name (dm, template_p)
*** 1072,1079 ****
      }
    
    RETURN_IF_ERROR (demangle_prefix (dm, template_p));
!   /* No need to demangle the final <component>; demangle_prefix will
!      handle it.  */
    RETURN_IF_ERROR (demangle_char (dm, 'E'));
  
    return STATUS_OK;
--- 1077,1084 ----
      }
    
    RETURN_IF_ERROR (demangle_prefix (dm, template_p));
!   /* No need to demangle the final <unqualified-name>; demangle_prefix
!      will handle it.  */
    RETURN_IF_ERROR (demangle_char (dm, 'E'));
  
    return STATUS_OK;
*************** demangle_nested_name (dm, template_p)
*** 1081,1096 ****
  
  /* Demangles and emits a <prefix>.
  
!     <prefix>            ::= <prefix> <component>
                          ::= <template-prefix> <template-args>
  			::= # empty
  			::= <substitution>
  
      <template-prefix>   ::= <prefix>
!                         ::= <substitution>
! 
!     <component>         ::= <unqualified-name>
!                         ::= <local-name>  */
  
  static status_t
  demangle_prefix (dm, template_p)
--- 1086,1098 ----
  
  /* Demangles and emits a <prefix>.
  
!     <prefix>            ::= <prefix> <unqualified-name>
                          ::= <template-prefix> <template-args>
  			::= # empty
  			::= <substitution>
  
      <template-prefix>   ::= <prefix>
!                         ::= <substitution>  */
  
  static status_t
  demangle_prefix (dm, template_p)
*************** demangle_prefix (dm, template_p)
*** 1145,1152 ****
  	    RETURN_IF_ERROR (demangle_substitution (dm, template_p));
  	  else
  	    {
! 	      /* It's just a name.  Remember whether it's a
! 		 constructor.  */
  	      RETURN_IF_ERROR (demangle_unqualified_name (dm));
  	      *template_p = 0;
  	    }
--- 1147,1153 ----
  	    RETURN_IF_ERROR (demangle_substitution (dm, template_p));
  	  else
  	    {
! 	      /* It's just a name.  */
  	      RETURN_IF_ERROR (demangle_unqualified_name (dm));
  	      *template_p = 0;
  	    }
*************** demangle_prefix (dm, template_p)
*** 1160,1167 ****
  	RETURN_IF_ERROR (demangle_local_name (dm));
        else if (peek == 'I')
  	{
- 	  /* The template name is a substitution candidate.  */
- 	  RETURN_IF_ERROR (substitution_add (dm, start, 0, NOT_TEMPLATE_PARM));
  	  RETURN_IF_ERROR (demangle_template_args (dm));
  
  	  /* Now we want to indicate to the caller that we've
--- 1161,1166 ----
*************** demangle_prefix (dm, template_p)
*** 1183,1191 ****
        else
  	return "Unexpected character in <compound-name>.";
  
!       /* Add a new substitution for the prefix thus far.  */
!       RETURN_IF_ERROR (substitution_add (dm, start, *template_p, 
! 					 NOT_TEMPLATE_PARM));
      }
  }
  
--- 1182,1192 ----
        else
  	return "Unexpected character in <compound-name>.";
  
!       if (peek != 'S'
! 	  && peek_char (dm) != 'E')
! 	/* Add a new substitution for the prefix thus far.  */
! 	RETURN_IF_ERROR (substitution_add (dm, start, *template_p, 
! 					   NOT_TEMPLATE_PARM));
      }
  }
  
*************** demangle_local_name (dm)
*** 2975,2981 ****
    RETURN_IF_ERROR (demangle_char (dm, 'Z'));
    RETURN_IF_ERROR (demangle_encoding (dm));
    RETURN_IF_ERROR (demangle_char (dm, 'E'));
!   RETURN_IF_ERROR (result_append (dm, "'s "));
  
    if (peek_char (dm) == 's')
      {
--- 2976,2982 ----
    RETURN_IF_ERROR (demangle_char (dm, 'Z'));
    RETURN_IF_ERROR (demangle_encoding (dm));
    RETURN_IF_ERROR (demangle_char (dm, 'E'));
!   RETURN_IF_ERROR (result_append (dm, "::"));
  
    if (peek_char (dm) == 's')
      {
*************** demangle_local_name (dm)
*** 2988,2994 ****
    else
      {
        int unused;
-       RETURN_IF_ERROR (result_append (dm, "local "));
        /* Local name for some other entity.  Demangle its name.  */
        RETURN_IF_ERROR (demangle_name (dm, &unused));
        RETURN_IF_ERROR (demangle_discriminator (dm, 1));
--- 2989,2994 ----


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