LLDB  mainline
CPlusPlusLanguage.h
Go to the documentation of this file.
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 
18 #include "lldb/Target/Language.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:
32  m_parsed(false), m_parse_error(false) {}
33 
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;
73  };
74 
75  CPlusPlusLanguage() = default;
76 
77  ~CPlusPlusLanguage() override = default;
78 
81  }
82 
83  std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
84  lldb::TypeCategoryImplSP GetFormatters() override;
85 
87 
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 
101 
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
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_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
std::unique_ptr< TypeScavenger > GetTypeScavenger() override
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
Definition: FormatClasses.h:42
~CPlusPlusLanguage() override=default
static lldb_private::Language * CreateInstance(lldb::LanguageType language)
ConstString GetPluginName() override
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
Definition: FormatClasses.h:41
static bool IsCPPMangledName(const char *name)
LanguageType
Programming language type.
static lldb_private::ConstString GetPluginNameStatic()
HardcodedFormatters::HardcodedSyntheticFinder GetHardcodedSynthetics() override
static bool ExtractContextAndIdentifier(const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
static uint32_t FindAlternateFunctionManglings(const ConstString mangled, std::set< ConstString > &candidates)
lldb::LanguageType GetLanguageType() const override
lldb::TypeCategoryImplSP GetFormatters() override
Annotates source code with color attributes.
Definition: Highlighter.h:92
HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override
const Highlighter * GetHighlighter() const override
A uniqued constant string class.
Definition: ConstString.h:38
bool IsSourceFile(llvm::StringRef file_path) const override