Demangle.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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-FileCopyrightText: Part of the LLVM Project
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef LLVM_DEMANGLE_DEMANGLE_H
  10. #define LLVM_DEMANGLE_DEMANGLE_H
  11. #include <cstddef>
  12. #include <string>
  13. namespace llvm {
  14. /// This is a llvm local version of __cxa_demangle. Other than the name and
  15. /// being in the llvm namespace it is identical.
  16. ///
  17. /// The mangled_name is demangled into buf and returned. If the buffer is not
  18. /// large enough, realloc is used to expand it.
  19. ///
  20. /// The *status will be set to a value from the following enumeration
  21. enum : int {
  22. demangle_unknown_error = -4,
  23. demangle_invalid_args = -3,
  24. demangle_invalid_mangled_name = -2,
  25. demangle_memory_alloc_failure = -1,
  26. demangle_success = 0,
  27. };
  28. char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
  29. int *status);
  30. enum MSDemangleFlags {
  31. MSDF_None = 0,
  32. MSDF_DumpBackrefs = 1 << 0,
  33. MSDF_NoAccessSpecifier = 1 << 1,
  34. MSDF_NoCallingConvention = 1 << 2,
  35. MSDF_NoReturnType = 1 << 3,
  36. MSDF_NoMemberType = 1 << 4,
  37. };
  38. char *microsoftDemangle(const char *mangled_name, char *buf, size_t *n,
  39. int *status, MSDemangleFlags Flags = MSDF_None);
  40. /// "Partial" demangler. This supports demangling a string into an AST
  41. /// (typically an intermediate stage in itaniumDemangle) and querying certain
  42. /// properties or partially printing the demangled name.
  43. struct ItaniumPartialDemangler {
  44. ItaniumPartialDemangler();
  45. ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
  46. ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other);
  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. /// Just print the entire mangled name into Buf. Buf and N behave like the
  52. /// second and third parameters to itaniumDemangle.
  53. char *finishDemangle(char *Buf, size_t *N) const;
  54. /// Get the base name of a function. This doesn't include trailing template
  55. /// arguments, ie for "a::b<int>" this function returns "b".
  56. char *getFunctionBaseName(char *Buf, size_t *N) const;
  57. /// Get the context name for a function. For "a::b::c", this function returns
  58. /// "a::b".
  59. char *getFunctionDeclContextName(char *Buf, size_t *N) const;
  60. /// Get the entire name of this function.
  61. char *getFunctionName(char *Buf, size_t *N) const;
  62. /// Get the parameters for this function.
  63. char *getFunctionParameters(char *Buf, size_t *N) const;
  64. char *getFunctionReturnType(char *Buf, size_t *N) const;
  65. /// If this function has any any cv or reference qualifiers. These imply that
  66. /// the function is a non-static member function.
  67. bool hasFunctionQualifiers() const;
  68. /// If this symbol describes a constructor or destructor.
  69. bool isCtorOrDtor() const;
  70. /// If this symbol describes a function.
  71. bool isFunction() const;
  72. /// If this symbol describes a variable.
  73. bool isData() const;
  74. /// If this symbol is a <special-name>. These are generally implicitly
  75. /// generated by the implementation, such as vtables and typeinfo names.
  76. bool isSpecialName() const;
  77. ~ItaniumPartialDemangler();
  78. private:
  79. void *RootNode;
  80. void *Context;
  81. };
  82. } // namespace llvm
  83. #endif