本文整理汇总了C++中CIndexer::getClangResourcesPath方法的典型用法代码示例。如果您正苦于以下问题:C++ CIndexer::getClangResourcesPath方法的具体用法?C++ CIndexer::getClangResourcesPath怎么用?C++ CIndexer::getClangResourcesPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIndexer
的用法示例。
在下文中一共展示了CIndexer::getClangResourcesPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clang_indexSourceFile_Impl
//.........这里部分代码省略.........
if (!CInvok)
return;
// Recover resources if we crash before exiting this function.
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInvocation,
llvm::CrashRecoveryContextReleaseRefCleanup<CompilerInvocation> >
CInvokCleanup(CInvok.getPtr());
if (CInvok->getFrontendOpts().Inputs.empty())
return;
OwningPtr<MemBufferOwner> BufOwner(new MemBufferOwner());
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<MemBufferOwner>
BufOwnerCleanup(BufOwner.get());
for (unsigned I = 0; I != num_unsaved_files; ++I) {
StringRef Data(unsaved_files[I].Contents, unsaved_files[I].Length);
const llvm::MemoryBuffer *Buffer
= llvm::MemoryBuffer::getMemBufferCopy(Data, unsaved_files[I].Filename);
CInvok->getPreprocessorOpts().addRemappedFile(unsaved_files[I].Filename, Buffer);
BufOwner->Buffers.push_back(Buffer);
}
// Since libclang is primarily used by batch tools dealing with
// (often very broken) source code, where spell-checking can have a
// significant negative impact on performance (particularly when
// precompiled headers are involved), we disable it.
CInvok->getLangOpts()->SpellChecking = false;
if (index_options & CXIndexOpt_SuppressWarnings)
CInvok->getDiagnosticOpts().IgnoreWarnings = true;
ASTUnit *Unit = ASTUnit::create(CInvok.getPtr(), Diags,
/*CaptureDiagnostics=*/true,
/*UserFilesAreVolatile=*/true);
OwningPtr<CXTUOwner> CXTU(new CXTUOwner(MakeCXTranslationUnit(CXXIdx, Unit)));
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<CXTUOwner>
CXTUCleanup(CXTU.get());
OwningPtr<IndexingFrontendAction> IndexAction;
IndexAction.reset(new IndexingFrontendAction(client_data, CB,
index_options, CXTU->getTU()));
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<IndexingFrontendAction>
IndexActionCleanup(IndexAction.get());
bool Persistent = requestedToGetTU;
bool OnlyLocalDecls = false;
bool PrecompilePreamble = false;
bool CacheCodeCompletionResults = false;
PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
PPOpts.AllowPCHWithCompilerErrors = true;
if (requestedToGetTU) {
OnlyLocalDecls = CXXIdx->getOnlyLocalDecls();
PrecompilePreamble = TU_options & CXTranslationUnit_PrecompiledPreamble;
// FIXME: Add a flag for modules.
CacheCodeCompletionResults
= TU_options & CXTranslationUnit_CacheCompletionResults;
if (TU_options & CXTranslationUnit_DetailedPreprocessingRecord) {
PPOpts.DetailedRecord = true;
}
}
IndexAction->EnablePPDetailedRecordForModules
= PPOpts.DetailedRecord ||
(TU_options & CXTranslationUnit_DetailedPreprocessingRecord);
if (!requestedToGetTU)
PPOpts.DetailedRecord = false;
DiagnosticErrorTrap DiagTrap(*Diags);
bool Success = ASTUnit::LoadFromCompilerInvocationAction(CInvok.getPtr(), Diags,
IndexAction.get(),
Unit,
Persistent,
CXXIdx->getClangResourcesPath(),
OnlyLocalDecls,
/*CaptureDiagnostics=*/true,
PrecompilePreamble,
CacheCodeCompletionResults,
/*IncludeBriefCommentsInCodeCompletion=*/false,
/*UserFilesAreVolatile=*/true);
if (DiagTrap.hasErrorOccurred() && CXXIdx->getDisplayDiagnostics())
printDiagsToStderr(Unit);
if (!Success)
return;
if (out_TU)
*out_TU = CXTU->takeTU();
ITUI->result = 0; // success.
}
示例2: clang_indexSourceFile_Impl
//.........这里部分代码省略.........
CInvokCleanup(CInvok.get());
if (CInvok->getFrontendOpts().Inputs.empty())
return CXError_Failure;
typedef SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 8> MemBufferOwner;
std::unique_ptr<MemBufferOwner> BufOwner(new MemBufferOwner);
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<MemBufferOwner> BufOwnerCleanup(
BufOwner.get());
for (auto &UF : unsaved_files) {
std::unique_ptr<llvm::MemoryBuffer> MB =
llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename);
CInvok->getPreprocessorOpts().addRemappedFile(UF.Filename, MB.get());
BufOwner->push_back(std::move(MB));
}
// Since libclang is primarily used by batch tools dealing with
// (often very broken) source code, where spell-checking can have a
// significant negative impact on performance (particularly when
// precompiled headers are involved), we disable it.
CInvok->getLangOpts()->SpellChecking = false;
if (index_options & CXIndexOpt_SuppressWarnings)
CInvok->getDiagnosticOpts().IgnoreWarnings = true;
ASTUnit *Unit = ASTUnit::create(CInvok.get(), Diags, CaptureDiagnostics,
/*UserFilesAreVolatile=*/true);
if (!Unit)
return CXError_InvalidArguments;
std::unique_ptr<CXTUOwner> CXTU(
new CXTUOwner(MakeCXTranslationUnit(CXXIdx, Unit)));
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<CXTUOwner>
CXTUCleanup(CXTU.get());
// Enable the skip-parsed-bodies optimization only for C++; this may be
// revisited.
bool SkipBodies = (index_options & CXIndexOpt_SkipParsedBodiesInSession) &&
CInvok->getLangOpts()->CPlusPlus;
if (SkipBodies)
CInvok->getFrontendOpts().SkipFunctionBodies = true;
std::unique_ptr<IndexingFrontendAction> IndexAction;
IndexAction.reset(new IndexingFrontendAction(client_data, CB,
index_options, CXTU->getTU(),
SkipBodies ? IdxSession->SkipBodyData.get() : nullptr));
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<IndexingFrontendAction>
IndexActionCleanup(IndexAction.get());
bool Persistent = requestedToGetTU;
bool OnlyLocalDecls = false;
bool PrecompilePreamble = false;
bool CacheCodeCompletionResults = false;
PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
PPOpts.AllowPCHWithCompilerErrors = true;
if (requestedToGetTU) {
OnlyLocalDecls = CXXIdx->getOnlyLocalDecls();
PrecompilePreamble = TU_options & CXTranslationUnit_PrecompiledPreamble;
// FIXME: Add a flag for modules.
CacheCodeCompletionResults
= TU_options & CXTranslationUnit_CacheCompletionResults;
}
if (TU_options & CXTranslationUnit_DetailedPreprocessingRecord) {
PPOpts.DetailedRecord = true;
}
if (!requestedToGetTU && !CInvok->getLangOpts()->Modules)
PPOpts.DetailedRecord = false;
DiagnosticErrorTrap DiagTrap(*Diags);
bool Success = ASTUnit::LoadFromCompilerInvocationAction(
CInvok.get(), CXXIdx->getPCHContainerOperations(), Diags,
IndexAction.get(), Unit, Persistent, CXXIdx->getClangResourcesPath(),
OnlyLocalDecls, CaptureDiagnostics, PrecompilePreamble,
CacheCodeCompletionResults,
/*IncludeBriefCommentsInCodeCompletion=*/false,
/*UserFilesAreVolatile=*/true);
if (DiagTrap.hasErrorOccurred() && CXXIdx->getDisplayDiagnostics())
printDiagsToStderr(Unit);
if (isASTReadError(Unit))
return CXError_ASTReadError;
if (!Success)
return CXError_Failure;
if (out_TU)
*out_TU = CXTU->takeTU();
return CXError_Success;
}