Skip to content
Permalink
Browse files

clang ASTImporter interface changes

  • Loading branch information
balazske committed Nov 7, 2018
1 parent 55ee900 commit 7085d20a03e41f26abfa4db63ae14b29f659072f
@@ -1982,7 +1982,13 @@ clang::QualType ClangASTSource::CopyTypeWithMerger(
return QualType();
}

return merger.ImporterForOrigin(from_context).Import(type);
llvm::Expected<QualType> type_or_error = merger.ImporterForOrigin(from_context).Import(type);
if (!type_or_error) {
lldbassert(0 && "Couldn't import a type!");
llvm::consumeError(type_or_error.takeError());
return QualType();
}
return *type_or_error;
}

clang::Decl *ClangASTSource::CopyDecl(Decl *src_decl) {
@@ -1995,7 +2001,13 @@ clang::Decl *ClangASTSource::CopyDecl(Decl *src_decl) {
return nullptr;
}

return m_merger_up->ImporterForOrigin(from_context).Import(src_decl);
llvm::Expected<Decl *> decl_or_error = m_merger_up->ImporterForOrigin(from_context).Import(src_decl);
if (!decl_or_error) {
lldbassert(0 && "Couldn't import a decl!");
llvm::consumeError(decl_or_error.takeError());
return nullptr;
}
return *decl_or_error;
} else {
lldbassert(0 && "No mechanism for copying a decl!");
return nullptr;
@@ -237,7 +237,7 @@ class Completer : public clang::RecursiveASTVisitor<Completer> {
public:
Completer(clang::ASTImporter &exporter, clang::FileID file)
: m_exporter(exporter), m_file(file) {}

// Implements the RecursiveASTVisitor's core API. It is called on each Decl
// that the RecursiveASTVisitor encounters, and returns true if the traversal
// should continue.
@@ -272,9 +272,14 @@ static clang::QualType ExportAllDeclaredTypes(
merger.AddSources(importer_source);
clang::ASTImporter &exporter = merger.ImporterForOrigin(source);
CompleteAllDeclContexts(exporter, file, root);
clang::QualType ret = exporter.Import(root);
llvm::Expected<clang::QualType> ret_or_error = exporter.Import(root);
merger.RemoveSources(importer_source);
return ret;
if (ret_or_error)
return *ret_or_error;
else {
llvm::consumeError(ret_or_error.takeError());
return clang::QualType();
}
}

TypeFromUser ClangExpressionDeclMap::DeportType(ClangASTContext &target,
@@ -283,7 +288,7 @@ TypeFromUser ClangExpressionDeclMap::DeportType(ClangASTContext &target,
assert (&target == m_target->GetScratchClangASTContext());
assert ((TypeSystem*)&source == parser_type.GetTypeSystem());
assert (source.getASTContext() == m_ast_context);

if (m_ast_importer_sp) {
return TypeFromUser(m_ast_importer_sp->DeportType(
target.getASTContext(), source.getASTContext(),
@@ -822,7 +827,7 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
log->Printf(" CEDM::FEVD[%u] Inspecting (NamespaceMap*)%p (%d entries)",
current_id, static_cast<void *>(namespace_map.get()),
(int)namespace_map->size());

for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(),
e = namespace_map->end();
i != e; ++i) {
@@ -842,7 +847,7 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
FindExternalVisibleDecls(context, lldb::ModuleSP(), namespace_decl,
current_id);
}

ClangASTSource::FindExternalVisibleDecls(context);
}

@@ -1979,18 +1984,18 @@ void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
if (copied_function_template) {
if (log) {
ASTDumper ast_dumper((clang::Decl *)copied_function_template);

StreamString ss;

function->DumpSymbolContext(&ss);

log->Printf(" CEDM::FEVD[%u] Imported decl for function template"
" %s (description %s), returned %s",
current_id,
copied_function_template->getNameAsString().c_str(),
ss.GetData(), ast_dumper.GetCString());
}

context.AddNamedDecl(copied_function_template);
}
} else if (src_function_decl) {
@@ -1220,7 +1220,12 @@ clang::Decl *ClangASTContext::CopyDecl(ASTContext *dst_ast, ASTContext *src_ast,
FileManager file_manager(file_system_options);
ASTImporter importer(*dst_ast, file_manager, *src_ast, file_manager, false);

return importer.Import(source_decl);
if (llvm::Expected<clang::Decl *> ret_or_error = importer.Import(source_decl))
return *ret_or_error;
else {
llvm::consumeError(ret_or_error.takeError());
return nullptr;
}
}

bool ClangASTContext::AreTypesSame(CompilerType type1, CompilerType type2,
@@ -57,8 +57,12 @@ clang::QualType ClangASTImporter::CopyType(clang::ASTContext *dst_ast,
clang::QualType type) {
MinionSP minion_sp(GetMinion(dst_ast, src_ast));

if (minion_sp)
return minion_sp->Import(type);
if (minion_sp) {
if (llvm::Expected<QualType> ret_or_error = minion_sp->Import(type))
return *ret_or_error;
else
llvm::consumeError(ret_or_error.takeError());
}

return QualType();
}
@@ -99,7 +103,7 @@ clang::Decl *ClangASTImporter::CopyDecl(clang::ASTContext *dst_ast,
minion_sp = GetMinion(dst_ast, src_ast);

if (minion_sp) {
clang::Decl *result = minion_sp->Import(decl);
llvm::Expected<clang::Decl *> result = minion_sp->Import(decl);

if (!result) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
@@ -120,9 +124,14 @@ clang::Decl *ClangASTImporter::CopyDecl(clang::ASTContext *dst_ast,
"metadata 0x%" PRIx64,
decl->getDeclKindName(), user_id);
}

// FIXME: Include error information in log message.
llvm::consumeError(result.takeError());

return nullptr;
}

return result;
return *result;
}

return nullptr;
@@ -916,13 +925,15 @@ void ClangASTImporter::Minion::ImportDefinitionTo(clang::Decl *to,
if (!from_superclass)
break;

Decl *imported_from_superclass_decl = Import(from_superclass);
llvm::Expected<Decl *> imported_from_superclass_decl = Import(from_superclass);

if (!imported_from_superclass_decl)
if (!imported_from_superclass_decl) {
llvm::consumeError(imported_from_superclass_decl.takeError());
break;
}

ObjCInterfaceDecl *imported_from_superclass =
dyn_cast<ObjCInterfaceDecl>(imported_from_superclass_decl);
dyn_cast<ObjCInterfaceDecl>(*imported_from_superclass_decl);

if (!imported_from_superclass)
break;

0 comments on commit 7085d20

Please sign in to comment.
You can’t perform that action at this time.