blob: b118631fbcf63ba39b753e134e2675324f467b0f [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===--- Demangle.h ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Andrew Scullcdfcccc2018-10-05 20:58:37 +010010#ifndef LLVM_DEMANGLE_DEMANGLE_H
11#define LLVM_DEMANGLE_DEMANGLE_H
12
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010013#include <cstddef>
14
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
34enum MSDemangleFlags { MSDF_None = 0, MSDF_DumpBackrefs = 1 << 0 };
35char *microsoftDemangle(const char *mangled_name, char *buf, size_t *n,
36 int *status, MSDemangleFlags Flags = MSDF_None);
37
38/// "Partial" demangler. This supports demangling a string into an AST
39/// (typically an intermediate stage in itaniumDemangle) and querying certain
40/// properties or partially printing the demangled name.
41struct ItaniumPartialDemangler {
42 ItaniumPartialDemangler();
43
44 ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
45 ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other);
46
47 /// Demangle into an AST. Subsequent calls to the rest of the member functions
48 /// implicitly operate on the AST this produces.
49 /// \return true on error, false otherwise
50 bool partialDemangle(const char *MangledName);
51
52 /// Just print the entire mangled name into Buf. Buf and N behave like the
53 /// second and third parameters to itaniumDemangle.
54 char *finishDemangle(char *Buf, size_t *N) const;
55
56 /// Get the base name of a function. This doesn't include trailing template
57 /// arguments, ie for "a::b<int>" this function returns "b".
58 char *getFunctionBaseName(char *Buf, size_t *N) const;
59
60 /// Get the context name for a function. For "a::b::c", this function returns
61 /// "a::b".
62 char *getFunctionDeclContextName(char *Buf, size_t *N) const;
63
64 /// Get the entire name of this function.
65 char *getFunctionName(char *Buf, size_t *N) const;
66
67 /// Get the parameters for this function.
68 char *getFunctionParameters(char *Buf, size_t *N) const;
69 char *getFunctionReturnType(char *Buf, size_t *N) const;
70
71 /// If this function has any any cv or reference qualifiers. These imply that
72 /// the function is a non-static member function.
73 bool hasFunctionQualifiers() const;
74
75 /// If this symbol describes a constructor or destructor.
76 bool isCtorOrDtor() const;
77
78 /// If this symbol describes a function.
79 bool isFunction() const;
80
81 /// If this symbol describes a variable.
82 bool isData() const;
83
84 /// If this symbol is a <special-name>. These are generally implicitly
85 /// generated by the implementation, such as vtables and typeinfo names.
86 bool isSpecialName() const;
87
88 ~ItaniumPartialDemangler();
89private:
90 void *RootNode;
91 void *Context;
92};
93} // namespace llvm
94
95#endif