blob: 6fea7ef13f11d8d298d9054a042581bdf50bb8ec [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===--- Demangle.h ---------------------------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8
Andrew Scullcdfcccc2018-10-05 20:58:37 +01009#ifndef LLVM_DEMANGLE_DEMANGLE_H
10#define LLVM_DEMANGLE_DEMANGLE_H
11
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010012#include <cstddef>
Andrew Walbran16937d02019-10-22 13:54:20 +010013#include <string>
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010014
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///
Andrew Scullcdfcccc2018-10-05 20:58:37 +010022/// The *status will be set to a value from the following enumeration
23enum : int {
24 demangle_unknown_error = -4,
25 demangle_invalid_args = -3,
26 demangle_invalid_mangled_name = -2,
27 demangle_memory_alloc_failure = -1,
28 demangle_success = 0,
29};
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010030
31char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
32 int *status);
Andrew Scullcdfcccc2018-10-05 20:58:37 +010033
Andrew Scull0372a572018-11-16 15:47:06 +000034
Andrew Scullcdfcccc2018-10-05 20:58:37 +010035enum MSDemangleFlags { MSDF_None = 0, MSDF_DumpBackrefs = 1 << 0 };
36char *microsoftDemangle(const char *mangled_name, char *buf, size_t *n,
37 int *status, MSDemangleFlags Flags = MSDF_None);
38
Andrew Walbran16937d02019-10-22 13:54:20 +010039/// Attempt to demangle a string using different demangling schemes.
40/// The function uses heuristics to determine which demangling scheme to use.
41/// \param MangledName - reference to string to demangle.
42/// \returns - the demangled string, or a copy of the input string if no
43/// demangling occurred.
44std::string demangle(const std::string &MangledName);
45
Andrew Scullcdfcccc2018-10-05 20:58:37 +010046/// "Partial" demangler. This supports demangling a string into an AST
47/// (typically an intermediate stage in itaniumDemangle) and querying certain
48/// properties or partially printing the demangled name.
49struct ItaniumPartialDemangler {
50 ItaniumPartialDemangler();
51
52 ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
53 ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other);
54
55 /// Demangle into an AST. Subsequent calls to the rest of the member functions
56 /// implicitly operate on the AST this produces.
57 /// \return true on error, false otherwise
58 bool partialDemangle(const char *MangledName);
59
60 /// Just print the entire mangled name into Buf. Buf and N behave like the
61 /// second and third parameters to itaniumDemangle.
62 char *finishDemangle(char *Buf, size_t *N) const;
63
64 /// Get the base name of a function. This doesn't include trailing template
65 /// arguments, ie for "a::b<int>" this function returns "b".
66 char *getFunctionBaseName(char *Buf, size_t *N) const;
67
68 /// Get the context name for a function. For "a::b::c", this function returns
69 /// "a::b".
70 char *getFunctionDeclContextName(char *Buf, size_t *N) const;
71
72 /// Get the entire name of this function.
73 char *getFunctionName(char *Buf, size_t *N) const;
74
75 /// Get the parameters for this function.
76 char *getFunctionParameters(char *Buf, size_t *N) const;
77 char *getFunctionReturnType(char *Buf, size_t *N) const;
78
79 /// If this function has any any cv or reference qualifiers. These imply that
80 /// the function is a non-static member function.
81 bool hasFunctionQualifiers() const;
82
83 /// If this symbol describes a constructor or destructor.
84 bool isCtorOrDtor() const;
85
86 /// If this symbol describes a function.
87 bool isFunction() const;
88
89 /// If this symbol describes a variable.
90 bool isData() const;
91
92 /// If this symbol is a <special-name>. These are generally implicitly
93 /// generated by the implementation, such as vtables and typeinfo names.
94 bool isSpecialName() const;
95
96 ~ItaniumPartialDemangler();
97private:
98 void *RootNode;
99 void *Context;
100};
101} // namespace llvm
102
103#endif