cp-demangle.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,161 行 · 第 1/5 页

C
2,161 行
字号
  demangle_number_literally (dm, number, 10, 1);  /* Don't display the vcall offset unless in verbose mode.  */  if (flag_verbose)    {      status = result_add_string (dm, number);      if (STATUS_NO_ERROR (status))	status = result_add_char (dm, ']');    }  dyn_string_delete (number);  RETURN_IF_ERROR (status);  return STATUS_OK;}/* Demangles and emits a <call-offset>.    <call-offset> ::= h <nv-offset> _		  ::= v <v-offset> _  */static status_tdemangle_call_offset (dm)     demangling_t dm;{  DEMANGLE_TRACE ("call-offset", dm);  switch (peek_char (dm))    {    case 'h':      advance_char (dm);      /* Demangle the offset.  */      RETURN_IF_ERROR (demangle_nv_offset (dm));      /* Demangle the separator.  */      RETURN_IF_ERROR (demangle_char (dm, '_'));      break;    case 'v':      advance_char (dm);      /* Demangle the offset.  */      RETURN_IF_ERROR (demangle_v_offset (dm));      /* Demangle the separator.  */      RETURN_IF_ERROR (demangle_char (dm, '_'));      break;    default:      return "Unrecognized <call-offset>.";    }  return STATUS_OK;}/* Demangles and emits a <special-name>.      <special-name> ::= GV <object name>   # Guard variable                   ::= TV <type>          # virtual table                   ::= TT <type>          # VTT                   ::= TI <type>          # typeinfo structure		   ::= TS <type>          # typeinfo name     Other relevant productions include thunks:    <special-name> ::= T <call-offset> <base encoding> 			 # base is the nominal target function of thunk    <special-name> ::= Tc <call-offset> <call-offset> <base encoding>			 # base is the nominal target function of thunk			 # first call-offset is 'this' adjustment			 # second call-offset is result adjustment   where    <call-offset>  ::= h <nv-offset> _		   ::= v <v-offset> _   Also demangles the special g++ manglings,    <special-name> ::= TC <type> <offset number> _ <base type>                                          # construction vtable		   ::= TF <type>	  # typeinfo function (old ABI only)		   ::= TJ <type>	  # java Class structure  */static status_tdemangle_special_name (dm)     demangling_t dm;{  dyn_string_t number;  int unused;  char peek = peek_char (dm);  DEMANGLE_TRACE ("special-name", dm);  if (peek == 'G')    {      /* A guard variable name.  Consume the G.  */      advance_char (dm);      RETURN_IF_ERROR (demangle_char (dm, 'V'));      RETURN_IF_ERROR (result_add (dm, "guard variable for "));      RETURN_IF_ERROR (demangle_name (dm, &unused));    }  else if (peek == 'T')    {      status_t status = STATUS_OK;      /* Other C++ implementation miscellania.  Consume the T.  */      advance_char (dm);      switch (peek_char (dm))	{	case 'V':	  /* Virtual table.  */	  advance_char (dm);	  RETURN_IF_ERROR (result_add (dm, "vtable for "));	  RETURN_IF_ERROR (demangle_type (dm));	  break;	case 'T':	  /* VTT structure.  */	  advance_char (dm);	  RETURN_IF_ERROR (result_add (dm, "VTT for "));	  RETURN_IF_ERROR (demangle_type (dm));	  break;	case 'I':	  /* Typeinfo structure.  */	  advance_char (dm);	  RETURN_IF_ERROR (result_add (dm, "typeinfo for "));	  RETURN_IF_ERROR (demangle_type (dm));	  break;	case 'F':	  /* Typeinfo function.  Used only in old ABI with new mangling.  */	  advance_char (dm);	  RETURN_IF_ERROR (result_add (dm, "typeinfo fn for "));	  RETURN_IF_ERROR (demangle_type (dm));	  break;	case 'S':	  /* Character string containing type name, used in typeinfo. */	  advance_char (dm);	  RETURN_IF_ERROR (result_add (dm, "typeinfo name for "));	  RETURN_IF_ERROR (demangle_type (dm));	  break;	case 'J':	  /* The java Class variable corresponding to a C++ class.  */	  advance_char (dm);	  RETURN_IF_ERROR (result_add (dm, "java Class for "));	  RETURN_IF_ERROR (demangle_type (dm));	  break;	case 'h':	  /* Non-virtual thunk.  */	  advance_char (dm);	  RETURN_IF_ERROR (result_add (dm, "non-virtual thunk"));	  RETURN_IF_ERROR (demangle_nv_offset (dm));	  /* Demangle the separator.  */	  RETURN_IF_ERROR (demangle_char (dm, '_'));	  /* Demangle and emit the target name and function type.  */	  RETURN_IF_ERROR (result_add (dm, " to "));	  RETURN_IF_ERROR (demangle_encoding (dm));	  break;	case 'v':	  /* Virtual thunk.  */	  advance_char (dm);	  RETURN_IF_ERROR (result_add (dm, "virtual thunk"));	  RETURN_IF_ERROR (demangle_v_offset (dm));	  /* Demangle the separator.  */	  RETURN_IF_ERROR (demangle_char (dm, '_'));	  /* Demangle and emit the target function.  */	  RETURN_IF_ERROR (result_add (dm, " to "));	  RETURN_IF_ERROR (demangle_encoding (dm));	  break;	case 'c':	  /* Covariant return thunk.  */	  advance_char (dm);	  RETURN_IF_ERROR (result_add (dm, "covariant return thunk"));	  RETURN_IF_ERROR (demangle_call_offset (dm));	  RETURN_IF_ERROR (demangle_call_offset (dm));	  /* Demangle and emit the target function.  */	  RETURN_IF_ERROR (result_add (dm, " to "));	  RETURN_IF_ERROR (demangle_encoding (dm));	  break;	case 'C':	  /* TC is a special g++ mangling for a construction vtable. */	  if (!flag_strict)	    {	      dyn_string_t derived_type;	      advance_char (dm);	      RETURN_IF_ERROR (result_add (dm, "construction vtable for "));	      /* Demangle the derived type off to the side.  */	      RETURN_IF_ERROR (result_push (dm));	      RETURN_IF_ERROR (demangle_type (dm));	      derived_type = (dyn_string_t) result_pop (dm);	      /* Demangle the offset.  */	      number = dyn_string_new (4);	      if (number == NULL)		{		  dyn_string_delete (derived_type);		  return STATUS_ALLOCATION_FAILED;		}	      demangle_number_literally (dm, number, 10, 1);	      /* Demangle the underscore separator.  */	      status = demangle_char (dm, '_');	      /* Demangle the base type.  */	      if (STATUS_NO_ERROR (status))		status = demangle_type (dm);	      /* Emit the derived type.  */	      if (STATUS_NO_ERROR (status))		status = result_add (dm, "-in-");	      if (STATUS_NO_ERROR (status))		status = result_add_string (dm, derived_type);	      dyn_string_delete (derived_type);	      /* Don't display the offset unless in verbose mode.  */	      if (flag_verbose)		{		  status = result_add_char (dm, ' ');		  if (STATUS_NO_ERROR (status))		    result_add_string (dm, number);		}	      dyn_string_delete (number);	      RETURN_IF_ERROR (status);	      break;	    }	  /* If flag_strict, fall through.  */	default:	  return "Unrecognized <special-name>.";	}    }  else    return STATUS_ERROR;  return STATUS_OK;}/* Demangles and emits a <ctor-dtor-name>.         <ctor-dtor-name>                   ::= C1  # complete object (in-charge) ctor                   ::= C2  # base object (not-in-charge) ctor                   ::= C3  # complete object (in-charge) allocating ctor                   ::= D0  # deleting (in-charge) dtor                   ::= D1  # complete object (in-charge) dtor                   ::= D2  # base object (not-in-charge) dtor  */static status_tdemangle_ctor_dtor_name (dm)     demangling_t dm;{  static const char *const ctor_flavors[] =   {    "in-charge",    "not-in-charge",    "allocating"  };  static const char *const dtor_flavors[] =   {    "in-charge deleting",    "in-charge",    "not-in-charge"  };  int flavor;  char peek = peek_char (dm);  DEMANGLE_TRACE ("ctor-dtor-name", dm);    if (peek == 'C')    {      /* A constructor name.  Consume the C.  */      advance_char (dm);      if (peek_char (dm) < '1' || peek_char (dm) > '3')	return "Unrecognized constructor.";      RETURN_IF_ERROR (result_add_string (dm, dm->last_source_name));      /* Print the flavor of the constructor if in verbose mode.  */      flavor = next_char (dm) - '1';      if (flag_verbose)	{	  RETURN_IF_ERROR (result_add (dm, "["));	  RETURN_IF_ERROR (result_add (dm, ctor_flavors[flavor]));	  RETURN_IF_ERROR (result_add_char (dm, ']'));	}    }  else if (peek == 'D')    {      /* A destructor name.  Consume the D.  */      advance_char (dm);      if (peek_char (dm) < '0' || peek_char (dm) > '2')	return "Unrecognized destructor.";      RETURN_IF_ERROR (result_add_char (dm, '~'));      RETURN_IF_ERROR (result_add_string (dm, dm->last_source_name));      /* Print the flavor of the destructor if in verbose mode.  */      flavor = next_char (dm) - '0';      if (flag_verbose)	{	  RETURN_IF_ERROR (result_add (dm, " ["));	  RETURN_IF_ERROR (result_add (dm, dtor_flavors[flavor]));	  RETURN_IF_ERROR (result_add_char (dm, ']'));	}    }  else    return STATUS_ERROR;  return STATUS_OK;}/* Handle pointer, reference, and pointer-to-member cases for   demangle_type.  All consecutive `P's, `R's, and 'M's are joined to   build a pointer/reference type.  We snarf all these, plus the   following <type>, all at once since we need to know whether we have   a pointer to data or pointer to function to construct the right   output syntax.  C++'s pointer syntax is hairy.     This function adds substitution candidates for every nested   pointer/reference type it processes, including the outermost, final   type, assuming the substitution starts at SUBSTITUTION_START in the   demangling result.  For example, if this function demangles   `PP3Foo', it will add a substitution for `Foo', `Foo*', and   `Foo**', in that order.   *INSERT_POS is a quantity used internally, when this function calls   itself recursively, to figure out where to insert pointer   punctuation on the way up.  On entry to this function, INSERT_POS   should point to a temporary value, but that value need not be   initialized.     <type> ::= P <type>            ::= R <type>            ::= <pointer-to-member-type>     <pointer-to-member-type> ::= M </class/ type> </member/ type>  */static status_tdemangle_type_ptr (dm, insert_pos, substitution_start)     demangling_t dm;     int *insert_pos;     int substitution_start;{  status_t status;  int is_substitution_candidate = 1;  DEMANGLE_TRACE ("type*", dm);  /* Scan forward, collecting pointers and references into symbols,     until we hit something else.  Then emit the type.  */  switch (peek_char (dm))    {    case 'P':      /* A pointer.  Snarf the `P'.  */      advance_char (dm);      /* Demangle the underlying type.  */      RETURN_IF_ERROR (demangle_type_ptr (dm, insert_pos, 					  substitution_start));      /* Insert an asterisk where we're told to; it doesn't	 necessarily go at the end.  */      RETURN_IF_ERROR (result_insert_char (dm, *insert_pos, '*'));      /* The next (outermost) pointer or reference character should go	 after this one.  */      ++(*insert_pos);      break;    case 'R':      /* A reference.  Snarf the `R'.  */      advance_char (dm);      /* Demangle the underlying type.  */      RETURN_IF_ERROR (demangle_type_ptr (dm, insert_pos, 					  substitution_start));      /* Insert an ampersand where we're told to; it doesn't	 necessarily go at the end.  */      RETURN_IF_ERROR (result_insert_char (dm, *insert_pos, '&'));      /* The next (outermost) pointer or reference character should go	 after this one.  */      ++(*insert_pos);      break;    case 'M':    {      /* A pointer-to-member.  */      dyn_string_t class_type;            /* Eat the 'M'.  */      advance_char (dm);            /* Capture the type of which this is a pointer-to-member.  */      RETURN_IF_ERROR (result_push (dm));      RETURN_IF_ERROR (demangle_type (dm));      class_type = (dyn_string_t) result_pop (dm);            if (peek_char (dm) == 'F')	/* A pointer-to-member function.  We want output along the	   lines of `void (C::*) (int, int)'.  Demangle the function	   type, which would in this case give `void () (int, int)'	   and set *insert_pos to the spot between the first	   parentheses.  */	status = demangle_type_ptr (dm, insert_pos, substitution_start);      else if (peek_char (dm) == 'A')	/* A pointer-to-member array variable.  We want output that	   looks like `int (Klass::*) [10]'.  Demangle the array type	   as `int () [10]', and set *insert_pos to the spot between	   the parentheses.  */	status = demangle_array_type (dm, insert_pos);      else        {	  /* A pointer-to-member variable.  Demangle the type of the             pointed-to member.  */	  status = demangle_type (dm);	  /* Make it pretty.  */	  if (STATUS_NO_ERROR (status)	      && !result_previous_char_is_space (dm))	    status = result_add_char (dm, ' ');	  /* The pointer-to-member notation (e.g. `C::*') follows the             member's type.  */	  *insert_pos = result_caret_pos (dm);	}      /* Build the pointer-to-member notation.  */      if (STATUS_NO_ERROR (status))	status = result_insert (dm, *insert_pos, "::*");      if (STATUS_NO_ERROR (status))	status = result

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?