本文整理汇总了C++中SgVarRefExp::set_parent方法的典型用法代码示例。如果您正苦于以下问题:C++ SgVarRefExp::set_parent方法的具体用法?C++ SgVarRefExp::set_parent怎么用?C++ SgVarRefExp::set_parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgVarRefExp
的用法示例。
在下文中一共展示了SgVarRefExp::set_parent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: moveForDeclaredVariables
// Move variables declared in a for statement to just outside that statement.
void moveForDeclaredVariables(SgNode* root)
{
vector<SgForStatement*> for_statements;
FindForStatementsVisitor(for_statements).traverse(root, preorder);
for (unsigned int i = 0; i < for_statements.size(); ++i)
{
SgForStatement* stmt = for_statements[i];
#ifdef FD_DEBUG
cout << "moveForDeclaredVariables: " << stmt->unparseToString() << endl;
#endif
SgForInitStatement* init = stmt->get_for_init_stmt();
if (!init) continue;
SgStatementPtrList& inits = init->get_init_stmt();
vector<SgVariableDeclaration*> decls;
for (SgStatementPtrList::iterator j = inits.begin(); j != inits.end(); ++j) {
SgStatement* one_init = *j;
if (isSgVariableDeclaration(one_init))
{
decls.push_back(isSgVariableDeclaration(one_init));
}
}
if (decls.empty()) continue;
SgStatement* parent = isSgStatement(stmt->get_parent());
assert (parent);
SgBasicBlock* bb = new SgBasicBlock(SgNULL_FILE);
stmt->set_parent(bb);
bb->set_parent(parent);
SgStatementPtrList ls;
for (unsigned int j = 0; j < decls.size(); ++j)
{
for (SgInitializedNamePtrList::iterator k = decls[j]->get_variables().begin(); k != decls[j]->get_variables().end(); ++k)
{
#ifdef FD_DEBUG
cout << "Working on variable " << (*k)->get_name().getString() << endl;
#endif
SgVariableSymbol* sym = new SgVariableSymbol(*k);
bb->insert_symbol((*k)->get_name(), sym);
(*k)->set_scope(bb);
SgAssignInitializer* kinit = 0;
if (isSgAssignInitializer((*k)->get_initializer()))
{
kinit = isSgAssignInitializer((*k)->get_initializer());
(*k)->set_initializer(0);
}
if (kinit)
{
SgVarRefExp* vr = new SgVarRefExp(SgNULL_FILE, sym);
vr->set_endOfConstruct(SgNULL_FILE);
vr->set_lvalue(true);
SgAssignOp* assignment = new SgAssignOp(SgNULL_FILE,vr,kinit->get_operand());
vr->set_parent(assignment);
kinit->get_operand()->set_parent(assignment);
SgExprStatement* expr = new SgExprStatement(SgNULL_FILE, assignment);
assignment->set_parent(expr);
ls.push_back(expr);
expr->set_parent(init);
}
}
#if 0
SgStatementPtrList::iterator fiiter = std::find(inits.begin(), inits.end(), decls[j]);
assert (fiiter != inits.end());
size_t idx = fiiter - inits.begin();
inits.erase(inits.begin() + idx);
inits.insert(inits.begin() + idx, ls.begin(), ls.end());
#endif
bb->get_statements().push_back(decls[j]);
decls[j]->set_parent(bb);
}
inits = ls;
bb->get_statements().push_back(stmt);
// printf ("In moveForDeclaredVariables(): parent = %p = %s bb = %p stmt = %p = %s \n",parent,parent->class_name().c_str(),bb,stmt,stmt->class_name().c_str());
ROSE_ASSERT(stmt->get_parent() == bb);
parent->replace_statement(stmt, bb);
}
}