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


C++ Statement::copy方法代码示例

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


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

示例1: processEndExpr

/***************************************************************
* Function: processEndExpr(StmtSequence*)
* Purpose : Pre-process range end expressions in sequences
* Initial : Maxime Chevalier-Boisvert on March 1, 2009
****************************************************************
Revisions and bug fixes:
*/
StmtSequence* processEndExpr(StmtSequence* pSeq, ProgFunction* pFunction)
{
	// Get a reference to the statement vector
	const StmtSequence::StmtVector& seqStmts = pSeq->getStatements();
	
	// Create a statement vector to store the transformed output
	StmtSequence::StmtVector output;
	
	// For each statement in the sequence
	for (StmtSequence::StmtVector::const_iterator stmtItr = seqStmts.begin(); stmtItr != seqStmts.end(); ++stmtItr)
	{
		// Get a pointer to the statement
		Statement* pStmt = *stmtItr;

		// Switch on the statement type
		switch (pStmt->getStmtType())
		{
			// Expression statement
			case Statement::EXPR:
			{
				// Get a typed pointer to the statement 
				ExprStmt* pExprStmt = (ExprStmt*)pStmt;
				
				// Transform the expression
				output.push_back(
					new ExprStmt(
						processEndExpr(pExprStmt->getExpression(), pFunction), 
						pExprStmt->getSuppressFlag()
					)
				);
			}
			break;

			// Assignment statement
			case Statement::ASSIGN:
			{
				// Get a typed pointer to the statement 
				AssignStmt* pAssignStmt = (AssignStmt*)pStmt;
			
				// Get a reference to the left expressions
				const AssignStmt::ExprVector& leftExprs = pAssignStmt->getLeftExprs();
				
				// Create a vector for the transformed left-expressions
				AssignStmt::ExprVector newLExprs;
				
				// Transform the left-side expressions
				for (AssignStmt::ExprVector::const_iterator itr = leftExprs.begin(); itr != leftExprs.end(); ++itr)
					newLExprs.push_back(processEndExpr(*itr, pFunction));
				
				// Transform the right-side expression
				Expression* pRightExpr = processEndExpr(pAssignStmt->getRightExpr(), pFunction);
				
				// Create and return the transformed assignment statement object
				output.push_back(new AssignStmt(newLExprs, pRightExpr, pAssignStmt->getSuppressFlag()));
			}
			break;
			
			// If-else statement
			case Statement::IF_ELSE:
			{
				// Get a typed pointer to the statement 
				IfElseStmt* pIfStmt = (IfElseStmt*)pStmt;
				
				// Transform the statement
				output.push_back(
					new IfElseStmt(
						processEndExpr(pIfStmt->getCondition(), pFunction),
						processEndExpr(pIfStmt->getIfBlock(), pFunction),
						processEndExpr(pIfStmt->getElseBlock(), pFunction)
					)
				);
			}
			break;
			
			// Loop statement
			case Statement::LOOP:
			{
				// Get a typed pointer to the statement 
				LoopStmt* pLoopStmt = (LoopStmt*)pStmt;

				// Transform the expression
				output.push_back(
					new LoopStmt(
						pLoopStmt->getIndexVar()? pLoopStmt->getIndexVar()->copy():NULL,
						pLoopStmt->getTestVar()? pLoopStmt->getTestVar()->copy():NULL,
						processEndExpr(pLoopStmt->getInitSeq(), pFunction),
						processEndExpr(pLoopStmt->getTestSeq(), pFunction),
						processEndExpr(pLoopStmt->getBodySeq(), pFunction),
						processEndExpr(pLoopStmt->getIncrSeq(), pFunction),
                        pLoopStmt->getAnnotations()
					)
				);
			}
//.........这里部分代码省略.........
开发者ID:Sable,项目名称:mcvm,代码行数:101,代码来源:transform_endexpr.cpp

示例2: transformLogic


//.........这里部分代码省略.........
		Statement* pStmt = *stmtItr;
		
		// Switch on the statement type
		switch (pStmt->getStmtType())
		{
			// Expression statement
			case Statement::EXPR:
			{
				// Get a typed pointer to the statement
				ExprStmt* pExprStmt = (ExprStmt*)pStmt;
				
				// Transform the expression
				Expression* pNewExpr = transformLogicExpr(pExprStmt->getExpression(), output, pFunction);
				
				// Create a new expression statement
				output.push_back(new ExprStmt(pNewExpr, pExprStmt->getSuppressFlag()));
			}
			break;
			
			// Assignment statement
			case Statement::ASSIGN:
			{
				// Get a typed pointer to the statement
				AssignStmt* pAssignStmt = (AssignStmt*)pStmt;
	
				// Get the left expressions for this assignment
				const AssignStmt::ExprVector& leftExprs = pAssignStmt->getLeftExprs();
				
				// Create a vector to store the transformed left expressions
				AssignStmt::ExprVector newLeftExprs;
				
				// For each left expression
				for (AssignStmt::ExprVector::const_iterator itr = leftExprs.begin(); itr != leftExprs.end(); ++itr)
					newLeftExprs.push_back(transformLogicExpr(*itr, output, pFunction));
				
				// Transform the right expression
				Expression* pNewRExpr = transformLogicExpr(pAssignStmt->getRightExpr(), output, pFunction);
				
				// Create a new assignment statement
				output.push_back(new AssignStmt(newLeftExprs, pNewRExpr, pAssignStmt->getSuppressFlag()));
			}
			break;
		
			// If-else statement
			case Statement::IF_ELSE:
			{
				// Get a typed pointer to the statement
				IfElseStmt* pIfStmt = (IfElseStmt*)pStmt;
								
				// Transform the test expression
				Expression* pNewTest = transformLogicExpr(pIfStmt->getCondition(), output, pFunction);
				
				// Convert the if and else blocks to split form
				StmtSequence* pNewIfBlock = transformLogic(pIfStmt->getIfBlock(), pFunction);
				StmtSequence* pNewElseBlock = transformLogic(pIfStmt->getElseBlock(), pFunction);
				
				// Create a new if-else statement and add it to the vector
				output.push_back(new IfElseStmt(pNewTest, pNewIfBlock, pNewElseBlock));
			}
			break;
			
			// Loop statement
			case Statement::LOOP:
			{
				// Get a typed pointer to the statement
				LoopStmt* pLoopStmt = (LoopStmt*)pStmt;
				
				// Transform the statement sequences of the loop
				StmtSequence* pNewInitSeq = transformLogic(pLoopStmt->getInitSeq(), pFunction);
				StmtSequence* pNewTestSeq = transformLogic(pLoopStmt->getTestSeq(), pFunction);
				StmtSequence* pNewBodySeq = transformLogic(pLoopStmt->getBodySeq(), pFunction);
				StmtSequence* pNewIncrSeq = transformLogic(pLoopStmt->getIncrSeq(), pFunction);
				
				// Create a new loop statement
				output.push_back(
					new LoopStmt(
						pLoopStmt->getIndexVar(),
						pLoopStmt->getTestVar(),
						pNewInitSeq,
						pNewTestSeq,
						pNewBodySeq,
						pNewIncrSeq,
                        pLoopStmt->getAnnotations()			
					)
				);
			}
			break;

			// Other statement types
			default:
			{
				// Copy the statement and add it to the output
				output.push_back(pStmt->copy());
			}
		}
	}
	
	// Return the transformed output
	return new StmtSequence(output);
}
开发者ID:Sable,项目名称:mcvm,代码行数:101,代码来源:transform_logic.cpp


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