Skip to content

Commit c68b4d6

Browse files
committed
[lldb][ClangASTImporter][NFC] Create helper for CanImport
Upstreams a `CanImport` helper for `clang::Decl`s.
1 parent 8968183 commit c68b4d6

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,16 @@ clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx,
371371
return result;
372372
}
373373

374+
bool ClangASTImporter::CanImport(const Decl *d) {
375+
if (!d)
376+
return false;
377+
if (isa<TagDecl>(d))
378+
return GetDeclOrigin(d).Valid();
379+
if (isa<ObjCInterfaceDecl>(d))
380+
return GetDeclOrigin(d).Valid();
381+
return false;
382+
}
383+
374384
bool ClangASTImporter::CanImport(const CompilerType &type) {
375385
if (!ClangUtil::IsClangType(type))
376386
return false;
@@ -380,23 +390,10 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
380390

381391
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
382392
switch (type_class) {
383-
case clang::Type::Record: {
384-
const clang::CXXRecordDecl *cxx_record_decl =
385-
qual_type->getAsCXXRecordDecl();
386-
if (cxx_record_decl) {
387-
if (GetDeclOrigin(cxx_record_decl).Valid())
388-
return true;
389-
}
390-
} break;
391-
392-
case clang::Type::Enum: {
393-
auto *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getOriginalDecl();
394-
if (enum_decl) {
395-
if (GetDeclOrigin(enum_decl).Valid())
396-
return true;
397-
}
398-
} break;
399-
393+
case clang::Type::Record:
394+
return CanImport(qual_type->getAsCXXRecordDecl());
395+
case clang::Type::Enum:
396+
return CanImport(llvm::cast<clang::EnumType>(qual_type)->getOriginalDecl());
400397
case clang::Type::ObjCObject:
401398
case clang::Type::ObjCInterface: {
402399
const clang::ObjCObjectType *objc_class_type =
@@ -406,10 +403,7 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
406403
objc_class_type->getInterface();
407404
// We currently can't complete objective C types through the newly added
408405
// ASTContext because it only supports TagDecl objects right now...
409-
if (class_interface_decl) {
410-
if (GetDeclOrigin(class_interface_decl).Valid())
411-
return true;
412-
}
406+
return CanImport(class_interface_decl);
413407
}
414408
} break;
415409

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)