summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/InitPreprocessor.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/Frontend/InitPreprocessor.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/Frontend/InitPreprocessor.cpp')
-rw-r--r--clang/lib/Frontend/InitPreprocessor.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 181f6710256..7275733bbb0 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -478,6 +478,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
static void InitializeFileRemapping(Diagnostic &Diags,
SourceManager &SourceMgr,
FileManager &FileMgr,
+ const FileSystemOptions &FSOpts,
const PreprocessorOptions &InitOpts) {
// Remap files in the source manager (with buffers).
for (PreprocessorOptions::const_remapped_file_buffer_iterator
@@ -488,7 +489,7 @@ static void InitializeFileRemapping(Diagnostic &Diags,
// Create the file entry for the file that we're mapping from.
const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
Remap->second->getBufferSize(),
- 0);
+ 0, FSOpts);
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
@@ -510,7 +511,7 @@ static void InitializeFileRemapping(Diagnostic &Diags,
Remap != RemapEnd;
++Remap) {
// Find the file that we're mapping to.
- const FileEntry *ToFile = FileMgr.getFile(Remap->second);
+ const FileEntry *ToFile = FileMgr.getFile(Remap->second, FSOpts);
if (!ToFile) {
Diags.Report(diag::err_fe_remap_missing_to_file)
<< Remap->first << Remap->second;
@@ -520,7 +521,7 @@ static void InitializeFileRemapping(Diagnostic &Diags,
// Create the file entry for the file that we're mapping from.
const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
ToFile->getSize(),
- 0);
+ 0, FSOpts);
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
@@ -530,7 +531,7 @@ static void InitializeFileRemapping(Diagnostic &Diags,
// Load the contents of the file we're mapping to.
std::string ErrorStr;
const llvm::MemoryBuffer *Buffer
- = llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr);
+ = FileMgr.getBufferForFile(ToFile->getName(), FSOpts, &ErrorStr);
if (!Buffer) {
Diags.Report(diag::err_fe_error_opening)
<< Remap->second << ErrorStr;
@@ -547,6 +548,7 @@ static void InitializeFileRemapping(Diagnostic &Diags,
/// environment ready to process a single file. This returns true on error.
///
void clang::InitializePreprocessor(Preprocessor &PP,
+ const FileSystemOptions &FSOpts,
const PreprocessorOptions &InitOpts,
const HeaderSearchOptions &HSOpts,
const FrontendOptions &FEOpts) {
@@ -556,7 +558,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
MacroBuilder Builder(Predefines);
InitializeFileRemapping(PP.getDiagnostics(), PP.getSourceManager(),
- PP.getFileManager(), InitOpts);
+ PP.getFileManager(), FSOpts, InitOpts);
// Emit line markers for various builtin sections of the file. We don't do
// this in asm preprocessor mode, because "# 4" is not a line marker directive
OpenPOWER on IntegriCloud