annotate lldb/source/Target/Language.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1f2b6ac9f198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===-- Language.cpp ------------------------------------------------------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #include <functional>
anatofuz
parents:
diff changeset
10 #include <map>
anatofuz
parents:
diff changeset
11 #include <mutex>
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 #include "lldb/Target/Language.h"
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 #include "lldb/Core/PluginManager.h"
anatofuz
parents:
diff changeset
16 #include "lldb/Symbol/SymbolFile.h"
anatofuz
parents:
diff changeset
17 #include "lldb/Symbol/TypeList.h"
anatofuz
parents:
diff changeset
18 #include "lldb/Target/Target.h"
anatofuz
parents:
diff changeset
19 #include "lldb/Utility/Stream.h"
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 #include "llvm/Support/Threading.h"
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 using namespace lldb;
anatofuz
parents:
diff changeset
24 using namespace lldb_private;
anatofuz
parents:
diff changeset
25 using namespace lldb_private::formatters;
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 typedef std::unique_ptr<Language> LanguageUP;
anatofuz
parents:
diff changeset
28 typedef std::map<lldb::LanguageType, LanguageUP> LanguagesMap;
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 static LanguagesMap &GetLanguagesMap() {
anatofuz
parents:
diff changeset
31 static LanguagesMap *g_map = nullptr;
anatofuz
parents:
diff changeset
32 static llvm::once_flag g_initialize;
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 llvm::call_once(g_initialize, [] {
anatofuz
parents:
diff changeset
35 g_map = new LanguagesMap(); // NOTE: INTENTIONAL LEAK due to global
anatofuz
parents:
diff changeset
36 // destructor chain
anatofuz
parents:
diff changeset
37 });
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 return *g_map;
anatofuz
parents:
diff changeset
40 }
anatofuz
parents:
diff changeset
41 static std::mutex &GetLanguagesMutex() {
anatofuz
parents:
diff changeset
42 static std::mutex *g_mutex = nullptr;
anatofuz
parents:
diff changeset
43 static llvm::once_flag g_initialize;
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 llvm::call_once(g_initialize, [] {
anatofuz
parents:
diff changeset
46 g_mutex = new std::mutex(); // NOTE: INTENTIONAL LEAK due to global
anatofuz
parents:
diff changeset
47 // destructor chain
anatofuz
parents:
diff changeset
48 });
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 return *g_mutex;
anatofuz
parents:
diff changeset
51 }
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 Language *Language::FindPlugin(lldb::LanguageType language) {
anatofuz
parents:
diff changeset
54 std::lock_guard<std::mutex> guard(GetLanguagesMutex());
anatofuz
parents:
diff changeset
55 LanguagesMap &map(GetLanguagesMap());
anatofuz
parents:
diff changeset
56 auto iter = map.find(language), end = map.end();
anatofuz
parents:
diff changeset
57 if (iter != end)
anatofuz
parents:
diff changeset
58 return iter->second.get();
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 Language *language_ptr = nullptr;
anatofuz
parents:
diff changeset
61 LanguageCreateInstance create_callback;
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 for (uint32_t idx = 0;
anatofuz
parents:
diff changeset
64 (create_callback =
anatofuz
parents:
diff changeset
65 PluginManager::GetLanguageCreateCallbackAtIndex(idx)) != nullptr;
anatofuz
parents:
diff changeset
66 ++idx) {
anatofuz
parents:
diff changeset
67 language_ptr = create_callback(language);
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69 if (language_ptr) {
anatofuz
parents:
diff changeset
70 map[language] = std::unique_ptr<Language>(language_ptr);
anatofuz
parents:
diff changeset
71 return language_ptr;
anatofuz
parents:
diff changeset
72 }
anatofuz
parents:
diff changeset
73 }
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 return nullptr;
anatofuz
parents:
diff changeset
76 }
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 Language *Language::FindPlugin(llvm::StringRef file_path) {
anatofuz
parents:
diff changeset
79 Language *result = nullptr;
anatofuz
parents:
diff changeset
80 ForEach([&result, file_path](Language *language) {
anatofuz
parents:
diff changeset
81 if (language->IsSourceFile(file_path)) {
anatofuz
parents:
diff changeset
82 result = language;
anatofuz
parents:
diff changeset
83 return false;
anatofuz
parents:
diff changeset
84 }
anatofuz
parents:
diff changeset
85 return true;
anatofuz
parents:
diff changeset
86 });
anatofuz
parents:
diff changeset
87 return result;
anatofuz
parents:
diff changeset
88 }
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 Language *Language::FindPlugin(LanguageType language,
anatofuz
parents:
diff changeset
91 llvm::StringRef file_path) {
anatofuz
parents:
diff changeset
92 Language *result = FindPlugin(language);
anatofuz
parents:
diff changeset
93 // Finding a language by file path is slower, we so we use this as the
anatofuz
parents:
diff changeset
94 // fallback.
anatofuz
parents:
diff changeset
95 if (!result)
anatofuz
parents:
diff changeset
96 result = FindPlugin(file_path);
anatofuz
parents:
diff changeset
97 return result;
anatofuz
parents:
diff changeset
98 }
anatofuz
parents:
diff changeset
99
anatofuz
parents:
diff changeset
100 void Language::ForEach(std::function<bool(Language *)> callback) {
anatofuz
parents:
diff changeset
101 // If we want to iterate over all languages, we first have to complete the
anatofuz
parents:
diff changeset
102 // LanguagesMap.
anatofuz
parents:
diff changeset
103 static llvm::once_flag g_initialize;
anatofuz
parents:
diff changeset
104 llvm::call_once(g_initialize, [] {
anatofuz
parents:
diff changeset
105 for (unsigned lang = eLanguageTypeUnknown; lang < eNumLanguageTypes;
anatofuz
parents:
diff changeset
106 ++lang) {
anatofuz
parents:
diff changeset
107 FindPlugin(static_cast<lldb::LanguageType>(lang));
anatofuz
parents:
diff changeset
108 }
anatofuz
parents:
diff changeset
109 });
anatofuz
parents:
diff changeset
110
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
111 // callback may call a method in Language that attempts to acquire the same
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
112 // lock (such as Language::ForEach or Language::FindPlugin). To avoid a
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
113 // deadlock, we do not use callback while holding the lock.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
114 std::vector<Language *> loaded_plugins;
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
115 {
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
116 std::lock_guard<std::mutex> guard(GetLanguagesMutex());
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
117 LanguagesMap &map(GetLanguagesMap());
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
118 for (const auto &entry : map) {
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
119 if (entry.second)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
120 loaded_plugins.push_back(entry.second.get());
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
121 }
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
122 }
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
123
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
124 for (auto *lang : loaded_plugins) {
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
125 if (!callback(lang))
150
anatofuz
parents:
diff changeset
126 break;
anatofuz
parents:
diff changeset
127 }
anatofuz
parents:
diff changeset
128 }
anatofuz
parents:
diff changeset
129
anatofuz
parents:
diff changeset
130 bool Language::IsTopLevelFunction(Function &function) { return false; }
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 lldb::TypeCategoryImplSP Language::GetFormatters() { return nullptr; }
anatofuz
parents:
diff changeset
133
anatofuz
parents:
diff changeset
134 HardcodedFormatters::HardcodedFormatFinder Language::GetHardcodedFormats() {
anatofuz
parents:
diff changeset
135 return {};
anatofuz
parents:
diff changeset
136 }
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
138 HardcodedFormatters::HardcodedSummaryFinder Language::GetHardcodedSummaries() {
anatofuz
parents:
diff changeset
139 return {};
anatofuz
parents:
diff changeset
140 }
anatofuz
parents:
diff changeset
141
anatofuz
parents:
diff changeset
142 HardcodedFormatters::HardcodedSyntheticFinder
anatofuz
parents:
diff changeset
143 Language::GetHardcodedSynthetics() {
anatofuz
parents:
diff changeset
144 return {};
anatofuz
parents:
diff changeset
145 }
anatofuz
parents:
diff changeset
146
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
147 std::vector<FormattersMatchCandidate>
150
anatofuz
parents:
diff changeset
148 Language::GetPossibleFormattersMatches(ValueObject &valobj,
anatofuz
parents:
diff changeset
149 lldb::DynamicValueType use_dynamic) {
anatofuz
parents:
diff changeset
150 return {};
anatofuz
parents:
diff changeset
151 }
anatofuz
parents:
diff changeset
152
anatofuz
parents:
diff changeset
153 struct language_name_pair {
anatofuz
parents:
diff changeset
154 const char *name;
anatofuz
parents:
diff changeset
155 LanguageType type;
anatofuz
parents:
diff changeset
156 };
anatofuz
parents:
diff changeset
157
anatofuz
parents:
diff changeset
158 struct language_name_pair language_names[] = {
anatofuz
parents:
diff changeset
159 // To allow GetNameForLanguageType to be a simple array lookup, the first
anatofuz
parents:
diff changeset
160 // part of this array must follow enum LanguageType exactly.
anatofuz
parents:
diff changeset
161 {"unknown", eLanguageTypeUnknown},
anatofuz
parents:
diff changeset
162 {"c89", eLanguageTypeC89},
anatofuz
parents:
diff changeset
163 {"c", eLanguageTypeC},
anatofuz
parents:
diff changeset
164 {"ada83", eLanguageTypeAda83},
anatofuz
parents:
diff changeset
165 {"c++", eLanguageTypeC_plus_plus},
anatofuz
parents:
diff changeset
166 {"cobol74", eLanguageTypeCobol74},
anatofuz
parents:
diff changeset
167 {"cobol85", eLanguageTypeCobol85},
anatofuz
parents:
diff changeset
168 {"fortran77", eLanguageTypeFortran77},
anatofuz
parents:
diff changeset
169 {"fortran90", eLanguageTypeFortran90},
anatofuz
parents:
diff changeset
170 {"pascal83", eLanguageTypePascal83},
anatofuz
parents:
diff changeset
171 {"modula2", eLanguageTypeModula2},
anatofuz
parents:
diff changeset
172 {"java", eLanguageTypeJava},
anatofuz
parents:
diff changeset
173 {"c99", eLanguageTypeC99},
anatofuz
parents:
diff changeset
174 {"ada95", eLanguageTypeAda95},
anatofuz
parents:
diff changeset
175 {"fortran95", eLanguageTypeFortran95},
anatofuz
parents:
diff changeset
176 {"pli", eLanguageTypePLI},
anatofuz
parents:
diff changeset
177 {"objective-c", eLanguageTypeObjC},
anatofuz
parents:
diff changeset
178 {"objective-c++", eLanguageTypeObjC_plus_plus},
anatofuz
parents:
diff changeset
179 {"upc", eLanguageTypeUPC},
anatofuz
parents:
diff changeset
180 {"d", eLanguageTypeD},
anatofuz
parents:
diff changeset
181 {"python", eLanguageTypePython},
anatofuz
parents:
diff changeset
182 {"opencl", eLanguageTypeOpenCL},
anatofuz
parents:
diff changeset
183 {"go", eLanguageTypeGo},
anatofuz
parents:
diff changeset
184 {"modula3", eLanguageTypeModula3},
anatofuz
parents:
diff changeset
185 {"haskell", eLanguageTypeHaskell},
anatofuz
parents:
diff changeset
186 {"c++03", eLanguageTypeC_plus_plus_03},
anatofuz
parents:
diff changeset
187 {"c++11", eLanguageTypeC_plus_plus_11},
anatofuz
parents:
diff changeset
188 {"ocaml", eLanguageTypeOCaml},
anatofuz
parents:
diff changeset
189 {"rust", eLanguageTypeRust},
anatofuz
parents:
diff changeset
190 {"c11", eLanguageTypeC11},
anatofuz
parents:
diff changeset
191 {"swift", eLanguageTypeSwift},
anatofuz
parents:
diff changeset
192 {"julia", eLanguageTypeJulia},
anatofuz
parents:
diff changeset
193 {"dylan", eLanguageTypeDylan},
anatofuz
parents:
diff changeset
194 {"c++14", eLanguageTypeC_plus_plus_14},
anatofuz
parents:
diff changeset
195 {"fortran03", eLanguageTypeFortran03},
anatofuz
parents:
diff changeset
196 {"fortran08", eLanguageTypeFortran08},
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
197 {"renderscript", eLanguageTypeRenderScript},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
198 {"bliss", eLanguageTypeBLISS},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
199 {"kotlin", eLanguageTypeKotlin},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
200 {"zig", eLanguageTypeZig},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
201 {"crystal", eLanguageTypeCrystal},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
202 {"<invalid language>",
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
203 static_cast<LanguageType>(
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
204 0x0029)}, // Not yet taken by any language in the DWARF spec
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
205 // and thus has no entry in LanguageType
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
206 {"c++17", eLanguageTypeC_plus_plus_17},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
207 {"c++20", eLanguageTypeC_plus_plus_20},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
208 {"c17", eLanguageTypeC17},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
209 {"fortran18", eLanguageTypeFortran18},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
210 {"ada2005", eLanguageTypeAda2005},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
211 {"ada2012", eLanguageTypeAda2012},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
212 {"HIP", eLanguageTypeHIP},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
213 {"assembly", eLanguageTypeAssembly},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
214 {"c-sharp", eLanguageTypeC_sharp},
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
215 {"mojo", eLanguageTypeMojo},
150
anatofuz
parents:
diff changeset
216 // Vendor Extensions
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
217 {"assembler", eLanguageTypeMipsAssembler},
150
anatofuz
parents:
diff changeset
218 // Now synonyms, in arbitrary order
anatofuz
parents:
diff changeset
219 {"objc", eLanguageTypeObjC},
anatofuz
parents:
diff changeset
220 {"objc++", eLanguageTypeObjC_plus_plus},
anatofuz
parents:
diff changeset
221 {"pascal", eLanguageTypePascal83}};
anatofuz
parents:
diff changeset
222
anatofuz
parents:
diff changeset
223 static uint32_t num_languages =
anatofuz
parents:
diff changeset
224 sizeof(language_names) / sizeof(struct language_name_pair);
anatofuz
parents:
diff changeset
225
anatofuz
parents:
diff changeset
226 LanguageType Language::GetLanguageTypeFromString(llvm::StringRef string) {
anatofuz
parents:
diff changeset
227 for (const auto &L : language_names) {
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
228 if (string.equals_insensitive(L.name))
150
anatofuz
parents:
diff changeset
229 return static_cast<LanguageType>(L.type);
anatofuz
parents:
diff changeset
230 }
anatofuz
parents:
diff changeset
231
anatofuz
parents:
diff changeset
232 return eLanguageTypeUnknown;
anatofuz
parents:
diff changeset
233 }
anatofuz
parents:
diff changeset
234
anatofuz
parents:
diff changeset
235 const char *Language::GetNameForLanguageType(LanguageType language) {
anatofuz
parents:
diff changeset
236 if (language < num_languages)
anatofuz
parents:
diff changeset
237 return language_names[language].name;
anatofuz
parents:
diff changeset
238 else
anatofuz
parents:
diff changeset
239 return language_names[eLanguageTypeUnknown].name;
anatofuz
parents:
diff changeset
240 }
anatofuz
parents:
diff changeset
241
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
242 void Language::PrintSupportedLanguagesForExpressions(Stream &s,
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
243 llvm::StringRef prefix,
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
244 llvm::StringRef suffix) {
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
245 auto supported = Language::GetLanguagesSupportingTypeSystemsForExpressions();
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
246 for (size_t idx = 0; idx < num_languages; ++idx) {
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
247 auto const &lang = language_names[idx];
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
248 if (supported[lang.type])
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
249 s << prefix << lang.name << suffix;
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
250 }
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
251 }
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
252
150
anatofuz
parents:
diff changeset
253 void Language::PrintAllLanguages(Stream &s, const char *prefix,
anatofuz
parents:
diff changeset
254 const char *suffix) {
anatofuz
parents:
diff changeset
255 for (uint32_t i = 1; i < num_languages; i++) {
anatofuz
parents:
diff changeset
256 s.Printf("%s%s%s", prefix, language_names[i].name, suffix);
anatofuz
parents:
diff changeset
257 }
anatofuz
parents:
diff changeset
258 }
anatofuz
parents:
diff changeset
259
anatofuz
parents:
diff changeset
260 void Language::ForAllLanguages(
anatofuz
parents:
diff changeset
261 std::function<bool(lldb::LanguageType)> callback) {
anatofuz
parents:
diff changeset
262 for (uint32_t i = 1; i < num_languages; i++) {
anatofuz
parents:
diff changeset
263 if (!callback(language_names[i].type))
anatofuz
parents:
diff changeset
264 break;
anatofuz
parents:
diff changeset
265 }
anatofuz
parents:
diff changeset
266 }
anatofuz
parents:
diff changeset
267
anatofuz
parents:
diff changeset
268 bool Language::LanguageIsCPlusPlus(LanguageType language) {
anatofuz
parents:
diff changeset
269 switch (language) {
anatofuz
parents:
diff changeset
270 case eLanguageTypeC_plus_plus:
anatofuz
parents:
diff changeset
271 case eLanguageTypeC_plus_plus_03:
anatofuz
parents:
diff changeset
272 case eLanguageTypeC_plus_plus_11:
anatofuz
parents:
diff changeset
273 case eLanguageTypeC_plus_plus_14:
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
274 case eLanguageTypeC_plus_plus_17:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
275 case eLanguageTypeC_plus_plus_20:
150
anatofuz
parents:
diff changeset
276 case eLanguageTypeObjC_plus_plus:
anatofuz
parents:
diff changeset
277 return true;
anatofuz
parents:
diff changeset
278 default:
anatofuz
parents:
diff changeset
279 return false;
anatofuz
parents:
diff changeset
280 }
anatofuz
parents:
diff changeset
281 }
anatofuz
parents:
diff changeset
282
anatofuz
parents:
diff changeset
283 bool Language::LanguageIsObjC(LanguageType language) {
anatofuz
parents:
diff changeset
284 switch (language) {
anatofuz
parents:
diff changeset
285 case eLanguageTypeObjC:
anatofuz
parents:
diff changeset
286 case eLanguageTypeObjC_plus_plus:
anatofuz
parents:
diff changeset
287 return true;
anatofuz
parents:
diff changeset
288 default:
anatofuz
parents:
diff changeset
289 return false;
anatofuz
parents:
diff changeset
290 }
anatofuz
parents:
diff changeset
291 }
anatofuz
parents:
diff changeset
292
anatofuz
parents:
diff changeset
293 bool Language::LanguageIsC(LanguageType language) {
anatofuz
parents:
diff changeset
294 switch (language) {
anatofuz
parents:
diff changeset
295 case eLanguageTypeC:
anatofuz
parents:
diff changeset
296 case eLanguageTypeC89:
anatofuz
parents:
diff changeset
297 case eLanguageTypeC99:
anatofuz
parents:
diff changeset
298 case eLanguageTypeC11:
anatofuz
parents:
diff changeset
299 return true;
anatofuz
parents:
diff changeset
300 default:
anatofuz
parents:
diff changeset
301 return false;
anatofuz
parents:
diff changeset
302 }
anatofuz
parents:
diff changeset
303 }
anatofuz
parents:
diff changeset
304
anatofuz
parents:
diff changeset
305 bool Language::LanguageIsCFamily(LanguageType language) {
anatofuz
parents:
diff changeset
306 switch (language) {
anatofuz
parents:
diff changeset
307 case eLanguageTypeC:
anatofuz
parents:
diff changeset
308 case eLanguageTypeC89:
anatofuz
parents:
diff changeset
309 case eLanguageTypeC99:
anatofuz
parents:
diff changeset
310 case eLanguageTypeC11:
anatofuz
parents:
diff changeset
311 case eLanguageTypeC_plus_plus:
anatofuz
parents:
diff changeset
312 case eLanguageTypeC_plus_plus_03:
anatofuz
parents:
diff changeset
313 case eLanguageTypeC_plus_plus_11:
anatofuz
parents:
diff changeset
314 case eLanguageTypeC_plus_plus_14:
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
315 case eLanguageTypeC_plus_plus_17:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
316 case eLanguageTypeC_plus_plus_20:
150
anatofuz
parents:
diff changeset
317 case eLanguageTypeObjC_plus_plus:
anatofuz
parents:
diff changeset
318 case eLanguageTypeObjC:
anatofuz
parents:
diff changeset
319 return true;
anatofuz
parents:
diff changeset
320 default:
anatofuz
parents:
diff changeset
321 return false;
anatofuz
parents:
diff changeset
322 }
anatofuz
parents:
diff changeset
323 }
anatofuz
parents:
diff changeset
324
anatofuz
parents:
diff changeset
325 bool Language::LanguageIsPascal(LanguageType language) {
anatofuz
parents:
diff changeset
326 switch (language) {
anatofuz
parents:
diff changeset
327 case eLanguageTypePascal83:
anatofuz
parents:
diff changeset
328 return true;
anatofuz
parents:
diff changeset
329 default:
anatofuz
parents:
diff changeset
330 return false;
anatofuz
parents:
diff changeset
331 }
anatofuz
parents:
diff changeset
332 }
anatofuz
parents:
diff changeset
333
anatofuz
parents:
diff changeset
334 LanguageType Language::GetPrimaryLanguage(LanguageType language) {
anatofuz
parents:
diff changeset
335 switch (language) {
anatofuz
parents:
diff changeset
336 case eLanguageTypeC_plus_plus:
anatofuz
parents:
diff changeset
337 case eLanguageTypeC_plus_plus_03:
anatofuz
parents:
diff changeset
338 case eLanguageTypeC_plus_plus_11:
anatofuz
parents:
diff changeset
339 case eLanguageTypeC_plus_plus_14:
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
340 case eLanguageTypeC_plus_plus_17:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
341 case eLanguageTypeC_plus_plus_20:
150
anatofuz
parents:
diff changeset
342 return eLanguageTypeC_plus_plus;
anatofuz
parents:
diff changeset
343 case eLanguageTypeC:
anatofuz
parents:
diff changeset
344 case eLanguageTypeC89:
anatofuz
parents:
diff changeset
345 case eLanguageTypeC99:
anatofuz
parents:
diff changeset
346 case eLanguageTypeC11:
anatofuz
parents:
diff changeset
347 return eLanguageTypeC;
anatofuz
parents:
diff changeset
348 case eLanguageTypeObjC:
anatofuz
parents:
diff changeset
349 case eLanguageTypeObjC_plus_plus:
anatofuz
parents:
diff changeset
350 return eLanguageTypeObjC;
anatofuz
parents:
diff changeset
351 case eLanguageTypePascal83:
anatofuz
parents:
diff changeset
352 case eLanguageTypeCobol74:
anatofuz
parents:
diff changeset
353 case eLanguageTypeCobol85:
anatofuz
parents:
diff changeset
354 case eLanguageTypeFortran77:
anatofuz
parents:
diff changeset
355 case eLanguageTypeFortran90:
anatofuz
parents:
diff changeset
356 case eLanguageTypeFortran95:
anatofuz
parents:
diff changeset
357 case eLanguageTypeFortran03:
anatofuz
parents:
diff changeset
358 case eLanguageTypeFortran08:
anatofuz
parents:
diff changeset
359 case eLanguageTypeAda83:
anatofuz
parents:
diff changeset
360 case eLanguageTypeAda95:
anatofuz
parents:
diff changeset
361 case eLanguageTypeModula2:
anatofuz
parents:
diff changeset
362 case eLanguageTypeJava:
anatofuz
parents:
diff changeset
363 case eLanguageTypePLI:
anatofuz
parents:
diff changeset
364 case eLanguageTypeUPC:
anatofuz
parents:
diff changeset
365 case eLanguageTypeD:
anatofuz
parents:
diff changeset
366 case eLanguageTypePython:
anatofuz
parents:
diff changeset
367 case eLanguageTypeOpenCL:
anatofuz
parents:
diff changeset
368 case eLanguageTypeGo:
anatofuz
parents:
diff changeset
369 case eLanguageTypeModula3:
anatofuz
parents:
diff changeset
370 case eLanguageTypeHaskell:
anatofuz
parents:
diff changeset
371 case eLanguageTypeOCaml:
anatofuz
parents:
diff changeset
372 case eLanguageTypeRust:
anatofuz
parents:
diff changeset
373 case eLanguageTypeSwift:
anatofuz
parents:
diff changeset
374 case eLanguageTypeJulia:
anatofuz
parents:
diff changeset
375 case eLanguageTypeDylan:
anatofuz
parents:
diff changeset
376 case eLanguageTypeMipsAssembler:
anatofuz
parents:
diff changeset
377 case eLanguageTypeUnknown:
anatofuz
parents:
diff changeset
378 default:
anatofuz
parents:
diff changeset
379 return language;
anatofuz
parents:
diff changeset
380 }
anatofuz
parents:
diff changeset
381 }
anatofuz
parents:
diff changeset
382
anatofuz
parents:
diff changeset
383 std::set<lldb::LanguageType> Language::GetSupportedLanguages() {
anatofuz
parents:
diff changeset
384 std::set<lldb::LanguageType> supported_languages;
anatofuz
parents:
diff changeset
385 ForEach([&](Language *lang) {
anatofuz
parents:
diff changeset
386 supported_languages.emplace(lang->GetLanguageType());
anatofuz
parents:
diff changeset
387 return true;
anatofuz
parents:
diff changeset
388 });
anatofuz
parents:
diff changeset
389 return supported_languages;
anatofuz
parents:
diff changeset
390 }
anatofuz
parents:
diff changeset
391
anatofuz
parents:
diff changeset
392 LanguageSet Language::GetLanguagesSupportingTypeSystems() {
anatofuz
parents:
diff changeset
393 return PluginManager::GetAllTypeSystemSupportedLanguagesForTypes();
anatofuz
parents:
diff changeset
394 }
anatofuz
parents:
diff changeset
395
anatofuz
parents:
diff changeset
396 LanguageSet Language::GetLanguagesSupportingTypeSystemsForExpressions() {
anatofuz
parents:
diff changeset
397 return PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions();
anatofuz
parents:
diff changeset
398 }
anatofuz
parents:
diff changeset
399
anatofuz
parents:
diff changeset
400 LanguageSet Language::GetLanguagesSupportingREPLs() {
anatofuz
parents:
diff changeset
401 return PluginManager::GetREPLAllTypeSystemSupportedLanguages();
anatofuz
parents:
diff changeset
402 }
anatofuz
parents:
diff changeset
403
anatofuz
parents:
diff changeset
404 std::unique_ptr<Language::TypeScavenger> Language::GetTypeScavenger() {
anatofuz
parents:
diff changeset
405 return nullptr;
anatofuz
parents:
diff changeset
406 }
anatofuz
parents:
diff changeset
407
anatofuz
parents:
diff changeset
408 const char *Language::GetLanguageSpecificTypeLookupHelp() { return nullptr; }
anatofuz
parents:
diff changeset
409
anatofuz
parents:
diff changeset
410 size_t Language::TypeScavenger::Find(ExecutionContextScope *exe_scope,
anatofuz
parents:
diff changeset
411 const char *key, ResultSet &results,
anatofuz
parents:
diff changeset
412 bool append) {
anatofuz
parents:
diff changeset
413 if (!exe_scope || !exe_scope->CalculateTarget().get())
anatofuz
parents:
diff changeset
414 return false;
anatofuz
parents:
diff changeset
415
anatofuz
parents:
diff changeset
416 if (!key || !key[0])
anatofuz
parents:
diff changeset
417 return false;
anatofuz
parents:
diff changeset
418
anatofuz
parents:
diff changeset
419 if (!append)
anatofuz
parents:
diff changeset
420 results.clear();
anatofuz
parents:
diff changeset
421
anatofuz
parents:
diff changeset
422 size_t old_size = results.size();
anatofuz
parents:
diff changeset
423
anatofuz
parents:
diff changeset
424 if (this->Find_Impl(exe_scope, key, results))
anatofuz
parents:
diff changeset
425 return results.size() - old_size;
anatofuz
parents:
diff changeset
426 return 0;
anatofuz
parents:
diff changeset
427 }
anatofuz
parents:
diff changeset
428
anatofuz
parents:
diff changeset
429 bool Language::ImageListTypeScavenger::Find_Impl(
anatofuz
parents:
diff changeset
430 ExecutionContextScope *exe_scope, const char *key, ResultSet &results) {
anatofuz
parents:
diff changeset
431 bool result = false;
anatofuz
parents:
diff changeset
432
anatofuz
parents:
diff changeset
433 Target *target = exe_scope->CalculateTarget().get();
anatofuz
parents:
diff changeset
434 if (target) {
anatofuz
parents:
diff changeset
435 const auto &images(target->GetImages());
anatofuz
parents:
diff changeset
436 ConstString cs_key(key);
anatofuz
parents:
diff changeset
437 llvm::DenseSet<SymbolFile *> searched_sym_files;
anatofuz
parents:
diff changeset
438 TypeList matches;
anatofuz
parents:
diff changeset
439 images.FindTypes(nullptr, cs_key, false, UINT32_MAX, searched_sym_files,
anatofuz
parents:
diff changeset
440 matches);
anatofuz
parents:
diff changeset
441 for (const auto &match : matches.Types()) {
anatofuz
parents:
diff changeset
442 if (match) {
anatofuz
parents:
diff changeset
443 CompilerType compiler_type(match->GetFullCompilerType());
anatofuz
parents:
diff changeset
444 compiler_type = AdjustForInclusion(compiler_type);
anatofuz
parents:
diff changeset
445 if (!compiler_type)
anatofuz
parents:
diff changeset
446 continue;
anatofuz
parents:
diff changeset
447 std::unique_ptr<Language::TypeScavenger::Result> scavengeresult(
anatofuz
parents:
diff changeset
448 new Result(compiler_type));
anatofuz
parents:
diff changeset
449 results.insert(std::move(scavengeresult));
anatofuz
parents:
diff changeset
450 result = true;
anatofuz
parents:
diff changeset
451 }
anatofuz
parents:
diff changeset
452 }
anatofuz
parents:
diff changeset
453 }
anatofuz
parents:
diff changeset
454
anatofuz
parents:
diff changeset
455 return result;
anatofuz
parents:
diff changeset
456 }
anatofuz
parents:
diff changeset
457
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
458 std::pair<llvm::StringRef, llvm::StringRef>
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
459 Language::GetFormatterPrefixSuffix(llvm::StringRef type_hint) {
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
460 return std::pair<llvm::StringRef, llvm::StringRef>();
150
anatofuz
parents:
diff changeset
461 }
anatofuz
parents:
diff changeset
462
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
463 bool Language::DemangledNameContainsPath(llvm::StringRef path,
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
464 ConstString demangled) const {
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
465 // The base implementation does a simple contains comparision:
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
466 if (path.empty())
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
467 return false;
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
468 return demangled.GetStringRef().contains(path);
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
469 }
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
470
150
anatofuz
parents:
diff changeset
471 DumpValueObjectOptions::DeclPrintingHelper Language::GetDeclPrintingHelper() {
anatofuz
parents:
diff changeset
472 return nullptr;
anatofuz
parents:
diff changeset
473 }
anatofuz
parents:
diff changeset
474
anatofuz
parents:
diff changeset
475 LazyBool Language::IsLogicalTrue(ValueObject &valobj, Status &error) {
anatofuz
parents:
diff changeset
476 return eLazyBoolCalculate;
anatofuz
parents:
diff changeset
477 }
anatofuz
parents:
diff changeset
478
anatofuz
parents:
diff changeset
479 bool Language::IsNilReference(ValueObject &valobj) { return false; }
anatofuz
parents:
diff changeset
480
anatofuz
parents:
diff changeset
481 bool Language::IsUninitializedReference(ValueObject &valobj) { return false; }
anatofuz
parents:
diff changeset
482
anatofuz
parents:
diff changeset
483 bool Language::GetFunctionDisplayName(const SymbolContext *sc,
anatofuz
parents:
diff changeset
484 const ExecutionContext *exe_ctx,
anatofuz
parents:
diff changeset
485 FunctionNameRepresentation representation,
anatofuz
parents:
diff changeset
486 Stream &s) {
anatofuz
parents:
diff changeset
487 return false;
anatofuz
parents:
diff changeset
488 }
anatofuz
parents:
diff changeset
489
anatofuz
parents:
diff changeset
490 void Language::GetExceptionResolverDescription(bool catch_on, bool throw_on,
anatofuz
parents:
diff changeset
491 Stream &s) {
anatofuz
parents:
diff changeset
492 GetDefaultExceptionResolverDescription(catch_on, throw_on, s);
anatofuz
parents:
diff changeset
493 }
anatofuz
parents:
diff changeset
494
anatofuz
parents:
diff changeset
495 void Language::GetDefaultExceptionResolverDescription(bool catch_on,
anatofuz
parents:
diff changeset
496 bool throw_on,
anatofuz
parents:
diff changeset
497 Stream &s) {
anatofuz
parents:
diff changeset
498 s.Printf("Exception breakpoint (catch: %s throw: %s)",
anatofuz
parents:
diff changeset
499 catch_on ? "on" : "off", throw_on ? "on" : "off");
anatofuz
parents:
diff changeset
500 }
anatofuz
parents:
diff changeset
501 // Constructor
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
502 Language::Language() = default;
150
anatofuz
parents:
diff changeset
503
anatofuz
parents:
diff changeset
504 // Destructor
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
505 Language::~Language() = default;