summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization/ASTReader.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-11-03 22:45:23 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-11-03 22:45:23 +0000
commit71731d6b05db0fd5ff6c2e0641b050599706ae02 (patch)
tree662dbb298a9ba35a0e003756388af16da7f753f6 /clang/lib/Serialization/ASTReader.cpp
parentef43990bb89741d779777bebd75e0bbb2c4172bf (diff)
downloadbcm5719-llvm-71731d6b05db0fd5ff6c2e0641b050599706ae02.tar.gz
bcm5719-llvm-71731d6b05db0fd5ff6c2e0641b050599706ae02.zip
Implement -working-directory.
When -working-directory is passed in command line, file paths are resolved relative to the specified directory. This helps both when using libclang (where we can't require the user to actually change the working directory) and to help reproduce test cases when the reproduction work comes along. --FileSystemOptions is introduced which controls how file system operations are performed (currently it just contains the working directory value if set). --FileSystemOptions are passed around to various interfaces that perform file operations. --Opening & reading the content of files should be done only through FileManager. This is useful in general since file operations will be abstracted in the future for the reproduction mechanism. FileSystemOptions is independent of FileManager so that we can have multiple translation units sharing the same FileManager but with different FileSystemOptions. Addresses rdar://8583824. llvm-svn: 118203
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r--clang/lib/Serialization/ASTReader.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 5c947bc6395..b90203b477b 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1234,7 +1234,7 @@ ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) {
case SM_SLOC_FILE_ENTRY: {
std::string Filename(BlobStart, BlobStart + BlobLen);
MaybeAddSystemRootToFilename(Filename);
- const FileEntry *File = FileMgr.getFile(Filename);
+ const FileEntry *File = FileMgr.getFile(Filename, FileSystemOpts);
if (File == 0) {
std::string ErrorStr = "could not find file '";
ErrorStr += Filename;
@@ -1549,7 +1549,8 @@ void ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) {
const char *FullFileNameStart = BlobStart + Record[3];
const FileEntry *File
= PP->getFileManager().getFile(FullFileNameStart,
- FullFileNameStart + (BlobLen - Record[3]));
+ FullFileNameStart + (BlobLen - Record[3]),
+ FileSystemOpts);
// FIXME: Stable encoding
InclusionDirective::InclusionKind Kind
@@ -2257,7 +2258,10 @@ ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName,
//
// FIXME: This shouldn't be here, we should just take a raw_ostream.
std::string ErrStr;
- F.Buffer.reset(llvm::MemoryBuffer::getFileOrSTDIN(FileName, &ErrStr));
+ if (FileName == "-")
+ F.Buffer.reset(llvm::MemoryBuffer::getSTDIN(&ErrStr));
+ else
+ F.Buffer.reset(FileMgr.getBufferForFile(FileName, FileSystemOpts, &ErrStr));
if (!F.Buffer) {
Error(ErrStr.c_str());
return IgnorePCH;
@@ -2459,11 +2463,13 @@ void ASTReader::InitializeContext(ASTContext &Ctx) {
/// directly from the AST file, without actually loading the AST
/// file.
std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName,
+ FileManager &FileMgr,
+ const FileSystemOptions &FSOpts,
Diagnostic &Diags) {
// Open the AST file.
std::string ErrStr;
llvm::OwningPtr<llvm::MemoryBuffer> Buffer;
- Buffer.reset(llvm::MemoryBuffer::getFile(ASTFileName.c_str(), &ErrStr));
+ Buffer.reset(FileMgr.getBufferForFile(ASTFileName, FSOpts, &ErrStr));
if (!Buffer) {
Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr;
return std::string();
@@ -4477,6 +4483,7 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context,
const char *isysroot, bool DisableValidation)
: Listener(new PCHValidator(PP, *this)), DeserializationListener(0),
SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),
+ FileSystemOpts(PP.getFileSystemOpts()),
Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context),
Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation),
NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0),
@@ -4490,9 +4497,11 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context,
}
ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
+ const FileSystemOptions &FileSystemOpts,
Diagnostic &Diags, const char *isysroot,
bool DisableValidation)
: DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr),
+ FileSystemOpts(FileSystemOpts),
Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0),
isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0),
NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0),
OpenPOWER on IntegriCloud