Skip to content

Commit d78f7bf

Browse files
committed
[lldb][ClangASTImporter][NFC] Factor out CanImport logic
1 parent 049e044 commit d78f7bf

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
@@ -365,6 +365,16 @@ clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx,
365365
return result;
366366
}
367367

368+
bool ClangASTImporter::CanImport(const Decl *d) {
369+
if (!d)
370+
return false;
371+
if (isa<TagDecl>(d))
372+
return GetDeclOrigin(d).Valid();
373+
if (isa<ObjCInterfaceDecl>(d))
374+
return GetDeclOrigin(d).Valid();
375+
return false;
376+
}
377+
368378
bool ClangASTImporter::CanImport(const CompilerType &type) {
369379
if (!ClangUtil::IsClangType(type))
370380
return false;
@@ -374,24 +384,10 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
374384

375385
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
376386
switch (type_class) {
377-
case clang::Type::Record: {
378-
const clang::CXXRecordDecl *cxx_record_decl =
379-
qual_type->getAsCXXRecordDecl();
380-
if (cxx_record_decl) {
381-
if (GetDeclOrigin(cxx_record_decl).Valid())
382-
return true;
383-
}
384-
} break;
385-
386-
case clang::Type::Enum: {
387-
clang::EnumDecl *enum_decl =
388-
llvm::cast<clang::EnumType>(qual_type)->getDecl();
389-
if (enum_decl) {
390-
if (GetDeclOrigin(enum_decl).Valid())
391-
return true;
392-
}
393-
} break;
394-
387+
case clang::Type::Record:
388+
return CanImport(qual_type->getAsRecordDecl());
389+
case clang::Type::Enum:
390+
return CanImport(llvm::cast<clang::EnumType>(qual_type)->getDecl());
395391
case clang::Type::ObjCObject:
396392
case clang::Type::ObjCInterface: {
397393
const clang::ObjCObjectType *objc_class_type =
@@ -401,10 +397,7 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
401397
objc_class_type->getInterface();
402398
// We currently can't complete objective C types through the newly added
403399
// ASTContext because it only supports TagDecl objects right now...
404-
if (class_interface_decl) {
405-
if (GetDeclOrigin(class_interface_decl).Valid())
406-
return true;
407-
}
400+
return CanImport(class_interface_decl);
408401
}
409402
} break;
410403

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

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

160+
bool CanImport(const clang::Decl *d);
161+
160162
/// If the given type was copied from another TypeSystemClang then copy over
161163
/// all missing information (e.g., the definition of a 'class' type).
162164
///

0 commit comments

Comments
 (0)