本文整理汇总了C++中SgVariableDeclaration类的典型用法代码示例。如果您正苦于以下问题:C++ SgVariableDeclaration类的具体用法?C++ SgVariableDeclaration怎么用?C++ SgVariableDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SgVariableDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildListOfGlobalVariables
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;
}
示例2: isSgFunctionDeclaration
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();
}
}
示例3: 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;
}
示例4: ROSE_ASSERT
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() */
示例5: 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
}
}
}
}
}
}
}
}
}
}
示例6: 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);
}
示例7: 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;
}
示例8: main
int main (int argc, char *argv[])
{
// grab the scope in which AST will be added
SgProject *project = frontend (argc, argv);
SgGlobal *globalScope = getFirstGlobalScope (project);
ROSE_ASSERT(globalScope != NULL);
// DQ (9/28/2009): Tracking down GNU 4.0.x compiler problem!
// SageBuilder::clearScopeStack();
// SageBuilder::pushScopeStack (globalScope);
// bottom up for volatile int j; no previous knowledge of target scope
SgVariableDeclaration *varDecl0 = buildVariableDeclaration("j",
buildVolatileType(buildIntType()));
//const int jc = 0;
SgVariableDeclaration *varDecl0c = buildVariableDeclaration("jc",
buildConstType(buildIntType()), buildAssignInitializer(buildIntVal(0)));
// int * restrict p;
SgVariableDeclaration *varDecl0p = buildVariableDeclaration("jp",
// buildRestrictType(buildIntType()));
buildRestrictType(buildPointerType(buildIntType())));
// top down for others; set implicit target scope info. in scope stack.
pushScopeStack (isSgScopeStatement (globalScope));
// extern int i;
SgVariableDeclaration *varDecl = buildVariableDeclaration
(SgName ("i"), buildIntType());
((varDecl->get_declarationModifier()).get_storageModifier()).setExtern();
appendStatement (varDecl);
// two ways to build a same declaration
// int i;
#if 1
SgVariableDeclaration *varDecl2 = buildVariableDeclaration
(SgName ("i"), buildIntType());
#else
// this one does not yet working,maybe related to copy mechanism
SgVariableDeclaration *varDecl2 = isSgVariableDeclaration(deepCopy(varDecl));
((varDecl->get_declarationModifier()).get_storageModifier()).setDefault();
#endif
appendStatement (varDecl2);
insertStatementAfter(varDecl2,varDecl0);
prependStatement(varDecl0c);
prependStatement(varDecl0p);
popScopeStack ();
AstTests::runAllTests(project);
return backend (project);
}
示例9: hasPrivateDataMembers
static
bool hasPrivateDataMembers(SgClassDeclaration* cd_copy)
{
const SgNodePtrList& variables = NodeQuery::querySubTree(cd_copy, V_SgVariableDeclaration);
SgNodePtrList::const_iterator varIt = variables.begin();
for (; varIt != variables.end(); ++varIt) {
SgVariableDeclaration* node = isSgVariableDeclaration(*varIt);
SgAccessModifier am = node->get_declarationModifier().get_accessModifier();
if (am.isPrivate())
return true;
}
return false;
}
示例10: visit
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.
示例11: main
// ******************************************
// 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);
}
示例12: 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;
}
示例13: 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++;
}
}
}
示例14: isSgInitializedName
void BasicProgmemTransform::transformCharArrayInitialization(SgFunctionDeclaration *func) {
/* *
* Translates statements of the form:
* char arr[n] = "some string"; to:
* char arr[n];
* strcpy_P(arr, <progmem placeholder>);
* */
Rose_STL_Container<SgNode *> initNames = NodeQuery::querySubTree(func, V_SgInitializedName);
for(auto &item: initNames) {
SgInitializedName *initName = isSgInitializedName(item);
if(initName->get_initializer() == NULL) {
continue;
}
SgVariableDeclaration * varDecl = isSgVariableDeclaration(initName->get_declaration());
if(varDecl == NULL) {
continue;
}
SgAssignInitializer *assignInit = isSgAssignInitializer(initName->get_initializer());
if(assignInit == NULL) {
continue;
}
SgType *type = initName->get_type();
SgType *eleType = SageInterface::getElementType(type);
if(isSgArrayType(type) && eleType != NULL && isSgTypeChar(eleType)) {
SgStringVal* strVal = isSgStringVal(assignInit->get_operand());
std::string str = strVal->get_value();
int arrSize = getDeclaredArraySize(isSgArrayType(type));
if(arrSize == 0) {
//char arr[] = "something";
int size = str.length() + 1;
SgArrayType *type = SageBuilder::buildArrayType(SageBuilder::buildCharType(), SageBuilder::buildIntVal(size));
initName->set_type(type);
}
varDecl->reset_initializer(NULL);
SgVariableDeclaration *placeholder = getVariableDeclPlaceholderForString(str);
SgVarRefExp *ref = SageBuilder::buildVarRefExp(placeholder);
std::stringstream instr;
instr << "\n strcpy_P(" << initName->get_name().getString();
instr << ", " << ref->get_symbol()->get_name().getString() << ");\n";
SageInterface::attachComment(varDecl, instr.str(), PreprocessingInfo::after);
printf("transformed %s\n", initName->unparseToString().c_str());
}
}
}
示例15: 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;
}