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


C++ SgVariableDeclaration::get_traversalSuccessorContainer方法代码示例

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


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

示例1: newDeclaration

MySynthesizedAttribute
MyTraversal::evaluateRewriteSynthesizedAttribute (
		SgNode* astNode,
		MyInheritedAttribute inheritedAttribute,
		SubTreeSynthesizedAttributes synthesizedAttributeList )
{
	MySynthesizedAttribute returnAttribute;

	switch(astNode->variantT())
	{

		case V_SgVarRefExp: {
				cout << " found V_SgVarRefExp " << astNode->unparseToString() <<  endl;
				if(mReplaceVariable) {
					if( ( strcmp( astNode->unparseToString().c_str(), VARIABLE_NAME )==0 ) &&
							( isSgTypeInt(isSgVarRefExp(astNode)->get_type()) )
						) {
						returnAttribute.setVarRefFound( true );
						AstRestructure::unparserReplace( isSgVarRefExp(astNode), "newInt" );
						cout << "   replacing with 'newInt' " << endl;
					}
				}
			} break;

		case V_SgVariableDeclaration: {
				SgVariableDeclaration *varDecl = isSgVariableDeclaration(astNode);
				cout << " found V_SgVariableDeclaration " << astNode->unparseToString() <<  endl;
				// replace only integer variables called "i"
				if( (varDecl->get_traversalSuccessorContainer().size() > 0) &&
                                    isSgInitializedName( varDecl->get_traversalSuccessorContainer()[0]) && 
                                                ( strcmp(isSgInitializedName(varDecl->get_traversalSuccessorContainer()[0])->get_name().str(), VARIABLE_NAME )==0 ) &&
						( isSgTypeInt(isSgInitializedName(varDecl->get_traversalSuccessorContainer()[0])->get_type()) )
					) {
					// found declaration of "int i"
					string newDeclaration("int newInt = i + 100;");
					returnAttribute.insert( varDecl, newDeclaration, HighLevelCollectionTypedefs::LocalScope, HighLevelCollectionTypedefs::AfterCurrentPosition );
					assert( mReplaceVariable==0 ); // if it's true, there is another "int i", and this transformation wont work...
					mReplaceVariable = 1;
					cout << "   inserted: '" << newDeclaration <<"' , starting variable replacement " <<  endl;
				}
			} break;

		default:
			break;
	} // node type

	bool synth = false;
	for( SubTreeSynthesizedAttributes::iterator i=synthesizedAttributeList.begin();
             i!= synthesizedAttributeList.end(); i++ ) {
                if( (*i).getVarRefFound() ) synth = true;
	}
	if( synth ) {
		returnAttribute.setVarRefFound( true );
		if(isSgStatement( astNode )) {
			cout << "   new statement " << " : '" << astNode->unparseToString() << "' " << endl;
			returnAttribute.setVarRefFound( false );
			//if(!isSgReturnStmt( astNode )) { // DEBUG, this should work!??!?
				returnAttribute.replace( astNode, astNode->unparseToString(), HighLevelCollectionTypedefs::LocalScope );
			//}
		}
	}

	if(isSgScopeStatement(astNode)) {
		// dont replace variable in higher scopes...
		if(mReplaceVariable > 0) {
			mReplaceVariable--;
			cerr << "end of scope " << mReplaceVariable << endl;
		}
	} 

	return returnAttribute;
}
开发者ID:Federico2014,项目名称:edg4x-rose,代码行数:72,代码来源:rewriteExample2.C


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