Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:45

0001 //===-- RichManglingContext.h -----------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_CORE_RICHMANGLINGCONTEXT_H
0010 #define LLDB_CORE_RICHMANGLINGCONTEXT_H
0011 
0012 #include "lldb/lldb-forward.h"
0013 #include "lldb/lldb-private.h"
0014 
0015 #include "lldb/Utility/ConstString.h"
0016 
0017 #include "llvm/ADT/Any.h"
0018 #include "llvm/ADT/SmallString.h"
0019 #include "llvm/Demangle/Demangle.h"
0020 
0021 namespace lldb_private {
0022 
0023 /// Uniform wrapper for access to rich mangling information from different
0024 /// providers. See Mangled::DemangleWithRichManglingInfo()
0025 class RichManglingContext {
0026 public:
0027   RichManglingContext() {
0028     m_ipd_buf = static_cast<char *>(std::malloc(m_ipd_buf_size));
0029     m_ipd_buf[0] = '\0';
0030   }
0031 
0032   ~RichManglingContext();
0033 
0034   /// Use the ItaniumPartialDemangler to obtain rich mangling information from
0035   /// the given mangled name.
0036   bool FromItaniumName(ConstString mangled);
0037 
0038   /// Use the legacy language parser implementation to obtain rich mangling
0039   /// information from the given demangled name.
0040   bool FromCxxMethodName(ConstString demangled);
0041 
0042   /// If this symbol describes a constructor or destructor.
0043   bool IsCtorOrDtor() const;
0044 
0045   /// Get the base name of a function. This doesn't include trailing template
0046   /// arguments, ie "a::b<int>" gives "b".
0047   llvm::StringRef ParseFunctionBaseName();
0048 
0049   /// Get the context name for a function. For "a::b::c", this function returns
0050   /// "a::b".
0051   llvm::StringRef ParseFunctionDeclContextName();
0052 
0053   /// Get the entire demangled name.
0054   llvm::StringRef ParseFullName();
0055 
0056 private:
0057   enum InfoProvider { None, ItaniumPartialDemangler, PluginCxxLanguage };
0058 
0059   /// Selects the rich mangling info provider.
0060   InfoProvider m_provider = None;
0061 
0062   /// Members for ItaniumPartialDemangler
0063   llvm::ItaniumPartialDemangler m_ipd;
0064   /// Note: m_ipd_buf is a raw pointer due to being resized by realloc via
0065   /// ItaniumPartialDemangler. It should be managed with malloc/free, not
0066   /// new/delete.
0067   char *m_ipd_buf;
0068   size_t m_ipd_buf_size = 2048;
0069 
0070   /// Members for PluginCxxLanguage
0071   /// Cannot forward declare inner class CPlusPlusLanguage::MethodName. The
0072   /// respective header is in Plugins and including it from here causes cyclic
0073   /// dependency. Instead keep a llvm::Any and cast it on-access in the cpp.
0074   llvm::Any m_cxx_method_parser;
0075 
0076   /// Clean up memory when using PluginCxxLanguage
0077   void ResetCxxMethodParser();
0078 
0079   /// Clean up memory and set a new info provider for this instance.
0080   void ResetProvider(InfoProvider new_provider);
0081 
0082   /// Uniform handling of string buffers for ItaniumPartialDemangler.
0083   llvm::StringRef processIPDStrResult(char *ipd_res, size_t res_len);
0084 
0085   /// Cast the given parser to the given type. Ideally we would have a type
0086   /// trait to deduce \a ParserT from a given InfoProvider, but unfortunately we
0087   /// can't access CPlusPlusLanguage::MethodName from within the header.
0088   template <class ParserT> static ParserT *get(llvm::Any parser) {
0089     assert(parser.has_value());
0090     assert(llvm::any_cast<ParserT *>(&parser));
0091     return *llvm::any_cast<ParserT *>(&parser);
0092   }
0093 };
0094 
0095 } // namespace lldb_private
0096 
0097 #endif