本文整理汇总了C++中clang::CompilerInstance::getSourceManager方法的典型用法代码示例。如果您正苦于以下问题:C++ CompilerInstance::getSourceManager方法的具体用法?C++ CompilerInstance::getSourceManager怎么用?C++ CompilerInstance::getSourceManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clang::CompilerInstance
的用法示例。
在下文中一共展示了CompilerInstance::getSourceManager方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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() ;
}
示例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: 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));
}
示例4: 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);
}
}
示例5:
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();
}
示例6: 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 ;
}
示例7: mpVisitor
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);
}
示例8: 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));
}
示例9: 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;
}
示例10: 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);
}
}
}
示例11: CI
IncludeDirectives::IncludeDirectives(clang::CompilerInstance &CI)
: CI(CI), Sources(CI.getSourceManager()) {
// addPPCallbacks takes ownership of the callback
CI.getPreprocessor().addPPCallbacks(new IncludeDirectivesPPCallback(this));
}