本文整理汇总了C++中FileManager::getFile方法的典型用法代码示例。如果您正苦于以下问题:C++ FileManager::getFile方法的具体用法?C++ FileManager::getFile怎么用?C++ FileManager::getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::getFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
llvm::raw_stdout_ostream ost;
//DiagnosticOptions dops;
TextDiagnosticPrinter tdp(ost);//, dops);
Diagnostic diag(&tdp);
LangOptions lang;
//lang.GNUMode = 1;
SourceManager sm;
FileManager fm;
HeaderSearch headers(fm);
InitHeaderSearch init(headers);
init.AddDefaultSystemIncludePaths(lang);
init.Realize();
TargetInfo *ti = TargetInfo::CreateTargetInfo(LLVM_HOSTTRIPLE);
Preprocessor pp(diag, lang, *ti, sm, headers);
PreprocessorInitOptions ppio;
InitializePreprocessor(pp, ppio);
const FileEntry *file = fm.getFile("foo.c");
sm.createMainFileID(file, SourceLocation());
pp.EnterMainSourceFile();
IdentifierTable tab(lang);
MyAction action(pp);
Parser p(pp, action);
p.ParseTranslationUnit();
return 0;
}
示例2: createInMemoryFile
static FileID createInMemoryFile(StringRef FileName, MemoryBuffer *Source,
SourceManager &Sources, FileManager &Files,
vfs::InMemoryFileSystem *MemFS) {
MemFS->addFileNoOwn(FileName, 0, Source);
return Sources.createFileID(Files.getFile(FileName), SourceLocation(),
SrcMgr::C_User);
}
示例3: ReadSourceLocation
static bool ReadSourceLocation(FileManager &FM, SourceManager &SM,
const char *&Memory, const char *MemoryEnd,
SourceLocation &Location) {
// Read the filename.
unsigned FileNameLen = 0;
if (ReadUnsigned(Memory, MemoryEnd, FileNameLen) ||
Memory + FileNameLen > MemoryEnd)
return true;
llvm::StringRef FileName(Memory, FileNameLen);
Memory += FileNameLen;
// Read the line, column.
unsigned Line = 0, Column = 0;
if (ReadUnsigned(Memory, MemoryEnd, Line) ||
ReadUnsigned(Memory, MemoryEnd, Column))
return true;
if (FileName.empty()) {
Location = SourceLocation();
return false;
}
const FileEntry *File = FM.getFile(FileName);
if (!File)
return true;
// Make sure that this file has an entry in the source manager.
if (!SM.hasFileInfo(File))
SM.createFileID(File, SourceLocation(), SrcMgr::C_User);
Location = SM.getLocation(File, Line, Column);
return false;
}
示例4: InitializeSourceManager
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, unless it's already
// been created (e.g., by a precompiled preamble).
if (!SourceMgr.getMainFileID().isInvalid()) {
// Do nothing: the main file has already been set.
} else if (InputFile != "-") {
const FileEntry *File = FileMgr.getFile(InputFile);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
SourceMgr.createMainFileID(File);
} else {
llvm::OwningPtr<llvm::MemoryBuffer> SB;
if (llvm::MemoryBuffer::getSTDIN(SB)) {
// FIXME: Give ec.message() in this diag.
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File);
SourceMgr.overrideFileContents(File, SB.take());
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
示例5: InitializeSourceManager
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;
}
示例6: InitializeSourceManager
bool CompilerInstance::InitializeSourceManager(StringRef InputFile,
SrcMgr::CharacteristicKind Kind,
DiagnosticsEngine &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr,
const FrontendOptions &Opts) {
// Figure out where to get and map in the main file.
if (InputFile != "-") {
const FileEntry *File = FileMgr.getFile(InputFile);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
SourceMgr.createMainFileID(File, Kind);
} else {
OwningPtr<llvm::MemoryBuffer> SB;
if (llvm::MemoryBuffer::getSTDIN(SB)) {
// FIXME: Give ec.message() in this diag.
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File, Kind);
SourceMgr.overrideFileContents(File, SB.take());
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
示例7: InitializeFileRemapping
// Initialize the remapping of files to alternative contents, e.g.,
// those specified through other files.
static void InitializeFileRemapping(DiagnosticsEngine &Diags,
SourceManager &SourceMgr,
FileManager &FileMgr,
const PreprocessorOptions &InitOpts) {
// Remap files in the source manager (with buffers).
for (PreprocessorOptions::const_remapped_file_buffer_iterator
Remap = InitOpts.remapped_file_buffer_begin(),
RemapEnd = InitOpts.remapped_file_buffer_end();
Remap != RemapEnd;
++Remap) {
// Create the file entry for the file that we're mapping from.
const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
Remap->second->getBufferSize(),
0);
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
if (!InitOpts.RetainRemappedFileBuffers)
delete Remap->second;
continue;
}
// Override the contents of the "from" file with the contents of
// the "to" file.
SourceMgr.overrideFileContents(FromFile, Remap->second,
InitOpts.RetainRemappedFileBuffers);
}
// Remap files in the source manager (with other files).
for (PreprocessorOptions::const_remapped_file_iterator
Remap = InitOpts.remapped_file_begin(),
RemapEnd = InitOpts.remapped_file_end();
Remap != RemapEnd;
++Remap) {
// Find the file that we're mapping to.
const FileEntry *ToFile = FileMgr.getFile(Remap->second);
if (!ToFile) {
Diags.Report(diag::err_fe_remap_missing_to_file)
<< Remap->first << Remap->second;
continue;
}
// Create the file entry for the file that we're mapping from.
const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
ToFile->getSize(), 0);
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
continue;
}
// Override the contents of the "from" file with the contents of
// the "to" file.
SourceMgr.overrideFileContents(FromFile, ToFile);
}
SourceMgr.setOverridenFilesKeepOriginalName(
InitOpts.RemappedFilesKeepOriginalName);
}
示例8: InitializeSourceManager
bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
DiagnosticsEngine &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr,
const FrontendOptions &Opts) {
SrcMgr::CharacteristicKind
Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
if (Input.isBuffer()) {
SourceMgr.createMainFileIDForMemBuffer(Input.getBuffer(), Kind);
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
StringRef InputFile = Input.getFile();
// Figure out where to get and map in the main file.
if (InputFile != "-") {
const FileEntry *File = FileMgr.getFile(InputFile);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
// The natural SourceManager infrastructure can't currently handle named
// pipes, but we would at least like to accept them for the main
// file. Detect them here, read them with the more generic MemoryBuffer
// function, and simply override their contents as we do for STDIN.
if (File->isNamedPipe()) {
OwningPtr<llvm::MemoryBuffer> MB;
if (llvm::error_code ec = llvm::MemoryBuffer::getFile(InputFile, MB)) {
Diags.Report(diag::err_cannot_open_file) << InputFile << ec.message();
return false;
}
// Create a new virtual file that will have the correct size.
File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0);
SourceMgr.overrideFileContents(File, MB.take());
}
SourceMgr.createMainFileID(File, Kind);
} else {
OwningPtr<llvm::MemoryBuffer> SB;
if (llvm::MemoryBuffer::getSTDIN(SB)) {
// FIXME: Give ec.message() in this diag.
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File, Kind);
SourceMgr.overrideFileContents(File, SB.take());
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
示例9: collectModuleHeaderIncludes
/// \brief Collect the set of header includes needed to construct the given
/// module and update the TopHeaders file set of the module.
///
/// \param Module The module we're collecting includes from.
///
/// \param Includes Will be augmented with the set of \#includes or \#imports
/// needed to load all of the named headers.
static void collectModuleHeaderIncludes(const LangOptions &LangOpts,
FileManager &FileMgr,
ModuleMap &ModMap,
clang::Module *Module,
SmallVectorImpl<char> &Includes) {
// Don't collect any headers for unavailable modules.
if (!Module->isAvailable())
return;
// Add includes for each of these headers.
for (unsigned I = 0, N = Module->NormalHeaders.size(); I != N; ++I) {
const FileEntry *Header = Module->NormalHeaders[I];
Module->addTopHeader(Header);
addHeaderInclude(Header, Includes, LangOpts);
}
// Note that Module->PrivateHeaders will not be a TopHeader.
if (const FileEntry *UmbrellaHeader = Module->getUmbrellaHeader()) {
Module->addTopHeader(UmbrellaHeader);
if (Module->Parent) {
// Include the umbrella header for submodules.
addHeaderInclude(UmbrellaHeader, Includes, LangOpts);
}
} else if (const DirectoryEntry *UmbrellaDir = Module->getUmbrellaDir()) {
// Add all of the headers we find in this subdirectory.
llvm::error_code EC;
SmallString<128> DirNative;
llvm::sys::path::native(UmbrellaDir->getName(), DirNative);
for (llvm::sys::fs::recursive_directory_iterator Dir(DirNative.str(), EC),
DirEnd;
Dir != DirEnd && !EC; Dir.increment(EC)) {
// Check whether this entry has an extension typically associated with
// headers.
if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->path()))
.Cases(".h", ".H", ".hh", ".hpp", true)
.Default(false))
continue;
// If this header is marked 'unavailable' in this module, don't include
// it.
if (const FileEntry *Header = FileMgr.getFile(Dir->path())) {
if (ModMap.isHeaderInUnavailableModule(Header))
continue;
Module->addTopHeader(Header);
}
// Include this header umbrella header for submodules.
addHeaderInclude(Dir->path(), Includes, LangOpts);
}
}
// Recurse into submodules.
for (clang::Module::submodule_iterator Sub = Module->submodule_begin(),
SubEnd = Module->submodule_end();
Sub != SubEnd; ++Sub)
collectModuleHeaderIncludes(LangOpts, FileMgr, ModMap, *Sub, Includes);
}
示例10: makeArrayRef
ArrayRef<const FileEntry *> Module::getTopHeaders(FileManager &FileMgr) {
if (!TopHeaderNames.empty()) {
for (std::vector<std::string>::iterator
I = TopHeaderNames.begin(), E = TopHeaderNames.end(); I != E; ++I) {
if (const FileEntry *FE = FileMgr.getFile(*I))
TopHeaders.insert(FE);
}
TopHeaderNames.clear();
}
return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end());
}
示例11: testClang
void testClang()
{
return; //maks:teste
std::string InFile = "E:/GAMEDEVELOPMENT/output/dots.c";
// Create a file manager object to provide access to and cache the filesystem.
FileManager FileMgr;
char *PredefineBuffer = "";
ASTConsumer *consumer = new ASTDumper();
// Create the diagnostic client for reporting errors or for
// implementing -verify.
DiagnosticClient* TextDiagClient = 0;
TextDiagClient = new TextDiagnosticPrinter();
llvm::OwningPtr<DiagnosticClient> DiagClient(TextDiagClient);
Diagnostic Diags(DiagClient.get());
LangOptions LangInfo;
SourceManager SourceMgr;
HeaderSearch HeaderInfo(FileMgr);
TargetInfo *Target;
std::string Triple = CreateTargetTriple();
//llvm::OwningPtr<TargetInfo> Target(TargetInfo::CreateTargetInfo(Triple));
Target = TargetInfo::CreateTargetInfo(Triple);
// Set up the preprocessor with these options.
Preprocessor PP(Diags, LangInfo, *Target, SourceMgr, HeaderInfo);
PP.setPredefines(PredefineBuffer);
const FileEntry *File = FileMgr.getFile(InFile);
if (File) SourceMgr.createMainFileID(File, SourceLocation());
ParseAST(PP, consumer, false);
}
示例12: if
/// \brief Helper static function to normalize a path for injection into
/// a synthetic header.
/*static*/ std::string
HeaderSearch::NormalizeDashIncludePath(StringRef File, FileManager &FileMgr) {
// Implicit include paths should be resolved relative to the current
// working directory first, and then use the regular header search
// mechanism. The proper way to handle this is to have the
// predefines buffer located at the current working directory, but
// it has no file entry. For now, workaround this by using an
// absolute path if we find the file here, and otherwise letting
// header search handle it.
SmallString<128> Path(File);
llvm::sys::fs::make_absolute(Path);
bool exists;
if (llvm::sys::fs::exists(Path.str(), exists) || !exists)
Path = File;
else if (exists)
FileMgr.getFile(File);
return Lexer::Stringify(Path.str());
}
示例13: InitializeFileRemapping
// Initialize the remapping of files to alternative contents, e.g.,
// those specified through other files.
static void InitializeFileRemapping(Diagnostic &Diags,
SourceManager &SourceMgr,
FileManager &FileMgr,
const PreprocessorOptions &InitOpts) {
// Remap files in the source manager.
for (PreprocessorOptions::remapped_file_iterator
Remap = InitOpts.remapped_file_begin(),
RemapEnd = InitOpts.remapped_file_end();
Remap != RemapEnd;
++Remap) {
// Find the file that we're mapping to.
const FileEntry *ToFile = FileMgr.getFile(Remap->second);
if (!ToFile) {
Diags.Report(diag::err_fe_remap_missing_to_file)
<< Remap->first << Remap->second;
continue;
}
// Create the file entry for the file that we're mapping from.
const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
ToFile->getSize(),
0);
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
continue;
}
// Load the contents of the file we're mapping to.
std::string ErrorStr;
const llvm::MemoryBuffer *Buffer
= llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr);
if (!Buffer) {
Diags.Report(diag::err_fe_error_opening)
<< Remap->second << ErrorStr;
continue;
}
// Override the contents of the "from" file with the contents of
// the "to" file.
SourceMgr.overrideFileContents(FromFile, Buffer);
}
}
示例14: main
int main()
{
llvm::raw_fd_ostream out_stream(1, false);
DiagnosticOptions diag_options;
TextDiagnosticPrinter *diagClient = new TextDiagnosticPrinter(out_stream, diag_options);
Diagnostic diags(diagClient);
LangOptions opts;
TargetOptions target_opts;
target_opts.Triple = LLVM_HOSTTRIPLE;
TargetInfo *target = TargetInfo::CreateTargetInfo(diags, target_opts);
FileManager fm;
SourceManager sm(diags);
HeaderSearch headers(fm);
Preprocessor pp(diags, opts, *target, sm, headers);
PreprocessorOptions preprocessor_options;
HeaderSearchOptions header_search_options;
FrontendOptions frontend_options;
InitializePreprocessor(
pp, preprocessor_options, header_search_options, frontend_options);
FileEntry const *file = fm.getFile("test.cpp");
FileID main_file = sm.createMainFileID(file);
diagClient->BeginSourceFile(opts, &pp);
pp.EnterMainSourceFile();
bool invalid = false;
llvm::StringRef sr = sm.getBufferData(main_file, &invalid);
(void) sr;
Token tok;
do {
pp.Lex(tok);
if (diags.hasErrorOccurred()) {
break;
}
pp.DumpToken(tok);
cerr << endl;
} while (tok.isNot(tok::eof));
}
示例15: Locked
GlobalModuleIndex::ErrorCode
GlobalModuleIndex::writeIndex(FileManager &FileMgr, StringRef Path) {
llvm::SmallString<128> IndexPath;
IndexPath += Path;
llvm::sys::path::append(IndexPath, IndexFileName);
// Coordinate building the global index file with other processes that might
// try to do the same.
llvm::LockFileManager Locked(IndexPath);
switch (Locked) {
case llvm::LockFileManager::LFS_Error:
return EC_IOError;
case llvm::LockFileManager::LFS_Owned:
// We're responsible for building the index ourselves. Do so below.
break;
case llvm::LockFileManager::LFS_Shared:
// Someone else is responsible for building the index. We don't care
// when they finish, so we're done.
return EC_Building;
}
// The module index builder.
GlobalModuleIndexBuilder Builder(FileMgr);
// Load each of the module files.
std::error_code EC;
for (llvm::sys::fs::directory_iterator D(Path, EC), DEnd;
D != DEnd && !EC;
D.increment(EC)) {
// If this isn't a module file, we don't care.
if (llvm::sys::path::extension(D->path()) != ".pcm") {
// ... unless it's a .pcm.lock file, which indicates that someone is
// in the process of rebuilding a module. They'll rebuild the index
// at the end of that translation unit, so we don't have to.
if (llvm::sys::path::extension(D->path()) == ".pcm.lock")
return EC_Building;
continue;
}
// If we can't find the module file, skip it.
const FileEntry *ModuleFile = FileMgr.getFile(D->path());
if (!ModuleFile)
continue;
// Load this module file.
if (Builder.loadModuleFile(ModuleFile))
return EC_IOError;
}
// The output buffer, into which the global index will be written.
SmallVector<char, 16> OutputBuffer;
{
llvm::BitstreamWriter OutputStream(OutputBuffer);
Builder.writeIndex(OutputStream);
}
// Write the global index file to a temporary file.
llvm::SmallString<128> IndexTmpPath;
int TmpFD;
if (llvm::sys::fs::createUniqueFile(IndexPath + "-%%%%%%%%", TmpFD,
IndexTmpPath))
return EC_IOError;
// Open the temporary global index file for output.
llvm::raw_fd_ostream Out(TmpFD, true);
if (Out.has_error())
return EC_IOError;
// Write the index.
Out.write(OutputBuffer.data(), OutputBuffer.size());
Out.close();
if (Out.has_error())
return EC_IOError;
// Remove the old index file. It isn't relevant any more.
llvm::sys::fs::remove(IndexPath.str());
// Rename the newly-written index file to the proper name.
if (llvm::sys::fs::rename(IndexTmpPath.str(), IndexPath.str())) {
// Rename failed; just remove the
llvm::sys::fs::remove(IndexTmpPath.str());
return EC_IOError;
}
// We're done.
return EC_None;
}