1 //===-- CPlusPlusLanguage.h -------------------------------------*- C++ -*-===//
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-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_CPlusPlusLanguage_h_
10 #define liblldb_CPlusPlusLanguage_h_
15 #include "llvm/ADT/StringRef.h"
17 #include "Plugins/Language/ClangCommon/ClangHighlighter.h"
18 #include "lldb/Target/Language.h"
19 #include "lldb/Utility/ConstString.h"
20 #include "lldb/lldb-private.h"
22 namespace lldb_private {
24 class CPlusPlusLanguage : public Language {
25 ClangHighlighter m_highlighter;
31 : m_full(), m_basename(), m_context(), m_arguments(), m_qualifiers(),
32 m_parsed(false), m_parse_error(false) {}
34 MethodName(ConstString s)
35 : m_full(s), m_basename(), m_context(), m_arguments(), m_qualifiers(),
36 m_parsed(false), m_parse_error(false) {}
48 ConstString GetFullName() const { return m_full; }
50 std::string GetScopeQualifiedName();
52 llvm::StringRef GetBasename();
54 llvm::StringRef GetContext();
56 llvm::StringRef GetArguments();
58 llvm::StringRef GetQualifiers();
62 bool TrySimplifiedParse();
64 ConstString m_full; // Full name:
65 // "lldb::SBTarget::GetBreakpointAtIndex(unsigned int)
67 llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
68 llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
69 llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
70 llvm::StringRef m_qualifiers; // Qualifiers: "const"
75 CPlusPlusLanguage() = default;
77 ~CPlusPlusLanguage() override = default;
79 lldb::LanguageType GetLanguageType() const override {
80 return lldb::eLanguageTypeC_plus_plus;
83 std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
84 lldb::TypeCategoryImplSP GetFormatters() override;
86 HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override;
88 HardcodedFormatters::HardcodedSyntheticFinder
89 GetHardcodedSynthetics() override;
91 bool IsSourceFile(llvm::StringRef file_path) const override;
93 const Highlighter *GetHighlighter() const override { return &m_highlighter; }
96 static void Initialize();
98 static void Terminate();
100 static lldb_private::Language *CreateInstance(lldb::LanguageType language);
102 static lldb_private::ConstString GetPluginNameStatic();
104 static bool IsCPPMangledName(const char *name);
106 // Extract C++ context and identifier from a string using heuristic matching
108 // CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name
109 // with parens and arguments.
110 // If the name is a lone C identifier (e.g. C) or a qualified C identifier
111 // (e.g. A::B::C) it will return true,
112 // and identifier will be the identifier (C and C respectively) and the
113 // context will be "" and "A::B" respectively.
114 // If the name fails the heuristic matching for a qualified or unqualified
115 // C/C++ identifier, then it will return false
116 // and identifier and context will be unchanged.
118 static bool ExtractContextAndIdentifier(const char *name,
119 llvm::StringRef &context,
120 llvm::StringRef &identifier);
122 // Given a mangled function name, calculates some alternative manglings since
123 // the compiler mangling may not line up with the symbol we are expecting
125 FindAlternateFunctionManglings(const ConstString mangled,
126 std::set<ConstString> &candidates);
128 // PluginInterface protocol
129 ConstString GetPluginName() override;
131 uint32_t GetPluginVersion() override;
134 } // namespace lldb_private
136 #endif // liblldb_CPlusPlusLanguage_h_