createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot,
bool DisablePCHValidation,
Preprocessor &PP, ASTContext &Context,
- void *DeserializationListener);
+ void *DeserializationListener, bool Preamble);
/// Create a code completion consumer using the invocation; note that this
/// will cause the source manager to truncate the input source file at the
public ExternalSLocEntrySource {
public:
enum ASTReadResult { Success, Failure, IgnorePCH };
+ /// \brief Types of AST files.
+ enum ASTFileType {
+ Module, ///< File is a module proper.
+ PCH, ///< File is a PCH file treated as such.
+ Preamble, ///< File is a PCH file treated as the preamble.
+ MainFile ///< File is a PCH file treated as the actual main file.
+ };
friend class PCHValidator;
friend class ASTDeclReader;
friend class ASTStmtReader;
/// \brief Information that is needed for every module.
struct PerFileData {
- PerFileData();
+ PerFileData(ASTFileType Ty);
~PerFileData();
// === General information ===
+ /// \brief The type of this AST file.
+ ASTFileType Type;
+
/// \brief The file name of the AST file.
std::string FileName;
void MaybeAddSystemRootToFilename(std::string &Filename);
- ASTReadResult ReadASTCore(llvm::StringRef FileName);
+ ASTReadResult ReadASTCore(llvm::StringRef FileName, ASTFileType Type);
ASTReadResult ReadASTBlock(PerFileData &F);
bool CheckPredefinesBuffers();
bool ParseLineTable(PerFileData &F, llvm::SmallVectorImpl<uint64_t> &Record);
/// \brief Load the precompiled header designated by the given file
/// name.
- ASTReadResult ReadAST(const std::string &FileName);
+ ASTReadResult ReadAST(const std::string &FileName, ASTFileType Type);
/// \brief Set the AST callbacks listener.
void setListener(ASTReaderListener *listener) {
Reader->setListener(new ASTInfoCollector(LangInfo, HeaderInfo, TargetTriple,
Predefines, Counter));
- switch (Reader->ReadAST(Filename)) {
+ switch (Reader->ReadAST(Filename, ASTReader::MainFile)) {
case ASTReader::Success:
break;
if (!getOnlyLocalDecls())
return Decl::MaxPCHLevel;
- unsigned Result = 0;
- if (isMainFileAST() || SavedMainFileBuffer)
- ++Result;
- return Result;
+ return 0;
}
ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
bool DisablePCHValidation,
void *DeserializationListener){
llvm::OwningPtr<ExternalASTSource> Source;
+ bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
DisablePCHValidation,
getPreprocessor(), getASTContext(),
- DeserializationListener));
+ DeserializationListener,
+ Preamble));
getASTContext().setExternalSource(Source);
}
bool DisablePCHValidation,
Preprocessor &PP,
ASTContext &Context,
- void *DeserializationListener) {
+ void *DeserializationListener,
+ bool Preamble) {
llvm::OwningPtr<ASTReader> Reader;
Reader.reset(new ASTReader(PP, &Context,
Sysroot.empty() ? 0 : Sysroot.c_str(),
Reader->setDeserializationListener(
static_cast<ASTDeserializationListener *>(DeserializationListener));
- switch (Reader->ReadAST(Path)) {
+ switch (Reader->ReadAST(Path,
+ Preamble ? ASTReader::Preamble : ASTReader::PCH)) {
case ASTReader::Success:
// Set the predefines buffer as suggested by the PCH reader. Typically, the
// predefines buffer will be empty.
return IgnorePCH;
}
- // Load the chained file.
- switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen))) {
+ // Load the chained file, which is always a PCH file.
+ switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) {
case Failure: return Failure;
// If we have to ignore the dependency, we'll have to ignore this too.
case IgnorePCH: return IgnorePCH;
return Failure;
}
-ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName) {
- switch(ReadASTCore(FileName)) {
+ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
+ ASTFileType Type) {
+ switch(ReadASTCore(FileName, Type)) {
case Failure: return Failure;
case IgnorePCH: return IgnorePCH;
case Success: break;
return Success;
}
-ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName) {
+ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName,
+ ASTFileType Type) {
PerFileData *Prev = Chain.empty() ? 0 : Chain.back();
- Chain.push_back(new PerFileData());
+ Chain.push_back(new PerFileData(Type));
PerFileData &F = *Chain.back();
if (Prev)
Prev->NextInSource = &F;
}
}
-ASTReader::PerFileData::PerFileData()
- : SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0),
+ASTReader::PerFileData::PerFileData(ASTFileType Ty)
+ : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0),
LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0),
IdentifierLookupTable(0), LocalNumMacroDefinitions(0),
MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0),
D->setImplicit(Record[Idx++]);
D->setUsed(Record[Idx++]);
D->setAccess((AccessSpecifier)Record[Idx++]);
- D->setPCHLevel(Record[Idx++] + 1);
+ D->setPCHLevel(Record[Idx++] + (F.Type <= ASTReader::PCH));
}
void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {