cp-demangle.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,161 行 · 第 1/5 页
C
2,161 行
*suppress_return_type = 1; RETURN_IF_ERROR (demangle_operator_name (dm, 0, &num_args)); } else if (peek == 'C' || peek == 'D') { /* Constructors never have a return type encoded. */ if (peek == 'C') *suppress_return_type = 1; RETURN_IF_ERROR (demangle_ctor_dtor_name (dm)); } else return "Unexpected character in <unqualified-name>."; return STATUS_OK;}/* Demangles and emits <source-name>. <source-name> ::= <length number> <identifier> */static status_tdemangle_source_name (dm) demangling_t dm;{ int length; DEMANGLE_TRACE ("source-name", dm); /* Decode the length of the identifier. */ RETURN_IF_ERROR (demangle_number (dm, &length, 10, 0)); if (length == 0) return "Zero length in <source-name>."; /* Now the identifier itself. It's placed into last_source_name, where it can be used to build a constructor or destructor name. */ RETURN_IF_ERROR (demangle_identifier (dm, length, dm->last_source_name)); /* Emit it. */ RETURN_IF_ERROR (result_add_string (dm, dm->last_source_name)); return STATUS_OK;}/* Demangles a number, either a <number> or a <positive-number> at the current position, consuming all consecutive digit characters. Sets *VALUE to the resulting numberand returns STATUS_OK. The number is interpreted as BASE, which must be either 10 or 36. If IS_SIGNED is non-zero, negative numbers -- prefixed with `n' -- are accepted. <number> ::= [n] <positive-number> <positive-number> ::= <decimal integer> */static status_tdemangle_number (dm, value, base, is_signed) demangling_t dm; int *value; int base; int is_signed;{ dyn_string_t number = dyn_string_new (10); DEMANGLE_TRACE ("number", dm); if (number == NULL) return STATUS_ALLOCATION_FAILED; demangle_number_literally (dm, number, base, is_signed); *value = strtol (dyn_string_buf (number), NULL, base); dyn_string_delete (number); return STATUS_OK;}/* Demangles a number at the current position. The digits (and minus sign, if present) that make up the number are appended to STR. Only base-BASE digits are accepted; BASE must be either 10 or 36. If IS_SIGNED, negative numbers -- prefixed with `n' -- are accepted. Does not consume a trailing underscore or other terminating character. */static status_tdemangle_number_literally (dm, str, base, is_signed) demangling_t dm; dyn_string_t str; int base; int is_signed;{ DEMANGLE_TRACE ("number*", dm); if (base != 10 && base != 36) return STATUS_INTERNAL_ERROR; /* An `n' denotes a negative number. */ if (is_signed && peek_char (dm) == 'n') { /* Skip past the n. */ advance_char (dm); /* The normal way to write a negative number is with a minus sign. */ if (!dyn_string_append_char (str, '-')) return STATUS_ALLOCATION_FAILED; } /* Loop until we hit a non-digit. */ while (1) { char peek = peek_char (dm); if (IS_DIGIT ((unsigned char) peek) || (base == 36 && peek >= 'A' && peek <= 'Z')) { /* Accumulate digits. */ if (!dyn_string_append_char (str, next_char (dm))) return STATUS_ALLOCATION_FAILED; } else /* Not a digit? All done. */ break; } return STATUS_OK;}/* Demangles an identifier at the current position of LENGTH characters and places it in IDENTIFIER. */static status_tdemangle_identifier (dm, length, identifier) demangling_t dm; int length; dyn_string_t identifier;{ DEMANGLE_TRACE ("identifier", dm); dyn_string_clear (identifier); if (!dyn_string_resize (identifier, length)) return STATUS_ALLOCATION_FAILED; while (length-- > 0) { if (end_of_name_p (dm)) return "Unexpected end of name in <identifier>."; if (!dyn_string_append_char (identifier, next_char (dm))) return STATUS_ALLOCATION_FAILED; } /* GCC encodes anonymous namespaces using a `_GLOBAL_[_.$]N.' followed by the source file name and some random characters. Unless we're in strict mode, decipher these names appropriately. */ if (!flag_strict) { char *name = dyn_string_buf (identifier); int prefix_length = strlen (ANONYMOUS_NAMESPACE_PREFIX); /* Compare the first, fixed part. */ if (strncmp (name, ANONYMOUS_NAMESPACE_PREFIX, prefix_length) == 0) { name += prefix_length; /* The next character might be a period, an underscore, or dollar sign, depending on the target architecture's assembler's capabilities. After that comes an `N'. */ if ((*name == '.' || *name == '_' || *name == '$') && *(name + 1) == 'N') /* This looks like the anonymous namespace identifier. Replace it with something comprehensible. */ dyn_string_copy_cstr (identifier, "(anonymous namespace)"); } } return STATUS_OK;}/* Demangles and emits an <operator-name>. If SHORT_NAME is non-zero, the short form is emitted; otherwise the full source form (`operator +' etc.) is emitted. *NUM_ARGS is set to the number of operands that the operator takes. <operator-name> ::= nw # new ::= na # new[] ::= dl # delete ::= da # delete[] ::= ps # + (unary) ::= ng # - (unary) ::= ad # & (unary) ::= de # * (unary) ::= co # ~ ::= pl # + ::= mi # - ::= ml # * ::= dv # / ::= rm # % ::= an # & ::= or # | ::= eo # ^ ::= aS # = ::= pL # += ::= mI # -= ::= mL # *= ::= dV # /= ::= rM # %= ::= aN # &= ::= oR # |= ::= eO # ^= ::= ls # << ::= rs # >> ::= lS # <<= ::= rS # >>= ::= eq # == ::= ne # != ::= lt # < ::= gt # > ::= le # <= ::= ge # >= ::= nt # ! ::= aa # && ::= oo # || ::= pp # ++ ::= mm # -- ::= cm # , ::= pm # ->* ::= pt # -> ::= cl # () ::= ix # [] ::= qu # ? ::= sz # sizeof ::= cv <type> # cast ::= v [0-9] <source-name> # vendor extended operator */static status_tdemangle_operator_name (dm, short_name, num_args) demangling_t dm; int short_name; int *num_args;{ struct operator_code { /* The mangled code for this operator. */ const char *code; /* The source name of this operator. */ const char *name; /* The number of arguments this operator takes. */ int num_args; }; static const struct operator_code operators[] = { { "aN", "&=" , 2 }, { "aS", "=" , 2 }, { "aa", "&&" , 2 }, { "ad", "&" , 1 }, { "an", "&" , 2 }, { "cl", "()" , 0 }, { "cm", "," , 2 }, { "co", "~" , 1 }, { "dV", "/=" , 2 }, { "da", " delete[]", 1 }, { "de", "*" , 1 }, { "dl", " delete" , 1 }, { "dv", "/" , 2 }, { "eO", "^=" , 2 }, { "eo", "^" , 2 }, { "eq", "==" , 2 }, { "ge", ">=" , 2 }, { "gt", ">" , 2 }, { "ix", "[]" , 2 }, { "lS", "<<=" , 2 }, { "le", "<=" , 2 }, { "ls", "<<" , 2 }, { "lt", "<" , 2 }, { "mI", "-=" , 2 }, { "mL", "*=" , 2 }, { "mi", "-" , 2 }, { "ml", "*" , 2 }, { "mm", "--" , 1 }, { "na", " new[]" , 1 }, { "ne", "!=" , 2 }, { "ng", "-" , 1 }, { "nt", "!" , 1 }, { "nw", " new" , 1 }, { "oR", "|=" , 2 }, { "oo", "||" , 2 }, { "or", "|" , 2 }, { "pL", "+=" , 2 }, { "pl", "+" , 2 }, { "pm", "->*" , 2 }, { "pp", "++" , 1 }, { "ps", "+" , 1 }, { "pt", "->" , 2 }, { "qu", "?" , 3 }, { "rM", "%=" , 2 }, { "rS", ">>=" , 2 }, { "rm", "%" , 2 }, { "rs", ">>" , 2 }, { "sz", " sizeof" , 1 } }; const int num_operators = sizeof (operators) / sizeof (struct operator_code); int c0 = next_char (dm); int c1 = next_char (dm); const struct operator_code* p1 = operators; const struct operator_code* p2 = operators + num_operators; DEMANGLE_TRACE ("operator-name", dm); /* Is this a vendor-extended operator? */ if (c0 == 'v' && IS_DIGIT (c1)) { RETURN_IF_ERROR (result_add (dm, "operator ")); RETURN_IF_ERROR (demangle_source_name (dm)); *num_args = 0; return STATUS_OK; } /* Is this a conversion operator? */ if (c0 == 'c' && c1 == 'v') { RETURN_IF_ERROR (result_add (dm, "operator ")); /* Demangle the converted-to type. */ RETURN_IF_ERROR (demangle_type (dm)); *num_args = 0; return STATUS_OK; } /* Perform a binary search for the operator code. */ while (1) { const struct operator_code* p = p1 + (p2 - p1) / 2; char match0 = p->code[0]; char match1 = p->code[1]; if (c0 == match0 && c1 == match1) /* Found it. */ { if (!short_name) RETURN_IF_ERROR (result_add (dm, "operator")); RETURN_IF_ERROR (result_add (dm, p->name)); *num_args = p->num_args; return STATUS_OK; } if (p == p1) /* Couldn't find it. */ return "Unknown code in <operator-name>."; /* Try again. */ if (c0 < match0 || (c0 == match0 && c1 < match1)) p2 = p; else p1 = p; }}/* Demangles and omits an <nv-offset>. <nv-offset> ::= <offset number> # non-virtual base override */static status_tdemangle_nv_offset (dm) demangling_t dm;{ dyn_string_t number; status_t status = STATUS_OK; DEMANGLE_TRACE ("h-offset", dm); /* Demangle the offset. */ number = dyn_string_new (4); if (number == NULL) return STATUS_ALLOCATION_FAILED; demangle_number_literally (dm, number, 10, 1); /* Don't display the offset unless in verbose mode. */ if (flag_verbose) { status = result_add (dm, " [nv:"); if (STATUS_NO_ERROR (status)) status = result_add_string (dm, number); if (STATUS_NO_ERROR (status)) status = result_add_char (dm, ']'); } /* Clean up. */ dyn_string_delete (number); RETURN_IF_ERROR (status); return STATUS_OK;}/* Demangles and emits a <v-offset>. <v-offset> ::= <offset number> _ <virtual offset number> # virtual base override, with vcall offset */static status_tdemangle_v_offset (dm) demangling_t dm;{ dyn_string_t number; status_t status = STATUS_OK; DEMANGLE_TRACE ("v-offset", dm); /* Demangle the offset. */ number = dyn_string_new (4); if (number == NULL) return STATUS_ALLOCATION_FAILED; demangle_number_literally (dm, number, 10, 1); /* Don't display the offset unless in verbose mode. */ if (flag_verbose) { status = result_add (dm, " [v:"); if (STATUS_NO_ERROR (status)) status = result_add_string (dm, number); if (STATUS_NO_ERROR (status)) result_add_char (dm, ','); } dyn_string_delete (number); RETURN_IF_ERROR (status); /* Demangle the separator. */ RETURN_IF_ERROR (demangle_char (dm, '_')); /* Demangle the vcall offset. */ number = dyn_string_new (4); if (number == NULL) return STATUS_ALLOCATION_FAILED;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?