View | Details | Raw Unified | Return to bug 253881 | Differences between
and this patch

Collapse All | Expand All

(-)b/contrib/llvm-project/lldb/source/Symbol/TypeSystem.cpp (-104 / +76 lines)
Lines 227-288 void TypeSystemMap::ForEach(std::function<bool(TypeSystem *)> const &callback) { Link Here
227
llvm::Expected<TypeSystem &>
227
llvm::Expected<TypeSystem &>
228
TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language,
228
TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language,
229
                                        Module *module, bool can_create) {
229
                                        Module *module, bool can_create) {
230
  llvm::Error error = llvm::Error::success();
231
  assert(!error); // Check the success value when assertions are enabled
232
  std::lock_guard<std::mutex> guard(m_mutex);
230
  std::lock_guard<std::mutex> guard(m_mutex);
233
  if (m_clear_in_progress) {
231
  if (m_clear_in_progress)
234
    error = llvm::make_error<llvm::StringError>(
232
    return llvm::make_error<llvm::StringError>(
235
        "Unable to get TypeSystem because TypeSystemMap is being cleared",
233
        "Unable to get TypeSystem because TypeSystemMap is being cleared",
236
        llvm::inconvertibleErrorCode());
234
        llvm::inconvertibleErrorCode());
237
  } else {
238
    collection::iterator pos = m_map.find(language);
239
    if (pos != m_map.end()) {
240
      auto *type_system = pos->second.get();
241
      if (type_system) {
242
        llvm::consumeError(std::move(error));
243
        return *type_system;
244
      }
245
      error = llvm::make_error<llvm::StringError>(
246
          "TypeSystem for language " +
247
              llvm::StringRef(Language::GetNameForLanguageType(language)) +
248
              " doesn't exist",
249
          llvm::inconvertibleErrorCode());
250
      return std::move(error);
251
    }
252
235
253
    for (const auto &pair : m_map) {
236
  collection::iterator pos = m_map.find(language);
254
      if (pair.second && pair.second->SupportsLanguage(language)) {
237
  if (pos != m_map.end()) {
255
        // Add a new mapping for "language" to point to an already existing
238
    auto *type_system = pos->second.get();
256
        // TypeSystem that supports this language
239
    if (type_system)
257
        m_map[language] = pair.second;
240
      return *type_system;
258
        if (pair.second.get()) {
241
    return llvm::make_error<llvm::StringError>(
259
          llvm::consumeError(std::move(error));
242
        "TypeSystem for language " +
260
          return *pair.second.get();
243
            llvm::StringRef(Language::GetNameForLanguageType(language)) +
261
        }
244
            " doesn't exist",
262
        error = llvm::make_error<llvm::StringError>(
245
        llvm::inconvertibleErrorCode());
263
            "TypeSystem for language " +
246
  }
264
                llvm::StringRef(Language::GetNameForLanguageType(language)) +
265
                " doesn't exist",
266
            llvm::inconvertibleErrorCode());
267
        return std::move(error);
268
      }
269
    }
270
247
271
    if (!can_create) {
248
  for (const auto &pair : m_map) {
272
      error = llvm::make_error<llvm::StringError>(
249
    if (pair.second && pair.second->SupportsLanguage(language)) {
273
          "Unable to find type system for language " +
250
      // Add a new mapping for "language" to point to an already existing
274
              llvm::StringRef(Language::GetNameForLanguageType(language)),
251
      // TypeSystem that supports this language
275
          llvm::inconvertibleErrorCode());
252
      m_map[language] = pair.second;
276
    } else {
253
      if (pair.second.get())
277
      // Cache even if we get a shared pointer that contains a null type system
254
        return *pair.second.get();
278
      // back
255
      return llvm::make_error<llvm::StringError>(
279
      auto type_system_sp = TypeSystem::CreateInstance(language, module);
280
      m_map[language] = type_system_sp;
281
      if (type_system_sp.get()) {
282
        llvm::consumeError(std::move(error));
283
        return *type_system_sp.get();
284
      }
285
      error = llvm::make_error<llvm::StringError>(
286
          "TypeSystem for language " +
256
          "TypeSystem for language " +
287
              llvm::StringRef(Language::GetNameForLanguageType(language)) +
257
              llvm::StringRef(Language::GetNameForLanguageType(language)) +
288
              " doesn't exist",
258
              " doesn't exist",
Lines 290-357 TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language, Link Here
290
    }
260
    }
291
  }
261
  }
292
262
293
  return std::move(error);
263
  if (!can_create)
264
    return llvm::make_error<llvm::StringError>(
265
        "Unable to find type system for language " +
266
            llvm::StringRef(Language::GetNameForLanguageType(language)),
267
        llvm::inconvertibleErrorCode());
268
269
  // Cache even if we get a shared pointer that contains a null type system
270
  // back
271
  auto type_system_sp = TypeSystem::CreateInstance(language, module);
272
  m_map[language] = type_system_sp;
273
  if (type_system_sp.get())
274
    return *type_system_sp.get();
275
  return llvm::make_error<llvm::StringError>(
276
      "TypeSystem for language " +
277
          llvm::StringRef(Language::GetNameForLanguageType(language)) +
278
          " doesn't exist",
279
      llvm::inconvertibleErrorCode());
294
}
280
}
295
281
296
llvm::Expected<TypeSystem &>
282
llvm::Expected<TypeSystem &>
297
TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language,
283
TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language,
298
                                        Target *target, bool can_create) {
284
                                        Target *target, bool can_create) {
299
  llvm::Error error = llvm::Error::success();
300
  assert(!error); // Check the success value when assertions are enabled
301
  std::lock_guard<std::mutex> guard(m_mutex);
285
  std::lock_guard<std::mutex> guard(m_mutex);
302
  if (m_clear_in_progress) {
286
  if (m_clear_in_progress)
303
    error = llvm::make_error<llvm::StringError>(
287
    return llvm::make_error<llvm::StringError>(
304
        "Unable to get TypeSystem because TypeSystemMap is being cleared",
288
        "Unable to get TypeSystem because TypeSystemMap is being cleared",
305
        llvm::inconvertibleErrorCode());
289
        llvm::inconvertibleErrorCode());
306
  } else {
307
    collection::iterator pos = m_map.find(language);
308
    if (pos != m_map.end()) {
309
      auto *type_system = pos->second.get();
310
      if (type_system) {
311
        llvm::consumeError(std::move(error));
312
        return *type_system;
313
      }
314
      error = llvm::make_error<llvm::StringError>(
315
          "TypeSystem for language " +
316
              llvm::StringRef(Language::GetNameForLanguageType(language)) +
317
              " doesn't exist",
318
          llvm::inconvertibleErrorCode());
319
      return std::move(error);
320
    }
321
290
322
    for (const auto &pair : m_map) {
291
  collection::iterator pos = m_map.find(language);
323
      if (pair.second && pair.second->SupportsLanguage(language)) {
292
  if (pos != m_map.end()) {
324
        // Add a new mapping for "language" to point to an already existing
293
    auto *type_system = pos->second.get();
325
        // TypeSystem that supports this language
294
    if (type_system)
326
        m_map[language] = pair.second;
295
      return *type_system;
327
        if (pair.second.get()) {
296
    return llvm::make_error<llvm::StringError>(
328
          llvm::consumeError(std::move(error));
297
        "TypeSystem for language " +
329
          return *pair.second.get();
298
            llvm::StringRef(Language::GetNameForLanguageType(language)) +
330
        }
299
            " doesn't exist",
331
        error = llvm::make_error<llvm::StringError>(
300
        llvm::inconvertibleErrorCode());
332
            "TypeSystem for language " +
301
  }
333
                llvm::StringRef(Language::GetNameForLanguageType(language)) +
334
                " doesn't exist",
335
            llvm::inconvertibleErrorCode());
336
        return std::move(error);
337
      }
338
    }
339
302
340
    if (!can_create) {
303
  for (const auto &pair : m_map) {
341
      error = llvm::make_error<llvm::StringError>(
304
    if (pair.second && pair.second->SupportsLanguage(language)) {
342
          "Unable to find type system for language " +
305
      // Add a new mapping for "language" to point to an already existing
343
              llvm::StringRef(Language::GetNameForLanguageType(language)),
306
      // TypeSystem that supports this language
344
          llvm::inconvertibleErrorCode());
307
      m_map[language] = pair.second;
345
    } else {
308
      if (pair.second.get())
346
      // Cache even if we get a shared pointer that contains a null type system
309
        return *pair.second.get();
347
      // back
310
      return llvm::make_error<llvm::StringError>(
348
      auto type_system_sp = TypeSystem::CreateInstance(language, target);
349
      m_map[language] = type_system_sp;
350
      if (type_system_sp.get()) {
351
        llvm::consumeError(std::move(error));
352
        return *type_system_sp.get();
353
      }
354
      error = llvm::make_error<llvm::StringError>(
355
          "TypeSystem for language " +
311
          "TypeSystem for language " +
356
              llvm::StringRef(Language::GetNameForLanguageType(language)) +
312
              llvm::StringRef(Language::GetNameForLanguageType(language)) +
357
              " doesn't exist",
313
              " doesn't exist",
Lines 359-363 TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language, Link Here
359
    }
315
    }
360
  }
316
  }
361
317
362
  return std::move(error);
318
  if (!can_create)
319
    return llvm::make_error<llvm::StringError>(
320
        "Unable to find type system for language " +
321
            llvm::StringRef(Language::GetNameForLanguageType(language)),
322
        llvm::inconvertibleErrorCode());
323
324
  // Cache even if we get a shared pointer that contains a null type system
325
  // back
326
  auto type_system_sp = TypeSystem::CreateInstance(language, target);
327
  m_map[language] = type_system_sp;
328
  if (type_system_sp.get())
329
    return *type_system_sp.get();
330
  return llvm::make_error<llvm::StringError>(
331
      "TypeSystem for language " +
332
          llvm::StringRef(Language::GetNameForLanguageType(language)) +
333
          " doesn't exist",
334
      llvm::inconvertibleErrorCode());
363
}
335
}

Return to bug 253881