LLVM  14.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 
15 namespace 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
23 enum : int {
29 };
30 
31 char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
32  int *status);
33 
34 
36  MSDF_None = 0,
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.
56 char *microsoftDemangle(const char *mangled_name, size_t *n_read,
57  char *buf, size_t *n_buf,
58  int *status, MSDemangleFlags Flags = MSDF_None);
59 
60 // Demangles a Rust v0 mangled symbol. The API follows that of __cxa_demangle.
61 char *rustDemangle(const char *MangledName, char *Buf, size_t *N, int *Status);
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.
68 std::string demangle(const std::string &MangledName);
69 
70 /// "Partial" demangler. This supports demangling a string into an AST
71 /// (typically an intermediate stage in itaniumDemangle) and querying certain
72 /// properties or partially printing the demangled name.
75 
78 
79  /// Demangle into an AST. Subsequent calls to the rest of the member functions
80  /// implicitly operate on the AST this produces.
81  /// \return true on error, false otherwise
82  bool partialDemangle(const char *MangledName);
83 
84  /// Just print the entire mangled name into Buf. Buf and N behave like the
85  /// second and third parameters to itaniumDemangle.
86  char *finishDemangle(char *Buf, size_t *N) const;
87 
88  /// Get the base name of a function. This doesn't include trailing template
89  /// arguments, ie for "a::b<int>" this function returns "b".
90  char *getFunctionBaseName(char *Buf, size_t *N) const;
91 
92  /// Get the context name for a function. For "a::b::c", this function returns
93  /// "a::b".
94  char *getFunctionDeclContextName(char *Buf, size_t *N) const;
95 
96  /// Get the entire name of this function.
97  char *getFunctionName(char *Buf, size_t *N) const;
98 
99  /// Get the parameters for this function.
100  char *getFunctionParameters(char *Buf, size_t *N) const;
101  char *getFunctionReturnType(char *Buf, size_t *N) const;
102 
103  /// If this function has any any cv or reference qualifiers. These imply that
104  /// the function is a non-static member function.
105  bool hasFunctionQualifiers() const;
106 
107  /// If this symbol describes a constructor or destructor.
108  bool isCtorOrDtor() const;
109 
110  /// If this symbol describes a function.
111  bool isFunction() const;
112 
113  /// If this symbol describes a variable.
114  bool isData() const;
115 
116  /// If this symbol is a <special-name>. These are generally implicitly
117  /// generated by the implementation, such as vtables and typeinfo names.
118  bool isSpecialName() const;
119 
121 private:
122  void *RootNode;
123  void *Context;
124 };
125 } // namespace llvm
126 
127 #endif
llvm::ItaniumPartialDemangler::~ItaniumPartialDemangler
~ItaniumPartialDemangler()
Definition: ItaniumDemangle.cpp:361
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::ItaniumPartialDemangler::ItaniumPartialDemangler
ItaniumPartialDemangler()
Definition: ItaniumDemangle.cpp:358
llvm::ItaniumPartialDemangler::getFunctionName
char * getFunctionName(char *Buf, size_t *N) const
Get the entire name of this function.
Definition: ItaniumDemangle.cpp:473
llvm::MSDF_NoAccessSpecifier
@ MSDF_NoAccessSpecifier
Definition: Demangle.h:38
llvm::ItaniumPartialDemangler::isSpecialName
bool isSpecialName() const
If this symbol is a <special-name>.
Definition: ItaniumDemangle.cpp:569
llvm::ItaniumPartialDemangler
"Partial" demangler.
Definition: Demangle.h:73
llvm::demangle_success
@ demangle_success
Definition: Demangle.h:28
llvm::ItaniumPartialDemangler::partialDemangle
bool partialDemangle(const char *MangledName)
Demangle into an AST.
Definition: ItaniumDemangle.cpp:379
llvm::MSDF_None
@ MSDF_None
Definition: Demangle.h:36
llvm::MSDF_NoCallingConvention
@ MSDF_NoCallingConvention
Definition: Demangle.h:39
llvm::ItaniumPartialDemangler::operator=
ItaniumPartialDemangler & operator=(ItaniumPartialDemangler &&Other)
Definition: ItaniumDemangle.cpp:372
llvm::demangle
std::string demangle(const std::string &MangledName)
Attempt to demangle a string using different demangling schemes.
Definition: Demangle.cpp:27
llvm::demangle_invalid_mangled_name
@ demangle_invalid_mangled_name
Definition: Demangle.h:26
llvm::ItaniumPartialDemangler::isData
bool isData() const
If this symbol describes a variable.
Definition: ItaniumDemangle.cpp:575
llvm::ItaniumPartialDemangler::getFunctionParameters
char * getFunctionParameters(char *Buf, size_t *N) const
Get the parameters for this function.
Definition: ItaniumDemangle.cpp:480
llvm::MSDF_NoReturnType
@ MSDF_NoReturnType
Definition: Demangle.h:40
llvm::ItaniumPartialDemangler::getFunctionDeclContextName
char * getFunctionDeclContextName(char *Buf, size_t *N) const
Get the context name for a function.
Definition: ItaniumDemangle.cpp:427
Status
Definition: SIModeRegister.cpp:28
llvm::MSDemangleFlags
MSDemangleFlags
Definition: Demangle.h:35
llvm::MSDF_DumpBackrefs
@ MSDF_DumpBackrefs
Definition: Demangle.h:37
llvm::ItaniumPartialDemangler::hasFunctionQualifiers
bool hasFunctionQualifiers() const
If this function has any any cv or reference qualifiers.
Definition: ItaniumDemangle.cpp:523
llvm::ItaniumPartialDemangler::getFunctionBaseName
char * getFunctionBaseName(char *Buf, size_t *N) const
Get the base name of a function.
Definition: ItaniumDemangle.cpp:398
llvm::demangle_memory_alloc_failure
@ demangle_memory_alloc_failure
Definition: Demangle.h:27
llvm::demangle_unknown_error
@ demangle_unknown_error
Definition: Demangle.h:24
llvm::microsoftDemangle
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.
Definition: MicrosoftDemangle.cpp:2341
llvm::ItaniumPartialDemangler::getFunctionReturnType
char * getFunctionReturnType(char *Buf, size_t *N) const
Definition: ItaniumDemangle.cpp:499
llvm::sys::fs::status
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
N
#define N
llvm::ItaniumPartialDemangler::finishDemangle
char * finishDemangle(char *Buf, size_t *N) const
Just print the entire mangled name into Buf.
Definition: ItaniumDemangle.cpp:518
llvm::itaniumDemangle
char * itaniumDemangle(const char *mangled_name, char *buf, size_t *n, int *status)
Definition: ItaniumDemangle.cpp:326
n
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
Definition: README.txt:685
llvm::demangle_invalid_args
@ demangle_invalid_args
Definition: Demangle.h:25
llvm::MSDF_NoMemberType
@ MSDF_NoMemberType
Definition: Demangle.h:41
llvm::ItaniumPartialDemangler::isCtorOrDtor
bool isCtorOrDtor() const
If this symbol describes a constructor or destructor.
Definition: ItaniumDemangle.cpp:531
llvm::ItaniumPartialDemangler::isFunction
bool isFunction() const
If this symbol describes a function.
Definition: ItaniumDemangle.cpp:563
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1172
llvm::rustDemangle
char * rustDemangle(const char *MangledName, char *Buf, size_t *N, int *Status)
Definition: RustDemangle.cpp:149