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