本文整理汇总了C++中clang::CompilerInstance类的典型用法代码示例。如果您正苦于以下问题:C++ CompilerInstance类的具体用法?C++ CompilerInstance怎么用?C++ CompilerInstance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompilerInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TextDiagnosticPrinter
void c2ffi::init_ci(config &c, clang::CompilerInstance &ci) {
using clang::DiagnosticOptions;
using clang::TextDiagnosticPrinter;
using clang::TargetOptions;
using clang::TargetInfo;
ci.getInvocation().setLangDefaults(ci.getLangOpts(), c.kind,
clang::LangStandard::lang_unspecified);
DiagnosticOptions *dopt = new DiagnosticOptions;
TextDiagnosticPrinter *tpd =
new TextDiagnosticPrinter(llvm::errs(), dopt, false);
ci.createDiagnostics(tpd);
llvm::IntrusiveRefCntPtr<TargetOptions> *pto =
new llvm::IntrusiveRefCntPtr<TargetOptions>(new TargetOptions());
if(c.arch == "")
(*pto)->Triple = llvm::sys::getDefaultTargetTriple();
else
(*pto)->Triple = c.arch;
TargetInfo *pti = TargetInfo::CreateTargetInfo(ci.getDiagnostics(), pto->getPtr());
ci.setTarget(pti);
ci.createFileManager();
ci.createSourceManager(ci.getFileManager());
ci.createPreprocessor(clang::TU_Complete);
ci.getPreprocessorOpts().UsePredefines = false;
}
示例2: initialize
bool WebCLValidatorAction::initialize(clang::CompilerInstance &instance)
{
if (!WebCLAction::initialize(instance))
return false;
rewriter_ = new clang::Rewriter(
instance.getSourceManager(), instance.getLangOpts());
if (!rewriter_) {
reporter_->fatal("Internal error. Can't create rewriter.\n");
return false;
}
transformer_ = new WebCLTransformer(instance, *rewriter_);
if (!transformer_) {
reporter_->fatal("Internal error. Can't create AST transformer.\n");
return false;
}
// Consumer must be allocated dynamically. The framework deletes
// it.
consumer_ = new WebCLConsumer(instance, *rewriter_, *transformer_);
if (!consumer_) {
reporter_->fatal("Internal error. Can't create AST consumer.\n");
return false;
}
sema_ = new clang::Sema(
instance.getPreprocessor(), instance.getASTContext(), *consumer_);
if (!sema_) {
reporter_->fatal("Internal error. Can't create semantic actions.\n");
return false;
}
return true;
}
示例3:
std::unique_ptr<clang::ASTConsumer>
FindAllSymbolsAction::CreateASTConsumer(clang::CompilerInstance &Compiler,
StringRef InFile) {
Compiler.getPreprocessor().addCommentHandler(&Handler);
Compiler.getPreprocessor().addPPCallbacks(llvm::make_unique<FindAllMacros>(
Reporter, &Compiler.getSourceManager(), &Collector));
return MatchFinder.newASTConsumer();
}
示例4: MkApiASTConsumer2
MkApiASTConsumer2(clang::CompilerInstance &CI, llvm::StringRef InFile)
: mpVisitor(0)
{
CI.setASTConsumer(this);
//cout << "predefines: " << CI.getPreprocessor().getPredefines() << endl;
// A Rewriter helps us manage the code rewriting task.
mRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
mpVisitor = new MkApiASTVisitor(mRewriter);
}
示例5: getFileName
std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) {
clang::FileID fid = ci.getSourceManager().getFileID(sl) ;
if ( ! fid.isInvalid() ) {
const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ;
if ( fe != NULL ) {
char * resolved_path = almostRealPath( fe->getName() ) ;
if ( resolved_path != NULL and hsd.isPathInUserDir(resolved_path)) {
return std::string(resolved_path) ;
}
}
}
return std::string() ;
}
示例6: MatchFinder
std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
clang::CompilerInstance &Compiler, StringRef File) {
// FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
// modify Compiler.
Context.setSourceManager(&Compiler.getSourceManager());
Context.setCurrentFile(File);
Context.setASTContext(&Compiler.getASTContext());
std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
CheckFactories->createChecks(&Context, Checks);
ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
if (auto *P = Context.getCheckProfileData())
FinderOptions.CheckProfiling.emplace(P->Records);
std::unique_ptr<ast_matchers::MatchFinder> Finder(
new ast_matchers::MatchFinder(std::move(FinderOptions)));
for (auto &Check : Checks) {
Check->registerMatchers(&*Finder);
Check->registerPPCallbacks(Compiler);
}
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
if (!Checks.empty())
Consumers.push_back(Finder->newASTConsumer());
AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts();
// FIXME: Remove this option once clang's cfg-temporary-dtors option defaults
// to true.
AnalyzerOptions->Config["cfg-temporary-dtors"] =
Context.getOptions().AnalyzeTemporaryDtors ? "true" : "false";
GlobList &Filter = Context.getChecksFilter();
AnalyzerOptions->CheckersControlList = getCheckersControlList(Filter);
if (!AnalyzerOptions->CheckersControlList.empty()) {
setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
AnalyzerOptions->AnalyzeNestedBlocks = true;
AnalyzerOptions->eagerlyAssumeBinOpBifurcation = true;
std::unique_ptr<ento::AnalysisASTConsumer> AnalysisConsumer =
ento::CreateAnalysisConsumer(Compiler);
AnalysisConsumer->AddDiagnosticConsumer(
new AnalyzerDiagnosticConsumer(Context));
Consumers.push_back(std::move(AnalysisConsumer));
}
return llvm::make_unique<ClangTidyASTConsumer>(
std::move(Consumers), std::move(Finder), std::move(Checks));
}
示例7: parseAST
bool parseAST(const char* szSourceCodeFilePath, clang::ast_matchers::MatchFinder finder)
{
// create the compiler instance setup for this file as main file
prepareCompilerforFile(szSourceCodeFilePath);
std::unique_ptr<clang::ASTConsumer> pAstConsumer (finder.newASTConsumer());
clang::DiagnosticConsumer& diagConsumer = m_CompilerInstance.getDiagnosticClient();
diagConsumer.BeginSourceFile(m_CompilerInstance.getLangOpts(), &m_CompilerInstance.getPreprocessor());
clang::ParseAST(m_CompilerInstance.getPreprocessor(), pAstConsumer.get(), m_CompilerInstance.getASTContext());
diagConsumer.EndSourceFile();
return diagConsumer.getNumErrors() != 0;
}
示例8: recordSourceFileUnit
static bool
recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
StringRef indexStorePath, bool indexSystemModules,
bool isDebugCompilation, StringRef targetTriple,
ArrayRef<const clang::FileEntry *> fileDependencies,
const clang::CompilerInstance &clangCI,
DiagnosticEngine &diags) {
auto &fileMgr = clangCI.getFileManager();
auto *module = primarySourceFile->getParentModule();
bool isSystem = module->isSystemModule();
auto *mainFile = fileMgr.getFile(primarySourceFile->getFilename());
// FIXME: Get real values for the following.
StringRef swiftVersion;
StringRef sysrootPath = clangCI.getHeaderSearchOpts().Sysroot;
IndexUnitWriter unitWriter(fileMgr, indexStorePath,
"swift", swiftVersion, indexUnitToken, module->getNameStr(),
mainFile, isSystem, /*isModuleUnit=*/false, isDebugCompilation,
targetTriple, sysrootPath, getModuleInfoFromOpaqueModule);
// Module dependencies.
ModuleDecl::ImportFilter importFilter;
importFilter |= ModuleDecl::ImportFilterKind::Public;
importFilter |= ModuleDecl::ImportFilterKind::Private;
importFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
SmallVector<ModuleDecl::ImportedModule, 8> imports;
primarySourceFile->getImportedModules(imports, importFilter);
StringScratchSpace moduleNameScratch;
addModuleDependencies(imports, indexStorePath, indexSystemModules,
targetTriple, clangCI, diags, unitWriter, moduleNameScratch);
// File dependencies.
for (auto *F : fileDependencies)
unitWriter.addFileDependency(F, /*FIXME:isSystem=*/false, /*Module=*/nullptr);
recordSourceFile(primarySourceFile, indexStorePath, diags,
[&](StringRef recordFile, StringRef filename) {
unitWriter.addRecordFile(recordFile, fileMgr.getFile(filename),
module->isSystemModule(), /*Module=*/nullptr);
});
std::string error;
if (unitWriter.write(error)) {
diags.diagnose(SourceLoc(), diag::error_write_index_unit, error);
return true;
}
return false;
}
示例9: MyASTConsumer
MyASTConsumer(clang::CompilerInstance &ci) : clang::ASTConsumer(), ci(ci),
annotator (OutputPath, DataPath)
{
for(std::string &s : ProjectPaths) {
auto colonPos = s.find(':');
if (colonPos >= s.size()) {
std::cerr << "fail to parse project option : " << s << std::endl;
continue;
}
auto secondColonPos = s.find(':', colonPos+1);
ProjectInfo info { s.substr(0, colonPos), s.substr(colonPos+1, secondColonPos - colonPos -1),
secondColonPos < s.size() ? s.substr(secondColonPos + 1) : std::string() };
annotator.addProject(std::move(info));
}
for(std::string &s : ExternalProjectPaths) {
auto colonPos = s.find(':');
if (colonPos >= s.size()) {
std::cerr << "fail to parse project option : " << s << std::endl;
continue;
}
auto secondColonPos = s.find(':', colonPos+1);
if (secondColonPos >= s.size()) {
std::cerr << "fail to parse project option : " << s << std::endl;
continue;
}
ProjectInfo info { s.substr(0, colonPos), s.substr(colonPos+1, secondColonPos - colonPos -1),
ProjectInfo::External };
info.external_root_url = s.substr(secondColonPos + 1);
annotator.addProject(std::move(info));
}
//ci.getLangOpts().DelayedTemplateParsing = (true);
ci.getPreprocessor().enableIncrementalProcessing();
}
示例10: prepareCompilerforFile
void prepareCompilerforFile(const char* szSourceCodeFilePath)
{
// To reuse the source manager we have to create these tables.
m_CompilerInstance.getSourceManager().clearIDTables();
//m_CompilerInstance.InitializeSourceManager(clang::FrontendInputFile(szSourceCodeFilePath, clang::InputKind::IK_C));// ger(m_CompilerInstance.getFileManager());
// supply the file to the source manager and set it as main-file
const clang::FileEntry * file = m_CompilerInstance.getFileManager().getFile(szSourceCodeFilePath);
clang::FileID fileID = m_CompilerInstance.getSourceManager().createFileID(file, clang::SourceLocation(), clang::SrcMgr::CharacteristicKind::C_User);
m_CompilerInstance.getSourceManager().setMainFileID(fileID);
// CodeGenAction needs this
clang::FrontendOptions& feOptions = m_CompilerInstance.getFrontendOpts();
feOptions.Inputs.clear();
feOptions.Inputs.push_back(clang::FrontendInputFile(szSourceCodeFilePath, clang::FrontendOptions::getInputKindForExtension(clang::StringRef(szSourceCodeFilePath).rsplit('.').second), false));
}
示例11: CreateASTConsumer
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &CI, StringRef InFile) override {
CI.setExternalSemaSource(SemaSource);
SemaSource->setFilePath(InFile);
SemaSource->setCompilerInstance(&CI);
return llvm::make_unique<ASTConsumerManagerWrapper>(SymbolIndexMgr);
}
示例12: handleBeginSource
bool CollectMacrosSourceFileCallbacks::handleBeginSource(clang::CompilerInstance &compilerInstance)
{
auto callbacks = std::make_unique<CollectMacrosPreprocessorCallbacks>(
m_symbolEntries,
m_sourceLocationEntries,
m_sourceFiles,
m_usedMacros,
m_fileStatuses,
m_sourceDependencies,
m_filePathCache,
compilerInstance.getSourceManager(),
compilerInstance.getPreprocessorPtr());
compilerInstance.getPreprocessorPtr()->addPPCallbacks(std::move(callbacks));
return true;
}
示例13: sizeOfPointer
int TypeUtils::sizeOfPointer(const clang::CompilerInstance &ci, clang::QualType qt)
{
if (!qt.getTypePtrOrNull())
return -1;
// HACK: What's a better way of getting the size of a pointer ?
auto &astContext = ci.getASTContext();
return astContext.getTypeSize(astContext.getPointerType(qt));
}
示例14: isInUserOrTrickCode
bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) {
clang::FileID fid = ci.getSourceManager().getFileID(sl) ;
bool ret = false ;
if ( ! fid.isInvalid() ) {
const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ;
if ( fe != NULL ) {
char * resolved_path = almostRealPath( fe->getName() ) ;
if ( resolved_path != NULL ) {
if ( hsd.isPathInUserOrTrickDir(resolved_path)) {
ret = true ;
}
free(resolved_path) ;
}
}
}
return ret ;
}
示例15: set_location
void Decl::set_location(clang::CompilerInstance &ci, const clang::Decl *d) {
clang::SourceLocation sloc = d->getLocation();
if(sloc.isValid()) {
std::string loc = sloc.printToString(ci.getSourceManager());
set_location(loc);
}
}