LLVM 24.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
49 /// Don't write "(void)" for functions that take no parameters.
51 /// Don't add decoration to RTTI type descriptors:
52 /// struct MyStruct `RTTI Type Descriptor Name'
53 /// will instead output
54 /// struct MyStruct
56};
57
58/// Demangles the Microsoft symbol pointed at by mangled_name and returns it.
59/// Returns a pointer to the start of a null-terminated demangled string on
60/// success, or nullptr on error.
61/// If n_read is non-null and demangling was successful, it receives how many
62/// bytes of the input string were consumed.
63/// status receives one of the demangle_ enum entries above if it's not nullptr.
64/// Flags controls various details of the demangled representation.
65DEMANGLE_ABI char *microsoftDemangle(std::string_view mangled_name,
66 size_t *n_read, int *status,
68
69DEMANGLE_ABI std::optional<size_t>
70getArm64ECInsertionPointInMangledName(std::string_view MangledName);
71
72// Demangles a Rust v0 mangled symbol.
73DEMANGLE_ABI char *rustDemangle(std::string_view MangledName);
74
75// Demangles a D mangled symbol.
76DEMANGLE_ABI char *dlangDemangle(std::string_view MangledName);
77
78/// Attempt to demangle a string using different demangling schemes.
79/// The function uses heuristics to determine which demangling scheme to use.
80/// \param MangledName - reference to string to demangle.
81/// \returns - the demangled string, or a copy of the input string if no
82/// demangling occurred.
83DEMANGLE_ABI std::string demangle(std::string_view MangledName);
84
85DEMANGLE_ABI bool nonMicrosoftDemangle(std::string_view MangledName,
86 std::string &Result,
87 bool CanHaveLeadingDot = true,
88 bool ParseParams = true);
89
90/// "Partial" demangler. This supports demangling a string into an AST
91/// (typically an intermediate stage in itaniumDemangle) and querying certain
92/// properties or partially printing the demangled name.
95
99
100 /// Demangle into an AST. Subsequent calls to the rest of the member functions
101 /// implicitly operate on the AST this produces.
102 /// \return true on error, false otherwise
103 DEMANGLE_ABI bool partialDemangle(const char *MangledName);
104
105 /// Just print the entire mangled name into Buf. Buf and N behave like the
106 /// second and third parameters to __cxa_demangle.
107 DEMANGLE_ABI char *finishDemangle(char *Buf, size_t *N) const;
108
109 /// See \ref finishDemangle
110 ///
111 /// \param[in] OB A llvm::itanium_demangle::OutputBuffer that the demangled
112 /// name will be printed into.
113 ///
114 DEMANGLE_ABI char *finishDemangle(void *OB) const;
115
116 /// Get the base name of a function. This doesn't include trailing template
117 /// arguments, ie for "a::b<int>" this function returns "b".
118 DEMANGLE_ABI char *getFunctionBaseName(char *Buf, size_t *N) const;
119
120 /// Get the context name for a function. For "a::b::c", this function returns
121 /// "a::b".
122 DEMANGLE_ABI char *getFunctionDeclContextName(char *Buf, size_t *N) const;
123
124 /// Get the entire name of this function.
125 DEMANGLE_ABI char *getFunctionName(char *Buf, size_t *N) const;
126
127 /// Get the parameters for this function.
128 DEMANGLE_ABI char *getFunctionParameters(char *Buf, size_t *N) const;
129 DEMANGLE_ABI char *getFunctionReturnType(char *Buf, size_t *N) const;
130
131 /// If this function has any cv or reference qualifiers. These imply that
132 /// the function is a non-static member function.
134
135 /// If this symbol describes a constructor or destructor.
136 DEMANGLE_ABI bool isCtorOrDtor() const;
137
138 /// If this symbol describes a function.
139 DEMANGLE_ABI bool isFunction() const;
140
141 /// If this symbol describes a variable.
142 DEMANGLE_ABI bool isData() const;
143
144 /// If this symbol is a <special-name>. These are generally implicitly
145 /// generated by the implementation, such as vtables and typeinfo names.
146 DEMANGLE_ABI bool isSpecialName() const;
147
149
150private:
151 void *RootNode;
152 void *Context;
153};
154} // namespace llvm
155
156#endif
#define DEMANGLE_ABI
DEMANGLE_ABI is the export/visibility macro used to mark symbols declared in llvm/Demangle as exporte...
This is an optimization pass for GlobalISel generic memory operations.
DEMANGLE_ABI bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result, bool CanHaveLeadingDot=true, bool ParseParams=true)
Definition Demangle.cpp:60
@ 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 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_ABI char * dlangDemangle(std::string_view MangledName)
DEMANGLE_ABI char * rustDemangle(std::string_view MangledName)
@ Other
Any other memory.
Definition ModRef.h:68
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_NoVoidParameter
Don't write "(void)" for functions that take no parameters.
Definition Demangle.h:50
@ MSDF_NoTagSpecifier
Definition Demangle.h:48
@ MSDF_NoReturnType
Definition Demangle.h:45
@ MSDF_NoDecorativeRTTITypeDescriptor
Don't add decoration to RTTI type descriptors: struct MyStruct ‘RTTI Type Descriptor Name’ will inste...
Definition Demangle.h:55
@ 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:21
#define N
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.