本文整理汇总了C++中SgVariableDeclaration::set_definingDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C++ SgVariableDeclaration::set_definingDeclaration方法的具体用法?C++ SgVariableDeclaration::set_definingDeclaration怎么用?C++ SgVariableDeclaration::set_definingDeclaration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgVariableDeclaration
的用法示例。
在下文中一共展示了SgVariableDeclaration::set_definingDeclaration方法的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: thisname
//.........这里部分代码省略.........
thisname << ++gensym_counter;
SgInitializedName* thisinitname = 0;
if (isSgMemberFunctionSymbol(funsym) && !fundecl->get_declarationModifier().get_storageModifier().isStatic())
{
assert (thisptr != NULL);
SgType* thisptrtype = thisptr->get_type();
const SgSpecialFunctionModifier& specialMod =
funsym->get_declaration()->get_specialFunctionModifier();
if (specialMod.isConstructor()) {
SgFunctionType* ft = funsym->get_declaration()->get_type();
ROSE_ASSERT (ft);
SgMemberFunctionType* mft = isSgMemberFunctionType(ft);
ROSE_ASSERT (mft);
SgType* ct = mft->get_class_type();
thisptrtype = new SgPointerType(ct);
}
SgConstVolatileModifier& thiscv = fundecl->get_declarationModifier().get_typeModifier().get_constVolatileModifier();
// if (thiscv.isConst() || thiscv.isVolatile()) { FIXME
thisptrtype = new SgModifierType(thisptrtype);
isSgModifierType(thisptrtype)->get_typeModifier().get_constVolatileModifier() = thiscv;
// }
// cout << thisptrtype->unparseToString() << " --- " << thiscv.isConst() << " " << thiscv.isVolatile() << endl;
SgAssignInitializer* assignInitializer = new SgAssignInitializer(SgNULL_FILE, thisptr);
assignInitializer->set_endOfConstruct(SgNULL_FILE);
#if 1
printf ("before new SgVariableDeclaration(): assignInitializer = %p assignInitializer->isTransformation() = %s \n",assignInitializer,assignInitializer->isTransformation() ? "true" : "false");
#endif
thisdecl = new SgVariableDeclaration(SgNULL_FILE, thisname, thisptrtype, assignInitializer);
#if 1
printf ("(after new SgVariableDeclaration(): assignInitializer = %p assignInitializer->isTransformation() = %s \n",assignInitializer,assignInitializer->isTransformation() ? "true" : "false");
#endif
thisdecl->set_endOfConstruct(SgNULL_FILE);
thisdecl->get_definition()->set_endOfConstruct(SgNULL_FILE);
thisdecl->set_definingDeclaration(thisdecl);
thisinitname = (thisdecl->get_variables()).back();
//thisinitname = lastElementOfContainer(thisdecl->get_variables());
// thisinitname->set_endOfConstruct(SgNULL_FILE);
assignInitializer->set_parent(thisinitname);
markAsTransformation(assignInitializer);
// printf ("Built new SgVariableDeclaration #1 = %p \n",thisdecl);
// DQ (6/23/2006): New test
ROSE_ASSERT(assignInitializer->get_parent() != NULL);
}
// Get the list of actual argument expressions from the function call, which we'll later use to initialize new local
// variables in the inlined code. We need to detach the actual arguments from the AST here since we'll be reattaching
// them below (otherwise we would violate the invariant that the AST is a tree).
SgFunctionDefinition* targetFunction = PRE::getFunctionDefinition(funcall);
SgExpressionPtrList funargs = funcall->get_args()->get_expressions();
funcall->get_args()->get_expressions().clear();
BOOST_FOREACH (SgExpression *actual, funargs)
actual->set_parent(NULL);
// Make a copy of the to-be-inlined function so we're not modifying and (re)inserting the original.
SgBasicBlock* funbody_raw = fundef->get_body();
SgInitializedNamePtrList& params = fundecl->get_args();
std::vector<SgInitializedName*> inits;
SgTreeCopy tc;
SgFunctionDefinition* function_copy = isSgFunctionDefinition(fundef->copy(tc));
ROSE_ASSERT (function_copy);
SgBasicBlock* funbody_copy = function_copy->get_body();
renameLabels(funbody_copy, targetFunction);