diff --git a/clang/include/clang/AST/ASTImporter.h b/clang/include/clang/AST/ASTImporter.h --- a/clang/include/clang/AST/ASTImporter.h +++ b/clang/include/clang/AST/ASTImporter.h @@ -344,6 +344,12 @@ Import(ExprWithCleanups::CleanupObject From); /// Import the given type from the "from" context into the "to" + /// context. + /// + /// \returns The equivalent type in the "to" context, or the import error. + llvm::Expected Import(const Type *FromT); + + /// Import the given qualified type from the "from" context into the "to" /// context. A null type is imported as a null type (no error). /// /// \returns The equivalent type in the "to" context, or the import error. diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -8168,28 +8168,37 @@ return make_error(ImportError::UnsupportedConstruct); } -Expected ASTImporter::Import(QualType FromT) { - if (FromT.isNull()) - return QualType{}; - - const Type *FromTy = FromT.getTypePtr(); +Expected ASTImporter::Import(const Type *FromT) { + if (!FromT) + return FromT; // Check whether we've already imported this type. - llvm::DenseMap::iterator Pos - = ImportedTypes.find(FromTy); + llvm::DenseMap::iterator Pos = + ImportedTypes.find(FromT); if (Pos != ImportedTypes.end()) - return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); + return Pos->second; // Import the type ASTNodeImporter Importer(*this); - ExpectedType ToTOrErr = Importer.Visit(FromTy); + ExpectedType ToTOrErr = Importer.Visit(FromT); if (!ToTOrErr) return ToTOrErr.takeError(); // Record the imported type. - ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); + ImportedTypes[FromT] = ToTOrErr->getTypePtr(); + + return ToTOrErr->getTypePtr(); +} + +Expected ASTImporter::Import(QualType FromT) { + if (FromT.isNull()) + return QualType{}; + + Expected ToTyOrErr = Import(FromT.getTypePtr()); + if (!ToTyOrErr) + return ToTyOrErr.takeError(); - return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); + return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers()); } Expected ASTImporter::Import(TypeSourceInfo *FromTSI) {