当前位置: 首页>>代码示例>>C++>>正文


C++ SourceManager::getExpansionLoc方法代码示例

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


在下文中一共展示了SourceManager::getExpansionLoc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getStmtRangeWithSemicolon

// Get the source range of the specified Stmt, ensuring that a semicolon is
// included, if necessary - since the clang ranges do not guarantee this.
SrcRange getStmtRangeWithSemicolon(const clang::Stmt *S,
                                   const clang::SourceManager& sm,
                                   const clang::LangOptions& options)
{
	clang::SourceLocation SLoc = sm.getExpansionLoc(S->getLocStart());
	clang::SourceLocation ELoc = sm.getExpansionLoc(S->getLocEnd());
	unsigned start = sm.getFileOffset(SLoc);
	unsigned end   = sm.getFileOffset(ELoc);

	// Below code copied from clang::Lexer::MeasureTokenLength():
	clang::SourceLocation Loc = sm.getExpansionLoc(ELoc);
	std::pair<clang::FileID, unsigned> LocInfo = sm.getDecomposedLoc(Loc);
	llvm::StringRef Buffer = sm.getBufferData(LocInfo.first);
	const char *StrData = Buffer.data()+LocInfo.second;
	clang::Lexer TheLexer(Loc, options, Buffer.begin(), StrData, Buffer.end());
	clang::Token TheTok;
	TheLexer.LexFromRawLexer(TheTok);
	// End copied code.
	end += TheTok.getLength();

	// Check if we the source range did include the semicolon.
	if (TheTok.isNot(clang::tok::semi) && TheTok.isNot(clang::tok::r_brace)) {
		TheLexer.LexFromRawLexer(TheTok);
		if (TheTok.is(clang::tok::semi)) {
			end += TheTok.getLength();
		}
	}

	return SrcRange(start, end);
}
开发者ID:AugustusHuang,项目名称:ccons,代码行数:32,代码来源:ClangUtils.cpp

示例2: getMacroRange

// Get the source range of the macro definition excluding the #define.
SrcRange getMacroRange(const clang::MacroInfo *MI,
                       const clang::SourceManager& sm,
                       const clang::LangOptions& options)
{
	clang::SourceLocation SLoc = sm.getExpansionLoc(MI->getDefinitionLoc());
	clang::SourceLocation ELoc = sm.getExpansionLoc(MI->getDefinitionEndLoc());
	return constructSrcRange(sm, options, SLoc, ELoc);
}
开发者ID:AugustusHuang,项目名称:ccons,代码行数:9,代码来源:ClangUtils.cpp

示例3: getStmtRange

// Get the source range of the specified Stmt.
SrcRange getStmtRange(const clang::Stmt *S,
                      const clang::SourceManager& sm,
                      const clang::LangOptions& options)
{
	clang::SourceLocation SLoc = sm.getExpansionLoc(S->getLocStart());
	clang::SourceLocation ELoc = sm.getExpansionLoc(S->getLocEnd());
	// This is necessary to get the correct range of function-like macros.
	if (SLoc == ELoc && S->getLocEnd().isMacroID())
		ELoc = sm.getExpansionRange(S->getLocEnd()).second;
	return constructSrcRange(sm, options, SLoc, ELoc);
}
开发者ID:AugustusHuang,项目名称:ccons,代码行数:12,代码来源:ClangUtils.cpp

示例4: getExpansionLoc

	clang::SourceLocation getExpansionLoc(const clang::SourceManager& sm, clang::SourceLocation loc) {
		if(sm.isMacroArgExpansion(loc)) { loc = sm.getExpansionLoc(loc); }
		return loc;
	}
开发者ID:zmanchun,项目名称:insieme,代码行数:4,代码来源:source_locations.cpp


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