LLVM 20.0.0git
Demangle.h
Go to the documentation of this file.
1//===--- Demangle.h ---------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEMANGLE_DEMANGLE_H
10#define LLVM_DEMANGLE_DEMANGLE_H
11
12#include <cstddef>
13#include <string>
14#include <string_view>
15
16namespace llvm {
17/// This is a llvm local version of __cxa_demangle. Other than the name and
18/// being in the llvm namespace it is identical.
19///
20/// The mangled_name is demangled into buf and returned. If the buffer is not
21/// large enough, realloc is used to expand it.
22///
23/// The *status will be set to a value from the following enumeration
24enum : int {
30};
31
32/// Returns a non-NULL pointer to a NUL-terminated C style string
33/// that should be explicitly freed, if successful. Otherwise, may return
34/// nullptr if mangled_name is not a valid mangling or is nullptr.
35char *itaniumDemangle(std::string_view mangled_name, bool ParseParams = true);
36
45};
46
47/// Demangles the Microsoft symbol pointed at by mangled_name and returns it.
48/// Returns a pointer to the start of a null-terminated demangled string on
49/// success, or nullptr on error.
50/// If n_read is non-null and demangling was successful, it receives how many
51/// bytes of the input string were consumed.
52/// status receives one of the demangle_ enum entries above if it's not nullptr.
53/// Flags controls various details of the demangled representation.
54char *microsoftDemangle(std::string_view mangled_name, size_t *n_read,
55 int *status, MSDemangleFlags Flags = MSDF_None);
56
57// Demangles a Rust v0 mangled symbol.
58char *rustDemangle(std::string_view MangledName);
59
60// Demangles a D mangled symbol.
61char *dlangDemangle(std::string_view MangledName);
62
63/// Attempt to demangle a string using different demangling schemes.
64/// The function uses heuristics to determine which demangling scheme to use.
65/// \param MangledName - reference to string to demangle.
66/// \returns - the demangled string, or a copy of the input string if no
67/// demangling occurred.
68std::string demangle(std::string_view MangledName);
69
70bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result,
71 bool CanHaveLeadingDot = true,
72 bool ParseParams = true);
73
74/// "Partial" demangler. This supports demangling a string into an AST
75/// (typically an intermediate stage in itaniumDemangle) and querying certain
76/// properties or partially printing the demangled name.
79
82
83 /// Demangle into an AST. Subsequent calls to the rest of the member functions
84 /// implicitly operate on the AST this produces.
85 /// \return true on error, false otherwise
86 bool partialDemangle(const char *MangledName);
87
88 /// Just print the entire mangled name into Buf. Buf and N behave like the
89 /// second and third parameters to __cxa_demangle.
90 char *finishDemangle(char *Buf, size_t *N) const;
91
92 /// Get the base name of a function. This doesn't include trailing template
93 /// arguments, ie for "a::b<int>" this function returns "b".
94 char *getFunctionBaseName(char *Buf, size_t *N) const;
95
96 /// Get the context name for a function. For "a::b::c", this function returns
97 /// "a::b".
98 char *getFunctionDeclContextName(char *Buf, size_t *N) const;
99
100 /// Get the entire name of this function.
101 char *getFunctionName(char *Buf, size_t *N) const;
102
103 /// Get the parameters for this function.
104 char *getFunctionParameters(char *Buf, size_t *N) const;
105 char *getFunctionReturnType(char *Buf, size_t *N) const;
106
107 /// If this function has any cv or reference qualifiers. These imply that
108 /// the function is a non-static member function.
109 bool hasFunctionQualifiers() const;
110
111 /// If this symbol describes a constructor or destructor.
112 bool isCtorOrDtor() const;
113
114 /// If this symbol describes a function.
115 bool isFunction() const;
116
117 /// If this symbol describes a variable.
118 bool isData() const;
119
120 /// If this symbol is a <special-name>. These are generally implicitly
121 /// generated by the implementation, such as vtables and typeinfo names.
122 bool isSpecialName() const;
123
125
126private:
127 void *RootNode;
128 void *Context;
129};
130} // namespace llvm
131
132#endif
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result, bool CanHaveLeadingDot=true, bool ParseParams=true)
Definition: Demangle.cpp:49
@ demangle_unknown_error
Definition: Demangle.h:25
@ demangle_success
Definition: Demangle.h:29
@ demangle_invalid_mangled_name
Definition: Demangle.h:27
@ demangle_invalid_args
Definition: Demangle.h:26
@ demangle_memory_alloc_failure
Definition: Demangle.h:28
char * itaniumDemangle(std::string_view mangled_name, bool ParseParams=true)
Returns a non-NULL pointer to a NUL-terminated C style string that should be explicitly freed,...
char * dlangDemangle(std::string_view MangledName)
char * rustDemangle(std::string_view MangledName)
@ Other
Any other memory.
char * microsoftDemangle(std::string_view mangled_name, size_t *n_read, int *status, MSDemangleFlags Flags=MSDF_None)
Demangles the Microsoft symbol pointed at by mangled_name and returns it.
MSDemangleFlags
Definition: Demangle.h:37
@ MSDF_NoReturnType
Definition: Demangle.h:42
@ MSDF_None
Definition: Demangle.h:38
@ MSDF_DumpBackrefs
Definition: Demangle.h:39
@ MSDF_NoMemberType
Definition: Demangle.h:43
@ MSDF_NoVariableType
Definition: Demangle.h:44
@ MSDF_NoCallingConvention
Definition: Demangle.h:41
@ MSDF_NoAccessSpecifier
Definition: Demangle.h:40
std::string demangle(std::string_view MangledName)
Attempt to demangle a string using different demangling schemes.
Definition: Demangle.cpp:20
#define N
"Partial" demangler.
Definition: Demangle.h:77
char * getFunctionParameters(char *Buf, size_t *N) const
Get the parameters for this function.
bool isFunction() const
If this symbol describes a function.
char * getFunctionBaseName(char *Buf, size_t *N) const
Get the base name of a function.
bool isSpecialName() const
If this symbol is a <special-name>.
bool partialDemangle(const char *MangledName)
Demangle into an AST.
char * getFunctionName(char *Buf, size_t *N) const
Get the entire name of this function.
bool hasFunctionQualifiers() const
If this function has any cv or reference qualifiers.
char * finishDemangle(char *Buf, size_t *N) const
Just print the entire mangled name into Buf.
char * getFunctionReturnType(char *Buf, size_t *N) const
ItaniumPartialDemangler & operator=(ItaniumPartialDemangler &&Other)
bool isCtorOrDtor() const
If this symbol describes a constructor or destructor.
char * getFunctionDeclContextName(char *Buf, size_t *N) const
Get the context name for a function.
bool isData() const
If this symbol describes a variable.