本文整理汇总了C++中ASTUnit::isInMainFileID方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTUnit::isInMainFileID方法的具体用法?C++ ASTUnit::isInMainFileID怎么用?C++ ASTUnit::isInMainFileID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTUnit
的用法示例。
在下文中一共展示了ASTUnit::isInMainFileID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: indexPreprocessingRecord
static void indexPreprocessingRecord(ASTUnit &Unit, IndexingContext &IdxCtx) {
Preprocessor &PP = Unit.getPreprocessor();
if (!PP.getPreprocessingRecord())
return;
// FIXME: Only deserialize inclusion directives.
PreprocessingRecord::iterator I, E;
std::tie(I, E) = Unit.getLocalPreprocessingEntities();
bool isModuleFile = Unit.isModuleFile();
for (; I != E; ++I) {
PreprocessedEntity *PPE = *I;
if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
SourceLocation Loc = ID->getSourceRange().getBegin();
// Modules have synthetic main files as input, give an invalid location
// if the location points to such a file.
if (isModuleFile && Unit.isInMainFileID(Loc))
Loc = SourceLocation();
IdxCtx.ppIncludedFile(Loc, ID->getFileName(),
ID->getFile(),
ID->getKind() == InclusionDirective::Import,
!ID->wasInQuotes(), ID->importedModule());
}
}
}
示例2: getInclusions
static void getInclusions(const SrcMgr::SLocEntry &(SourceManager::*Getter)(unsigned, bool*) const, unsigned n,
CXTranslationUnit TU, CXInclusionVisitor CB,
CXClientData clientData)
{
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
SourceManager &SM = CXXUnit->getSourceManager();
ASTContext &Ctx = CXXUnit->getASTContext();
SmallVector<CXSourceLocation, 10> InclusionStack;
const bool HasPreamble = SM.getPreambleFileID().isValid();
for (unsigned i = 0 ; i < n ; ++i) {
bool Invalid = false;
const SrcMgr::SLocEntry &SL = (SM.*Getter)(i, &Invalid);
if (!SL.isFile() || Invalid)
continue;
const SrcMgr::FileInfo &FI = SL.getFile();
if (!FI.getContentCache()->OrigEntry)
continue;
// If this is the main file, and there is a preamble, skip this SLoc. The
// inclusions of the preamble already showed it.
SourceLocation L = FI.getIncludeLoc();
if (HasPreamble && CXXUnit->isInMainFileID(L))
continue;
// Build the inclusion stack.
InclusionStack.clear();
while (L.isValid()) {
PresumedLoc PLoc = SM.getPresumedLoc(L);
InclusionStack.push_back(cxloc::translateSourceLocation(Ctx, L));
L = PLoc.isValid()? PLoc.getIncludeLoc() : SourceLocation();
}
// If there is a preamble, the last entry is the "inclusion" of that
// preamble into the main file, which has the bogus entry of main.c:1:1
if (HasPreamble && !InclusionStack.empty())
InclusionStack.pop_back();
// Callback to the client.
// FIXME: We should have a function to construct CXFiles.
CB(static_cast<CXFile>(
const_cast<FileEntry *>(FI.getContentCache()->OrigEntry)),
InclusionStack.data(), InclusionStack.size(), clientData);
}
}