bool FortranAnalysis::isRegionSelector(SgInitializedName * var) { bool isSelector = false; SgType * var_type = var->get_type(); // see if var is already in selector list // // for (int i = 0; i < selectors.size(); i++) { // if (var->get_name().getString() == selectors[i]->get_name().getString()) { // return true; // } // } // first do the easy stuff // if (isSgArrayType(var_type) != NULL) { SgArrayType * array_type = isSgArrayType(var_type); SgExpressionPtrList & dim_ptrs = array_type->get_dim_info()->get_expressions(); if (array_type->get_rank() == 1 && isSgTypeInt(array_type->findBaseType()) != NULL) { // TODO - could be a variable reference rather than a value expression if (isSgIntVal(dim_ptrs.front()) != NULL) { if (isSgIntVal(dim_ptrs.front())->get_value() == 4) isSelector = true; } } } // look for var in region and transfer_halo calls // if (isSelector == true) { /* SgStatementPtrList & stmts = */ src_func_decl->get_definition()->get_body()->getStatementList(); } return isSelector; }
bool Type::isPlainInt() const { return isSgTypeInt( t_ ) != 0; }
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; }