|
|
|||
File indexing completed on 2026-05-10 08:43:47
0001 //===--- Demangle.h ---------------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_DEMANGLE_DEMANGLE_H 0010 #define LLVM_DEMANGLE_DEMANGLE_H 0011 0012 #include <cstddef> 0013 #include <optional> 0014 #include <string> 0015 #include <string_view> 0016 0017 namespace llvm { 0018 /// This is a llvm local version of __cxa_demangle. Other than the name and 0019 /// being in the llvm namespace it is identical. 0020 /// 0021 /// The mangled_name is demangled into buf and returned. If the buffer is not 0022 /// large enough, realloc is used to expand it. 0023 /// 0024 /// The *status will be set to a value from the following enumeration 0025 enum : int { 0026 demangle_unknown_error = -4, 0027 demangle_invalid_args = -3, 0028 demangle_invalid_mangled_name = -2, 0029 demangle_memory_alloc_failure = -1, 0030 demangle_success = 0, 0031 }; 0032 0033 /// Returns a non-NULL pointer to a NUL-terminated C style string 0034 /// that should be explicitly freed, if successful. Otherwise, may return 0035 /// nullptr if mangled_name is not a valid mangling or is nullptr. 0036 char *itaniumDemangle(std::string_view mangled_name, bool ParseParams = true); 0037 0038 enum MSDemangleFlags { 0039 MSDF_None = 0, 0040 MSDF_DumpBackrefs = 1 << 0, 0041 MSDF_NoAccessSpecifier = 1 << 1, 0042 MSDF_NoCallingConvention = 1 << 2, 0043 MSDF_NoReturnType = 1 << 3, 0044 MSDF_NoMemberType = 1 << 4, 0045 MSDF_NoVariableType = 1 << 5, 0046 }; 0047 0048 /// Demangles the Microsoft symbol pointed at by mangled_name and returns it. 0049 /// Returns a pointer to the start of a null-terminated demangled string on 0050 /// success, or nullptr on error. 0051 /// If n_read is non-null and demangling was successful, it receives how many 0052 /// bytes of the input string were consumed. 0053 /// status receives one of the demangle_ enum entries above if it's not nullptr. 0054 /// Flags controls various details of the demangled representation. 0055 char *microsoftDemangle(std::string_view mangled_name, size_t *n_read, 0056 int *status, MSDemangleFlags Flags = MSDF_None); 0057 0058 std::optional<size_t> 0059 getArm64ECInsertionPointInMangledName(std::string_view MangledName); 0060 0061 // Demangles a Rust v0 mangled symbol. 0062 char *rustDemangle(std::string_view MangledName); 0063 0064 // Demangles a D mangled symbol. 0065 char *dlangDemangle(std::string_view MangledName); 0066 0067 /// Attempt to demangle a string using different demangling schemes. 0068 /// The function uses heuristics to determine which demangling scheme to use. 0069 /// \param MangledName - reference to string to demangle. 0070 /// \returns - the demangled string, or a copy of the input string if no 0071 /// demangling occurred. 0072 std::string demangle(std::string_view MangledName); 0073 0074 bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result, 0075 bool CanHaveLeadingDot = true, 0076 bool ParseParams = true); 0077 0078 /// "Partial" demangler. This supports demangling a string into an AST 0079 /// (typically an intermediate stage in itaniumDemangle) and querying certain 0080 /// properties or partially printing the demangled name. 0081 struct ItaniumPartialDemangler { 0082 ItaniumPartialDemangler(); 0083 0084 ItaniumPartialDemangler(ItaniumPartialDemangler &&Other); 0085 ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other); 0086 0087 /// Demangle into an AST. Subsequent calls to the rest of the member functions 0088 /// implicitly operate on the AST this produces. 0089 /// \return true on error, false otherwise 0090 bool partialDemangle(const char *MangledName); 0091 0092 /// Just print the entire mangled name into Buf. Buf and N behave like the 0093 /// second and third parameters to __cxa_demangle. 0094 char *finishDemangle(char *Buf, size_t *N) const; 0095 0096 /// Get the base name of a function. This doesn't include trailing template 0097 /// arguments, ie for "a::b<int>" this function returns "b". 0098 char *getFunctionBaseName(char *Buf, size_t *N) const; 0099 0100 /// Get the context name for a function. For "a::b::c", this function returns 0101 /// "a::b". 0102 char *getFunctionDeclContextName(char *Buf, size_t *N) const; 0103 0104 /// Get the entire name of this function. 0105 char *getFunctionName(char *Buf, size_t *N) const; 0106 0107 /// Get the parameters for this function. 0108 char *getFunctionParameters(char *Buf, size_t *N) const; 0109 char *getFunctionReturnType(char *Buf, size_t *N) const; 0110 0111 /// If this function has any cv or reference qualifiers. These imply that 0112 /// the function is a non-static member function. 0113 bool hasFunctionQualifiers() const; 0114 0115 /// If this symbol describes a constructor or destructor. 0116 bool isCtorOrDtor() const; 0117 0118 /// If this symbol describes a function. 0119 bool isFunction() const; 0120 0121 /// If this symbol describes a variable. 0122 bool isData() const; 0123 0124 /// If this symbol is a <special-name>. These are generally implicitly 0125 /// generated by the implementation, such as vtables and typeinfo names. 0126 bool isSpecialName() const; 0127 0128 ~ItaniumPartialDemangler(); 0129 0130 private: 0131 void *RootNode; 0132 void *Context; 0133 }; 0134 } // namespace llvm 0135 0136 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|