diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-03 22:45:23 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-03 22:45:23 +0000 |
commit | 389db16c63eec6ecfa9b235155252d8da766e94e (patch) | |
tree | fee8c776b8591a09c1387bcc7dd3bd1bccb14e7e /lib/Serialization/ASTReader.cpp | |
parent | f1410802d1c9e7ff72b2818ad91fd85283abc6bf (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118203 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTReader.cpp')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 5c947bc639..b90203b477 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/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), |