本文整理汇总了C++中SgVariableDeclaration::set_parent方法的典型用法代码示例。如果您正苦于以下问题:C++ SgVariableDeclaration::set_parent方法的具体用法?C++ SgVariableDeclaration::set_parent怎么用?C++ SgVariableDeclaration::set_parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgVariableDeclaration
的用法示例。
在下文中一共展示了SgVariableDeclaration::set_parent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildClassDeclarationAndDefinition
SgVariableDeclaration*
buildStructVariable ( SgScopeStatement* scope,
vector<SgType*> memberTypes, vector<string> memberNames,
string structName = "", string varName = "", SgAggregateInitializer *initializer = NULL )
{
ROSE_ASSERT(memberTypes.size() == memberNames.size());
SgClassDeclaration* classDeclaration = buildClassDeclarationAndDefinition(structName,scope);
vector<SgType*>::iterator typeIterator = memberTypes.begin();
vector<string>::iterator memberNameIterator = memberNames.begin();
while (typeIterator != memberTypes.end())
{
// printf ("Adding data member type = %s variable name = %s \n",(*typeIterator)->unparseToString().c_str(),memberNameIterator->c_str());
SgVariableDeclaration* memberDeclaration = new SgVariableDeclaration(SOURCE_POSITION,*memberNameIterator,*typeIterator,NULL);
memberDeclaration->set_endOfConstruct(SOURCE_POSITION);
classDeclaration->get_definition()->append_member(memberDeclaration);
memberDeclaration->set_parent(classDeclaration->get_definition());
// Liao (2/13/2008) scope and symbols for member variables
SgInitializedName* initializedName = *(memberDeclaration->get_variables().begin());
initializedName->set_file_info(SOURCE_POSITION);
initializedName->set_scope(classDeclaration->get_definition());
// set nondefning declaration pointer
memberDeclaration->set_firstNondefiningDeclaration(memberDeclaration);
SgVariableSymbol* variableSymbol = new SgVariableSymbol(initializedName);
classDeclaration->get_definition()->insert_symbol(*memberNameIterator,variableSymbol);
typeIterator++;
memberNameIterator++;
}
SgClassType* classType = new SgClassType(classDeclaration->get_firstNondefiningDeclaration());
SgVariableDeclaration* variableDeclaration = new SgVariableDeclaration(SOURCE_POSITION,varName,classType,initializer);
variableDeclaration->set_endOfConstruct(SOURCE_POSITION);
//Liao (2/13/2008) scope and symbols for struct variable
SgInitializedName* initializedName = *(variableDeclaration->get_variables().begin());
initializedName->set_file_info(SOURCE_POSITION);
initializedName->set_scope(scope);
SgVariableSymbol* variableSymbol = new SgVariableSymbol(initializedName);
scope->insert_symbol(varName,variableSymbol);
//set nondefining declaration
variableDeclaration->set_firstNondefiningDeclaration(variableDeclaration);
// This is required, since it is not set in the SgVariableDeclaration constructor
initializer->set_parent(variableDeclaration);
variableDeclaration->set_variableDeclarationContainsBaseTypeDefiningDeclaration(true);
variableDeclaration->set_baseTypeDefiningDeclaration(classDeclaration->get_definingDeclaration());
classDeclaration->set_parent(variableDeclaration);
return variableDeclaration;
}
示例2: rand
DoxygenFile::DoxygenFile(SgProject *prj, string filename)
{
Sg_File_Info *info = new Sg_File_Info(filename, 0, 0);
SgInitializedName *iname = new SgInitializedName;
stringstream sname;
sname << "SAGE_Doxygen_Dummy_" << rand();
iname->set_name(sname.str());
iname->set_type(new SgTypeInt);
iname->set_file_info(info);
iname->get_storageModifier().setExtern();
SgVariableDeclaration *decl = new SgVariableDeclaration;
decl->get_variables().push_back(iname);
decl->set_startOfConstruct(info);
decl->set_endOfConstruct(info);
decl->get_declarationModifier().get_storageModifier().setExtern();
iname->set_parent(decl);
iname->set_prev_decl_item(iname);
// SgGlobal *glob = prj->get_file(0).get_globalScope();
SgSourceFile* sourceFile = isSgSourceFile(prj->get_fileList()[0]);
ROSE_ASSERT(sourceFile != NULL);
SgGlobal *glob = sourceFile->get_globalScope();
// glob->insertStatementInScope(decl, true);
glob->get_declarations().insert(glob->get_declarations().begin(),decl);
decl->set_parent(glob);
SgVariableSymbol* variableSymbol = new SgVariableSymbol(iname);
glob->insert_symbol(sname.str(),variableSymbol);
decl->set_parent(glob);
std::cout << "Before complete string." << std::endl;
//glob->append_declaration(decl);
iname->set_scope(glob);
decl->unparseToCompleteString();
std::cout << "After complete string." << std::endl;
commentParent = decl;
printf("commentParent = %p\n", commentParent);
}
示例3: backend
// ******************************************
// MAIN PROGRAM
// ******************************************
int
main( int argc, char * argv[] )
{
// Initialize and check compatibility. See rose::initialize
ROSE_INITIALIZE;
// Build the AST used by ROSE
SgProject* project = frontend(argc,argv);
assert(project != NULL);
vector<SgType*> memberTypes;
vector<string> memberNames;
string name = "a";
for (int i = 0; i < 10; i++)
{
memberTypes.push_back(SgTypeInt::createType());
name = "_" + name;
memberNames.push_back(name);
}
// Build the initializer
SgExprListExp* initializerList = new SgExprListExp(SOURCE_POSITION);
initializerList->set_endOfConstruct(SOURCE_POSITION);
SgAggregateInitializer* structureInitializer = new SgAggregateInitializer(SOURCE_POSITION,initializerList);
structureInitializer->set_endOfConstruct(SOURCE_POSITION);
// Build the data member initializers for the structure (one SgAssignInitializer for each data member)
for (unsigned int i = 0; i < memberNames.size(); i++)
{
// Set initial value to "i"
SgIntVal* value = new SgIntVal(SOURCE_POSITION,i);
value->set_endOfConstruct(SOURCE_POSITION);
SgAssignInitializer* memberInitializer = new SgAssignInitializer(SOURCE_POSITION,value);
memberInitializer->set_endOfConstruct(SOURCE_POSITION);
structureInitializer->append_initializer(memberInitializer);
memberInitializer->set_parent(structureInitializer);
}
// Access the first file and add a struct with data members specified
SgSourceFile* file = isSgSourceFile((*project)[0]);
ROSE_ASSERT(file != NULL);
SgVariableDeclaration* variableDeclaration = buildStructVariable(file->get_globalScope(),memberTypes,memberNames,"X","x",structureInitializer);
file->get_globalScope()->prepend_declaration(variableDeclaration);
variableDeclaration->set_parent(file->get_globalScope());
AstTests::runAllTests(project);
// Code generation phase (write out new application "rose_<input file name>")
return backend(project);
}
示例4: isSgBasicBlock
void
SimpleInstrumentation::visit ( SgNode* astNode )
{
SgBasicBlock* block = isSgBasicBlock(astNode);
if (block != NULL)
{
// Mark this as a transformation (required)
Sg_File_Info* sourceLocation = Sg_File_Info::generateDefaultFileInfoForTransformationNode();
ROSE_ASSERT(sourceLocation != NULL);
SgType* type = new SgTypeInt();
ROSE_ASSERT(type != NULL);
SgName name = "newVariable";
SgVariableDeclaration* variableDeclaration = new SgVariableDeclaration(sourceLocation,name,type);
ROSE_ASSERT(variableDeclaration != NULL);
SgInitializedName* initializedName = *(variableDeclaration->get_variables().begin());
initializedName->set_file_info(Sg_File_Info::generateDefaultFileInfoForTransformationNode());
// DQ (6/18/2007): The unparser requires that the scope be set (for name qualification to work).
initializedName->set_scope(block);
// Liao (2/13/2008): AstTests requires this to be set
variableDeclaration->set_firstNondefiningDeclaration(variableDeclaration);
ROSE_ASSERT(block->get_statements().size() > 0);
block->get_statements().insert(block->get_statements().begin(),variableDeclaration);
variableDeclaration->set_parent(block);
// Add a symbol to the sybol table for the new variable
SgVariableSymbol* variableSymbol = new SgVariableSymbol(initializedName);
block->insert_symbol(name,variableSymbol);
}
}
示例5: partialRedundancyEliminationOne
//.........这里部分代码省略.........
// << cfg.graph.source(*j) << " to " << cfg.graph.target(*j) << endl;
}
}
// printf ("Before final test: needToMakeCachevar = %s \n",needToMakeCachevar ? "true" : "false");
// Add cache variable if necessary
SgVarRefExp* cachevar = 0;
if (needToMakeCachevar)
{
SgName cachevarname = "cachevar__";
cachevarname << ++SageInterface::gensym_counter;
// printf ("Building variable name = %s \n",cachevarname.str());
SgType* type = expr->get_type();
if (isSgArrayType(type))
type = new SgPointerType(isSgArrayType(type)->get_base_type());
assert (SageInterface::isDefaultConstructible(type));
// FIXME: assert (isAssignable(type));
SgVariableDeclaration* decl = new SgVariableDeclaration(SgNULL_FILE, cachevarname, type, NULL);
decl->set_definingDeclaration(decl);
SgInitializedName* initname = decl->get_variables().back();
// DQ (10/5/2007): Added an assertion.
ROSE_ASSERT(initname != NULL);
decl->addToAttachedPreprocessingInfo(
new PreprocessingInfo(PreprocessingInfo::CplusplusStyleComment,
(string("// Partial redundancy elimination: ") + cachevarname.str() +
" is a cache of " + expr->unparseToString()).c_str(),
"Compiler-Generated in PRE", 0, 0, 0, PreprocessingInfo::before));
SgVariableSymbol* cachevarsym = new SgVariableSymbol(initname);
decl->set_parent(root);
// DQ (10/5/2007): Added scope (suggested by Jeremiah).
initname->set_scope(root);
root->get_statements().insert(root->get_statements().begin(),decl);
root->insert_symbol(cachevarname, cachevarsym);
cachevar = new SgVarRefExp(SgNULL_FILE, cachevarsym);
cachevar->set_endOfConstruct(SgNULL_FILE);
}
// Do expression computation replacements
for (set<SgNode*>::iterator i = replacements.begin(); i != replacements.end(); ++i)
{
ReplaceExpressionWithVarrefVisitor(expr, cachevar).traverse(*i, postorder);
}
// Do edge insertions
// int count = 0;
bool failAtEndOfFunction = false;
for (j = cfg.graph.edges().begin(); j != jend; ++j)
{
// printf ("Build the insertion list! count = %d \n",count++);
if (edge_insert[*j])
{
#if 0
// DQ (3/13/2006): Compiler warns that "src" is unused, so I have commented it out!
Vertex src = cfg.graph.source(*j), tgt = cfg.graph.target(*j);
cerr << "Doing insertion between " << src << " and " << tgt << endl;
#endif
pair<SgNode*, bool> insert_point = cfg.edge_insertion_point[*j];
if (insert_point.first)
示例6: thisname
//.........这里部分代码省略.........
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);
ASSERT_require(funbody_raw->get_symbol_table()->size() == funbody_copy->get_symbol_table()->size());
// We don't need to keep the copied SgFunctionDefinition now that the labels in it have been moved to the target function
// (having it in the memory pool confuses the AST tests), but we must not delete the formal argument list or the body
// because we need them below.
示例7: if
//.........这里部分代码省略.........
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);
// thisdecl = new SgVariableDeclaration(SgNULL_FILE, thisname, thisptrtype, new SgAssignInitializer(SgNULL_FILE, thisptr));
thisdecl = new SgVariableDeclaration(SgNULL_FILE, thisname, thisptrtype, assignInitializer);
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);
// printf ("Built new SgVariableDeclaration #1 = %p \n",thisdecl);
// DQ (6/23/2006): New test
ROSE_ASSERT(assignInitializer->get_parent() != NULL);
}
std::cout << "Trying to inline function " << fundecl->get_name().str() << std::endl;
SgBasicBlock* funbody_raw = fundef->get_body();
SgInitializedNamePtrList& params = fundecl->get_args();
SgInitializedNamePtrList::iterator i;
SgExpressionPtrList& funargs = funcall->get_args()->get_expressions();
SgExpressionPtrList::iterator j;
//int ctr; // unused variable, Liao
std::vector<SgInitializedName*> inits;
SgTreeCopy tc;
SgFunctionDefinition* function_copy = isSgFunctionDefinition(fundef->copy(tc));
ROSE_ASSERT (function_copy);
SgBasicBlock* funbody_copy = function_copy->get_body();
SgFunctionDefinition* targetFunction = PRE::getFunctionDefinition(funcall);
renameLabels(funbody_copy, targetFunction);
std::cout << "Original symbol count: " << funbody_raw->get_symbol_table()->size() << std::endl;
std::cout << "Copied symbol count: " << funbody_copy->get_symbol_table()->size() << std::endl;
// std::cout << "Original symbol count f: " << fundef->get_symbol_table()->size() << std::endl;
// std::cout << "Copied symbol count f: " << function_copy->get_symbol_table()->size() << std::endl;
// We don't need to keep the copied function definition now that the
// labels in it have been moved to the target function. Having it in the
// memory pool confuses the AST tests.
function_copy->set_declaration(NULL);
示例8: 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); \
} \
//.........这里部分代码省略.........