本文整理汇总了C++中SgVarRefExp::get_parent方法的典型用法代码示例。如果您正苦于以下问题:C++ SgVarRefExp::get_parent方法的具体用法?C++ SgVarRefExp::get_parent怎么用?C++ SgVarRefExp::get_parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgVarRefExp
的用法示例。
在下文中一共展示了SgVarRefExp::get_parent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createFirstLoop
/*
* Create LHS of a loop dependent statement
*/
void createFirstLoop(SgExprStatement* exprStatement,
ArrayAssignmentStatementQueryInheritedAttributeType & arrayAssignmentStatementQueryInheritedData,
OperandDataBaseType & operandDataBase) {
//transformArrayRefAPP(exprStatement, arrayAssignmentStatementQueryInheritedData, operandDataBase);
// Change the LHS, it will the first PntrArrayRef
SgScopeStatement* scope = exprStatement->get_scope();
// Figure out the dimensionality of the statement globally
vector<SgExpression*> parameters;
int maxNumberOfIndexOffsets = 6; // default value for A++/P++ arrays
ROSE_ASSERT(arrayAssignmentStatementQueryInheritedData.arrayStatementDimensionDefined == TRUE);
if (arrayAssignmentStatementQueryInheritedData.arrayStatementDimensionDefined == TRUE) {
// The the globally computed array dimension from the arrayAssignmentStatementQueryInheritedData
maxNumberOfIndexOffsets = arrayAssignmentStatementQueryInheritedData.arrayStatementDimension;
}
// Then we want the minimum of all the dimensions accesses (or is it the maximum?)
for (int n = 0; n < maxNumberOfIndexOffsets; n++) {
parameters.push_back(buildVarRefExp("_" + StringUtility::numberToString(n + 1), scope));
}
vector<SgVarRefExp*> varRefList = querySubTree<SgVarRefExp> (exprStatement, V_SgVarRefExp);
ROSE_ASSERT(varRefList.size() > 0);
SgVarRefExp* lhsVarRefExp = (*varRefList.begin()); // LHS should be the first ref
SgExpression* replaceExp;
if(isFunctionParenthesisOperator(isSgFunctionCallExp(lhsVarRefExp->get_parent()->get_parent())))
{
replaceExp = isSgFunctionCallExp(lhsVarRefExp->get_parent()->get_parent());
}
else
{
replaceExp = lhsVarRefExp;
}
SgVarRefExp* newVarRefExp = buildVarRefExp("__T_pointer", scope);
string functionName = "SC_"+lhsVarRefExp->get_symbol()->get_declaration()->get_name();
SgFunctionCallExp* functionCallExp = buildFunctionCallExp(functionName, buildIntType(),
buildExprListExp(parameters), scope);
SgPntrArrRefExp* pntrArrRefExp2 = buildPntrArrRefExp(newVarRefExp, functionCallExp);
ROSE_ASSERT(replaceExp != NULL);
replaceExpression(replaceExp, pntrArrRefExp2);
return;
}
示例2: testOMPForSensitiveInsertion
void testOMPForSensitiveInsertion()
{
annotateAllOmpFors(project);
Rose_STL_Container<SgNode*> iteratorUses = NodeQuery::querySubTree(project, V_SgInitializedName);
OMPcfgRWTransaction trans;
//VirtualCFG::cfgRWTransaction trans;
trans.beginTransaction();
for(Rose_STL_Container<SgNode*>::iterator it = iteratorUses.begin(); it!=iteratorUses.end(); it++)
{
SgInitializedName *initName = isSgInitializedName(*it); ROSE_ASSERT(initName);
//printf("initialized Name <%s | %s>\n", initName->get_parent()->unparseToString().c_str(), initName->get_parent()->class_name().c_str());
if(initName->get_name().getString() == "iterator")
{
//printf(" inserting1 at spot <%s | %s>\n", initName->get_parent()->unparseToString().c_str(), initName->get_parent()->class_name().c_str());
trans.insertBefore(initName, fooCallCreate());
trans.insertAfter(initName, fooCallCreate());
}
}
iteratorUses = NodeQuery::querySubTree(project, V_SgVarRefExp);
for(Rose_STL_Container<SgNode*>::iterator it = iteratorUses.begin(); it!=iteratorUses.end(); it++)
{
SgVarRefExp *varRef = isSgVarRefExp(*it); ROSE_ASSERT(varRef);
if(varRef->get_symbol()->get_name().getString() == "iterator")
{
//printf(" inserting2 at spot <%s | %s>\n", varRef->get_parent()->unparseToString().c_str(), varRef->get_parent()->class_name().c_str());
trans.insertBefore(varRef->get_parent(), fooCallCreate());
trans.insertAfter(varRef->get_parent(), fooCallCreate());
}
}
trans.commitTransaction();
}
示例3: main
int main( int argc, char * argv[] )
{
// Option to linearize the array.
Rose_STL_Container<std::string> localCopy_argv = CommandlineProcessing::generateArgListFromArgcArgv(argc, argv);
int newArgc;
char** newArgv = NULL;
vector<string> argList = localCopy_argv;
if (CommandlineProcessing::isOption(argList,"-f2c:","linearize",true) == true)
{
isLinearlizeArray = true;
}
CommandlineProcessing::generateArgcArgvFromList(argList,newArgc, newArgv);
// Build the AST used by ROSE
SgProject* project = frontend(newArgc,newArgv);
AstTests::runAllTests(project);
if (SgProject::get_verbose() > 2)
generateAstGraph(project,8000,"_orig");
// Traversal with Memory Pool to search for variableDeclaration
variableDeclTraversal translateVariableDeclaration;
traverseMemoryPoolVisitorPattern(translateVariableDeclaration);
for(vector<SgVariableDeclaration*>::iterator dec=variableDeclList.begin(); dec!=variableDeclList.end(); ++dec)
{
/*
For the Fortran AST, a single variableDeclaration can be shared by multiple variables.
This violated the normalization rules for C unparser. Therefore, we have to transform it.
*/
SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(*dec);
ROSE_ASSERT(variableDeclaration);
if((variableDeclaration->get_variables()).size() != 1)
{
updateVariableDeclarationList(variableDeclaration);
statementList.push_back(variableDeclaration);
removeList.push_back(variableDeclaration);
}
}
// reset the vector that collects all variable declaration. We need to walk through memory pool again to find types
variableDeclList.clear();
traverseMemoryPoolVisitorPattern(translateVariableDeclaration);
for(vector<SgVariableDeclaration*>::iterator dec=variableDeclList.begin(); dec!=variableDeclList.end(); ++dec)
{
SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(*dec);
ROSE_ASSERT(variableDeclaration);
SgInitializedNamePtrList initializedNameList = variableDeclaration->get_variables();
for(SgInitializedNamePtrList::iterator i=initializedNameList.begin(); i!=initializedNameList.end();++i)
{
SgInitializedName* initiallizedName = isSgInitializedName(*i);
SgType* baseType = initiallizedName->get_type();
if(baseType->variantT() == V_SgArrayType)
{
SgArrayType* arrayBase = isSgArrayType(baseType);
// At this moment, we are still working on the Fortran-stype AST. Therefore, there is no nested types for multi-dim array.
if(arrayBase->findBaseType()->variantT() == V_SgTypeString)
{
arrayBase->reset_base_type(translateType(arrayBase->findBaseType()));
arrayBase->set_rank(arrayBase->get_rank()+1);
}
}
else
{
initiallizedName->set_type(translateType(baseType));
}
}
}
// replace the AttributeSpecificationStatement
Rose_STL_Container<SgNode*> AttributeSpecificationStatement = NodeQuery::querySubTree (project,V_SgAttributeSpecificationStatement);
for (Rose_STL_Container<SgNode*>::iterator i = AttributeSpecificationStatement.begin(); i != AttributeSpecificationStatement.end(); i++)
{
SgAttributeSpecificationStatement* attributeSpecificationStatement = isSgAttributeSpecificationStatement(*i);
ROSE_ASSERT(attributeSpecificationStatement);
translateAttributeSpecificationStatement(attributeSpecificationStatement);
statementList.push_back(attributeSpecificationStatement);
removeList.push_back(attributeSpecificationStatement);
}
// replace the parameter reference
parameterTraversal translateParameterRef;
traverseMemoryPoolVisitorPattern(translateParameterRef);
for(vector<SgVarRefExp*>::iterator i=parameterRefList.begin(); i!=parameterRefList.end(); ++i)
{
SgVarRefExp* parameterRef = isSgVarRefExp(*i);
if(parameterSymbolList.find(parameterRef->get_symbol()) != parameterSymbolList.end())
{
SgExpression* newExpr = isSgExpression(deepCopy(parameterSymbolList.find(parameterRef->get_symbol())->second));
ROSE_ASSERT(newExpr);
newExpr->set_parent(parameterRef->get_parent());
replaceExpression(parameterRef,
newExpr,
false);
}
}
/*
Parameters will be replaced by #define, all the declarations should be removed
*/
for(map<SgVariableSymbol*,SgExpression*>::iterator i=parameterSymbolList.begin();i!=parameterSymbolList.end();++i)
//.........这里部分代码省略.........
示例4: createSecondLoop
/*
* This method creates the appropriate statement
* and surrounding loop around it
*/
SgExprStatement* ArrayAssignmentStatementTransformation::createSecondLoop(SgExprStatement* exprStatement,
ArrayAssignmentStatementQueryInheritedAttributeType & arrayAssignmentStatementQueryInheritedData,
OperandDataBaseType & operandDataBase) {
bool isAPPExist = checkAPPExist(exprStatement);
if (!isAPPExist)
return NULL;
#if DEBUG
cout << " Creating Second Loop for a dependent statement : " << exprStatement->unparseToString() << endl;
#endif
vector<SgVarRefExp*> varRefList = querySubTree<SgVarRefExp> (exprStatement, V_SgVarRefExp);
ROSE_ASSERT(varRefList.size() > 0);
SgScopeStatement* scope = exprStatement->get_scope();
#if DEBUG
cout << " LHS Operand is : " << (*varRefList.begin())->unparseToString() << endl;
#endif
SgVarRefExp* lhsVarRefExp = (*varRefList.begin());
// Remove it from NodeList since we will copy this node
// for a new statement and check it later
vector<int>::iterator dimIter = dimensionList.begin();
for(vector<SgExpression*>::iterator iter=nodeList.begin(); iter!=nodeList.end(); iter++, dimIter++)
{
if((*iter) == lhsVarRefExp)
{
#if DEBUG
cout << " Erasing element : " << (*iter)->unparseToString() << endl;
#endif
nodeList.erase(iter);
dimensionList.erase(dimIter);
break;
}
}
SgExpression* replaceExp;
if(isFunctionParenthesisOperator(isSgFunctionCallExp(lhsVarRefExp->get_parent()->get_parent())))
{
replaceExp = isSgFunctionCallExp(lhsVarRefExp->get_parent()->get_parent());
}
else
{
replaceExp = lhsVarRefExp;
}
vector<SgExpression*> parameters;
// Figure out the dimensionality of the statement globally
int maxNumberOfIndexOffsets = 6; // default value for A++/P++ arrays
ROSE_ASSERT(arrayAssignmentStatementQueryInheritedData.arrayStatementDimensionDefined == TRUE);
if (arrayAssignmentStatementQueryInheritedData.arrayStatementDimensionDefined == TRUE) {
// The the globally computed array dimension from the arrayAssignmentStatementQueryInheritedData
maxNumberOfIndexOffsets = arrayAssignmentStatementQueryInheritedData.arrayStatementDimension;
}
// Then we want the minimum of all the dimensions accesses (or is it the maximum?)
for (int n = 0; n < maxNumberOfIndexOffsets; n++) {
parameters.push_back(buildVarRefExp("_" + StringUtility::numberToString(n + 1), scope));
}
// Copy the old replacement expression for the new statement
SgExpression* copyReplaceExp = copyExpression(replaceExp);
vector<SgVarRefExp*> copyVarRefList = querySubTree<SgVarRefExp> (copyReplaceExp, V_SgVarRefExp);
ROSE_ASSERT(copyVarRefList.size() > 0);
#if DEBUG
cout << " Inserting VarRef into processing list: " << (*copyVarRefList.begin())->unparseToString() << endl;
#endif
nodeList.push_back((*copyVarRefList.begin()));
dimensionList.push_back(maxNumberOfIndexOffsets);
SgVarRefExp* newVarRefExp = buildVarRefExp("__T_pointer", scope);
string functionName = "SC_"+lhsVarRefExp->get_symbol()->get_declaration()->get_name();
SgFunctionCallExp* functionCallExp = buildFunctionCallExp(functionName, buildIntType(),
buildExprListExp(parameters), scope);
SgPntrArrRefExp* pntrArrRefExp2 = buildPntrArrRefExp(newVarRefExp, functionCallExp);
SgExprStatement* assignExprStatement = buildAssignStatement( copyReplaceExp , pntrArrRefExp2);
insertStatementAfter(exprStatement, assignExprStatement);
return assignExprStatement;
}
示例5: visit
virtual void visit(SgNode* n) {
SgVarRefExp* vr = isSgVarRefExp(n);
if (vr && vr->get_symbol()->get_declaration() == initname) {
switch (vr->get_parent()->variantT()) {
case V_SgReturnStmt:
case V_SgExprStatement:
case V_SgIfStmt:
case V_SgWhileStmt:
case V_SgDoWhileStmt:
case V_SgSwitchStatement:
case V_SgCaseOptionStmt:
case V_SgForStatement:
case V_SgForInitStatement:
#ifdef FD_DEBUG
cout << "Statement: Variable " << initname->get_name().getString() << " is safe" << endl;
#endif
// Safe
break;
case V_SgPlusPlusOp:
case V_SgMinusMinusOp:
#ifdef FD_DEBUG
cout << "Inc/dec: Variable " << initname->get_name().getString() << " is safe" << endl;
#endif
// Safe
break;
case V_SgAddOp:
case V_SgSubtractOp:
case V_SgMinusOp:
case V_SgUnaryAddOp:
case V_SgNotOp:
case V_SgPointerDerefExp:
case V_SgBitComplementOp:
case V_SgThrowOp:
case V_SgEqualityOp:
case V_SgLessThanOp:
case V_SgLessOrEqualOp:
case V_SgGreaterThanOp:
case V_SgGreaterOrEqualOp:
case V_SgNotEqualOp:
case V_SgMultiplyOp:
case V_SgDivideOp:
case V_SgIntegerDivideOp:
case V_SgModOp:
case V_SgAndOp:
case V_SgOrOp:
case V_SgBitAndOp:
case V_SgBitOrOp:
case V_SgBitXorOp:
case V_SgCommaOpExp:
case V_SgLshiftOp:
case V_SgRshiftOp:
case V_SgAssignInitializer:
#ifdef FD_DEBUG
cout << "Non-mutating: Variable " << initname->get_name().getString() << " is safe" << endl;
#endif
// Safe
break;
case V_SgExprListExp:
if (isSgFunctionCallExp(n->get_parent()->get_parent())) {
if (isPotentiallyModified(vr, n->get_parent()->get_parent())) {
#ifdef FD_DEBUG
cout << "Function call: Variable " << initname->get_name().getString() << " is unsafe" << endl;
#endif
safe = false;
}
} else if (isSgConstructorInitializer(n->get_parent()->get_parent())) {
#ifdef FD_DEBUG
cout << "Constructor: Variable " << initname->get_name().getString() << " is unsafe" << endl;
#endif
safe = false;
// FIXME: constructors
} else {
cerr << n->get_parent()->get_parent()->sage_class_name() << endl;
assert (!"Unknown SgExprListExp case");
}
break;
case V_SgAssignOp:
case V_SgPlusAssignOp:
case V_SgMinusAssignOp: {
SgBinaryOp* binop = isSgBinaryOp(vr->get_parent());
SgExpression* rhs = binop->get_rhs_operand();
bool lhs_good = (binop->get_lhs_operand() == vr);
#ifdef FD_DEBUG
cout << "Assign case for " << initname->get_name().getString() << endl;
cout << "lhs_good = " << (lhs_good ? "true" : "false") << endl;
#endif
SgAddOp* rhs_a = isSgAddOp(rhs);
SgExpression* rhs_a_lhs = rhs_a ? rhs_a->get_lhs_operand() : 0;
SgExpression* rhs_a_rhs = rhs_a ? rhs_a->get_rhs_operand() : 0;
if (lhs_good) {
if (isSgValueExp(binop->get_rhs_operand())) {
// Safe
} else if (isSgVarRefExp(rhs)) {
// Safe
} else if (isSgCastExp(binop->get_rhs_operand()) &&
isSgValueExp(isSgCastExp(binop->get_rhs_operand())
//.........这里部分代码省略.........