From 57949eb6772d8f6ec39d876ef1b1ff9552b9a26b Mon Sep 17 00:00:00 2001 From: Balazs Keri <1.int32@gmail.com> Date: Mon, 25 Mar 2019 09:16:39 +0000 Subject: [PATCH] [ASTImporter] Changed use of Import to Import_New in ASTNodeImporter. Reviewers: a.sidorin, shafik, martong, a_sidorin Reviewed By: a_sidorin Subscribers: a_sidorin, rnkovacs, gamesh411, dkrupp, martong, Szelethus, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D53757 llvm-svn: 356874 --- clang/lib/AST/ASTImporter.cpp | 72 +++++++++++++------------------------------ 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 5b038e7..dbad548 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -148,32 +148,20 @@ namespace clang { // Use this to import pointers of specific type. template LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { - auto ToI = Importer.Import(From); - if (!ToI && From) - return make_error(); - To = cast_or_null(ToI); - return Error::success(); - // FIXME: This should be the final code. - //auto ToOrErr = Importer.Import(From); - //if (ToOrErr) { - // To = cast_or_null(*ToOrErr); - //} - //return ToOrErr.takeError(); + auto ToOrErr = Importer.Import_New(From); + if (ToOrErr) + To = cast_or_null(*ToOrErr); + return ToOrErr.takeError(); } // Call the import function of ASTImporter for a baseclass of type `T` and // cast the return value to `T`. template Expected import(T *From) { - auto *To = Importer.Import(From); - if (!To && From) - return make_error(); - return cast_or_null(To); - // FIXME: This should be the final code. - //auto ToOrErr = Importer.Import(From); - //if (!ToOrErr) - // return ToOrErr.takeError(); - //return cast_or_null(*ToOrErr); + auto ToOrErr = Importer.Import_New(From); + if (!ToOrErr) + return ToOrErr.takeError(); + return cast_or_null(*ToOrErr); } template @@ -184,13 +172,7 @@ namespace clang { // Call the import function of ASTImporter for type `T`. template Expected import(const T &From) { - T To = Importer.Import(From); - T DefaultT; - if (To == DefaultT && !(From == DefaultT)) - return make_error(); - return To; - // FIXME: This should be the final code. - //return Importer.Import(From); + return Importer.Import_New(From); } template @@ -282,8 +264,15 @@ namespace clang { void InitializeImportedDecl(Decl *FromD, Decl *ToD) { ToD->IdentifierNamespace = FromD->IdentifierNamespace; if (FromD->hasAttrs()) - for (const Attr *FromAttr : FromD->getAttrs()) - ToD->addAttr(Importer.Import(FromAttr)); + for (const Attr *FromAttr : FromD->getAttrs()) { + // FIXME: Return of the error here is not possible until store of + // import errors is implemented. + auto ToAttrOrErr = import(FromAttr); + if (ToAttrOrErr) + ToD->addAttr(*ToAttrOrErr); + else + llvm::consumeError(ToAttrOrErr.takeError()); + } if (FromD->isUsed()) ToD->setIsUsed(); if (FromD->isImplicit()) @@ -643,15 +632,6 @@ namespace clang { FunctionDecl *FromFD); }; -// FIXME: Temporary until every import returns Expected. -template <> -Expected ASTNodeImporter::import(const TemplateName &From) { - TemplateName To = Importer.Import(From); - if (To.isNull() && !From.isNull()) - return make_error(); - return To; -} - template Error ASTNodeImporter::ImportTemplateArgumentListInfo( SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, @@ -1692,15 +1672,10 @@ Error ASTNodeImporter::ImportImplicitMethods( static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer) { if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { - Decl *ToTypedef = Importer.Import(FromTypedef); - if (!ToTypedef) - return make_error(); - To->setTypedefNameForAnonDecl(cast(ToTypedef)); - // FIXME: This should be the final code. - //if (Expected ToTypedefOrErr = Importer.Import(FromTypedef)) - // To->setTypedefNameForAnonDecl(cast(*ToTypedefOrErr)); - //else - // return ToTypedefOrErr.takeError(); + if (ExpectedDecl ToTypedefOrErr = Importer.Import_New(FromTypedef)) + To->setTypedefNameForAnonDecl(cast(*ToTypedefOrErr)); + else + return ToTypedefOrErr.takeError(); } return Error::success(); } @@ -3386,9 +3361,6 @@ ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { // FIXME here we leak `NamedChain` which is allocated before return ToIndirectField; - for (const auto *Attr : D->attrs()) - ToIndirectField->addAttr(Importer.Import(Attr)); - ToIndirectField->setAccess(D->getAccess()); ToIndirectField->setLexicalDeclContext(LexicalDC); LexicalDC->addDeclInternal(ToIndirectField); -- 2.7.4