summaryrefslogtreecommitdiffstats
path: root/lib/Lex/HeaderMap.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
commit389db16c63eec6ecfa9b235155252d8da766e94e (patch)
treefee8c776b8591a09c1387bcc7dd3bd1bccb14e7e /lib/Lex/HeaderMap.cpp
parentf1410802d1c9e7ff72b2818ad91fd85283abc6bf (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/Lex/HeaderMap.cpp')
-rw-r--r--lib/Lex/HeaderMap.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/Lex/HeaderMap.cpp b/lib/Lex/HeaderMap.cpp
index 4010d613ac..5d9b218a7d 100644
--- a/lib/Lex/HeaderMap.cpp
+++ b/lib/Lex/HeaderMap.cpp
@@ -75,13 +75,14 @@ static inline unsigned HashHMapKey(llvm::StringRef Str) {
/// map. If it doesn't look like a HeaderMap, it gives up and returns null.
/// If it looks like a HeaderMap but is obviously corrupted, it puts a reason
/// into the string error argument and returns null.
-const HeaderMap *HeaderMap::Create(const FileEntry *FE) {
+const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM,
+ const FileSystemOptions &FSOpts) {
// If the file is too small to be a header map, ignore it.
unsigned FileSize = FE->getSize();
if (FileSize <= sizeof(HMapHeader)) return 0;
llvm::OwningPtr<const llvm::MemoryBuffer> FileBuffer(
- llvm::MemoryBuffer::getFile(FE->getName(), 0, FE->getSize()));
+ FM.getBufferForFile(FE, FSOpts));
if (FileBuffer == 0) return 0; // Unreadable file?
const char *FileStart = FileBuffer->getBufferStart();
@@ -200,7 +201,8 @@ void HeaderMap::dump() const {
/// LookupFile - Check to see if the specified relative filename is located in
/// this HeaderMap. If so, open it and return its FileEntry.
const FileEntry *HeaderMap::LookupFile(llvm::StringRef Filename,
- FileManager &FM) const {
+ FileManager &FM,
+ const FileSystemOptions &FileSystemOpts) const {
const HMapHeader &Hdr = getHeader();
unsigned NumBuckets = getEndianAdjustedWord(Hdr.NumBuckets);
@@ -223,6 +225,6 @@ const FileEntry *HeaderMap::LookupFile(llvm::StringRef Filename,
llvm::SmallString<1024> DestPath;
DestPath += getString(B.Prefix);
DestPath += getString(B.Suffix);
- return FM.getFile(DestPath.begin(), DestPath.end());
+ return FM.getFile(DestPath.begin(), DestPath.end(), FileSystemOpts);
}
}