[cfe-commits] r167504 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp
Douglas Gregor
dgregor at apple.com
Tue Nov 6 15:40:54 PST 2012
Author: dgregor
Date: Tue Nov 6 17:40:54 2012
New Revision: 167504
URL: http://llvm.org/viewvc/llvm-project?rev=167504&view=rev
Log:
Tease out the routine that reads the control block of an AST file from
the validation of an AST file against a specific set of options.
Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=167504&r1=167503&r2=167504&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Nov 6 17:40:54 2012
@@ -1160,6 +1160,13 @@
FileManager &FileMgr,
DiagnosticsEngine &Diags);
+ /// \brief Read the control block for the named AST file.
+ ///
+ /// \returns true if an error occurred, false otherwise.
+ static bool readASTFileControlBlock(StringRef Filename,
+ FileManager &FileMgr,
+ ASTReaderListener &Listener);
+
/// \brief Determine whether the given AST file is acceptable to load into a
/// translation unit with the given language and target options.
static bool isAcceptableASTFile(StringRef Filename,
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=167504&r1=167503&r2=167504&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Nov 6 17:40:54 2012
@@ -3127,17 +3127,15 @@
};
}
-bool ASTReader::isAcceptableASTFile(StringRef Filename,
- FileManager &FileMgr,
- const LangOptions &LangOpts,
- const TargetOptions &TargetOpts,
- const PreprocessorOptions &PPOpts) {
+bool ASTReader::readASTFileControlBlock(StringRef Filename,
+ FileManager &FileMgr,
+ ASTReaderListener &Listener) {
// Open the AST file.
std::string ErrStr;
OwningPtr<llvm::MemoryBuffer> Buffer;
Buffer.reset(FileMgr.getBufferForFile(Filename, &ErrStr));
if (!Buffer) {
- return false;
+ return true;
}
// Initialize the stream
@@ -3152,10 +3150,9 @@
Stream.Read(8) != 'P' ||
Stream.Read(8) != 'C' ||
Stream.Read(8) != 'H') {
- return false;
+ return true;
}
- SimplePCHValidator Validator(LangOpts, TargetOpts, PPOpts, FileMgr);
RecordData Record;
bool InControlBlock = false;
while (!Stream.AtEndOfStream()) {
@@ -3168,7 +3165,7 @@
switch (BlockID) {
case CONTROL_BLOCK_ID:
if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) {
- return false;
+ return true;
} else {
InControlBlock = true;
}
@@ -3176,7 +3173,7 @@
default:
if (Stream.SkipBlock())
- return false;
+ return true;
break;
}
continue;
@@ -3184,8 +3181,9 @@
if (Code == llvm::bitc::END_BLOCK) {
if (Stream.ReadBlockEnd()) {
- return false;
+ return true;
}
+
InControlBlock = false;
continue;
}
@@ -3203,46 +3201,46 @@
switch ((ControlRecordTypes)RecCode) {
case METADATA: {
if (Record[0] != VERSION_MAJOR) {
- return false;
+ return true;
}
const std::string &CurBranch = getClangFullRepositoryVersion();
StringRef ASTBranch(BlobStart, BlobLen);
if (StringRef(CurBranch) != ASTBranch)
- return false;
+ return true;
break;
}
case LANGUAGE_OPTIONS:
- if (ParseLanguageOptions(Record, false, Validator))
- return false;
+ if (ParseLanguageOptions(Record, false, Listener))
+ return true;
break;
case TARGET_OPTIONS:
- if (ParseTargetOptions(Record, false, Validator))
- return false;
+ if (ParseTargetOptions(Record, false, Listener))
+ return true;
break;
case DIAGNOSTIC_OPTIONS:
- if (ParseDiagnosticOptions(Record, false, Validator))
- return false;
+ if (ParseDiagnosticOptions(Record, false, Listener))
+ return true;
break;
case FILE_SYSTEM_OPTIONS:
- if (ParseFileSystemOptions(Record, false, Validator))
- return false;
+ if (ParseFileSystemOptions(Record, false, Listener))
+ return true;
break;
case HEADER_SEARCH_OPTIONS:
- if (ParseHeaderSearchOptions(Record, false, Validator))
- return false;
+ if (ParseHeaderSearchOptions(Record, false, Listener))
+ return true;
break;
case PREPROCESSOR_OPTIONS: {
std::string IgnoredSuggestedPredefines;
- if (ParsePreprocessorOptions(Record, false, Validator,
+ if (ParsePreprocessorOptions(Record, false, Listener,
IgnoredSuggestedPredefines))
- return false;
+ return true;
break;
}
@@ -3253,7 +3251,17 @@
}
}
- return true;
+ return false;
+}
+
+
+bool ASTReader::isAcceptableASTFile(StringRef Filename,
+ FileManager &FileMgr,
+ const LangOptions &LangOpts,
+ const TargetOptions &TargetOpts,
+ const PreprocessorOptions &PPOpts) {
+ SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts, FileMgr);
+ return !readASTFileControlBlock(Filename, FileMgr, validator);
}
bool ASTReader::ReadSubmoduleBlock(ModuleFile &F) {
More information about the cfe-commits
mailing list