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


C++ SourceFile::createDataTargetForEntryPoint方法代码示例

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


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

示例1: runtime_error

//! Takes an AST node subclass and returns an appropriate DataTarget object that contains
//! the same information. Supported AST node types are:
//! - SymbolASTNode
//! - NaturalLocationASTNode
//! - AddressRangeASTNode
//!
//! \exception elftosb::semantic_error Thrown if a semantic problem is found with
//!		the target node.
DataTarget * ConversionController::createTargetFromNode(ASTNode * targetNode)
{
	assert(targetNode);
	
	DataTarget * target = NULL;
	SymbolASTNode * symbolNode;
	NaturalLocationASTNode * naturalNode;
	AddressRangeASTNode * addressNode;
	
	if (symbolNode = dynamic_cast<SymbolASTNode*>(targetNode))
	{
		SourceFile * sourceFile = getSourceFromName(symbolNode->getSource(), symbolNode->getFirstLine());
		std::string * symbolName = symbolNode->getSymbolName();
		
		// symbol name is optional
		if (symbolName)
		{
			if (!sourceFile->supportsNamedSymbols())
			{
				throw std::runtime_error(format_string("line %d: source does not support symbols", symbolNode->getFirstLine()));
			}
			
			target = sourceFile->createDataTargetForSymbol(*symbolName);
			if (!target)
			{
				throw std::runtime_error(format_string("line %d: source does not have a symbol with that name", symbolNode->getFirstLine()));
			}
		}
		else
		{
			// no symbol name was specified so use entry point
			target = sourceFile->createDataTargetForEntryPoint();
			if (!target)
			{
				throw std::runtime_error(format_string("line %d: source does not have an entry point", symbolNode->getFirstLine()));
			}
		}
	}
	else if (naturalNode = dynamic_cast<NaturalLocationASTNode*>(targetNode))
	{
		// the target is the source's natural location
		target = new NaturalDataTarget();
	}
	else if (addressNode = dynamic_cast<AddressRangeASTNode*>(targetNode))
	{
		// evaluate begin address
		ExprASTNode * beginExpr = dynamic_cast<ExprASTNode*>(addressNode->getBegin());
		if (!beginExpr)
		{
			throw semantic_error("address range must always have a beginning expression");
		}
		IntConstExprASTNode * beginIntExpr = dynamic_cast<IntConstExprASTNode*>(beginExpr->reduce(m_context));
		if (!beginIntExpr)
		{
			throw semantic_error("address range begin did not evaluate to an integer");
		}
		uint32_t beginAddress = static_cast<uint32_t>(beginIntExpr->getValue());
		
		// evaluate end address
		ExprASTNode * endExpr = dynamic_cast<ExprASTNode*>(addressNode->getEnd());
		uint32_t endAddress = 0;
		bool hasEndAddress = false;
		if (endExpr)
		{
			IntConstExprASTNode * endIntExpr = dynamic_cast<IntConstExprASTNode*>(endExpr->reduce(m_context));
			if (!endIntExpr)
			{
				throw semantic_error("address range end did not evaluate to an integer");
			}
			endAddress = static_cast<uint32_t>(endIntExpr->getValue());
			hasEndAddress = true;
		}
		
		// create target
		if (hasEndAddress)
		{
			target = new ConstantDataTarget(beginAddress, endAddress);
		}
		else
		{
			target = new ConstantDataTarget(beginAddress);
		}
	}
	else
	{
		throw semantic_error("unexpected load target node type");
	}
	
	return target;
}
开发者ID:AmesianX,项目名称:elftosb,代码行数:98,代码来源:ConversionController.cpp


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