]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / Plugins / Language / CPlusPlus / CPlusPlusLanguage.h
1 //===-- CPlusPlusLanguage.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-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef liblldb_CPlusPlusLanguage_h_
10 #define liblldb_CPlusPlusLanguage_h_
11
12 #include <set>
13 #include <vector>
14
15 #include "llvm/ADT/StringRef.h"
16
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"
21
22 namespace lldb_private {
23
24 class CPlusPlusLanguage : public Language {
25   ClangHighlighter m_highlighter;
26
27 public:
28   class MethodName {
29   public:
30     MethodName()
31         : m_full(), m_basename(), m_context(), m_arguments(), m_qualifiers(),
32           m_parsed(false), m_parse_error(false) {}
33
34     MethodName(ConstString s)
35         : m_full(s), m_basename(), m_context(), m_arguments(), m_qualifiers(),
36           m_parsed(false), m_parse_error(false) {}
37
38     void Clear();
39
40     bool IsValid() {
41       if (!m_parsed)
42         Parse();
43       if (m_parse_error)
44         return false;
45       return (bool)m_full;
46     }
47
48     ConstString GetFullName() const { return m_full; }
49
50     std::string GetScopeQualifiedName();
51
52     llvm::StringRef GetBasename();
53
54     llvm::StringRef GetContext();
55
56     llvm::StringRef GetArguments();
57
58     llvm::StringRef GetQualifiers();
59
60   protected:
61     void Parse();
62     bool TrySimplifiedParse();
63
64     ConstString m_full; // Full name:
65                         // "lldb::SBTarget::GetBreakpointAtIndex(unsigned int)
66                         // const"
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"
71     bool m_parsed;
72     bool m_parse_error;
73   };
74
75   CPlusPlusLanguage() = default;
76
77   ~CPlusPlusLanguage() override = default;
78
79   lldb::LanguageType GetLanguageType() const override {
80     return lldb::eLanguageTypeC_plus_plus;
81   }
82
83   std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
84   lldb::TypeCategoryImplSP GetFormatters() override;
85
86   HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override;
87
88   HardcodedFormatters::HardcodedSyntheticFinder
89   GetHardcodedSynthetics() override;
90
91   bool IsSourceFile(llvm::StringRef file_path) const override;
92
93   const Highlighter *GetHighlighter() const override { return &m_highlighter; }
94
95   // Static Functions
96   static void Initialize();
97
98   static void Terminate();
99
100   static lldb_private::Language *CreateInstance(lldb::LanguageType language);
101
102   static lldb_private::ConstString GetPluginNameStatic();
103
104   static bool IsCPPMangledName(const char *name);
105
106   // Extract C++ context and identifier from a string using heuristic matching
107   // (as opposed to
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.
117
118   static bool ExtractContextAndIdentifier(const char *name,
119                                           llvm::StringRef &context,
120                                           llvm::StringRef &identifier);
121
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
124   static uint32_t
125   FindAlternateFunctionManglings(const ConstString mangled,
126                                  std::set<ConstString> &candidates);
127
128   // PluginInterface protocol
129   ConstString GetPluginName() override;
130
131   uint32_t GetPluginVersion() override;
132 };
133
134 } // namespace lldb_private
135
136 #endif // liblldb_CPlusPlusLanguage_h_