Skip to content

Commit 1ccc702

Browse files
committed
[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.
1 parent 19f1ce6 commit 1ccc702

File tree

2 files changed

+11
-49
lines changed

2 files changed

+11
-49
lines changed

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

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ class ScopedLexicalDeclEraser {
5252
ClangASTSource::ClangASTSource(const lldb::TargetSP &target,
5353
const lldb::ClangASTImporterSP &importer)
5454
: m_import_in_progress(false), m_lookups_enabled(false), m_target(target),
55-
m_ast_context(nullptr), m_active_lexical_decls(), m_active_lookups() {
56-
m_ast_importer_sp = importer;
55+
m_ast_context(nullptr), m_ast_importer_sp(importer),
56+
m_active_lexical_decls(), m_active_lookups() {
57+
assert(m_ast_importer_sp && "No ClangASTImporter passed to ClangASTSource?");
5758
}
5859

5960
void ClangASTSource::InstallASTContext(TypeSystemClang &clang_ast_context) {
@@ -64,9 +65,6 @@ void ClangASTSource::InstallASTContext(TypeSystemClang &clang_ast_context) {
6465
}
6566

6667
ClangASTSource::~ClangASTSource() {
67-
if (!m_ast_importer_sp)
68-
return;
69-
7068
m_ast_importer_sp->ForgetDestination(m_ast_context);
7169

7270
if (!m_target)
@@ -216,10 +214,6 @@ void ClangASTSource::CompleteType(TagDecl *tag_decl) {
216214
m_active_lexical_decls.insert(tag_decl);
217215
ScopedLexicalDeclEraser eraser(m_active_lexical_decls, tag_decl);
218216

219-
if (!m_ast_importer_sp) {
220-
return;
221-
}
222-
223217
if (!m_ast_importer_sp->CompleteTagDecl(tag_decl)) {
224218
// We couldn't complete the type. Maybe there's a definition somewhere
225219
// else that can be completed.
@@ -343,11 +337,6 @@ void ClangASTSource::CompleteType(clang::ObjCInterfaceDecl *interface_decl) {
343337
LLDB_LOG(log, " [COID] Before:\n{0}",
344338
ClangUtil::DumpDecl(interface_decl));
345339

346-
if (!m_ast_importer_sp) {
347-
lldbassert(0 && "No mechanism for completing a type!");
348-
return;
349-
}
350-
351340
ClangASTImporter::DeclOrigin original = m_ast_importer_sp->GetDeclOrigin(interface_decl);
352341

353342
if (original.Valid()) {
@@ -420,9 +409,6 @@ void ClangASTSource::FindExternalLexicalDecls(
420409
llvm::function_ref<bool(Decl::Kind)> predicate,
421410
llvm::SmallVectorImpl<Decl *> &decls) {
422411

423-
if (!m_ast_importer_sp)
424-
return;
425-
426412
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
427413

428414
const Decl *context_decl = dyn_cast<Decl>(decl_context);
@@ -587,8 +573,8 @@ void ClangASTSource::FindExternalVisibleDecls(NameSearchContext &context) {
587573

588574
if (const NamespaceDecl *namespace_context =
589575
dyn_cast<NamespaceDecl>(context.m_decl_context)) {
590-
ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer_sp ?
591-
m_ast_importer_sp->GetNamespaceMap(namespace_context) : nullptr;
576+
ClangASTImporter::NamespaceMapSP namespace_map =
577+
m_ast_importer_sp->GetNamespaceMap(namespace_context);
592578

593579
if (log && log->GetVerbose())
594580
LLDB_LOG(log,
@@ -1791,21 +1777,11 @@ NamespaceDecl *ClangASTSource::AddNamespace(
17911777
}
17921778

17931779
clang::Decl *ClangASTSource::CopyDecl(Decl *src_decl) {
1794-
if (m_ast_importer_sp) {
1795-
return m_ast_importer_sp->CopyDecl(m_ast_context, src_decl);
1796-
} else {
1797-
lldbassert(0 && "No mechanism for copying a decl!");
1798-
return nullptr;
1799-
}
1780+
return m_ast_importer_sp->CopyDecl(m_ast_context, src_decl);
18001781
}
18011782

18021783
ClangASTImporter::DeclOrigin ClangASTSource::GetDeclOrigin(const clang::Decl *decl) {
1803-
if (m_ast_importer_sp) {
1804-
return m_ast_importer_sp->GetDeclOrigin(decl);
1805-
} else {
1806-
// this can happen early enough that no ExternalASTSource is installed.
1807-
return ClangASTImporter::DeclOrigin();
1808-
}
1784+
return m_ast_importer_sp->GetDeclOrigin(decl);
18091785
}
18101786

18111787
CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
@@ -1816,15 +1792,8 @@ CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
18161792

18171793
SetImportInProgress(true);
18181794

1819-
QualType copied_qual_type;
1820-
1821-
if (m_ast_importer_sp) {
1822-
copied_qual_type = ClangUtil::GetQualType(
1823-
m_ast_importer_sp->CopyType(*m_clang_ast_context, src_type));
1824-
} else {
1825-
lldbassert(0 && "No mechanism for copying a type!");
1826-
return CompilerType();
1827-
}
1795+
QualType copied_qual_type = ClangUtil::GetQualType(
1796+
m_ast_importer_sp->CopyType(*m_clang_ast_context, src_type));
18281797

18291798
SetImportInProgress(false);
18301799

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,7 @@ TypeFromUser ClangExpressionDeclMap::DeportType(TypeSystemClang &target,
181181
assert((TypeSystem *)&source == parser_type.GetTypeSystem());
182182
assert(&source.getASTContext() == m_ast_context);
183183

184-
if (m_ast_importer_sp) {
185-
return TypeFromUser(m_ast_importer_sp->DeportType(target, parser_type));
186-
} else {
187-
lldbassert(0 && "No mechanism for deporting a type!");
188-
return TypeFromUser();
189-
}
184+
return TypeFromUser(m_ast_importer_sp->DeportType(target, parser_type));
190185
}
191186

192187
bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl,
@@ -682,9 +677,7 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
682677
}
683678

684679
ClangASTImporter::NamespaceMapSP namespace_map =
685-
m_ast_importer_sp
686-
? m_ast_importer_sp->GetNamespaceMap(namespace_context)
687-
: ClangASTImporter::NamespaceMapSP();
680+
m_ast_importer_sp->GetNamespaceMap(namespace_context);
688681

689682
if (!namespace_map)
690683
return;

0 commit comments

Comments
 (0)