Lines 224-285
void TypeSystemMap::ForEach(std::function<bool(TypeSystem *)> const &callback) {
Link Here
|
224 |
llvm::Expected<TypeSystem &> TypeSystemMap::GetTypeSystemForLanguage( |
224 |
llvm::Expected<TypeSystem &> TypeSystemMap::GetTypeSystemForLanguage( |
225 |
lldb::LanguageType language, |
225 |
lldb::LanguageType language, |
226 |
llvm::Optional<CreateCallback> create_callback) { |
226 |
llvm::Optional<CreateCallback> create_callback) { |
227 |
llvm::Error error = llvm::Error::success(); |
|
|
228 |
assert(!error); // Check the success value when assertions are enabled |
229 |
std::lock_guard<std::mutex> guard(m_mutex); |
227 |
std::lock_guard<std::mutex> guard(m_mutex); |
230 |
if (m_clear_in_progress) { |
228 |
if (m_clear_in_progress) |
231 |
error = llvm::make_error<llvm::StringError>( |
229 |
return llvm::make_error<llvm::StringError>( |
232 |
"Unable to get TypeSystem because TypeSystemMap is being cleared", |
230 |
"Unable to get TypeSystem because TypeSystemMap is being cleared", |
233 |
llvm::inconvertibleErrorCode()); |
231 |
llvm::inconvertibleErrorCode()); |
234 |
} else { |
|
|
235 |
collection::iterator pos = m_map.find(language); |
236 |
if (pos != m_map.end()) { |
237 |
auto *type_system = pos->second.get(); |
238 |
if (type_system) { |
239 |
llvm::consumeError(std::move(error)); |
240 |
return *type_system; |
241 |
} |
242 |
error = llvm::make_error<llvm::StringError>( |
243 |
"TypeSystem for language " + |
244 |
llvm::StringRef(Language::GetNameForLanguageType(language)) + |
245 |
" doesn't exist", |
246 |
llvm::inconvertibleErrorCode()); |
247 |
return std::move(error); |
248 |
} |
249 |
|
232 |
|
250 |
for (const auto &pair : m_map) { |
233 |
collection::iterator pos = m_map.find(language); |
251 |
if (pair.second && pair.second->SupportsLanguage(language)) { |
234 |
if (pos != m_map.end()) { |
252 |
// Add a new mapping for "language" to point to an already existing |
235 |
auto *type_system = pos->second.get(); |
253 |
// TypeSystem that supports this language |
236 |
if (type_system) |
254 |
m_map[language] = pair.second; |
237 |
return *type_system; |
255 |
if (pair.second.get()) { |
238 |
return llvm::make_error<llvm::StringError>( |
256 |
llvm::consumeError(std::move(error)); |
239 |
"TypeSystem for language " + |
257 |
return *pair.second.get(); |
240 |
llvm::StringRef(Language::GetNameForLanguageType(language)) + |
258 |
} |
241 |
" doesn't exist", |
259 |
error = llvm::make_error<llvm::StringError>( |
242 |
llvm::inconvertibleErrorCode()); |
260 |
"TypeSystem for language " + |
243 |
} |
261 |
llvm::StringRef(Language::GetNameForLanguageType(language)) + |
|
|
262 |
" doesn't exist", |
263 |
llvm::inconvertibleErrorCode()); |
264 |
return std::move(error); |
265 |
} |
266 |
} |
267 |
|
244 |
|
268 |
if (!create_callback) { |
245 |
for (const auto &pair : m_map) { |
269 |
error = llvm::make_error<llvm::StringError>( |
246 |
if (pair.second && pair.second->SupportsLanguage(language)) { |
270 |
"Unable to find type system for language " + |
247 |
// Add a new mapping for "language" to point to an already existing |
271 |
llvm::StringRef(Language::GetNameForLanguageType(language)), |
248 |
// TypeSystem that supports this language |
272 |
llvm::inconvertibleErrorCode()); |
249 |
m_map[language] = pair.second; |
273 |
} else { |
250 |
if (pair.second.get()) |
274 |
// Cache even if we get a shared pointer that contains a null type system |
251 |
return *pair.second.get(); |
275 |
// back |
252 |
return llvm::make_error<llvm::StringError>( |
276 |
TypeSystemSP type_system_sp = (*create_callback)(); |
|
|
277 |
m_map[language] = type_system_sp; |
278 |
if (type_system_sp.get()) { |
279 |
llvm::consumeError(std::move(error)); |
280 |
return *type_system_sp.get(); |
281 |
} |
282 |
error = llvm::make_error<llvm::StringError>( |
283 |
"TypeSystem for language " + |
253 |
"TypeSystem for language " + |
284 |
llvm::StringRef(Language::GetNameForLanguageType(language)) + |
254 |
llvm::StringRef(Language::GetNameForLanguageType(language)) + |
285 |
" doesn't exist", |
255 |
" doesn't exist", |
Lines 287-293
llvm::Expected<TypeSystem &> TypeSystemMap::GetTypeSystemForLanguage(
Link Here
|
287 |
} |
257 |
} |
288 |
} |
258 |
} |
289 |
|
259 |
|
290 |
return std::move(error); |
260 |
if (!create_callback) |
|
|
261 |
return llvm::make_error<llvm::StringError>( |
262 |
"Unable to find type system for language " + |
263 |
llvm::StringRef(Language::GetNameForLanguageType(language)), |
264 |
llvm::inconvertibleErrorCode()); |
265 |
|
266 |
// Cache even if we get a shared pointer that contains a null type system |
267 |
// back |
268 |
TypeSystemSP type_system_sp = (*create_callback)(); |
269 |
m_map[language] = type_system_sp; |
270 |
if (type_system_sp.get()) |
271 |
return *type_system_sp.get(); |
272 |
return llvm::make_error<llvm::StringError>( |
273 |
"TypeSystem for language " + |
274 |
llvm::StringRef(Language::GetNameForLanguageType(language)) + |
275 |
" doesn't exist", |
276 |
llvm::inconvertibleErrorCode()); |
291 |
} |
277 |
} |
292 |
|
278 |
|
293 |
llvm::Expected<TypeSystem &> |
279 |
llvm::Expected<TypeSystem &> |