mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-10 18:11:19 +00:00
Changed every use of ASTImporter::Import to Import_New
Reviewers: a.sidorin, shafik, martong, a_sidorin Reviewed By: a_sidorin Subscribers: rnkovacs, dkrupp, martong, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D55049 llvm-svn: 357913
This commit is contained in:
parent
50c3b290ed
commit
a1f6b103f3
@ -7792,9 +7792,10 @@ Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) {
|
||||
if (!FromDC)
|
||||
return FromDC;
|
||||
|
||||
auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC)));
|
||||
if (!ToDC)
|
||||
return nullptr;
|
||||
ExpectedDecl ToDCOrErr = Import_New(cast<Decl>(FromDC));
|
||||
if (!ToDCOrErr)
|
||||
return ToDCOrErr.takeError();
|
||||
auto *ToDC = cast<DeclContext>(*ToDCOrErr);
|
||||
|
||||
// When we're using a record/enum/Objective-C class/protocol as a context, we
|
||||
// need it to have a definition.
|
||||
@ -8590,10 +8591,16 @@ Decl *ASTImporter::MapImported(Decl *From, Decl *To) {
|
||||
|
||||
bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To,
|
||||
bool Complain) {
|
||||
llvm::DenseMap<const Type *, const Type *>::iterator Pos
|
||||
= ImportedTypes.find(From.getTypePtr());
|
||||
if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To))
|
||||
return true;
|
||||
llvm::DenseMap<const Type *, const Type *>::iterator Pos =
|
||||
ImportedTypes.find(From.getTypePtr());
|
||||
if (Pos != ImportedTypes.end()) {
|
||||
if (ExpectedType ToFromOrErr = Import_New(From)) {
|
||||
if (ToContext.hasSameType(*ToFromOrErr, To))
|
||||
return true;
|
||||
} else {
|
||||
llvm::consumeError(ToFromOrErr.takeError());
|
||||
}
|
||||
}
|
||||
|
||||
StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
|
||||
getStructuralEquivalenceKind(*this), false,
|
||||
|
@ -56,7 +56,12 @@ LookupSameContext(Source<TranslationUnitDecl *> SourceTU, const DeclContext *DC,
|
||||
}
|
||||
auto *ND = cast<NamedDecl>(DC);
|
||||
DeclarationName Name = ND->getDeclName();
|
||||
Source<DeclarationName> SourceName = ReverseImporter.Import(Name);
|
||||
auto SourceNameOrErr = ReverseImporter.Import_New(Name);
|
||||
if (!SourceNameOrErr) {
|
||||
llvm::consumeError(SourceNameOrErr.takeError());
|
||||
return nullptr;
|
||||
}
|
||||
Source<DeclarationName> SourceName = *SourceNameOrErr;
|
||||
DeclContext::lookup_result SearchResult =
|
||||
SourceParentDC.get()->lookup(SourceName.get());
|
||||
size_t SearchResultSize = SearchResult.size();
|
||||
@ -354,9 +359,13 @@ void ExternalASTMerger::RemoveSources(llvm::ArrayRef<ImporterSource> Sources) {
|
||||
|
||||
template <typename DeclTy>
|
||||
static bool importSpecializations(DeclTy *D, ASTImporter *Importer) {
|
||||
for (auto *Spec : D->specializations())
|
||||
if (!Importer->Import(Spec))
|
||||
for (auto *Spec : D->specializations()) {
|
||||
auto ImportedSpecOrError = Importer->Import_New(Spec);
|
||||
if (!ImportedSpecOrError) {
|
||||
llvm::consumeError(ImportedSpecOrError.takeError());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -383,15 +392,21 @@ bool ExternalASTMerger::FindExternalVisibleDeclsByName(const DeclContext *DC,
|
||||
Candidates.push_back(C);
|
||||
};
|
||||
|
||||
ForEachMatchingDC(DC, [&](ASTImporter &Forward, ASTImporter &Reverse,
|
||||
Source<const DeclContext *> SourceDC) -> bool {
|
||||
DeclarationName FromName = Reverse.Import(Name);
|
||||
DeclContextLookupResult Result = SourceDC.get()->lookup(FromName);
|
||||
for (NamedDecl *FromD : Result) {
|
||||
FilterFoundDecl(std::make_pair(FromD, &Forward));
|
||||
}
|
||||
return false;
|
||||
});
|
||||
ForEachMatchingDC(DC,
|
||||
[&](ASTImporter &Forward, ASTImporter &Reverse,
|
||||
Source<const DeclContext *> SourceDC) -> bool {
|
||||
auto FromNameOrErr = Reverse.Import_New(Name);
|
||||
if (!FromNameOrErr) {
|
||||
llvm::consumeError(FromNameOrErr.takeError());
|
||||
return false;
|
||||
}
|
||||
DeclContextLookupResult Result =
|
||||
SourceDC.get()->lookup(*FromNameOrErr);
|
||||
for (NamedDecl *FromD : Result) {
|
||||
FilterFoundDecl(std::make_pair(FromD, &Forward));
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (Candidates.empty())
|
||||
return false;
|
||||
@ -400,7 +415,10 @@ bool ExternalASTMerger::FindExternalVisibleDeclsByName(const DeclContext *DC,
|
||||
for (const Candidate &C : Candidates) {
|
||||
Decl *LookupRes = C.first.get();
|
||||
ASTImporter *Importer = C.second;
|
||||
NamedDecl *ND = cast_or_null<NamedDecl>(Importer->Import(LookupRes));
|
||||
auto NDOrErr = Importer->Import_New(LookupRes);
|
||||
assert(NDOrErr);
|
||||
(void)static_cast<bool>(NDOrErr);
|
||||
NamedDecl *ND = cast_or_null<NamedDecl>(*NDOrErr);
|
||||
assert(ND);
|
||||
// If we don't import specialization, they are not available via lookup
|
||||
// because the lookup result is imported TemplateDecl and it does not
|
||||
@ -422,9 +440,12 @@ void ExternalASTMerger::FindExternalLexicalDecls(
|
||||
Source<const DeclContext *> SourceDC) -> bool {
|
||||
for (const Decl *SourceDecl : SourceDC.get()->decls()) {
|
||||
if (IsKindWeWant(SourceDecl->getKind())) {
|
||||
Decl *ImportedDecl = Forward.Import(const_cast<Decl *>(SourceDecl));
|
||||
assert(!ImportedDecl || IsSameDC(ImportedDecl->getDeclContext(), DC));
|
||||
(void)ImportedDecl;
|
||||
auto ImportedDeclOrErr = Forward.Import_New(SourceDecl);
|
||||
if (ImportedDeclOrErr)
|
||||
assert(!(*ImportedDeclOrErr) ||
|
||||
IsSameDC((*ImportedDeclOrErr)->getDeclContext(), DC));
|
||||
else
|
||||
llvm::consumeError(ImportedDeclOrErr.takeError());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -357,13 +357,28 @@ CrossTranslationUnitContext::importDefinition(const FunctionDecl *FD) {
|
||||
assert(FD->hasBody() && "Functions to be imported should have body.");
|
||||
|
||||
ASTImporter &Importer = getOrCreateASTImporter(FD->getASTContext());
|
||||
auto *ToDecl =
|
||||
cast_or_null<FunctionDecl>(Importer.Import(const_cast<FunctionDecl *>(FD)));
|
||||
if (!ToDecl)
|
||||
auto ToDeclOrError = Importer.Import_New(FD);
|
||||
if (!ToDeclOrError) {
|
||||
handleAllErrors(ToDeclOrError.takeError(),
|
||||
[&](const ImportError &IE) {
|
||||
switch (IE.Error) {
|
||||
case ImportError::NameConflict:
|
||||
// FIXME: Add statistic.
|
||||
break;
|
||||
case ImportError::UnsupportedConstruct:
|
||||
// FIXME: Add statistic.
|
||||
break;
|
||||
case ImportError::Unknown:
|
||||
llvm_unreachable("Unknown import error happened.");
|
||||
break;
|
||||
}
|
||||
});
|
||||
return llvm::make_error<IndexError>(index_error_code::failed_import);
|
||||
assert(ToDecl->hasBody());
|
||||
assert(FD->hasBody() && "Functions already imported should have body.");
|
||||
}
|
||||
auto *ToDecl = cast<FunctionDecl>(*ToDeclOrError);
|
||||
assert(ToDecl->hasBody() && "Imported function should have body.");
|
||||
++NumGetCTUSuccess;
|
||||
|
||||
return ToDecl;
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,13 @@ void ASTMergeAction::ExecuteAction() {
|
||||
if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list"))
|
||||
continue;
|
||||
|
||||
Decl *ToD = Importer.Import(D);
|
||||
llvm::Expected<Decl *> ToDOrError = Importer.Import_New(D);
|
||||
|
||||
if (ToD) {
|
||||
DeclGroupRef DGR(ToD);
|
||||
if (ToDOrError) {
|
||||
DeclGroupRef DGR(*ToDOrError);
|
||||
CI.getASTConsumer().HandleTopLevelDecl(DGR);
|
||||
} else {
|
||||
llvm::consumeError(ToDOrError.takeError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +89,8 @@ class TestImportBase : public CompilerOptionSpecificTest,
|
||||
public ::testing::WithParamInterface<ArgVector> {
|
||||
|
||||
template <typename NodeType>
|
||||
NodeType importNode(ASTUnit *From, ASTUnit *To, ASTImporter &Importer,
|
||||
NodeType Node) {
|
||||
llvm::Expected<NodeType> importNode(ASTUnit *From, ASTUnit *To,
|
||||
ASTImporter &Importer, NodeType Node) {
|
||||
ASTContext &ToCtx = To->getASTContext();
|
||||
|
||||
// Add 'From' file to virtual file system so importer can 'find' it
|
||||
@ -100,17 +100,19 @@ class TestImportBase : public CompilerOptionSpecificTest,
|
||||
createVirtualFileIfNeeded(To, FromFileName,
|
||||
From->getBufferForFile(FromFileName));
|
||||
|
||||
auto Imported = Importer.Import(Node);
|
||||
auto Imported = Importer.Import_New(Node);
|
||||
|
||||
// This should dump source locations and assert if some source locations
|
||||
// were not imported.
|
||||
SmallString<1024> ImportChecker;
|
||||
llvm::raw_svector_ostream ToNothing(ImportChecker);
|
||||
ToCtx.getTranslationUnitDecl()->print(ToNothing);
|
||||
if (Imported) {
|
||||
// This should dump source locations and assert if some source locations
|
||||
// were not imported.
|
||||
SmallString<1024> ImportChecker;
|
||||
llvm::raw_svector_ostream ToNothing(ImportChecker);
|
||||
ToCtx.getTranslationUnitDecl()->print(ToNothing);
|
||||
|
||||
// This traverses the AST to catch certain bugs like poorly or not
|
||||
// implemented subtrees.
|
||||
Imported->dump(ToNothing);
|
||||
// This traverses the AST to catch certain bugs like poorly or not
|
||||
// implemented subtrees.
|
||||
(*Imported)->dump(ToNothing);
|
||||
}
|
||||
|
||||
return Imported;
|
||||
}
|
||||
@ -151,11 +153,16 @@ class TestImportBase : public CompilerOptionSpecificTest,
|
||||
EXPECT_TRUE(Verifier.match(ToImport, WrapperMatcher));
|
||||
|
||||
auto Imported = importNode(FromAST.get(), ToAST.get(), Importer, ToImport);
|
||||
if (!Imported)
|
||||
return testing::AssertionFailure() << "Import failed, nullptr returned!";
|
||||
if (!Imported) {
|
||||
std::string ErrorText;
|
||||
handleAllErrors(
|
||||
Imported.takeError(),
|
||||
[&ErrorText](const ImportError &Err) { ErrorText = Err.message(); });
|
||||
return testing::AssertionFailure()
|
||||
<< "Import failed, error: \"" << ErrorText << "\"!";
|
||||
}
|
||||
|
||||
|
||||
return Verifier.match(Imported, WrapperMatcher);
|
||||
return Verifier.match(*Imported, WrapperMatcher);
|
||||
}
|
||||
|
||||
template <typename NodeType>
|
||||
@ -277,7 +284,9 @@ public:
|
||||
EXPECT_TRUE(FoundDecl.size() == 1);
|
||||
const Decl *ToImport = selectFirst<Decl>(DeclToImportID, FoundDecl);
|
||||
auto Imported = importNode(From, To, *ImporterRef, ToImport);
|
||||
EXPECT_TRUE(Imported);
|
||||
EXPECT_TRUE(static_cast<bool>(Imported));
|
||||
if (!Imported)
|
||||
llvm::consumeError(Imported.takeError());
|
||||
}
|
||||
|
||||
// Find the declaration and import it.
|
||||
@ -339,13 +348,23 @@ class ASTImporterTestBase : public CompilerOptionSpecificTest {
|
||||
Decl *import(ASTImporterLookupTable &LookupTable, ASTUnit *ToAST,
|
||||
Decl *FromDecl) {
|
||||
lazyInitImporter(LookupTable, ToAST);
|
||||
return Importer->Import(FromDecl);
|
||||
if (auto ImportedOrErr = Importer->Import_New(FromDecl))
|
||||
return *ImportedOrErr;
|
||||
else {
|
||||
llvm::consumeError(ImportedOrErr.takeError());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QualType import(ASTImporterLookupTable &LookupTable, ASTUnit *ToAST,
|
||||
QualType FromType) {
|
||||
lazyInitImporter(LookupTable, ToAST);
|
||||
return Importer->Import(FromType);
|
||||
if (auto ImportedOrErr = Importer->Import_New(FromType))
|
||||
return *ImportedOrErr;
|
||||
else {
|
||||
llvm::consumeError(ImportedOrErr.takeError());
|
||||
return QualType{};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user