Index: include/clang/AST/ASTImporter.h =================================================================== --- include/clang/AST/ASTImporter.h +++ include/clang/AST/ASTImporter.h @@ -166,30 +166,41 @@ } /// Import the given type from the "from" context into the "to" - /// context. + /// context. A null type is imported as a null type (no error). /// - /// \returns the equivalent type in the "to" context, or a NULL type if - /// an error occurred. + /// \returns The equivalent type in the "to" context, or the import error. + llvm::Expected Import_New(QualType FromT); + // FIXME: Remove this version. QualType Import(QualType FromT); /// Import the given type source information from the /// "from" context into the "to" context. /// - /// \returns the equivalent type source information in the "to" - /// context, or NULL if an error occurred. + /// \returns The equivalent type source information in the "to" + /// context, or the import error. + llvm::Expected Import_New(TypeSourceInfo *FromTSI); + // FIXME: Remove this version. TypeSourceInfo *Import(TypeSourceInfo *FromTSI); /// Import the given attribute from the "from" context into the /// "to" context. /// - /// \returns the equivalent attribute in the "to" context. + /// \returns The equivalent attribute in the "to" context, or the import + /// error. + llvm::Expected Import_New(const Attr *FromAttr); + // FIXME: Remove this version. Attr *Import(const Attr *FromAttr); /// Import the given declaration from the "from" context into the /// "to" context. /// - /// \returns the equivalent declaration in the "to" context, or a NULL type - /// if an error occurred. + /// \returns The equivalent declaration in the "to" context, or the import + /// error. + llvm::Expected Import_New(Decl *FromD); + llvm::Expected Import_New(const Decl *FromD) { + return Import_New(const_cast(FromD)); + } + // FIXME: Remove this version. Decl *Import(Decl *FromD); Decl *Import(const Decl *FromD) { return Import(const_cast(FromD)); @@ -210,87 +221,117 @@ /// Import the given expression from the "from" context into the /// "to" context. /// - /// \returns the equivalent expression in the "to" context, or NULL if - /// an error occurred. + /// \returns The equivalent expression in the "to" context, or the import + /// error. + llvm::Expected Import_New(Expr *FromE); + // FIXME: Remove this version. Expr *Import(Expr *FromE); /// Import the given statement from the "from" context into the /// "to" context. /// - /// \returns the equivalent statement in the "to" context, or NULL if - /// an error occurred. + /// \returns The equivalent statement in the "to" context, or the import + /// error. + llvm::Expected Import_New(Stmt *FromS); + // FIXME: Remove this version. Stmt *Import(Stmt *FromS); /// Import the given nested-name-specifier from the "from" /// context into the "to" context. /// - /// \returns the equivalent nested-name-specifier in the "to" - /// context, or NULL if an error occurred. + /// \returns The equivalent nested-name-specifier in the "to" + /// context, or the import error. + llvm::Expected + Import_New(NestedNameSpecifier *FromNNS); + // FIXME: Remove this version. NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS); - /// Import the given nested-name-specifier from the "from" + /// Import the given nested-name-specifier-loc from the "from" /// context into the "to" context. /// - /// \returns the equivalent nested-name-specifier in the "to" - /// context. + /// \returns The equivalent nested-name-specifier-loc in the "to" + /// context, or the import error. + llvm::Expected + Import_New(NestedNameSpecifierLoc FromNNS); + // FIXME: Remove this version. NestedNameSpecifierLoc Import(NestedNameSpecifierLoc FromNNS); - /// Import the goven template name from the "from" context into the - /// "to" context. + /// Import the given template name from the "from" context into the + /// "to" context, or the import error. + llvm::Expected Import_New(TemplateName From); + // FIXME: Remove this version. TemplateName Import(TemplateName From); /// Import the given source location from the "from" context into /// the "to" context. /// - /// \returns the equivalent source location in the "to" context, or an - /// invalid source location if an error occurred. + /// \returns The equivalent source location in the "to" context, or the + /// import error. + llvm::Expected Import_New(SourceLocation FromLoc); + // FIXME: Remove this version. SourceLocation Import(SourceLocation FromLoc); /// Import the given source range from the "from" context into /// the "to" context. /// - /// \returns the equivalent source range in the "to" context, or an - /// invalid source location if an error occurred. + /// \returns The equivalent source range in the "to" context, or the import + /// error. + llvm::Expected Import_New(SourceRange FromRange); + // FIXME: Remove this version. SourceRange Import(SourceRange FromRange); /// Import the given declaration name from the "from" /// context into the "to" context. /// - /// \returns the equivalent declaration name in the "to" context, - /// or an empty declaration name if an error occurred. + /// \returns The equivalent declaration name in the "to" context, or the + /// import error. + llvm::Expected Import_New(DeclarationName FromName); + // FIXME: Remove this version. DeclarationName Import(DeclarationName FromName); /// Import the given identifier from the "from" context /// into the "to" context. /// - /// \returns the equivalent identifier in the "to" context. Note: It + /// \returns The equivalent identifier in the "to" context. Note: It /// returns nullptr only if the FromId was nullptr. IdentifierInfo *Import(const IdentifierInfo *FromId); /// Import the given Objective-C selector from the "from" /// context into the "to" context. /// - /// \returns the equivalent selector in the "to" context. + /// \returns The equivalent selector in the "to" context, or the import + /// error. + llvm::Expected Import_New(Selector FromSel); + // FIXME: Remove this version. Selector Import(Selector FromSel); /// Import the given file ID from the "from" context into the /// "to" context. /// - /// \returns the equivalent file ID in the source manager of the "to" - /// context. + /// \returns The equivalent file ID in the source manager of the "to" + /// context, or the import error. + llvm::Expected Import_New(FileID); + // FIXME: Remove this version. FileID Import(FileID); /// Import the given C++ constructor initializer from the "from" /// context into the "to" context. /// - /// \returns the equivalent initializer in the "to" context. + /// \returns The equivalent initializer in the "to" context, or the import + /// error. + llvm::Expected + Import_New(CXXCtorInitializer *FromInit); + // FIXME: Remove this version. CXXCtorInitializer *Import(CXXCtorInitializer *FromInit); /// Import the given CXXBaseSpecifier from the "from" context into /// the "to" context. /// - /// \returns the equivalent CXXBaseSpecifier in the source manager of the - /// "to" context. + /// \returns The equivalent CXXBaseSpecifier in the source manager of the + /// "to" context, or the import error. + llvm::Expected + Import_New(const CXXBaseSpecifier *FromSpec); + // FIXME: Remove this version. CXXBaseSpecifier *Import(const CXXBaseSpecifier *FromSpec); /// Import the definition of the given declaration, including all of Index: lib/AST/ASTImporter.cpp =================================================================== --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -7656,6 +7656,12 @@ ASTImporter::~ASTImporter() = default; +Expected ASTImporter::Import_New(QualType FromT) { + QualType ToT = Import(FromT); + if (ToT.isNull() && !FromT.isNull()) + return make_error(); + return ToT; +} QualType ASTImporter::Import(QualType FromT) { if (FromT.isNull()) return {}; @@ -7682,6 +7688,12 @@ return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); } +Expected ASTImporter::Import_New(TypeSourceInfo *FromTSI) { + TypeSourceInfo *ToTSI = Import(FromTSI); + if (!ToTSI && FromTSI) + return llvm::make_error(); + return ToTSI; +} TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { if (!FromTSI) return FromTSI; @@ -7696,8 +7708,12 @@ T, Import(FromTSI->getTypeLoc().getBeginLoc())); } +Expected ASTImporter::Import_New(const Attr *FromAttr) { + return Import(FromAttr); +} Attr *ASTImporter::Import(const Attr *FromAttr) { Attr *ToAttr = FromAttr->clone(ToContext); + // NOTE: Import of SourceRange may fail. ToAttr->setRange(Import(FromAttr->getRange())); return ToAttr; } @@ -7715,6 +7731,12 @@ } } +Expected ASTImporter::Import_New(Decl *FromD) { + Decl *ToD = Import(FromD); + if (!ToD && FromD) + return llvm::make_error(); + return ToD; +} Decl *ASTImporter::Import(Decl *FromD) { if (!FromD) return nullptr; @@ -7803,6 +7825,12 @@ return ToDC; } +Expected ASTImporter::Import_New(Expr *FromE) { + Expr *ToE = Import(FromE); + if (!ToE && FromE) + return llvm::make_error(); + return ToE; +} Expr *ASTImporter::Import(Expr *FromE) { if (!FromE) return nullptr; @@ -7810,6 +7838,12 @@ return cast_or_null(Import(cast(FromE))); } +Expected ASTImporter::Import_New(Stmt *FromS) { + Stmt *ToS = Import(FromS); + if (!ToS && FromS) + return llvm::make_error(); + return ToS; +} Stmt *ASTImporter::Import(Stmt *FromS) { if (!FromS) return nullptr; @@ -7845,6 +7879,12 @@ return *ToSOrErr; } +Expected ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { + NestedNameSpecifier *ToNNS = Import(FromNNS); + if (!ToNNS && FromNNS) + return llvm::make_error(); + return ToNNS; +} NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { if (!FromNNS) return nullptr; @@ -7898,6 +7938,10 @@ llvm_unreachable("Invalid nested name specifier kind"); } +Expected ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) { + NestedNameSpecifierLoc ToNNS = Import(FromNNS); + return ToNNS; +} NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { // Copied from NestedNameSpecifier mostly. SmallVector NestedNames; @@ -7969,6 +8013,12 @@ return Builder.getWithLocInContext(getToContext()); } +Expected ASTImporter::Import_New(TemplateName From) { + TemplateName To = Import(From); + if (To.isNull() && !From.isNull()) + return llvm::make_error(); + return To; +} TemplateName ASTImporter::Import(TemplateName From) { switch (From.getKind()) { case TemplateName::Template: @@ -8059,6 +8109,12 @@ llvm_unreachable("Invalid template name kind"); } +Expected ASTImporter::Import_New(SourceLocation FromLoc) { + SourceLocation ToLoc = Import(FromLoc); + if (ToLoc.isInvalid() && !FromLoc.isInvalid()) + return llvm::make_error(); + return ToLoc; +} SourceLocation ASTImporter::Import(SourceLocation FromLoc) { if (FromLoc.isInvalid()) return {}; @@ -8073,10 +8129,20 @@ return ToSM.getComposedLoc(ToFileID, Decomposed.second); } +Expected ASTImporter::Import_New(SourceRange FromRange) { + SourceRange ToRange = Import(FromRange); + return ToRange; +} SourceRange ASTImporter::Import(SourceRange FromRange) { return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); } +Expected ASTImporter::Import_New(FileID FromID) { + FileID ToID = Import(FromID); + if (ToID.isInvalid() && FromID.isValid()) + return llvm::make_error(); + return ToID; +} FileID ASTImporter::Import(FileID FromID) { llvm::DenseMap::iterator Pos = ImportedFileIDs.find(FromID); if (Pos != ImportedFileIDs.end()) @@ -8134,6 +8200,12 @@ return ToID; } +Expected ASTImporter::Import_New(CXXCtorInitializer *From) { + CXXCtorInitializer *To = Import(From); + if (!To && From) + return llvm::make_error(); + return To; +} CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { Expr *ToExpr = Import(From->getInit()); if (!ToExpr && From->getInit()) @@ -8179,6 +8251,12 @@ } } +Expected ASTImporter::Import_New(const CXXBaseSpecifier *From) { + CXXBaseSpecifier *To = Import(From); + if (!To && From) + return llvm::make_error(); + return To; +} CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); if (Pos != ImportedCXXBaseSpecifiers.end()) @@ -8244,6 +8322,12 @@ llvm::consumeError(std::move(Err)); } +Expected ASTImporter::Import_New(DeclarationName FromName) { + DeclarationName ToName = Import(FromName); + if (!ToName && FromName) + return llvm::make_error(); + return ToName; +} DeclarationName ASTImporter::Import(DeclarationName FromName) { if (!FromName) return {}; @@ -8320,6 +8404,12 @@ return ToId; } +Expected ASTImporter::Import_New(Selector FromSel) { + Selector ToSel = Import(FromSel); + if (ToSel.isNull() && !FromSel.isNull()) + return llvm::make_error(); + return ToSel; +} Selector ASTImporter::Import(Selector FromSel) { if (FromSel.isNull()) return {};