mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-14 03:29:57 +00:00
[clang][lldb][NFC] Encapsulate ExternalASTMerger::ImporterSource
NFC preparation work for upcoming ExternalASTMerger patches. llvm-svn: 373312
This commit is contained in:
parent
f58d01930f
commit
cf62871488
@ -80,10 +80,17 @@ public:
|
||||
/// import SourceLocations properly. Additionally, when import occurs for
|
||||
/// a DeclContext whose origin has been overridden, then this
|
||||
/// ExternalASTMerger must be able to determine that.
|
||||
struct ImporterSource {
|
||||
class ImporterSource {
|
||||
ASTContext *
|
||||
FileManager &FM;
|
||||
const OriginMap &OM;
|
||||
|
||||
public:
|
||||
ImporterSource(ASTContext &_AST, FileManager &_FM, const OriginMap &_OM)
|
||||
: AST(_AST), FM(_FM), OM(_OM) {}
|
||||
ASTContext &getASTContext() const { return AST; }
|
||||
FileManager &getFileManager() const { return FM; }
|
||||
const OriginMap &getOriginMap() const { return OM; }
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -105,15 +105,16 @@ private:
|
||||
llvm::raw_ostream &logs() { return Parent.logs(); }
|
||||
public:
|
||||
LazyASTImporter(ExternalASTMerger &_Parent, ASTContext &ToContext,
|
||||
FileManager &ToFileManager, ASTContext &FromContext,
|
||||
FileManager &FromFileManager,
|
||||
const ExternalASTMerger::OriginMap &_FromOrigins,
|
||||
FileManager &ToFileManager,
|
||||
const ExternalASTMerger::ImporterSource &_Source,
|
||||
std::shared_ptr<ASTImporterSharedState> SharedState)
|
||||
: ASTImporter(ToContext, ToFileManager, FromContext, FromFileManager,
|
||||
: ASTImporter(ToContext, ToFileManager, _Source.getASTContext(),
|
||||
_Source.getFileManager(),
|
||||
/*MinimalImport=*/true, SharedState),
|
||||
Parent(_Parent), Reverse(FromContext, FromFileManager, ToContext,
|
||||
ToFileManager, /*MinimalImport=*/true),
|
||||
FromOrigins(_FromOrigins) {}
|
||||
Parent(_Parent),
|
||||
Reverse(_Source.getASTContext(), _Source.getFileManager(), ToContext,
|
||||
ToFileManager, /*MinimalImport=*/true),
|
||||
FromOrigins(_Source.getOriginMap()) {}
|
||||
|
||||
/// Whenever a DeclContext is imported, ensure that ExternalASTSource's origin
|
||||
/// map is kept up to date. Also set the appropriate flags.
|
||||
@ -323,23 +324,23 @@ ExternalASTMerger::ExternalASTMerger(const ImporterTarget &Target,
|
||||
|
||||
void ExternalASTMerger::AddSources(llvm::ArrayRef<ImporterSource> Sources) {
|
||||
for (const ImporterSource &S : Sources) {
|
||||
assert(&S.AST != &Target.AST);
|
||||
assert(&S.getASTContext() != &Target.AST);
|
||||
Importers.push_back(std::make_unique<LazyASTImporter>(
|
||||
*this, Target.AST, Target.FM, S.AST, S.FM, S.OM, SharedState));
|
||||
*this, Target.AST, Target.FM, S, SharedState));
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalASTMerger::RemoveSources(llvm::ArrayRef<ImporterSource> Sources) {
|
||||
if (LoggingEnabled())
|
||||
for (const ImporterSource &S : Sources)
|
||||
logs() << "(ExternalASTMerger*)" << (void*)this
|
||||
<< " removing source (ASTContext*)" << (void*)&S.AST
|
||||
logs() << "(ExternalASTMerger*)" << (void *)this
|
||||
<< " removing source (ASTContext*)" << (void *)&S.getASTContext()
|
||||
<< "\n";
|
||||
Importers.erase(
|
||||
std::remove_if(Importers.begin(), Importers.end(),
|
||||
[&Sources](std::unique_ptr<ASTImporter> &Importer) -> bool {
|
||||
for (const ImporterSource &S : Sources) {
|
||||
if (&Importer->getFromContext() == &S.AST)
|
||||
if (&Importer->getFromContext() == &S.getASTContext())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -349,7 +350,7 @@ void ExternalASTMerger::RemoveSources(llvm::ArrayRef<ImporterSource> Sources) {
|
||||
std::pair<const DeclContext *, DCOrigin> Origin = *OI;
|
||||
bool Erase = false;
|
||||
for (const ImporterSource &S : Sources) {
|
||||
if (&S.AST == Origin.second.AST) {
|
||||
if (&S.getASTContext() == Origin.second.AST) {
|
||||
Erase = true;
|
||||
break;
|
||||
}
|
||||
|
@ -263,8 +263,8 @@ void AddExternalSource(CIAndOrigins &CI,
|
||||
{CI.getASTContext(), CI.getFileManager()});
|
||||
llvm::SmallVector<ExternalASTMerger::ImporterSource, 3> Sources;
|
||||
for (CIAndOrigins &Import : Imports)
|
||||
Sources.push_back({Import.getASTContext(), Import.getFileManager(),
|
||||
Import.getOriginMap()});
|
||||
Sources.emplace_back(Import.getASTContext(), Import.getFileManager(),
|
||||
Import.getOriginMap());
|
||||
auto ES = std::make_unique<ExternalASTMerger>(Target, Sources);
|
||||
CI.getASTContext().setExternalSource(ES.release());
|
||||
CI.getASTContext().getTranslationUnitDecl()->setHasExternalVisibleStorage();
|
||||
|
@ -84,9 +84,9 @@ void ClangASTSource::InstallASTContext(clang::ASTContext &ast_context,
|
||||
&type_system_or_err.get())) {
|
||||
lldbassert(module_ast_ctx->getASTContext());
|
||||
lldbassert(module_ast_ctx->getFileManager());
|
||||
sources.push_back({*module_ast_ctx->getASTContext(),
|
||||
*module_ast_ctx->getFileManager(),
|
||||
module_ast_ctx->GetOriginMap()});
|
||||
sources.emplace_back(*module_ast_ctx->getASTContext(),
|
||||
*module_ast_ctx->getFileManager(),
|
||||
module_ast_ctx->GetOriginMap());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,8 +277,8 @@ static clang::QualType ExportAllDeclaredTypes(
|
||||
clang::FileManager &source_file_manager,
|
||||
const clang::ExternalASTMerger::OriginMap &source_origin_map,
|
||||
clang::FileID file, clang::QualType root) {
|
||||
clang::ExternalASTMerger::ImporterSource importer_source = {
|
||||
source, source_file_manager, source_origin_map};
|
||||
clang::ExternalASTMerger::ImporterSource importer_source(
|
||||
source, source_file_manager, source_origin_map);
|
||||
merger.AddSources(importer_source);
|
||||
clang::ASTImporter &exporter = merger.ImporterForOrigin(source);
|
||||
CompleteAllDeclContexts(exporter, file, root);
|
||||
|
@ -573,8 +573,9 @@ ClangModulesDeclVendorImpl::DoGetModule(clang::ModuleIdPath path,
|
||||
|
||||
clang::ExternalASTMerger::ImporterSource
|
||||
ClangModulesDeclVendorImpl::GetImporterSource() {
|
||||
return {m_compiler_instance->getASTContext(),
|
||||
m_compiler_instance->getFileManager(), m_origin_map};
|
||||
return clang::ExternalASTMerger::ImporterSource(
|
||||
m_compiler_instance->getASTContext(),
|
||||
m_compiler_instance->getFileManager(), m_origin_map);
|
||||
}
|
||||
|
||||
static const char *ModuleImportBufferName = "LLDBModulesMemoryBuffer";
|
||||
|
@ -657,8 +657,7 @@ AppleObjCDeclVendor::FindDecls(ConstString name, bool append,
|
||||
|
||||
clang::ExternalASTMerger::ImporterSource
|
||||
AppleObjCDeclVendor::GetImporterSource() {
|
||||
return {*m_ast_ctx.getASTContext(),
|
||||
*m_ast_ctx.getFileManager(),
|
||||
m_ast_ctx.GetOriginMap()
|
||||
};
|
||||
return clang::ExternalASTMerger::ImporterSource(*m_ast_ctx.getASTContext(),
|
||||
*m_ast_ctx.getFileManager(),
|
||||
m_ast_ctx.GetOriginMap());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user