[cfe-commits] r115626 - in /cfe/trunk: include/clang/Frontend/CompilerInstance.h include/clang/Serialization/ASTReader.h lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInstance.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTReaderDecl.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Tue Oct 5 09:15:20 PDT 2010
Author: cornedbee
Date: Tue Oct 5 11:15:19 2010
New Revision: 115626
URL: http://llvm.org/viewvc/llvm-project?rev=115626&view=rev
Log:
Give every file that ASTReader loads a type: module, PCH, precompiled preamble or main file. Base Decls' PCHLevel on this to make it more sane.
Modified:
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=115626&r1=115625&r2=115626&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Tue Oct 5 11:15:19 2010
@@ -534,7 +534,7 @@
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
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=115626&r1=115625&r2=115626&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Oct 5 11:15:19 2010
@@ -170,6 +170,13 @@
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;
@@ -201,11 +208,14 @@
/// \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;
@@ -695,7 +705,7 @@
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);
@@ -776,7 +786,7 @@
/// \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) {
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=115626&r1=115625&r2=115626&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Oct 5 11:15:19 2010
@@ -479,7 +479,7 @@
Reader->setListener(new ASTInfoCollector(LangInfo, HeaderInfo, TargetTriple,
Predefines, Counter));
- switch (Reader->ReadAST(Filename)) {
+ switch (Reader->ReadAST(Filename, ASTReader::MainFile)) {
case ASTReader::Success:
break;
@@ -1305,10 +1305,7 @@
if (!getOnlyLocalDecls())
return Decl::MaxPCHLevel;
- unsigned Result = 0;
- if (isMainFileAST() || SavedMainFileBuffer)
- ++Result;
- return Result;
+ return 0;
}
ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=115626&r1=115625&r2=115626&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue Oct 5 11:15:19 2010
@@ -251,10 +251,12 @@
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);
}
@@ -264,7 +266,8 @@
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(),
@@ -272,7 +275,8 @@
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.
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=115626&r1=115625&r2=115626&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Oct 5 11:15:19 2010
@@ -1746,8 +1746,8 @@
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;
@@ -2025,8 +2025,9 @@
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;
@@ -2124,9 +2125,10 @@
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;
@@ -4215,8 +4217,8 @@
}
}
-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),
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=115626&r1=115625&r2=115626&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Tue Oct 5 11:15:19 2010
@@ -168,7 +168,7 @@
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) {
More information about the cfe-commits
mailing list