blob: b9b4d158e2ae7a39cc6b0e93ed9cca9088b4bd92 [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
Andrew Scull0372a572018-11-16 15:47:06 +000034/// Calls the callback \c Callback with \c Ctx as an argument whenever a type is
35/// encountered. Returns true if \c MangledName couldn't be parsed.
36bool itaniumFindTypesInMangledName(const char *MangledName, void *Ctx,
37 void (*Callback)(void *, const char *));
38
39
Andrew Scullcdfcccc2018-10-05 20:58:37 +010040enum MSDemangleFlags { MSDF_None = 0, MSDF_DumpBackrefs = 1 << 0 };
41char *microsoftDemangle(const char *mangled_name, char *buf, size_t *n,
42 int *status, MSDemangleFlags Flags = MSDF_None);
43
44/// "Partial" demangler. This supports demangling a string into an AST
45/// (typically an intermediate stage in itaniumDemangle) and querying certain
46/// properties or partially printing the demangled name.
47struct ItaniumPartialDemangler {
48 ItaniumPartialDemangler();
49
50 ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
51 ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other);
52
53 /// Demangle into an AST. Subsequent calls to the rest of the member functions
54 /// implicitly operate on the AST this produces.
55 /// \return true on error, false otherwise
56 bool partialDemangle(const char *MangledName);
57
58 /// Just print the entire mangled name into Buf. Buf and N behave like the
59 /// second and third parameters to itaniumDemangle.
60 char *finishDemangle(char *Buf, size_t *N) const;
61
62 /// Get the base name of a function. This doesn't include trailing template
63 /// arguments, ie for "a::b<int>" this function returns "b".
64 char *getFunctionBaseName(char *Buf, size_t *N) const;
65
66 /// Get the context name for a function. For "a::b::c", this function returns
67 /// "a::b".
68 char *getFunctionDeclContextName(char *Buf, size_t *N) const;
69
70 /// Get the entire name of this function.
71 char *getFunctionName(char *Buf, size_t *N) const;
72
73 /// Get the parameters for this function.
74 char *getFunctionParameters(char *Buf, size_t *N) const;
75 char *getFunctionReturnType(char *Buf, size_t *N) const;
76
77 /// If this function has any any cv or reference qualifiers. These imply that
78 /// the function is a non-static member function.
79 bool hasFunctionQualifiers() const;
80
81 /// If this symbol describes a constructor or destructor.
82 bool isCtorOrDtor() const;
83
84 /// If this symbol describes a function.
85 bool isFunction() const;
86
87 /// If this symbol describes a variable.
88 bool isData() const;
89
90 /// If this symbol is a <special-name>. These are generally implicitly
91 /// generated by the implementation, such as vtables and typeinfo names.
92 bool isSpecialName() const;
93
94 ~ItaniumPartialDemangler();
95private:
96 void *RootNode;
97 void *Context;
98};
99} // namespace llvm
100
101#endif