//===----------------------------------------------------------------------===//
#include "Preamble.h"
+#include "Compiler.h"
#include "Logger.h"
#include "Trace.h"
#include "clang/Basic/SourceLocation.h"
} // namespace
-PreambleData::PreambleData(llvm::StringRef Version,
+PreambleData::PreambleData(const ParseInputs &Inputs,
PrecompiledPreamble Preamble,
std::vector<Diag> Diags, IncludeStructure Includes,
MainFileMacros Macros,
std::unique_ptr<PreambleFileStatusCache> StatCache,
CanonicalIncludes CanonIncludes)
- : Version(Version), Preamble(std::move(Preamble)), Diags(std::move(Diags)),
+ : Version(Inputs.Version), CompileCommand(Inputs.CompileCommand),
+ Preamble(std::move(Preamble)), Diags(std::move(Diags)),
Includes(std::move(Includes)), Macros(std::move(Macros)),
StatCache(std::move(StatCache)), CanonIncludes(std::move(CanonIncludes)) {
}
std::shared_ptr<const PreambleData>
buildPreamble(PathRef FileName, CompilerInvocation &CI,
std::shared_ptr<const PreambleData> OldPreamble,
- const tooling::CompileCommand &OldCompileCommand,
const ParseInputs &Inputs, bool StoreInMemory,
PreambleParsedCallback PreambleCallback) {
// Note that we don't need to copy the input contents, preamble can live
ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0);
if (OldPreamble &&
- compileCommandsAreEqual(Inputs.CompileCommand, OldCompileCommand) &&
+ compileCommandsAreEqual(Inputs.CompileCommand,
+ OldPreamble->CompileCommand) &&
OldPreamble->Preamble.CanReuse(CI, ContentsBuffer.get(), Bounds,
Inputs.FS.get())) {
vlog("Reusing preamble version {0} for version {1} of {2}",
BuiltPreamble->getSize(), FileName, Inputs.Version);
std::vector<Diag> Diags = PreambleDiagnostics.take();
return std::make_shared<PreambleData>(
- Inputs.Version, std::move(*BuiltPreamble), std::move(Diags),
+ Inputs, std::move(*BuiltPreamble), std::move(Diags),
SerializedDeclsCollector.takeIncludes(),
SerializedDeclsCollector.takeMacros(), std::move(StatCache),
SerializedDeclsCollector.takeCanonicalIncludes());
/// As we must avoid re-parsing the preamble, any information that can only
/// be obtained during parsing must be eagerly captured and stored here.
struct PreambleData {
- PreambleData(llvm::StringRef Version, PrecompiledPreamble Preamble,
+ PreambleData(const ParseInputs &Inputs, PrecompiledPreamble Preamble,
std::vector<Diag> Diags, IncludeStructure Includes,
MainFileMacros Macros,
std::unique_ptr<PreambleFileStatusCache> StatCache,
std::shared_ptr<const PreambleData>
buildPreamble(PathRef FileName, CompilerInvocation &CI,
std::shared_ptr<const PreambleData> OldPreamble,
- const tooling::CompileCommand &OldCompileCommand,
const ParseInputs &Inputs, bool StoreInMemory,
PreambleParsedCallback PreambleCallback);
std::tie(PrevInputs->CompileCommand, PrevInputs->Contents) ==
std::tie(Inputs.CompileCommand, Inputs.Contents);
- tooling::CompileCommand OldCommand = PrevInputs->CompileCommand;
bool RanCallbackForPrevInputs = RanASTCallback;
{
std::lock_guard<std::mutex> Lock(Mutex);
Inputs.ForceRebuild ? std::shared_ptr<const PreambleData>()
: getPossiblyStalePreamble();
std::shared_ptr<const PreambleData> NewPreamble = buildPreamble(
- FileName, *Invocation, OldPreamble, OldCommand, Inputs,
- StorePreambleInMemory,
+ FileName, *Invocation, OldPreamble, Inputs, StorePreambleInMemory,
[this, Version(Inputs.Version)](
ASTContext &Ctx, std::shared_ptr<clang::Preprocessor> PP,
const CanonicalIncludes &CanonIncludes) {
FileIndex Index;
bool IndexUpdated = false;
- buildPreamble(
- FooCpp, *CI, /*OldPreamble=*/nullptr, tooling::CompileCommand(), PI,
- /*StoreInMemory=*/true,
- [&](ASTContext &Ctx, std::shared_ptr<Preprocessor> PP,
- const CanonicalIncludes &CanonIncludes) {
- EXPECT_FALSE(IndexUpdated) << "Expected only a single index update";
- IndexUpdated = true;
- Index.updatePreamble(FooCpp, /*Version=*/"null", Ctx, std::move(PP),
- CanonIncludes);
- });
+ buildPreamble(FooCpp, *CI, /*OldPreamble=*/nullptr, PI,
+ /*StoreInMemory=*/true,
+ [&](ASTContext &Ctx, std::shared_ptr<Preprocessor> PP,
+ const CanonicalIncludes &CanonIncludes) {
+ EXPECT_FALSE(IndexUpdated)
+ << "Expected only a single index update";
+ IndexUpdated = true;
+ Index.updatePreamble(FooCpp, /*Version=*/"null", Ctx,
+ std::move(PP), CanonIncludes);
+ });
ASSERT_TRUE(IndexUpdated);
// Check the index contains symbols from the preamble, but not from the main
assert(CI && "Failed to build compilation invocation.");
auto Preamble =
buildPreamble(FullFilename, *CI,
- /*OldPreamble=*/nullptr,
- /*OldCompileCommand=*/Inputs.CompileCommand, Inputs,
+ /*OldPreamble=*/nullptr, Inputs,
/*StoreInMemory=*/true, /*PreambleCallback=*/nullptr);
auto AST =
buildAST(FullFilename, std::move(CI), Diags.take(), Inputs, Preamble);