本文整理汇总了C++中SgStatement::replace_expression方法的典型用法代码示例。如果您正苦于以下问题:C++ SgStatement::replace_expression方法的具体用法?C++ SgStatement::replace_expression怎么用?C++ SgStatement::replace_expression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgStatement
的用法示例。
在下文中一共展示了SgStatement::replace_expression方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doFiniteDifferencingOne
//.........这里部分代码省略.........
break;
case V_SgPlusPlusOp:
{
SgExpression* lhs = isSgPlusPlusOp(modstmt)->get_operand();
SgIntVal* one = new SgIntVal(SgNULL_FILE, 1);
one->set_endOfConstruct(SgNULL_FILE);
SgAddOp* add = new SgAddOp(SgNULL_FILE, lhs, one);
add->set_endOfConstruct(SgNULL_FILE);
lhs->set_parent(add);
one->set_parent(add);
replaceCopiesOfExpression(lhs,add,eCopy);
}
break;
case V_SgMinusMinusOp:
{
SgExpression* lhs = isSgMinusMinusOp(modstmt)->get_operand();
SgIntVal* one = new SgIntVal(SgNULL_FILE, 1);
one->set_endOfConstruct(SgNULL_FILE);
SgSubtractOp* sub = new SgSubtractOp(SgNULL_FILE, lhs, one);
sub->set_endOfConstruct(SgNULL_FILE);
lhs->set_parent(sub);
one->set_parent(sub);
replaceCopiesOfExpression(lhs,sub,eCopy);
}
break;
default:
cerr << modstmt->sage_class_name() << endl;
assert (false);
break;
}
#ifdef FD_DEBUG
cout << "e is " << e->unparseToString() << endl;
cout << "eCopy is " << eCopy->unparseToString() << endl;
#endif
updateCache = doFdVariableUpdate(rules, varref, e, eCopy);
#ifdef FD_DEBUG
cout << "updateCache is " << updateCache->unparseToString() << endl;
#endif
if (updateCache)
{
ROSE_ASSERT(modstmt != NULL);
SgNode* ifp = modstmt->get_parent();
SgCommaOpExp* comma = new SgCommaOpExp(SgNULL_FILE, updateCache, modstmt);
modstmt->set_parent(comma);
updateCache->set_parent(comma);
if (ifp == NULL)
{
printf ("modstmt->get_parent() == NULL modstmt = %p = %s \n",modstmt,modstmt->class_name().c_str());
modstmt->get_startOfConstruct()->display("modstmt->get_parent() == NULL: debug");
}
ROSE_ASSERT(ifp != NULL);
#ifdef FD_DEBUG
cout << "New expression is " << comma->unparseToString() << endl;
cout << "IFP is " << ifp->sage_class_name() << ": " << ifp->unparseToString() << endl;
#endif
if (isSgExpression(ifp))
{
isSgExpression(ifp)->replace_expression(modstmt, comma);
comma->set_parent(ifp);
}
else
{
// DQ (12/16/2006): Need to handle cases that are not SgExpression (now that SgExpressionRoot is not used!)
// cerr << ifp->sage_class_name() << endl;
// assert (!"Bad parent type for inserting comma expression");
SgStatement* statement = isSgStatement(ifp);
if (statement != NULL)
{
#ifdef FD_DEBUG
printf ("Before statement->replace_expression(): statement = %p = %s modstmt = %p = %s \n",statement,statement->class_name().c_str(),modstmt,modstmt->class_name().c_str());
SgExprStatement* expresionStatement = isSgExprStatement(statement);
if (expresionStatement != NULL)
{
SgExpression* expression = expresionStatement->get_expression();
printf ("expressionStatement expression = %p = %s \n",expression,expression->class_name().c_str());
}
#endif
statement->replace_expression(modstmt, comma);
comma->set_parent(statement);
}
else
{
ROSE_ASSERT(ifp != NULL);
printf ("Error: parent is neither a SgExpression nor a SgStatement ifp = %p = %s \n",ifp,ifp->class_name().c_str());
ROSE_ASSERT(false);
}
}
#ifdef FD_DEBUG
cout << "IFP is now " << ifp->unparseToString() << endl;
#endif
}
}
}
}
示例2: visit
virtual void visit(SgNode* n) {
if (isSgVarRefExp(n)) {
SgVarRefExp* copy_vr = isSgVarRefExp(n);
assert (copy_vr->get_symbol());
SgInitializedName* copy = copy_vr->get_symbol()->get_declaration();
assert (copy);
SgInitializer* copyinit = copy->get_initializer();
SgScopeStatement* copyscope =
SageInterface::getScope(copy->get_parent()->get_parent());
if (isSgAssignInitializer(copyinit)) {
SgAssignInitializer* init =
isSgAssignInitializer(copyinit);
SgExpression* orig_expr = init->get_operand();
// cout << "orig is " << orig_expr->unparseToString() << ", copy is " << copy->get_name().str() << endl;
if (!isPotentiallyModified(copy_vr, copyscope) &&
!isSgGlobal(copyscope) &&
!isSgNamespaceDefinitionStatement(copyscope)) {
bool shouldReplace = false;
if (isSgVarRefExp(orig_expr)) {
SgVarRefExp* orig_vr = isSgVarRefExp(orig_expr);
// cout << "Found potential copy from " << orig_vr->get_symbol()->get_name().str() << " to " << copy_vr->get_symbol()->get_name().str() << endl;
SgInitializedName* orig =
orig_vr->get_symbol()->get_declaration();
assert (orig);
SgNode* origscope = orig->get_parent()->get_parent();
assert (origscope);
if (!hasAddressTaken(orig_vr, origscope) &&
isSgBasicBlock(copyscope) &&
!isPotentiallyModifiedDuringLifeOf(isSgBasicBlock(copyscope),
orig, copy) &&
!isSgGlobal(origscope) &&
!isSgNamespaceDefinitionStatement(origscope)) {
shouldReplace = true;
}
} else if (isSgValueExp(orig_expr)) {
shouldReplace = true;
}
// cout << "shouldReplace is " << shouldReplace << endl;
if (shouldReplace) {
assert (orig_expr);
SgExpression* orig_copy = isSgExpression(orig_expr /*->copy(SgTreeCopy()) */);
assert (orig_copy);
orig_copy->set_parent(copy_vr->get_parent());
orig_copy->set_lvalue(copy_vr->get_lvalue());
ROSE_ASSERT(copy_vr != NULL);
ROSE_ASSERT(copy_vr->get_parent() != NULL);
// ROSE_ASSERT(isSgExpression(copy_vr->get_parent()) != NULL);
// DQ (12/15/2006): Need to handle cases where the parent is a SgStatement or a SgExpression (or make it an error).
// isSgExpression(copy_vr->get_parent())->replace_expression(copy_vr, orig_copy);
SgStatement* statement = isSgStatement(copy_vr->get_parent());
if (statement != NULL)
{
statement->replace_expression(copy_vr, orig_copy);
}
else
{
SgExpression* expression = isSgExpression(copy_vr->get_parent());
if (expression != NULL)
{
expression->replace_expression(copy_vr, orig_copy);
}
else
{
printf ("Error: what is this copy_vr->get_parent() = %s \n",copy_vr->get_parent()->class_name().c_str());
ROSE_ASSERT(false);
}
}
}
}
}
}
}