Skip to content

Commit 0c17fe0

Browse files
committed
[lldb][ClangASTImporter][NFC] Factor out CanImport logic
(cherry picked from commit cb255e8501b45ad6ddd6c72c09228aa3e4d8aea6)
1 parent 27246c7 commit 0c17fe0

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,16 @@ clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx,
363363
return result;
364364
}
365365

366+
bool ClangASTImporter::CanImport(const Decl *d) {
367+
if (!d)
368+
return false;
369+
if (isa<TagDecl>(d))
370+
return GetDeclOrigin(d).Valid();
371+
if (isa<ObjCInterfaceDecl>(d))
372+
return GetDeclOrigin(d).Valid();
373+
return false;
374+
}
375+
366376
bool ClangASTImporter::CanImport(const CompilerType &type) {
367377
if (!ClangUtil::IsClangType(type))
368378
return false;
@@ -372,24 +382,10 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
372382

373383
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
374384
switch (type_class) {
375-
case clang::Type::Record: {
376-
const clang::CXXRecordDecl *cxx_record_decl =
377-
qual_type->getAsCXXRecordDecl();
378-
if (cxx_record_decl) {
379-
if (GetDeclOrigin(cxx_record_decl).Valid())
380-
return true;
381-
}
382-
} break;
383-
384-
case clang::Type::Enum: {
385-
clang::EnumDecl *enum_decl =
386-
llvm::cast<clang::EnumType>(qual_type)->getDecl();
387-
if (enum_decl) {
388-
if (GetDeclOrigin(enum_decl).Valid())
389-
return true;
390-
}
391-
} break;
392-
385+
case clang::Type::Record:
386+
return CanImport(qual_type->getAsRecordDecl());
387+
case clang::Type::Enum:
388+
return CanImport(llvm::cast<clang::EnumType>(qual_type)->getDecl());
393389
case clang::Type::ObjCObject:
394390
case clang::Type::ObjCInterface: {
395391
const clang::ObjCObjectType *objc_class_type =
@@ -399,10 +395,7 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
399395
objc_class_type->getInterface();
400396
// We currently can't complete objective C types through the newly added
401397
// ASTContext because it only supports TagDecl objects right now...
402-
if (class_interface_decl) {
403-
if (GetDeclOrigin(class_interface_decl).Valid())
404-
return true;
405-
}
398+
return CanImport(class_interface_decl);
406399
}
407400
} break;
408401

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class ClangASTImporter {
137137
/// \see ClangASTImporter::Import
138138
bool CanImport(const CompilerType &type);
139139

140+
bool CanImport(const clang::Decl *d);
141+
140142
/// If the given type was copied from another TypeSystemClang then copy over
141143
/// all missing information (e.g., the definition of a 'class' type).
142144
///

0 commit comments

Comments
 (0)