本文整理汇总了C++中FileID类的典型用法代码示例。如果您正苦于以下问题:C++ FileID类的具体用法?C++ FileID怎么用?C++ FileID使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileID类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: translateLoc
void CXIndexDataConsumer::translateLoc(SourceLocation Loc,
CXIdxClientFile *indexFile, CXFile *file,
unsigned *line, unsigned *column,
unsigned *offset) {
if (Loc.isInvalid())
return;
SourceManager &SM = Ctx->getSourceManager();
Loc = SM.getFileLoc(Loc);
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
FileID FID = LocInfo.first;
unsigned FileOffset = LocInfo.second;
if (FID.isInvalid())
return;
const FileEntry *FE = SM.getFileEntryForID(FID);
if (indexFile)
*indexFile = getIndexFile(FE);
if (file)
*file = const_cast<FileEntry *>(FE);
if (line)
*line = SM.getLineNumber(FID, FileOffset);
if (column)
*column = SM.getColumnNumber(FID, FileOffset);
if (offset)
*offset = FileOffset;
}
示例2: assert
/// EnterMainSourceFile - Enter the specified FileID as the main source file,
/// which implicitly adds the builtin defines etc.
void Preprocessor::EnterMainSourceFile() {
// We do not allow the preprocessor to reenter the main file. Doing so will
// cause FileID's to accumulate information from both runs (e.g. #line
// information) and predefined macros aren't guaranteed to be set properly.
assert(NumEnteredSourceFiles == 0 && "Cannot reenter the main file!");
FileID MainFileID = SourceMgr.getMainFileID();
// If MainFileID is loaded it means we loaded an AST file, no need to enter
// a main file.
if (!SourceMgr.isLoadedFileID(MainFileID)) {
// Enter the main file source buffer.
EnterSourceFile(MainFileID, nullptr, SourceLocation());
// If we've been asked to skip bytes in the main file (e.g., as part of a
// precompiled preamble), do so now.
if (SkipMainFilePreamble.first > 0)
CurLexer->SetByteOffset(SkipMainFilePreamble.first,
SkipMainFilePreamble.second);
// Tell the header info that the main file was entered. If the file is later
// #imported, it won't be re-entered.
if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID))
HeaderInfo.IncrementIncludeCount(FE);
}
// Preprocess Predefines to populate the initial preprocessor state.
std::unique_ptr<llvm::MemoryBuffer> SB =
llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>");
assert(SB && "Cannot create predefined source buffer");
FileID FID = SourceMgr.createFileID(std::move(SB));
assert(FID.isValid() && "Could not create FileID for predefines?");
setPredefinesFileID(FID);
// Start parsing the predefines.
EnterSourceFile(FID, nullptr, SourceLocation());
if (!PPOpts->PCHThroughHeader.empty()) {
// Lookup and save the FileID for the through header. If it isn't found
// in the search path, it's a fatal error.
const DirectoryLookup *CurDir;
const FileEntry *File = LookupFile(
SourceLocation(), PPOpts->PCHThroughHeader,
/*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr, CurDir,
/*SearchPath=*/nullptr, /*RelativePath=*/nullptr,
/*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr,
/*IsFrameworkFound=*/nullptr);
if (!File) {
Diag(SourceLocation(), diag::err_pp_through_header_not_found)
<< PPOpts->PCHThroughHeader;
return;
}
setPCHThroughHeaderFileID(
SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User));
}
// Skip tokens from the Predefines and if needed the main file.
if ((usingPCHWithThroughHeader() && SkippingUntilPCHThroughHeader) ||
(usingPCHWithPragmaHdrStop() && SkippingUntilPragmaHdrStop))
SkipTokensWhileUsingPCH();
}
示例3: assert
/// EnterMainSourceFile - Enter the specified FileID as the main source file,
/// which implicitly adds the builtin defines etc.
bool Preprocessor::EnterMainSourceFile() {
// We do not allow the preprocessor to reenter the main file. Doing so will
// cause FileID's to accumulate information from both runs (e.g. #line
// information) and predefined macros aren't guaranteed to be set properly.
assert(NumEnteredSourceFiles == 0 && "Cannot reenter the main file!");
FileID MainFileID = SourceMgr.getMainFileID();
// Enter the main file source buffer.
std::string ErrorStr;
if (EnterSourceFile(MainFileID, 0, ErrorStr))
return true;
// Tell the header info that the main file was entered. If the file is later
// #imported, it won't be re-entered.
if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID))
HeaderInfo.IncrementIncludeCount(FE);
// Preprocess Predefines to populate the initial preprocessor state.
llvm::MemoryBuffer *SB =
llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>");
assert(SB && "Cannot fail to create predefined source buffer");
FileID FID = SourceMgr.createFileIDForMemBuffer(SB);
assert(!FID.isInvalid() && "Could not create FileID for predefines?");
// Start parsing the predefines.
return EnterSourceFile(FID, 0, ErrorStr);
}
示例4: addAngledInclude
Replacement IncludeDirectives::addAngledInclude(const clang::FileEntry *File,
llvm::StringRef Include) {
FileID FID = Sources.translateFile(File);
assert(!FID.isInvalid() && "Invalid file entry given!");
if (hasInclude(File, Include))
return Replacement();
unsigned Offset, NLFlags;
std::tie(Offset, NLFlags) = angledIncludeInsertionOffset(FID);
StringRef EOL = guessEOL(Sources, FID);
llvm::SmallString<32> InsertionText;
if (NLFlags & NL_Prepend)
InsertionText += EOL;
if (NLFlags & NL_PrependAnother)
InsertionText += EOL;
InsertionText += "#include <";
InsertionText += Include;
InsertionText += ">";
if (NLFlags & NL_AppendTwice) {
InsertionText += EOL;
InsertionText += EOL;
}
return Replacement(File->getName(), Offset, 0, InsertionText);
}
示例5: assert
/// EnterMainSourceFile - Enter the specified FileID as the main source file,
/// which implicitly adds the builtin defines etc.
void Preprocessor::EnterMainSourceFile() {
// We do not allow the preprocessor to reenter the main file. Doing so will
// cause FileID's to accumulate information from both runs (e.g. #line
// information) and predefined macros aren't guaranteed to be set properly.
assert(NumEnteredSourceFiles == 0 && "Cannot reenter the main file!");
FileID MainFileID = SourceMgr.getMainFileID();
// If MainFileID is loaded it means we loaded an AST file, no need to enter
// a main file.
if (!SourceMgr.isLoadedFileID(MainFileID)) {
// Enter the main file source buffer.
EnterSourceFile(MainFileID, 0, SourceLocation());
// If we've been asked to skip bytes in the main file (e.g., as part of a
// precompiled preamble), do so now.
if (SkipMainFilePreamble.first > 0)
CurLexer->SkipBytes(SkipMainFilePreamble.first,
SkipMainFilePreamble.second);
// Tell the header info that the main file was entered. If the file is later
// #imported, it won't be re-entered.
if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID))
HeaderInfo.IncrementIncludeCount(FE);
}
// Preprocess Predefines to populate the initial preprocessor state.
llvm::MemoryBuffer *SB =
llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>");
assert(SB && "Cannot create predefined source buffer");
FileID FID = SourceMgr.createFileIDForMemBuffer(SB);
assert(!FID.isInvalid() && "Could not create FileID for predefines?");
// Start parsing the predefines.
EnterSourceFile(FID, 0, SourceLocation());
}
示例6: clang_getFileLocation
void clang_getFileLocation(CXSourceLocation location,
CXFile *file,
unsigned *line,
unsigned *column,
unsigned *offset) {
if (!isASTUnitSourceLocation(location)) {
CXLoadedDiagnostic::decodeLocation(location, file, line,
column, offset);
return;
}
SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
if (!location.ptr_data[0] || Loc.isInvalid())
return createNullLocation(file, line, column, offset);
const SourceManager &SM =
*static_cast<const SourceManager*>(location.ptr_data[0]);
SourceLocation FileLoc = SM.getFileLoc(Loc);
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(FileLoc);
FileID FID = LocInfo.first;
unsigned FileOffset = LocInfo.second;
if (FID.isInvalid())
return createNullLocation(file, line, column, offset);
if (file)
*file = const_cast<FileEntry *>(SM.getFileEntryForID(FID));
if (line)
*line = SM.getLineNumber(FID, FileOffset);
if (column)
*column = SM.getColumnNumber(FID, FileOffset);
if (offset)
*offset = FileOffset;
}
示例7: getRequest
rc_t LogCollectorImpl::reqFileData(file_id_t file_id, file_size_t pos, uint8_t* data, uint32_t len) {
Request* pRequest = getRequest(0);
if (NULL == pRequest) { return RC_S_NULL_VALUE; }
// FileData
FileDataRequest* pFileDataRequest = pRequest->GetFileDataRequest();
if (NULL == pFileDataRequest) { return RC_E_NOMEM; }
// send only
if (IFileNode::INVALID_FILE_ID == file_id || NULL == data || 0 == len) {
if (0 == pFileDataRequest->filedata_size() || RC_S_OK != pRequest->SerializeRequest()) { return RC_S_FAILED; }
return m_autoRelINetHandler->Send(this, pRequest->GetRequestData(), pRequest->GetRequestSize());
}
//
// deflate
ASSERT(IFileCollector::kMAX_READ_SIZE >= len);
size_t encode_size = m_autoRelMemDefalte->len();
if (RC_S_OK != m_autoRelICoderDefalte->encode(m_autoRelMemDefalte->data(), &encode_size, data, len)) {
LOG(ILogWriter::LV_WARN, "Deflate EnCode Failed, Org. Data Len=%u", len);
return RC_S_FAILED;
}
// is too big
if (INetHandler::kMAX_REQ_DATA_SIZE < encode_size) { return RC_E_ACCESS; }
if (INetHandler::kMAX_REQ_DATA_SIZE < pFileDataRequest->ByteSize() + encode_size) {
if (RC_S_OK != pRequest->SerializeRequest()) {
LOG(ILogWriter::LV_WARN, "FileData Packet EnCode Failed. len=%u(less)", pFileDataRequest->ByteSize() + encode_size);
return RC_S_FAILED;
}
if (RC_S_OK != m_autoRelINetHandler->Send(this, pRequest->GetRequestData(), pRequest->GetRequestSize())) { return RC_S_FAILED; }
pFileDataRequest = pRequest->GetFileDataRequest();
}
// make sure have FileDataRequest
if (NULL == pFileDataRequest) { return RC_E_NOMEM; }
FileDataRequest_FileData* pFileData = pFileDataRequest->add_filedata();
if (NULL == pFileData) { return RC_E_NOMEM; }
FileID* pFileID = pFileData->mutable_id();
if (NULL == pFileID) { return RC_E_NOMEM; }
pFileID->set_id(file_id);
pFileData->set_pos(pos);
pFileData->set_encode(FileDataRequest_FileData_EncodeType_DEFLATE);
pFileData->set_org_len(len);
pFileData->set_data(m_autoRelMemDefalte->data(), encode_size);
return RC_S_OK;
}
示例8: setSourceManager
void VerifyDiagnosticConsumer::UpdateParsedFileStatus(SourceManager &SM,
FileID FID,
ParsedStatus PS) {
// Check SourceManager hasn't changed.
setSourceManager(SM);
#ifndef NDEBUG
if (FID.isInvalid())
return;
const FileEntry *FE = SM.getFileEntryForID(FID);
if (PS == IsParsed) {
// Move the FileID from the unparsed set to the parsed set.
UnparsedFiles.erase(FID);
ParsedFiles.insert(std::make_pair(FID, FE));
} else if (!ParsedFiles.count(FID) && !UnparsedFiles.count(FID)) {
// Add the FileID to the unparsed set if we haven't seen it before.
// Check for directives.
bool FoundDirectives;
if (PS == IsUnparsedNoDirectives)
FoundDirectives = false;
else
FoundDirectives = !LangOpts || findDirectives(SM, FID, *LangOpts);
// Add the FileID to the unparsed set.
UnparsedFiles.insert(std::make_pair(FID,
UnparsedFileStatus(FE, FoundDirectives)));
}
#endif
}
示例9: FindExpectedDiags
/// FindExpectedDiags - Lex the main source file to find all of the
// expected errors and warnings.
static void FindExpectedDiags(const Preprocessor &PP, ExpectedData &ED,
FileID FID) {
// Create a raw lexer to pull all the comments out of FID.
if (FID.isInvalid())
return;
SourceManager& SM = PP.getSourceManager();
// Create a lexer to lex all the tokens of the main file in raw mode.
const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
Lexer RawLex(FID, FromFile, SM, PP.getLangOpts());
// Return comments as tokens, this is how we find expected diagnostics.
RawLex.SetCommentRetentionState(true);
Token Tok;
Tok.setKind(tok::comment);
while (Tok.isNot(tok::eof)) {
RawLex.Lex(Tok);
if (!Tok.is(tok::comment)) continue;
std::string Comment = PP.getSpelling(Tok);
if (Comment.empty()) continue;
// Find all expected errors/warnings/notes.
ParseDirective(Comment, ED, SM, Tok.getLocation(), PP.getDiagnostics());
};
}
示例10: assert
/// \brief Returns true if the preprocessed entity that \arg PPEI iterator
/// points to is coming from the file \arg FID.
///
/// Can be used to avoid implicit deserializations of preallocated
/// preprocessed entities if we only care about entities of a specific file
/// and not from files #included in the range given at
/// \see getPreprocessedEntitiesInRange.
bool PreprocessingRecord::isEntityInFileID(iterator PPEI, FileID FID) {
if (FID.isInvalid())
return false;
PPEntityID PPID = PPEI.Position;
if (PPID < 0) {
assert(unsigned(-PPID-1) < LoadedPreprocessedEntities.size() &&
"Out-of bounds loaded preprocessed entity");
assert(ExternalSource && "No external source to load from");
unsigned LoadedIndex = LoadedPreprocessedEntities.size()+PPID;
if (PreprocessedEntity *PPE = LoadedPreprocessedEntities[LoadedIndex])
return isPreprocessedEntityIfInFileID(PPE, FID, SourceMgr);
// See if the external source can see if the entity is in the file without
// deserializing it.
llvm::Optional<bool>
IsInFile = ExternalSource->isPreprocessedEntityInFileID(LoadedIndex, FID);
if (IsInFile.hasValue())
return IsInFile.getValue();
// The external source did not provide a definite answer, go and deserialize
// the entity to check it.
return isPreprocessedEntityIfInFileID(
getLoadedPreprocessedEntity(LoadedIndex),
FID, SourceMgr);
}
assert(unsigned(PPID) < PreprocessedEntities.size() &&
"Out-of bounds local preprocessed entity");
return isPreprocessedEntityIfInFileID(PreprocessedEntities[PPID],
FID, SourceMgr);
}
示例11: findDirectives
/// \brief Lex the specified source file to determine whether it contains
/// any expected-* directives. As a Lexer is used rather than a full-blown
/// Preprocessor, directives inside skipped #if blocks will still be found.
///
/// \return true if any directives were found.
static bool findDirectives(SourceManager &SM, FileID FID,
const LangOptions &LangOpts) {
// Create a raw lexer to pull all the comments out of FID.
if (FID.isInvalid())
return false;
// Create a lexer to lex all the tokens of the main file in raw mode.
const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
Lexer RawLex(FID, FromFile, SM, LangOpts);
// Return comments as tokens, this is how we find expected diagnostics.
RawLex.SetCommentRetentionState(true);
Token Tok;
Tok.setKind(tok::comment);
VerifyDiagnosticConsumer::DirectiveStatus Status =
VerifyDiagnosticConsumer::HasNoDirectives;
while (Tok.isNot(tok::eof)) {
RawLex.Lex(Tok);
if (!Tok.is(tok::comment)) continue;
std::string Comment = RawLex.getSpelling(Tok, SM, LangOpts);
if (Comment.empty()) continue;
// Find first directive.
if (ParseDirective(Comment, 0, SM, Tok.getLocation(),
SM.getDiagnostics(), Status))
return true;
}
return false;
}
示例12: importedModule
bool IndexingContext::importedModule(const ImportDecl *ImportD) {
if (ImportD->isInvalidDecl())
return true;
SourceLocation Loc;
auto IdLocs = ImportD->getIdentifierLocs();
if (!IdLocs.empty())
Loc = IdLocs.back();
else
Loc = ImportD->getLocation();
SourceManager &SM = Ctx->getSourceManager();
FileID FID = SM.getFileID(SM.getFileLoc(Loc));
if (FID.isInvalid())
return true;
bool Invalid = false;
const SrcMgr::SLocEntry &SEntry = SM.getSLocEntry(FID, &Invalid);
if (Invalid || !SEntry.isFile())
return true;
if (SEntry.getFile().getFileCharacteristic() != SrcMgr::C_User) {
switch (IndexOpts.SystemSymbolFilter) {
case IndexingOptions::SystemSymbolFilterKind::None:
return true;
case IndexingOptions::SystemSymbolFilterKind::DeclarationsOnly:
case IndexingOptions::SystemSymbolFilterKind::All:
break;
}
}
const Module *Mod = ImportD->getImportedModule();
if (!ImportD->isImplicit() && Mod->Parent && !IdLocs.empty()) {
reportModuleReferences(Mod->Parent, IdLocs.drop_back(), ImportD,
DataConsumer);
}
SymbolRoleSet Roles = (unsigned)SymbolRole::Declaration;
if (ImportD->isImplicit())
Roles |= (unsigned)SymbolRole::Implicit;
return DataConsumer.handleModuleOccurence(ImportD, Mod, Roles, Loc);
}
示例13: getEntityDecl
bool CXIndexDataConsumer::markEntityOccurrenceInFile(const NamedDecl *D,
SourceLocation Loc) {
if (!D || Loc.isInvalid())
return true;
SourceManager &SM = Ctx->getSourceManager();
D = getEntityDecl(D);
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SM.getFileLoc(Loc));
FileID FID = LocInfo.first;
if (FID.isInvalid())
return true;
const FileEntry *FE = SM.getFileEntryForID(FID);
if (!FE)
return true;
RefFileOccurrence RefOccur(FE, D);
std::pair<llvm::DenseSet<RefFileOccurrence>::iterator, bool>
res = RefFileOccurrences.insert(RefOccur);
return !res.second; // already in map
}
示例14: isPreprocessedEntityIfInFileID
static bool isPreprocessedEntityIfInFileID(PreprocessedEntity *PPE, FileID FID,
SourceManager &SM) {
assert(FID.isValid());
if (!PPE)
return false;
SourceLocation Loc = PPE->getSourceRange().getBegin();
if (Loc.isInvalid())
return false;
return SM.isInFileID(SM.getFileLoc(Loc), FID);
}
示例15: importedModule
bool IndexingContext::importedModule(const ImportDecl *ImportD) {
SourceLocation Loc;
auto IdLocs = ImportD->getIdentifierLocs();
if (!IdLocs.empty())
Loc = IdLocs.front();
else
Loc = ImportD->getLocation();
SourceManager &SM = Ctx->getSourceManager();
Loc = SM.getFileLoc(Loc);
if (Loc.isInvalid())
return true;
FileID FID;
unsigned Offset;
std::tie(FID, Offset) = SM.getDecomposedLoc(Loc);
if (FID.isInvalid())
return true;
bool Invalid = false;
const SrcMgr::SLocEntry &SEntry = SM.getSLocEntry(FID, &Invalid);
if (Invalid || !SEntry.isFile())
return true;
if (SEntry.getFile().getFileCharacteristic() != SrcMgr::C_User) {
switch (IndexOpts.SystemSymbolFilter) {
case IndexingOptions::SystemSymbolFilterKind::None:
return true;
case IndexingOptions::SystemSymbolFilterKind::DeclarationsOnly:
case IndexingOptions::SystemSymbolFilterKind::All:
break;
}
}
SymbolRoleSet Roles = (unsigned)SymbolRole::Declaration;
if (ImportD->isImplicit())
Roles |= (unsigned)SymbolRole::Implicit;
return DataConsumer.handleModuleOccurence(ImportD, Roles, FID, Offset);
}