@@ -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+
374384bool 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
0 commit comments