本文整理汇总了C++中SgInitializedName::set_initializer方法的典型用法代码示例。如果您正苦于以下问题:C++ SgInitializedName::set_initializer方法的具体用法?C++ SgInitializedName::set_initializer怎么用?C++ SgInitializedName::set_initializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgInitializedName
的用法示例。
在下文中一共展示了SgInitializedName::set_initializer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doFiniteDifferencingOne
// Do finite differencing on one expression within one context. The expression
// must be defined and valid within the entire body of root. The rewrite rules
// are used to simplify expressions. When a variable var is updated from
// old_value to new_value, an expression of the form (var, (old_value,
// new_value)) is created and rewritten. The rewrite rules may either produce
// an arbitrary expression (which will be used as-is) or one of the form (var,
// (something, value)) (which will be changed to (var = value)).
void doFiniteDifferencingOne(SgExpression* e,
SgBasicBlock* root,
RewriteRule* rules)
{
SgStatementPtrList& root_stmts = root->get_statements();
SgStatementPtrList::iterator i;
for (i = root_stmts.begin(); i != root_stmts.end(); ++i)
{
if (expressionComputedIn(e, *i))
break;
}
if (i == root_stmts.end())
return; // Expression is not used within root, so quit
vector<SgVariableSymbol*> used_symbols = SageInterface::getSymbolsUsedInExpression(e);
SgName cachename = "cache_fd__"; cachename << ++SageInterface::gensym_counter;
SgVariableDeclaration* cachedecl = new SgVariableDeclaration(SgNULL_FILE, cachename, e->get_type(),0 /* new SgAssignInitializer(SgNULL_FILE, e) */);
SgInitializedName* cachevar = cachedecl->get_variables().back();
ROSE_ASSERT (cachevar);
root->get_statements().insert(i, cachedecl);
cachedecl->set_parent(root);
cachedecl->set_definingDeclaration(cachedecl);
cachevar->set_scope(root);
SgVariableSymbol* sym = new SgVariableSymbol(cachevar);
root->insert_symbol(cachename, sym);
SgVarRefExp* vr = new SgVarRefExp(SgNULL_FILE, sym);
vr->set_endOfConstruct(SgNULL_FILE);
replaceCopiesOfExpression(e, vr, root);
vector<SgExpression*> modifications_to_used_symbols;
FdFindModifyingStatementsVisitor(used_symbols, modifications_to_used_symbols).go(root);
cachedecl->addToAttachedPreprocessingInfo(
new PreprocessingInfo(PreprocessingInfo::CplusplusStyleComment,(string("// Finite differencing: ") +
cachename.str() + " is a cache of " +
e->unparseToString()).c_str(),"Compiler-Generated in Finite Differencing",0, 0, 0, PreprocessingInfo::before));
if (modifications_to_used_symbols.size() == 0)
{
SgInitializer* cacheinit = new SgAssignInitializer(SgNULL_FILE, e);
e->set_parent(cacheinit);
cachevar->set_initializer(cacheinit);
cacheinit->set_parent(cachevar);
}
else
{
for (unsigned int i = 0; i < modifications_to_used_symbols.size(); ++i)
{
SgExpression* modstmt = modifications_to_used_symbols[i];
#ifdef FD_DEBUG
cout << "Updating cache after " << modstmt->unparseToString() << endl;
#endif
SgExpression* updateCache = 0;
SgVarRefExp* varref = new SgVarRefExp(SgNULL_FILE, sym);
varref->set_endOfConstruct(SgNULL_FILE);
SgTreeCopy tc;
SgExpression* eCopy = isSgExpression(e->copy(tc));
switch (modstmt->variantT())
{
case V_SgAssignOp:
{
SgAssignOp* assignment = isSgAssignOp(modstmt);
assert (assignment);
SgExpression* lhs = assignment->get_lhs_operand();
SgExpression* rhs = assignment->get_rhs_operand();
replaceCopiesOfExpression(lhs, rhs, eCopy);
}
break;
case V_SgPlusAssignOp:
case V_SgMinusAssignOp:
case V_SgAndAssignOp:
case V_SgIorAssignOp:
case V_SgMultAssignOp:
case V_SgDivAssignOp:
case V_SgModAssignOp:
case V_SgXorAssignOp:
case V_SgLshiftAssignOp:
case V_SgRshiftAssignOp:
{
SgBinaryOp* assignment = isSgBinaryOp(modstmt);
assert (assignment);
SgExpression* lhs = assignment->get_lhs_operand();
SgExpression* rhs = assignment->get_rhs_operand();
SgTreeCopy tc;
SgExpression* rhsCopy = isSgExpression(rhs->copy(tc));
SgExpression* newval = 0;
switch (modstmt->variantT())
{
#define DO_OP(op, nonassignment) \
case V_##op: { \
newval = new nonassignment(SgNULL_FILE, lhs, rhsCopy); \
newval->set_endOfConstruct(SgNULL_FILE); \
} \
//.........这里部分代码省略.........
示例2: convertInitializerIntoAssignment
// Convert something like "int a = foo();" into "int a; a = foo();"
SgAssignOp* convertInitializerIntoAssignment(SgAssignInitializer* init)
{
#ifndef CXX_IS_ROSE_CODE_GENERATION
using namespace SageBuilder;
assert (SageInterface::isDefaultConstructible(init->get_operand_i()->get_type()));
SgStatement* stmt = getStatementOfExpression(init);
assert (stmt);
SgScopeStatement* parent = isSgScopeStatement(stmt->get_parent());
if (!parent && isSgForInitStatement(stmt->get_parent()))
parent = isSgScopeStatement(stmt->get_parent()->get_parent()->get_parent());
assert (parent);
SgNode* initparent = init->get_parent();
assert (initparent);
SgInitializedName* initname = NULL;
if (isSgInitializedName(initparent))
initname = isSgInitializedName(initparent);
else
if (isSgVariableDefinition(initparent))
initname = isSgVariableDefinition(initparent)->get_vardefn();
else
if (isSgVariableDeclaration(initparent))
{
SgInitializedNamePtrList& vars = isSgVariableDeclaration(initparent)->get_variables();
for (SgInitializedNamePtrList::iterator i = vars.begin(); i != vars.end(); ++i)
{
if ((*i)->get_initializer() == init)
{
initname = *i;
break;
}
}
}
else
{
std::cout << "initparent is a " << initparent->sage_class_name() << std::endl;
assert (!"Should not happen");
}
assert (initname);
assert (initname->get_initializer() == init);
assert (parent);
SgSymbol* sym = initname->get_symbol_from_symbol_table();
ROSE_ASSERT (isSgVariableSymbol(sym));
SgVarRefExp* vr = buildVarRefExp(isSgVariableSymbol(sym));
vr->set_lvalue(true);
SgExprStatement* assign_stmt = buildAssignStatement(vr, init->get_operand());
initname->set_initializer(NULL);
// assignment->set_parent(assign_stmt);
// cout << "stmt is " << stmt->unparseToString() << endl;
// cout << "stmt->get_parent() is a " << stmt->get_parent()->sage_class_name() << endl;
myStatementInsert(stmt, assign_stmt, false);
assign_stmt->set_parent(parent);
// FixSgTree(assign_stmt);
// FixSgTree(parent);
// AstPostProcessing(assign_stmt);
return isSgAssignOp(assign_stmt->get_expression());
#else
return NULL;
#endif
}