aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--include/clang/AST/ASTImporter.h7
-rw-r--r--include/clang/Basic/FileManager.h63
-rw-r--r--include/clang/Basic/FileSystemOptions.h29
-rw-r--r--include/clang/Basic/SourceManager.h15
-rw-r--r--include/clang/Driver/CC1Options.td5
-rw-r--r--include/clang/Driver/Options.td5
-rw-r--r--include/clang/Frontend/ASTUnit.h15
-rw-r--r--include/clang/Frontend/CompilerInstance.h9
-rw-r--r--include/clang/Frontend/CompilerInvocation.h9
-rw-r--r--include/clang/Frontend/Utils.h2
-rw-r--r--include/clang/Lex/HeaderMap.h7
-rw-r--r--include/clang/Lex/HeaderSearch.h5
-rw-r--r--include/clang/Lex/PTHManager.h4
-rw-r--r--include/clang/Lex/Preprocessor.h3
-rw-r--r--include/clang/Serialization/ASTReader.h7
-rw-r--r--lib/AST/ASTImporter.cpp8
-rw-r--r--lib/Basic/FileManager.cpp60
-rw-r--r--lib/Basic/SourceManager.cpp7
-rw-r--r--lib/Driver/Driver.cpp17
-rw-r--r--lib/Driver/Tools.cpp2
-rw-r--r--lib/Frontend/ASTMerge.cpp7
-rw-r--r--lib/Frontend/ASTUnit.cpp33
-rw-r--r--lib/Frontend/CompilerInstance.cpp32
-rw-r--r--lib/Frontend/CompilerInvocation.cpp28
-rw-r--r--lib/Frontend/FrontendAction.cpp5
-rw-r--r--lib/Frontend/FrontendActions.cpp5
-rw-r--r--lib/Frontend/InitHeaderSearch.cpp5
-rw-r--r--lib/Frontend/InitPreprocessor.cpp12
-rw-r--r--lib/Lex/HeaderMap.cpp10
-rw-r--r--lib/Lex/HeaderSearch.cpp30
-rw-r--r--lib/Lex/PTHLexer.cpp6
-rw-r--r--lib/Lex/Preprocessor.cpp3
-rw-r--r--lib/Serialization/ASTReader.cpp17
-rw-r--r--test/Misc/Inputs/working-directory.h1
-rw-r--r--test/Misc/working-directory.c5
-rw-r--r--tools/libclang/CIndex.cpp7
-rw-r--r--tools/libclang/CIndexCodeCompletion.cpp11
-rw-r--r--tools/libclang/CIndexer.h6
38 files changed, 398 insertions, 104 deletions
diff --git a/include/clang/AST/ASTImporter.h b/include/clang/AST/ASTImporter.h
index a1c4d5399e..1ad33990f2 100644
--- a/include/clang/AST/ASTImporter.h
+++ b/include/clang/AST/ASTImporter.h
@@ -28,6 +28,7 @@ namespace clang {
class Diagnostic;
class Expr;
class FileManager;
+ class FileSystemOptions;
class IdentifierInfo;
class NestedNameSpecifier;
class Stmt;
@@ -45,6 +46,8 @@ namespace clang {
/// \brief The file managers we're importing to and from.
FileManager &ToFileManager, &FromFileManager;
+
+ const FileSystemOptions &ToFileSystemOpts, &FromFileSystemOpts;
/// \brief The diagnostics object that we should use to emit diagnostics.
Diagnostic &Diags;
@@ -76,7 +79,9 @@ namespace clang {
public:
ASTImporter(Diagnostic &Diags,
ASTContext &ToContext, FileManager &ToFileManager,
- ASTContext &FromContext, FileManager &FromFileManager);
+ const FileSystemOptions &ToFileSystemOpts,
+ ASTContext &FromContext, FileManager &FromFileManager,
+ const FileSystemOptions &FromFileSystemOpts);
virtual ~ASTImporter();
diff --git a/include/clang/Basic/FileManager.h b/include/clang/Basic/FileManager.h
index e71f51a0e7..44a7079edd 100644
--- a/include/clang/Basic/FileManager.h
+++ b/include/clang/Basic/FileManager.h
@@ -24,8 +24,16 @@
#include <sys/types.h>
#include <sys/stat.h>
+namespace llvm {
+class MemoryBuffer;
+namespace sys {
+class Path;
+}
+}
+
namespace clang {
class FileManager;
+class FileSystemOptions;
/// DirectoryEntry - Cached information about one directory on the disk.
///
@@ -162,9 +170,8 @@ class FileManager {
// Caching.
llvm::OwningPtr<StatSysCallCache> StatCache;
- int stat_cached(const char* path, struct stat* buf) {
- return StatCache.get() ? StatCache->stat(path, buf) : stat(path, buf);
- }
+ int stat_cached(const char* path, struct stat* buf,
+ const FileSystemOptions &FileSystemOpts);
public:
FileManager();
@@ -189,25 +196,61 @@ public:
/// getDirectory - Lookup, cache, and verify the specified directory. This
/// returns null if the directory doesn't exist.
///
- const DirectoryEntry *getDirectory(llvm::StringRef Filename) {
- return getDirectory(Filename.begin(), Filename.end());
+ const DirectoryEntry *getDirectory(llvm::StringRef Filename,
+ const FileSystemOptions &FileSystemOpts) {
+ return getDirectory(Filename.begin(), Filename.end(), FileSystemOpts);
}
- const DirectoryEntry *getDirectory(const char *FileStart,const char *FileEnd);
+ const DirectoryEntry *getDirectory(const char *FileStart,const char *FileEnd,
+ const FileSystemOptions &FileSystemOpts);
/// getFile - Lookup, cache, and verify the specified file. This returns null
/// if the file doesn't exist.
///
- const FileEntry *getFile(llvm::StringRef Filename) {
- return getFile(Filename.begin(), Filename.end());
+ const FileEntry *getFile(llvm::StringRef Filename,
+ const FileSystemOptions &FileSystemOpts) {
+ return getFile(Filename.begin(), Filename.end(), FileSystemOpts);
}
const FileEntry *getFile(const char *FilenameStart,
- const char *FilenameEnd);
+ const char *FilenameEnd,
+ const FileSystemOptions &FileSystemOpts);
/// \brief Retrieve a file entry for a "virtual" file that acts as
/// if there were a file with the given name on disk. The file
/// itself is not accessed.
const FileEntry *getVirtualFile(llvm::StringRef Filename, off_t Size,
- time_t ModificationTime);
+ time_t ModificationTime,
+ const FileSystemOptions &FileSystemOpts);
+
+ /// \brief Open the specified file as a MemoryBuffer, returning a new
+ /// MemoryBuffer if successful, otherwise returning null.
+ llvm::MemoryBuffer *getBufferForFile(const FileEntry *Entry,
+ const FileSystemOptions &FileSystemOpts,
+ std::string *ErrorStr = 0,
+ struct stat *FileInfo = 0) {
+ return getBufferForFile(Entry->getName(), FileSystemOpts,
+ ErrorStr, Entry->getSize(), FileInfo);
+ }
+ llvm::MemoryBuffer *getBufferForFile(llvm::StringRef Filename,
+ const FileSystemOptions &FileSystemOpts,
+ std::string *ErrorStr = 0,
+ int64_t FileSize = -1,
+ struct stat *FileInfo = 0) {
+ return getBufferForFile(Filename.begin(), Filename.end(), FileSystemOpts,
+ ErrorStr, FileSize, FileInfo);
+ }
+ llvm::MemoryBuffer *getBufferForFile(const char *FilenameStart,
+ const char *FilenameEnd,
+ const FileSystemOptions &FileSystemOpts,
+ std::string *ErrorStr = 0,
+ int64_t FileSize = -1,
+ struct stat *FileInfo = 0);
+
+ /// \brief If path is not absolute and FileSystemOptions set the working
+ /// directory, the path is modified to be relative to the given
+ /// working directory.
+ static void FixupRelativePath(llvm::sys::Path &path,
+ const FileSystemOptions &FSOpts);
+
void PrintStats() const;
};
diff --git a/include/clang/Basic/FileSystemOptions.h b/include/clang/Basic/FileSystemOptions.h
new file mode 100644
index 0000000000..4f3c2ae03d
--- /dev/null
+++ b/include/clang/Basic/FileSystemOptions.h
@@ -0,0 +1,29 @@
+//===--- FileSystemOptions.h - File System Options --------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the FileSystemOptions interface.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_FILESYSTEMOPTIONS_H
+#define LLVM_CLANG_BASIC_FILESYSTEMOPTIONS_H
+
+namespace clang {
+
+/// \brief Keeps track of options that affect how file operations are performed.
+class FileSystemOptions {
+public:
+ /// \brief If set, paths are resolved as if the working directory was
+ /// set to the value of WorkingDir.
+ std::string WorkingDir;
+};
+
+} // end namespace clang
+
+#endif
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 2098698400..4f5c17344d 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -33,6 +33,7 @@ namespace clang {
class Diagnostic;
class SourceManager;
class FileManager;
+class FileSystemOptions;
class FileEntry;
class LineTableInfo;
@@ -369,7 +370,10 @@ public:
class SourceManager {
/// \brief Diagnostic object.
Diagnostic &Diag;
-
+
+ FileManager &FileMgr;
+ const FileSystemOptions &FileSystemOpts;
+
mutable llvm::BumpPtrAllocator ContentCacheAlloc;
/// FileInfos - Memoized information about all of the files tracked by this
@@ -427,8 +431,10 @@ class SourceManager {
explicit SourceManager(const SourceManager&);
void operator=(const SourceManager&);
public:
- SourceManager(Diagnostic &Diag)
- : Diag(Diag), ExternalSLocEntries(0), LineTable(0), NumLinearScans(0),
+ SourceManager(Diagnostic &Diag, FileManager &FileMgr,
+ const FileSystemOptions &FSOpts)
+ : Diag(Diag), FileMgr(FileMgr), FileSystemOpts(FSOpts),
+ ExternalSLocEntries(0), LineTable(0), NumLinearScans(0),
NumBinaryProbes(0) {
clearIDTables();
}
@@ -438,6 +444,9 @@ public:
Diagnostic &getDiagnostics() const { return Diag; }
+ FileManager &getFileManager() const { return FileMgr; }
+ const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
+
//===--------------------------------------------------------------------===//
// MainFileID creation and querying methods.
//===--------------------------------------------------------------------===//
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 8a967d033a..dee123ddd4 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -366,6 +366,11 @@ def create_module : Flag<"-create-module">,
def import_module : Separate<"-import-module">,
HelpText<"Import a module definition file">;
+def working_directory : JoinedOrSeparate<"-working-directory">,
+ HelpText<"Resolve file paths relative to the specified directory">;
+def working_directory_EQ : Joined<"-working-directory=">,
+ Alias<working_directory>;
+
def relocatable_pch : Flag<"-relocatable-pch">,
HelpText<"Whether to build a relocatable precompiled header">;
def chained_pch : Flag<"-chained-pch">,
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index da762becb6..907639f58b 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -624,6 +624,11 @@ def x : JoinedOrSeparate<"-x">, Flags<[DriverOption]>,
MetaVarName<"<language>">;
def y : Joined<"-y">;
+def working_directory : Separate<"-working-directory">,
+ HelpText<"Resolve file paths relative to the specified directory">;
+def working_directory_EQ : Joined<"-working-directory=">,
+ Alias<working_directory>;
+
// Double dash options, which are usually an alias for one of the previous
// options.
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h
index 45f771763d..980cd54cb3 100644
--- a/include/clang/Frontend/ASTUnit.h
+++ b/include/clang/Frontend/ASTUnit.h
@@ -21,6 +21,7 @@
#include "clang/Lex/PreprocessingRecord.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
#include "clang-c/Index.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/OwningPtr.h"
@@ -68,7 +69,9 @@ private:
llvm::OwningPtr<TargetInfo> Target;
llvm::OwningPtr<Preprocessor> PP;
llvm::OwningPtr<ASTContext> Ctx;
-
+
+ FileSystemOptions FileSystemOpts;
+
/// \brief The AST consumer that received information about the translation
/// unit as it was parsed or loaded.
llvm::OwningPtr<ASTConsumer> Consumer;
@@ -359,6 +362,8 @@ public:
const FileManager &getFileManager() const { return *FileMgr; }
FileManager &getFileManager() { return *FileMgr; }
+ const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
+
const std::string &getOriginalSourceFileName();
const std::string &getASTFileName();
@@ -452,7 +457,12 @@ public:
unsigned cached_completion_size() const {
return CachedCompletionResults.size();
}
-
+
+ llvm::MemoryBuffer *getBufferForFile(llvm::StringRef Filename,
+ std::string *ErrorStr = 0,
+ int64_t FileSize = -1,
+ struct stat *FileInfo = 0);
+
/// \brief Whether this AST represents a complete translation unit.
///
/// If false, this AST is only a partial translation unit, e.g., one
@@ -473,6 +483,7 @@ public:
/// \returns - The initialized ASTUnit or null if the AST failed to load.
static ASTUnit *LoadFromASTFile(const std::string &Filename,
llvm::IntrusiveRefCntPtr<Diagnostic> Diags,
+ const FileSystemOptions &FileSystemOpts,
bool OnlyLocalDecls = false,
RemappedFile *RemappedFiles = 0,
unsigned NumRemappedFiles = 0,
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h
index e5121e1bf9..3db6077029 100644
--- a/include/clang/Frontend/CompilerInstance.h
+++ b/include/clang/Frontend/CompilerInstance.h
@@ -220,6 +220,10 @@ public:
return Invocation->getDiagnosticOpts();
}
+ const FileSystemOptions &getFileSystemOpts() const {
+ return Invocation->getFileSystemOpts();
+ }
+
FrontendOptions &getFrontendOpts() {
return Invocation->getFrontendOpts();
}
@@ -499,7 +503,8 @@ public:
void createFileManager();
/// Create the source manager and replace any existing one with it.
- void createSourceManager();
+ void createSourceManager(FileManager &FileMgr,
+ const FileSystemOptions &FSOpts);
/// Create the preprocessor, using the invocation, file, and source managers,
/// and replace any existing one with it.
@@ -517,6 +522,7 @@ public:
const DependencyOutputOptions &,
const TargetInfo &,
const FrontendOptions &,
+ const FileSystemOptions &,
SourceManager &, FileManager &);
/// Create the AST context.
@@ -617,6 +623,7 @@ public:
static bool InitializeSourceManager(llvm::StringRef InputFile,
Diagnostic &Diags,
FileManager &FileMgr,
+ const FileSystemOptions &FSOpts,
SourceManager &SourceMgr,
const FrontendOptions &Opts);
diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h
index aef02448f0..641c5f6650 100644
--- a/include/clang/Frontend/CompilerInvocation.h
+++ b/include/clang/Frontend/CompilerInvocation.h
@@ -12,6 +12,7 @@
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/TargetOptions.h"
+#include "clang/Basic/FileSystemOptions.h"
#include "clang/Frontend/AnalyzerOptions.h"
#include "clang/Frontend/CodeGenOptions.h"
#include "clang/Frontend/DependencyOutputOptions.h"
@@ -52,6 +53,9 @@ class CompilerInvocation {
/// Options controlling the diagnostic engine.
DiagnosticOptions DiagnosticOpts;
+ /// Options controlling file system operations.
+ FileSystemOptions FileSystemOpts;
+
/// Options controlling the frontend itself.
FrontendOptions FrontendOpts;
@@ -126,6 +130,11 @@ public:
DiagnosticOptions &getDiagnosticOpts() { return DiagnosticOpts; }
const DiagnosticOptions &getDiagnosticOpts() const { return DiagnosticOpts; }
+ FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
+ const FileSystemOptions &getFileSystemOpts() const {
+ return FileSystemOpts;
+ }
+
HeaderSearchOptions &getHeaderSearchOpts() { return HeaderSearchOpts; }
const HeaderSearchOptions &getHeaderSearchOpts() const {
return HeaderSearchOpts;
diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h
index fe722db381..ff075445b4 100644
--- a/include/clang/Frontend/Utils.h
+++ b/include/clang/Frontend/Utils.h
@@ -39,6 +39,7 @@ class SourceManager;
class Stmt;
class TargetInfo;
class FrontendOptions;
+class FileSystemOptions;
/// Normalize \arg File for use in a user defined #include directive (in the
/// predefines buffer).
@@ -53,6 +54,7 @@ void ApplyHeaderSearchOptions(HeaderSearch &HS,
/// InitializePreprocessor - Initialize the preprocessor getting it and the
/// environment ready to process a single file.
void InitializePreprocessor(Preprocessor &PP,
+ const FileSystemOptions &FSOpts,
const PreprocessorOptions &PPOpts,
const HeaderSearchOptions &HSOpts,
const FrontendOptions &FEOpts);
diff --git a/include/clang/Lex/HeaderMap.h b/include/clang/Lex/HeaderMap.h
index 9837e29653..4f17ae3ec3 100644
--- a/include/clang/Lex/HeaderMap.h
+++ b/include/clang/Lex/HeaderMap.h
@@ -21,6 +21,7 @@ namespace llvm {
namespace clang {
class FileEntry;
class FileManager;
+ class FileSystemOptions;
struct HMapBucket;
struct HMapHeader;
@@ -43,11 +44,13 @@ public:
/// HeaderMap::Create - This attempts to load the specified file as a header
/// map. If it doesn't look like a HeaderMap, it gives up and returns null.
- static const HeaderMap *Create(const FileEntry *FE);
+ static const HeaderMap *Create(const FileEntry *FE, FileManager &FM,
+ const FileSystemOptions &FSOpts);
/// LookupFile - Check to see if the specified relative filename is located in
/// this HeaderMap. If so, open it and return its FileEntry.
- const FileEntry *LookupFile(llvm::StringRef Filename, FileManager &FM) const;
+ const FileEntry *LookupFile(llvm::StringRef Filename, FileManager &FM,
+ const FileSystemOptions &FileSystemOpts) const;
/// getFileName - Return the filename of the headermap.
const char *getFileName() const;
diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h
index 80b38dee06..7d467a5680 100644
--- a/include/clang/Lex/HeaderSearch.h
+++ b/include/clang/Lex/HeaderSearch.h
@@ -23,6 +23,7 @@ namespace clang {
class ExternalIdentifierLookup;
class FileEntry;
class FileManager;
+class FileSystemOptions;
class IdentifierInfo;
/// HeaderFileInfo - The preprocessor keeps track of this information for each
@@ -71,6 +72,7 @@ struct HeaderFileInfo {
/// file referenced by a #include or #include_next, (sub-)framework lookup, etc.
class HeaderSearch {
FileManager &FileMgr;
+ const FileSystemOptions &FileSystemOpts;
/// #include search path information. Requests for #include "x" search the
/// directory of the #including file first, then each directory in SearchDirs
@@ -118,10 +120,11 @@ class HeaderSearch {
explicit HeaderSearch(const HeaderSearch&);
void operator=(const HeaderSearch&);
public:
- HeaderSearch(FileManager &FM);
+ HeaderSearch(FileManager &FM, const FileSystemOptions &FSOpts);
~HeaderSearch();
FileManager &getFileMgr() const { return FileMgr; }
+ const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
/// SetSearchPaths - Interface for setting the file search paths.
///
diff --git a/include/clang/Lex/PTHManager.h b/include/clang/Lex/PTHManager.h
index 5e8a4f144c..a3787e3ffe 100644
--- a/include/clang/Lex/PTHManager.h
+++ b/include/clang/Lex/PTHManager.h
@@ -119,7 +119,9 @@ public:
/// Create - This method creates PTHManager objects. The 'file' argument
/// is the name of the PTH file. This method returns NULL upon failure.
- static PTHManager *Create(const std::string& file, Diagnostic &Diags);
+ static PTHManager *Create(const std::string& file, FileManager &FileMgr,
+ const FileSystemOptions &FSOpts,
+ Diagnostic &Diags);
void setPreprocessor(Preprocessor *pp) { PP = pp; }
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 7b138884e0..b45f47bf11 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -35,6 +35,7 @@ namespace clang {
class SourceManager;
class ExternalPreprocessorSource;
class FileManager;
+class FileSystemOptions;
class FileEntry;
class HeaderSearch;
class PragmaNamespace;
@@ -57,6 +58,7 @@ class Preprocessor {
LangOptions Features;
const TargetInfo &Target;
FileManager &FileMgr;
+ const FileSystemOptions &FileSystemOpts;
SourceManager &SourceMgr;
ScratchBuffer *ScratchBuf;
HeaderSearch &HeaderInfo;
@@ -279,6 +281,7 @@ public:
const LangOptions &getLangOptions() const { return Features; }
const TargetInfo &getTargetInfo() const { return Target; }
FileManager &getFileManager() const { return FileMgr; }
+ const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
SourceManager &getSourceManager() const { return SourceMgr; }
HeaderSearch &getHeaderSearchInfo() const { return HeaderInfo; }
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index 9ac7c31852..420197c260 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -67,6 +67,7 @@ class ASTDeclReader;
class ASTStmtReader;
class ASTIdentifierLookupTrait;
class TypeLocReader;
+class FileSystemOptions;
struct HeaderFileInfo;
struct PCHPredefinesBlock {
@@ -193,6 +194,7 @@ private:
SourceManager &SourceMgr;
FileManager &FileMgr;
+ const FileSystemOptions &FileSystemOpts;
Diagnostic &Diags;
/// \brief The semantic analysis object that will be processing the
@@ -802,7 +804,8 @@ public:
/// \param DisableValidation If true, the AST reader will suppress most
/// of its regular consistency checking, allowing the use of precompiled
/// headers that cannot be determined to be compatible.
- ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
+ ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
+ const FileSystemOptions &FileSystemOpts,
Diagnostic &Diags, const char *isysroot = 0,
bool DisableValidation = false);
~ASTReader();
@@ -834,6 +837,8 @@ public:
/// \brief Retrieve the name of the original source file name directly from
/// the AST file, without actually loading the AST file.
static std::string getOriginalSourceFile(const std::string &ASTFileName,
+ FileManager &FileMgr,
+ const FileSystemOptions &FSOpts,
Diagnostic &Diags);
/// \brief Returns the suggested contents of the predefines buffer,
diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp
index a8cb1c5bed..7747e617e3 100644
--- a/lib/AST/ASTImporter.cpp
+++ b/lib/AST/ASTImporter.cpp
@@ -2980,9 +2980,12 @@ Expr *ASTNodeImporter::VisitCStyleCastExpr(CStyleCastExpr *E) {
ASTImporter::ASTImporter(Diagnostic &Diags,
ASTContext &ToContext, FileManager &ToFileManager,
- ASTContext &FromContext, FileManager &FromFileManager)
+ const FileSystemOptions &ToFileSystemOpts,
+ ASTContext &FromContext, FileManager &FromFileManager,
+ const FileSystemOptions &FromFileSystemOpts)
: ToContext(ToContext), FromContext(FromContext),
ToFileManager(ToFileManager), FromFileManager(FromFileManager),
+ ToFileSystemOpts(ToFileSystemOpts), FromFileSystemOpts(FromFileSystemOpts),
Diags(Diags) {
ImportedDecls[FromContext.getTranslationUnitDecl()]
= ToContext.getTranslationUnitDecl();
@@ -3153,7 +3156,8 @@ FileID ASTImporter::Import(FileID FromID) {
// disk again
// FIXME: We definitely want to re-use the existing MemoryBuffer, rather
// than mmap the files several times.
- const FileEntry *Entry = ToFileManager.getFile(Cache->Entry->getName());
+ const FileEntry *Entry = ToFileManager.getFile(Cache->Entry->getName(),
+ ToFileSystemOpts);
ToID = ToSM.createFileID(Entry, ToIncludeLoc,
FromSLoc.getFile().getFileCharacteristic());
} else {
diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp
index 565f8a61de..247ba1b752 100644
--- a/lib/Basic/FileManager.cpp
+++ b/lib/Basic/FileManager.cpp
@@ -18,8 +18,10 @@
//===----------------------------------------------------------------------===//
#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/Config/config.h"
@@ -197,7 +199,8 @@ void FileManager::removeStatCache(StatSysCallCache *statCache) {
/// \brief Retrieve the directory that the given file name resides in.
static const DirectoryEntry *getDirectoryFromFile(FileManager &FileMgr,
const char *NameStart,
- const char *NameEnd) {
+ const char *NameEnd,
+ const FileSystemOptions &FileSystemOpts) {
// Figure out what directory it is in. If the string contains a / in it,
// strip off everything after it.
// FIXME: this logic should be in sys::Path.
@@ -211,18 +214,19 @@ static const DirectoryEntry *getDirectoryFromFile(FileManager &FileMgr,
if (SlashPos < NameStart) {
// Use the current directory if file has no path component.
const char *Name = ".";
- return FileMgr.getDirectory(Name, Name+1);
+ return FileMgr.getDirectory(Name, Name+1, FileSystemOpts);
} else if (SlashPos == NameEnd-1)
return 0; // If filename ends with a /, it's a directory.