• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ clang::CompilerInstance类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中clang::CompilerInstance的典型用法代码示例。如果您正苦于以下问题:C++ CompilerInstance类的具体用法?C++ CompilerInstance怎么用?C++ CompilerInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CompilerInstance类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:pfalcon,项目名称:c2ffi,代码行数:29,代码来源:init.cpp


示例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;
}
开发者ID:KhronosGroup,项目名称:webcl-validator,代码行数:35,代码来源:WebCLAction.cpp


示例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();
}
开发者ID:adiog,项目名称:clang-tools-extra,代码行数:8,代码来源:FindAllSymbolsAction.cpp


示例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);
 }
开发者ID:capturePointer,项目名称:dllapi,代码行数:9,代码来源:mkapi.cpp


示例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() ;
}
开发者ID:lonnell,项目名称:trick,代码行数:13,代码来源:Utilities.cpp


示例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));
}
开发者ID:MorpheusCommunity,项目名称:clang-tools-extra,代码行数:51,代码来源:ClangTidy.cpp


示例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;
	}
开发者ID:KrishnaPG,项目名称:CodingAssistant-Clang,代码行数:14,代码来源:main.cpp


示例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;
}
开发者ID:JoniusLi,项目名称:swift-1,代码行数:49,代码来源:IndexRecord.cpp


示例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();
    }
开发者ID:mengjues,项目名称:woboq_codebrowser,代码行数:35,代码来源:main.cpp


示例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));
	}
开发者ID:KrishnaPG,项目名称:CodingAssistant-Clang,代码行数:16,代码来源:main.cpp


示例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);
 }
开发者ID:cierpuchaw,项目名称:clang-tools-extra,代码行数:7,代码来源:IncludeFixerPlugin.cpp


示例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;
}
开发者ID:choenig,项目名称:qt-creator,代码行数:17,代码来源:collectmacrossourcefilecallbacks.cpp


示例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));
}
开发者ID:EugeneZelenko,项目名称:clazy,代码行数:8,代码来源:TypeUtils.cpp


示例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 ;
}
开发者ID:lonnell,项目名称:trick,代码行数:17,代码来源:Utilities.cpp


示例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);
    }
}
开发者ID:abduld,项目名称:c2ffi,代码行数:8,代码来源:Decl.cpp


示例16: emitLLVM

	// Executes CodeGenAction and returns the pointer (caller should own and delete it)
	// Returns NULL on failure (in case of any compiler errors etc.)
	clang::CodeGenAction* emitLLVM(const char* szSourceCodeFilePath)
	{
		// create the compiler instance setup for this file as the main file
		prepareCompilerforFile(szSourceCodeFilePath);

		// Create an action and make the compiler instance carry it out
		clang::CodeGenAction *Act = new clang::EmitLLVMOnlyAction();
		if (!m_CompilerInstance.ExecuteAction(*Act))
			return NULL;

		return Act;
	}
开发者ID:KrishnaPG,项目名称:CodingAssistant-Clang,代码行数:14,代码来源:main.cpp


示例17: if

void c2ffi::process_macros(clang::CompilerInstance &ci, std::ostream &os) {
    using namespace c2ffi;

    clang::SourceManager &sm = ci.getSourceManager();
    clang::Preprocessor &pp = ci.getPreprocessor();

    for(clang::Preprocessor::macro_iterator i = pp.macro_begin();
        i != pp.macro_end(); i++) {
        const clang::MacroInfo *mi = (*i).second->getMacroInfo();
        const clang::SourceLocation sl = mi->getDefinitionLoc();
        std::string loc = sl.printToString(sm);
        const char *name = (*i).first->getNameStart();

        if(mi->isBuiltinMacro() || loc.substr(0,10) == "<built-in>") {
        } else if(mi->isFunctionLike()) {
        } else if(best_guess type = macro_type(pp, name, mi)) {
            os << "/* " << loc << " */" << std::endl;
            os << "#define " << name << " "
                      << macro_to_string(pp, mi)
                      << std::endl << std::endl;
        }
    }


    for(clang::Preprocessor::macro_iterator i = pp.macro_begin();
        i != pp.macro_end(); i++) {
        clang::MacroInfo *mi = (*i).second->getMacroInfo();
        clang::SourceLocation sl = mi->getDefinitionLoc();
        std::string loc = sl.printToString(sm);
        const char *name = (*i).first->getNameStart();

        if(mi->isBuiltinMacro() || loc.substr(0,10) == "<built-in>") {
        } else if(mi->isFunctionLike()) {
        } else if(best_guess type = macro_type(pp, name, mi)) {
            output_redef(pp, name, mi, type, os);
        }
    }
}
开发者ID:furunkel,项目名称:c2ffi,代码行数:38,代码来源:Expr.cpp


示例18: lookup

void c2ffi::add_include(clang::CompilerInstance &ci, const char *path, bool is_angled,
                        bool show_error) {
    struct stat buf;
    if(stat(path, &buf) < 0 || !S_ISDIR(buf.st_mode)) {
        if(show_error) {
            std::cerr << "Error: Not a directory: ";
            if(is_angled)
                std::cerr << "-i ";
            else
                std::cerr << "-I ";

            std::cerr << path << std::endl;
            exit(1);
        }

        return;
    }

    const clang::DirectoryEntry *dirent = ci.getFileManager().getDirectory(path);
    clang::DirectoryLookup lookup(dirent, clang::SrcMgr::C_System, false);

    ci.getPreprocessor().getHeaderSearchInfo()
        .AddSearchPath(lookup, is_angled);
}
开发者ID:rmattes,项目名称:c2ffi,代码行数:24,代码来源:init.cpp


示例19: CreateASTConsumer

TriaAction::CreateAstConsumerResultType TriaAction::CreateASTConsumer (clang::CompilerInstance &ci,
                                                                       llvm::StringRef fileName) {
	ci.getFrontendOpts().SkipFunctionBodies = true;
	ci.getPreprocessor().enableIncrementalProcessing (true);
	ci.getLangOpts().DelayedTemplateParsing = true;
	
	// Enable everything for code compatibility
	ci.getLangOpts().MicrosoftExt = true;
	ci.getLangOpts().DollarIdents = true;
	ci.getLangOpts().CPlusPlus11 = true;
	ci.getLangOpts().GNUMode = true;
	
#if CLANG_VERSION_MINOR < 6
	ci.getLangOpts().CPlusPlus1y = true;
#else
	ci.getLangOpts().CPlusPlus14 = true;
#endif
	
	if (argVerboseTimes) {
		UNIQUE_COMPAT(PreprocessorHooks, hook, new PreprocessorHooks (ci));
		hook->timing ()->name = sourceFileName (this->m_definitions->sourceFiles ());
		this->m_definitions->setTimingNode (hook->timing ());
		ci.getPreprocessor ().addPPCallbacks (MOVE_COMPAT(hook));
	}
	
	// 
	QStringList whichInherit;
	for (const std::string &cur : argInspectBases) {
		whichInherit.append (QString::fromStdString (cur));
	}
	
	// 
	TriaASTConsumer *consumer = new TriaASTConsumer (ci, fileName, whichInherit, argInspectAll,
	                                                 argGlobalClass, this->m_definitions);
	
#if CLANG_VERSION_MINOR < 6
	return consumer;
#else
	return std::unique_ptr< clang::ASTConsumer > (consumer);
#endif
}
开发者ID:NuriaProject,项目名称:Tria,代码行数:41,代码来源:triaaction.cpp


示例20: BeginSourceFileAction

  bool
  BeginSourceFileAction(
      clang::CompilerInstance &CI, StringRef Filename) override {
    xmlDoc = xmlNewDoc(BAD_CAST "1.0");
    xmlNodePtr rootnode = xmlNewNode(nullptr, BAD_CAST "clangAST");
    xmlDocSetRootElement(xmlDoc, rootnode);

    char strftimebuf[BUFSIZ];
    time_t t = time(nullptr);

    strftime(strftimebuf, sizeof strftimebuf, "%F %T", localtime(&t));

    xmlNewProp(rootnode, BAD_CAST "source", BAD_CAST Filename.data());
    xmlNewProp(rootnode,
        BAD_CAST "language",
        BAD_CAST getLanguageString(CI.getLangOpts()));
    xmlNewProp(rootnode, BAD_CAST "time", BAD_CAST strftimebuf);

    return true;
  };
开发者ID:omni-compiler,项目名称:ClangXcodeML,代码行数:20,代码来源:CXXtoXML.cpp



注:本文中的clang::CompilerInstance类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ clang::Preprocessor类代码示例发布时间:2022-05-31
下一篇:
C++ clang::ASTContext类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap