diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Frontend/ASTUnit.cpp | 134 |
1 files changed, 64 insertions, 70 deletions
diff --git a/contrib/llvm/tools/clang/lib/Frontend/ASTUnit.cpp b/contrib/llvm/tools/clang/lib/Frontend/ASTUnit.cpp index 1bb5c3f..e6ba292 100644 --- a/contrib/llvm/tools/clang/lib/Frontend/ASTUnit.cpp +++ b/contrib/llvm/tools/clang/lib/Frontend/ASTUnit.cpp @@ -1,4 +1,4 @@ -//===--- ASTUnit.cpp - ASTUnit utility ------------------------------------===// +//===--- ASTUnit.cpp - ASTUnit utility --------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -47,6 +47,7 @@ #include <atomic> #include <cstdio> #include <cstdlib> + using namespace clang; using llvm::TimeRecord; @@ -185,7 +186,7 @@ struct ASTUnit::ASTWriterData { llvm::BitstreamWriter Stream; ASTWriter Writer; - ASTWriterData() : Stream(Buffer), Writer(Stream) { } + ASTWriterData() : Stream(Buffer), Writer(Stream, { }) { } }; void ASTUnit::clearFileLevelDecls() { @@ -649,12 +650,12 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags, } std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile( - const std::string &Filename, - const PCHContainerReader &PCHContainerRdr, + const std::string &Filename, const PCHContainerReader &PCHContainerRdr, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, - const FileSystemOptions &FileSystemOpts, bool OnlyLocalDecls, - ArrayRef<RemappedFile> RemappedFiles, bool CaptureDiagnostics, - bool AllowPCHWithCompilerErrors, bool UserFilesAreVolatile) { + const FileSystemOptions &FileSystemOpts, bool UseDebugInfo, + bool OnlyLocalDecls, ArrayRef<RemappedFile> RemappedFiles, + bool CaptureDiagnostics, bool AllowPCHWithCompilerErrors, + bool UserFilesAreVolatile) { std::unique_ptr<ASTUnit> AST(new ASTUnit(true)); // Recover resources if we crash before exiting this method. @@ -708,7 +709,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile( bool disableValid = false; if (::getenv("LIBCLANG_DISABLE_PCH_VALIDATION")) disableValid = true; - AST->Reader = new ASTReader(PP, Context, PCHContainerRdr, + AST->Reader = new ASTReader(PP, Context, PCHContainerRdr, { }, /*isysroot=*/"", /*DisableValidation=*/disableValid, AllowPCHWithCompilerErrors); @@ -926,6 +927,7 @@ public: const Preprocessor &PP, StringRef isysroot, raw_ostream *Out) : PCHGenerator(PP, "", nullptr, isysroot, std::make_shared<PCHBuffer>(), + ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>>(), /*AllowASTWithErrors=*/true), Unit(Unit), Hash(Unit.getCurrentTopLevelHashValue()), Action(Action), Out(Out) { @@ -973,7 +975,7 @@ public: } }; -} +} // anonymous namespace std::unique_ptr<ASTConsumer> PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI, @@ -1076,11 +1078,10 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps, // Configure the various subsystems. LangOpts = Clang->getInvocation().LangOpts; FileSystemOpts = Clang->getFileSystemOpts(); - IntrusiveRefCntPtr<vfs::FileSystem> VFS = - createVFSFromCompilerInvocation(Clang->getInvocation(), getDiagnostics()); - if (!VFS) - return true; - FileMgr = new FileManager(FileSystemOpts, VFS); + if (!FileMgr) { + Clang->createFileManager(); + FileMgr = &Clang->getFileManager(); + } SourceMgr = new SourceManager(getDiagnostics(), *FileMgr, UserFilesAreVolatile); TheSema.reset(); @@ -1724,9 +1725,10 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( std::shared_ptr<PCHContainerOperations> PCHContainerOps, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, ASTFrontendAction *Action, ASTUnit *Unit, bool Persistent, StringRef ResourceFilesPath, - bool OnlyLocalDecls, bool CaptureDiagnostics, bool PrecompilePreamble, - bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, - bool UserFilesAreVolatile, std::unique_ptr<ASTUnit> *ErrAST) { + bool OnlyLocalDecls, bool CaptureDiagnostics, + unsigned PrecompilePreambleAfterNParses, bool CacheCodeCompletionResults, + bool IncludeBriefCommentsInCodeCompletion, bool UserFilesAreVolatile, + std::unique_ptr<ASTUnit> *ErrAST) { assert(CI && "A CompilerInvocation is required"); std::unique_ptr<ASTUnit> OwnAST; @@ -1745,8 +1747,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( } AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; - if (PrecompilePreamble) - AST->PreambleRebuildCounter = 2; + if (PrecompilePreambleAfterNParses > 0) + AST->PreambleRebuildCounter = PrecompilePreambleAfterNParses; AST->TUKind = Action ? Action->getTranslationUnitKind() : TU_Complete; AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults; AST->IncludeBriefCommentsInCodeCompletion @@ -1863,7 +1865,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( bool ASTUnit::LoadFromCompilerInvocation( std::shared_ptr<PCHContainerOperations> PCHContainerOps, - bool PrecompilePreamble) { + unsigned PrecompilePreambleAfterNParses) { if (!Invocation) return true; @@ -1873,8 +1875,8 @@ bool ASTUnit::LoadFromCompilerInvocation( ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts()); std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer; - if (PrecompilePreamble) { - PreambleRebuildCounter = 2; + if (PrecompilePreambleAfterNParses > 0) { + PreambleRebuildCounter = PrecompilePreambleAfterNParses; OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation); } @@ -1892,10 +1894,11 @@ bool ASTUnit::LoadFromCompilerInvocation( std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation( CompilerInvocation *CI, std::shared_ptr<PCHContainerOperations> PCHContainerOps, - IntrusiveRefCntPtr<DiagnosticsEngine> Diags, bool OnlyLocalDecls, - bool CaptureDiagnostics, bool PrecompilePreamble, - TranslationUnitKind TUKind, bool CacheCodeCompletionResults, - bool IncludeBriefCommentsInCodeCompletion, bool UserFilesAreVolatile) { + IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr, + bool OnlyLocalDecls, bool CaptureDiagnostics, + unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind, + bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, + bool UserFilesAreVolatile) { // Create the AST unit. std::unique_ptr<ASTUnit> AST(new ASTUnit(false)); ConfigureDiags(Diags, *AST, CaptureDiagnostics); @@ -1907,12 +1910,8 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation( AST->IncludeBriefCommentsInCodeCompletion = IncludeBriefCommentsInCodeCompletion; AST->Invocation = CI; - AST->FileSystemOpts = CI->getFileSystemOpts(); - IntrusiveRefCntPtr<vfs::FileSystem> VFS = - createVFSFromCompilerInvocation(*CI, *Diags); - if (!VFS) - return nullptr; - AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS); + AST->FileSystemOpts = FileMgr->getFileSystemOpts(); + AST->FileMgr = FileMgr; AST->UserFilesAreVolatile = UserFilesAreVolatile; // Recover resources if we crash before exiting this method. @@ -1922,7 +1921,8 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation( llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> > DiagCleanup(Diags.get()); - if (AST->LoadFromCompilerInvocation(PCHContainerOps, PrecompilePreamble)) + if (AST->LoadFromCompilerInvocation(PCHContainerOps, + PrecompilePreambleAfterNParses)) return nullptr; return AST; } @@ -1933,11 +1933,11 @@ ASTUnit *ASTUnit::LoadFromCommandLine( IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath, bool OnlyLocalDecls, bool CaptureDiagnostics, ArrayRef<RemappedFile> RemappedFiles, bool RemappedFilesKeepOriginalName, - bool PrecompilePreamble, TranslationUnitKind TUKind, + unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind, bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, bool AllowPCHWithCompilerErrors, bool SkipFunctionBodies, bool UserFilesAreVolatile, bool ForSerialization, - std::unique_ptr<ASTUnit> *ErrAST) { + llvm::Optional<StringRef> ModuleFormat, std::unique_ptr<ASTUnit> *ErrAST) { assert(Diags.get() && "no DiagnosticsEngine was provided"); SmallVector<StoredDiagnostic, 4> StoredDiagnostics; @@ -1970,6 +1970,9 @@ ASTUnit *ASTUnit::LoadFromCommandLine( CI->getFrontendOpts().SkipFunctionBodies = SkipFunctionBodies; + if (ModuleFormat) + CI->getHeaderSearchOpts().ModuleFormat = ModuleFormat.getValue(); + // Create the AST unit. std::unique_ptr<ASTUnit> AST; AST.reset(new ASTUnit(false)); @@ -2001,7 +2004,8 @@ ASTUnit *ASTUnit::LoadFromCommandLine( llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit> ASTUnitCleanup(AST.get()); - if (AST->LoadFromCompilerInvocation(PCHContainerOps, PrecompilePreamble)) { + if (AST->LoadFromCompilerInvocation(PCHContainerOps, + PrecompilePreambleAfterNParses)) { // Some error occurred, if caller wants to examine diagnostics, pass it the // ASTUnit. if (ErrAST) { @@ -2043,6 +2047,7 @@ bool ASTUnit::Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps, getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation); // Clear out the diagnostics state. + FileMgr.reset(); getDiagnostics().Reset(); ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts()); if (OverrideMainBuffer) @@ -2124,7 +2129,7 @@ namespace { return Next.getCodeCompletionTUInfo(); } }; -} +} // anonymous namespace /// \brief Helper function that computes which global names are hidden by the /// local code-completion results. @@ -2210,7 +2215,6 @@ static void CalculateHiddenNames(const CodeCompletionContext &Context, } } - void AugmentedCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, @@ -2504,7 +2508,7 @@ bool ASTUnit::serialize(raw_ostream &OS) { SmallString<128> Buffer; llvm::BitstreamWriter Stream(Buffer); - ASTWriter Writer(Stream); + ASTWriter Writer(Stream, { }); return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS); } @@ -2782,39 +2786,29 @@ bool ASTUnit::visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn) { return true; } -namespace { -struct PCHLocatorInfo { - serialization::ModuleFile *Mod; - PCHLocatorInfo() : Mod(nullptr) {} -}; -} - -static bool PCHLocator(serialization::ModuleFile &M, void *UserData) { - PCHLocatorInfo &Info = *static_cast<PCHLocatorInfo*>(UserData); - switch (M.Kind) { - case serialization::MK_ImplicitModule: - case serialization::MK_ExplicitModule: - return true; // skip dependencies. - case serialization::MK_PCH: - Info.Mod = &M; - return true; // found it. - case serialization::MK_Preamble: - return false; // look in dependencies. - case serialization::MK_MainFile: - return false; // look in dependencies. - } - - return true; -} - const FileEntry *ASTUnit::getPCHFile() { if (!Reader) return nullptr; - PCHLocatorInfo Info; - Reader->getModuleManager().visit(PCHLocator, &Info); - if (Info.Mod) - return Info.Mod->File; + serialization::ModuleFile *Mod = nullptr; + Reader->getModuleManager().visit([&Mod](serialization::ModuleFile &M) { + switch (M.Kind) { + case serialization::MK_ImplicitModule: + case serialization::MK_ExplicitModule: + return true; // skip dependencies. + case serialization::MK_PCH: + Mod = &M; + return true; // found it. + case serialization::MK_Preamble: + return false; // look in dependencies. + case serialization::MK_MainFile: + return false; // look in dependencies. + } + + return true; + }); + if (Mod) + return Mod->File; return nullptr; } @@ -2854,9 +2848,9 @@ void ASTUnit::ConcurrencyState::finish() { #else // NDEBUG -ASTUnit::ConcurrencyState::ConcurrencyState() { Mutex = 0; } +ASTUnit::ConcurrencyState::ConcurrencyState() { Mutex = nullptr; } ASTUnit::ConcurrencyState::~ConcurrencyState() {} void ASTUnit::ConcurrencyState::start() {} void ASTUnit::ConcurrencyState::finish() {} -#endif +#endif // NDEBUG |