[lldb][ClangASTImporter][NFC] Create helper for CanImport

Upstreams a `CanImport` helper for `clang::Decl`s.
This commit is contained in:
Michael Buch 2025-08-13 10:21:31 +01:00
parent 89681839e3
commit c68b4d64dd
2 changed files with 17 additions and 21 deletions

View File

@ -371,6 +371,16 @@ clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx,
return result; return result;
} }
bool ClangASTImporter::CanImport(const Decl *d) {
if (!d)
return false;
if (isa<TagDecl>(d))
return GetDeclOrigin(d).Valid();
if (isa<ObjCInterfaceDecl>(d))
return GetDeclOrigin(d).Valid();
return false;
}
bool ClangASTImporter::CanImport(const CompilerType &type) { bool ClangASTImporter::CanImport(const CompilerType &type) {
if (!ClangUtil::IsClangType(type)) if (!ClangUtil::IsClangType(type))
return false; return false;
@ -380,23 +390,10 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
const clang::Type::TypeClass type_class = qual_type->getTypeClass(); const clang::Type::TypeClass type_class = qual_type->getTypeClass();
switch (type_class) { switch (type_class) {
case clang::Type::Record: { case clang::Type::Record:
const clang::CXXRecordDecl *cxx_record_decl = return CanImport(qual_type->getAsCXXRecordDecl());
qual_type->getAsCXXRecordDecl(); case clang::Type::Enum:
if (cxx_record_decl) { return CanImport(llvm::cast<clang::EnumType>(qual_type)->getOriginalDecl());
if (GetDeclOrigin(cxx_record_decl).Valid())
return true;
}
} break;
case clang::Type::Enum: {
auto *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getOriginalDecl();
if (enum_decl) {
if (GetDeclOrigin(enum_decl).Valid())
return true;
}
} break;
case clang::Type::ObjCObject: case clang::Type::ObjCObject:
case clang::Type::ObjCInterface: { case clang::Type::ObjCInterface: {
const clang::ObjCObjectType *objc_class_type = const clang::ObjCObjectType *objc_class_type =
@ -406,10 +403,7 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
objc_class_type->getInterface(); objc_class_type->getInterface();
// We currently can't complete objective C types through the newly added // We currently can't complete objective C types through the newly added
// ASTContext because it only supports TagDecl objects right now... // ASTContext because it only supports TagDecl objects right now...
if (class_interface_decl) { return CanImport(class_interface_decl);
if (GetDeclOrigin(class_interface_decl).Valid())
return true;
}
} }
} break; } break;

View File

@ -157,6 +157,8 @@ public:
/// \see ClangASTImporter::Import /// \see ClangASTImporter::Import
bool CanImport(const CompilerType &type); bool CanImport(const CompilerType &type);
bool CanImport(const clang::Decl *d);
/// If the given type was copied from another TypeSystemClang then copy over /// If the given type was copied from another TypeSystemClang then copy over
/// all missing information (e.g., the definition of a 'class' type). /// all missing information (e.g., the definition of a 'class' type).
/// ///