LLVM  10.0.0svn
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 char *microsoftDemangle(const char *mangled_name, char *buf, size_t *n,
44  int *status, MSDemangleFlags Flags = MSDF_None);
45 
46 /// Attempt to demangle a string using different demangling schemes.
47 /// The function uses heuristics to determine which demangling scheme to use.
48 /// \param MangledName - reference to string to demangle.
49 /// \returns - the demangled string, or a copy of the input string if no
50 /// demangling occurred.
51 std::string demangle(const std::string &MangledName);
52 
53 /// "Partial" demangler. This supports demangling a string into an AST
54 /// (typically an intermediate stage in itaniumDemangle) and querying certain
55 /// properties or partially printing the demangled name.
58 
61 
62  /// Demangle into an AST. Subsequent calls to the rest of the member functions
63  /// implicitly operate on the AST this produces.
64  /// \return true on error, false otherwise
65  bool partialDemangle(const char *MangledName);
66 
67  /// Just print the entire mangled name into Buf. Buf and N behave like the
68  /// second and third parameters to itaniumDemangle.
69  char *finishDemangle(char *Buf, size_t *N) const;
70 
71  /// Get the base name of a function. This doesn't include trailing template
72  /// arguments, ie for "a::b<int>" this function returns "b".
73  char *getFunctionBaseName(char *Buf, size_t *N) const;
74 
75  /// Get the context name for a function. For "a::b::c", this function returns
76  /// "a::b".
77  char *getFunctionDeclContextName(char *Buf, size_t *N) const;
78 
79  /// Get the entire name of this function.
80  char *getFunctionName(char *Buf, size_t *N) const;
81 
82  /// Get the parameters for this function.
83  char *getFunctionParameters(char *Buf, size_t *N) const;
84  char *getFunctionReturnType(char *Buf, size_t *N) const;
85 
86  /// If this function has any any cv or reference qualifiers. These imply that
87  /// the function is a non-static member function.
88  bool hasFunctionQualifiers() const;
89 
90  /// If this symbol describes a constructor or destructor.
91  bool isCtorOrDtor() const;
92 
93  /// If this symbol describes a function.
94  bool isFunction() const;
95 
96  /// If this symbol describes a variable.
97  bool isData() const;
98 
99  /// If this symbol is a <special-name>. These are generally implicitly
100  /// generated by the implementation, such as vtables and typeinfo names.
101  bool isSpecialName() const;
102 
104 private:
105  void *RootNode;
106  void *Context;
107 };
108 } // namespace llvm
109 
110 #endif
char * itaniumDemangle(const char *mangled_name, char *buf, size_t *n, int *status)
ItaniumPartialDemangler & operator=(ItaniumPartialDemangler &&Other)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:953
bool isData() const
If this symbol describes a variable.
bool isFunction() const
If this symbol describes a function.
char * getFunctionName(char *Buf, size_t *N) const
Get the entire name of this function.
bool isCtorOrDtor() const
If this symbol describes a constructor or destructor.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
MSDemangleFlags
Definition: Demangle.h:35
char * getFunctionBaseName(char *Buf, size_t *N) const
Get the base name of a function.
bool partialDemangle(const char *MangledName)
Demangle into an AST.
char * getFunctionDeclContextName(char *Buf, size_t *N) const
Get the context name for a function.
std::string demangle(const std::string &MangledName)
Attempt to demangle a string using different demangling schemes.
Definition: Demangle.cpp:22
char * getFunctionParameters(char *Buf, size_t *N) const
Get the parameters for this function.
char * getFunctionReturnType(char *Buf, size_t *N) const
bool isSpecialName() const
If this symbol is a <special-name>.
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.
#define N
"Partial" demangler.
Definition: Demangle.h:56
char * microsoftDemangle(const char *mangled_name, char *buf, size_t *n, int *status, MSDemangleFlags Flags=MSDF_None)