[lldb][NFC] Remove unnecessary ClangASTImporter checks in ClangASTSource
authorRaphael Isemann <teemperor@gmail.com>
Fri, 31 Jan 2020 12:00:32 +0000 (13:00 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Fri, 31 Jan 2020 12:17:08 +0000 (13:17 +0100)
A ClangASTSource always has a ClangASTImporter. Let's remove these sporadic
checks with a single assert during construction. They were added originally
for the modern-type-lookup mode that didn't use a ClangASTImporter in there.

lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

index 18e1353ee9b2976494a4e3627beec3851c43c936..8fb0f40ea1d3a162159ba3c23d77859b9493fe0b 100644 (file)
@@ -52,8 +52,9 @@ private:
 ClangASTSource::ClangASTSource(const lldb::TargetSP &target,
                                const lldb::ClangASTImporterSP &importer)
     : m_import_in_progress(false), m_lookups_enabled(false), m_target(target),
-      m_ast_context(nullptr), m_active_lexical_decls(), m_active_lookups() {
-  m_ast_importer_sp = importer;
+      m_ast_context(nullptr), m_ast_importer_sp(importer),
+      m_active_lexical_decls(), m_active_lookups() {
+  assert(m_ast_importer_sp && "No ClangASTImporter passed to ClangASTSource?");
 }
 
 void ClangASTSource::InstallASTContext(TypeSystemClang &clang_ast_context) {
@@ -64,9 +65,6 @@ void ClangASTSource::InstallASTContext(TypeSystemClang &clang_ast_context) {
 }
 
 ClangASTSource::~ClangASTSource() {
-  if (!m_ast_importer_sp)
-    return;
-
   m_ast_importer_sp->ForgetDestination(m_ast_context);
 
   if (!m_target)
@@ -216,10 +214,6 @@ void ClangASTSource::CompleteType(TagDecl *tag_decl) {
   m_active_lexical_decls.insert(tag_decl);
   ScopedLexicalDeclEraser eraser(m_active_lexical_decls, tag_decl);
 
-  if (!m_ast_importer_sp) {
-    return;
-  }
-
   if (!m_ast_importer_sp->CompleteTagDecl(tag_decl)) {
     // We couldn't complete the type.  Maybe there's a definition somewhere
     // else that can be completed.
@@ -343,11 +337,6 @@ void ClangASTSource::CompleteType(clang::ObjCInterfaceDecl *interface_decl) {
   LLDB_LOG(log, "      [COID] Before:\n{0}",
            ClangUtil::DumpDecl(interface_decl));
 
-  if (!m_ast_importer_sp) {
-    lldbassert(0 && "No mechanism for completing a type!");
-    return;
-  }
-
   ClangASTImporter::DeclOrigin original = m_ast_importer_sp->GetDeclOrigin(interface_decl);
 
   if (original.Valid()) {
@@ -420,9 +409,6 @@ void ClangASTSource::FindExternalLexicalDecls(
     llvm::function_ref<bool(Decl::Kind)> predicate,
     llvm::SmallVectorImpl<Decl *> &decls) {
 
-  if (!m_ast_importer_sp)
-    return;
-
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
   const Decl *context_decl = dyn_cast<Decl>(decl_context);
@@ -587,8 +573,8 @@ void ClangASTSource::FindExternalVisibleDecls(NameSearchContext &context) {
 
   if (const NamespaceDecl *namespace_context =
           dyn_cast<NamespaceDecl>(context.m_decl_context)) {
-    ClangASTImporter::NamespaceMapSP namespace_map =  m_ast_importer_sp ?
-        m_ast_importer_sp->GetNamespaceMap(namespace_context) : nullptr;
+    ClangASTImporter::NamespaceMapSP namespace_map =
+        m_ast_importer_sp->GetNamespaceMap(namespace_context);
 
     if (log && log->GetVerbose())
       LLDB_LOG(log,
@@ -1791,21 +1777,11 @@ NamespaceDecl *ClangASTSource::AddNamespace(
 }
 
 clang::Decl *ClangASTSource::CopyDecl(Decl *src_decl) {
-  if (m_ast_importer_sp) {
-    return m_ast_importer_sp->CopyDecl(m_ast_context, src_decl);
-  } else {
-    lldbassert(0 && "No mechanism for copying a decl!");
-    return nullptr;
-  }
+  return m_ast_importer_sp->CopyDecl(m_ast_context, src_decl);
 }
 
 ClangASTImporter::DeclOrigin ClangASTSource::GetDeclOrigin(const clang::Decl *decl) {
-  if (m_ast_importer_sp) {
-    return m_ast_importer_sp->GetDeclOrigin(decl);
-  } else {
-    // this can happen early enough that no ExternalASTSource is installed.
-    return ClangASTImporter::DeclOrigin();
-  }
+  return m_ast_importer_sp->GetDeclOrigin(decl);
 }
 
 CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
@@ -1816,15 +1792,8 @@ CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
 
   SetImportInProgress(true);
 
-  QualType copied_qual_type;
-
-  if (m_ast_importer_sp) {
-    copied_qual_type = ClangUtil::GetQualType(
-        m_ast_importer_sp->CopyType(*m_clang_ast_context, src_type));
-  } else {
-    lldbassert(0 && "No mechanism for copying a type!");
-    return CompilerType();
-  }
+  QualType copied_qual_type = ClangUtil::GetQualType(
+      m_ast_importer_sp->CopyType(*m_clang_ast_context, src_type));
 
   SetImportInProgress(false);
 
index c776043f6b36945ff024f323aa6dbc2e8642b3c4..8f4c92e332784fb802f43dd627a7204f7ea9725a 100644 (file)
@@ -181,12 +181,7 @@ TypeFromUser ClangExpressionDeclMap::DeportType(TypeSystemClang &target,
   assert((TypeSystem *)&source == parser_type.GetTypeSystem());
   assert(&source.getASTContext() == m_ast_context);
 
-  if (m_ast_importer_sp) {
-    return TypeFromUser(m_ast_importer_sp->DeportType(target, parser_type));
-  } else {
-    lldbassert(0 && "No mechanism for deporting a type!");
-    return TypeFromUser();
-  }
+  return TypeFromUser(m_ast_importer_sp->DeportType(target, parser_type));
 }
 
 bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl,
@@ -682,9 +677,7 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
     }
 
     ClangASTImporter::NamespaceMapSP namespace_map =
-        m_ast_importer_sp
-            ? m_ast_importer_sp->GetNamespaceMap(namespace_context)
-            : ClangASTImporter::NamespaceMapSP();
+        m_ast_importer_sp->GetNamespaceMap(namespace_context);
 
     if (!namespace_map)
       return;