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