blob: ec2681af75953d705efec47d59fe03a5c3a51074 [file] [log] [blame]
Enrico Granata5f9d3102015-08-27 21:33:50 +00001//===-- CPlusPlusLanguage.h ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_CPlusPlusLanguage_h_
11#define liblldb_CPlusPlusLanguage_h_
12
13// C Includes
14// C++ Includes
Jim Inghamaa816b82015-09-02 01:59:14 +000015#include <vector>
16
Enrico Granata5f9d3102015-08-27 21:33:50 +000017// Other libraries and framework includes
Jim Inghamaa816b82015-09-02 01:59:14 +000018#include "llvm/ADT/StringRef.h"
19
Enrico Granata5f9d3102015-08-27 21:33:50 +000020// Project includes
21#include "lldb/lldb-private.h"
Jim Inghamaa816b82015-09-02 01:59:14 +000022#include "lldb/Core/ConstString.h"
Enrico Granata5f9d3102015-08-27 21:33:50 +000023#include "lldb/Target/Language.h"
24
25namespace lldb_private {
26
27class CPlusPlusLanguage :
28 public Language
29{
30public:
Jim Inghamaa816b82015-09-02 01:59:14 +000031 class MethodName
32 {
33 public:
34 enum Type
35 {
36 eTypeInvalid,
37 eTypeUnknownMethod,
38 eTypeClassMethod,
39 eTypeInstanceMethod
40 };
41
42 MethodName () :
43 m_full(),
44 m_basename(),
45 m_context(),
46 m_arguments(),
47 m_qualifiers(),
48 m_type (eTypeInvalid),
49 m_parsed (false),
50 m_parse_error (false)
51 {
52 }
53
54 MethodName (const ConstString &s) :
55 m_full(s),
56 m_basename(),
57 m_context(),
58 m_arguments(),
59 m_qualifiers(),
60 m_type (eTypeInvalid),
61 m_parsed (false),
62 m_parse_error (false)
63 {
64 }
65
66 void
67 Clear();
68
69 bool
70 IsValid ()
71 {
72 if (!m_parsed)
73 Parse();
74 if (m_parse_error)
75 return false;
76 if (m_type == eTypeInvalid)
77 return false;
78 return (bool)m_full;
79 }
80
81 Type
82 GetType () const
83 {
84 return m_type;
85 }
86
87 const ConstString &
88 GetFullName () const
89 {
90 return m_full;
91 }
92
93 llvm::StringRef
94 GetBasename ();
95
96 llvm::StringRef
97 GetContext ();
98
99 llvm::StringRef
100 GetArguments ();
101
102 llvm::StringRef
103 GetQualifiers ();
104
105 protected:
106 void
107 Parse();
108
109 ConstString m_full; // Full name: "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) const"
110 llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
111 llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
112 llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
113 llvm::StringRef m_qualifiers; // Qualifiers: "const"
114 Type m_type;
115 bool m_parsed;
116 bool m_parse_error;
117 };
118
Enrico Granata5f9d3102015-08-27 21:33:50 +0000119 virtual ~CPlusPlusLanguage() = default;
120
121 CPlusPlusLanguage () = default;
122
123 lldb::LanguageType
Enrico Granata33e97e62015-09-04 21:01:18 +0000124 GetLanguageType () const override
Enrico Granata5f9d3102015-08-27 21:33:50 +0000125 {
126 return lldb::eLanguageTypeC_plus_plus;
127 }
128
Enrico Granata33e97e62015-09-04 21:01:18 +0000129 lldb::TypeCategoryImplSP
130 GetFormatters () override;
131
Enrico Granata7cb59e12015-09-16 18:28:11 +0000132 HardcodedFormatters::HardcodedSummaryFinder
133 GetHardcodedSummaries () override;
134
135 HardcodedFormatters::HardcodedSyntheticFinder
136 GetHardcodedSynthetics () override;
137
Enrico Granata5f9d3102015-08-27 21:33:50 +0000138 //------------------------------------------------------------------
139 // Static Functions
140 //------------------------------------------------------------------
141 static void
142 Initialize();
143
144 static void
145 Terminate();
146
147 static lldb_private::Language *
148 CreateInstance (lldb::LanguageType language);
149
150 static lldb_private::ConstString
151 GetPluginNameStatic();
Jim Inghamaa816b82015-09-02 01:59:14 +0000152
153 static bool
154 IsCPPMangledName(const char *name);
155
156 // Extract C++ context and identifier from a string using heuristic matching (as opposed to
157 // CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name with parens and arguments.
158 // If the name is a lone C identifier (e.g. C) or a qualified C identifier (e.g. A::B::C) it will return true,
159 // and identifier will be the identifier (C and C respectively) and the context will be "" and "A::B::" respectively.
160 // If the name fails the heuristic matching for a qualified or unqualified C/C++ identifier, then it will return false
161 // and identifier and context will be unchanged.
162
163 static bool
164 ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier);
165
166 // in some cases, compilers will output different names for one same type. when that happens, it might be impossible
167 // to construct SBType objects for a valid type, because the name that is available is not the same as the name that
168 // can be used as a search key in FindTypes(). the equivalents map here is meant to return possible alternative names
169 // for a type through which a search can be conducted. Currently, this is only enabled for C++ but can be extended
170 // to ObjC or other languages if necessary
171 static uint32_t
172 FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents);
173
Enrico Granata5f9d3102015-08-27 21:33:50 +0000174
175 //------------------------------------------------------------------
176 // PluginInterface protocol
177 //------------------------------------------------------------------
178 virtual ConstString
Enrico Granata33e97e62015-09-04 21:01:18 +0000179 GetPluginName() override;
Enrico Granata5f9d3102015-08-27 21:33:50 +0000180
181 virtual uint32_t
Enrico Granata33e97e62015-09-04 21:01:18 +0000182 GetPluginVersion() override;
Enrico Granata5f9d3102015-08-27 21:33:50 +0000183};
184
185} // namespace lldb_private
186
187#endif // liblldb_CPlusPlusLanguage_h_