⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cp-demangle.c

📁 功能较全面的反汇编器:反汇编器ht-2.0.15.tar.gz
💻 C
📖 第 1 页 / 共 5 页
字号:
  if (! d_check_char (di, 'Z'))    return NULL;  return d_encoding (di, top_level);}/* Return whether a function should have a return type.  The argument   is the function name, which may be qualified in various ways.  The   rules are that template functions have return types with some   exceptions, function types which are not part of a function name   mangling have return types with some exceptions, and non-template   function names do not have return types.  The exceptions are that   constructors, destructors, and conversion operators do not have   return types.  */static inthas_return_type (struct demangle_component *dc){  if (dc == NULL)    return 0;  switch (dc->type)    {    default:      return 0;    case DEMANGLE_COMPONENT_TEMPLATE:      return ! is_ctor_dtor_or_conversion (d_left (dc));    case DEMANGLE_COMPONENT_RESTRICT_THIS:    case DEMANGLE_COMPONENT_VOLATILE_THIS:    case DEMANGLE_COMPONENT_CONST_THIS:      return has_return_type (d_left (dc));    }}/* Return whether a name is a constructor, a destructor, or a   conversion operator.  */static intis_ctor_dtor_or_conversion (struct demangle_component *dc){  if (dc == NULL)    return 0;  switch (dc->type)    {    default:      return 0;    case DEMANGLE_COMPONENT_QUAL_NAME:    case DEMANGLE_COMPONENT_LOCAL_NAME:      return is_ctor_dtor_or_conversion (d_right (dc));    case DEMANGLE_COMPONENT_CTOR:    case DEMANGLE_COMPONENT_DTOR:    case DEMANGLE_COMPONENT_CAST:      return 1;    }}/* <encoding> ::= <(function) name> <bare-function-type>              ::= <(data) name>              ::= <special-name>   TOP_LEVEL is non-zero when called at the top level, in which case   if DMGL_PARAMS is not set we do not demangle the function   parameters.  We only set this at the top level, because otherwise   we would not correctly demangle names in local scopes.  */static struct demangle_component *d_encoding (struct d_info *di, int top_level){  char peek = d_peek_char (di);  if (peek == 'G' || peek == 'T')    return d_special_name (di);  else    {      struct demangle_component *dc;      dc = d_name (di);      if (dc != NULL && top_level && (di->options & DMGL_PARAMS) == 0)	{	  /* Strip off any initial CV-qualifiers, as they really apply	     to the `this' parameter, and they were not output by the	     v2 demangler without DMGL_PARAMS.  */	  while (dc->type == DEMANGLE_COMPONENT_RESTRICT_THIS		 || dc->type == DEMANGLE_COMPONENT_VOLATILE_THIS		 || dc->type == DEMANGLE_COMPONENT_CONST_THIS)	    dc = d_left (dc);	  /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then	     there may be CV-qualifiers on its right argument which	     really apply here; this happens when parsing a class	     which is local to a function.  */	  if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME)	    {	      struct demangle_component *dcr;	      dcr = d_right (dc);	      while (dcr->type == DEMANGLE_COMPONENT_RESTRICT_THIS		     || dcr->type == DEMANGLE_COMPONENT_VOLATILE_THIS		     || dcr->type == DEMANGLE_COMPONENT_CONST_THIS)		dcr = d_left (dcr);	      dc->u.s_binary.right = dcr;	    }	  return dc;	}      peek = d_peek_char (di);      if (dc == NULL || peek == '\0' || peek == 'E')	return dc;      return d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME, dc,			  d_bare_function_type (di, has_return_type (dc)));    }}/* <name> ::= <nested-name>          ::= <unscoped-name>          ::= <unscoped-template-name> <template-args>          ::= <local-name>   <unscoped-name> ::= <unqualified-name>                   ::= St <unqualified-name>   <unscoped-template-name> ::= <unscoped-name>                            ::= <substitution>*/static struct demangle_component *d_name (struct d_info *di){  char peek = d_peek_char (di);  struct demangle_component *dc;  switch (peek)    {    case 'N':      return d_nested_name (di);    case 'Z':      return d_local_name (di);    case 'L':      return d_unqualified_name (di);	    case 'S':      {	int subst;	if (d_peek_next_char (di) != 't')	  {	    dc = d_substitution (di, 0);	    subst = 1;	  }	else	  {	    d_advance (di, 2);	    dc = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME,			      d_make_name (di, "std", 3),			      d_unqualified_name (di));	    di->expansion += 3;	    subst = 0;	  }	if (d_peek_char (di) != 'I')	  {	    /* The grammar does not permit this case to occur if we	       called d_substitution() above (i.e., subst == 1).  We	       don't bother to check.  */	  }	else	  {	    /* This is <template-args>, which means that we just saw	       <unscoped-template-name>, which is a substitution	       candidate if we didn't just get it from a	       substitution.  */	    if (! subst)	      {		if (! d_add_substitution (di, dc))		  return NULL;	      }	    dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,			      d_template_args (di));	  }	return dc;      }    default:      dc = d_unqualified_name (di);      if (d_peek_char (di) == 'I')	{	  /* This is <template-args>, which means that we just saw	     <unscoped-template-name>, which is a substitution	     candidate.  */	  if (! d_add_substitution (di, dc))	    return NULL;	  dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,			    d_template_args (di));	}      return dc;    }}/* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E                 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E*/static struct demangle_component *d_nested_name (struct d_info *di){  struct demangle_component *ret;  struct demangle_component **pret;  if (! d_check_char (di, 'N'))    return NULL;  pret = d_cv_qualifiers (di, &ret, 1);  if (pret == NULL)    return NULL;  *pret = d_prefix (di);  if (*pret == NULL)    return NULL;  if (! d_check_char (di, 'E'))    return NULL;  return ret;}/* <prefix> ::= <prefix> <unqualified-name>            ::= <template-prefix> <template-args>            ::= <template-param>            ::=            ::= <substitution>   <template-prefix> ::= <prefix> <(template) unqualified-name>                     ::= <template-param>                     ::= <substitution>*/static struct demangle_component *d_prefix (struct d_info *di){  struct demangle_component *ret = NULL;  while (1)    {      char peek;      enum demangle_component_type comb_type;      struct demangle_component *dc;      peek = d_peek_char (di);      if (peek == '\0')	return NULL;      /* The older code accepts a <local-name> here, but I don't see	 that in the grammar.  The older code does not accept a	 <template-param> here.  */      comb_type = DEMANGLE_COMPONENT_QUAL_NAME;      if (IS_DIGIT (peek)	  || IS_LOWER (peek)	  || peek == 'C'	  || peek == 'D'	  || peek == 'L')	dc = d_unqualified_name (di);      else if (peek == 'S')	dc = d_substitution (di, 1);      else if (peek == 'I')	{	  if (ret == NULL)	    return NULL;	  comb_type = DEMANGLE_COMPONENT_TEMPLATE;	  dc = d_template_args (di);	}      else if (peek == 'T')	dc = d_template_param (di);      else if (peek == 'E')	return ret;      else	return NULL;      if (ret == NULL)	ret = dc;      else	ret = d_make_comp (di, comb_type, ret, dc);      if (peek != 'S' && d_peek_char (di) != 'E')	{	  if (! d_add_substitution (di, ret))	    return NULL;	}    }}/* <unqualified-name> ::= <operator-name>                      ::= <ctor-dtor-name>                      ::= <source-name>		      ::= <local-source-name>     <local-source-name>	::= L <source-name> <discriminator>*/static struct demangle_component *d_unqualified_name (struct d_info *di){  char peek;  peek = d_peek_char (di);  if (IS_DIGIT (peek))    return d_source_name (di);  else if (IS_LOWER (peek))    {      struct demangle_component *ret;      ret = d_operator_name (di);      if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR)	di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2;      return ret;    }  else if (peek == 'C' || peek == 'D')    return d_ctor_dtor_name (di);  else if (peek == 'L')    {      struct demangle_component * ret;      d_advance (di, 1);      ret = d_source_name (di);      if (ret == NULL)	return NULL;      if (! d_discriminator (di))	return NULL;      return ret;    }  else    return NULL;}/* <source-name> ::= <(positive length) number> <identifier>  */static struct demangle_component *d_source_name (struct d_info *di){  long len;  struct demangle_component *ret;  len = d_number (di);  if (len <= 0)    return NULL;  ret = d_identifier (di, len);  di->last_name = ret;  return ret;}/* number ::= [n] <(non-negative decimal integer)>  */static longd_number (struct d_info *di){  int negative;  char peek;  long ret;  negative = 0;  peek = d_peek_char (di);  if (peek == 'n')    {      negative = 1;      d_advance (di, 1);      peek = d_peek_char (di);    }  ret = 0;  while (1)    {      if (! IS_DIGIT (peek))	{	  if (negative)	    ret = - ret;	  return ret;	}      ret = ret * 10 + peek - '0';      d_advance (di, 1);      peek = d_peek_char (di);    }}/* identifier ::= <(unqualified source code identifier)>  */static struct demangle_component *d_identifier (struct d_info *di, int len){  const char *name;  name = d_str (di);  if (di->send - name < len)    return NULL;  d_advance (di, len);  /* A Java mangled name may have a trailing '$' if it is a C++     keyword.  This '$' is not included in the length count.  We just     ignore the '$'.  */  if ((di->options & DMGL_JAVA) != 0      && d_peek_char (di) == '$')    d_advance (di, 1);  /* Look for something which looks like a gcc encoding of an     anonymous namespace, and replace it with a more user friendly     name.  */  if (len >= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN + 2      && memcmp (name, ANONYMOUS_NAMESPACE_PREFIX,		 ANONYMOUS_NAMESPACE_PREFIX_LEN) == 0)    {      const char *s;      s = name + ANONYMOUS_NAMESPACE_PREFIX_LEN;      if ((*s == '.' || *s == '_' || *s == '$')	  && s[1] == 'N')	{	  di->expansion -= len - sizeof "(anonymous namespace)";	  return d_make_name (di, "(anonymous namespace)",			      sizeof "(anonymous namespace)" - 1);	}    }  return d_make_name (di, name, len);}/* operator_name ::= many different two character encodings.                 ::= cv <type>                 ::= v <digit> <source-name>*/#define NL(s) s, (sizeof s) - 1CP_STATIC_IF_GLIBCPP_V3const struct demangle_operator_info cplus_demangle_operators[] ={  { "aN", NL ("&="),        2 },  { "aS", NL ("="),         2 },  { "aa", NL ("&&"),        2 },  { "ad", NL ("&"),         1 },  { "an", NL ("&"),         2 },  { "cl", NL ("()"),        0 },  { "cm", NL (","),         2 },  { "co", NL ("~"),         1 },  { "dV", NL ("/="),        2 },  { "da", NL ("delete[]"),  1 },  { "de", NL ("*"),         1 },  { "dl", NL ("delete"),    1 },  { "dv", NL ("/"),         2 },  { "eO", NL ("^="),        2 },  { "eo", NL ("^"),         2 },  { "eq", NL ("=="),        2 },  { "ge", NL (">="),        2 },  { "gt", NL (">"),         2 },  { "ix", NL ("[]"),        2 },  { "lS", NL ("<<="),       2 },  { "le", NL ("<="),        2 },  { "ls", NL ("<<"),        2 },  { "lt", NL ("<"),         2 },  { "mI", NL ("-="),        2 },  { "mL", NL ("*="),        2 },  { "mi", NL ("-"),         2 },  { "ml", NL ("*"),         2 },  { "mm", NL ("--"),        1 },  { "na", NL ("new[]"),     1 },  { "ne", NL ("!="),        2 },  { "ng", NL ("-"),         1 },  { "nt", NL ("!"),         1 },  { "nw", NL ("new"),       1 },  { "oR", NL ("|="),        2 },  { "oo", NL ("||"),        2 },  { "or", NL ("|"),         2 },  { "pL", NL ("+="),        2 },  { "pl", NL ("+"),         2 },  { "pm", NL ("->*"),       2 },  { "pp", NL ("++"),        1 },  { "ps", NL ("+"),         1 },  { "pt", NL ("->"),        2 },  { "qu", NL ("?"),         3 },  { "rM", NL ("%="),        2 },  { "rS", NL (">>="),       2 },  { "rm", NL ("%"),         2 },  { "rs", NL (">>"),        2 },  { "st", NL ("sizeof "),   1 },

⌨️ 快捷键说明

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