1 //===--- Demangle.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEMANGLE_DEMANGLE_H
11 #define LLVM_DEMANGLE_DEMANGLE_H
16 /// This is a llvm local version of __cxa_demangle. Other than the name and
17 /// being in the llvm namespace it is identical.
19 /// The mangled_name is demangled into buf and returned. If the buffer is not
20 /// large enough, realloc is used to expand it.
22 /// The *status will be set to a value from the following enumeration
24 demangle_unknown_error = -4,
25 demangle_invalid_args = -3,
26 demangle_invalid_mangled_name = -2,
27 demangle_memory_alloc_failure = -1,
31 char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
35 enum MSDemangleFlags { MSDF_None = 0, MSDF_DumpBackrefs = 1 << 0 };
36 char *microsoftDemangle(const char *mangled_name, char *buf, size_t *n,
37 int *status, MSDemangleFlags Flags = MSDF_None);
39 /// "Partial" demangler. This supports demangling a string into an AST
40 /// (typically an intermediate stage in itaniumDemangle) and querying certain
41 /// properties or partially printing the demangled name.
42 struct ItaniumPartialDemangler {
43 ItaniumPartialDemangler();
45 ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
46 ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other);
48 /// Demangle into an AST. Subsequent calls to the rest of the member functions
49 /// implicitly operate on the AST this produces.
50 /// \return true on error, false otherwise
51 bool partialDemangle(const char *MangledName);
53 /// Just print the entire mangled name into Buf. Buf and N behave like the
54 /// second and third parameters to itaniumDemangle.
55 char *finishDemangle(char *Buf, size_t *N) const;
57 /// Get the base name of a function. This doesn't include trailing template
58 /// arguments, ie for "a::b<int>" this function returns "b".
59 char *getFunctionBaseName(char *Buf, size_t *N) const;
61 /// Get the context name for a function. For "a::b::c", this function returns
63 char *getFunctionDeclContextName(char *Buf, size_t *N) const;
65 /// Get the entire name of this function.
66 char *getFunctionName(char *Buf, size_t *N) const;
68 /// Get the parameters for this function.
69 char *getFunctionParameters(char *Buf, size_t *N) const;
70 char *getFunctionReturnType(char *Buf, size_t *N) const;
72 /// If this function has any any cv or reference qualifiers. These imply that
73 /// the function is a non-static member function.
74 bool hasFunctionQualifiers() const;
76 /// If this symbol describes a constructor or destructor.
77 bool isCtorOrDtor() const;
79 /// If this symbol describes a function.
80 bool isFunction() const;
82 /// If this symbol describes a variable.
85 /// If this symbol is a <special-name>. These are generally implicitly
86 /// generated by the implementation, such as vtables and typeinfo names.
87 bool isSpecialName() const;
89 ~ItaniumPartialDemangler();