зеркало из https://github.com/microsoft/clang-1.git
Add CompilerInstance::InitializeSourceManager.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88764 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
3e42ffd3a8
Коммит
ccb6cb6fd9
|
@ -489,6 +489,26 @@ public:
|
||||||
std::string *ResultPathName = 0);
|
std::string *ResultPathName = 0);
|
||||||
|
|
||||||
/// }
|
/// }
|
||||||
|
/// @name Initialization Utility Methods
|
||||||
|
/// {
|
||||||
|
|
||||||
|
/// InitializeSourceManager - Initialize the source manager to set InputFile
|
||||||
|
/// as the main file.
|
||||||
|
///
|
||||||
|
/// \return True on success.
|
||||||
|
bool InitializeSourceManager(llvm::StringRef InputFile);
|
||||||
|
|
||||||
|
/// InitializeSourceManager - Initialize the source manager to set InputFile
|
||||||
|
/// as the main file.
|
||||||
|
///
|
||||||
|
/// \return True on success.
|
||||||
|
static bool InitializeSourceManager(llvm::StringRef InputFile,
|
||||||
|
Diagnostic &Diags,
|
||||||
|
FileManager &FileMgr,
|
||||||
|
SourceManager &SourceMgr,
|
||||||
|
const FrontendOptions &Opts);
|
||||||
|
|
||||||
|
/// }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "clang/Frontend/Utils.h"
|
#include "clang/Frontend/Utils.h"
|
||||||
#include "clang/Sema/CodeCompleteConsumer.h"
|
#include "clang/Sema/CodeCompleteConsumer.h"
|
||||||
#include "llvm/LLVMContext.h"
|
#include "llvm/LLVMContext.h"
|
||||||
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/System/Path.h"
|
#include "llvm/System/Path.h"
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
@ -361,3 +362,40 @@ CompilerInstance::createOutputFile(llvm::StringRef OutputPath,
|
||||||
|
|
||||||
return OS;
|
return OS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialization Utilities
|
||||||
|
|
||||||
|
bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile) {
|
||||||
|
return InitializeSourceManager(InputFile, getDiagnostics(), getFileManager(),
|
||||||
|
getSourceManager(), getFrontendOpts());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
|
||||||
|
Diagnostic &Diags,
|
||||||
|
FileManager &FileMgr,
|
||||||
|
SourceManager &SourceMgr,
|
||||||
|
const FrontendOptions &Opts) {
|
||||||
|
// Figure out where to get and map in the main file.
|
||||||
|
if (Opts.EmptyInputOnly) {
|
||||||
|
const char *EmptyStr = "";
|
||||||
|
llvm::MemoryBuffer *SB =
|
||||||
|
llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<empty input>");
|
||||||
|
SourceMgr.createMainFileIDForMemBuffer(SB);
|
||||||
|
} else if (InputFile != "-") {
|
||||||
|
const FileEntry *File = FileMgr.getFile(InputFile);
|
||||||
|
if (File) SourceMgr.createMainFileID(File, SourceLocation());
|
||||||
|
if (SourceMgr.getMainFileID().isInvalid()) {
|
||||||
|
Diags.Report(diag::err_fe_error_reading) << InputFile;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
|
||||||
|
SourceMgr.createMainFileIDForMemBuffer(SB);
|
||||||
|
if (SourceMgr.getMainFileID().isInvalid()) {
|
||||||
|
Diags.Report(diag::err_fe_error_reading_stdin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -164,37 +164,6 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
|
||||||
// Utility Methods
|
// Utility Methods
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static bool InitializeSourceManager(Preprocessor &PP,
|
|
||||||
const FrontendOptions &FEOpts,
|
|
||||||
const std::string &InFile) {
|
|
||||||
// Figure out where to get and map in the main file.
|
|
||||||
SourceManager &SourceMgr = PP.getSourceManager();
|
|
||||||
FileManager &FileMgr = PP.getFileManager();
|
|
||||||
|
|
||||||
if (FEOpts.EmptyInputOnly) {
|
|
||||||
const char *EmptyStr = "";
|
|
||||||
llvm::MemoryBuffer *SB =
|
|
||||||
llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<empty input>");
|
|
||||||
SourceMgr.createMainFileIDForMemBuffer(SB);
|
|
||||||
} else if (InFile != "-") {
|
|
||||||
const FileEntry *File = FileMgr.getFile(InFile);
|
|
||||||
if (File) SourceMgr.createMainFileID(File, SourceLocation());
|
|
||||||
if (SourceMgr.getMainFileID().isInvalid()) {
|
|
||||||
PP.getDiagnostics().Report(diag::err_fe_error_reading) << InFile.c_str();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
|
|
||||||
SourceMgr.createMainFileIDForMemBuffer(SB);
|
|
||||||
if (SourceMgr.getMainFileID().isInvalid()) {
|
|
||||||
PP.getDiagnostics().Report(diag::err_fe_error_reading_stdin);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetBuiltinIncludePath(const char *Argv0) {
|
std::string GetBuiltinIncludePath(const char *Argv0) {
|
||||||
llvm::sys::Path P =
|
llvm::sys::Path P =
|
||||||
llvm::sys::Path::GetMainExecutable(Argv0,
|
llvm::sys::Path::GetMainExecutable(Argv0,
|
||||||
|
@ -423,7 +392,7 @@ static void ProcessInputFile(CompilerInstance &CI, const std::string &InFile,
|
||||||
|
|
||||||
// Initialize the main file entry. This needs to be delayed until after PCH
|
// Initialize the main file entry. This needs to be delayed until after PCH
|
||||||
// has loaded.
|
// has loaded.
|
||||||
if (InitializeSourceManager(PP, CI.getFrontendOpts(), InFile))
|
if (!CI.InitializeSourceManager(InFile))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Consumer) {
|
if (Consumer) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче