本文整理汇总了C++中SgVariableDeclaration::get_variables方法的典型用法代码示例。如果您正苦于以下问题:C++ SgVariableDeclaration::get_variables方法的具体用法?C++ SgVariableDeclaration::get_variables怎么用?C++ SgVariableDeclaration::get_variables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgVariableDeclaration
的用法示例。
在下文中一共展示了SgVariableDeclaration::get_variables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: anyOfListPotentiallyModifiedIn
// Are any variables in syms modified anywhere within n, or is n a declaration
// of one of them?
// FIXME: move to inliner
bool anyOfListPotentiallyModifiedIn(const vector<SgVariableSymbol*>& syms,
SgNode* n) {
bool modified = false;
for (vector<SgVariableSymbol*>::const_iterator j = syms.begin();
j != syms.end(); ++j) {
SgVarRefExp* vr = new SgVarRefExp(SgNULL_FILE, *j);
vr->set_endOfConstruct(SgNULL_FILE);
if (isPotentiallyModified(vr, n)) {
modified = true;
}
delete vr;
if (modified) break;
if (isSgVariableDeclaration(n)) {
SgVariableDeclaration* decl = isSgVariableDeclaration(n);
for (SgInitializedNamePtrList::const_iterator i =
decl->get_variables().begin();
i != decl->get_variables().end(); ++i) {
if (*i == (*j)->get_declaration()) {
modified = true;
break;
}
}
}
if (modified) break;
}
return modified;
}
示例2: 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;
}
示例3: isSgVariableDeclaration
void
CompassAnalyses::StaticConstructorInitialization::Traversal::
visit(SgNode* node)
{
// Test for static initialization of variables of type class, such initializations where they are
// static or appear in global scope can be called in an order dependent upon the compiler and this
// can lead to subtle bugs in large scale applications.
SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node);
if (variableDeclaration != NULL)
{
SgInitializedNamePtrList::iterator i = variableDeclaration->get_variables().begin();
while (i != variableDeclaration->get_variables().end())
{
SgInitializedName* initializedName = *i;
// Check the type and see if it is a class (check for typedefs too)
SgType* variableType = initializedName->get_type();
SgClassType *classType = isSgClassType(variableType);
if (classType != NULL)
{
// Now check if this is a global or namespace variable or an static class member
// This might also have to be a test for other scopes as well.
SgScopeStatement* scope = variableDeclaration->get_scope();
if (isSgGlobal(scope) != NULL || isSgNamespaceDefinitionStatement(scope) != NULL)
{
// printf ("Found a global variable defining a class = %p \n",initializedName);
// variableDeclaration->get_file_info()->display("global variable defining a class");
output->addOutput(new CheckerOutput(initializedName));
}
if (isSgClassDefinition(scope) != NULL)
{
// Now check if it is a static data member
if (variableDeclaration->get_declarationModifier().get_storageModifier().isStatic() == true)
{
// printf ("Found a static data member defining a class = %p \n",initializedName);
// variableDeclaration->get_file_info()->display("static data member defining a class");
output->addOutput(new CheckerOutput(initializedName));
}
}
}
// increment though the variables in the declaration (typically just one)
i++;
}
}
} //End of the visit function.
示例4: if
string
Doxygen::getDeclStmtName(SgDeclarationStatement *st)
{
SgFunctionDeclaration *fn = isSgFunctionDeclaration(st);
SgVariableDeclaration *vn = isSgVariableDeclaration(st);
SgClassDeclaration *cn = isSgClassDeclaration(st);
if (fn)
{
return fn->get_name().str();
}
else if (vn)
{
/* XXX The following is a bit dodgy since single
* SgVariableDeclaration may declare multiple
* variables. But doxygen doesn't handle this case
* properly. A useful transform may split up the
* SgVariableDeclaration for doxygen's sake */
return (*(vn->get_variables().begin()))->get_name().str();
}
else if (cn)
{
return cn->get_name().str();
}
else
{
fprintf(stderr, "Cannot handle this case: %s\n", st->sage_class_name());
abort();
}
}
示例5: assert
Rose_STL_Container<SgInitializedName*>
buildListOfGlobalVariables ( SgSourceFile* file )
{
// This function builds a list of global variables (from a SgFile).
assert(file != NULL);
Rose_STL_Container<SgInitializedName*> globalVariableList;
SgGlobal* globalScope = file->get_globalScope();
assert(globalScope != NULL);
Rose_STL_Container<SgDeclarationStatement*>::iterator i = globalScope->get_declarations().begin();
while(i != globalScope->get_declarations().end())
{
SgVariableDeclaration *variableDeclaration = isSgVariableDeclaration(*i);
if (variableDeclaration != NULL)
{
Rose_STL_Container<SgInitializedName*> & variableList = variableDeclaration->get_variables();
Rose_STL_Container<SgInitializedName*>::iterator var = variableList.begin();
while(var != variableList.end())
{
globalVariableList.push_back(*var);
var++;
}
}
i++;
}
return globalVariableList;
}
示例6: isSgVariableDeclaration
void
Traversal::visit(SgNode* node)
{
SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node);
// Look for variable declarations appearing in global scope!
// if (variableDeclaration != NULL && isSgGlobal(variableDeclaration->get_parent()) != NULL)
if (variableDeclaration != NULL)
{
SgInitializedNamePtrList::iterator i = variableDeclaration->get_variables().begin();
while (i != variableDeclaration->get_variables().end())
{
SgInitializedName* initializedName = *i;
// Check the type and see if it is a class (check for typedefs too)
SgType* variableType = initializedName->get_type();
SgClassType *classType = isSgClassType(variableType);
if (classType != NULL)
{
// Now check if this is a global variable or an static class member
SgScopeStatement* scope = variableDeclaration->get_scope();
if (isSgGlobal(scope) != NULL)
{
printf ("Found a global variable defining a class \n");
// variableDeclaration->get_file_info()->display("global variable defining a class");
outputPositionInformation(variableDeclaration);
}
if (isSgClassDefinition(scope) != NULL)
{
// Now check if it is a static data member
if (variableDeclaration->get_declarationModifier().get_storageModifier().isStatic() == true)
{
printf ("Found a static data member defining a class \n");
// variableDeclaration->get_file_info()->display("static data member defining a class");
outputPositionInformation(variableDeclaration);
}
}
}
// increment though the variables in the declaration (typically just one)
i++;
}
}
}
示例7: isSgClassDefinition
NameQuerySynthesizedAttributeType
NameQuery::queryNameUnionFieldNames (SgNode * astNode)
{
ROSE_ASSERT (astNode != 0);
NameQuerySynthesizedAttributeType returnNameList;
// SgNode *sageReturnNode = NULL;
SgClassDefinition *sageClassDefinition = isSgClassDefinition (astNode);
if (sageClassDefinition != NULL)
{
ROSE_ASSERT (sageClassDefinition->get_declaration () != NULL);
if (sageClassDefinition->get_declaration ()->get_class_type () ==
SgClassDeclaration::e_struct)
{
SgDeclarationStatementPtrList declarationStatementPtrList =
sageClassDefinition->get_members ();
typedef SgDeclarationStatementPtrList::iterator LI;
for (LI i = declarationStatementPtrList.begin ();
i != declarationStatementPtrList.end (); ++i)
{
SgNode *listElement = *i;
SgVariableDeclaration *sageVariableDeclaration =
isSgVariableDeclaration (listElement);
if (sageVariableDeclaration != NULL)
{
typedef SgInitializedNamePtrList::iterator INITLI;
SgInitializedNamePtrList sageInitializedNameList = sageVariableDeclaration->get_variables ();
for (INITLI i = sageInitializedNameList.begin ();
i != sageInitializedNameList.end (); ++i)
{
SgInitializedName* initializedListElement = *i;
ROSE_ASSERT (isSgInitializedName (initializedListElement) != NULL);
returnNameList.push_back (initializedListElement->get_name().str());
} /* End iteration over declarationStatementPtrList */
} /* End iteration over declarationStatementPtrList */
}
}
}
return returnNameList;
} /* End function queryUnionFieldNames() */
示例8: visit
virtual void visit(SgNode* n) {
if (isSgBasicBlock(n)) {
SgBasicBlock* bb = isSgBasicBlock(n);
SgStatementPtrList& stmts = bb->get_statements();
size_t initi;
for (size_t decli = 0; decli < stmts.size(); ++decli) {
if (isSgVariableDeclaration(stmts[decli])) {
SgVariableDeclaration* decl = isSgVariableDeclaration(stmts[decli]);
SgInitializedNamePtrList& vars = decl->get_variables();
for (size_t vari = 0; vari != vars.size(); ++vari) {
SgInitializedName* in = vars[vari];
if (in->get_initializer() == 0) {
bool used = false;
for (initi = decli + 1; initi < stmts.size();
used |= containsVariableReference(stmts[initi], in),
++initi) {
SgExprStatement* initExprStmt = isSgExprStatement(stmts[initi]);
if (initExprStmt) {
SgExpression* top = initExprStmt->get_expression();
if (isSgAssignOp(top)) {
SgVarRefExp* vr = isSgVarRefExp(isSgAssignOp(top)->get_lhs_operand());
ROSE_ASSERT(isSgAssignOp(top) != NULL);
SgExpression* newinit = isSgAssignOp(top)->get_rhs_operand();
if (!used && vr && vr->get_symbol()->get_declaration() == in) {
ROSE_ASSERT(newinit != NULL);
// printf ("MoveDeclarationsToFirstUseVisitor::visit(): newinit = %p = %s \n",newinit,newinit->class_name().c_str());
ROSE_ASSERT(newinit->get_type() != NULL);
SgAssignInitializer* i = new SgAssignInitializer(SgNULL_FILE,newinit,newinit->get_type());
i->set_endOfConstruct(SgNULL_FILE);
// printf ("Built a SgAssignInitializer #1 \n");
vars[vari]->set_initializer(i);
stmts[initi] = decl;
newinit->set_parent(i);
// DQ (6/23/2006): Set the parent and file_info pointers
// printf ("Setting parent of i = %p = %s to parent = %p = %s \n",i,i->class_name().c_str(),in,in->class_name().c_str());
i->set_parent(in);
ROSE_ASSERT(i->get_parent() != NULL);
i->set_file_info(new Sg_File_Info(*(newinit->get_file_info())));
ROSE_ASSERT(i->get_file_info() != NULL);
// Assumes only one var per declaration FIXME
ROSE_ASSERT (vars.size() == 1);
stmts.erase(stmts.begin() + decli);
--decli; // To counteract ++decli in loop header
break; // To get out of initi loop
}
}
}
}
}
}
}
}
}
}
示例9: isSgVariableDeclaration
void
Unparse_Jovial::unparseVarDeclStmt(SgStatement* stmt, SgUnparse_Info& info)
{
SgVariableDeclaration* vardecl = isSgVariableDeclaration(stmt);
ROSE_ASSERT(vardecl != NULL);
SgInitializedNamePtrList::iterator p = vardecl->get_variables().begin();
// Jovial has only one variable per declaration
unparseVarDecl(vardecl, *p, info);
}
示例10: main
int main(int argc, char** argv) {
SgProject* proj = frontend(argc,argv);
SgFunctionDeclaration* mainDecl = SageInterface::findMain(proj);
SgFunctionDefinition* mainDef = mainDecl->get_definition();
std::vector<SgNode*> ifExps;
ifExps = NodeQuery::querySubTree(mainDef, V_SgIfStmt);
for (int i = 0; i < ifExps.size(); i++) {
getIfConds(isSgIfStmt(ifExps[i]), isSgScopeStatement(mainDef));
}
std::vector<SgNode*> assignNodes = NodeQuery::querySubTree(mainDef, V_SgVariableDeclaration);
std::cout << assignNodes.size() << " nodes found" << std::endl;
std::vector<SgBinaryOp*> bin_ops;
std::vector<SgUnaryOp*> un_ops;
std::vector<SgNode*> other;
std::vector<SgExpression*> results;
for (std::vector<SgNode*>::iterator i = assignNodes.begin(); i != assignNodes.end(); i++) {
SgVariableDeclaration* vdecl = isSgVariableDeclaration(*i);
SgInitializedNamePtrList vlst = vdecl->get_variables();
SgInitializedName* initName = isSgInitializedName((*(vlst.begin())));
SgExpression* exp = isSgAssignInitializer(initName->get_initializer())->get_operand();
std::cout << exp->class_name() << std::endl;
if (!isSgFunctionCallExp(exp)) {
getExps(exp, isSgInitializedName(*i), results, 0);
std::cout << "prefixes" << std::endl;
for (int j = 0; j < prefixes.size(); j++) {
SgExprStatement* expSt = SageBuilder::buildExprStatement_nfi(prefixes[j]);
SageInterface::insertStatement(isSgVariableDeclaration(*i),expSt,true);
std::cout << prefixes[j]->class_name() << std::endl;
}
std::cout << "results" << std::endl;
for (int j = 0; j < results.size(); j++) {
std::cout << results[j]->class_name() << std::endl;
}
std::cout << "postfixes" << std::endl;
for (int j = 0; j < postfixes.size(); j++) {
SgExprStatement* expSt = SageBuilder::buildExprStatement_nfi(postfixes[j]);
SageInterface::insertStatement(isSgVariableDeclaration(*i),expSt,false);
std::cout << postfixes[j]->class_name() << std::endl;
}
replaceExps(exp,vdecl);
simplifyExps(exp);
}
}
backend(proj);
return 0;
}
示例11: buildVariableDeclaration
SgVariableDeclaration *
RoseStatementsAndExpressionsBuilder::appendVariableDeclarationAsFormalParameter (
std::string const & variableName, SgType * type, SgScopeStatement * scope,
SgFunctionParameterList * formalParameters)
{
using namespace SageBuilder;
using namespace SageInterface;
SgVariableDeclaration * variableDeclaration = buildVariableDeclaration (
variableName, type, NULL, scope);
formalParameters->append_arg (
*(variableDeclaration->get_variables ().begin ()));
return variableDeclaration;
}
示例12: isSgInitializedName
bool
TaintAnalysis::magic_tainted(SgNode *node, FiniteVarsExprsProductLattice *prodLat) {
if (isSgInitializedName(node)) {
SgInitializedName *iname = isSgInitializedName(node);
std::string vname = iname->get_name().getString();
TaintLattice *tlat = dynamic_cast<TaintLattice*>(prodLat->getVarLattice(varID(iname)));
if (tlat && 0==vname.compare(0, 7, "TAINTED")) {
bool modified = tlat->set_vertex(TaintLattice::VERTEX_TAINTED);
if (debug) {
*debug <<"TaintAnalysis::magic_tainted: lattice is magically " <<tlat->to_string()
<<(modified?" (modified)":" (not modified)") <<"\n";
}
return modified;
}
} else if (isSgVarRefExp(node)) {
SgVarRefExp *vref = isSgVarRefExp(node);
std::string vname = vref->get_symbol()->get_name().getString();
TaintLattice *tlat = dynamic_cast<TaintLattice*>(prodLat->getVarLattice(varID(vref)));
if (tlat && 0==vname.compare(0, 7, "TAINTED")) {
bool modified = tlat->set_vertex(TaintLattice::VERTEX_TAINTED);
if (debug) {
*debug <<"TaintAnalysis::magic_tainted: lattice is magically " <<tlat->to_string()
<<(modified?" (modified)":" (not modified)") <<"\n";
}
return modified;
}
} else if (isSgVariableDeclaration(node)) {
SgVariableDeclaration *vdecl = isSgVariableDeclaration(node);
const SgInitializedNamePtrList &inames = vdecl->get_variables();
for (size_t i=0; i<inames.size(); ++i) {
std::string vname = inames[i]->get_name().getString();
TaintLattice *tlat = dynamic_cast<TaintLattice*>(prodLat->getVarLattice(varID(inames[i])));
if (tlat && 0==vname.compare(0, 7, "TAINTED")) {
bool modified = tlat->set_vertex(TaintLattice::VERTEX_TAINTED);
if (debug) {
*debug <<"TaintAnalysis::magic_tainted: lattice is magically " <<tlat->to_string()
<<(modified?" (modified)":" (not modified)") <<"\n";
}
return modified;
}
}
}
return false;
}
示例13: 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);
}
示例14: removeVariableDeclaration
// Remove the declaration of a given variable.
void removeVariableDeclaration(SgInitializedName* initname) {
SgVariableDeclaration* parent =
isSgVariableDeclaration(initname->get_parent());
assert (parent);
SgInitializedNamePtrList& vars = parent->get_variables();
SgInitializedNamePtrList::iterator i = vars.begin();
for (; i != vars.end(); ++i)
if (*i == initname)
break;
assert (i != vars.end());
#if 0
vars.erase(i);
if (vars.empty()) {
myRemoveStatement(parent);
}
#endif
ROSE_ASSERT (vars.size() == 1);
SageInterface::myRemoveStatement(parent);
}
示例15: isSgName
Rose_STL_Container<SgNode*> NodeQuery::queryNodeVariableDeclarationFromName(SgNode* astNode, SgNode* nameNode){
ROSE_ASSERT( nameNode != NULL );
ROSE_ASSERT( astNode != NULL );
Rose_STL_Container<SgNode*> returnList;
if(astNode->variantT() == V_SgVariableDeclaration){
SgName* sageName = isSgName(nameNode);
ROSE_ASSERT( sageName != NULL );
std::string nameToMatch = sageName->str();
ROSE_ASSERT( nameToMatch.length() > 0 );
SgVariableDeclaration* sageVariableDeclaration = isSgVariableDeclaration(astNode);
ROSE_ASSERT(sageVariableDeclaration != NULL);
ROSE_ASSERT( sageVariableDeclaration->get_definition() != NULL );
SgInitializedNamePtrList sageInitializedNameList = sageVariableDeclaration->get_variables ();
//see if this variable declaration fits the criteria
typedef SgInitializedNamePtrList::iterator variableIterator;
for (variableIterator k = sageInitializedNameList.begin ();
k != sageInitializedNameList.end(); ++k)
{
SgInitializedName* elmVar = *k;
std::string name = elmVar->get_name().str();
if(name == nameToMatch)
returnList.push_back(astNode);
}
}
return returnList;
}; /* End function: queryNodeVariableDeclarationFromName */