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; }
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(); } }
// 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; }
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() */
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 } } } } } } } } } }
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); }
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; }
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); }
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; }
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.
// ****************************************** // 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); }
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; }
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++; } } }
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()); } } }
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; }
void FindVariableDeclarations::visit ( SgNode* astNode ) { SgBasicBlock* block = isSgBasicBlock(astNode); if (block != NULL) { SgStatementPtrList & listOfStatements = block->get_statements(); for (size_t i = 0; i < listOfStatements.size(); i++) { SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(listOfStatements[i]); if (variableDeclaration != NULL) { printf ("Found a variable decaration in a SgBasicBlock at: \n"); variableDeclaration->get_file_info()->display("Found a variable decaration in a SgBasicBlock"); } } } }
bool findPublicVarMembers (SgNode *node, string &str) { SgVariableDeclaration *decl; if (decl = isSgVariableDeclaration(node)) { SgDeclarationModifier &dfm = decl->get_declarationModifier(); if (dfm.get_accessModifier().isPublic()) { // check if it belongs to a class SgStatement *block = ((SgVariableDeclaration *) node)->get_scope(); SgClassDefinition *classDef; if (classDef = isSgClassDefinition(block)) { if (classDef->get_declaration()->get_class_type() == SgClassDeclaration::e_class) { str = classDef->get_qualified_name().getString(); return true; } } } } return false; }
void Unparse_Jovial::unparseVarDecl(SgStatement* stmt, SgInitializedName* initializedName, SgUnparse_Info& info) { SgName name = initializedName->get_name(); SgType* type = initializedName->get_type(); SgInitializer* init = initializedName->get_initializer(); ROSE_ASSERT(type); SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(stmt); ROSE_ASSERT(variableDeclaration != NULL); #if 0 if (variableDeclaration->get_declarationModifier().get_typeModifier().isStatic() == true) { curprint("STATIC "); } #endif switch (type->variantT()) { case V_SgArrayType: curprint("TABLE "); curprint(name.str()); break; default: curprint("ITEM "); curprint(name.str()); curprint(" "); } unparseType(type, info); if (init != NULL) { curprint(" = "); SgInitializer* initializer = isSgInitializer(init); ROSE_ASSERT(initializer != NULL); // TODO // unparseExpression(initializer, info); } curprint(" ;\n"); }
// 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); }
virtual void visit(SgNode* n) { if (isSgFunctionDefinition(n)) { renameLabels(isSgFunctionDefinition(n), isSgFunctionDefinition(n)); } else if (isSgInitializedName(n)) { SgInitializedName* n2 = isSgInitializedName(n); ROSE_ASSERT(n2->get_file_info() != NULL); if (isMemberVariable(*n2)) return; // JW (7/16/2004): Added patch if (isSgVariableDeclaration(n2->get_parent())) { SgVariableDeclaration* decl = isSgVariableDeclaration(n2->get_parent()); if (isSgGlobal(decl->get_parent())) return; if (isSgNamespaceDefinitionStatement(decl->get_parent())) return; } if (isSgCtorInitializerList(n2->get_parent())) return; if (n2->get_name().getString() == "") return; SgName name(n2->get_name()); SgSymbolTable* symtab = n2->get_scope()->get_symbol_table(); SgSymbol* sym = symtab->find(n2); if (sym) { symtab->remove(sym); } name << "__" << counter++; n2->set_name(name); SgVariableSymbol* n2symbol = new SgVariableSymbol(n2); n2symbol->set_parent(symtab); symtab->insert(name, n2symbol); // printf ("RenameVariablesVisitor(): name = %s scope = %p = %s \n",name.str(),savedScope,savedScope->class_name().c_str()); ROSE_ASSERT(n2->get_parent() != NULL); ROSE_ASSERT(n2->get_file_info() != NULL); } }
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 */
void mlmFrontend::attachAttribute(SgPragmaDeclaration* pragma, AstAttribute* attr) { // attribute to specify memory level if(isSgVariableDeclaration(getNextStatement(pragma))) { SgVariableDeclaration* decl = isSgVariableDeclaration(getNextStatement(pragma)); ROSE_ASSERT(decl); SgInitializedNamePtrList nameList = decl->get_variables(); if(nameList.size() == 1) { SgInitializedName* initName = nameList[0]; SgSymbol* symbol = initName->get_symbol_from_symbol_table(); symbol->setAttribute("mlmAttribute", attr); } } // attribute to specify tiling level else if(isSgForStatement(getNextStatement(pragma))) { SgForStatement* forStmt = isSgForStatement(getNextStatement(pragma)); ROSE_ASSERT(forStmt); forStmt->setAttribute("mlmAttribute", attr); } }
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); } }
DeterminismState getExpectation(SgNode *ast, const char *varName) { SgName name(varName); Rose_STL_Container<SgNode*> sdNodes = NodeQuery::querySubTree(ast, &name, NodeQuery::VariableDeclarationFromName); if (sdNodes.size() != 1) { cerr << "Didn't find target variable " << varName << " in list of size " << sdNodes.size() << endl; for (Rose_STL_Container<SgNode*>::iterator i = sdNodes.begin(); i != sdNodes.end(); ++i) cerr << "\t" << (*(isSgVariableDeclaration(*i)->get_variables().begin()))->get_name().str() << endl; return QUESTIONABLE; } SgNode *nSd = *(sdNodes.begin()); SgVariableDeclaration *vdSd = dynamic_cast<SgVariableDeclaration *>(nSd); if (!vdSd) { cerr << "Node wasn't a variable declaration" << endl; return QUESTIONABLE; } SgInitializedName *inSd = vdSd->get_decl_item(name); SgAssignInitializer *aiSd = dynamic_cast<SgAssignInitializer*>(inSd->get_initializer()); if (!aiSd) { cerr << "Couldn't pull an assignment initializer out" << endl; return QUESTIONABLE; } SgIntVal *ivSd = dynamic_cast<SgIntVal*>(aiSd->get_operand()); if (!ivSd) { cerr << "Assignment wasn't an intval" << endl; return QUESTIONABLE; } int value = ivSd->get_value(); return value ? DETERMINISTIC : NONDETERMINISTIC; }
void FortranOpenMPModuleDeclarationsIndirectLoop::createFirstTimeExecutionDeclaration () { using namespace SageBuilder; using namespace SageInterface; using namespace BooleanVariableNames; Debug::getInstance ()->debugMessage ( "Creating first time execution boolean at module scope", Debug::FUNCTION_LEVEL, __FILE__, __LINE__); SgVariableDeclaration * variableDeclaration = buildVariableDeclaration (getFirstTimeExecutionVariableName ( parallelLoop->getUserSubroutineName ()), buildBoolType (), buildAssignInitializer (buildBoolValExp (true), buildBoolType ()), moduleScope); variableDeclaration->get_declarationModifier ().get_accessModifier ().setUndefined (); variableDeclarations->add (getFirstTimeExecutionVariableName ( parallelLoop->getUserSubroutineName ()), variableDeclaration); appendStatement (variableDeclaration, moduleScope); }
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); }
SgClassDeclaration* RtedTransformation::instrumentClassDeclarationIntoTopOfAllSourceFiles( SgProject* project, SgClassDeclaration* classDecl) { // ********************** if (RTEDDEBUG) cerr <<"@@@ instrumenting into top "<< endl; // deep copy the classdecl and make it unparseable SgClassDeclaration* cd_copy = SageInterface::deepCopy(classDecl); // cout << ">>>>>> Original ClassType :::: " << classDecl->get_type() << endl; // cout << ">>>>>> Copied ClassType :::: " << cd_copy->get_type() << endl; // SgClassType* type_copy = new SgClassType(cd_copy); //cd_copy->set_type(type_copy); ROSE_ASSERT(cd_copy); const SgNodePtrList& nodes2 = NodeQuery::querySubTree(cd_copy, V_SgLocatedNode); SgNodePtrList::const_iterator nodesIT2 = nodes2.begin(); for (; nodesIT2 != nodes2.end(); ++nodesIT2) { SgLocatedNode* node = isSgLocatedNode(*nodesIT2); ROSE_ASSERT(node); Sg_File_Info* file_info = node->get_file_info(); file_info->setOutputInCodeGeneration(); //cerr << "copying node : " << node->class_name() << endl; } if (RTEDDEBUG) cerr << "deep copy of firstnondefining" << endl; SgClassDeclaration* nondefDecl = isSgClassDeclaration(classDecl->get_firstNondefiningDeclaration()); SgClassDeclaration* cdn_copy = SageInterface::deepCopy(nondefDecl); ROSE_ASSERT(cdn_copy); const SgNodePtrList& nodes = NodeQuery::querySubTree(cdn_copy, V_SgLocatedNode); SgNodePtrList::const_iterator nodesIT = nodes.begin(); for (; nodesIT != nodes.end(); ++nodesIT) { SgLocatedNode* node = isSgLocatedNode(*nodesIT); ROSE_ASSERT(node); Sg_File_Info* file_info = node->get_file_info(); file_info->setOutputInCodeGeneration(); } cd_copy->set_firstNondefiningDeclaration(cdn_copy); SgClassType* cls_type = SgClassType::createType(cdn_copy); cls_type->set_declaration(cdn_copy); ROSE_ASSERT(cls_type != NULL); ROSE_ASSERT (cls_type->get_declaration() == cdn_copy); cdn_copy->set_type(cls_type); cdn_copy->set_definingDeclaration(cd_copy); cd_copy->set_type(cdn_copy->get_type()); if (RTEDDEBUG) { cerr << "@@@@@@@@@@@@@@ Original Class classDecl : " << classDecl << " :: " << cd_copy << endl; cerr << "@@@@@@@@@@@@@@ Original Class nondefining : " << classDecl->get_firstNondefiningDeclaration()<< " :: " << cdn_copy << endl; cerr << "@@@@@@@@@@@@@@@@@@ TYPE OF cd_copy->get_type() : " << cd_copy->get_type() << endl; cerr << "@@@@@@@@@@@@@@@@@@ TYPE OF cdn_copy->get_type() : " << cdn_copy->get_type() << endl; cerr << "@@@@@@@@@@@@@@@@@@ TYPE OF cd_copy->get_type()->declaration : " <<cd_copy->get_type()->get_declaration() << endl; cerr << "@@@@@@@@@@@@@@@@@@ TYPE OF cd_copy->definingDeclaration : " << cd_copy->get_definingDeclaration() << endl; cerr << "@@@@@@@@@@@@@@@@@@ TYPE OF cd_copy->set_firstNondefiningDeclaration : " << cd_copy->get_firstNondefiningDeclaration() << endl; } // ********************** // add to top of each source file // insert at top of all source files in reverse order // only if the class has private members and if it is declared in a header file std::vector<SgSourceFile*>::const_iterator aa = srcfiles.begin(); std::vector<SgSourceFile*>::const_iterator zz = srcfiles.end(); for (; aa != zz; ++aa) { SgSourceFile* sf = *aa; assert( isInInstrumentedFile(sf) ); if (RTEDDEBUG) cerr << "Looking through sourcefile: " << sf -> get_file_info() -> get_filename() << endl; // once we have the new class_decl inserted, we remove all functions and the constructor and destructor const SgNodePtrList& remNodes = NodeQuery::querySubTree(cd_copy, V_SgFunctionDeclaration); SgNodePtrList::const_iterator remNodesIt = remNodes.begin(); for (; remNodesIt != remNodes.end(); ++remNodesIt) { SgFunctionDeclaration* node = isSgFunctionDeclaration(*remNodesIt); ROSE_ASSERT(node); SageInterface::removeStatement(node); } if (RTEDDEBUG) cerr << " changing privates to public" << endl; // change each private: to public: SgClassDefinition* cd_def = cd_copy->get_definition(); ROSE_ASSERT(cd_def); SgDeclarationStatementPtrList decls = cd_def->get_members(); SgDeclarationStatementPtrList::const_iterator itDecls = decls.begin(); for (;itDecls!=decls.end();++itDecls) { SgVariableDeclaration* node = isSgVariableDeclaration(*itDecls); if (node) { SgDeclarationModifier& mod = node->get_declarationModifier(); SgAccessModifier& am = mod.get_accessModifier(); if (am.isPrivate() || am.isProtected()) am.setPublic(); } } // get the namespace RTED to put new class into if (RTEDDEBUG) cerr << "Finding Namespace RTED " << endl; SourceFileRoseNMType::const_iterator pit = sourceFileRoseNamespaceMap.find(sf); ROSE_ASSERT(pit!=sourceFileRoseNamespaceMap.end()); SgNamespaceDeclarationStatement* firstNamespace = pit->second; // insert at top of file - after includes if (RTEDDEBUG) { cerr << " Prepending to source file: " << sf -> get_file_info() -> get_filename() << " class : " << cd_copy->get_name().str() << endl; } // we prepend it to the top of the file and later move the include back up SageInterface::prependStatement(cdn_copy,firstNamespace->get_definition()); SageInterface::appendStatement(cd_copy, firstNamespace->get_definition() ); ROSE_ASSERT(cdn_copy->get_symbol_from_symbol_table() != NULL); classesInRTEDNamespace[classDecl->get_definition()] = cd_def; } return cd_copy; }
void FortranCUDAUserSubroutine::createStatements () { using namespace SageInterface; using boost::iequals; using std::string; using std::vector; class TreeVisitor: public AstSimpleProcessing { private: /* * ====================================================== * The recursive visit of a user subroutine populates * this vector with successive function calls which are * then appended after the visit * ====================================================== */ vector < SgProcedureHeaderStatement * > calledRoutines; public: vector < SgProcedureHeaderStatement * > getCalledRoutinesInStatement() { return calledRoutines; } TreeVisitor () { } virtual void visit (SgNode * node) { SgExprStatement * isExprStatement = isSgExprStatement ( node ); if ( isExprStatement != NULL ) { SgFunctionCallExp * functionCallExp = isSgFunctionCallExp ( isExprStatement->get_expression() ); if ( functionCallExp != NULL ) { string const calleeName = functionCallExp->getAssociatedFunctionSymbol ()->get_name ().getString (); Debug::getInstance ()->debugMessage ("Found function call in user subroutine " + calleeName + "'", Debug::OUTER_LOOP_LEVEL, __FILE__, __LINE__); /* * ====================================================== * As we are in fortran, all user subroutines must be * SgProcedureHeaderStatements = subroutines and not * functions. This might be extended to cover also * functions in the future (?). Probably not in OP2 * ====================================================== */ SgProcedureHeaderStatement * isProcedureHeaderStatement = isSgProcedureHeaderStatement ( functionCallExp->getAssociatedFunctionDeclaration() ); calledRoutines.push_back ( isProcedureHeaderStatement ); } } } }; Debug::getInstance ()->debugMessage ("User subroutine: outputting and modifying statements", Debug::FUNCTION_LEVEL, __FILE__, __LINE__); SgFunctionParameterList * originalParameters = originalSubroutine->get_parameterList (); vector <SgStatement *> originalStatements = originalSubroutine->get_definition ()->get_body ()->get_statements (); for (vector <SgStatement *>::iterator it = originalStatements.begin (); it != originalStatements.end (); ++it) { SgExprStatement * isExprStatement = isSgExprStatement ( *it ); if ( isExprStatement != NULL ) { SgFunctionCallExp * functionCallExp = isSgFunctionCallExp ( isExprStatement->get_expression() ); if ( functionCallExp != NULL ) { string const calleeName = functionCallExp->getAssociatedFunctionSymbol ()->get_name ().getString (); Debug::getInstance ()->debugMessage ("Found function call in user subroutine " + calleeName + "'", Debug::OUTER_LOOP_LEVEL, __FILE__, __LINE__); /* * ====================================================== * As we are in fortran, all user subroutines must be * SgProcedureHeaderStatements = subroutines and not * functions. This might be extended to cover also * functions in the future (probably not in OP2) * ====================================================== */ SgProcedureHeaderStatement * isProcedureHeaderStatement = isSgProcedureHeaderStatement ( functionCallExp->getAssociatedFunctionDeclaration() ); calledRoutines.push_back ( isProcedureHeaderStatement ); } } SgVariableDeclaration * isVariableDeclaration = isSgVariableDeclaration ( *it); if (isVariableDeclaration == NULL) { /* * ====================================================== * Do not append use statement, because other subroutines * are directly appended to the CUDA module * ====================================================== */ SgUseStatement * isUseStmt = isSgUseStatement ( *it ); if (isUseStmt != NULL) { Debug::getInstance ()->debugMessage ( "Not appending use statement", Debug::HIGHEST_DEBUG_LEVEL, __FILE__, __LINE__); } else { Debug::getInstance ()->debugMessage ( "Appending (non-variable-declaration) statement", Debug::HIGHEST_DEBUG_LEVEL, __FILE__, __LINE__); appendStatement (*it, subroutineScope); /* * ====================================================== * Recursively look for subroutine calls inside shallow * nodes in the routines (e.g. when a call is inside an * if). After the visit get the generated vector of names * and append it to the userSubroutine vector * ====================================================== */ TreeVisitor * visitor = new TreeVisitor (); visitor->traverse (*it, preorder); Debug::getInstance ()->debugMessage ("Appending deep subroutine calls", Debug::OUTER_LOOP_LEVEL, __FILE__, __LINE__); vector < SgProcedureHeaderStatement * > deepStatementCalls = visitor->getCalledRoutinesInStatement (); vector < SgProcedureHeaderStatement * >::iterator itDeepCalls; for (itDeepCalls = deepStatementCalls.begin(); itDeepCalls != deepStatementCalls.end(); ++itDeepCalls) calledRoutines.push_back (*itDeepCalls); Debug::getInstance ()->debugMessage ("Appending deep subroutine calls", Debug::OUTER_LOOP_LEVEL, __FILE__, __LINE__); } } else { Debug::getInstance ()->debugMessage ("Appending variable declaration", Debug::HIGHEST_DEBUG_LEVEL, __FILE__, __LINE__); unsigned int OP_DAT_ArgumentGroup = 1; for (SgInitializedNamePtrList::iterator variableIt = isVariableDeclaration->get_variables ().begin (); variableIt != isVariableDeclaration->get_variables ().end (); ++variableIt) { string const variableName = (*variableIt)->get_name ().getString (); SgType * type = (*variableIt)->get_typeptr (); /* * ====================================================== * Specification of "value" attribute is only * for user kernels. Our call convention is that * in all deeper level calls we always pass parameters * by reference (see else branch below) * ====================================================== */ bool isFormalParamater = false; for (SgInitializedNamePtrList::iterator paramIt = originalParameters->get_args ().begin (); paramIt != originalParameters->get_args ().end (); ++paramIt, ++OP_DAT_ArgumentGroup) { string const formalParamterName = (*paramIt)->get_name ().getString (); if (iequals (variableName, formalParamterName)) { isFormalParamater = true; if (parallelLoop->isIndirect (OP_DAT_ArgumentGroup) && parallelLoop->isRead (OP_DAT_ArgumentGroup)) { Debug::getInstance ()->debugMessage ("'" + variableName + "' is an INDIRECT formal parameter which is READ", Debug::HIGHEST_DEBUG_LEVEL, __FILE__, __LINE__); SgVariableDeclaration * variableDeclaration; if ( isUserKernel == true ) variableDeclaration = FortranStatementsAndExpressionsBuilder::appendVariableDeclarationAsFormalParameter ( variableName, type, subroutineScope, formalParameters, 0); else variableDeclaration = FortranStatementsAndExpressionsBuilder::appendVariableDeclarationAsFormalParameter ( variableName, type, subroutineScope, formalParameters, 0); ROSE_ASSERT ( variableDeclaration != NULL ); } else if (parallelLoop->isGlobal (OP_DAT_ArgumentGroup) && parallelLoop->isRead (OP_DAT_ArgumentGroup)) { Debug::getInstance ()->debugMessage ("'" + variableName + "' is a GLOBAL formal parameter which is READ", Debug::HIGHEST_DEBUG_LEVEL, __FILE__, __LINE__); SgVariableDeclaration * variableDeclaration = FortranStatementsAndExpressionsBuilder::appendVariableDeclarationAsFormalParameter ( variableName, type, subroutineScope, formalParameters, 0); } else { Debug::getInstance ()->debugMessage ("'" + variableName + "' is a formal parameter " + parallelLoop->getOpDatInformation (OP_DAT_ArgumentGroup), Debug::HIGHEST_DEBUG_LEVEL, __FILE__, __LINE__); if ( isUserKernel == true ) SgVariableDeclaration * variableDeclaration = FortranStatementsAndExpressionsBuilder::appendVariableDeclarationAsFormalParameter ( variableName, type, subroutineScope, formalParameters, 0); else SgVariableDeclaration * variableDeclaration = FortranStatementsAndExpressionsBuilder::appendVariableDeclarationAsFormalParameter ( variableName, type, subroutineScope, formalParameters, 0); } } } if (isFormalParamater == false) { Debug::getInstance ()->debugMessage ("'" + variableName + "' is NOT a formal parameter", Debug::HIGHEST_DEBUG_LEVEL, __FILE__, __LINE__); SgVariableDeclaration * variableDeclaration = FortranStatementsAndExpressionsBuilder::appendVariableDeclaration ( variableName, type, subroutineScope); } } } } }
NodeQuerySynthesizedAttributeType NodeQuery::querySolverVariableTypes (SgNode * astNode) { ROSE_ASSERT (astNode != NULL); NodeQuerySynthesizedAttributeType returnNodeList; /* SgVariableDeclaration* sageVariableDeclaration = isSgVariableDeclaration(astNode); if(sageVariableDeclaration != NULL) { SgInitializedNamePtrList sageInitializedNameList = sageVariableDeclaration->get_variables(); printf ("\nHere is a function declaration :Line = %d Columns = %d \n", ROSE:: getLineNumber (isSgLocatedNode(astNode) ), ROSE:: getColumnNumber ( isSgLocatedNode(astNode) )); cout << "The filename is:" << ROSE::getFileName(isSgLocatedNode(astNode)) << endl; typedef SgInitializedNamePtrList::iterator LI; for ( LI i = sageInitializedNameList.begin(); i != sageInitializedNameList.end(); ++i) { SgType* sageElementType = i->get_type(); ROSE_ASSERT( sageElementType != NULL); cout << "The class name is: " << sageElementType->sage_class_name() << endl; returnNodeList.push_back( sageElementType ); } cout << endl << "End printout of this Initialized Name list" << endl; } */ // SgVarRefExp *sageVarRefExp = isSgVarRefExp (astNode); switch (astNode->variantT ()) { case V_SgVariableDeclaration: { SgVariableDeclaration *sageVariableDeclaration = isSgVariableDeclaration (astNode); ROSE_ASSERT (sageVariableDeclaration != NULL); SgInitializedNamePtrList sageInitializedNameList = sageVariableDeclaration->get_variables (); #if DEBUG_NODEQUERY printf ("\nIn filename: %s ", ROSE::getFileName (isSgLocatedNode (astNode))); printf ("\nHere is a variable :Line = %d Columns = %d \n", ROSE::getLineNumber (isSgLocatedNode (astNode)), ROSE::getColumnNumber (isSgLocatedNode (astNode))); //cout << "The typename of the variable is: " << typeName << endl; #endif typedef SgInitializedNamePtrList::iterator variableIterator; SgType *typeNode; for (variableIterator variableListElement = sageInitializedNameList.begin (); variableListElement != sageInitializedNameList.end (); ++variableListElement) { SgInitializedName* elmVar = *variableListElement; ROSE_ASSERT (elmVar != NULL); typeNode = elmVar->get_type (); ROSE_ASSERT (typeNode != NULL); returnNodeList.push_back (typeNode); } break; } /* End case V_SgVariableDeclaration */ case V_SgFunctionDeclaration: case V_SgMemberFunctionDeclaration: { SgFunctionDeclaration * sageFunctionDeclaration = isSgFunctionDeclaration (astNode); ROSE_ASSERT (sageFunctionDeclaration != NULL); SgInitializedNamePtrList sageInitializedNameList = sageFunctionDeclaration->get_args (); SgType *typeNode; typedef SgInitializedNamePtrList::iterator variableIterator; for (variableIterator variableListElement = sageInitializedNameList.begin (); variableListElement != sageInitializedNameList.end (); ++variableListElement) { SgInitializedName* elmVar = *variableListElement; ROSE_ASSERT (elmVar != NULL); typeNode = elmVar->get_type (); ROSE_ASSERT (typeNode != NULL); returnNodeList.push_back (typeNode); } break; } default: { // DQ (8/20/2005): Added default to avoid compiler warnings about unrepresented cases } } /* End switch case astNode */ return returnNodeList; } /* End function querySolverType() */
StructLayoutInfo NonpackedTypeLayoutGenerator::layoutType(SgType* t) const { switch (t->variantT()) { case V_SgClassType: { // Also covers structs and unions SgClassDeclaration* decl = isSgClassDeclaration(isSgClassType(t)->get_declaration()); ROSE_ASSERT (decl); decl = isSgClassDeclaration(decl->get_definingDeclaration()); ROSE_ASSERT (decl); SgClassDefinition* def = decl->get_definition(); ROSE_ASSERT (def); StructLayoutInfo layout; size_t currentOffset = 0; const SgBaseClassPtrList& bases = def->get_inheritances(); for (SgBaseClassPtrList::const_iterator i = bases.begin(); i != bases.end(); ++i) { SgBaseClass* base = *i; SgClassDeclaration* basecls = base->get_base_class(); layoutOneField(basecls->get_type(), base, false, currentOffset, layout); } const SgDeclarationStatementPtrList& body = def->get_members(); bool isUnion = (decl->get_class_type() == SgClassDeclaration::e_union); for (SgDeclarationStatementPtrList::const_iterator i = body.begin(); i != body.end(); ++i) { SgDeclarationStatement* mem = *i; SgVariableDeclaration* vardecl = isSgVariableDeclaration(mem); SgClassDeclaration* classdecl = isSgClassDeclaration(mem); bool isUnnamedUnion = classdecl ? classdecl->get_isUnNamed() : false; if (vardecl) { if (!vardecl->get_declarationModifier().isDefault()) continue; // Static fields and friends ROSE_ASSERT (!vardecl->get_bitfield()); const SgInitializedNamePtrList& vars = isSgVariableDeclaration(mem)->get_variables(); for (SgInitializedNamePtrList::const_iterator j = vars.begin(); j != vars.end(); ++j) { SgInitializedName* var = *j; layoutOneField(var->get_type(), var, isUnion, currentOffset, layout); } } else if (isUnnamedUnion) { layoutOneField(classdecl->get_type(), classdecl, isUnion, currentOffset, layout); } // else continue; } if (layout.alignment != 0 && layout.size % layout.alignment != 0) { size_t paddingNeeded = layout.alignment - (layout.size % layout.alignment); if (!isUnion) { layout.fields.push_back(StructLayoutEntry(NULL, layout.size, paddingNeeded)); } layout.size += paddingNeeded; } return layout; } case V_SgArrayType: { StructLayoutInfo layout = this->beginning->layoutType(isSgArrayType(t)->get_base_type()); layout.fields.clear(); SgExpression* numElements = isSgArrayType(t)->get_index(); //Adjustment for UPC array like a[100*THREADS],treat it as a[100] // Liao, 8/7/2008 if (isUpcArrayWithThreads(isSgArrayType(t))) { SgMultiplyOp* multiply = isSgMultiplyOp(isSgArrayType(t)->get_index()); ROSE_ASSERT(multiply); // DQ (9/26/2011): Do constant folding if required. // SageInterface::constantFolding(multiply); numElements = multiply->get_lhs_operand(); } if (!isSgValueExp(numElements)) { cerr << "Error: trying to compute static size of an array with non-constant size" << endl; abort(); } layout.size *= SageInterface::getIntegerConstantValue(isSgValueExp(numElements)); return layout; } case V_SgTypeComplex: { //"Each complex type has the same representation and alignment requirements as //an array type containing exactly two elements of the corresponding real type" StructLayoutInfo layout = this->beginning->layoutType(isSgTypeComplex(t)->get_base_type()); layout.size *= 2; return layout; } case V_SgTypeImaginary: { StructLayoutInfo layout = this->beginning->layoutType(isSgTypeImaginary(t)->get_base_type()); return layout; } default: return ChainableTypeLayoutGenerator::layoutType(t); } }