Lines Matching +full:class +full:- +full:dg
1 //===--- PrecompiledPreamble.cpp - Build precompiled preambles --*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Helper class to build precompiled preamble.
11 //===----------------------------------------------------------------------===//
28 #include "llvm/Config/llvm-config.h"
49 #warning "Unknown platform. Defaulting to UNIX-style paths for in-memory PCHs" in getInMemoryPreamblePath()
59 // so we create an in-memory VFS with just that and overlay it on top. in createVFSOverlayForPreamblePCH()
62 PCHFS->addFile(PCHFilename, 0, std::move(PCHBuffer)); in createVFSOverlayForPreamblePCH()
65 Overlay->pushOverlay(PCHFS); in createVFSOverlayForPreamblePCH()
69 class PreambleDependencyCollector : public DependencyCollector {
74 // spuriously added by '-isystem' (e.g. to suppress warnings from those
88 class MissingFileCollector : public PPCallbacks {
106 // (We have some false negatives if PP recovered e.g. <foo> -> "foo") in InclusionDirective()
128 if (IncludingFile->getDir()) in InclusionDirective()
129 NotFoundRelativeTo(IncludingFile->getDir()); in InclusionDirective()
143 class TemporaryFiles {
149 // Disallow constructing the class directly.
198 // so it's not intended to be used outside preamble-handling.
199 class TempPCHFile {
204 // crash-recovery testing, which is the only case where the preamble files in create()
212 // that we would never get a race condition in a multi-threaded setting in create()
221 llvm::sys::path::append(TempPath, "preamble-%%%%%%.pch"); in create()
223 // Use the same owner-only file permissions as fs::createTemporaryFile(). in create()
243 TemporaryFiles::getInstance().addFile(this->FilePath); in TempPCHFile()
249 class PrecompilePreambleAction : public ASTFrontendAction {
263 *FileOS << Buffer->Data; in setEmittedPreamblePCH()
268 this->HasEmittedPreamblePCH = true; in setEmittedPreamblePCH()
283 friend class PrecompilePreambleConsumer;
288 std::unique_ptr<llvm::raw_pwrite_stream> FileOS; // null if in-memory
292 class PrecompilePreambleConsumer : public PCHGenerator {
303 bool HandleTopLevelDecl(DeclGroupRef DG) override { in HandleTopLevelDecl() argument
304 Action.Callbacks.HandleTopLevelDecl(DG); in HandleTopLevelDecl()
344 template <class T> bool moveOnNoError(llvm::ErrorOr<T> Val, T &Output) { in moveOnNoError()
359 class PrecompiledPreamble::PCHStorage {
364 S->File = std::move(File); in file()
369 S->Memory = std::move(Buf); in inMemory()
373 enum class Kind { InMemory, TempFile };
383 return File->getFilePath(); in filePath()
387 return StringRef(Memory->Data.data(), Memory->Data.size()); in memoryContents()
390 // Shrink in-memory buffers to fit.
391 // This incurs a copy, but preambles tend to be long-lived.
396 Memory->Data = decltype(Memory->Data)(Memory->Data); in shrink()
423 FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts(); in Build()
425 PreambleInvocation->getPreprocessorOpts(); in Build()
443 std::vector<char> PreambleBytes(MainFileBuffer->getBufferStart(), in Build()
444 MainFileBuffer->getBufferStart() + in Build()
451 StoreInMemory ? getInMemoryPreamblePath() : Storage->filePath()); in Build()
465 Clang->setInvocation(std::move(PreambleInvocation)); in Build()
466 Clang->setDiagnostics(&Diagnostics); in Build()
469 if (!Clang->createTarget()) in Build()
472 if (Clang->getFrontendOpts().Inputs.size() != 1 || in Build()
473 Clang->getFrontendOpts().Inputs[0].getKind().getFormat() != in Build()
475 Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() == in Build()
482 ProcessWarningOptions(Diagnostics, Clang->getDiagnosticOpts()); in Build()
485 createVFSFromCompilerInvocation(Clang->getInvocation(), Diagnostics, VFS); in Build()
488 Clang->setFileManager(new FileManager(Clang->getFileSystemOpts(), VFS)); in Build()
491 Clang->setSourceManager( in Build()
492 new SourceManager(Diagnostics, Clang->getFileManager())); in Build()
495 Clang->addDependencyCollector(PreambleDepCollector); in Build()
497 Clang->getLangOpts().CompilingPCH = true; in Build()
502 MainFileBuffer->getBuffer().slice(0, Bounds.Size), MainFilePath); in Build()
515 /*WritePCHFile=*/Storage->getKind() == PCHStorage::Kind::TempFile, in Build()
517 if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) in Build()
520 // Performed after BeginSourceFile to ensure Clang->Preprocessor can be in Build()
527 Clang->getPreprocessor().addPPCallbacks(std::move(DelegatedPPCallbacks)); in Build()
529 Clang->getPreprocessor().addCommentHandler(CommentHandler); in Build()
531 Clang->getPreprocessor().addPPCallbacks( in Build()
533 MissingFiles, Clang->getPreprocessor().getHeaderSearchInfo(), in Build()
534 Clang->getSourceManager())); in Build()
536 if (llvm::Error Err = Act->Execute()) in Build()
542 Act->EndSourceFile(); in Build()
544 if (!Act->hasEmittedPreamblePCH()) in Build()
552 SourceManager &SourceMgr = Clang->getSourceManager(); in Build()
553 for (auto &Filename : PreambleDepCollector->getDependencies()) { in Build()
554 auto MaybeFile = Clang->getFileManager().getOptionalFileRef(Filename); in Build()
575 Storage->shrink(); in Build()
586 switch (Storage->getKind()) { in getSize()
588 return Storage->memoryContents().size(); in getSize()
591 if (llvm::sys::fs::file_size(Storage->filePath(), Result)) in getSize()
613 PreambleInvocation->getPreprocessorOpts(); in CanReuse()
617 // the main-file buffer within the precompiled preamble to fit the in CanReuse()
624 // The preamble has not changed. We may be able to re-use the precompiled in CanReuse()
652 PreambleFileHash::createForMemoryBuffer(RB.second->getMemBufferRef()); in CanReuse()
670 if (OverridenFileBuffer->second != F.second) in CanReuse()
685 // This file was remapped; check whether the newly-mapped file in CanReuse()
687 if (Overridden->second != F.second) in CanReuse()
704 // consider the preamble out-of-date. in CanReuse()
706 if (Status->isRegularFile()) in CanReuse()
736 assert(this->Storage != nullptr); in PrecompiledPreamble()
799 if (VFS == RealFS || VFS->exists(PCHPath)) in setupPreambleStorage()
801 auto Buf = RealFS->getBufferForFile(PCHPath); in setupPreambleStorage()
809 // We have a slight inconsistency here -- we're using the VFS to in setupPreambleStorage()
814 // For in-memory preamble, we have to provide a VFS overlay that makes it in setupPreambleStorage()
828 void PreambleCallbacks::HandleTopLevelDecl(DeclGroupRef DG) {} in HandleTopLevelDecl() argument
841 return "build-preamble.error"; in name()