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


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

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


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

示例1: if

//! Takes an AST node that is one of the following subclasses and creates the corresponding
//! type of DataSource object from it.
//! - StringConstASTNode
//! - ExprASTNode
//! - SourceASTNode
//! - SectionASTNode
//! - SectionMatchListASTNode
//! - BlobConstASTNode
//! - IVTConstASTNode
//!
//! \exception elftosb::semantic_error Thrown if a semantic problem is found with
//!		the data node.
//! \exception std::runtime_error Thrown if an error occurs that shouldn't be possible
//!		based on the grammar.
DataSource * ConversionController::createSourceFromNode(ASTNode * dataNode)
{
	assert(dataNode);
	
	DataSource * source = NULL;
	StringConstASTNode * stringNode;
	BlobConstASTNode * blobNode;
	ExprASTNode * exprNode;
	SourceASTNode * sourceNode;
	SectionASTNode * sectionNode;
	SectionMatchListASTNode * matchListNode;
    IVTConstASTNode * ivtNode;
	
	if (stringNode = dynamic_cast<StringConstASTNode*>(dataNode))
	{
		// create a data source with the string contents
		std::string * stringData = stringNode->getString();
		const uint8_t * stringContents = reinterpret_cast<const uint8_t *>(stringData->c_str());
		source = new UnmappedDataSource(stringContents, static_cast<unsigned>(stringData->size()));
	}
	else if (blobNode = dynamic_cast<BlobConstASTNode*>(dataNode))
	{
		// create a data source with the raw binary data
		Blob * blob = blobNode->getBlob();
		source = new UnmappedDataSource(blob->getData(), blob->getLength());
	}
	else if (exprNode = dynamic_cast<ExprASTNode*>(dataNode))
	{
		// reduce the expression first
		exprNode = exprNode->reduce(m_context);
		IntConstExprASTNode * intNode = dynamic_cast<IntConstExprASTNode*>(exprNode);
		if (!intNode)
		{
			throw semantic_error("load pattern expression did not evaluate to an integer");
		}
		
		SizedIntegerValue intValue(intNode->getValue(), intNode->getSize());
		source = new PatternSource(intValue);
	}
	else if (sourceNode = dynamic_cast<SourceASTNode*>(dataNode))
	{
		// load the entire source contents
		SourceFile * sourceFile = getSourceFromName(sourceNode->getSourceName(), sourceNode->getFirstLine());
		source = sourceFile->createDataSource();
	}
	else if (sectionNode = dynamic_cast<SectionASTNode*>(dataNode))
	{
		// load some subset of the source
		SourceFile * sourceFile = getSourceFromName(sectionNode->getSourceName(), sectionNode->getFirstLine());
		if (!sourceFile->supportsNamedSections())
		{
			throw semantic_error(format_string("line %d: source does not support sections", sectionNode->getFirstLine()));
		}
		
		// create data source from the section name
		std::string * sectionName = sectionNode->getSectionName();
		GlobMatcher globber(*sectionName);
		source = sourceFile->createDataSource(globber);
		if (!source)
		{
			throw semantic_error(format_string("line %d: no sections match the pattern", sectionNode->getFirstLine()));
		}
	}
	else if (matchListNode = dynamic_cast<SectionMatchListASTNode*>(dataNode))
	{
		SourceFile * sourceFile = getSourceFromName(matchListNode->getSourceName(), matchListNode->getFirstLine());
		if (!sourceFile->supportsNamedSections())
		{
			throw semantic_error(format_string("line %d: source type does not support sections", matchListNode->getFirstLine()));
		}
		
		// create string matcher
		ExcludesListMatcher matcher;
		
		// add each pattern to the matcher
		ListASTNode * matchList = matchListNode->getSections();
		ListASTNode::iterator it = matchList->begin();
		for (; it != matchList->end(); ++it)
		{
			ASTNode * node = *it;
			sectionNode = dynamic_cast<SectionASTNode*>(node);
			if (!sectionNode)
			{
				throw std::runtime_error(format_string("line %d: unexpected node type in section pattern list", (*it)->getFirstLine()));
			}
			bool isInclude = sectionNode->getAction() == SectionASTNode::kInclude;
//.........这里部分代码省略.........
开发者ID:AmesianX,项目名称:elftosb,代码行数:101,代码来源:ConversionController.cpp


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