[Lldb-commits] [lldb] 1ccc702 - [lldb][NFC] Remove unnecessary ClangASTImporter checks in ClangASTSource

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 31 04:17:30 PST 2020


Author: Raphael Isemann
Date: 2020-01-31T13:17:08+01:00
New Revision: 1ccc702912fa9c41a58b9007807780a0dcb07707

URL: https://github.com/llvm/llvm-project/commit/1ccc702912fa9c41a58b9007807780a0dcb07707
DIFF: https://github.com/llvm/llvm-project/commit/1ccc702912fa9c41a58b9007807780a0dcb07707.diff

LOG: [lldb][NFC] Remove unnecessary ClangASTImporter checks in ClangASTSource

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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 18e1353ee9b2..8fb0f40ea1d3 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -52,8 +52,9 @@ class ScopedLexicalDeclEraser {
 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);
 

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index c776043f6b36..8f4c92e33278 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -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;


        


More information about the lldb-commits mailing list