[Lldb-commits] [lldb] c68b4d6 - [lldb][ClangASTImporter][NFC] Create helper for CanImport
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 13 02:22:42 PDT 2025
Author: Michael Buch
Date: 2025-08-13T10:22:23+01:00
New Revision: c68b4d64dd89993468a23dcc1c5deb858d7e3b2f
URL: https://github.com/llvm/llvm-project/commit/c68b4d64dd89993468a23dcc1c5deb858d7e3b2f
DIFF: https://github.com/llvm/llvm-project/commit/c68b4d64dd89993468a23dcc1c5deb858d7e3b2f.diff
LOG: [lldb][ClangASTImporter][NFC] Create helper for CanImport
Upstreams a `CanImport` helper for `clang::Decl`s.
Added:
Modified:
lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 8a39fae9498c0..08e2d0f1b4011 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -371,6 +371,16 @@ clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx,
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) {
if (!ClangUtil::IsClangType(type))
return false;
@@ -380,23 +390,10 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
switch (type_class) {
- case clang::Type::Record: {
- const clang::CXXRecordDecl *cxx_record_decl =
- qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl) {
- 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::Record:
+ return CanImport(qual_type->getAsCXXRecordDecl());
+ case clang::Type::Enum:
+ return CanImport(llvm::cast<clang::EnumType>(qual_type)->getOriginalDecl());
case clang::Type::ObjCObject:
case clang::Type::ObjCInterface: {
const clang::ObjCObjectType *objc_class_type =
@@ -406,10 +403,7 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
objc_class_type->getInterface();
// We currently can't complete objective C types through the newly added
// ASTContext because it only supports TagDecl objects right now...
- if (class_interface_decl) {
- if (GetDeclOrigin(class_interface_decl).Valid())
- return true;
- }
+ return CanImport(class_interface_decl);
}
} break;
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
index 1c77c5bb4a47b..03d2556ca6f23 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
@@ -157,6 +157,8 @@ class ClangASTImporter {
/// \see ClangASTImporter::Import
bool CanImport(const CompilerType &type);
+ bool CanImport(const clang::Decl *d);
+
/// If the given type was copied from another TypeSystemClang then copy over
/// all missing information (e.g., the definition of a 'class' type).
///
More information about the lldb-commits
mailing list