3#include "markLhsValues.h"
5#include "FileUtility.h"
6#include <Sawyer/Message.h>
8#include "AstJSONGeneration.h"
10#include "SgNodeHelper.h"
12#include "Rose/AST/Utility.h"
14#include "sageInterface.h"
15#include "Combinatorics.h"
18#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
19#include "replaceExpressionWithStatement.h"
21#include "constantFolding.h"
28#include "sageBuilder.h"
34#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
37#include "AstInterface_ROSE.h"
38#include "LoopTransformInterface.h"
40#include "DepInfoAnal.h"
41#include "ArrayAnnot.h"
42#include "ArrayInterface.h"
44#include "LoopUnroll.h"
45#include "abstract_handle.h"
46#include "roseAdapter.h"
49#include <boost/lexical_cast.hpp>
50#include <boost/foreach.hpp>
56#include <unordered_map>
58#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
66 extern jclass currentJavaTraversalClass;
67 extern JNIEnv *currentEnvironment;
68 extern jmethodID mainMethod;
69 extern jmethodID hasConflictsMethod;
70 extern jmethodID getTempDirectoryMethod;
71 extern jmethodID createTempFileMethod;
72 extern jmethodID createTempNamedFileMethod;
73 extern jmethodID createTempNamedDirectoryMethod;
80using namespace Rose::Frontend::Java::Ecj;
86namespace EDG_ROSE_Translation
89#if defined(ROSE_BUILD_CXX_LANGUAGE_SUPPORT) && !defined(ROSE_USE_CLANG_FRONTEND)
91 extern std::map<std::string, SgIncludeFile*> edg_include_file_map;
94 std::map<std::string, SgIncludeFile*> edg_include_file_map;
101#include "detectMacroOrIncludeFileExpansions.h"
104 template<
class T>
void setSourcePositionToDefault( T* node );
108#ifdef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
109 #include "transformationSupport.h"
113#include "rose_config.h"
119#include "AST_FILE_IO.h"
124#define OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS 1
134typedef std::set<SgLabelStatement*> SgLabelStatementPtrSet;
153 vector<SgBasicBlock*> addedBasicBlockNodes;
170 std::vector<SgNode*> resultlist;
171 void visit (
SgNode* node)
174 ROSE_ASSERT(result != NULL);
176 printf (
"In SageInterface::deleteAllNodes(): result = %p = %s \n",result,result->
class_name().c_str());
181 resultlist.push_back(result);
184 resultlist.push_back(result);
188 virtual ~MyTraversal() {}
192 size_t numberOfNodes_before = numberOfNodes();
194 MyTraversal my_traversal;
198 my_traversal.traverseMemoryPool();
204 vector<SgNode*> & nodeList = my_traversal.resultlist;
206 printf (
"In SageInterface::deleteAllNodes(): get list of SgNode: nodeList.size() = %zu \n",nodeList.size());
208 vector<SgNode*>::iterator i = nodeList.begin();
211 while (i != nodeList.end())
217 printf (
" --- calling delete (and thus the destructor) node = %p = %s \n",node,node->
class_name().c_str());
227 vector<SgFunctionDeclaration*> functionDeclarationList = getSgNodeListFromMemoryPool<SgFunctionDeclaration>();
228 printf (
"In SageInterface::deleteAllNodes(): get list of SgFunctionDeclaration: functionDeclarationList.size() = %zu \n",functionDeclarationList.size());
232 AST_FILE_IO::clearAllMemoryPools();
234 size_t numberOfNodes_after = numberOfNodes();
237 printf (
"Leaving SageInterface::deleteAllNodes(): numberOfNodes_before = %zu numberOfNodes_after = %zu \n",numberOfNodes_before,numberOfNodes_after);
266 void visit (
SgNode* node)
273 resultlist.push_back(result);
276 virtual ~MyTraversal() {}
280 size_t numberOfNodes_before = numberOfNodes();
282 MyTraversal my_traversal;
286 my_traversal.traverseMemoryPool();
295 ASSERT_not_null(decl);
298 printf (
"TOP of SageInterface::DeclarationSets::addDeclaration(): decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
303 if (firstNondefiningDeclaration ==
nullptr)
307 printf (
"WARNING: SageInterface::DeclarationSets::addDeclaration(): firstNondefiningDeclaration == NULL: decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
311 ASSERT_not_null(firstNondefiningDeclaration);
313 if (decl == firstNondefiningDeclaration)
316 if (isSgTypedefDeclaration(decl) !=
nullptr)
318 printf (
"TOP of SageInterface::DeclarationSets::addDeclaration(): decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
321 if (declarationMap.find(firstNondefiningDeclaration) == declarationMap.end())
324 printf (
"In SageInterface::DeclarationSets::addDeclaration(): Add a set for decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
327 if (isSgTypedefDeclaration(decl) !=
nullptr)
329 printf (
"In SageInterface::DeclarationSets::addDeclaration(): Add a set for decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
333 declarationMap[decl] =
new set<SgDeclarationStatement*>();
335 ROSE_ASSERT (declarationMap.find(firstNondefiningDeclaration) != declarationMap.end());
336 ROSE_ASSERT(declarationMap[decl] !=
nullptr);
339 declarationMap[firstNondefiningDeclaration]->insert(decl);
343 if (declarationMap[firstNondefiningDeclaration]->find(decl) == declarationMap[firstNondefiningDeclaration]->end())
346 printf (
"In SageInterface::DeclarationSets::addDeclaration(): Add the declaration to the existing set: decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
349 if (isSgTypedefDeclaration(decl) !=
nullptr)
351 printf (
"In SageInterface::DeclarationSets::addDeclaration(): Add the declaration to the existing set: decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
355 declarationMap[firstNondefiningDeclaration]->insert(decl);
360 printf (
"WARNING: SageInterface::DeclarationSets::addDeclaration(): A set already exists for decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
364 bool ignore_error = (isSgFunctionParameterList(decl) !=
nullptr);
375 bool isInTemplateFunctionDeclaration = enclosingFunction !=
nullptr && (isSgTemplateMemberFunctionDeclaration(enclosingFunction) || isSgTemplateFunctionDeclaration(enclosingFunction));
379 bool isInTemplateClassDefinition = enclosingClassDefinition !=
nullptr && isSgTemplateClassDefinition(enclosingClassDefinition);
381 bool isInTemplateDeclaration = isInTemplateFunctionDeclaration || isInTemplateClassDefinition;
383 ignore_error = ignore_error || (isSgTypedefDeclaration(decl) !=
nullptr) || (isSgTemplateInstantiationDecl(decl) !=
nullptr) || (isInTemplateDeclaration ==
true);
388 if (isSgClassDeclaration(decl) !=
nullptr)
390 ignore_error = ignore_error || (isSgClassDeclaration(decl)->get_isUnNamed() ==
true);
398 if (declarationMap.find(firstNondefiningDeclaration) != declarationMap.end())
401 ROSE_ASSERT (declarationMap[firstNondefiningDeclaration] !=
nullptr);
402 if (declarationMap[firstNondefiningDeclaration]->find(decl) == declarationMap[firstNondefiningDeclaration]->end())
405 declarationMap[firstNondefiningDeclaration]->insert(decl);
410 printf (
"This declaration is already in the set (skip adding it twice): decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
419 printf (
"In SageInterface::DeclarationSets::addDeclaration(): Adding set and declaration for the firstNondefiningDeclaration = %p = %s = %s \n",
420 firstNondefiningDeclaration,firstNondefiningDeclaration->
class_name().c_str(),
get_name(firstNondefiningDeclaration).c_str());
427 declarationMap[firstNondefiningDeclaration] =
new set<SgDeclarationStatement*>();
429 ROSE_ASSERT (declarationMap.find(firstNondefiningDeclaration) != declarationMap.end());
433 declarationMap[firstNondefiningDeclaration]->insert(decl);
436 ROSE_ASSERT(declarationMap[firstNondefiningDeclaration]->find(decl) != declarationMap[firstNondefiningDeclaration]->end());
438 printf (
"SageInterface::DeclarationSets::addDeclaration(): No set exists for the firstNondefiningDeclaration = %p = %s = %s \n",firstNondefiningDeclaration,firstNondefiningDeclaration->
class_name().c_str(),
get_name(firstNondefiningDeclaration).c_str());
445 printf (
"Leaving SageInterface::DeclarationSets::addDeclaration(): decl = %p = %s = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
449const std::set<SgDeclarationStatement*>*
455 ROSE_ASSERT(declarationMap.find(firstNondefiningDeclaration) != declarationMap.end());
457 const set<SgDeclarationStatement*>* declarationSet = declarationMap[firstNondefiningDeclaration];
460 return declarationSet;
463std::map<SgDeclarationStatement*,std::set<SgDeclarationStatement*>* > &
464SageInterface::DeclarationSets::getDeclarationMap()
466 return declarationMap;
482#define DEBUG_LOCATED_IN_DEFINING_SCOPE 0
485 ROSE_ASSERT(firstNondefiningDeclaration !=
nullptr);
487 set<SgDeclarationStatement*>* declarationSet = declarationMap[firstNondefiningDeclaration];
488 ROSE_ASSERT(declarationSet !=
nullptr);
490 set<SgDeclarationStatement*>::iterator i = declarationSet->begin();
492 bool isDefinedInNamedScope =
false;
494#if DEBUG_LOCATED_IN_DEFINING_SCOPE
495 printf (
"In DeclarationSets::isLocatedInDefiningScope(): decl = %p = %s \n",decl,decl->
class_name().c_str());
496 printf (
" --- declarationSet->size() = %" PRIuPTR
" \n",declarationSet->size());
499 while (isDefinedInNamedScope ==
false && i != declarationSet->end())
501 ROSE_ASSERT(*i !=
nullptr);
502#if DEBUG_LOCATED_IN_DEFINING_SCOPE
503 printf (
" --- *i = %p = %s \n",*i,(*i)->class_name().c_str());
507 SgScopeStatement* structural_scope = isSgScopeStatement((*i)->get_parent());
509#if DEBUG_LOCATED_IN_DEFINING_SCOPE
510 printf (
" --- semantic_scope = %p = %s \n",semantic_scope,semantic_scope->
class_name().c_str());
511 printf (
" --- structural_scope = %p = %s \n",structural_scope,structural_scope->
class_name().c_str());
514 SgScopeStatement* scope = isSgClassDefinition(semantic_scope) !=
nullptr ? semantic_scope : structural_scope;
515 ASSERT_not_null(scope);
517#if DEBUG_LOCATED_IN_DEFINING_SCOPE
518 printf (
" --- scope = %p = %s \n",scope,scope->
class_name().c_str());
519 printf (
" --- scope->isNamedScope() = %s \n",scope->
isNamedScope() ?
"true" :
"false");
521 SgGlobal* globalScope = isSgGlobal(scope);
524 if (globalScope !=
nullptr || (scope->
isNamedScope() ==
true && isSgClassDefinition(structural_scope) ==
nullptr) )
527 bool willBeOutput = ((*i)->get_file_info()->isCompilerGenerated() ==
false ||
528 ((*i)->get_file_info()->isCompilerGenerated() &&
529 (*i)->get_file_info()->isOutputInCodeGeneration()) );
530#if DEBUG_LOCATED_IN_DEFINING_SCOPE
531 printf (
" --- before: willBeOutput = %s \n",willBeOutput ?
"true" :
"false");
534 willBeOutput = willBeOutput && scope == structural_scope;
536#if DEBUG_LOCATED_IN_DEFINING_SCOPE
537 printf (
" --- after: willBeOutput = %s \n",willBeOutput ?
"true" :
"false");
543 isDefinedInNamedScope = willBeOutput;
549#if DEBUG_LOCATED_IN_DEFINING_SCOPE
550 if (associatedDeclaration !=
nullptr)
552 printf (
"Leaving DeclarationSets::isLocatedInDefiningScope(): associatedDeclaration = %p = %s \n",associatedDeclaration,
associatedDeclaration->
class_name().c_str());
556 printf (
"Leaving DeclarationSets::isLocatedInDefiningScope(): associatedDeclaration = %p \n",associatedDeclaration);
560 return isDefinedInNamedScope;
564SageInterface::buildDeclarationSets(
SgNode* n)
566 DeclarationSets* declarationSet =
new DeclarationSets();
571 DeclarationSets* declarationSet;
574 DeclarationSetTraversal(DeclarationSets* ds) : declarationSet(ds) {}
580 declarationSet->addDeclaration(decl);
586 DeclarationSetTraversal traversal(declarationSet);
587 traversal.traverse(n, preorder);
589 return declarationSet;
596string getVariantName ( VariantT v )
598 ROSE_ASSERT(
int(v) <
int(V_SgNumVariants));
605 extern const char* roseGlobalVariantNameList[];
606 return string(roseGlobalVariantNameList[v]);
613 bool usingTemplateSyntax =
false;
614 string nameString = name.getString();
617 usingTemplateSyntax = (nameString.find(
'<') != string::npos) && (nameString.find(
'>') != string::npos);
621 if (nameString ==
"<unnamed>")
623 printf (
"In SageInterface::hasTemplateSyntax(): Identified case of name == <unnamed> \n");
625 usingTemplateSyntax =
false;
629 return usingTemplateSyntax;
641 ROSE_ASSERT(node != NULL);
645 ROSE_ASSERT(isSgFile(node) == NULL);
646 ROSE_ASSERT(isSgFileList(node) == NULL);
647 ROSE_ASSERT(isSgProject(node) == NULL);
652 while (parent !=
nullptr && isSgFileList(parent) ==
nullptr)
656 printf (
"--- parent = %p = %s \n",parent,parent->
class_name().c_str());
659 parent->
get_file_info()->display(
"In SageInterface::whereAmI() diagnostics support");
686 ifstmt->setCaseInsensitive(
true);
689 if (conditional) conditional->
set_parent(ifstmt);
691 if (false_body) false_body->
set_parent(ifstmt);
698 ROSE_ASSERT(switchStatement != NULL);
702 switchStatement->setCaseInsensitive(
true);
707 if (switchStatement->
get_body() ==
nullptr)
711 if (item_selector !=
nullptr)
721 ROSE_ASSERT(whileStatement);
725 whileStatement->setCaseInsensitive(
true);
729 if (whileStatement->
get_body() ==
nullptr)
733 if (whileStatement->get_else_body() ==
nullptr)
734 whileStatement->set_else_body(else_body);
737 if (condition) condition->
set_parent(whileStatement);
741 if (else_body !=
nullptr)
743 whileStatement->set_else_body(else_body);
764 ROSE_ASSERT(declaration != NULL);
768 while ( isSgNamespaceDefinitionStatement(tempScope) ==
nullptr && isSgGlobal(tempScope) ==
nullptr )
771 ROSE_ASSERT(tempScope != NULL);
778 return namespaceScope;
792 ASSERT_not_null(defn);
796 ASSERT_not_null(templateDeclaration);
802 if (templateInstatiationClassDefinition !=
nullptr)
806 ASSERT_not_null(parentTemplateInstantiationDefinition);
808 ASSERT_not_null(parentTemplateInstantiationDeclaration);
811 ASSERT_not_null(parentDeclaration);
813 else if (cdefn !=
nullptr)
817 ASSERT_not_null(parentDeclaration);
819 else if (nrscope !=
nullptr)
821 parentDeclaration = isSgDeclarationStatement(nrscope->
get_parent());
822 ASSERT_not_null(parentDeclaration);
829 return parentDeclaration;
838 ASSERT_not_null(var_decl);
839 ASSERT_not_null(base_decl);
853 if (find(stmt_list.begin(), stmt_list.end(), base_decl) != stmt_list.end())
858 var_decl->set_baseTypeDefiningDeclaration(base_decl);
864 t1.traverseMemoryPool();
873 bool foundExistingPrototype =
false;
875 ROSE_ASSERT(scope != NULL);
876 ROSE_ASSERT(functionDeclaration != NULL);
877 ROSE_ASSERT(startingAtDeclaration != NULL);
880 if (isSgDeclarationScope(scope)) {
881 printf(
"TODO: SgDeclarationScope handling in SageInterface::isPrototypeInScope see ROSE-1378\n");
892 SgDeclarationStatementPtrList::iterator startingLocation = find(declarationList.begin(),declarationList.end(),startingAtDeclaration);
894 if (startingLocation != declarationList.end())
897 printf (
"startingLocation = %p = %s = %s \n",*startingLocation,(*startingLocation)->class_name().c_str(),
SageInterface::get_name(*startingLocation).c_str());
900 SgDeclarationStatementPtrList::iterator i = startingLocation;
902 SgName targetName = functionDeclaration->get_name();
904 while (i != declarationList.end())
910 if (templateMemberFunction !=
nullptr)
913 if (targetScope == templateMemberFunction->
get_scope())
915 if (targetName == templateMemberFunction->get_name())
918 if (templateMemberFunction->
isForward() ==
true)
920 foundExistingPrototype =
true;
933 return foundExistingPrototype;
939 ROSE_ASSERT(node1 && node2);
949 }
while( (curnode!=
nullptr) && (curnode!=node1));
966#define DEBUG_HAS_SAME_SCOPE 0
968#if DEBUG_HAS_SAME_SCOPE
969 printf (
"In SageInterface::hasSameGlobalScope(): \n");
970 printf (
" --- statement_1 = %p = %s \n",statement_1,statement_1->
class_name().c_str());
971 printf (
" --- statement_2 = %p = %s \n",statement_2,statement_2->
class_name().c_str());
974 bool includingSelf =
true;
975 SgGlobal* global_scope_1 = getEnclosingNode<SgGlobal>(statement_1,includingSelf);
976 SgGlobal* global_scope_2 = getEnclosingNode<SgGlobal>(statement_2,includingSelf);
978#if DEBUG_HAS_SAME_SCOPE
979 printf (
" --- global_scope_1 = %p = %s \n",global_scope_1,global_scope_1->
class_name().c_str());
981 printf (
" --- --- sourcefile_1 = %p filename = %s \n",sourcefile_1,sourcefile_1->
getFileName().c_str());
983 printf (
" --- global_scope_2 = %p = %s \n",global_scope_2,global_scope_2->
class_name().c_str());
985 printf (
" --- --- sourcefile_2 = %p filename = %s \n",sourcefile_2,sourcefile_2->
getFileName().c_str());
988 bool returnResult = (global_scope_1 == global_scope_2);
990#if DEBUG_HAS_SAME_SCOPE
991 printf (
"Leaving SageInterface::hasSameGlobalScope(): returning: %s \n",returnResult ?
"true" :
"false");
1001 std::vector<SgNode*> intersectionSet;
1004 std::vector<SgNode*> AST_original = NodeQuery::querySubTree (original,V_SgNode);
1005 std::vector<SgNode*> AST_copy = NodeQuery::querySubTree (copy,V_SgNode);
1007 int AST_original_size = AST_original.size();
1008 int AST_copy_size = AST_copy.size();
1012 printf (
"Original AST size = %d \n",AST_original_size);
1013 printf (
"Copy of original AST size = %d \n",AST_copy_size);
1016 int differenceInSizes = AST_original_size - AST_copy_size;
1017 if (differenceInSizes == 0)
1020 printf (
"Copied AST is the SAME size as the original (size = %d) \n",AST_original_size);
1024 printf (
"Warning: Copied AST and the original are DIFFERENT sizes (original size = %d copyied size = %d) \n",AST_original_size,AST_copy_size);
1029 std::set<SgNode*> AST_set_original;
1030 for (
int i = 0; i < AST_original_size; i++)
1032 AST_set_original.insert(AST_original[i]);
1035 std::set<SgNode*> AST_set_copy;
1036 for (
int i = 0; i < AST_copy_size; i++)
1038 AST_set_copy.insert(AST_copy[i]);
1041 int size = AST_original_size;
1042 std::vector<SgNode*> intersectionList(size);
1045 std::vector<SgNode*>::iterator end = set_intersection(AST_set_original.begin(),AST_set_original.end(),AST_set_copy.begin(),AST_set_copy.end(),intersectionList.begin());
1048 std::vector<SgNode*> meaningIntersectionList = std::vector<SgNode*>(intersectionList.begin(),end);
1049 std::vector<SgNode*> deleteList;
1050 for (
int i = 0; i < (int)meaningIntersectionList.size(); i++)
1052 if (meaningIntersectionList[i] !=
nullptr && isSgType(meaningIntersectionList[i]) !=
nullptr)
1054 deleteList.push_back(meaningIntersectionList[i]);
1060 printf (
"Remove the types that are allowed to be shared: deleteList.size() = %ld \n",(
long)deleteList.size());
1062 for (std::vector<SgNode*>::iterator i = deleteList.begin(); i != deleteList.end(); i++)
1064 meaningIntersectionList.erase(find(meaningIntersectionList.begin(),meaningIntersectionList.end(),*i));
1068 printf (
"After removing the types there are meaningIntersectionList.size() = %ld \n",(
long)meaningIntersectionList.size());
1070 for (
int i = 0; i < (int)meaningIntersectionList.size(); i++)
1072 printf (
" meaningIntersectionList[%d] = %p = %s = %s \n",i,meaningIntersectionList[i],meaningIntersectionList[i]->class_name().c_str(),
get_name(meaningIntersectionList[i]).c_str());
1075 int unmatchedIRnodes = 0;
1076 if (help !=
nullptr)
1078 std::vector<SgNode*> tmp_AST_original;
1079 std::vector<SgNode*> tmp_AST_copy;
1081 int AST_original_size = AST_original.size();
1082 for (
int j = 0; j < AST_original_size; j++)
1084 if (AST_original[j] != NULL && isSgType(AST_original[j]) == NULL)
1086 tmp_AST_original.push_back(AST_original[j]);
1090 int AST_copy_size = AST_copy.size();
1091 for (
int j = 0; j < AST_copy_size; j++)
1093 if (AST_copy[j] != NULL && isSgType(AST_copy[j]) == NULL)
1095 tmp_AST_copy.push_back(AST_copy[j]);
1099 std::vector<SgNode*> deleteList_original;
1100 std::vector<SgNode*> deleteList_copy;
1101 for (
int j = 0; j < (int)tmp_AST_original.size(); j++)
1104 SgCopyHelp::copiedNodeMapTypeIterator i = help->get_copiedNodeMap().find(tmp_AST_original[j]);
1106 if (i != help->get_copiedNodeMap().end())
1109 SgNode* associated_node_copy = i->second;
1110 ROSE_ASSERT(associated_node_copy != NULL);
1111 deleteList_original.push_back(tmp_AST_original[j]);
1112 deleteList_copy.push_back(associated_node_copy);
1117 if (templateMemberFunction != NULL)
1119 printf (
"In SageInterface::astIntersection(): Found a SgTemplateInstantiationMemberFunctionDecl = %p copy = %p \n",templateMemberFunction,associated_node_copy);
1127 int deleteList_original_size = deleteList_original.size();
1128 for (
int j = 0; j < deleteList_original_size; j++)
1131 std::vector<SgNode*>::iterator k = find(tmp_AST_original.begin(),tmp_AST_original.end(),deleteList_original[j]);
1132 if (k != tmp_AST_original.end())
1134 tmp_AST_original.erase(k);
1139 printf (
"IR nodes different between the original AST and the copy of the AST = %" PRIuPTR
" \n",tmp_AST_original.size());
1141 for (
int j = 0; j < (int)tmp_AST_original.size(); j++)
1143 printf (
"non matched IR node = %p = %s = %s \n",tmp_AST_original[j],tmp_AST_original[j]->class_name().c_str(),
get_name(tmp_AST_original[j]).c_str());
1147 unmatchedIRnodes = (int)tmp_AST_original.size();
1151 if (differenceInSizes != 0)
1153 SgProject* originalProject = isSgProject(original);
1154 if (originalProject != NULL)
1156 printf (
"In %s Copied AST and the original are DIFFERENT sizes (original size = %d copyied size = %d) IR nodes different = %d \n",
1157 (*originalProject)[0]->get_sourceFileNameWithoutPath().c_str(),AST_original_size,AST_copy_size,unmatchedIRnodes);
1160 if (unmatchedIRnodes > 0)
1162 printf (
"Make this an error under stricter testing \n");
1167 return intersectionSet;
1177 ROSE_ASSERT(initializedNameNode != NULL);
1179#define DEBUG_SET_NAME 0
1183 printf (
"In SageInterface::set_name(): initializedNameNode = %p name = %s new_name = %s \n",initializedNameNode,initializedNameNode->get_name().str(),new_name.str());
1190 while((node!=NULL) && ( isSgScopeStatement(node)==NULL))
1193 ROSE_ASSERT(node!=NULL);
1201 if (isSgEnumDeclaration(initializedNameNode->
get_parent()) != NULL)
1203 ROSE_ASSERT(scope_stmt != NULL);
1204 printf (
"scope_stmt = %p = %s \n",scope_stmt,scope_stmt->
class_name().c_str());
1206 printf (
"Detected isSgEnumDeclaration as parent: exiting as a test in SageInterface::set_name() \n");
1211 ROSE_ASSERT(scope_stmt != NULL);
1217 ROSE_ASSERT(parent_declaration != NULL);
1220 std::pair<SgSymbolTable::hash_iterator,SgSymbolTable::hash_iterator> pair_it = scope_stmt->
get_symbol_table()->get_table()->equal_range(initializedNameNode->get_name());
1222 SgSymbolTable::hash_iterator found_it = scope_stmt->
get_symbol_table()->get_table()->end();
1224 for (SgSymbolTable::hash_iterator it = pair_it.first; it != pair_it.second; ++it)
1227 printf (
"Looking for symbol in scope = %p = %s \n",scope_stmt,scope_stmt->
class_name().c_str());
1228 printf (
" --- *it = %p = %s \n",(*it).second,(*it).second->class_name().c_str());
1230 switch(parent_declaration->
variantT())
1232 case V_SgFunctionParameterList:
1233 case V_SgVariableDeclaration:
1235 if (isSgVariableSymbol((*it).second) != NULL)
1240 case V_SgClassDeclaration:
1242 if (isSgClassSymbol((*it).second) != NULL)
1247 case V_SgFunctionDeclaration:
1249 if (isSgFunctionSymbol((*it).second) != NULL)
1255 case V_SgEnumDeclaration:
1257 if (isSgEnumFieldSymbol((*it).second) != NULL)
1264 printf (
"Default reached in switch in SageInterface::set_name() \n");
1272 printf (
"Warning: There is no Variable, Class, Function, or EnumValue symbol associated with p_name \n");
1279 printf (
"WARNING: SageInterface::set_name(): This statement can not be transformed because it is part of a header file specific more then once with different include file syntax \n");
1285 printf (
"In SageInterface::set_name(): This statement can be transformed! parent_declaration = %p = %s \n",parent_declaration,
get_name(parent_declaration).c_str());
1290 printf (
"Exiting as a test! \n");
1295 SgSymbol * associated_symbol = (*found_it).second;
1310 found_it = scope_stmt->
get_symbol_table()->get_table()->insert(pair<SgName,SgSymbol*> ( new_name,associated_symbol));
1312 found_it = scope_stmt->
get_symbol_table()->get_table()->insert(pair<SgName,SgSymbol*> ( new_name,associated_symbol));
1317 printf (
"Warning: insertion of new symbol failed \n");
1323 printf (
"Reset initializedNameNode->get_name() = %s to new_name = %s \n",initializedNameNode->get_name().str(),new_name.str());
1327 initializedNameNode->set_name(new_name);
1332 ROSE_ASSERT(enclosingStatement != NULL);
1348 void visit (
SgNode* node)
1353 ROSE_ASSERT(varRefExp != NULL);
1354 ROSE_ASSERT(variableSymbol != NULL);
1356 if (varRefExp->get_symbol() == variableSymbol)
1359 printf (
"In SageInterface::set_name(): Found associated SgVarRefExp varRefExp = %p to symbol associated_symbol = %p \n",varRefExp,variableSymbol);
1362 printf (
"Exiting as a test! \n");
1373 printf (
"In SageInterface::set_name(): When unparsing header files, we need to set the physical file id to the correct file \n");
1378 ROSE_ASSERT(associatedStatement != NULL);
1384 ROSE_ASSERT(associatedStatement != NULL);
1392 RoseVisitor(
SgSymbol* symbol_parmeter) : counter(0), symbol(symbol_parmeter)
1395 printf (
"roseVisitor::visit: counter %4d node = %s \n",counter,symbol_parmeter->
class_name().c_str());
1403 RoseVisitor t1(associated_symbol);
1408 printf (
"Leaving SageInterface::set_name(): initializedNameNode = %p name = %s new_name = %s (return 1) \n",initializedNameNode,initializedNameNode->get_name().str(),new_name.str());
1420 printf (
"In SageInterface::listHeaderFiles(): includeFile filename = %s \n",includeFile->get_filename().str());
1426 void visit (
SgNode* node)
1428 printf (
"In listHeaderFiles visit(): node = %p = %s \n",node,node->
class_name().c_str());
1430 if (includeFile != NULL)
1432 printf (
"include file: filename = %s \n",includeFile->get_filename().str());
1438 PrefixTraversal traversal;
1439 traversal.traverse(includeFile, preorder);
1458 ROSE_ASSERT(scope != NULL);
1459 int scope_file_id = scope->
get_file_info()->get_physical_file_id();
1461 bool return_value =
false;
1465 SgDeclarationStatementPtrList & declarationStatementList = scope->
getDeclarationList();
1467 printf (
"In scopeHasStatementsFromSameFile(): DeclarationStatementList not implemented \n");
1470 printf (
"declarationStatementList.size() = %zu \n",declarationStatementList.size());
1472 SgDeclarationStatementPtrList::iterator i = declarationStatementList.begin();
1474 while (i != declarationStatementList.end() && return_value ==
false)
1477 int statement_file_id = statement->
get_file_info()->get_physical_file_id();
1479 if (statement_file_id == scope_file_id)
1481 return_value =
true;
1487 printf (
"Exiting as a test! \n");
1495 printf (
"In scopeHasStatementsFromSameFile(): StatementList not implemented \n");
1497 SgStatementPtrList::iterator i = statementList.begin();
1499 while (i != statementList.end() && return_value ==
false)
1502 int statement_file_id = statement->
get_file_info()->get_physical_file_id();
1504 if (statement_file_id == scope_file_id)
1506 return_value =
true;
1513 return return_value;
1519 template <
class SageDecl>
1520 std::string genericGetName(SageDecl* dcl)
1523 return dcl->get_name();
1533 string name =
"undefined_name";
1535 ROSE_ASSERT(directive != NULL);
1544 case V_SgIncludeDirectiveStatement:
1545 case V_SgDefineDirectiveStatement:
1546 case V_SgUndefDirectiveStatement:
1547 case V_SgIfdefDirectiveStatement:
1548 case V_SgIfndefDirectiveStatement:
1549 case V_SgDeadIfDirectiveStatement:
1550 case V_SgIfDirectiveStatement:
1551 case V_SgElseDirectiveStatement:
1552 case V_SgElseifDirectiveStatement:
1553 case V_SgLineDirectiveStatement:
1554 case V_SgWarningDirectiveStatement:
1555 case V_SgErrorDirectiveStatement:
1556 case V_SgEmptyDirectiveStatement:
1563 case V_SgClinkageStartStatement:
1564 case V_SgClinkageEndStatement:
1570 case V_SgFortranIncludeLine:
1578 printf (
"Warning: default case reached in SageInterface::get_name ( const SgC_PreprocessorDirectiveStatement* directive ), directive = %p = %s \n",
1582 name =
"directive_default_name_case_reached_not_handled";
1594 string name =
"undefined_name";
1596 ROSE_ASSERT(declaration != NULL);
1600 if (directive != NULL)
1607 case V_SgTemplateMemberFunctionDeclaration:
1608 name = isSgTemplateMemberFunctionDeclaration(declaration)->get_name().str();
1611 case V_SgTemplateFunctionDeclaration:
1612 name = isSgTemplateFunctionDeclaration(declaration)->get_name().str();
1615 case V_SgTemplateClassDeclaration:
1616 name = isSgTemplateClassDeclaration(declaration)->get_name().str();
1619 case V_SgTemplateDeclaration:
1620 name = isSgTemplateDeclaration(declaration)->
get_name().str();
1623 case V_SgTemplateInstantiationDecl:
1624 name = isSgTemplateInstantiationDecl(declaration)->
get_templateName().str();
1627 case V_SgClassDeclaration:
1628 case V_SgDerivedTypeStatement:
1629 case V_SgJovialTableStatement:
1630 name = isSgClassDeclaration(declaration)->get_name().str();
1635 case V_SgJovialDefineDeclaration:
1636 case V_SgJovialDirectiveStatement:
1637 case V_SgJovialCompoolStatement:
1638 name =
"__" + declaration->
class_name() +
"_";
1642 case V_SgJovialLabelDeclaration:
1643 name = isSgJovialLabelDeclaration(declaration)->get_label();
1646 case V_SgEnumDeclaration:
1647 name = isSgEnumDeclaration(declaration)->
get_name().str();
1651 case V_SgTemplateInstantiationTypedefDeclaration:
1653 case V_SgTemplateTypedefDeclaration:
1654 case V_SgTypedefDeclaration:
1655 name = isSgTypedefDeclaration(declaration)->get_name().str();
1658 case V_SgFunctionDeclaration:
1659 case V_SgProgramHeaderStatement:
1660 case V_SgProcedureHeaderStatement:
1661 case V_SgMemberFunctionDeclaration:
1662 case V_SgTemplateInstantiationFunctionDecl:
1663 case V_SgTemplateInstantiationMemberFunctionDecl:
1664 case V_SgAdaFunctionRenamingDecl:
1665 case V_SgAdaEntryDecl:
1666 name = isSgFunctionDeclaration(declaration)->get_name().str();
1669 case V_SgNamespaceDeclarationStatement:
1670 name = isSgNamespaceDeclarationStatement(declaration)->
get_name().str();
1674 case V_SgFunctionParameterList:
1677 ROSE_ASSERT(declaration->
get_parent() != NULL);
1681 name =
get_name(functionDeclaration);
1689 name +=
"_parameter_list_";
1694 case V_SgTemplateVariableDeclaration:
1697 case V_SgVariableDeclaration:
1701 name =
"_variable_declaration_";
1703 ROSE_ASSERT(variableDeclaration != NULL);
1704 SgInitializedNamePtrList::const_iterator i = variableDeclaration->
get_variables().begin();
1707 ROSE_ASSERT(i != variableDeclaration->
get_variables().end());
1710 name += string((*i)->get_name().str());
1719 case V_SgVariableDefinition:
1723 name =
"_variable_definition_";
1725 ROSE_ASSERT(variableDefinition != NULL);
1728 ROSE_ASSERT(variableDefinition->
get_vardefn() != NULL);
1734 case V_SgPragmaDeclaration:
1736 name =
"_pragma_declaration_";
1738 ROSE_ASSERT(pragmaDeclaration != NULL);
1739 ROSE_ASSERT(pragmaDeclaration->get_pragma() != NULL);
1740 name +=
get_name(pragmaDeclaration->get_pragma());
1745 case V_SgUsingDirectiveStatement:
1747 name =
"_using_directive_statement_";
1749 ROSE_ASSERT(usingDeclaration != NULL);
1756 case V_SgNamespaceAliasDeclarationStatement:
1758 name =
"_namespace_alias_directive_statement_";
1760 ROSE_ASSERT(namespaceAliasDeclaration != NULL);
1761 ROSE_ASSERT(namespaceAliasDeclaration->
get_name().is_null() ==
false);
1762 name += namespaceAliasDeclaration->
get_name();
1767 case V_SgUsingDeclarationStatement:
1769 name =
"_using_declaration_statement_";
1771 ROSE_ASSERT(usingDeclaration != NULL);
1785 case V_SgTemplateInstantiationDirectiveStatement:
1787 name =
"_template_instantiation_directive_statement_";
1788 ROSE_ASSERT(declaration != NULL);
1790 ROSE_ASSERT(templateInstantiationDirective != NULL);
1791 ROSE_ASSERT(templateInstantiationDirective->
get_declaration() != NULL);
1799 case V_SgCtorInitializerList:
1801 name =
"_ctor_list_";
1803 ROSE_ASSERT(ctorDeclaration != NULL);
1804 ROSE_ASSERT(ctorDeclaration->
get_parent() != NULL);
1812 name =
"_asm_stmt_";
1813 const SgAsmStmt* asmStatement = isSgAsmStmt(declaration);
1814 ROSE_ASSERT(asmStatement != NULL);
1815 ROSE_ASSERT(asmStatement->
get_parent() != NULL);
1821 case V_SgImplicitStatement:
1823 name =
"_fortran_implicit_";
1825 ROSE_ASSERT(implicitStatement != NULL);
1826 ROSE_ASSERT(implicitStatement->
get_parent() != NULL);
1832 case V_SgNamelistStatement:
1834 name =
"_fortran_namelist_";
1836 ROSE_ASSERT(namelistStatement != NULL);
1837 ROSE_ASSERT(namelistStatement->
get_parent() != NULL);
1843 case V_SgEquivalenceStatement:
1845 name =
"_fortran_equivalence_";
1847 ROSE_ASSERT(equivalenceStatement != NULL);
1848 ROSE_ASSERT(equivalenceStatement->
get_parent() != NULL);
1855 case V_SgCommonBlock:
1857 name =
"_fortran_common_block_";
1858 const SgCommonBlock* commonBlockStatement = isSgCommonBlock(declaration);
1859 ROSE_ASSERT(commonBlockStatement != NULL);
1860 ROSE_ASSERT(commonBlockStatement->
get_parent() != NULL);
1866 case V_SgImportStatement:
1868 name =
"_fortran_import_stmt_";
1870 ROSE_ASSERT(importStatement != NULL);
1871 ROSE_ASSERT(importStatement->
get_parent() != NULL);
1877 case V_SgFormatStatement:
1879 name =
"_fortran_format_stmt_";
1881 ROSE_ASSERT(formatStatement != NULL);
1882 ROSE_ASSERT(formatStatement->
get_parent() != NULL);
1888 case V_SgModuleStatement:
1890 name =
"_fortran_module_stmt_";
1892 ROSE_ASSERT(moduleStatement != NULL);
1893 ROSE_ASSERT(moduleStatement->
get_parent() != NULL);
1899 case V_SgUseStatement:
1901 name =
"_fortran_use_stmt_";
1902 const SgUseStatement* useStatement = isSgUseStatement(declaration);
1903 ROSE_ASSERT(useStatement != NULL);
1904 ROSE_ASSERT(useStatement->
get_parent() != NULL);
1910 case V_SgContainsStatement:
1912 name =
"_fortran_contains_stmt_";
1914 ROSE_ASSERT(containsStatement != NULL);
1915 ROSE_ASSERT(containsStatement->
get_parent() != NULL);
1921 case V_SgEntryStatement:
1923 name =
"_fortran_entry_stmt_";
1925 ROSE_ASSERT(entryStatement != NULL);
1926 ROSE_ASSERT(entryStatement->
get_parent() != NULL);
1932 case V_SgAttributeSpecificationStatement:
1934 name =
"_fortran_attribute_specification_stmt_";
1936 ROSE_ASSERT(statement != NULL);
1937 ROSE_ASSERT(statement->
get_parent() != NULL);
1942 case V_SgInterfaceStatement:
1944 name =
"_fortran_interface_stmt_";
1946 ROSE_ASSERT(statement != NULL);
1947 ROSE_ASSERT(statement->
get_parent() != NULL);
1952 case V_SgFortranIncludeLine:
1954 name =
"_fortran_include_line_stmt_";
1956 ROSE_ASSERT(statement != NULL);
1957 ROSE_ASSERT(statement->
get_parent() != NULL);
1963 case V_SgJavaImportStatement:
1965 name =
"_java_import_stmt_";
1967 ROSE_ASSERT(statement != NULL);
1968 ROSE_ASSERT(statement->
get_parent() != NULL);
1973 case V_SgJavaPackageDeclaration:
1975 name =
"_java_package_declaration_";
1977 ROSE_ASSERT(package_declaration != NULL);
1978 ROSE_ASSERT(package_declaration->
get_parent() != NULL);
1983 case V_SgJavaPackageStatement:
1985 name =
"_java_package_stmt_";
1987 ROSE_ASSERT(statement != NULL);
1988 ROSE_ASSERT(statement->
get_parent() != NULL);
1994 case V_SgStaticAssertionDeclaration:
1996 name =
"_static_assertion_declaration_stmt_";
1998 ROSE_ASSERT(statement != NULL);
1999 ROSE_ASSERT(statement->
get_parent() != NULL);
2004 case V_SgNonrealDecl:
2006 const SgNonrealDecl * nrdecl = isSgNonrealDecl(declaration);
2007 ROSE_ASSERT(nrdecl != NULL);
2008 name = nrdecl->get_name();
2013 case V_SgEmptyDeclaration:
2016 ROSE_ASSERT(emptyDeclaration != NULL);
2021 case V_SgAdaPackageSpecDecl:
2023 name = genericGetName(isSgAdaPackageSpecDecl(declaration));
2027 case V_SgAdaPackageBodyDecl:
2029 name = genericGetName(isSgAdaPackageBodyDecl(declaration));
2033 case V_SgAdaFormalTypeDecl:
2035 name = genericGetName(isSgAdaFormalTypeDecl(declaration));
2039 case V_SgAdaGenericDecl:
2043 name =
get_name(gendcl->get_declaration());
2046 if (isSgFunctionDeclaration(dcl->get_declaration())) {
2047 name =
"_ada_generic_decl_" + genericGetName(isSgFunctionDeclaration(dcl->get_declaration()));
2050 if (isSgAdaPackageSpecDecl(dcl->get_declaration())) {
2051 name =
"_ada_generic_decl_" + genericGetName(isSgAdaPackageSpecDecl(dcl->get_declaration()));
2061 case V_SgAdaDiscriminatedTypeDecl:
2072 name =
"_incomplete_Ada_discriminated_type_";
2078 case V_SgAdaVariantDecl:
2080 name =
"_ada_variant_decl_";
2084 case V_SgAdaAttributeClause:
2086 name =
"_ada_attribute_clause_";
2090 case V_SgAdaRepresentationClause:
2092 name =
"_ada_representation_clause_";
2096 case V_SgAdaEnumRepresentationClause:
2098 name =
"_ada_enum_representation_clause_";
2102 case V_SgAdaComponentClause:
2104 name =
"_ada_component_clause_";
2108 case V_SgAdaTaskTypeDecl:
2110 name = genericGetName(isSgAdaTaskTypeDecl(declaration));
2114 case V_SgAdaProtectedTypeDecl:
2116 name = genericGetName(isSgAdaProtectedTypeDecl(declaration));
2120 case V_SgAdaTaskBodyDecl:
2122 name = genericGetName(isSgAdaTaskBodyDecl(declaration));
2126 case V_SgAdaProtectedBodyDecl:
2128 name = genericGetName(isSgAdaProtectedBodyDecl(declaration));
2132 case V_SgAdaRenamingDecl:
2134 name = genericGetName(isSgAdaRenamingDecl(declaration));
2138 case V_SgAdaTaskSpecDecl:
2140 name = genericGetName(isSgAdaTaskSpecDecl(declaration));
2144 case V_SgAdaProtectedSpecDecl:
2146 name = genericGetName(isSgAdaProtectedSpecDecl(declaration));
2150 case V_SgAdaGenericInstanceDecl:
2152 name = genericGetName(isSgAdaGenericInstanceDecl(declaration));
2156 case V_SgAdaFormalPackageDecl:
2158 name = genericGetName(isSgAdaFormalPackageDecl(declaration));
2162 case V_SgAdaParameterList:
2167 name = std::accumulate( plst->get_parameters().begin(), plst->get_parameters().end(),
2168 std::string{
"_ada_parameter_list_"},
2171 n += SageInterface::get_name(rhs);
2180 printf (
"Warning: default case reached in SageInterface::get_name ( const SgDeclarationStatement* declaration ), declaration = %p = %s \n",
2181 declaration,declaration->
class_name().c_str());
2191 string name =
"undefined_name";
2193 ROSE_ASSERT(scope != NULL);
2198 case V_SgTemplateClassDefinition:
2199 name =
get_name(isSgTemplateClassDefinition(scope)->get_declaration());
2202 case V_SgClassDefinition:
2203 case V_SgTemplateInstantiationDefn:
2204 name =
get_name(isSgClassDefinition(scope)->get_declaration());
2208 case V_SgTemplateFunctionDefinition:
2209 case V_SgFunctionDefinition:
2210 name =
get_name(isSgFunctionDefinition(scope)->get_declaration());
2213 case V_SgNamespaceDefinitionStatement:
2214 name =
get_name(isSgNamespaceDefinitionStatement(scope)->get_namespaceDeclaration());
2216 case V_SgJavaLabelStatement:
2217 name = (isSgJavaLabelStatement(scope)->get_label()).getString();
2221 case V_SgDeclarationScope:
2224 case V_SgAssociateStatement:
2225 case V_SgJavaForEachStatement:
2227 case V_SgFunctionParameterScope:
2228 case V_SgAdaPackageSpec:
2229 case V_SgAdaPackageBody:
2230 case V_SgAdaTaskSpec:
2231 case V_SgAdaTaskBody:
2232 case V_SgAdaProtectedSpec:
2233 case V_SgAdaProtectedBody:
2234 case V_SgAdaGenericDefn:
2235 case V_SgAdaAcceptStmt:
2236 case V_SgJovialForThenStatement:
2237 case V_SgMatlabForStatement:
2238 case V_SgBasicBlock:
2239 case V_SgCatchOptionStmt:
2240 case V_SgDoWhileStmt:
2241 case V_SgForStatement:
2244 case V_SgSwitchStatement:
2247 case V_SgForAllStatement:
2248 case V_SgRangeBasedForStatement:
2253 printf (
"Error: undefined case (SgScopeStatement) in SageInterface::get_name(): node = %s \n",scope->
class_name().c_str());
2263 string name =
"undefined_name";
2265 ROSE_ASSERT(stmt != NULL);
2268 if (declaration != NULL)
2286 case V_SgCaseOptionStmt:
2287 case V_SgCatchStatementSeq:
2288 case V_SgClinkageStartStatement:
2289 case V_SgContinueStmt:
2290 case V_SgDefaultOptionStmt:
2292 case V_SgForInitStmt:
2293 case V_SgFunctionTypeTable:
2294 case V_SgGotoStatement:
2295 case V_SgReturnStmt:
2301 case V_SgLabelStatement:
2304 name = labelStatement->
get_label().str();
2327 ROSE_ASSERT(node != NULL);
2329 string name =
"undefined_name";
2331 ROSE_ASSERT(node != NULL);
2335 case V_SgInitializedName:
2338 if (initializedName != NULL)
2340 name = initializedName->get_name().str();
2348 name =
"_pragma_string_";
2349 const SgPragma* pragma = isSgPragma(node);
2350 ROSE_ASSERT(pragma != NULL);
2351 name += pragma->get_pragma();
2365 case V_SgSourceFile:
2366#ifdef ROSE_ENABLE_BINARY_ANALYSIS
2367 case V_SgBinaryComposite:
2373 const SgFile* file = isSgFile(node);
2374 ROSE_ASSERT(file != NULL);
2381 case V_SgSymbolTable:
2383 name =
"_symbol_table_";
2388 case V_SgStorageModifier:
2390 name =
"_storage_modifier_";
2396 case V_Sg_File_Info:
2398 name =
"_file_info_";
2403 case V_SgTemplateArgument:
2405 name =
"_template_argument_";
2407 ROSE_ASSERT(templateArgument != NULL);
2413 ROSE_ASSERT(t != NULL);
2427 ROSE_ASSERT(templateArgument->get_initializedName() == NULL);
2432 ROSE_ASSERT(t == NULL);
2434 ROSE_ASSERT(initializedName != NULL);
2445 ROSE_ASSERT(t != NULL);
2452 printf (
"Error: default case reached in switch on templateArgument->get_argumentType() \n");
2461 case V_SgTypeModifier:
2464 ROSE_ASSERT(typeModifier != NULL);
2465 name =
"_type_modifier_" + typeModifier->displayString();
2472 const SgNameGroup* nameGroup = isSgNameGroup(node);
2473 ROSE_ASSERT(nameGroup != NULL);
2474 name =
"_name_group_" + nameGroup->get_group_name();
2479 case V_SgDataStatementGroup:
2482 ROSE_ASSERT(dataGroup != NULL);
2483 name =
"_data_statement_group_";
2488 case V_SgDataStatementObject:
2491 ROSE_ASSERT(dataObject != NULL);
2492 name =
"_data_statement_object_";
2497 case V_SgDataStatementValue:
2500 ROSE_ASSERT(dataValue != NULL);
2501 name =
"_data_statement_value_";
2506 case V_SgCommonBlockObject:
2509 ROSE_ASSERT(commonBlockObject != NULL);
2510 name =
"_common_block_object_" + commonBlockObject->get_block_name();
2515 case V_SgFormatItem:
2518 ROSE_ASSERT(formatItem != NULL);
2519 name =
"_format_item_";
2524 case V_SgFormatItemList:
2527 ROSE_ASSERT(formatItemList != NULL);
2528 name =
"_format_item_list_";
2533 case V_SgRenamePair:
2536 ROSE_ASSERT(renamePair != NULL);
2537 name = renamePair->get_local_name() +
"__" + renamePair->get_use_name() +
"_rename_pair_";
2544 const SgName* name_node = isSgName(node);
2545 ROSE_ASSERT(name_node != NULL);
2546 name =
"_name_" + name_node->getString();
2551 case V_SgTemplateParameter:
2554 ROSE_ASSERT(template_parameter_node != NULL);
2555 name =
"_template_parameter_";
2557 switch(template_parameter_node->get_parameterType())
2561 name +=
"type_parameter_";
2567 name +=
"nontype_parameter_";
2571 if (template_parameter_node->get_expression() != NULL)
2577 ROSE_ASSERT(template_parameter_node->get_initializedName() != NULL);
2583 name += template_parameter_node->get_initializedName()->
unparseToString();
2591 name +=
"template_parameter_";
2597 printf (
"Error: default reached \n");
2607 const SgBaseClass* base_class_node = isSgBaseClass(node);
2608 ROSE_ASSERT(base_class_node != NULL);
2609 ROSE_ASSERT(base_class_node->get_base_class() != NULL);
2614 ROSE_ASSERT(baseClassModifier != NULL);
2615 access = baseClassModifier->displayString();
2617 name =
"_base_class_" + access +
"_" +
get_name(base_class_node->get_base_class());
2623 printf (
"Default reached in switch for SgSupport IR node = %s \n",node->
class_name().c_str());
2624 name =
"default name";
2639 ROSE_ASSERT(symbol != NULL);
2641 string aliasSymbolPrefix =
"";
2642 if (isSgAliasSymbol(symbol) != NULL)
2644 aliasSymbolPrefix =
"_ALIAS";
2651 return symbol->
get_name() + aliasSymbolPrefix +
"_symbol_";
2659 ROSE_ASSERT(type != NULL);
2663 const SgNamedType* namedType = isSgNamedType(type);
2664 if (namedType != NULL)
2666 returnName =
"named_type_";
2667 returnName = namedType->
get_name().getString();
2673 case V_SgPointerType:
2676 returnName =
"pointer_to_";
2677 returnName +=
get_name(pointerType->get_base_type());
2681 case V_SgReferenceType:
2684 returnName =
"reference_to_";
2685 returnName +=
get_name(referenceType->get_base_type());
2691 const SgArrayType* arrayType = isSgArrayType(type);
2692 returnName =
"array_of_";
2693 returnName +=
get_name(arrayType->get_base_type());
2697 case V_SgModifierType:
2701 returnName +=
get_name(modifierType->get_base_type());
2706 case V_SgTemplateType:
2709 returnName =
"templateType_";
2710 returnName += templateType->get_name();
2727 string name =
"undefined_name";
2735 name =
"var_ref_of_";
2736 ROSE_ASSERT(varRef != NULL);
2737 ROSE_ASSERT(varRef->get_symbol() != NULL);
2738 name += varRef->get_symbol()->
get_name();
2743 case V_SgLabelRefExp:
2746 name =
"label_ref_of_";
2747 ROSE_ASSERT(labelRef != NULL);
2748 ROSE_ASSERT(labelRef->get_symbol() != NULL);
2749 name += labelRef->get_symbol()->
get_name();
2753 case V_SgPntrArrRefExp:
2756 name =
"array_ref_of_";
2763 case V_SgFunctionCallExp:
2766 name =
"function_call_";
2767 name +=
get_name(functionCall->get_function());
2771 case V_SgFunctionRefExp:
2774 name =
"function_ref_";
2775 name += functionRefExp->get_symbol()->
get_name();
2780 case V_SgMemberFunctionRefExp:
2783 name =
"member_function_ref_";
2784 name += memberFunctionRefExp->get_symbol()->
get_name();
2790 const SgIntVal* valueExp = isSgIntVal(expr);
2791 name =
"integer_value_exp_";
2798 const SgStringVal* valueExp = isSgStringVal(expr);
2799 name =
"string_value_exp_";
2800 name += valueExp->get_value();
2804 case V_SgSubscriptExpression:
2807 name =
"subscript_exp_";
2809 name +=
get_name(subscriptExpression->get_lowerBound());
2812 name +=
get_name(subscriptExpression->get_upperBound());
2815 name +=
get_name(subscriptExpression->get_stride());
2819 case V_SgNullExpression:
2821 name =
"null_expression";
2826 case V_SgExprListExp:
2829 name =
"expr_list_exp_";
2830 for (
size_t i = 0; i < exprListExp->get_expressions().size(); i++)
2832 name +=
get_name(exprListExp->get_expressions()[i]);
2838 case V_SgActualArgumentExpression:
2841 name =
"actual_arg_exp_name_";
2842 name += actualArgExp->get_argument_name();
2844 name +=
get_name(actualArgExp->get_expression());
2849 case V_SgTemplateParameterVal:
2852 name =
"template_parameter_value_expression_number_";
2862 const SgDotExp* dotExp = isSgDotExp(expr);
2863 ROSE_ASSERT(dotExp != NULL);
2865 name =
"_dot_exp_lhs_";
2867 name +=
"_dot_exp_rhs_";
2876 const SgLambdaExp* lambdaExp = isSgLambdaExp(expr);
2877 ROSE_ASSERT (lambdaExp != NULL);
2878 name =
"lambda_expression_";
2885 const SgThisExp* thisExp = isSgThisExp(expr);
2886 ROSE_ASSERT(thisExp != NULL);
2888 name =
"_this_exp_for_";
2891 ROSE_ASSERT(classSymbol != NULL);
2904 printf (
"Note: default reached in get_name() expr = %p = %s \n",expr,expr->
class_name().c_str());
2923 ROSE_ASSERT(node != NULL);
2929 case V_SgRenamePair:
2932 returnName =
"rename_pair_";
2933 returnName += n->get_local_name().str();
2934 returnName +=
"_from_";
2935 returnName += n->get_use_name().str();
2939 case V_SgInitializedName:
2942 ROSE_ASSERT (n != NULL);
2943 returnName =
"initialized_name_";
2944 returnName += n->get_name().str();
2949 case V_SgLambdaCapture:
2952 ROSE_ASSERT (n != NULL);
2953 returnName =
"lambda_capture_";
2959 case V_SgInterfaceBody:
2962 returnName =
"interface_body";
2982 string name =
"undefined_name";
2984 ROSE_ASSERT(node != NULL);
2987 if (locatedNode != NULL)
2989 const SgStatement* statement = isSgStatement(node);
2990 if (statement != NULL)
2997 if (expression != NULL)
3004 if (locatedNodeSupport != NULL)
3006 name =
get_name(locatedNodeSupport);
3010 const SgToken* token = isSgToken(node);
3017 printf (
"Unknown SgLocatedNode = %p = %s \n",node,node->
class_name().c_str());
3026 const SgSupport* supportNode = isSgSupport(node);
3027 if (supportNode != NULL)
3034 const SgSymbol* symbol = isSgSymbol(node);
3042 const SgType* type = isSgType(node);
3063 string name =
"undefined_name";
3065 ROSE_ASSERT(token != NULL);
3066 name = token->get_lexeme_string();
3071 else if (name ==
"\n")
3073 else if (name ==
"\t")
3115 case V_SgClassDeclaration:
3116 case V_SgTemplateClassDeclaration:
3120 ROSE_ASSERT(classDeclaration != NULL);
3122 string type_name = classDeclaration->get_name();
3124 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case class or template type: type_name = %s \n",type_name.c_str());
3126 string className = string(
"scope_") + scope +
"_type_name_" + type_name;
3128 printf (
"classDeclaration->get_scope() = %p = %s scope = %s \n",classDeclaration->
get_scope(),classDeclaration->
get_scope()->
class_name().c_str(),scope.c_str());
3135 case V_SgTemplateInstantiationDecl:
3138 ROSE_ASSERT(templateInstantiationDeclaration != NULL);
3144 string type_name = templateInstantiationDeclaration->get_name();
3146 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgTemplateInstantiationDecl: type_name = %s \n",type_name.c_str());
3148 string className = string(
"scope_") + scope +
"_type_name_" + type_name;
3163 printf (
"className = %s compressedClassName = %s \n",className.c_str(),compressedClassName.c_str());
3166 printf (
"templateInstantiationDeclaration->get_scope() = %p = %s scope = %s \n",
3170 s = compressedClassName;
3172 printf (
"Exiting as a test! \n");
3178 case V_SgFunctionDeclaration:
3179 case V_SgTemplateFunctionDeclaration:
3180 case V_SgTemplateInstantiationFunctionDecl:
3183 ROSE_ASSERT(functionDeclaration != NULL);
3185 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgFunctionDeclaration: not implemented \n");
3188 string original_name = functionDeclaration->get_name();
3190 string function_name_part = mangleFunctionName(original_name,
"return_type");
3191 string function_name = string(
"scope_") + scope +
"_function_name_" + function_name_part;
3205 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): Collision count = %d \n",count);
3212 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): case SgFunctionDeclaration: Exiting as a test! \n");
3218 case V_SgMemberFunctionDeclaration:
3219 case V_SgTemplateMemberFunctionDeclaration:
3220 case V_SgTemplateInstantiationMemberFunctionDecl:
3223 ROSE_ASSERT(memberFunctionDeclaration != NULL);
3225 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgMemberFunctionDeclaration: not implemented \n");
3228 string original_name = memberFunctionDeclaration->get_name();
3234 string member_function_name_part = mangleFunctionName(original_name,
"return_type");
3236 string member_function_name = string(
"scope_") + scope +
"_member_function_name_" + member_function_name_part;
3250 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): Collision count = %d \n",count);
3255 s = member_function_name;
3257 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): case SgMemberFunctionDeclaration: Exiting as a test! \n");
3265 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): Unsupported declaration = %p = %s \n",declaration,declaration->
class_name().c_str());
3271 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): s = %s \n",s.c_str());
3276 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): s = %s \n",s.c_str());
3281 printf (
"Exiting as a test! \n");
3300 printf (
"In generateUniqueNameForUseAsIdentifier(): evaluating declaration = %p = %s \n",declaration,declaration->
class_name().c_str());
3313 if (definingDeclaration != NULL)
3316 printf (
"In generateUniqueName(): Using the defining declaration = %p since %p was not in the map \n",definingDeclaration,declaration);
3324 printf (
"Warning: defining declaration not in SageInterface::local_node_to_name_map: declaration = %p = %s using name = %s \n",
3331 ROSE_ASSERT(nondefiningDeclaration != NULL);
3337 printf (
"Exiting as a test! \n");
3348 ROSE_ASSERT(astNode != NULL);
3358 void visit (
SgNode* node)
3365 if (classDeclaration != NULL || functionDeclaration != NULL)
3376 UniqueNameTraversal traversal;
3377 traversal.traverse(astNode, preorder);
3387 ROSE_ASSERT(classDeclaration != NULL);
3389 ROSE_ASSERT(definingDeclaration != NULL);
3390 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(definingDeclaration);
3394 if (definingClassDeclaration != NULL)
3396 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3397 ROSE_ASSERT(classDefinition != NULL);
3399 SgDeclarationStatementPtrList::iterator i = classDefinition->
get_members().begin();
3400 while ( i != classDefinition->
get_members().end() )
3403 ROSE_ASSERT( (*i)->get_parent() != NULL);
3404 ROSE_ASSERT( (*i)->get_parent() == classDefinition);
3407 if (memberFunction != NULL)
3410 if ( memberFunction->get_specialFunctionModifier().isConstructor() ==
true )
3411 defaultConstructor = memberFunction;
3422 return defaultConstructor;
3430 ROSE_ASSERT(classDeclaration != NULL);
3432 if (definingDeclaration != NULL)
3434 ROSE_ASSERT(definingDeclaration != NULL);
3435 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(definingDeclaration);
3439 if (definingClassDeclaration != NULL)
3441 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3442 ROSE_ASSERT(classDefinition != NULL);
3444 SgDeclarationStatementPtrList::iterator i = classDefinition->
get_members().begin();
3445 while ( i != classDefinition->
get_members().end() )
3449 ROSE_ASSERT(i_parent != NULL);
3454 if ( i_parent != classDefinition )
3456 printf (
"Error: (*i)->get_parent() = %p = %s \n",i_parent,i_parent->
class_name().c_str());
3457 printf (
"(*i) = %p = %s = %s \n",*i,(*i)->class_name().c_str(),(*i)->unparseToString().c_str());
3458 (*i)->get_file_info()->display(
"Called from SageInterface::getDefaultDestructor: debug");
3460 ROSE_ASSERT( i_parent == classDefinition);
3463 if (memberFunction != NULL)
3465 if ( memberFunction->get_specialFunctionModifier().isDestructor() ==
true )
3466 defaultDestructor = memberFunction;
3475 return defaultDestructor;
3487#define DEBUG_ADD_DEFAULT_CONSTRUCTOR 0
3491 ASSERT_not_null(classType);
3493 bool returnValue =
false;
3496 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
3497 ROSE_ASSERT(classDeclaration != NULL);
3499 ROSE_ASSERT(definingClassDeclaration != NULL);
3500 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3501 ROSE_ASSERT(classDefinition != NULL);
3503 SgDeclarationStatementPtrList & declarationList = classDefinition->
get_members();
3505 bool foundConstructor =
false;
3506 bool foundDefaultConstructor =
false;
3508#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3509 printf (
"In addDefaultConstructorIfRequired(): class name = %s \n",classDeclaration->get_name().str());
3512 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
3513 while (i != declarationList.end())
3516 if (memberFunctionDeclaration != NULL)
3518 bool isConstructor = memberFunctionDeclaration->get_specialFunctionModifier().isConstructor();
3519 if (isConstructor ==
true)
3521 foundConstructor =
true;
3523#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3524 printf (
"Found a constructor! \n");
3527 ROSE_ASSERT(functionParameterList != NULL);
3531 foundDefaultConstructor = ((foundDefaultConstructor ==
true) || (functionParameterList->
get_args().size() == 0));
3533#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3534 if (foundDefaultConstructor ==
true)
3536 printf (
"Found a default constructor! \n");
3540 printf (
"This is not a default constructor: functionParameterList->get_args().size() = %zu \n",functionParameterList->
get_args().size());
3546#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3547 printf (
"This is not a constructor \n");
3555#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3556 printf (
"foundConstructor = %s \n",foundConstructor ?
"true" :
"false");
3557 printf (
"foundDefaultConstructor = %s \n",foundDefaultConstructor ?
"true" :
"false");
3560 if (foundConstructor ==
true)
3563#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3564 printf (
"Since there is at least one constructor, we can't rely on compiler generated constructors \n");
3566 if (foundDefaultConstructor ==
true)
3569#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3570 printf (
"We can use the existing default constructor (no need to build one) \n");
3577#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3578 printf (
"########################################################### \n");
3579 printf (
"Need to build a default constructor in the associated class \n");
3582 ROSE_ASSERT(constructorDeclaration != NULL);
3584#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3585 printf (
" --- constructorDeclaration = %p = %s name = %s \n",constructorDeclaration,constructorDeclaration->
class_name().c_str(),constructorDeclaration->get_name().str());
3587 ROSE_ASSERT (constructorDeclaration->get_declarationModifier().get_accessModifier().isPublic() ==
true);
3589 classDefinition->prepend_statement(constructorDeclaration);
3592 ROSE_ASSERT(constructorDeclaration->
get_parent() != NULL);
3600 constructorDeclaration->
get_endOfConstruct ()->set_physical_file_id(physical_file_id);
3604 ROSE_ASSERT(constructorDeclaration->get_definition() != NULL);
3607 constructorDeclaration->get_definition()->
get_startOfConstruct()->set_physical_file_id(physical_file_id);
3608 constructorDeclaration->get_definition()->
get_endOfConstruct ()->set_physical_file_id(physical_file_id);
3611#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3612 printf (
"DONE: Need to build a default constructor in the associated class \n");
3613 printf (
"################################################################# \n");
3616 printf (
"Exiting as a test! \n");
3625#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3626 printf (
"No constructors found, so we don't need to add an explicit default constructor \n");
3630#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3631 printf (
"Leaving addDefaultConstructorIfRequired(): returnValue = %s \n",returnValue ?
"true" :
"false");
3663 astTraversal.
traverse(node,preorder);
3673 printf (
"Exiting as a test! \n");
3683 printf (
"Symbol Table from %p = %s at: \n",scope,scope->
sage_class_name());
3684 scope->
get_file_info()->display(
"Symbol Table Location (Called from SageInterface::OutputLocalSymbolTables::visit())");
3686 scope->print_symboltable(
"Called from SageInterface::OutputLocalSymbolTables::visit()");
3701 bool result =
false;
3716 bool result =
false;
3720 if (isTemplateMemberFunction(memberFunctionDeclaration) ==
true)
3723 printf (
"templateDeclaration = %p parent of templateDeclaration = %p \n",templateDeclaration,templateDeclaration->
get_parent());
3726 SgClassDeclaration* classDeclaration = memberFunctionDeclaration->get_class_scope()->get_declaration();
3727 ROSE_ASSERT(classDeclaration != NULL);
3730 if (classTemplateInstantiation != NULL)
3733 if (classTemplateDeclaration != NULL && classTemplateDeclaration != templateDeclaration)
3747 if (templateDeclaration != NULL && templateDeclaration->
get_parent() != NULL)
3750 if (isSgClassDefinition(parentScope) != NULL)
3763 printf (
"Error: This is no longer used. \n");
3776 if (firstNondefiningDeclaration != NULL)
3777 keyDeclaration = firstNondefiningDeclaration;
3779 keyDeclaration = definingDeclaration;
3780 ROSE_ASSERT(keyDeclaration != NULL);
3782 return keyDeclaration;
3788 string pragmaString = pragmaDeclaration->get_pragma()->get_pragma();
3789 istringstream istr(pragmaString);
3799 ROSE_ASSERT (n != NULL);
3800 bool result =
false;
3801 if (isSgOmpBarrierStatement(n)||
3802 isSgOmpBodyStatement(n)||
3803 isSgOmpDeclareSimdStatement(n) ||
3804 isSgOmpFlushStatement(n)||
3805 isSgOmpThreadprivateStatement(n)||
3806 isSgOmpTaskwaitStatement(n) )
3834 if (memberFunctionDeclaration != NULL)
3844 ROSE_ASSERT(scope != NULL);
3847 if (isSgDeclarationScope(scope)) {
3848 printf(
"TODO SageInterface::isOverloaded case when scope is SgDeclarationScope. See ROSE-1378.\n");
3854 isSgClassDefinition(memberFunctionDeclaration->
get_scope());
3855 ROSE_ASSERT(classDefinition != NULL);
3859 ROSE_ASSERT(classDeclaration != NULL);
3862 SgDeclarationStatementPtrList & memberList = classDefinition->
get_members();
3865 printf (
" memberList.size() = %" PRIuPTR
" \n",memberList.size());
3867 for (SgDeclarationStatementPtrList::iterator i = memberList.begin(); i != memberList.end(); i++)
3870 printf (
" counter = %d declaration = %p = %s \n",counter,*i,(*i)->class_name().c_str());
3876 if (tempMemberFunction != NULL)
3881 if ( keyDeclaration == generateUniqueDeclaration(tempMemberFunction) )
3884 printf (
"Skipping the case of keyDeclaration == generateUniqueDeclaration(tempMemberFunction) = %p \n",keyDeclaration);
3889 ROSE_ASSERT(tempMemberFunction->get_name() !=
"");
3891 printf (
" tempMemberFunction = (name) %s = (qualified) %s \n",
3892 tempMemberFunction->get_name().str(),
3893 tempMemberFunction->get_qualified_name().str());
3895 if (tempMemberFunction->get_name() == memberFunctionDeclaration->get_name())
3898 printf (
" Found a matching overloaded member function! \n");
3907 if (tempTemplateDeclaration != NULL)
3913 printf (
"tempTemplateDeclaration->get_name() = %s \n",tempTemplateDeclaration->
get_name().str());
3915 if (memberFunctionDeclaration->get_name() == tempTemplateDeclaration->
get_name())
3918 printf (
" Found a matching overloaded member function! \n");
3927 if (functionDeclaration->
variantT() == V_SgFunctionDeclaration)
3929 printf (
"In SageInterface::isOverloaded(): could friend functions be overloaded in a class? \n");
3942 printf (
"In SageInterface::isOverloaded(): case of non-member function not yet implemented! \n");
3949 return (counter > 1);
3964 ROSE_ASSERT(memberFunctionInstantiation != NULL);
3967 printf (
"buildForwardFunctionDeclaration: Member function = %p = %s = definition = %p \n",
3968 memberFunctionInstantiation,
3969 memberFunctionInstantiation->get_name().str(),
3970 memberFunctionInstantiation->get_definition());
3971 memberFunctionInstantiation->
get_file_info()->display(
"memberFunctionInstantiation: debug");
3977 class NondefiningFunctionDeclarationCopyType :
public SgCopyHelp
3987 SgNode* returnValue = NULL;
3995 case V_SgFunctionDeclaration:
3996 case V_SgMemberFunctionDeclaration:
3997 case V_SgTemplateInstantiationFunctionDecl:
3998 case V_SgTemplateInstantiationMemberFunctionDecl:
4002 ROSE_ASSERT(functionDeclaration != NULL);
4008 returnValue =
const_cast<SgNode *
>(n);
4020 case V_SgFunctionDefinition:
4022 printf (
"Skip copying the function definition if it is present \n");
4024 returnValue =
const_cast<SgNode *
>(n);
4038 if (returnValue == NULL)
4039 returnValue = n->copy(*
this);
4041 ROSE_ASSERT(returnValue != NULL);
4044 } nondefiningFunctionDeclarationCopy;
4049 if (memberFunctionInstantiation->get_definition() != NULL)
4051 printf (
"\n\nNEED TO REMOVE POINTERS IN THE NON-DEFINING DECLARATION TO THE SgClassDefinition objects. \n");
4056 memberFunctionInstantiation->set_definition(NULL);
4058 SgNode* copyOfMemberFunctionNode = memberFunctionInstantiation->copy(nondefiningFunctionDeclarationCopy);
4077 printf (
"copyOfMemberFunction->isForward() = %s \n",copyOfMemberFunction->
isForward() ?
"true" :
"false");
4078 printf (
"memberFunctionInstantiation->isForward() = %s \n",memberFunctionInstantiation->
isForward() ?
"true" :
"false");
4081 printf (
"memberFunctionInstantiation->isSpecialization() = %s \n",memberFunctionInstantiation->isSpecialization() ?
"true" :
"false");
4082 printf (
"copyOfMemberFunctionNode = %p = %s = %s memberFunctionInstantiation->isSpecialization() = %s \n",
4083 copyOfMemberFunction,copyOfMemberFunction->
class_name().c_str(),
SageInterface::get_name(copyOfMemberFunction).c_str(),copyOfMemberFunction->isSpecialization() ?
"true" :
"false");
4084 copyOfMemberFunction->
get_file_info()->display(
"copyOfMemberFunction: debug");
4088 ROSE_ASSERT(memberFunctionInstantiation->get_args().size() == copyOfMemberFunction->get_args().size());
4094 ROSE_ASSERT(copyOfMemberFunction != NULL);
4095 return copyOfMemberFunction;
4104 ROSE_ASSERT(declarationForType != NULL);
4107 switch(declarationForType->
variantT())
4110 case V_SgTemplateInstantiationDecl:
4111 case V_SgTemplateClassDeclaration:
4113 case V_SgClassDeclaration:
4118 if (isSgTemplateClassDeclaration(declarationForType) != NULL)
4127 ROSE_ASSERT(symbol != NULL);
4128 SgName name = classDeclaration->get_name();
4129 symbolTable->insert(name,symbol);
4133 case V_SgEnumDeclaration:
4137 ROSE_ASSERT(symbol != NULL);
4139 symbolTable->insert(name,symbol);
4143 case V_SgFunctionDeclaration:
4147 ROSE_ASSERT(symbol != NULL);
4148 SgName name = functionDeclaration->get_name();
4149 symbolTable->insert(name,symbol);
4153 case V_SgMemberFunctionDeclaration:
4157 ROSE_ASSERT(symbol != NULL);
4161 SgName name = functionDeclaration->get_name();
4162 symbolTable->insert(name,symbol);
4168 printf (
"Default reached in evaluation of typedef inner definition = %p = %s and building a symbol for it for the symbol table \n",declarationForType,declarationForType->
class_name().c_str());
4179 SgInitializedNamePtrList::iterator i = variableList.begin();
4180 while (i != variableList.end())
4184 if (
variable->get_scope() == scope)
4192 printf (
"WARNING: Scopes do NOT match! variable = %p = %s (could this be a static variable, or has the symbol table been setup before the scopes have been set?) \n",
variable,
variable->get_name().str());
4197 ROSE_ASSERT(symbol != NULL);
4199 symbolTable->insert(name,symbol);
4207SageInterface::supportForInitializedNameLists (
SgScopeStatement* scope, SgInitializedNamePtrList & variableList )
4210 ROSE_ASSERT(symbolTable != NULL);
4212 supportForVariableLists(scope,symbolTable,variableList);
4220 SgInitializedNamePtrList & variableList = variableDeclaration->
get_variables();
4221 supportForVariableLists(scope,symbolTable,variableList);
4229 ROSE_ASSERT(symbolTable != NULL);
4240 std::vector<SgNode*> labelList = NodeQuery::querySubTree (scope,V_SgLabelStatement);
4242 int numberOfLabels = labelList.size();
4243 for (
int i=0; i < numberOfLabels; i++)
4247 ROSE_ASSERT(labelStatement != NULL);
4248 ROSE_ASSERT(labelStatement->
get_scope() == scope);
4251 ROSE_ASSERT(symbol != NULL);
4255 SgName name = labelStatement->get_name();
4256 symbolTable->insert(name,symbol);
4266 ROSE_ASSERT(scope != NULL);
4268 printf (
"In SageInterface::rebuildSymbolTable(): Symbol Table from %p = %s \n",scope,scope->
class_name().c_str());
4271 printf (
"Exiting as a test \n");
4277 if (symbolTable != NULL)
4280 if (symbolTable->
size() != 0)
4282 printf (
"symbolTable->size() = %d \n",symbolTable->
size());
4284 ROSE_ASSERT(symbolTable->
size() == 0);
4286 printf (
"Symbol Table from %p = %s of size = %" PRIuPTR
" \n",scope,scope->
class_name().c_str(),symbolTable->
size());
4287 symbolTable->
print(
"Called from SageInterface::rebuildSymbolTable()");
4293 printf (
"In SageInterface::rebuildSymbolTable(): No symbol table found \n");
4295 ROSE_ASSERT(symbolTable == NULL);
4300 ROSE_ASSERT(symbolTable != NULL);
4301 ROSE_ASSERT(symbolTable->get_table() != NULL);
4305 ROSE_ASSERT(symbolTable->
get_parent() != NULL);
4318 case V_SgForStatement:
4325 SgStatementPtrList::iterator i = forStatement->get_init_stmt().begin();
4329 while (i != forStatement->get_init_stmt().end())
4333 if (variableDeclarationInitializer != NULL)
4338 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationInitializer );
4344 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(forStatement->get_test());
4345 if (variableDeclarationCondition != NULL)
4350 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4357 case V_SgJovialForThenStatement:
4358 case V_SgMatlabForStatement:
4366 case V_SgTemplateFunctionDefinition:
4368 case V_SgFunctionDefinition:
4375 if (functionDefinition != NULL)
4381 if (functionDeclaration != NULL)
4384 if (functionDeclaration->
isForward() ==
true)
4386 printf (
"ERROR: functionDeclaration = %p = %s = %s \n",functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
4387 printf (
" --- functionDeclaration (get_name()) = %s \n",
get_name(functionDeclaration).c_str());
4388 printf (
" --- functionDeclaration (mangled name) = %s \n",functionDeclaration->get_mangled_name().str());
4390 if (memberFunctionDeclaration != NULL)
4392 printf (
"memberFunctionDeclaration != NULL \n");
4395 ROSE_ASSERT(functionDeclaration->
isForward() ==
false);
4396 SgInitializedNamePtrList & argumentList = functionDeclaration->get_args();
4397 supportForVariableLists(scope,symbolTable,argumentList);
4410 supportForLabelStatements(scope,symbolTable);
4421 SgIfStmt* ifStatement = isSgIfStmt(scope);
4423 if (variableDeclarationCondition != NULL)
4428 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4434 case V_SgSwitchStatement:
4441 if (variableDeclarationSelector != NULL)
4446 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationSelector );
4458 SgWhileStmt* whileStatement = isSgWhileStmt(scope);
4460 if (variableDeclarationCondition != NULL)
4466 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4472 case V_SgCatchOptionStmt:
4473 case V_SgDoWhileStmt:
4482 case V_SgTemplateClassDefinition:
4484 case V_SgBasicBlock:
4485 case V_SgClassDefinition:
4486 case V_SgTemplateInstantiationDefn:
4488 case V_SgNamespaceDefinitionStatement:
4496 case V_SgJavaForEachStatement:
4499 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(javaForEachStatement->get_element());
4500 if (variableDeclarationCondition != NULL)
4506 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4514 printf (
"Default reached in SageInterface::rebuildSymbolTable() scope = %p = %s \n",scope,scope->
class_name().c_str());
4520 printf (
"In SageInterface::rebuildSymbolTable(): fixup declarations in Symbol Table from %p = %s \n",scope,scope->
class_name().c_str());
4528 for (SgStatementPtrList::iterator i = statementList.begin(); i != statementList.end(); i++)
4535 if (declaration != NULL)
4541 list<SgSymbol*> symbolList;
4544 case V_SgTemplateInstantiationMemberFunctionDecl:
4548 if (scope == derivedDeclaration->
get_scope())
4551 ROSE_ASSERT(symbol != NULL);
4557 SgName name = derivedDeclaration->get_name();
4558 symbolTable->insert(name,symbol);
4569 ROSE_ASSERT(derivedDeclarationScope != NULL);
4576 ROSE_ASSERT(templateDeclaration != NULL);
4584 SgType* functionType = templateDeclaration->get_type();
4585 SgTemplateParameterPtrList & templateParameterList = templateDeclaration->get_templateParameters();
4588 if (templateSymbol != NULL)
4592 printf (
"Building a symbol for derivedDeclaration = %p = %s to an alternative symbol table in derivedDeclarationScope = %p \n",
4593 derivedDeclaration,
get_name(derivedDeclaration).c_str(),derivedDeclarationScope);
4596 ROSE_ASSERT(symbol != NULL);
4597 SgName name = derivedDeclaration->get_name();
4609 case V_SgTemplateMemberFunctionDeclaration:
4611 case V_SgMemberFunctionDeclaration:
4616 if (scope == derivedDeclaration->
get_scope())
4620 if (isSgTemplateFunctionDeclaration(declaration) != NULL)
4625 ROSE_ASSERT(symbol != NULL);
4629 SgName name = derivedDeclaration->get_name();
4630 symbolTable->insert(name,symbol);
4641 case V_SgTemplateInstantiationFunctionDecl:
4645 if (scope == derivedDeclaration->
get_scope())
4648 ROSE_ASSERT(symbol != NULL);
4649 SgName name = derivedDeclaration->get_name();
4650 symbolTable->insert(name,symbol);
4654 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4656#if PRINT_DEVELOPER_WARNINGS
4657 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4666 case V_SgTemplateFunctionDeclaration:
4668 case V_SgFunctionDeclaration:
4674 if (useThisDeclaration ==
true)
4676 if (scope == derivedDeclaration->
get_scope())
4681 if (isSgTemplateFunctionDeclaration(declaration) != NULL)
4686 ROSE_ASSERT(symbol != NULL);
4687 SgName name = derivedDeclaration->get_name();
4688 symbolTable->insert(name,symbol);
4692 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4694#if PRINT_DEVELOPER_WARNINGS
4695 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4704 case V_SgTemplateVariableDeclaration:
4706 case V_SgVariableDeclaration:
4709 SgInitializedNamePtrList & variableList = derivedDeclaration->
get_variables();
4710 SgInitializedNamePtrList::iterator i = variableList.begin();
4711 while ( i != variableList.end() )
4717 if (
variable->get_scope() == scope)
4720 ROSE_ASSERT(symbol != NULL);
4725 symbolTable->insert(name,symbol);
4742 ROSE_ASSERT(symbolTable != NULL);
4751 case V_SgTemplateInstantiationDecl:
4758 if (scope == derivedDeclaration->
get_scope())
4762 ROSE_ASSERT(symbol != NULL);
4763 SgName name = derivedDeclaration->get_name();
4766 if (scope != derivedDeclaration->
get_scope())
4768 printf (
"Error: scopes don't match for derivedDeclaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4770 ROSE_ASSERT(scope == derivedDeclaration->
get_scope());
4772 symbolTable->insert(name,symbol);
4778 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4780#if PRINT_DEVELOPER_WARNINGS
4781 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4787 ROSE_ASSERT(symbol != NULL);
4788 SgName name = derivedDeclaration->get_name();
4789 symbolTable->insert(name,symbol);
4796 case V_SgTemplateClassDeclaration:
4798 case V_SgClassDeclaration:
4802 if (scope == derivedDeclaration->
get_scope())
4805 if (isSgTemplateClassDeclaration(declaration) != NULL)
4810 ROSE_ASSERT(symbol != NULL);
4811 SgName name = derivedDeclaration->get_name();
4812 symbolTable->insert(name,symbol);
4816 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4818#if PRINT_DEVELOPER_WARNINGS
4819 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4825 ROSE_ASSERT(symbol != NULL);
4826 SgName name = derivedDeclaration->get_name();
4827 symbolTable->insert(name,symbol);
4832 case V_SgEnumDeclaration:
4835 ROSE_ASSERT(derivedDeclaration != NULL);
4837 ROSE_ASSERT(symbol != NULL);
4839 symbolTable->insert(name,symbol);
4842 SgInitializedNamePtrList & enumFieldList = derivedDeclaration->
get_enumerators();
4843 SgInitializedNamePtrList::iterator i = enumFieldList.begin();
4846 while (i != enumFieldList.end())
4849 ROSE_ASSERT(enum_field_symbol != NULL);
4850 SgName enum_field_name = (*i)->get_name();
4851 symbolTable->insert(enum_field_name,enum_field_symbol);
4861 case V_SgTemplateTypedefDeclaration:
4863 case V_SgTypedefDeclaration:
4867 ROSE_ASSERT(symbol != NULL);
4868 SgName name = derivedDeclaration->get_name();
4869 symbolTable->insert(name,symbol);
4871 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration \n");
4876 if (derivedDeclaration->get_typedefBaseTypeContainsDefiningDeclaration() ==
true)
4879 ROSE_ASSERT(symbolTable != NULL);
4882 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == true calling supportForBaseTypeDefiningDeclaration() \n");
4890 if (declaration != NULL)
4893 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == false calling supportForBaseTypeDefiningDeclaration() \n");
4898 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == false: skipping call to supportForBaseTypeDefiningDeclaration() \n");
4902 printf (
"In SageInterface::rebuildSymbolTable(): Leaving case of SgTypedefDeclaration \n");
4907 case V_SgTemplateDeclaration:
4913 printf (
"case V_SgTemplateDeclaration: derivedDeclaration = %p \n",derivedDeclaration);
4914 printf (
"case V_SgTemplateDeclaration: derivedDeclaration->get_declarationModifier().isFriend() = %s \n",derivedDeclaration->get_declarationModifier().
isFriend() ?
"true" :
"false");
4915 printf (
"case V_SgTemplateDeclaration: derivedDeclaration->get_name() = %s \n",derivedDeclaration->
get_name().str());
4916 printf (
"case V_SgTemplateDeclaration: derivedDeclaration->get_string() = %s \n",derivedDeclaration->
get_string().str());
4918 if (scope == derivedDeclaration->
get_scope())
4921 ROSE_ASSERT(symbol != NULL);
4923 symbolTable->insert(name,symbol);
4927 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4929#if PRINT_DEVELOPER_WARNINGS
4930 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4937 ROSE_ASSERT(symbol != NULL);
4939 symbolTable->insert(name,symbol);
4946 case V_SgNamespaceAliasDeclarationStatement:
4949 ROSE_ASSERT(aliasDeclaration != NULL);
4953 ROSE_ASSERT(derivedDeclaration != NULL);
4957 ROSE_ASSERT(symbol != NULL);
4959 symbolTable->insert(name,symbol);
4967 case V_SgNamespaceDeclarationStatement:
4970 ROSE_ASSERT(derivedDeclaration != NULL);
4974 ROSE_ASSERT(symbol != NULL);
4976 symbolTable->insert(name,symbol);
4982 case V_SgUsingDirectiveStatement:
4983 case V_SgPragmaDeclaration:
4984 case V_SgTemplateInstantiationDirectiveStatement:
4985 case V_SgUsingDeclarationStatement:
4989 printf (
"This declaration is ignored in rebuilding symbol table %p = %s = %s \n",*i,(*i)->class_name().c_str(),
get_name(*i).c_str());
4998 printf (
"An ASM statement (SgAsmStmt) declaration is not really a declaration %p = %s = %s \n",*i,(*i)->class_name().c_str(),
get_name(*i).c_str());
5004 case V_SgVariableDefinition:
5005 case V_SgFunctionParameterList:
5006 case V_SgCtorInitializerList:
5009 printf (
"Special cases not handled %p = %s = %s \n",*i,(*i)->class_name().c_str(),
get_name(*i).c_str());
5013 case V_SgStaticAssertionDeclaration:
5017 printf (
"A static assertion statement (SgStaticAssertionDeclaration) declaration is not really a declaration %p = %s = %s \n",*i,(*i)->class_name().c_str(),
get_name(*i).c_str());
5024 printf (
"Error: Default reached in rebuildSymbolTable declaration = %p = %s \n",declaration,declaration->
class_name().c_str());
5029 ROSE_ASSERT(symbolTable != NULL);
5030 ROSE_ASSERT(symbolTable->get_table() != NULL);
5036 ROSE_ASSERT(symbolTable != NULL);
5037 ROSE_ASSERT(symbolTable->get_table() != NULL);
5040 printf (
"Leaving SageInterface::rebuildSymbolTable(): fixup declarations in Symbol Table from %p = %s \n",scope,scope->
class_name().c_str());
5044 printf (
"Symbol Table from %p = %s at: \n",scope,scope->
class_name().c_str());
5046 symbolTable->
print(
"Called from SageInterface::rebuildSymbolTable()");
5061#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
5062 ROSE_ASSERT(this_scope != NULL);
5063 ROSE_ASSERT(copy_scope != NULL);
5066 printf (
"In fixupReferencesToSymbols(this_scope = %p = %s = %s, copy_scope = %p = %s = %s) \n",
5074 printf (
"Before fixup: this scope = %p = %s this_symbolTable->get_table()->size() = %" PRIuPTR
" \n",this_scope,this_scope->
class_name().c_str(),this_symbolTable->get_table()->size());
5075 printf (
"Before fixup: copy scope = %p = %s copy_symbolTable->get_table()->size() = %" PRIuPTR
" \n",copy_scope,copy_scope->
class_name().c_str(),copy_symbolTable->get_table()->size());
5081 if (this_symbolTable->get_table()->size() != copy_symbolTable->get_table()->size())
5085 printf (
"Before fixup: this scope = %p = %s this_symbolTable->get_table()->size() = %" PRIuPTR
" \n",this_scope,this_scope->
class_name().c_str(),this_symbolTable->get_table()->size());
5086 printf (
"Before fixup: copy scope = %p = %s copy_symbolTable->get_table()->size() = %" PRIuPTR
" \n",copy_scope,copy_scope->
class_name().c_str(),copy_symbolTable->get_table()->size());
5087 printf (
"Warning the symbols tables in these different scopes are different sizes \n");
5092 SgSymbolTable::hash_iterator i = this_symbolTable->get_table()->begin();
5095 std::map<SgNode*, SgNode*> replacementMap;
5097 while (i != this_symbolTable->get_table()->end())
5099 ROSE_ASSERT ( isSgSymbol( (*i).second ) != NULL );
5101 SgName name = (*i).first;
5104 ROSE_ASSERT ( symbol != NULL );
5106 SgSymbol* associated_symbol = NULL;
5108 printf (
"Symbol number: %d (pair.first (SgName) = %s) pair.second (SgSymbol) = %p sage_class_name() = %s \n",counter,i->first.str(),i->second,i->second->class_name().c_str());
5111 SgSymbolTable::hash_iterator associated_symbol_iterator = copy_symbolTable->get_table()->find(name);
5116 while (associated_symbol_iterator != copy_symbolTable->get_table()->end() && associated_symbol_iterator->first == name)
5118 if ( associated_symbol_iterator->second->variantT() == symbol->
variantT() )
5120 associated_symbol = associated_symbol_iterator->second;
5123 associated_symbol_iterator++;
5126 if (associated_symbol != NULL)
5128 ROSE_ASSERT ( associated_symbol != NULL );
5131 ROSE_ASSERT(copy_scope->symbol_exists(associated_symbol) ==
true);
5136 replacementMap.insert(pair<SgNode*,SgNode*>(symbol,associated_symbol));
5143 help.get_copiedNodeMap().insert(pair<const SgNode*,SgNode*>(symbol,associated_symbol));
5150 printf (
"Warning: Symbol number: %d (pair.first (SgName) = %s) pair.second (SgSymbol) = %p sage_class_name() = %s \n",counter,i->first.str(),i->second,i->second->class_name().c_str());
5151 printf (
"Warning: associated_symbol == NULL, need to investigate this (ignoring for now) \n");
5161 printf (
"\n\n************************************************************\n");
5162 printf (
"fixupReferencesToSymbols(this_scope = %p copy_scope = %p = %s = %s): calling Utils::edgePointerReplacement() \n",this_scope,copy_scope,copy_scope->
class_name().c_str(),
get_name(copy_scope).c_str());
5168 printf (
"fixupReferencesToSymbols(): calling Utils::edgePointerReplacement(): DONE \n");
5169 printf (
"************************************************************\n\n");
5171 printf (
"\n\n After replacementMapTraversal(): intermediateDeleteSet: \n");
5172 displaySet(intermediateDeleteSet,
"After Utils::edgePointerReplacement");
5174 printf (
"After fixup: this_symbolTable->get_table()->size() = %" PRIuPTR
" \n",this_symbolTable->get_table()->size());
5175 printf (
"After fixup: copy_symbolTable->get_table()->size() = %" PRIuPTR
" \n",copy_symbolTable->get_table()->size());
5184 printf (
"Exiting as a test in fixupReferencesToSymbols() \n");
5200 vector<SgFile*> fileList;
5201 void visit (
SgNode* node)
5203 SgFile* file = isSgFile(node);
5204 ROSE_ASSERT(file != NULL);
5207 fileList.push_back(file);
5211 virtual ~FileTraversal() {}
5214 FileTraversal fileTraversal;
5219#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5230 return fileTraversal.fileList;
5248 void visit (
SgNode* node)
5250 project = isSgProject(node);
5251 ROSE_ASSERT(project!= NULL);
5253 virtual ~ProjectTraversal() {}
5256 ProjectTraversal projectTraversal;
5258 return projectTraversal.project;
5260 std::vector<SgProject* > resultlist = getSgNodeListFromMemoryPool<SgProject>();
5261 if (resultlist.empty())
5263 ROSE_ASSERT(resultlist.size()==1);
5264 return resultlist[0];
5269 return getEnclosingNode<SgProject>(node,
true );
5274 if (isSgFunctionRefExp(func))
5276 return isSgFunctionRefExp(func)->get_symbol()->get_declaration();
5278 else if (isSgDotExp(func) || isSgArrowExp(func))
5281 if (isSgMemberFunctionRefExp(func2))
5282 return isSgMemberFunctionRefExp(func2)->get_symbol()->get_declaration();
5285 cerr<<
"Warning in SageInterface::getDeclarationOfNamedFunction(): rhs operand of dot or arrow operations is not a member function, but a "<<func2->
class_name()<<endl;
5294 const SgExpressionPtrList& ls = el->get_expressions();
5295 if (ls.empty())
return 0;
5296 if (isSgAssignOp(ls.back()))
return 0;
5303 ASSERT_not_null(astNode);
5304 Rose_STL_Container<SgNode*> arr_exp_list = NodeQuery::querySubTree(astNode,V_SgPntrArrRefExp);
5305 for (
SgNode* expr : arr_exp_list)
5308 ASSERT_not_null(arr_exp);
5309 Rose_STL_Container<SgNode*> refList = NodeQuery::querySubTree(arr_exp->
get_lhs_operand(),V_SgVarRefExp);
5310 for (
SgNode* ref : refList)
5313 ASSERT_not_null(cur_ref);
5315 ASSERT_not_null(sym);
5317 ASSERT_not_null(iname);
5318 SgArrayType * a_type = isSgArrayType(iname->get_typeptr());
5319 if (a_type && a_type->get_dim_info())
5321 Rose_STL_Container<SgNode*> dim_ref_list = NodeQuery::querySubTree(a_type->get_dim_info(),V_SgVarRefExp);
5322 for (Rose_STL_Container<SgNode*>::iterator iter2 = dim_ref_list.begin(); iter2 != dim_ref_list.end(); iter2++)
5325 NodeList_t.push_back(dim_ref);
5335#if (INLINE_OPTIMIZED_IS_LANGUAGE_KIND_FUNCTIONS == 0)
5339#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5341 return Rose::is_Ada_language;
5343 bool returnValue =
false;
5347 int size = (int)fileList.size();
5348 for (
int i = 0; i < size; i++)
5350 if (fileList[i]->get_Ada_only() ==
true)
5361#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5363 return Rose::is_C_language;
5365 bool returnValue =
false;
5369 int size = (int)fileList.size();
5370 for (
int i = 0; i < size; i++)
5372 if (fileList[i]->get_C_only() ==
true)
5383#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5385 return Rose::is_OpenMP_language;
5387 bool returnValue =
false;
5391 int size = (int)fileList.size();
5392 for (
int i = 0; i < size; i++)
5394 if (fileList[i]->get_openmp() ==
true)
5405#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5407 return Rose::is_UPC_language;
5409 bool returnValue =
false;
5413 int size = (int)fileList.size();
5414 for (
int i = 0; i < size; i++)
5416 if (fileList[i]->get_UPC_only() ==
true)
5428#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5430 return Rose::is_CAF_language;
5432 bool returnValue =
false;
5436 int size = (int)fileList.size();
5437 for (
int i = 0; i < size; i++)
5439 if (fileList[i]->get_CoArrayFortran_only()==
true)
5452#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5454 return Rose::is_UPC_dynamic_threads;
5456 bool returnValue =
false;
5460 int size = (int)fileList.size();
5461 for (
int i = 0; i < size; i++)
5463 if (fileList[i]->get_upc_threads() > 0)
5476#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5478 return Rose::is_C99_language;
5480 bool returnValue =
false;
5484 int size = (int)fileList.size();
5485 for (
int i = 0; i < size; i++)
5487 if (fileList[i]->get_C99_only() ==
true)
5498#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5500 return Rose::is_Cxx_language;
5502 bool returnValue =
false;
5506 int size = (int)fileList.size();
5507 for (
int i = 0; i < size; i++)
5510 if (fileList[i]->get_Cxx_only() ==
true)
5512 ROSE_ASSERT(fileList[i]->get_Fortran_only() ==
false && fileList[i]->get_C99_only() ==
false && fileList[i]->get_C_only() ==
false && fileList[i]->get_binary_only() ==
false);
5525#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5527 return Rose::is_Java_language;
5529 bool returnValue =
false;
5533 int size = (int)fileList.size();
5534 for (
int i = 0; i < size; i++)
5536 if (fileList[i]->get_Java_only() ==
true)
5547#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5549 return Rose::is_Jvm_language;
5551 bool returnValue =
false;
5555 int size = (int)fileList.size();
5556 for (
int i = 0; i < size; i++)
5558 if (fileList[i]->get_Jvm_only() ==
true)
5570#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5572 return Rose::is_Jovial_language;
5574 bool returnValue =
false;
5578 int size = (int)fileList.size();
5579 for (
int i = 0; i < size; i++)
5581 if (fileList[i]->get_Jovial_only() ==
true)
5593#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5595 return Rose::is_Fortran_language;
5597 bool returnValue =
false;
5601 int size = (int)fileList.size();
5602 for (
int i = 0; i < size; i++)
5604 if (fileList[i]->get_Fortran_only() ==
true)
5616#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5618 return Rose::is_binary_executable;
5620 bool returnValue =
false;
5624 int size = (int)fileList.size();
5625 for (
int i = 0; i < size; i++)
5627 if (fileList[i]->get_binary_only() ==
true)
5638#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5640 return Rose::is_PHP_language;
5642 bool returnValue =
false;
5646 int size = (int)fileList.size();
5647 for (
int i = 0; i < size; i++)
5649 if (fileList[i]->get_PHP_only() ==
true)
5660#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5662 return Rose::is_Python_language;
5664 bool returnValue =
false;
5668 int size = (int)fileList.size();
5669 for (
int i = 0; i < size; i++)
5671 if (fileList[i]->get_Python_only() ==
true)
5682#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5684 return Rose::is_Cuda_language;
5686 bool returnValue =
false;
5690 int size = (int)fileList.size();
5691 for (
int i = 0; i < size; i++)
5693 if (fileList[i]->get_Cuda_only() ==
true)
5704#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5706 return Rose::is_OpenCL_language;
5708 bool returnValue =
false;
5712 int size = (int)fileList.size();
5713 for (
int i = 0; i < size; i++)
5715 if (fileList[i]->get_OpenCL_only() ==
true)
5763 ASSERT_not_null(functionDefinition);
5764 std::map<SgNode*,int> & scopeMap = functionDefinition->get_scope_number_list();
5767 scopeMap.erase(scopeMap.begin(),scopeMap.end());
5769 ASSERT_require(scopeMap.empty() ==
true);
5770 ASSERT_require(functionDefinition->get_scope_number_list().empty() ==
true);
5780 ROSE_ASSERT(functionDefinition != NULL);
5783 ROSE_ASSERT(functionDefinition->get_scope_number_list().empty() ==
true);
5789 ScopeNumberingTraversal() : count (0), storedFunctionDefinition(NULL) {}
5790 void visit (
SgNode* node)
5797 if (testFunctionDefinition != NULL && storedFunctionDefinition == NULL)
5799 ROSE_ASSERT(storedFunctionDefinition == NULL);
5800 storedFunctionDefinition = testFunctionDefinition;
5804 ROSE_ASSERT(storedFunctionDefinition != NULL);
5808 std::map<SgNode*,int> & scopeMap = storedFunctionDefinition->get_scope_number_list();
5809 scopeMap.insert(pair<SgNode*,int>(scope,count));
5811 string functionName = storedFunctionDefinition->get_declaration()->get_name().str();
5812 printf (
"In function = %s insert scope = %p = %s with count = %d into local map (size = %d) \n",
5813 functionName.c_str(),scope,scope->
class_name().c_str(),count,scopeMap.size());
5824 ScopeNumberingTraversal traversal;
5825 traversal.traverse(functionDefinition, preorder);
5839 ROSE_ASSERT(globalScope != NULL);
5840 std::map<SgNode*,std::string> & mangledNameCache = globalScope->get_mangledNameCache();
5843 mangledNameCache.erase(mangledNameCache.begin(),mangledNameCache.end());
5845 ROSE_ASSERT(mangledNameCache.empty() ==
true);
5846 ROSE_ASSERT(globalScope->get_mangledNameCache().empty() ==
true);
5854 ROSE_ASSERT(globalScope != NULL);
5855 ROSE_ASSERT(globalScope->get_mangledNameCache().empty() ==
true);
5861 MangledNameTraversal() : storedGlobalScope(NULL) {}
5862 void visit (
SgNode* node)
5865 if ( (mangleableNode != NULL) || (isSgGlobal(node) != NULL) )
5868 SgGlobal* testGlobalScope = isSgGlobal(mangleableNode);
5869 if (testGlobalScope != NULL && storedGlobalScope == NULL)
5871 ROSE_ASSERT(storedGlobalScope == NULL);
5872 storedGlobalScope = testGlobalScope;
5876 ROSE_ASSERT(storedGlobalScope != NULL);
5878 string mangledName = mangleableNode->get_mangled_name();
5881 std::map<SgNode*,std::string> & mangledNameCache = storedGlobalScope->get_mangledNameCache();
5882 mangledNameCache.insert(pair<SgNode*,std::string>(mangleableNode,mangledName));
5884 string nodeName =
get_name(mangleableNode);
5885 printf (
"At node = %p = %s = %s in local map (size = %d) \n",
5886 mangleableNode,mangleableNode->
class_name().c_str(),nodeName.c_str(),mangledNameCache.size());
5896 MangledNameTraversal traversal;
5897 traversal.traverse(globalScope, preorder);
5909 SgGlobal* globalScope = isSgGlobal(astNode);
5911 if (globalScope == NULL && isSgFile(astNode) != NULL)
5913 globalScope = isSgFile(astNode)->get_globalScope();
5914 ROSE_ASSERT(globalScope != NULL);
5917 if (globalScope == NULL && isSgProject(astNode) != NULL)
5920 ROSE_ASSERT( isSgProject(astNode)->get_fileList()->size() == 1 );
5921 globalScope = isSgProject(astNode)->get_fileList()->operator[](0)->get_globalScope();
5922 ROSE_ASSERT(globalScope != NULL);
5926 while (temp->
get_parent() != NULL && globalScope == NULL)
5929 globalScope = isSgGlobal(temp);
5931 ROSE_ASSERT(globalScope != NULL);
5938 std::map<SgNode*,std::string>::iterator i = mangledNameCache.find(astNode);
5941 if (i != mangledNameCache.end())
5945 mangledName = i->second;
5956#define DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE 0
5957#define DEBUG_MANGLED_SHORTNAME 1
5966#if DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE
5967 printf (
"In SageInterface::addMangledNameToCache(): TOP: astNode = %p = %s oldMangledName = %s \n",astNode,astNode->
class_name().c_str(),oldMangledName.c_str());
5971#ifdef DEBUG_MANGLED_SHORTNAME
5972 static std::unordered_map<uint64_t, std::string> mangledNameHashCollisionCheckMap;
5977 SgGlobal* globalScope = isSgGlobal(astNode);
5979 if (globalScope == NULL && isSgFile(astNode) != NULL)
5981 globalScope = isSgFile(astNode)->get_globalScope();
5982 ROSE_ASSERT(globalScope != NULL);
5985 if (globalScope == NULL && isSgProject(astNode) != NULL)
5988 ROSE_ASSERT( isSgProject(astNode)->get_fileList()->size() == 1 );
5989 globalScope = isSgProject(astNode)->get_fileList()->operator[](0)->get_globalScope();
5990 ROSE_ASSERT(globalScope != NULL);
5994 while (temp->
get_parent() != NULL && globalScope == NULL)
5997 globalScope = isSgGlobal(temp);
5999 ROSE_ASSERT(globalScope != NULL);
6004 std::string mangledName;
6006 if (SgProject::get_mangled_noshortname() ==
false) {
6009 if (oldMangledName.size() > 40) {
6010 std::map<std::string, uint64_t>::const_iterator shortMNIter = shortMangledNameCache.find(oldMangledName);
6011 uint64_t idNumber = 0;
6012 if (shortMNIter != shortMangledNameCache.end())
6014 idNumber = shortMNIter->second;
6016#ifdef DEBUG_MANGLED_SHORTNAME
6018 auto collisionIt = mangledNameHashCollisionCheckMap.find(idNumber);
6019 if(collisionIt != mangledNameHashCollisionCheckMap.end() &&
6020 oldMangledName != shortMNIter->first)
6022 mlog[Sawyer::Message::Common::ERROR] <<
" Got a short mangled name collision. \n "<<
6023 oldMangledName <<
" and \n " << shortMNIter->first <<
" \n" <<
6027 mangledNameHashCollisionCheckMap[idNumber] = oldMangledName;
6035 hasher.
insert(oldMangledName);
6038 shortMangledNameCache.insert(std::pair<std::string, uint64_t>(oldMangledName, idNumber));
6041 std::ostringstream mn;
6043 mangledName = mn.str();
6045 mangledName = oldMangledName;
6056 static unsigned long counter = 0;
6060 if (counter++ % 500 == 0)
6062 printf (
"WARNING: In SageInterface::addMangledNameToCache(): Using longer forms of mangled names (can cause some function names with embedded special characters to fail; test2004_141.C) \n");
6064 mangledName = oldMangledName;
6071 printf (
"Updating mangled name cache for node = %p = %s with mangledName = %s \n",astNode,astNode->
class_name().c_str(),mangledName.c_str());
6074#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
6080 printf (
"Warning: SageInterface::addMangledNameToCache(): In it might be premature to add this IR node and name to the mangledNameCache: statement = %p = %s oldMangledName = %s \n",
6081 statement,statement->
class_name().c_str(),oldMangledName.c_str());
6086 mangledNameCache.insert(pair<SgNode*,string>(astNode,mangledName));
6088#if DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE
6089 printf (
"In SageInterface::addMangledNameToCache(): returning mangledName = %s \n",mangledName.c_str());
6113 : storedNondefiningDeclaration(nonDefiningDeclaration),
6114 storedDefiningDeclaration(definingDeclaration)
6116 storedDeclarationFound =
false;
6117 nonDefiningDeclarationPreceedsDefiningDeclaration =
false;
6120 void visit (
SgNode* node)
6122 ROSE_ASSERT(storedNondefiningDeclaration != NULL);
6123 ROSE_ASSERT(storedDefiningDeclaration != NULL);
6124 ROSE_ASSERT(storedNondefiningDeclaration != storedDefiningDeclaration);
6132 if ( declaration != NULL )
6134 if (storedDeclarationFound ==
false)
6136 if (declaration == storedDefiningDeclaration)
6138 storedDeclarationFound =
true;
6139 nonDefiningDeclarationPreceedsDefiningDeclaration =
false;
6141 if (declaration == storedNondefiningDeclaration)
6143 storedDeclarationFound =
true;
6144 nonDefiningDeclarationPreceedsDefiningDeclaration =
true;
6151 bool storedDeclarationFound;
6152 bool nonDefiningDeclarationPreceedsDefiningDeclaration;
6159 ROSE_ASSERT(nonDefiningDeclaration != NULL);
6161 printf (
"In SageInterface::declarationPreceedsDefinition(): \n");
6162 printf (
" nondefiningDeclaration = %p = %s \n",nonDefiningDeclaration,nonDefiningDeclaration->
class_name().c_str());
6163 nonDefiningDeclaration->
get_file_info()->display(
"nonDefiningDeclaration");
6164 printf (
" nondefiningDeclaration->get_definingDeclaration() = %p \n",nonDefiningDeclaration->
get_definingDeclaration());
6165 printf (
" definingDeclaration = %p = %s \n",definingDeclaration,definingDeclaration->
class_name().c_str());
6166 definingDeclaration->
get_file_info()->display(
"definingDeclaration");
6167 printf (
"************************************************************* \n");
6174 printf (
"In SageInterface::declarationPreceedsDefinition() (warning): \n");
6175 printf (
" nondefiningDeclaration = %p \n",nonDefiningDeclaration);
6176 printf (
" nondefiningDeclaration->get_definingDeclaration() = %p \n",nonDefiningDeclaration->
get_definingDeclaration());
6177 printf (
" definingDeclaration = %p \n",definingDeclaration);
6182 bool returnResult =
false;
6183 if (nonDefiningDeclaration != definingDeclaration)
6186 SgGlobal* globalScope = TransformationSupport::getGlobalScope(definingDeclaration);
6187 ROSE_ASSERT(globalScope != NULL);
6190 DeclarationOrderTraversal traversal (nonDefiningDeclaration,definingDeclaration);
6193 traversal.traverse(globalScope, preorder);
6196 printf (
"Skipping traversal within SageInterface::declarationPreceedsDefinition() \n");
6197 traversal.storedDeclarationFound =
true;
6198 traversal.nonDefiningDeclarationPreceedsDefiningDeclaration =
false;
6205 if (traversal.storedDeclarationFound ==
false)
6208 printf (
"In SageInterface::declarationPreceedsDefinition(): warning, nonDefiningDeclaration not found in the AST \n");
6209 nonDefiningDeclaration->
get_file_info()->display(
"nonDefiningDeclaration");
6210 definingDeclaration->
get_file_info()->display(
"definingDeclaration");
6211 printf (
"---------------------------------------------------- \n\n");
6215 returnResult =
true;
6219 returnResult = traversal.nonDefiningDeclarationPreceedsDefiningDeclaration;
6225 printf (
"returnResult = %s \n",returnResult ?
"true" :
"false");
6226 printf (
"************************************************************* \n\n");
6228 return returnResult;
6245 : storedFunctionCall(functionCall)
6247 ROSE_ASSERT(functionCall != NULL);
6248 ROSE_ASSERT(functionCall->get_function() != NULL);
6249 SgExpression* functionExpression = functionCall->get_function();
6251 switch (functionExpression->
variantT())
6257 case V_SgArrowStarOp:
6258 case V_SgPointerDerefExp:
6261 printf (
"These are the acceptable cases, but not handled yet... \n");
6265 case V_SgFunctionRefExp:
6268 ROSE_ASSERT(functionRefExp != NULL);
6270 ROSE_ASSERT(functionSymbol != NULL);
6273 ROSE_ASSERT(functionSymbol->get_declaration() != NULL);
6274 storedFunctionDeclaration = functionSymbol->get_declaration();
6278 case V_SgMemberFunctionRefExp:
6281 ROSE_ASSERT(memberFunctionRefExp != NULL);
6283 ROSE_ASSERT(memberFunctionSymbol != NULL);
6285 storedFunctionDeclaration = memberFunctionSymbol->get_declaration();
6287 printf (
"V_SgMemberFunctionRefExp case not handled yet... \n");
6293 printf (
"default reached in SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope() functionExpression = %s \n",
6301 ROSE_ASSERT(storedFunctionDeclaration != NULL);
6303 storedFunctionCallFound =
false;
6307 void visit (
SgNode* node)
6309 ROSE_ASSERT(storedFunctionCall != NULL);
6310 ROSE_ASSERT(storedFunctionDeclaration != NULL);
6313 if (storedFunctionCallFound ==
false)
6316 if ( functionCall != NULL )
6318 if (functionCall == storedFunctionCall)
6320 storedFunctionCallFound =
true;
6330 ROSE_ASSERT(storedFunctionDeclaration != NULL);
6343 storedFunctionCallFound =
true;
6349 printf (
"Found a declaration which preceeds the function \n");
6350 declaration->
get_file_info()->display(
"Found a declaration which preceeds the function: declaration");
6351 storedFunctionCall->get_file_info()->display(
"Found a declaration which preceeds the function: storedFunctionCall");
6352 storedFunctionDeclaration->get_file_info()->display(
"Found a declaration which preceeds the function: storedFunctionDeclaration");
6358 if (parentScopeOfDeclaration == NULL)
6361 printf (
"Strange case of parentScopeOfDeclaration == NULL in SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope() \n");
6363 if (parent != NULL) {
6364 printf (
"declaration->get_parent() = %s \n",parent->
class_name().c_str());
6367 printf (
"declaration->get_parent() = NULL \n");
6369 declaration->
get_file_info()->display(
"case of parentScopeOfDeclaration == NULL");
6378 bool storedFunctionCallFound;
6386 ROSE_ASSERT(functionCall != NULL);
6388 printf (
"In SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope(): \n");
6389 printf (
" storedFunctionCall = %p = %s \n",functionCall,functionCall->
class_name().c_str());
6390 functionCall->
get_file_info()->display(
"storedFunctionCall");
6391 printf (
" storedFunctionCall->get_function() = %p = %s \n",functionCall->get_function(),functionCall->get_function()->
class_name().c_str());
6392 printf (
"************************************************************* \n");
6396 bool returnResult =
false;
6399 SgGlobal* globalScope = TransformationSupport::getGlobalScope(functionCall);
6400 ROSE_ASSERT(globalScope != NULL);
6403 DeclarationOrderTraversal traversal (functionCall);
6406 traversal.traverse(globalScope, preorder);
6409 printf (
"Skipping traversal within SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope() \n");
6410 traversal.storedFunctionCallFound =
true;
6411 traversal.functionCallExpressionPreceedsDeclarationWhichAssociatesScope =
false;
6418 if (traversal.storedFunctionCallFound ==
false)
6421 printf (
"In SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope(): warning, storedFunctionCall not found in the AST \n");
6423 printf (
"---------------------------------------------------- \n\n");
6428 returnResult =
true;
6432 returnResult = traversal.functionCallExpressionPreceedsDeclarationWhichAssociatesScope;
6436 ROSE_ASSERT(traversal.storedFunctionCallFound ==
true);
6438 printf (
"returnResult = %s \n",returnResult ?
"true" :
"false");
6439 printf (
"************************************************************* \n\n");
6441 return returnResult;
6462 ROSE_ASSERT(project != NULL);
6469 Rose_STL_Container<string>::iterator i = fileList.begin();
6472 if ( fileList.empty() ==
true )
6474 return "empty_file_list";
6478 string filename = *i;
6484 if (i != fileList.begin())
6485 projectName +=
"--";
6489 string filenameWithoutSuffix;
6490 if ( i != fileList.end() || supressSuffix ==
true )
6493 filenameWithoutSuffix = filename;
6500 filename = filenameWithoutPathOrSuffix;
6502 unsigned long int n = 0;
6503 while (n < filename.size())
6505 if (filename[n] ==
'/')
6512 projectName += filename;
6516 while (i != fileList.end());
6535 if (currentScope == NULL)
6537 ROSE_ASSERT(currentScope != NULL);
6540 while ((functionSymbol == NULL) && (tempScope != NULL))
6542 functionSymbol = tempScope->lookup_function_symbol(functionName);
6544 printf (
"In lookupFunctionSymbolInParentScopes(): Searching scope = %p = %s functionName = %s functionSymbol = %p \n",tempScope,tempScope->
class_name().c_str(),functionName.str(),functionSymbol);
6547 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6551 return functionSymbol;
6562 if (currentScope == NULL)
6564 ROSE_ASSERT(currentScope != NULL);
6567 while ((functionSymbol == NULL) && (tempScope != NULL))
6569 functionSymbol = tempScope->lookup_template_function_symbol(functionName, ftype, tplparams);
6571 printf (
"In lookupTemplateFunctionSymbolInParentScopes(): Searching scope = %p = %s functionName = %s functionSymbol = %p \n",tempScope,tempScope->
class_name().c_str(),functionName.str(),functionSymbol);
6574 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6578 return functionSymbol;
6589 if (currentScope == NULL)
6591 ROSE_ASSERT(currentScope != NULL);
6594 while ((functionSymbol == NULL) && (tempScope != NULL))
6596 functionSymbol = tempScope->lookup_template_member_function_symbol(functionName, ftype, tplparams);
6598 printf (
"In lookupTemplateMemberFunctionSymbolInParentScopes(): Searching scope = %p = %s functionName = %s functionSymbol = %p \n",tempScope,tempScope->
class_name().c_str(),functionName.str(),functionSymbol);
6601 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6605 return functionSymbol;
6613 if (isSgType(astNode) != NULL)
6615 printf (
"Error: the mechanism to add text to be unparsed at IR nodes is not intended to operate on SgType IR nodes (since they are shared) \n");
6619 if (astNode->
attributeExists(AstUnparseAttribute::markerName) ==
true)
6621 AstUnparseAttribute* code =
dynamic_cast<AstUnparseAttribute*
>(astNode->
getAttribute(AstUnparseAttribute::markerName));
6622 ROSE_ASSERT(code != NULL);
6626 code->addString(s,inputlocation);
6635 AstUnparseAttribute* code =
new AstUnparseAttribute(s,inputlocation);
6636 ROSE_ASSERT(code != NULL);
6653 ROSE_ASSERT(cscope != NULL);
6655 while ((cscope != NULL) && (symbol == NULL))
6658 symbol = cscope->lookup_class_symbol(name,NULL);
6661 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6692 if (currentScope == NULL)
6694 ROSE_ASSERT(currentScope != NULL);
6696 while (functionSymbol == NULL && tempScope != NULL)
6698 functionSymbol = tempScope->lookup_function_symbol(functionName,t);
6700 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6701 else tempScope = NULL;
6703 return functionSymbol;
6710 if (cscope ==
nullptr) {
6713 ASSERT_not_null(cscope);
6715 while ((cscope !=
nullptr) && (symbol ==
nullptr))
6717 symbol = cscope->lookup_symbol(name,templateParameterList,templateArgumentList);
6719 cscope = isSgGlobal(cscope) ? nullptr : cscope->
get_scope();
6738 if (currentScope == NULL)
6743 ROSE_ASSERT(currentScope != NULL);
6745#define DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS 0
6747#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6748 printf (
"In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): currentScope = %p = %s (templateParameterList = %p templateArgumentList = %p) \n",
6749 currentScope,currentScope->
class_name().c_str(),templateParameterList,templateArgumentList);
6752 while ((currentScope != NULL) && (symbol == NULL))
6754#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6755 printf(
" --- In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): name = %s currentScope = %p = %s \n",
6756 name.str(),currentScope,currentScope->
class_name().c_str());
6761 symbol = currentScope->lookup_symbol(name,templateParameterList,templateArgumentList);
6763 if (isSgAliasSymbol(symbol) != NULL)
6765#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6766 printf (
"Found a SgAliasSymbol: reset to NULL: symbol = %p = %s \n",symbol,symbol->
class_name().c_str());
6771#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS && 1
6773 printf(
" --- In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): symbol = %p \n",symbol);
6774 currentScope->print_symboltable(
"In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): debug");
6777 currentScope = isSgGlobal(currentScope) ? NULL : currentScope->
get_scope();
6779 currentScope = NULL;
6781#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6782 printf (
" --- In SageInterface:: (base of loop) lookupSymbolInParentScopesIgnoringAliasSymbols(): cscope = %p symbol = %p \n\n",currentScope,symbol);
6788#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6789 printf (
"Warning: In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): could not locate the specified name %s in any outer symbol table (templateParameterList = %p templateArgumentList = %p) \n",
6790 name.str(),templateParameterList,templateArgumentList);
6796 printf (
"Support for lookupSymbolInParentScopesIgnoringAliasSymbols() is not yet implemented \n");
6818 ROSE_ASSERT(cscope);
6820 while ((cscope!=NULL)&&(symbol==NULL))
6822 symbol = cscope->lookup_symbol(name);
6826 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6852 printf (
"WARNING: SageInterface::lookupVariableSymbolInParentScopes() should be implemented similar to SageInterface::lookupClassSymbolInParentScopes() \n");
6858 if (isSgAliasSymbol(symbol) != NULL)
6860 printf (
"Error: This SageInterface::lookupVariableSymbolInParentScopes() function does not handle SgAliasSymbols \n");
6863 result = isSgVariableSymbol(symbol);
6871 ROSE_ASSERT(cscope != NULL);
6873 while ((cscope != NULL) && (symbol == NULL))
6876 symbol = cscope->lookup_variable_symbol(name);
6879 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6888#define DEBUG_LOOKUP_TEMPLATE_VARIABLE 0
6893#if DEBUG_LOOKUP_TEMPLATE_VARIABLE
6894 printf (
"In SageInterface::lookupTemplateVariableSymbolInParentScopes():\n");
6895 printf (
" -- name = %s\n", name.str());
6896 printf (
" -- tplparams = %p [%zd]\n", tplparams, tplparams ? tplparams->size() : 0);
6897 printf (
" -- tplargs = %p [%zd]\n", tplargs, tplargs ? tplargs->size() : 0);
6898 printf (
" -- cscope = %p (%s)\n", cscope, cscope ? cscope->
class_name().c_str() :
"");
6904 ROSE_ASSERT(cscope != NULL);
6906 while ((cscope != NULL) && (symbol == NULL))
6909 symbol = cscope->lookup_template_variable_symbol(name, tplparams, tplargs);
6912 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6928 ROSE_ASSERT(cscope != NULL);
6930 while ((cscope != NULL) && (symbol == NULL))
6934 symbol = cscope->lookup_class_symbol(name,templateArgumentList);
6937 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6951 ROSE_ASSERT(cscope != NULL);
6953 while ((cscope != NULL) && (symbol == NULL))
6955 symbol = cscope->lookup_nonreal_symbol(name,templateParameterList,templateArgumentList);
6958 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6973 ROSE_ASSERT(cscope != NULL);
6976 printf (
"In lookupTypedefSymbolInParentScopes(): name = %s starting with cscope = %p = %s \n",name.str(),cscope,cscope->
class_name().c_str());
6980 while ((cscope != NULL) && (symbol == NULL))
6983 symbol = cscope->lookup_typedef_symbol(name);
6986 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6991 printf (
"In lookupTypedefSymbolInParentScopes(): symbol = %p next cscope = %p = %s \n",symbol,cscope,(cscope != NULL) ? cscope->
class_name().c_str() :
"null");
6996 printf (
"Leaving lookupTypedefSymbolInParentScopes(): symbol = %p \n",symbol);
7014 ROSE_ASSERT(cscope != NULL);
7016 while ((cscope != NULL) && (symbol == NULL))
7022 symbol = cscope->lookup_template_symbol(name,NULL,NULL);
7024 printf (
"In lookupTemplateSymbolInParentScopes(): Searching scope = %p = %s name = %s symbol = %p \n",cscope,cscope->
class_name().c_str(),name.str(),symbol);
7027 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7044 ROSE_ASSERT(cscope != NULL);
7046 while ((cscope != NULL) && (symbol == NULL))
7052 symbol = cscope->lookup_template_class_symbol(name,templateParameterList,templateArgumentList);
7054 printf (
"In lookupTemplateSymbolInParentScopes(): Searching scope = %p = %s name = %s symbol = %p \n",cscope,cscope->
class_name().c_str(),name.str(),symbol);
7057 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7074 ROSE_ASSERT(cscope != NULL);
7076 while ((cscope != NULL) && (symbol == NULL))
7079 symbol = cscope->lookup_enum_symbol(name);
7082 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7097 ROSE_ASSERT(cscope != NULL);
7099 while ((cscope != NULL) && (symbol == NULL))
7102 symbol = cscope->lookup_namespace_symbol(name);
7105 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7115SageInterface::setSourcePositionToDefault( T* node )
7133 ROSE_ASSERT(node != NULL);
7136 if (node->get_endOfConstruct() == NULL && node->get_startOfConstruct() == NULL)
7139 printf (
"Both startOfConstruct and endOfConstruct are NOT yet initialized with pointers to Sg_File_Info objects (node = %p = %s) \n",node,node->class_name().c_str());
7142 ROSE_ASSERT(node->get_endOfConstruct() == NULL);
7143 ROSE_ASSERT(node->get_startOfConstruct() == NULL);
7150 printf (
"In SageInterface::setSourcePositionToDefault(): Calling setSourcePositionUnavailableInFrontend() \n");
7152 start_fileInfo->setSourcePositionUnavailableInFrontend();
7153 end_fileInfo->setSourcePositionUnavailableInFrontend();
7157 printf (
"In SageInterface::setSourcePositionToDefault(): Calling setOutputInCodeGeneration() \n");
7163 node->set_startOfConstruct(start_fileInfo);
7164 node->set_endOfConstruct (end_fileInfo);
7166 node->get_startOfConstruct()->set_parent(node);
7167 node->get_endOfConstruct ()->set_parent(node);
7174 printf (
"Both startOfConstruct and endOfConstruct are ALREADY initialized with pointers to Sg_File_Info objects (node = %p = %s) \n",node,node->class_name().c_str());
7176 if (node->get_startOfConstruct() == NULL)
7178 printf (
"ERROR: startOfConstruct not set for locatedNode = %p = %s \n",node,node->class_name().c_str());
7180 if (node->get_endOfConstruct() == NULL)
7182 printf (
"ERROR: endOfConstruct not set for locatedNode = %p = %s \n",node,node->class_name().c_str());
7185 ROSE_ASSERT(node->get_startOfConstruct() != NULL);
7186 ROSE_ASSERT(node->get_endOfConstruct() != NULL);
7187 ROSE_ASSERT(node->get_endOfConstruct() != NULL && node->get_startOfConstruct() != NULL);
7208 if (expression != NULL)
7211 SgBinaryOp* binaryOp = isSgBinaryOp(expression);
7212 if (binaryOp != NULL)
7214 if (binaryOp->get_operatorPosition() == NULL)
7217 operator_fileInfo->setSourcePositionUnavailableInFrontend();
7219 binaryOp->set_operatorPosition(operator_fileInfo);
7222 binaryOp->get_operatorPosition()->
set_parent(binaryOp);
7227 if (expression->get_operatorPosition() == NULL)
7230 operator_fileInfo->setSourcePositionUnavailableInFrontend();
7232 expression->set_operatorPosition(operator_fileInfo);
7237 ROSE_ASSERT(expression->get_operatorPosition()->
get_parent() == expression);
7248#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
7249 printf (
"+++++ Depricated function (use setSourcePositionAsTransformation() instead) (no using internal source position mode) \n");
7268 ROSE_ASSERT(node != NULL);
7277 SgPragma* pragma = isSgPragma(node);
7278 SgGlobal* global = isSgGlobal(node);
7283 printf (
"Debug, Found a variable definition: %p\n", v_d);
7286 if (locatedNode != NULL)
7298 if (expression!=NULL)
7301 expression->get_operatorPosition()->
set_parent(expression);
7320 printf (
"+++++ Depricated name setOneSourcePositionNull() (use setSourcePositionPointersToNull() instead) (no using internal source position mode) \n");
7338 ROSE_ASSERT(node != NULL);
7342 SgPragma* pragma = isSgPragma(node);
7343 SgGlobal* global = isSgGlobal(node);
7349 if (locatedNode != NULL)
7352 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of startOfConstruct Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7360 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of endOfConstruct Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7366 if (expression != NULL)
7368 if (expression->get_operatorPosition() != NULL)
7369 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of operatorPosition Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7371 expression->set_operatorPosition(NULL);
7378 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7380 pragma->set_startOfConstruct(NULL);
7391 printf (
"+++++ Depricated name setSourcePositionForTransformation() (use setSourcePositionAtRootAndAllChildrenAsTransformation() instead) \n");
7404 Rose_STL_Container <SgNode*> nodeList = NodeQuery::querySubTree(root,V_SgNode);
7405 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i!=nodeList.end(); i++ )
7416SageInterface::setSourcePositionAtRootAndAllChildrenAsTransformation(
SgNode *root)
7418 Rose_STL_Container <SgNode*> nodeList= NodeQuery::querySubTree(root,V_SgNode);
7419 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i!=nodeList.end(); i++ )
7428SageInterface::setSourcePositionAtRootAndAllChildrenAsDefault(
SgNode *root)
7430 Rose_STL_Container <SgNode*> nodeList= NodeQuery::querySubTree(root,V_SgNode);
7431 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i!=nodeList.end(); i++ )
7433 setSourcePositionAsDefault(*i);
7443 Rose_STL_Container <SgNode*> nodeList = NodeQuery::querySubTree(root,V_SgNode);
7446 printf (
"In setSourcePositionAtRootAndAllChildren(): nodeList.size() = %" PRIuPTR
" \n",nodeList.size());
7449 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
7452 printf (
"In setSourcePositionAtRootAndAllChildren(): *i = %p = %s \n",*i,(*i)->class_name().c_str());
7471 printf (
"In SageInterface::setSourcePosition(): SourcePositionClassification scp = %s \n",
display(scp).c_str());
7476 case e_sourcePositionError:
7478 printf (
"Error: error value e_sourcePositionError in SageInterface::setSourcePosition() \n");
7485 printf (
"e_sourcePositionDefault in SageInterface::setSourcePosition() \n");
7488 if (locatedNode != NULL)
7490 setSourcePositionToDefault(locatedNode);
7495 printf (
"Error: can't call setSourcePosition() in mode e_sourcePositionDefault with non SgLocatedNode (node = %p = %s) \n",node,node->
class_name().c_str());
7504 printf (
"e_sourcePositionTransformation in SageInterface::setSourcePosition() \n");
7513 printf (
"e_sourcePositionCompilerGenerated in SageInterface::setSourcePosition() \n");
7515 printf (
"Sorry, not implemented \n");
7524 printf (
"e_sourcePositionNullPointers in SageInterface::setSourcePosition() \n");
7541 printf (
"e_sourcePositionFrontendConstruction in SageInterface::setSourcePosition() \n");
7544 if (locatedNode != NULL)
7547 setSourcePositionToDefault(locatedNode);
7552 SgPragma* pragma = isSgPragma(node);
7555 setSourcePositionToDefault(pragma);
7561 SgType* type = isSgType(node);
7569 if (functionParameterTypeList != NULL)
7575 printf (
"Error: can't call setSourcePosition() in mode e_sourcePositionFrontendConstruction with non SgLocatedNode (node = %p = %s) \n",node,node->
class_name().c_str());
7588 printf (
"Error: error value e_sourcePositionError in SageInterface::setSourcePosition() \n");
7594 printf (
"Error: default reached in SageInterface::setSourcePosition() \n");
7602 node->
get_file_info()->display(
"Leaving SageInterface::setSourcePosition()");
7609SageInterface::setSourcePositionForTransformation_memoryPool()
7614 printf (
"ERROR: In setSourcePositionForTransformation_memoryPool(): This seems like a very dangerous function to have, is it required? \n");
7617 VariantVector vv(V_SgNode);
7618 Rose_STL_Container<SgNode*> nodeList = NodeQuery::queryMemoryPool(vv);
7619 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++ )
7630 ROSE_ASSERT(project != NULL);
7633 ROSE_ASSERT(project->get_fileList().empty() ==
false);
7636 SgSourceFile* file = isSgSourceFile(project->get_fileList()[0]);
7637 SgGlobal* global = file->get_globalScope();
7640 SgFilePtrListPtr fileList = project->get_fileList();
7641 SgFilePtrList::const_iterator i= fileList->begin();
7643 SgGlobal* global = (*i)->get_globalScope();
7645 ROSE_ASSERT(global != NULL);
7666 if (declList.empty() ==
false)
7668 stmt = isSgStatement(declList.back());
7677 if (stmtList.empty() ==
false)
7679 stmt = stmtList.back();
7701 if (includingCompilerGenerated)
7705 if (declList.empty() ==
false)
7707 stmt = isSgStatement(declList.front());
7713 SgDeclarationStatementPtrList::iterator i=declList.begin();
7714 while (i != declList.end())
7741 if (includingCompilerGenerated)
7745 if (stmtList.empty() ==
false)
7747 stmt = stmtList.front();
7753 SgStatementPtrList::iterator i = stmtList.begin();
7754 while (i!=stmtList.end())
7789 SgDeclarationStatementPtrList::iterator i=declList.begin();
7790 while (i!=declList.end())
7814 SgStatementPtrList::iterator i=stmtList.begin();
7815 while (i!=stmtList.end())
7842 bool result =
false;
7845 if (isSgProgramHeaderStatement(n)) {
7850 if (isSgFunctionDeclaration(n) !=
nullptr) {
7851 bool either =
false;
7857 ROSE_ASSERT(stmnt !=
nullptr);
7864 ROSE_ASSERT(funcDefn !=
nullptr);
7865 if (funcDefn->get_name() ==
"main") {
7889 return isSgFunctionDeclaration(n);
7892 for (vector<SgNode*>::const_iterator i = children.begin();
7893 i != children.end(); ++i) {
7911 ROSE_ASSERT (scope != NULL);
7915 for (
size_t i = 0; i<stmt_list.size(); i++)
7919 if (isSgDeclarationStatement(cur_stmt))
7921 if (isSgPragmaDeclaration (cur_stmt))
7941 rt = n->copy (g_treeCopy);
7951 bool isC = TransformationSupport::getSourceFile(n)->get_outputLanguage() ==
SgFile::e_C_language;
7963#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
7965 for (std::vector<SgContinueStmt*>::iterator i = continues.begin(); i != continues.end(); ++i)
7970 LowLevelRewrite::replace(*i, make_unit_list( gotoStatement ) );
7976 printf (
"Not supported in mode: ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT (LowLevelRewrite::replace() is unavailable)");
7981#define DEBUG_TEMPLATE_ARG_EQUIVALENCE 0
7987#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7988 printf (
"In templateArgumentEquivalence(): same pointer to template argument: returning true \n");
7995#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7996 printf (
"In templateArgumentEquivalence(): different argumentType(): returning false \n");
8005 ROSE_ASSERT(arg1->
get_type() != NULL);
8006 ROSE_ASSERT(arg2->
get_type() != NULL);
8008#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8009 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::type_argument: checking for the same type: arg1->get_type() = %p = %s arg2->get_type() = %p = %s \n",
8017#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8018 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::type_argument: checking for the same type: returning true \n");
8031#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8032 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::type_argument: checking for the same type: pointers are different: returning typesAreEqual = %s \n",typesAreEqual ?
"true" :
"false");
8034 return typesAreEqual;
8042 if (expr1 == expr2) {
8043#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8044 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: checking for the same expression: returning true \n");
8048#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8049 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: same variant of expression: %s\n", expr1->
class_name().c_str());
8052 case V_SgLongIntVal: {
8056 printf (
"FATAL: In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: expression have the same variant %s but comparison is not NIY!\n", expr1->
class_name().c_str());
8061#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8062 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: different variant of expression: returning false \n");
8070 if (arg1->get_templateDeclaration() == arg2->get_templateDeclaration())
8072#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8073 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::template_template_argument: checking for the same templateDeclaration: returning true \n");
8079 ROSE_ASSERT(!
"NIY: template template argument comparaison.");
8085 ROSE_ASSERT(!
"Try to compare template arguments of unknown type...");
8094 ROSE_ASSERT(!
"Try to compare template arguments of unknown type start_of_pack_expansion_argument");
8100 printf (
"Error: default case not handled! \n");
8108#define DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE 0
8112 if (list1.size() != list2.size())
8114#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8115 printf (
"In templateArgumentListEquivalence(): different list sizes: returning false \n");
8116 printf (
" --- list1.size() = %zu \n",list1.size());
8117 printf (
" --- list2.size() = %zu \n",list2.size());
8124#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8125 printf (
"In templateArgumentListEquivalence(): same list using STL equality operator: returning true \n");
8131 for (
size_t i = 0; i < list1.size(); i++)
8133#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8134 printf (
"In templateArgumentListEquivalence(): calling templateArgumentEquivalence() for i = %zu \n",i);
8139#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8140 printf (
"In templateArgumentListEquivalence(): calling templateArgumentEquivalence() for i = %zu --- returned false: returning false \n",i);
8146#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8147 printf (
"In templateArgumentListEquivalence(): reached base of function: returning true \n");
8167 SgName labelname =
"rose_label__";
8180 if (isSgNullExpression(f->get_increment()))
return;
8185 f->set_increment(ne);
8195 ROSE_ASSERT(condstmt);
8197 if (isSgNullStatement(condstmt))
return true;
8201 return isSgNullExpression(exprStmt->get_expression());
8210 bbStmts = initStmts;
8211 for (
size_t i = 0; i < bbStmts.size(); ++i) {
8212 bbStmts[i]->set_parent(bb);
8215 const bool testIsNull = hasEmptyCondition(f);
8225 Rose_STL_Container<SgNode*> fors = NodeQuery::querySubTree(top,
8227 for (
size_t i = 0; i < fors.size(); ++i) {
8235 Rose_STL_Container<SgNode*> allGotos = NodeQuery::querySubTree(scope, V_SgGotoStatement);
8237 vector<SgGotoStatement*> result;
8238 for (Rose_STL_Container<SgNode*>::const_iterator i = allGotos.begin(); i != allGotos.end(); ++i) {
8239 if (isSgGotoStatement(*i)->
get_label() == l) {
8240 result.push_back(isSgGotoStatement(*i));
8248 vector<SgReturnStmt*> SageInterface::findReturnStmts(
SgStatement* scope) {
8251 Rose_STL_Container<SgNode*> returns = NodeQuery::querySubTree(scope, V_SgReturnStmt);
8253 vector<SgReturnStmt*> result;
8254 for (Rose_STL_Container<SgNode*>::const_iterator i = returns.begin(); i != returns.end(); ++i) {
8255 result.push_back(isSgReturnStmt(*i));
8261static void getSwitchCasesHelper(
SgStatement* top, vector<SgStatement*>& result) {
8263 if (isSgSwitchStatement(top))
return;
8264 if (isSgCaseOptionStmt(top) || isSgDefaultOptionStmt(top)) {
8265 result.push_back(top);
8268 for (
unsigned int i = 0; i < children.size(); ++i) {
8269 if (isSgStatement(children[i])) {
8270 getSwitchCasesHelper(isSgStatement(children[i]), result);
8276 vector<SgStatement*> result;
8277 getSwitchCasesHelper(sw->
get_body(), result);
8307 if (
const SgSymbol* symbol = isSgSymbol(astNode))
8308 return symbol->get_scope();
8313 else if (
const SgQualifiedName* qualifiedName = isSgQualifiedName(astNode))
8317 const SgNode* parentNode = astNode;
8318 while (!isSgScopeStatement(parentNode))
8323 if (isSgFunctionParameterList(parentNode) || isSgCtorInitializerList(parentNode))
8326 ROSE_ASSERT(funcDeclaration != NULL);
8328 if (funcDeclaration != NULL)
8330 return funcDeclaration->get_definition();
8335 if (parentNode == NULL)
8343 if ( isSgScopeStatement(parentNode) == NULL &&
8344 dynamic_cast<const SgType*
>(parentNode) == NULL &&
8345 dynamic_cast<const SgSymbol*
>(parentNode) == NULL )
8347 printf (
"Error: In SageInterface::getScope(): could not trace back to SgScopeStatement node \n");
8352 if (
dynamic_cast<const SgType*
>(parentNode) != NULL ||
dynamic_cast<const SgSymbol*
>(parentNode) != NULL )
8354 printf (
"Error: can't locate an associated SgStatement from astNode = %p = %s parentNode = %p = %s \n",astNode,astNode->
class_name().c_str(),parentNode,parentNode->
class_name().c_str());
8362 ROSE_ASSERT (scopeStatement != NULL);
8365 if (isSgScopeStatement(astNode))
8366 if (isSgScopeStatement(parentNode))
8368 ROSE_ASSERT (astNode == parentNode);
8395 printf (
"In getVarSymFromName(): name->get_name() = %s \n",name->get_name().str());
8398 ROSE_ASSERT (scope != NULL);
8400 printf (
"In getVarSymFromName(): name->get_name() = %s scope = %p = %s \n",name->get_name().str(),scope,scope->
class_name().c_str());
8402 v_sym = scope->lookup_var_symbol (name->get_name());
8411 if (decl_scope != NULL)
8412 v_sym = decl_scope->lookup_var_symbol (name->get_name());
8415 cerr <<
"\t\t*** WARNING: Can't seem to find a symbol for '"
8416 << name->get_name ().str ()
8446getVarSym_const (
const SgNode* n)
8452 v_sym = isSgVarRefExp (n)->get_symbol ();
8454 case V_SgInitializedName:
8455 v_sym = getVarSymFromName_const (isSgInitializedName (n));
8481 if (!decl)
return 0;
8482 const SgInitializedNamePtrList& names = decl->
get_variables ();
8483 if (names.begin () != names.end ())
8486 return getVarSym_const (name);
8505 if (names.begin () != names.end ())
8506 return *(names.begin ());
8512static void findBreakStmtsHelper(
SgStatement* code,
const std::string& fortranLabel,
bool inOutermostBody, vector<SgBreakStmt*>& breakStmts) {
8513 if (isSgWhileStmt(code) || isSgDoWhileStmt(code) || isSgForStatement(code) || isSgSwitchStatement(code)) {
8514 if (fortranLabel ==
"") {
8519 inOutermostBody =
false;
8522 if (isSgBreakStmt(code)) {
8524 bool breakMatchesThisConstruct =
false;
8525 if (bs->get_do_string_label() ==
"") {
8527 breakMatchesThisConstruct = inOutermostBody;
8529 breakMatchesThisConstruct = (fortranLabel == bs->get_do_string_label());
8531 if (breakMatchesThisConstruct) {
8532 breakStmts.push_back(bs);
8537 for (
unsigned int i = 0; i < children.size(); ++i) {
8538 if (isSgStatement(children[i])) {
8539 findBreakStmtsHelper(isSgStatement(children[i]), fortranLabel, inOutermostBody, breakStmts);
8547 vector<SgBreakStmt*> result;
8548 findBreakStmtsHelper(code, fortranLabel,
true, result);
8553static void findContinueStmtsHelper(
SgStatement* code,
const std::string& fortranLabel,
bool inOutermostBody, vector<SgContinueStmt*>& continueStmts) {
8554 if (isSgWhileStmt(code) || isSgDoWhileStmt(code) || isSgForStatement(code)) {
8555 if (fortranLabel ==
"") {
8560 inOutermostBody =
false;
8563 if (isSgContinueStmt(code)) {
8565 bool continueMatchesThisConstruct =
false;
8566 if (cs->get_do_string_label() ==
"") {
8568 continueMatchesThisConstruct = inOutermostBody;
8570 continueMatchesThisConstruct = (fortranLabel == cs->get_do_string_label());
8572 if (continueMatchesThisConstruct) {
8573 continueStmts.push_back(cs);
8578 for (
unsigned int i = 0; i < children.size(); ++i) {
8580 if (stmnt != NULL) {
8581 findContinueStmtsHelper(stmnt, fortranLabel, inOutermostBody, continueStmts);
8589 vector<SgContinueStmt*> result;
8590 findContinueStmtsHelper(code, fortranLabel,
true, result);
8601 std::cout <<
"Starting getInitializerOfExpression on 0x" << std::hex << (int)n <<
", which has type " << n->
sage_class_name() << std::endl;
8603 while (!isSgInitializer(n)) {
8606 std::cout <<
"Continuing getInitializerOfExpression on 0x" << std::hex << (int)n;
8608 std::cout << std::endl;
8612 return isSgInitializer(n);
8620 std::vector<SgVariableSymbol*> symbols;
8622 virtual void visit(
SgNode* n) {
8623 if (isSgVarRefExp(n))
8624 symbols.push_back(isSgVarRefExp(n)->get_symbol());
8628 GetSymbolsUsedInExpressionVisitor vis;
8629 vis.traverse(expr, preorder);
8636 return getEnclosingNode<SgSourceFile>(n, includingSelf);
8642 return findDeclarationStatement<SgFunctionDeclaration> (root, name, scope, isDefining);
8653 return getEnclosingNode<SgFunctionDefinition>(n, includingSelf);
8659 return getEnclosingNode<SgFunctionDeclaration>(astNode, includingSelf);
8669 return getEnclosingNode<SgGlobal>(astNode,
true );
8674 return getEnclosingNode<SgClassDefinition>(astNode, includingSelf);
8682 return getEnclosingNode<SgClassDeclaration>(astNode,
true);
8687 return getEnclosingNode<SgExprListExp>(astNode, includingSelf);
8693 bool returnValue =
false;
8699 virtual void visit(
SgNode* n)
8701 if (n == expression_target)
8707 Visitor(
SgExpression* expr) : expression_target(expr), in_subtree(
false) {}
8710 Visitor traversal(exp);
8712 traversal.traverse(subtree, preorder);
8714 returnValue = traversal.in_subtree;
8728 ROSE_ASSERT (functionCallExp != NULL);
8730 SgExpression* expression = functionCallExp->get_function();
8731 ROSE_ASSERT (expression != NULL);
8735 SgDotExp* dotExp = isSgDotExp(expression);
8738 ROSE_ASSERT (dotExp != NULL);
8741 ROSE_ASSERT (rhsOperand != NULL);
8746 if (memberFunctionRefExp != NULL)
8753 if (functionReferenceExp != NULL)
8758 SgArrowExp* arrowExp = isSgArrowExp(expression);
8759 if ( arrowExp != NULL)
8761 ROSE_ASSERT (arrowExp != NULL);
8764 ROSE_ASSERT (rhsOperand != NULL);
8769 if (memberFunctionRefExp != NULL)
8775 return returnDeclaration;
8780std::list<SgClassType*>
8785#define DEBUG_DATA_MEMBER_TYPE_CHAIN 0
8791 ROSE_ASSERT(varRefExp != NULL || memberFunctionRefExp != NULL);
8793 std::list<SgClassType*> returnTypeChain;
8796 std::list<SgClassType*> classChain;
8801 if (varRefExp != NULL)
8807 ROSE_ASSERT(memberFunctionRefExp != NULL);
8812 ROSE_ASSERT(parent != NULL);
8814#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8815 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): parent = %p = %s \n",parent,parent->
class_name().c_str());
8819 SgDotExp* dotExp = isSgDotExp(parent);
8823 if (arrowExp != NULL)
8825#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8826 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): Found an arrow expression \n");
8828 binaryOperator = arrowExp;
8833#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8834 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): Found an dot expression \n");
8836 binaryOperator = dotExp;
8840 if (binaryOperator != NULL)
8843 ROSE_ASSERT(lhs != NULL);
8845#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8846 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs = %p = %s \n",lhs,lhs->
class_name().c_str());
8852 while (isSgCastExp(temp_lhs) != NULL)
8854 cast = isSgCastExp(temp_lhs);
8855 ROSE_ASSERT(cast != NULL);
8858#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8859 printf (
"Top of loop: processing cast = %p temp_lhs = %p = %s \n",cast,temp_lhs,temp_lhs->
class_name().c_str());
8861 ROSE_ASSERT(cast->
get_type() != NULL);
8863 if (classType == NULL)
8865#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8866 printf (
" --- looking for base type: In SageInterface::getClassTypeChainForDataMemberReference(): classType == NULL: cast->get_type() = %p = %s \n",
8869 SgType* baseType = cast->
get_type()->
stripType(SgType::STRIP_POINTER_TYPE | SgType::STRIP_MODIFIER_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE | SgType::STRIP_TYPEDEF_TYPE);
8870 ROSE_ASSERT(baseType != NULL);
8872#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8873 printf (
" --- baseType = %p = %s name = %s \n",baseType,baseType->
class_name().c_str(),
get_name(baseType).c_str());
8875 classType = isSgClassType(baseType);
8879 ROSE_ASSERT(temp_lhs != NULL);
8881#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8882 printf (
" --- temp_lhs = %p = %s name = %s \n",temp_lhs,temp_lhs->
class_name().c_str(),
get_name(temp_lhs).c_str());
8888 if (classType != NULL)
8890 classChain.push_front(classType);
8894 if (classType != NULL)
8905 ROSE_ASSERT(target_type != NULL);
8906 SgClassType* target_classType = isSgClassType(target_type);
8908 if (target_classType != NULL)
8911 ROSE_ASSERT(target_declaration != NULL);
8912 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(target_declaration);
8913 ROSE_ASSERT(target_classDeclaration != NULL);
8915 ROSE_ASSERT(target_definingClassDeclaration != NULL);
8916 SgScopeStatement* target_scope = target_definingClassDeclaration->get_definition();
8917 ROSE_ASSERT(target_scope != NULL);
8919#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8920 printf (
"target_classDeclaration = %p = %s name = %s target_scope = %p = %s \n",
8921 target_classDeclaration,target_classDeclaration->
class_name().c_str(),target_classDeclaration->get_name().str(),target_scope,target_scope->
class_name().c_str());
8924 ROSE_ASSERT(source_classType != NULL);
8926 ROSE_ASSERT(source_declaration != NULL);
8927 SgClassDeclaration* source_classDeclaration = isSgClassDeclaration(source_declaration);
8928 ROSE_ASSERT(source_classDeclaration != NULL);
8930 ROSE_ASSERT(source_definingClassDeclaration != NULL);
8931 SgScopeStatement* source_scope = source_definingClassDeclaration->get_definition();
8932 ROSE_ASSERT(source_scope != NULL);
8934#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8935 printf (
"source_classDeclaration = %p = %s name = %s source_scope = %p = %s \n",
8936 source_classDeclaration,source_classDeclaration->
class_name().c_str(),source_classDeclaration->get_name().str(),source_scope,source_scope->
class_name().c_str());
8939 while (tmp_scope != NULL && tmp_scope != target_scope)
8941#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8942 printf (
"tmp_scope = %p = %s \n",tmp_scope,tmp_scope->
class_name().c_str());
8945 ROSE_ASSERT(tmp_classDefinition != NULL);
8947 ROSE_ASSERT(tmp_classDeclaration != NULL);
8949#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8950 SgName scope_name = tmp_classDeclaration->get_name();
8951 printf (
"scope_name = %s \n",scope_name.str());
8953 SgClassType* tmp_classType = tmp_classDeclaration->get_type();
8954 ROSE_ASSERT(tmp_classType != NULL);
8957 classChain.push_front(tmp_classType);
8961 if (isSgGlobal(tmp_scope) != NULL)
8970 printf (
"In loop processing cast: target_type = %p = %s \n",target_type,target_type->
class_name().c_str());
8976#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8977 printf (
"Bottom of loop: processing cast = %p temp_lhs = %p = %s \n",cast,temp_lhs,temp_lhs->
class_name().c_str());
8983 ROSE_ASSERT(temp_lhs != NULL);
8985#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8986 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): temp_lhs = %p = %s \n",temp_lhs,temp_lhs->
class_name().c_str());
8989 SgVarRefExp* derivedClassVarRefExp = isSgVarRefExp(temp_lhs);
8990 if (derivedClassVarRefExp != NULL)
8992 SgVariableSymbol* derivedClassVariableSymbol = derivedClassVarRefExp->get_symbol();
8993 ROSE_ASSERT(derivedClassVariableSymbol != NULL);
8995 SgName derivedClassVariableName = derivedClassVariableSymbol->
get_name();
8997#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8998 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): derivedClassVariableName = %s \n",derivedClassVariableName.str());
9002 ROSE_ASSERT(type != NULL);
9004#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9005 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs type = %p = %s \n",type,type->
class_name().c_str());
9009 SgType* stripped_type = type->
stripType(SgType::STRIP_POINTER_TYPE|SgType::STRIP_ARRAY_TYPE|SgType::STRIP_REFERENCE_TYPE|SgType::STRIP_RVALUE_REFERENCE_TYPE|SgType::STRIP_MODIFIER_TYPE);
9011#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9012 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs stripped_type = %p = %s \n",stripped_type,stripped_type->
class_name().c_str());
9016 SgClassType* classType = isSgClassType(stripped_type);
9019 if (classType != NULL)
9021#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9022 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs classType = %p = %s \n",classType,classType->
class_name().c_str());
9023 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
9024 ROSE_ASSERT(classDeclaration != NULL);
9025 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs classDeclaration = %p = %s name = %s \n",
9026 classDeclaration,classDeclaration->
class_name().c_str(),classDeclaration->get_name().str());
9031 classChain.push_front(classType);
9035#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9036 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs stripped_type is not a SgClassType \n");
9042#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9043 printf (
"Need to support alternative to SgVarRefExp: temp_lhs = %p = %s \n",temp_lhs,temp_lhs->
class_name().c_str());
9046 ROSE_ASSERT(type != NULL);
9048#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9049 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs type = %p = %s name = %s \n",type,type->
class_name().c_str(),
get_name(type).c_str());
9053 SgType* stripped_type = type->
stripType(SgType::STRIP_POINTER_TYPE|SgType::STRIP_ARRAY_TYPE|SgType::STRIP_REFERENCE_TYPE|SgType::STRIP_RVALUE_REFERENCE_TYPE|SgType::STRIP_MODIFIER_TYPE);
9055#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9056 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): stripped_type = %p = %s name = %s \n",stripped_type,stripped_type->
class_name().c_str(),
get_name(stripped_type).c_str());
9059 SgClassType* classType = isSgClassType(stripped_type);
9061 if (classType != NULL)
9063 classChain.push_front(classType);
9067#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9068 printf (
"classChain.size() = %zu \n",classChain.size());
9069 std::list<SgClassType*>::iterator iter = classChain.begin();
9070 while(iter != classChain.end())
9072 printf (
" --- *iter = %p = %s name = %s \n",*iter,(*iter)->class_name().c_str(),(*iter)->get_name().str());
9085 if (varRefExp != NULL)
9087 ROSE_ASSERT(varRefExp != NULL);
9088 ROSE_ASSERT(memberFunctionRefExp == NULL);
9090 referenceSymbol = varRefExp->get_symbol();
9094 ROSE_ASSERT(varRefExp == NULL);
9095 ROSE_ASSERT(memberFunctionRefExp != NULL);
9097 referenceSymbol = memberFunctionRefExp->get_symbol();
9099 ROSE_ASSERT(referenceSymbol != NULL);
9102#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9103 printf (
"referenceSymbol = %p = %s \n",referenceSymbol,referenceSymbol->
class_name().c_str());
9104 printf (
"symbolName = %s \n",symbolName.str());
9109 if (functionSymbol != NULL)
9114 if (templateInstantiationMemberFunctionDeclaration != NULL)
9116#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9117 printf (
"This is a template name, we want the name without template arguments \n");
9118 printf (
"templateInstantiationMemberFunctionDeclaration = %p \n",templateInstantiationMemberFunctionDeclaration);
9119 printf (
"templateInstantiationMemberFunctionDeclaration->get_name() = %s \n",templateInstantiationMemberFunctionDeclaration->get_name().str());
9126 isSgTemplateMemberFunctionDeclaration(templateInstantiationMemberFunctionDeclaration->
get_templateDeclaration());
9127 if (templateMemberFunctionDeclaration != NULL)
9129#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9130 printf (
"templateMemberFunctionDeclaration = %p \n",templateMemberFunctionDeclaration);
9131 printf (
"templateMemberFunctionDeclaration->get_name() = %s \n",templateMemberFunctionDeclaration->get_name().str());
9134 symbolName = templateMemberFunctionDeclaration->get_name();
9138#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9139 printf (
"templateMemberFunctionDeclaration == NULL: template declaration not available from template instantiation (rare, I think) \n");
9143 printf (
"Exiting as a test! \n");
9151 ROSE_ASSERT(declarationStatement != NULL);
9152#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9153 printf (
"functionSymbol != NULL: but declaration is not a member function: declarationStatement = %p = %s \n",declarationStatement,declarationStatement->
class_name().c_str());
9160 if (variableSymbol != NULL)
9166#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9167 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): NOTE: referenceSymbol is not a SgFunctionSymbol or SgVariableSymbol \n");
9170 printf (
"Exiting as a test! \n");
9177#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9178 printf (
"symbolName = %s \n",symbolName.str());
9187 std::list<SgClassType*> saveList;
9189#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9190 printf (
"classChain.size() = %zu \n",classChain.size());
9193 std::list<SgClassType*>::iterator i = classChain.begin();
9194 std::list<SgClassType*>::iterator save_iter = i;
9200 bool ambiguityDetectedSoSaveWholeChain =
false;
9202 while(i != classChain.end())
9204#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9205 printf (
"******** TOP OF WHILE LOOP ******** \n");
9206 printf (
" --- *i = %p = %s name = %s \n",*i,(*i)->class_name().c_str(),(*i)->get_name().str());
9207 printf (
" --- --- referenceSymbol = %p = %s \n",referenceSymbol,referenceSymbol->
class_name().c_str());
9209 bool ambiguityDetected =
false;
9212 ROSE_ASSERT(declarationStatement != NULL);
9214 if (definingDeclarationStatement != NULL)
9216 SgClassDeclaration* classDeclaration = isSgClassDeclaration(definingDeclarationStatement);
9217 ROSE_ASSERT(classDeclaration != NULL);
9220#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9221 printf (
" --- classDeclaration = %p = %s name = %s \n",classDeclaration,classDeclaration->
class_name().c_str(),classDeclaration->get_name().str());
9222 printf (
" --- classDefinition = %p = %s \n",classDefinition,classDefinition->
class_name().c_str());
9225 ambiguityDetected = classDefinition->hasAmbiguity(symbolName,referenceSymbol);
9227#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9228 printf (
" --- ambiguityDetected = %s \n",ambiguityDetected ?
"true" :
"false");
9233 if (ambiguityDetected ==
true || ambiguityDetectedSoSaveWholeChain ==
true)
9235 ambiguityDetectedSoSaveWholeChain =
true;
9237 if (save_iter != classChain.end())
9239#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9240 printf (
" --- add to saveList: *save_iter = %p \n",*save_iter);
9242 saveList.push_back(*save_iter);
9246#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9247 printf (
" --- save_iter == classChain.end() \n");
9252#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9253 printf (
"******** BOTTOM OF WHILE LOOP ******** \n");
9263#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9264 printf (
"saveList.size() = %zu \n",saveList.size());
9265 std::list<SgClassType*>::iterator saveList_iterator = saveList.begin();
9266 while (saveList_iterator != saveList.end())
9268 printf (
" --- *saveList_iterator = %p = %s name = %s \n",*saveList_iterator,(*saveList_iterator)->class_name().c_str(),(*saveList_iterator)->get_name().str());
9270 saveList_iterator++;
9274 returnTypeChain = saveList;
9279 return returnTypeChain;
9289#define DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE 0
9291 ROSE_ASSERT(memberFunctionRefExp != NULL);
9293 bool returnValue =
false;
9299 SgDotExp* dotExp = isSgDotExp(parent);
9306 if (arrowExp != NULL || dotExp != NULL || addressOfOp != NULL)
9310 ROSE_ASSERT(symbol != NULL);
9313 ROSE_ASSERT(functionDeclaration != NULL);
9316 if (functionDeclaration != NULL)
9318 bool isStatic = functionDeclaration->get_declarationModifier().get_storageModifier().
isStatic();
9319#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9320 printf (
"isStatic = %s \n",
isStatic ?
"true" :
"false");
9325 ROSE_ASSERT(scope != NULL);
9328 if (classDefinition != NULL)
9336#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9337 printf (
"In SageInterface::isMemberFunctionMemberReference(): memberFunctionRefExp is not associated with variableDeclaration (could not compute if it is static data member) \n");
9343#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9344 printf (
"In SageInterface::isMemberFunctionMemberReference(): memberFunctionRefExp parent is not a is not SgArrowExp or SgDotExp expression \n");
9348#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9349 printf (
"Leaving SageInterface::isMemberFunctionMemberReference(): returnValue = %s \n",returnValue ?
"true" :
"false");
9368#define DEBUG_IS_DATA_MEMBER_REFERENCE 0
9370 ROSE_ASSERT(varRefExp != NULL);
9372 bool returnValue =
false;
9378 SgDotExp* dotExp = isSgDotExp(parent);
9382 if (arrowExp != NULL || dotExp != NULL || addressOfOp != NULL)
9384 if (arrowExp != NULL)
9388 ROSE_ASSERT(parentOfArrowExp != NULL);
9389 SgSizeOfOp* sizeOfOp = isSgSizeOfOp(parentOfArrowExp);
9390 if (sizeOfOp != NULL && sizeOfOp->get_is_objectless_nonstatic_data_member_reference() ==
true)
9393#if DEBUG_IS_DATA_MEMBER_REFERENCE
9394 printf (
"In SageInterface::isDataMemberReference(): Found case of expression used in sizeof with objectless_nonstatic_data_member_reference \n");
9401 ROSE_ASSERT(symbol != NULL);
9404 ROSE_ASSERT(initializedName != NULL);
9408 if (variableDeclaration != NULL)
9410 bool isStatic = variableDeclaration->get_declarationModifier().get_storageModifier().
isStatic();
9414 ROSE_ASSERT(scope != NULL);
9417 if (classDefinition != NULL)
9425#if DEBUG_IS_DATA_MEMBER_REFERENCE
9426 printf (
"In SageInterface::isDataMemberReference(): varRefExp is not associated with variableDeclaration (could not compute if it is static data member) \n");
9432#if DEBUG_IS_DATA_MEMBER_REFERENCE
9433 printf (
"In SageInterface::isDataMemberReference(): varRefExp parent is not a is not SgArrowExp or SgDotExp expression \n");
9437#if DEBUG_IS_DATA_MEMBER_REFERENCE
9438 printf (
"Leaving SageInterface::isDataMemberReference(): returnValue = %s \n",returnValue ?
"true" :
"false");
9450 ROSE_ASSERT(varRefExp != NULL);
9452 bool returnValue =
false;
9456 if (addressOfOp != NULL)
9474 ROSE_ASSERT(varRefExp != NULL || memberFunctionRefExp != NULL);
9478 ROSE_ASSERT(refExp != NULL);
9480 bool returnValue =
false;
9485 if (addressOfOp != NULL)
9503 ROSE_ASSERT (astNode != NULL);
9507 ROSE_ASSERT (isSgProject(astNode) == NULL);
9509 SgNode* previous_parent = NULL;
9510 SgNode* previous_previous_parent = NULL;
9512 SgNode* parent = astNode;
9514 while ( (parent != NULL) && (isSgFile(parent) == NULL) && isSgJavaPackageDeclaration(parent) == NULL)
9517 printf (
"In getEnclosingFileNode(): parent = %p = %s \n",parent,parent->
class_name().c_str());
9519 previous_previous_parent = previous_parent;
9520 previous_parent = parent;
9525 if (previous_previous_parent != NULL && previous_parent != NULL && isSgJavaPackageDeclaration(parent) != NULL)
9529 printf (
"parent = %p = %s \n",parent,parent->
class_name().c_str());
9530 printf (
"previous_parent = %p = %s \n",previous_parent,previous_parent->
class_name().c_str());
9531 printf (
"previous_previous_parent = %p = %s \n",previous_previous_parent,previous_previous_parent->
class_name().c_str());
9533 SgClassDeclaration* classDeclaration = isSgClassDeclaration(previous_previous_parent);
9534 if (classDeclaration != NULL)
9537 printf (
"Class name = %p = %s = %s \n",classDeclaration,classDeclaration->
class_name().c_str(),classDeclaration->get_name().str());
9542 SgProject* project = TransformationSupport::getProject(parent);
9543 ROSE_ASSERT(project != NULL);
9544 SgFileList* fileList = project->get_fileList_ptr();
9545 ROSE_ASSERT(fileList != NULL);
9546 SgFilePtrList & vectorFile = fileList->get_listOfFiles();
9548 printf (
"Output list of files: \n");
9550 SgFilePtrList::iterator i = vectorFile.begin();
9551 while (i != vectorFile.end())
9554 ROSE_ASSERT(file != NULL);
9556 printf (
" --- filename = %s \n",file->
getFileName().c_str());
9559 string filenameWithoutPath = file->get_sourceFileNameWithoutPath();
9560 string classname = classDeclaration->get_name();
9561 string matchingfilename = classname +
".java";
9563 printf (
" --- --- filename = %s \n",filename.c_str());
9564 printf (
" --- --- filenameWithoutPath = %s \n",filenameWithoutPath.c_str());
9565 printf (
" --- --- classname = %s \n",classname.c_str());
9566 printf (
" --- --- matchingfilename = %s \n",matchingfilename.c_str());
9568 if (filenameWithoutPath == matchingfilename)
9571 printf (
" return file = %p \n",file);
9587 SgSourceFile *sourcefile = isSgSourceFile(attribute->getNode());
9588 ROSE_ASSERT(sourcefile != NULL);
9597 if (previous_parent == NULL && isSgJavaPackageDeclaration(parent) != NULL)
9600 ROSE_ASSERT(isSgJavaPackageDeclaration(astNode) != NULL);
9605 if (previous_previous_parent == NULL && isSgJavaPackageDeclaration(parent) != NULL)
9608 ROSE_ASSERT(isSgClassDefinition(astNode) != NULL);
9619 if (parent ==
nullptr)
9625 return isSgFile(parent);
9631 std::set<SgNode*> specific;
9632 std::set<SgNode*> non_specific;
9634 static void recursive_collect(
SgNode* node , std::set<SgNode *> & collection ) {
9636 if (node == NULL || !collection.insert(node).second)
return;
9639 for (std::vector<std::pair<SgNode*, std::string> >::iterator i = data_members.begin(); i != data_members.end(); ++i) {
9640 recursive_collect(i->first, collection);
9647 if (fileInfo != NULL) {
9648 if (fileInfo->isFrontendSpecific()) {
9650 recursive_collect(n, specific);
9652 non_specific.insert(n);
9653 recursive_collect(n, non_specific);
9656 fileInfo = isSg_File_Info(n);
9657 if (fileInfo != NULL) {
9658 if (fileInfo->isFrontendSpecific()) {
9661 non_specific.insert(n);
9667 std::set<SgNode*> apply() {
9668 traverseMemoryPool();
9670 std::set<SgNode*> result;
9672 std::set_difference(
9673 specific.begin(), specific.end(),
9674 non_specific.begin(), non_specific.end(),
9675 std::insert_iterator<set<SgNode*> >(result, result.begin())
9682 FrontendSpecificTraversal fst;
9695 void visit(
SgNode *astNode)
9697 ROSE_ASSERT(astNode != NULL);
9699 if (file_info != NULL)
9703 printf (
"Found shared node: astNode = %p = %s \n",astNode,astNode->
class_name().c_str());
9709 OutputSharedNodesTraversal tt;
9710 tt.traverse(node,preorder);
9718 while (n && !isSgStatement(n)) n = n->
get_parent();
9719 return isSgStatement(n);
9728SageInterface::DeferredTransformation::DeferredTransformation()
9729 : deferredTransformationKind(e_default),
9730 statementToRemove(NULL),
9731 statementToAdd(NULL),
9732 class_definition(NULL),
9733 target_class_member(NULL),
9734 new_function_prototype(NULL),
9736 locationToOverwriteWithTransformation(NULL),
9737 transformationToOverwriteFirstStatementInInterval(NULL),
9738 blockOfStatementsToOutline(NULL)
9742 printf (
"In SageInterface::DeferredTransformation default constructor called \n");
9750SageInterface::DeferredTransformation::DeferredTransformation(
9754 : deferredTransformationKind(e_outliner),
9755 statementToRemove(NULL),
9756 statementToAdd(NULL),
9757 class_definition(input_class_definition),
9758 target_class_member(input_target_class_member),
9759 new_function_prototype(input_new_function_prototype),
9761 locationToOverwriteWithTransformation(NULL),
9762 transformationToOverwriteFirstStatementInInterval(NULL),
9763 blockOfStatementsToOutline(NULL)
9767 printf (
"In SageInterface::DeferredTransformation constructor for outliner called \n");
9775 printf (
"In SageInterface::DeferredTransformation constructor for replaceDefiningFunctionDeclarationWithFunctionPrototype called \n");
9781 X.deferredTransformationKind = e_replaceDefiningFunctionDeclarationWithFunctionPrototype;
9782 X.statementToRemove = functionDeclaration;
9783 X.statementToAdd = NULL;
9784 X.class_definition = NULL;
9785 X.target_class_member = NULL;
9786 X.new_function_prototype = NULL;
9789 X.locationToOverwriteWithTransformation = NULL;
9790 X.transformationToOverwriteFirstStatementInInterval = NULL;
9791 X.blockOfStatementsToOutline = NULL;
9797SageInterface::DeferredTransformation::replaceStatement(
SgStatement* oldStmt,
SgStatement* newStmt,
bool )
9800 printf (
"In SageInterface::DeferredTransformation constructor for replaceStatement called \n");
9806 X.deferredTransformationKind = e_replaceStatement;
9807 X.statementToRemove = oldStmt;
9808 X.statementToAdd = newStmt;
9809 X.class_definition = NULL;
9810 X.target_class_member = NULL;
9811 X.new_function_prototype = NULL;
9814 X.locationToOverwriteWithTransformation = NULL;
9815 X.transformationToOverwriteFirstStatementInInterval = NULL;
9816 X.blockOfStatementsToOutline = NULL;
9821SageInterface::DeferredTransformation::DeferredTransformation (
const DeferredTransformation& X)
9823 : deferredTransformationKind(X.deferredTransformationKind),
9824 statementToRemove(X.statementToRemove),
9825 statementToAdd(X.StatementToAdd),
9826 class_definition(X.class_definition),
9827 target_class_member(X.target_class_member),
9828 new_function_prototype(X.new_function_prototype),
9829 targetClasses(X.targetClasses),
9830 targetFriends(X.targetFriends)
9836 printf (
"In SageInterface::DeferredTransformation copy constructor called \n");
9846 printf (
"Inside of SageInterface::DeferredTransformation::operator= (const DeferredTransformation& X) \n");
9851 targetFriends = X.targetFriends;
9852 targetClasses = X.targetClasses;
9858 transformationLabel = X.transformationLabel;
9861 deferredTransformationKind = X.deferredTransformationKind;
9862 statementToRemove = X.statementToRemove;
9863 statementToAdd = X.statementToAdd;
9865 class_definition = X.class_definition;
9866 target_class_member = X.target_class_member;
9867 new_function_prototype = X.new_function_prototype;
9868 targetClasses = X.targetClasses;
9869 targetFriends = X.targetFriends;
9872 statementInterval = X.statementInterval;
9873 locationToOverwriteWithTransformation = X.locationToOverwriteWithTransformation;
9874 transformationToOverwriteFirstStatementInInterval = X.transformationToOverwriteFirstStatementInInterval;
9877 blockOfStatementsToOutline = X.blockOfStatementsToOutline;
9888std::string SageInterface::DeferredTransformation::outputDeferredTransformationKind(
const TransformationKind & kind)
9890 string returnValue =
"uninitialized";
9893 case e_error: returnValue =
"e_error";
break;
9894 case e_default: returnValue =
"e_default";
break;
9895 case e_outliner: returnValue =
"e_outliner";
break;
9896 case e_replaceStatement: returnValue =
"e_replaceStatement";
break;
9897 case e_removeStatement: returnValue =
"e_removeStatement";
break;
9898 case e_replaceDefiningFunctionDeclarationWithFunctionPrototype: returnValue =
"e_replaceDefiningFunctionDeclarationWithFunctionPrototype";
break;
9899 case e_last: returnValue =
"e_last";
break;
9902 printf (
"Error: SageInterface::DeferredTransformation::get_deferredTransformationKind_string(): default reached \n");
9910void SageInterface::DeferredTransformation::display ( std::string label )
const
9912 printf (
"SageInterface::DeferredTransformation::display(): label = %s \n",label.c_str());
9917 printf (
" --- transformationLabel = %s \n",transformationLabel.c_str());
9919 printf (
" --- deferredTransformationKind = %s \n",outputDeferredTransformationKind(deferredTransformationKind).c_str());
9920 if (statementToRemove != NULL)
9922 printf (
" --- statementToRemove = %p = %s name = %s \n",statementToRemove,statementToRemove->class_name().c_str(),
get_name(statementToRemove).c_str());
9926 printf (
" --- statementToRemove == NULL \n");
9929 if (statementToAdd != NULL)
9931 printf (
" --- statementToAdd = %p = %s name = %s \n",statementToAdd,statementToAdd->class_name().c_str(),
get_name(statementToAdd).c_str());
9935 printf (
" --- statementToAdd == NULL \n");
9938 if (class_definition != NULL)
9941 printf (
" --- class_definition = %p \n",class_definition);
9944 if (target_class_member != NULL)
9946 printf (
" --- target_class_member = %p = %s name = %s \n",target_class_member,target_class_member->class_name().c_str(),
get_name(target_class_member).c_str());
9949 if (new_function_prototype != NULL)
9951 printf (
" --- new_function_prototype = %p = %s name = %s \n",new_function_prototype,new_function_prototype->class_name().c_str(),
get_name(new_function_prototype).c_str());
9955 if (locationToOverwriteWithTransformation != NULL)
9959 printf (
" --- locationToOverwriteWithTransformation = %p \n",locationToOverwriteWithTransformation);
9963 if (transformationToOverwriteFirstStatementInInterval != NULL)
9967 printf (
" --- transformationToOverwriteFirstStatementInInterval = %p \n",transformationToOverwriteFirstStatementInInterval);
9971 if (blockOfStatementsToOutline != NULL)
9973 printf (
" --- blockOfStatementsToOutline = %p \n",blockOfStatementsToOutline);
9976 printf (
"targetClasses.size() = %zu \n",targetClasses.size());
9977 printf (
"targetFriends.size() = %zu \n",targetFriends.size());
9980 printf (
"statementInterval.size() = %zu \n",statementInterval.size());
9990#define REMOVE_STATEMENT_DEBUG 0
9995#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
10006 ASSERT_not_null(targetStmt);
10014 bool isRemovable = (parentStatement != NULL) ? LowLevelRewrite::isRemovableStatement(targetStmt) :
false;
10016#if REMOVE_STATEMENT_DEBUG || 0
10017 printf (
"In SageInterface::removeStatement(): parentStatement = %p = %s remove targetStatement = %p = %s (isRemovable = %s) \n",
10018 parentStatement,parentStatement->
class_name().c_str(),targetStmt,targetStmt->
class_name().c_str(),isRemovable ?
"true" :
"false");
10021 if (isRemovable ==
true)
10028 if (autoRelocatePreprocessingInfo ==
true)
10038 if (comments !=
nullptr && isSgBasicBlock(targetStmt) ==
nullptr )
10040 vector<int> captureList;
10041#if REMOVE_STATEMENT_DEBUG
10042 printf (
"Found attached comments (removing %p = %s): comments->size() = %" PRIuPTR
" \n",targetStmt,targetStmt->
class_name().c_str(),comments->size());
10048 int commentIndex = 0;
10049 AttachedPreprocessingInfoType::iterator i;
10050 for (i = comments->begin(); i != comments->end(); i++)
10052 ROSE_ASSERT ( (*i) != NULL );
10053#if REMOVE_STATEMENT_DEBUG
10054 printf (
" Attached Comment (relativePosition=%s): %s\n",
10055 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
10056 (*i)->getString().c_str());
10057 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
10058 (*i)->get_file_info()->display(
"comment/directive location debug");
10060 captureList.push_back(commentIndex);
10064#if REMOVE_STATEMENT_DEBUG
10065 printf (
"captureList.size() = %" PRIuPTR
" \n",captureList.size());
10068 if (captureList.empty() ==
false)
10073 bool surroundingStatementPreceedsTargetStatement =
false;
10076 if (surroundingStatement !=
nullptr)
10079#if REMOVE_STATEMENT_DEBUG
10080 printf (
"In removeStatement(): surroundingStatementPreceedsTargetStatement = %s \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false");
10081 printf (
" --- moving comments from targetStmt = %p = %s name = %s \n",targetStmt,targetStmt->
class_name().c_str(),
get_name(targetStmt).c_str());
10082 printf (
" --- moving comments to surroundingStatement = %p = %s name = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str(),
get_name(surroundingStatement).c_str());
10097 printf (
"Error: This is not supported within Microsoft Windows (I forget why). \n");
10119 printf (
"In SageInterface::resetInternalMapsForTargetStatement(SgStatement*): sourceStatement = %p = %s \n",sourceStatement,sourceStatement->
class_name().c_str());
10128 printf (
"In SageInterface::resetInternalMapsForTargetStatement(SgStatement*): sourceFile = %p \n",sourceFile);
10131 if (sourceFile != NULL)
10133 std::map<SgStatement*,MacroExpansion*> & macroExpansionMap = sourceFile->get_macroExpansionMap();
10135 if (macroExpansionMap.find(sourceStatement) != macroExpansionMap.end())
10137 MacroExpansion* macroExpansion = macroExpansionMap[sourceStatement];
10138 ROSE_ASSERT(macroExpansion != NULL);
10140 printf (
"In resetInternalMapsForTargetStatement(): macroExpansion = %p = %s \n",macroExpansion,macroExpansion->macro_name.c_str());
10142 if (macroExpansion->isTransformed ==
false)
10145 std::vector<SgStatement*> & associatedStatementVector = macroExpansion->associatedStatementVector;
10147 for (
size_t i = 0; i < associatedStatementVector.size(); i++)
10150 SgStatement* statement = associatedStatementVector[i];
10152 printf (
"Mark as transformation to be output: statement = %p = %s \n",statement,statement->
class_name().c_str());
10176 macroExpansion->isTransformed =
true;
10193#if REMOVE_STATEMENT_DEBUG || 0
10194 printf (
"In moveCommentsToNewStatement(): surroundingStatementPreceedsTargetStatement = %s \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false");
10195 printf (
" --- sourceStatement = %p = %s name = %s \n",sourceStatement,sourceStatement->
class_name().c_str(),
get_name(sourceStatement).c_str());
10196 printf (
" --- targetStatement = %p = %s name = %s \n",targetStatement,targetStatement->
class_name().c_str(),
get_name(targetStatement).c_str());
10204#if REMOVE_STATEMENT_DEBUG
10205 printf (
"Output the comments attached to sourceStatement: \n");
10207 printf (
"Output the comments attached to targetStatement: \n");
10212 vector<int>::const_iterator j = indexList.begin();
10214 while (j != indexList.end())
10218#if REMOVE_STATEMENT_DEBUG || 0
10219 printf (
"Attaching comments to targetStatement = %p = %s on file = %s line %d \n",
10220 targetStatement,targetStatement->
class_name().c_str(),
10221 targetStatement->
get_file_info()->get_filenameString().c_str(),
10224 printf (
"(*comments)[*j]->getRelativePosition() = %s \n",PreprocessingInfo::relativePositionName((*comments)[*j]->getRelativePosition()).c_str());
10236 if (surroundingStatementPreceedsTargetStatement ==
true || isSgGlobal(targetStatement) != NULL )
10242 auto commentPosition = (*comments)[*j]->getRelativePosition();
10243 if (commentPosition == PreprocessingInfo::before)
10246 (*comments)[*j]->setRelativePosition(PreprocessingInfo::after);
10248 else if (commentPosition == PreprocessingInfo::after ||
10249 commentPosition == PreprocessingInfo::end_of)
10255 ROSE_ASSERT(
false &&
"Comment relative position neither, before, after, nor end_of");
10259 if (isSgGlobal(targetStatement))
10260 (*comments)[*j]->setRelativePosition(PreprocessingInfo::inside);
10271 if ((*comments)[*j]->getRelativePosition() == PreprocessingInfo::before)
10279 ASSERT_require((*comments)[*j]->getRelativePosition() == PreprocessingInfo::after);
10280 (*comments)[*j]->setRelativePosition(PreprocessingInfo::before);
10289 if (targetInfoList==NULL)
10298 if( prevTargetAnchorComment==NULL)
10311 prevTargetAnchorComment = (*comments)[*j];
10316#if REMOVE_STATEMENT_DEBUG
10317 printf (
"Marking entry from comments list as NULL on sourceStatement = %p = %s \n",sourceStatement,sourceStatement->
class_name().c_str());
10319 (*comments)[*j] =
nullptr;
10326 for (
size_t n = 0; n < indexList.size(); n++)
10328#if REMOVE_STATEMENT_DEBUG || 0
10329 printf (
"Erase entry from comments list on comments->size() %" PRIuPTR
" \n",comments->size());
10331 bool modifiedList =
false;
10332 AttachedPreprocessingInfoType::iterator k = comments->begin();
10333 while (k != comments->end() && modifiedList ==
false)
10338 k = comments->erase(k);
10339 modifiedList =
true;
10358 ROSE_ASSERT(targetStmt != NULL);
10363#if REMOVE_STATEMENT_DEBUG || 0
10364 printf (
"TOP of findSurroundingStatementFromSameFile(): surroundingStatementPreceedsTargetStatement = %s \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false");
10367 std::set<SgStatement*> previousVisitedStatementSet;
10372 surroundingStatementPreceedsTargetStatement =
true;
10374#if REMOVE_STATEMENT_DEBUG
10375 printf (
" targetStmt->get_file_info()->get_file_id() = %d \n",targetStmt->
get_file_info()->get_file_id());
10377#if REMOVE_STATEMENT_DEBUG
10378 printf (
"Before loop: surroundingStatement = %p = %s name = %s surroundingStatement_fileId = %d \n",surroundingStatement,
10381 bool returningNullSurroundingStatement =
false;
10383 while ((returningNullSurroundingStatement ==
false) && (surroundingStatement != NULL) && surroundingStatement_fileId != targetStmt->
get_file_info()->get_file_id())
10391#if REMOVE_STATEMENT_DEBUG
10392 printf (
"In loop: after getPreviousStatement(): surroundingStatement = %p = %s name = %s \n",surroundingStatement,
10396 if (surroundingStatement == NULL)
10399#if REMOVE_STATEMENT_DEBUG
10400 printf (
" surroundingStatement_fileId set to Sg_File_Info::BAD_FILE_ID \n");
10405 surroundingStatement_fileId = surroundingStatement->
get_file_info()->get_file_id();
10406#if REMOVE_STATEMENT_DEBUG
10407 printf (
" surroundingStatement = %p = %s surroundingStatement->get_file_info()->get_file_id() = %d \n",
10408 surroundingStatement,surroundingStatement->
class_name().c_str(),surroundingStatement->
get_file_info()->get_file_id());
10412#if REMOVE_STATEMENT_DEBUG
10413 if (surroundingStatement != NULL)
10415 printf (
"Looping toward the top of the file for a statement to attach comments and CPP directives to: surroundingStatement = %p = %s file = %s file id = %d line = %d \n",
10416 surroundingStatement,surroundingStatement->
class_name().c_str(),
10417 surroundingStatement->
get_file_info()->get_filenameString().c_str(),
10423 printf (
"surroundingStatement == NULL \n");
10428 if (previousVisitedStatementSet.find(surroundingStatement) != previousVisitedStatementSet.end())
10430 printf (
"This statement has been previously visited: surroundingStatement = %p = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str());
10432 printf (
"ERROR: SageInterface::findSurroundingStatementFromSameFile(): cannot located surrounding statement from same file (return NULL) \n");
10434 surroundingStatement = NULL;
10440 previousVisitedStatementSet.insert(surroundingStatement);
10444 if (surroundingStatement == NULL || isSgGlobal(surroundingStatement) != NULL)
10447#if REMOVE_STATEMENT_DEBUG
10448 printf (
"We just ran off the start (top) of the file... targetStmt = %p = %s \n",targetStmt,targetStmt->
class_name().c_str());
10454 surroundingStatementPreceedsTargetStatement =
false;
10457 surroundingStatement = targetStmt;
10458 SgStatement* previousStatement = surroundingStatement;
10462 std::set<SgStatement*> forwardVisitedStatementSet;
10465 while ( (surroundingStatement != NULL) && (surroundingStatement_fileId != targetStmt->
get_file_info()->get_file_id()) )
10468 if (forwardVisitedStatementSet.find(surroundingStatement) != forwardVisitedStatementSet.end())
10470 printf (
"This statement has been previously visited: surroundingStatement = %p = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str());
10472 printf (
"ERROR: SageInterface::findSurroundingStatementFromSameFile(): cannot located surrounding statement from same file (return NULL) \n");
10474 surroundingStatement = NULL;
10480 forwardVisitedStatementSet.insert(surroundingStatement);
10483 previousStatement = surroundingStatement;
10486 if (surroundingStatement == NULL)
10489#if REMOVE_STATEMENT_DEBUG
10490 printf (
"We just ran off the end (bottom) of the file... \n");
10495 returningNullSurroundingStatement =
true;
10499 surroundingStatement_fileId = surroundingStatement->
get_file_info()->get_file_id();
10500#if REMOVE_STATEMENT_DEBUG
10501 printf (
"Looping toward the bottom of the file for a statement to attach comments and CPP directives to: surroundingStatement = %p = %s file = %s file id = %d line = %d \n",
10502 surroundingStatement,surroundingStatement->
class_name().c_str(),
10503 surroundingStatement->
get_file_info()->get_filenameString().c_str(),
10510 if (surroundingStatement == NULL)
10512#if REMOVE_STATEMENT_DEBUG
10513 printf (
"Resetting the surroundingStatement to the previousStatement = %p = %s \n",previousStatement,previousStatement->
class_name().c_str());
10515 surroundingStatement = previousStatement;
10518 if (surroundingStatement == targetStmt)
10522#if REMOVE_STATEMENT_DEBUG
10523 printf (
"Setting the surroundingStatement to be global scope \n");
10525 surroundingStatement = TransformationSupport::getGlobalScope(targetStmt);
10531 ROSE_ASSERT(surroundingStatement != NULL);
10535 printf (
"This is a special statement (not associated with the original source code, comment relocation is not supported for these statements) targetStmt file id = %d \n",targetStmt->
get_file_info()->get_file_id());
10536 surroundingStatement = NULL;
10539#if REMOVE_STATEMENT_DEBUG
10540 printf (
"BOTTOM of findSurroundingStatementFromSameFile(): surroundingStatementPreceedsTargetStatement = %s surroundingStatement = %p \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false",surroundingStatement);
10541 if (surroundingStatement != NULL)
10543 printf (
"surroundingStatement = %p = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str());
10549 return surroundingStatement;
10559 virtual void visit(
SgNode* n) {
10563 Visitor().
traverse(root, postorder);
10573 ROSE_ASSERT(oldStmt);
10574 ROSE_ASSERT(newStmt);
10576 if (oldStmt == newStmt)
return;
10587 ROSE_ASSERT (f_do->get_body() == oldStmt);
10588 if (!isSgBasicBlock(newStmt))
10590 f_do->set_body(isSgBasicBlock(newStmt));
10607 printf (
"In SageInterface::replaceStatement(): physical_file_id = %d \n",physical_file_id);
10618 if (movePreprocessingInfoValue)
10624 printf (
"In SageInterface::replaceStatement(): calling moveUpPreprocessingInfo() changed to movePreprocessingInfo() \n");
10636 bool usePrepend =
true;
10638 movePreprocessingInfo ( oldStmt, newStmt, PreprocessingInfo::undef, PreprocessingInfo::undef, usePrepend );
10659 printf (
"In SageInterface::moveDeclarationToAssociatedNamespace(): declarationStatement = %p = %s \n",declarationStatement,declarationStatement->
class_name().c_str());
10660 printf (
" --- previousDeclarationStatement = %p = %s \n",previousDeclarationStatement,previousDeclarationStatement != NULL ? previousDeclarationStatement->
class_name().c_str() :
"null");
10661 printf (
" --- nextDeclarationStatement = %p \n",nextDeclarationStatement);
10662 printf (
" --- nextDeclarationStatement = %p = %s \n",nextDeclarationStatement, nextDeclarationStatement != NULL ? nextDeclarationStatement->
class_name().c_str() :
"null");
10666 if (previousDeclarationStatement != NULL)
10672 printf (
"There is no previous statement so there is no namespace to close off! \n");
10675 printf (
"Exiting as a test! \n");
10680 if (nextDeclarationStatement != NULL)
10687 printf (
"There is no next statement so there is no namespace to reopen! \n");
10691 printf (
"Exiting as a test! \n");
10696 if (previousDeclarationStatement != NULL && nextDeclarationStatement != NULL)
10700 printf (
"Identified the most common case... \n");
10705 printf (
"declarationScope = %p = %s \n",declarationScope,declarationScope->
class_name().c_str());
10709 printf (
"Exiting as a test! \n");
10715 if (previousDeclarationStatement != NULL && nextDeclarationStatement == NULL)
10719 printf (
"Found 2nd most common case: previousDeclarationStatement != NULL && nextDeclarationStatement == NULL \n");
10723 printf (
"Exiting as a test! \n");
10729 if (previousDeclarationStatement == NULL && nextDeclarationStatement == NULL)
10731 printf (
"This case should require no special handling, unless we are still in the wrong namespace \n");
10734 printf (
"Exiting as a test! \n");
10739 printf (
"This case should have been caught above! \n");
10742 printf (
"Exiting as a test! \n");
10749 if (declarationParent == NULL)
10752 printf (
"declarationStatement->get_parent() = %p = %s \n",declarationStatement->
get_parent(), (declarationStatement->
get_parent() != NULL) ? declarationStatement->
get_parent()->
class_name().c_str() :
"null");
10758 if (declarationParent != NULL)
10761 ROSE_ASSERT(declarationScope != NULL);
10764 if (namespaceDefinition != NULL)
10767 ROSE_ASSERT(namespaceDeclaration != NULL);
10769 printf (
"The declaration has been identified to be associuated with a valid namespace = %p = %s \n",namespaceDeclaration,namespaceDeclaration->
get_name().str());
10770 printf (
" --- declarationParent = %p = %s \n",declarationParent,declarationParent->
class_name().c_str());
10771 printf (
" --- Move declaration from scope = %p = %s to namespace = %p = %s \n",declarationParent,declarationParent->
class_name().c_str(),namespaceDeclaration,namespaceDeclaration->
get_name().str());
10774 printf (
"Exiting as a test! \n");
10781 printf (
"declaration is not associated with a namespace, so we don't have to wrap it: declarationScope = %p = %s \n",declarationScope,declarationScope->
class_name().c_str());
10788 printf (
"Warning: declarationParent == NULL: declarationStatement->get_parent() = %p = %s \n",declarationStatement->
get_parent(), (declarationStatement->
get_parent() != NULL) ? declarationStatement->
get_parent()->
class_name().c_str() :
"null");
10800 if (isSgTemplateInstantiationDefn(node) != NULL)
10803 printf (
"Note: In SageInterface::isTemplateInstantiationNode(): skipping SgTemplateInstantiationDefn \n");
10807 return isSgTemplateInstantiationDecl(node)
10810 || isSgTemplateInstantiationDefn(node)
10811 || isSgTemplateInstantiationFunctionDecl(node)
10812 || isSgTemplateInstantiationMemberFunctionDecl(node)
10813 || isSgTemplateInstantiationTypedefDeclaration(node)
10814 || isSgTemplateInstantiationDirectiveStatement(node)
10823SageInterface::isTemplateDeclarationNode(
SgNode* node)
10826 if (isSgTemplateDefinition(node) != NULL)
10829 printf (
"Note: In SageInterface::isTemplateDeclarationNode(): skipping SgTemplateDefinition \n");
10833 return isSgTemplateInstantiationDecl(node)
10836 || isSgTemplateInstantiationDefn(node)
10837 || isSgTemplateInstantiationFunctionDecl(node)
10838 || isSgTemplateInstantiationMemberFunctionDecl(node)
10839 || isSgTemplateInstantiationTypedefDeclaration(node)
10840 || isSgTemplateInstantiationDirectiveStatement(node)
10853 std::vector<SgDeclarationStatement*> templateInstantiationVector;
10865 if (declaration != NULL)
10867 templateInstantiationVector.push_back(declaration);
10876 std::cerr <<
"This feature for now is available with autotools only!" << std::endl;
10880 std::vector<SgDeclarationStatement*>::iterator j = templateInstantiationVector.begin();
10881 while (j != templateInstantiationVector.end())
10895 SgExpression * pattern_exp = isSgExpression(new_pattern);
10896 ROSE_ASSERT (anchor_exp != NULL);
10897 ROSE_ASSERT (pattern_exp != NULL);
10900 Rose_STL_Container<SgNode*> opaque_exp_list = NodeQuery::querySubTree(pattern_exp,V_SgExpression);
10901 for (
size_t i = 0; i<opaque_exp_list.size(); i++)
10903 SgExpression* opaque_exp = isSgExpression(opaque_exp_list[i]);
10904 ROSE_ASSERT (opaque_exp != NULL);
10905 if (opaque_exp->
variantT() == V_SgVariantExpression)
10914 return new_pattern;
10921 static int counter = 0;
10924 bool collision =
false;
10927 name =
"__" + baseName + boost::lexical_cast<string > (counter++) +
"__";
10933 collision = (nameSymbol != NULL);
10936 Rose_STL_Container<SgNode*> childScopes = NodeQuery::querySubTree(scope, V_SgScopeStatement);
10938 BOOST_FOREACH(
SgNode* childScope, childScopes)
10944 nameSymbol = childScopeStatement->lookup_symbol(
SgName(name),NULL,NULL);
10946 collision = collision || (nameSymbol != NULL);
10948 }
while (collision);
10958 SgType* variableType = expressionType;
10965 SgType* expressionBaseType = expressionType->
stripType(SgType::STRIP_TYPEDEF_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE);
10970 if (
SgArrayType* arrayType=isSgArrayType(expressionType)) {
10971 if(
SgArrayType* strippedArrayType = isSgArrayType(arrayType->stripType(SgType::STRIP_TYPEDEF_TYPE))) {
10972 SgType* strippedArrayBaseType = strippedArrayType->get_base_type();
10978 if (isSgPointerDerefExp(expression))
10986 ROSE_ASSERT(tempVarInitExpression != NULL);
10997 if (initializeInDeclaration)
11004 ROSE_ASSERT(tempVarDeclaration != NULL);
11007 if (reEvaluate != NULL)
11021 return std::make_pair(tempVarDeclaration, varRefExpression);
11034 SgType* variableType = expressionType;
11037 if (
SgArrayType* arrayType=isSgArrayType(expressionType))
11039 if(
SgArrayType* strippedArrayType = isSgArrayType(arrayType->stripType(SgType::STRIP_TYPEDEF_TYPE))) {
11040 SgType* strippedArrayBaseType = strippedArrayType->get_base_type();
11054 ROSE_ASSERT(tempVarDeclaration != NULL);
11058 return std::make_pair(tempVarDeclaration, varRefExpression);
11065 replaceExpressionInSgExpressionPtrList(
SgExpression* oldExp,
SgExpression* newExp, SgExpressionPtrList& lst,
bool replAll =
false)
11067 SgExpressionPtrList::iterator lim = lst.end();
11068 SgExpressionPtrList::iterator pos = lst.begin();
11073 pos = std::find(pos, lim, oldExp);
11075 if (pos != lim) { *pos = newExp; ++pos; chg =
true; }
11076 }
while (replAll && (pos != lim));
11090 ROSE_ASSERT(oldExp);
11091 ROSE_ASSERT(newExp);
11092 if (oldExp==newExp)
return;
11094 if (isSgVarRefExp(newExp))
11098 ROSE_ASSERT(parent!=NULL);
11104 if (isSgExprStatement(parent)) {
11105 isSgExprStatement(parent)->set_expression(newExp);
11106 }
else if (isSgForStatement(parent)) {
11107 ROSE_ASSERT (isSgForStatement(parent)->get_increment() == oldExp);
11108 isSgForStatement(parent)->set_increment(newExp);
11111 if(matlabFor->get_index() == oldExp)
11112 matlabFor->set_index(newExp);
11113 else if(matlabFor->get_range() == oldExp)
11114 matlabFor->set_range(newExp);
11116 ROSE_ASSERT(!
"sub-expression not found");
11118 if(jovFor->get_initialization() == oldExp)
11119 jovFor->set_initialization(newExp);
11120 else if(jovFor->get_while_expression() == oldExp)
11121 jovFor->set_while_expression(newExp);
11122 else if(jovFor->get_by_or_then_expression() == oldExp)
11123 jovFor->set_by_or_then_expression(newExp);
11125 ROSE_ASSERT(!
"sub-expression not found");
11126 }
else if (
SgRangeExp* rngexp = isSgRangeExp(parent)) {
11127 if (rngexp->get_start() == oldExp)
11128 rngexp->set_start(newExp);
11129 else if (rngexp->get_end() == oldExp)
11130 rngexp->set_end(newExp);
11131 else if (rngexp->get_stride() == oldExp)
11132 rngexp->set_stride(newExp);
11134 ROSE_ASSERT(!
"sub-expression not found");
11135 }
else if (isSgReturnStmt(parent)) {
11136 isSgReturnStmt(parent)->set_expression(newExp);
11137 }
else if (isSgBinaryOp(parent)!=NULL) {
11138 if (oldExp==isSgBinaryOp(parent)->get_lhs_operand()) {
11140 }
else if (oldExp==isSgBinaryOp(parent)->get_rhs_operand()) {
11145 }
else if (isSgUnaryOp(parent)!=NULL){
11146 if (oldExp==isSgUnaryOp(parent)->get_operand_i())
11150 }
else if (isSgConditionalExp(parent) != NULL) {
11160 }
else if (isSgExprListExp(parent) != NULL) {
11161 SgExpressionPtrList& explist = isSgExprListExp(parent)->get_expressions();
11162 for (Rose_STL_Container<SgExpression*>::iterator i=explist.begin();i!=explist.end();i++) {
11163 if (isSgExpression(*i)==oldExp) {
11169 }
else if (isSgValueExp(parent)) {
11174 ROSE_ASSERT(oldExp == actexp->get_expression());
11175 actexp->set_expression(newExp);
11177 if (oldExp == attrexp->get_object()) {
11178 attrexp->set_object(newExp);
11179 }
else if (oldExp == attrexp->get_args()) {
11181 ASSERT_not_null(newLst);
11183 attrexp->set_args(newLst);
11188 }
else if ((parentExp=isSgExpression(parent)) != NULL) {
11191 ROSE_ASSERT (worked);
11192 }
else if (isSgInitializedName(parent)) {
11194 if (oldExp == initializedNameParent->get_initializer()) {
11196 ROSE_ASSERT(isSgInitializer(newExp));
11197 initializedNameParent->set_initializer(isSgInitializer(newExp));
11202 }
else if (isSgCaseOptionStmt(parent)) {
11204 if (oldExp == case_stmt->
get_key()) {
11206 }
else if(oldExp == case_stmt->get_key_range_end()) {
11207 case_stmt->set_key_range_end(newExp);
11211 }
else if (isSgProcessControlStatement(parent)) {
11213 if (oldExp == ctrl_stmt->get_quiet()) {
11214 ctrl_stmt->set_quiet(newExp);
11215 }
else if (oldExp == ctrl_stmt->get_code()) {
11216 ctrl_stmt->set_code(newExp);
11220 }
else if (isSgFortranDo(parent)) {
11222 if (oldExp == fortranDo->get_initialization()) {
11223 fortranDo->set_initialization(newExp);
11224 }
else if(oldExp == fortranDo->get_bound()) {
11225 fortranDo->set_bound(newExp);
11226 }
else if (oldExp == fortranDo->get_increment()) {
11227 fortranDo->set_increment(newExp);
11233 ROSE_ASSERT(oldExp == stm->get_condition());
11234 stm->set_condition(newExp);
11237 ROSE_ASSERT(oldExp == ptype->get_modexpr());
11238 ptype->set_modexpr(newExp);
11241 ROSE_ASSERT(oldExp == stm->get_time());
11242 stm->set_time(newExp);
11244 ROSE_ASSERT(oldExp == clause->get_size());
11245 clause->set_size(newExp);
11247 ROSE_ASSERT(oldExp == dcl->get_renamed());
11248 dcl->set_renamed(newExp);
11250 ROSE_ASSERT(oldExp == dcl->get_entryBarrier());
11251 dcl->set_entryBarrier(newExp);
11253 ROSE_ASSERT(oldExp == stm->get_guard());
11254 stm->set_guard(newExp);
11256 ROSE_ASSERT(oldExp == delc->get_delta());
11257 delc->set_delta(newExp);
11259 ROSE_ASSERT(oldExp == digc->get_digits());
11260 digc->set_digits(newExp);
11262 replaceExpressionInSgExpressionPtrList(oldExp, newExp, disc->get_discriminants());
11264 ROSE_ASSERT(oldExp == rngc->get_range());
11265 rngc->set_range(newExp);
11267 replaceExpressionInSgExpressionPtrList(oldExp, newExp, idxc->get_indexRanges());
11269 ROSE_ASSERT(oldExp == vtdcl->get_discriminant());
11270 vtdcl->set_discriminant(newExp);
11272 ROSE_ASSERT(oldExp == clause->get_alignment());
11273 clause->set_alignment(newExp);
11275 ROSE_ASSERT(oldExp == vtwhen->get_choices());
11277 ROSE_ASSERT(newLst);
11278 vtwhen->set_choices(newLst);
11280 if (oldExp == clause->get_offset())
11281 clause->set_offset(newExp);
11282 else if (oldExp == clause->get_range() && isSgRangeExp(newExp))
11283 clause->set_range(isSgRangeExp(newExp));
11284 else if (oldExp == clause->get_component() && isSgVarRefExp(newExp))
11285 clause->set_component(isSgVarRefExp(newExp));
11289 cerr<<
"SageInterface::replaceExpression(). Unhandled parent expression type of SageIII enum value: " <<parent->
class_name()<<endl;
11304 return Rose::getNextStatement(currentStmt);
11313 return isSgIntVal(e) && isSgIntVal(e)->get_value() == value;
11318 ROSE_ASSERT(func1&& func2);
11319 bool result =
false;
11320 if (func1 == func2)
11326 if (func1->get_name() == func2->get_name())
11331 if (func1->get_qualified_name().getString() +
11332 func1->get_mangled_name().getString() ==
11333 func2->get_qualified_name().getString() +
11334 func2->get_mangled_name().getString()
11340 if (func1->get_name() == func2->get_name())
11345 cout<<
"Error: SageInterface::isSameFunction(): unhandled language"<<endl;
11356 bool result =
false;
11357 ROSE_ASSERT(stmt != NULL);
11359 ROSE_ASSERT(p_scope != NULL);
11364 if (stmtlist[stmtlist.size()-1] == stmt)
11370 if (stmtlist[stmtlist.size()-1] == stmt)
11375 if (stmtlist[stmtlist.size()-1] == stmt)
11387 virtual void visit(
SgNode* n) {
11389 if (valueExp != NULL) {
11390 valueExp->set_originalExpressionTree(NULL);
11394 if (cast_exp != NULL) {
11395 cast_exp->set_originalExpressionTree(NULL);
11400 Visitor().traverse(top, preorder);
11405 while (s && !isSgSwitchStatement(s)) {
11409 return isSgSwitchStatement(s);
11414 while (s && !isSgOmpClauseBodyStatement(s)) {
11420 return isSgOmpClauseBodyStatement(s);
11426 for (; s; s = isSgStatement(s->
get_parent())) {
11431 case V_SgDoWhileStmt: {
11432 if (label.empty()) {
11437 case V_SgForStatement: {
11438 if (label.empty()) {
11443 case V_SgFortranDo:
11444 case V_SgFortranNonblockedDo: {
11445 if (label.empty() ||
11446 label == isSgFortranDo(sc)->get_string_label()) {
11451 case V_SgWhileStmt: {
11452 if (label.empty() ||
11453 label == isSgWhileStmt(sc)->get_string_label()) {
11458 case V_SgSwitchStatement: {
11459 if (stopOnSwitches)
return sc;
11462 case V_SgJavaForEachStatement: {
11463 if (label.empty()) {
11468 case V_SgJavaLabelStatement: {
11469 if (label.empty() ||
11470 label == isSgJavaLabelStatement(sc)->get_label().getString()) {
11486 virtual void visit(
SgNode* n) {
11487 if (isSgBasicBlock(n)) {
11489 bool changes =
true;
11492 for (SgStatementPtrList::iterator i = bb->
get_statements().begin();
11494 if (isSgGotoStatement(*i)) {
11496 SgStatementPtrList::iterator inext = i;
11500 if (!isSgLabelStatement(*inext))
11515 RemoveJumpsToNextStatementVisitor().traverse(top, postorder);
11524 ROSE_ASSERT (parent);
11528 ROSE_ASSERT (bb || fis);
11529 SgStatementPtrList& siblings =
11531 SgStatementPtrList::iterator j =
11532 std::find(siblings.begin(), siblings.end(), stmt);
11533 ROSE_ASSERT (j != siblings.end());
11546 SgLabelStatementPtrSet& used;
11547 SgLabelStatementPtrSet& all;
11550 FindUsedAndAllLabelsVisitor(SgLabelStatementPtrSet& used,
11551 SgLabelStatementPtrSet& all):
11552 used(used), all(all) {}
11554 virtual void visit(
SgNode* n) {
11555 if (isSgGotoStatement(n)) {
11556 used.insert(isSgGotoStatement(n)->get_label());
11558 if (isSgLabelStatement(n)) {
11559 all.insert(isSgLabelStatement(n));
11564 SgLabelStatementPtrSet used;
11565 SgLabelStatementPtrSet unused;
11566 FindUsedAndAllLabelsVisitor(used, unused).traverse(top, preorder);
11568 for (SgLabelStatementPtrSet::iterator i = used.begin();
11569 i != used.end(); ++i) {
11570 assert (unused.find(*i) != unused.end());
11583 for (SgLabelStatementPtrSet::iterator i = unused.begin();
11584 i != unused.end(); ++i) {
11592 l_stmt->set_statement(NULL);
11602 if (isSgWhileStmt(loopStmt))
return isSgWhileStmt(loopStmt)->
get_body();
11603 if (isSgForStatement(loopStmt))
return isSgForStatement(loopStmt)->
get_loop_body();
11604 if (isSgDoWhileStmt(loopStmt))
return isSgDoWhileStmt(loopStmt)->
get_body();
11606 ROSE_ASSERT (!
"Bad loop kind");
11611 if (isSgWhileStmt(loopStmt)) {
11612 isSgWhileStmt(loopStmt)->
set_body(body);
11613 }
else if (isSgForStatement(loopStmt)) {
11615 }
else if (isSgDoWhileStmt(loopStmt)) {
11616 isSgDoWhileStmt(loopStmt)->
set_body(body);
11618 ROSE_ASSERT (!
"Bad loop kind");
11624 if (isSgWhileStmt(loopStmt))
return isSgWhileStmt(loopStmt)->
get_condition();
11625 if (isSgForStatement(loopStmt))
return isSgForStatement(loopStmt)->get_test();
11626 if (isSgDoWhileStmt(loopStmt))
return isSgDoWhileStmt(loopStmt)->
get_condition();
11628 ROSE_ASSERT (!
"Bad loop kind");
11633 if (isSgWhileStmt(loopStmt)) {
11635 }
else if (isSgForStatement(loopStmt)) {
11636 isSgForStatement(loopStmt)->set_test(cond);
11637 }
else if (isSgDoWhileStmt(loopStmt)) {
11640 ROSE_ASSERT (!
"Bad loop kind");
11649 SgCastExp* cast_exp = isSgCastExp(exp);
11650 if (cast_exp != NULL)
11653 assert(operand != 0);
11654 return SkipCasting(operand);
11663 ROSE_ASSERT(loop!=NULL);
11665 SgStatementPtrList &init = loop ->get_init_stmt();
11666 if (init.size() !=1)
11677 ROSE_ASSERT(ivarname != NULL);
11679 if (isSgAssignInitializer(initor))
11681 lbast = isSgAssignInitializer(initor)->
get_operand();
11696 ROSE_ASSERT(funcDef!=NULL);
11698 ROSE_ASSERT(funcBody!=NULL);
11700 std::ostringstream os;
11701 os<<ivarname->get_name().getString();
11706 if (visibleSym != NULL)
11717 Rose_STL_Container<SgNode*> varRefs = NodeQuery::querySubTree(loop,V_SgVarRefExp);
11718 for (Rose_STL_Container<SgNode *>::iterator i = varRefs.begin(); i != varRefs.end(); i++)
11721 if (vRef->get_symbol()==osymbol)
11722 vRef->set_symbol(nsymbol);
11727 init.push_back(ninit);
11734 trans_records.forLoopInitNormalizationTable[loop] =
true;
11735 trans_records.forLoopInitNormalizationRecord[loop] = make_pair (decl, ndecl) ;
11748 ROSE_ASSERT (loop != NULL);
11750 if (!trans_records.forLoopInitNormalizationTable[loop])
11755 ROSE_ASSERT (decl!= NULL);
11756 ROSE_ASSERT (ndecl!= NULL);
11760 SgStatementPtrList &init = loop ->get_init_stmt();
11761 ROSE_ASSERT(init.size() ==1);
11766 ROSE_ASSERT (exp_stmt != NULL);
11767 SgAssignOp* assign_op = isSgAssignOp(exp_stmt->get_expression());
11768 ROSE_ASSERT (assign_op != NULL);
11775 init.push_back(decl);
11786 Rose_STL_Container<SgNode*> varRefs = NodeQuery::querySubTree(loop,V_SgVarRefExp);
11787 for (Rose_STL_Container<SgNode *>::iterator i = varRefs.begin(); i != varRefs.end(); i++)
11790 if (vRef->get_symbol()==osymbol)
11791 vRef->set_symbol(nsymbol);
11795 trans_records.forLoopInitNormalizationTable[loop] =
false;
11801 ROSE_ASSERT(loop != NULL);
11808 if (test_stmt!=NULL)
11810 if (isSgNullStatement(test_stmt))
11816 if (isSgBinaryOp(test))
11820 ROSE_ASSERT(testlhs && testrhs);
11825 SgVarRefExp* testlhs_var = isSgVarRefExp(SkipCasting(testlhs));
11826 if (testlhs_var == NULL )
11829 if (var_symbol==NULL)
11833 case V_SgLessThanOp:
11838 case V_SgGreaterThanOp:
11842 case V_SgLessOrEqualOp:
11843 case V_SgGreaterOrEqualOp:
11844 case V_SgNotEqualOp:
11853 ROSE_ASSERT(loop != NULL);
11857 if (isSgBinaryOp(test))
11861 ROSE_ASSERT(testlhs && testrhs);
11866 SgVarRefExp* testlhs_var = isSgVarRefExp(SkipCasting(testlhs));
11867 if (testlhs_var == NULL )
11870 if (var_symbol==NULL)
11876 ROSE_ASSERT(incr != NULL);
11878 case V_SgPlusPlusOp:
11881 SgVarRefExp* incr_var = isSgVarRefExp(SkipCasting(isSgPlusPlusOp(incr)->get_operand()));
11882 if (incr_var == NULL)
return false;
11883 if ( incr_var->get_symbol() != var_symbol)
11889 case V_SgMinusMinusOp:
11892 SgVarRefExp* incr_var = isSgVarRefExp(SkipCasting(isSgMinusMinusOp(incr)->get_operand()));
11893 if (incr_var == NULL)
return false;
11894 if ( incr_var->get_symbol() != var_symbol)
11900 case V_SgMinusAssignOp:
11902 SgVarRefExp* incr_var = isSgVarRefExp(SkipCasting(isSgMinusAssignOp(incr)->get_lhs_operand()));
11904 ROSE_ASSERT (rhs != NULL);
11905 if (incr_var == NULL)
return false;
11906 if ( incr_var->get_symbol() != var_symbol)
11913 case V_SgPlusAssignOp:
11926 ROSE_ASSERT(loop != NULL);
11944 ROSE_ASSERT(body!=NULL);
11962 ROSE_ASSERT (loop != NULL);
11964 if (isSgNullExpression(e_3))
11967 loop->set_increment(iv);
11982 ROSE_ASSERT(func!=NULL);
11983 AstInterfaceImpl faImpl(func->get_definition()->
get_body());
11984 AstInterface fa(&faImpl);
11985 ArrayAnnotation* annot = ArrayAnnotation::get_inst();
11986 ArrayInterface array_interface (*annot);
11987 array_interface.initialize(fa, AstNodePtrImpl(func->get_definition()));
11988 array_interface.observe(fa);
11989 LoopTransformInterface :: set_astInterface(fa);
11990 LoopTransformInterface :: set_arrayInterface(&array_interface);
11994 AstNodePtr result = AstNodePtrImpl(loop->
get_parent()) ;
11996 LoopUnrolling lu(unrolling_factor);
11999 result = lu(lpTrans, result);
12043#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
12045 if (unrolling_factor <= 1)
12066 cerr<<
"Error in SageInterface::loopUnrolling(): target loop is not canonical."<<endl;
12070 ROSE_ASSERT(ivar&& lb && ub && step);
12071 ROSE_ASSERT(isSgBasicBlock(orig_body));
12074 bool needFringe =
true;
12075 SgForStatement* fringe_loop = deepCopy<SgForStatement>(target_loop);
12093 ROSE_ASSERT(scope != NULL);
12097 attachComment(fringe_decl,
"iter_count = (ub-lb+1)%step ==0?(ub-lb+1)/step: (ub-lb+1)/step+1;");
12098 attachComment(fringe_decl,
"fringe = iter_count%unroll_factor==0 ? 0:unroll_factor*step");
12105 ConstantFolding::constantFoldingOptimization(fringe_decl,
false);
12107 ROSE_ASSERT(ivarname != NULL);
12111 if (isSgIntVal(init1->get_operand_i()))
12112 if (isSgIntVal(init1->get_operand_i())->get_value() == 0)
12113 needFringe =
false;
12117 ROSE_ASSERT(ub_bin_op);
12127 ROSE_ASSERT(step_bin_op != NULL);
12130 bool isPlus =
false;
12131 if (isSgPlusAssignOp(step_bin_op))
12133 else if (isSgMinusAssignOp(step_bin_op))
12137 cerr<<
"Error in SageInterface::loopUnrolling(): illegal incremental exp of a canonical loop"<<endl;
12143 for (
size_t i =1; i<unrolling_factor; i++)
12147 std::vector<SgVarRefExp*> refs = querySubTree<SgVarRefExp> (body, V_SgVarRefExp);
12148 for (std::vector<SgVarRefExp*>::iterator iter = refs.begin(); iter !=refs.end(); iter++)
12177 ConstantFolding::constantFoldingOptimization(scope,
false);
12189static size_t myfactorial (
size_t n)
12192 for (
size_t i=2; i<=n; i++)
12203std::vector<size_t> getPermutationOrder(
size_t n,
size_t lexicoOrder)
12205 size_t k = lexicoOrder;
12206 std::vector<size_t> s(n);
12208 for (
size_t i=0; i<n; i++)
12212 size_t factorial = myfactorial(n-1);
12214 if (k/n>=factorial)
12216 printf(
"Error: in getPermutationOrder(), lexicoOrder is larger than n!-1\n");
12232 for (
size_t j=0; j<n-1; j++)
12236 int tempj = (k/factorial) % (n - j);
12239 int temps = s[j+tempj];
12242 for (
size_t i=j+tempj; i>j; i--)
12249 factorial = factorial /(n-(j+1));
12252 for (
size_t i = 0; i<n; i++)
12284 ROSE_ASSERT(loopNest != NULL);
12285 ROSE_ASSERT(targetLevel >0);
12292 std::vector<SgForStatement* > loops= SageInterface::querySubTree<SgForStatement>(loopNest,V_SgForStatement);
12293 ROSE_ASSERT(loops.size()>=targetLevel);
12311 cerr<<
"Error in SageInterface::loopTiling(): target loop is not canonical."<<endl;
12315 ROSE_ASSERT(ivar&& lb && ub && step);
12323 parent = isSgLocatedNode(loopNest ->get_parent());
12325 ROSE_ASSERT(parent!= NULL);
12327 string ivar2_name =
"_lt_var_"+ivar->get_name().getString();
12337 if (isSgBinaryOp(orig_test))
12339 if (isSgLessOrEqualOp(orig_test))
12341 else if (isSgGreaterOrEqualOp(orig_test))
12347 cerr<<
"Error: illegal condition operator for a canonical loop"<<endl;
12354 cerr<<
"Error: illegal condition expression for a canonical loop"<<endl;
12358 ROSE_ASSERT(cond_stmt != NULL);
12363 SgExpression* orig_incr_exp = target_loop->get_increment();
12364 if( isSgPlusAssignOp(orig_incr_exp))
12368 else if (isSgMinusAssignOp(orig_incr_exp))
12374 cerr<<
"Error: illegal increment expression for a canonical loop"<<endl;
12386 ROSE_ASSERT(assign_op);
12390 ROSE_ASSERT(bin_op);
12410 if (lexicoOrder == 0)
12413 ROSE_ASSERT(loop != NULL);
12415 ROSE_ASSERT (depth >1);
12416 ROSE_ASSERT(lexicoOrder<myfactorial(depth));
12419 std::vector<SgForStatement* > loopNest = SageInterface::querySubTree<SgForStatement>(loop,V_SgForStatement);
12420 ROSE_ASSERT(loopNest.size()>=depth);
12421 std::vector<std::vector<SgNode*> > loopHeads;
12422 for (std::vector<SgForStatement* > ::iterator i = loopNest.begin(); i!= loopNest.end(); i++)
12425 std::vector<SgNode*> head;
12427 head.push_back(cur_loop->get_test());
12428 head.push_back(cur_loop->get_increment());
12429 loopHeads.push_back(head);
12433 std::vector<size_t> changedOrder = getPermutationOrder (depth, lexicoOrder);
12436 for (
size_t i=0; i<depth; i++)
12439 if (i != changedOrder[i])
12442 std::vector<SgNode*> newhead = loopHeads[changedOrder[i]];
12450 init->set_parent(cur_loop);
12455 cur_loop->set_test(test);
12463 cur_loop->set_increment(incr);
12477 ROSE_ASSERT(loop != NULL);
12483 SgAssignOp* assign_op = isSgAssignOp (do_loop->get_initialization());
12484 ROSE_ASSERT (assign_op != NULL);
12486 ROSE_ASSERT (var != NULL);
12487 ivarname = var->get_symbol()->get_declaration();
12488 ROSE_ASSERT (ivarname != NULL);
12502 SgStatementPtrList & init = fs->get_init_stmt();
12503 if (init.size() !=1)
12505 cerr<<
"SageInterface::getLoopIndexVariable(), no or more than one initialization statements are encountered. Not supported yet "<<endl;
12516 if (isSgVariableDeclaration(init1))
12520 ROSE_ASSERT(ivarname != NULL);
12527 SgVarRefExp* var = isSgVarRefExp(SkipCasting(ivarast));
12530 ivarname = var->get_symbol()->get_declaration();
12537 if (
SgCommaOpExp* comma_exp = isSgCommaOpExp(exp_stmt->get_expression()))
12544 SgVarRefExp* var = isSgVarRefExp(assign_op->get_lhs_operand());
12547 ivarname = var->get_symbol()->get_declaration();
12555 mlog[Sawyer::Message::Common::WARN] <<
"Warning: SageInterface::getLoopIndexVariable(). Unhandled init_stmt type of SgForStatement"<<endl;
12556 mlog[Sawyer::Message::Common::WARN] <<
"Init statement is :"<<init1->
class_name() <<
" " <<init1->
unparseToString()<<endl;
12574 ROSE_ASSERT (ivar != NULL);
12575 ROSE_ASSERT (subtree_root != NULL);
12576 bool result =
false;
12581 if (i_index == ivar)
12601 ROSE_ASSERT (loop !=NULL);
12602 SgStatementPtrList& stmt_list = loop->get_init_stmt();
12603 if (stmt_list.size() >1)
return true;
12604 if (stmt_list.size() == 0)
return false;
12609 if (decl_stmt != NULL)
12614 ROSE_ASSERT (exp_stmt != NULL);
12615 if (isSgCommaOpExp (exp_stmt->get_expression()) )
12625 ROSE_ASSERT(loop != NULL);
12633 SgAssignOp* init_assign = isSgAssignOp (init);
12638 bool isCase1=
false;
12643 ivarname = var->get_symbol()->get_declaration();
12645 if (ivarname && lbast )
12657 SgBinaryOp* test = isSgBinaryOp(fs->get_test_expr());
12661 case V_SgLessOrEqualOp:
12662 if (isInclusiveUpperBound != NULL)
12663 *isInclusiveUpperBound =
true;
12664 if (hasIncrementalIterationSpace != NULL)
12665 *hasIncrementalIterationSpace =
true;
12667 case V_SgLessThanOp:
12668 if (isInclusiveUpperBound != NULL)
12669 *isInclusiveUpperBound =
false;
12670 if (hasIncrementalIterationSpace != NULL)
12671 *hasIncrementalIterationSpace =
true;
12673 case V_SgGreaterOrEqualOp:
12674 if (isInclusiveUpperBound != NULL)
12675 *isInclusiveUpperBound =
true;
12676 if (hasIncrementalIterationSpace != NULL)
12677 *hasIncrementalIterationSpace =
false;
12679 case V_SgGreaterThanOp:
12680 if (isInclusiveUpperBound != NULL)
12681 *isInclusiveUpperBound =
false;
12682 if (hasIncrementalIterationSpace != NULL)
12683 *hasIncrementalIterationSpace =
false;
12692 if (testvar == NULL)
12698 ubast = loop->get_bound();
12700 if (isInclusiveUpperBound != NULL)
12701 *isInclusiveUpperBound =
true;
12704 ROSE_ASSERT (incr != NULL);
12705 if (isSgNullExpression(incr))
12707 cerr<<
"Error:isCanonicalDoLoop() found NULL increment expression. Please call doLoopNormalization() first!"<<endl;
12708 ROSE_ASSERT (
false);
12710 if (hasIncrementalIterationSpace != NULL)
12712 *hasIncrementalIterationSpace =
true;
12714 if (
SgIntVal* i_v = isSgIntVal(incr))
12716 if (i_v->get_value()<0)
12717 *hasIncrementalIterationSpace =
false;
12723 case V_SgPlusAssignOp:
12724 case V_SgMinusAssignOp:
12725 incr_var = isSgVarRefExp(SkipCasting(isSgBinaryOp(incr)->get_lhs_operand()));
12728 case V_SgPlusPlusOp:
12729 case V_SgMinusMinusOp:
12730 incr_var = isSgVarRefExp(SkipCasting(isSgUnaryOp(incr)->get_operand()));
12736 if (incr_var == NULL)
12750 if (body != NULL) {
12751 *body = fs->get_body();
12788 ROSE_ASSERT (s != NULL);
12791 std::set<SgNode*> bset = SgNodeHelper::loopRelevantBreakStmtNodes (s);
12792 if (bset.size()!=0 )
12806 ROSE_ASSERT(loop != NULL);
12817 SgStatementPtrList & init = fs->get_init_stmt();
12818 if (init.size() !=1)
12821 SgExpression* ivarast=NULL, *lbast=NULL, *ubast=NULL, *stepast=NULL;
12824 bool isCase1=
false, isCase2=
false;
12826 if (isSgVariableDeclaration(init1))
12830 ROSE_ASSERT(ivarname != NULL);
12832 if (isSgAssignInitializer(initor))
12834 lbast = isSgAssignInitializer(initor)->
get_operand();
12840 SgVarRefExp* var = isSgVarRefExp(SkipCasting(ivarast));
12843 ivarname = var->get_symbol()->get_declaration();
12848 ROSE_ASSERT(!(isCase1&&isCase2));
12850 if (!(isCase1||isCase2))
12862 case V_SgLessOrEqualOp:
12863 if (isInclusiveUpperBound != NULL)
12864 *isInclusiveUpperBound =
true;
12865 if (hasIncrementalIterationSpace != NULL)
12866 *hasIncrementalIterationSpace =
true;
12868 case V_SgLessThanOp:
12869 if (isInclusiveUpperBound != NULL)
12870 *isInclusiveUpperBound =
false;
12871 if (hasIncrementalIterationSpace != NULL)
12872 *hasIncrementalIterationSpace =
true;
12874 case V_SgGreaterOrEqualOp:
12875 if (isInclusiveUpperBound != NULL)
12876 *isInclusiveUpperBound =
true;
12877 if (hasIncrementalIterationSpace != NULL)
12878 *hasIncrementalIterationSpace =
false;
12880 case V_SgGreaterThanOp:
12881 if (isInclusiveUpperBound != NULL)
12882 *isInclusiveUpperBound =
false;
12883 if (hasIncrementalIterationSpace != NULL)
12884 *hasIncrementalIterationSpace =
false;
12893 if (testvar == NULL)
12917 case V_SgPlusAssignOp:
12918 case V_SgMinusAssignOp:
12919 incr_var = isSgVarRefExp(SkipCasting(isSgBinaryOp(incr)->get_lhs_operand()));
12922 case V_SgPlusPlusOp:
12923 case V_SgMinusMinusOp:
12924 incr_var = isSgVarRefExp(SkipCasting(isSgUnaryOp(incr)->get_operand()));
12927 case V_SgAssignOp: {
12928 incr_var=isSgVarRefExp(SkipCasting(isSgBinaryOp(incr)->get_lhs_operand()));
12929 if(incr_var == NULL)
12931 SgAddOp* addOp=isSgAddOp(SkipCasting(isSgBinaryOp(incr)->get_rhs_operand()));
12932 SgSubtractOp* subtractOp=isSgSubtractOp(SkipCasting(isSgBinaryOp(incr)->get_rhs_operand()));
12936 else if(subtractOp)
12937 arithOp=subtractOp;
12940 ROSE_ASSERT(arithOp!=0);
12941 if(
SgVarRefExp* varRefExp=isSgVarRefExp(SkipCasting(isSgBinaryOp(arithOp)->get_lhs_operand()))) {
12943 incr_var=varRefExp;
12945 }
else if(
SgVarRefExp* varRefExp=isSgVarRefExp(SkipCasting(isSgBinaryOp(arithOp)->get_rhs_operand()))) {
12946 if(isSgAddOp(arithOp)) {
12948 incr_var=varRefExp;
12958 if (incr_var == NULL)
12979 if (body != NULL) {
12988 ROSE_ASSERT(loop != NULL);
12989 ROSE_ASSERT(lb != NULL);
12994 if (forstmt != NULL)
12999 Rose_STL_Container<SgNode* > testList = NodeQuery::querySubTree( *((forstmt->get_init_stmt()).begin()), V_SgAssignOp);
13000 if (testList.size()>0)
13002 ROSE_ASSERT(testList.size()==1);
13003 SgAssignOp * assignop = isSgAssignOp((*testList.begin()));
13004 ROSE_ASSERT(assignop);
13014 Rose_STL_Container<SgNode* > testList = NodeQuery::querySubTree( *((forstmt->get_init_stmt()).begin()), V_SgAssignInitializer );
13015 ROSE_ASSERT(testList.size()==1);
13017 ROSE_ASSERT(init != NULL);
13018 init->set_operand(lb);
13023 else if (dostmt != NULL)
13026 ROSE_ASSERT (init != NULL);
13028 ROSE_ASSERT (a_op!=NULL);
13035 cerr<<
"Error. SageInterface::setLoopLowerBound(), illegal loop type:"<< loop->
class_name()<<endl;
13036 ROSE_ASSERT (
false);
13043 ROSE_ASSERT(loop != NULL);
13044 ROSE_ASSERT(ub != NULL);
13048 if (forstmt != NULL)
13051 SgBinaryOp * binop= isSgBinaryOp(isSgExprStatement(forstmt->get_test())->get_expression());
13052 ROSE_ASSERT(binop != NULL);
13056 else if (dostmt != NULL)
13058 dostmt->set_bound(ub);
13064 cerr<<
"Error. SageInterface::setLoopUpperBound(), illegal loop type:"<< loop->
class_name()<<endl;
13065 ROSE_ASSERT (
false);
13073 ROSE_ASSERT(loop != NULL);
13074 ROSE_ASSERT(stride != NULL);
13078 if (dostmt != NULL)
13080 dostmt->set_increment(stride);
13084 else if (forstmt != NULL)
13088 Rose_STL_Container<SgNode*> testList = NodeQuery::querySubTree( forstmt->get_increment(), V_SgPlusPlusOp);
13089 if (testList.size()>0)
13091 ROSE_ASSERT(testList.size() == 1);
13093 (isSgPlusPlusOp( *testList.begin())->
get_operand()));
13095 forstmt->set_increment(plusassignop);
13099 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgMinusMinusOp);
13100 if (testList.size()>0)
13102 ROSE_ASSERT(testList.size()==1);
13104 (isSgMinusMinusOp(*testList.begin())->
get_operand()));
13106 forstmt->set_increment(plusassignop);
13110 testList = NodeQuery::querySubTree( forstmt->get_increment(), V_SgPlusAssignOp);
13111 if (testList.size()>0)
13113 ROSE_ASSERT(testList.size()==1);
13114 SgPlusAssignOp * assignop = isSgPlusAssignOp(*(testList.begin()));
13115 ROSE_ASSERT(assignop!=NULL);
13120 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgMinusAssignOp);
13121 if (testList.size()>0)
13123 ROSE_ASSERT(testList.size()==1);
13126 SgExprStatement* exprstmt = isSgExprStatement((*testList.begin())->get_parent());
13127 ROSE_ASSERT(exprstmt !=NULL);
13129 exprstmt->set_expression(plusassignop);
13140 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgAddOp);
13141 if (testList.size()>0)
13143 ROSE_ASSERT(testList.size()==1);
13145 SgAddOp * addop = isSgAddOp(*(testList.begin()));
13146 ROSE_ASSERT(addop!=NULL);
13160 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgSubtractOp);
13161 if (testList.size()>0)
13163 ROSE_ASSERT(testList.size()==1);
13165 SgSubtractOp * subtractop = isSgSubtractOp(*(testList.begin()));
13166 ROSE_ASSERT(subtractop!=NULL);
13169 SgAssignOp *assignop = isSgAssignOp((*testList.begin())->get_parent());
13170 ROSE_ASSERT(assignop !=NULL);
13177 cerr<<
"Error. SageInterface::setLoopStride(), illegal loop type:"<< loop->
class_name()<<endl;
13178 ROSE_ASSERT (
false);
13189 SgExpression *exp = (n != 0)? n->get_expression() : isSgExpression(s);
13192 case V_SgPlusAssignOp:
13193 case V_SgMinusAssignOp:
13194 case V_SgAndAssignOp:
13195 case V_SgIorAssignOp:
13196 case V_SgMultAssignOp:
13197 case V_SgDivAssignOp:
13198 case V_SgModAssignOp:
13199 case V_SgXorAssignOp:
13207 if ( init->variantT() == V_SgAssignInitializer)
13208 init = isSgAssignInitializer(init)->
get_operand();
13212 *readlhs = (exp->
variantT() != V_SgAssignOp);
13226 Rose_STL_Container<SgNode*> gotos = NodeQuery::querySubTree(top,V_SgGotoStatement);
13227 for (
size_t i = 0; i < gotos.size(); ++i)
13232 if (!lsParent)
continue;
13235 size_t j = std::find(bbStatements.begin(), bbStatements.end(), ls) - bbStatements.begin();
13237 ROSE_ASSERT (j != bbStatements.size());
13239 while (j < bbStatements.size() - 1 && isSgLabelStatement(bbStatements[j + 1]))
13243 gs->
set_label(isSgLabelStatement(bbStatements[j]));
13259 ROSE_ASSERT(decl != NULL);
13260 ROSE_ASSERT(assign_stmt != NULL);
13263 SgAssignOp * assign_op = isSgAssignOp (assign_stmt->get_expression());
13264 if (assign_op == NULL)
13267 if (assign_op_var == NULL)
return false;
13271 if (decl_var->get_initptr()!= NULL )
return false;
13278 if (decl_var_symbol!=NULL)
13281 if (assign_op_var->get_symbol() != decl_var_symbol)
return false;
13286 if (assign_op_var->get_symbol()->
get_name() != decl_var ->get_name())
return false;
13300 if (removeAssignStmt)
13304 decl_var->set_initptr(initor);
13315 ROSE_ASSERT(assign_stmt != NULL);
13316 SgAssignOp * assign_op = isSgAssignOp (assign_stmt->get_expression());
13317 if (assign_op == NULL)
13320 if (assign_op_var == NULL)
13324 ROSE_ASSERT(decl != NULL);
13326 if (decl_var->get_initptr()!= NULL)
13333 ROSE_ASSERT(decl_var != NULL);
13335 if (decl_var_symbol != NULL) {
13337 if (assign_op_var->get_symbol() != decl_var_symbol)
13343 if (assign_op_var->get_symbol()->
get_name() != decl_var ->get_name())
13356 decl_var->set_initptr(initor);
13386 ROSE_ASSERT (decl != NULL);
13390 if (initor == NULL)
13397 rhs = ainitor->get_operand();
13403 decl_var->set_initptr(NULL);
13415 cerr<<
"SageInterface::splitVariableDeclaration() topLevelOnly == false is not yet implemented."<<endl;
13416 ROSE_ASSERT (
false);
13419 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(scope, V_SgVariableDeclaration);
13420 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
13425 ROSE_ASSERT(decl != NULL);
13438 ROSE_ASSERT (root != NULL);
13441 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(root, V_SgVarRefExp);
13445 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
13448 ROSE_ASSERT (vRef != NULL);
13449 result.push_back(vRef);
13456 ROSE_ASSERT (root != NULL);
13457 Rose_STL_Container<SgNode*> constructorList= NodeQuery::querySubTree(root, V_SgConstructorInitializer);
13458 for (
size_t i =0; i< constructorList.size(); i++)
13463 Rose_STL_Container<SgNode*> varList = NodeQuery::querySubTree (a_type->get_index(),V_SgVarRefExp);
13464 for (
size_t j =0 ; j< varList.size(); j++)
13466 SgVarRefExp* var_exp = isSgVarRefExp(varList[j]) ;
13467 currentVarRefList.push_back(var_exp);
13491 SgExpression* lhsCopy = isSgExpression(lhs->copy(treeCopy));
13492 ROSE_ASSERT (lhsCopy);
13516 SgExpression* lhsCopy = isSgExpression(lhs->copy(treeCopy));
13517 ROSE_ASSERT (lhsCopy);
13541 SgExpression* lhsCopy = isSgExpression(lhs->copy(treeCopy));
13542 ROSE_ASSERT (lhsCopy);
13559 ROSE_ASSERT(from != NULL);
13561#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
13565 ROSE_ASSERT (
false);
13570 SgStatement* stmt = getStatementOfExpression(from);
13572 if (!isSgForInitStatement(stmt->
get_parent())) {
13581 if (!parent && isSgForInitStatement(stmt->
get_parent()))
13587 SgName varname =
"rose_temp__";
13588 if (newName ==
"") {
13596 vector<SgExpression*> ancestors;
13597 for (
SgExpression *expr = from, *anc = isSgExpression(fromparent); anc != 0;
13598 expr = anc, anc = isSgExpression(anc->get_parent()))
13600 if ((isSgAndOp(anc) && expr != isSgAndOp(anc)->get_lhs_operand()) ||
13603 ancestors.push_back(anc);
13606 for (vector<SgExpression*>::reverse_iterator ai = ancestors.rbegin(); ai != ancestors.rend(); ++ai)
13609 switch ((*ai)->variantT()) {
13614 case V_SgConditionalExp:
13616 default: assert (!
"Should not happen"); abort();
13621 if (ancestors.size() != 0) {
13629 ROSE_ASSERT (initname);
13631 replaceExpressionWithExpression(from, varref);
13635 initname->set_initializer(ai);
13637 myStatementInsert(stmt, vardecl,
true);
13658 SplitStatementGenerator gen;
13664 Rose_STL_Container<SgNode*> gotos = NodeQuery::querySubTree(top,
13665 V_SgGotoStatement);
13666 map<SgLabelStatement*, SgLabelStatement*> labelsToReplace;
for
13667 (
size_t i = 0; i < gotos.size(); ++i) {
13670 if (!gsParent)
continue;
13672 size_t j = std::find(bbStatements.begin(), bbStatements.end(), gs)
13673 - bbStatements.begin();
13674 ROSE_ASSERT (j != bbStatements.size());
13675 if (j == 0)
continue;
13676 if (isSgLabelStatement(bbStatements[j - 1])) {
13677 labelsToReplace[isSgLabelStatement(bbStatements[j - 1])] =
13681 for (
size_t i = 0; i < gotos.size(); ++i) {
13684 while (labelsToReplace.find(oldLabel) != labelsToReplace.end()) {
13685 oldLabel = labelsToReplace[oldLabel];
13695 case V_SgBoolValExp:
return (isSgBoolValExp(e)->get_value() != 0);
13697 case V_SgBoolValExp:
return (isSgBoolValExp(e)->get_value() ==
true);
13699 case V_SgIntVal:
return isSgIntVal(e)->get_value() != 0;
13700 case V_SgCastExp:
return isConstantTrue(isSgCastExp(e)->get_operand());
13702 case V_SgAddressOfOp:
return true;
13703 default:
return false;
13709 case V_SgBoolValExp:
return isSgBoolValExp(e)->get_value() ==
false;
13710 case V_SgIntVal:
return isSgIntVal(e)->get_value() == 0;
13711 case V_SgCastExp:
return
13713 case V_SgNotOp:
return isConstantTrue(isSgNotOp(e)->get_operand());
13714 default:
return false;
13721 if (!fc)
return false;
13723 if (fr == NULL)
return false;
13724 return fr->get_symbol()->get_declaration() == decl;
13730 if (!fc)
return false;
13732 if (fr == NULL)
return false;
13734 fr->get_symbol()->get_declaration()->get_qualified_name().getString();
13735 return (name == qualifiedName &&
13736 fc->get_args()->get_expressions().size() == arity);
13741 ROSE_ASSERT( e != NULL);
13757 ROSE_ASSERT(expList);
13759 expList->append_expression(exp);
13765 for (
size_t i = 0; i < exp.size(); ++i)
13774template <
class actualFunction>
13784 ROSE_ASSERT(paralist);
13789 cerr <<
"Waring! Setting a used SgFunctionParameterList to function: "
13790 << (func->get_name()).getString()<<endl
13791 <<
" Sharing parameter lists can corrupt symbol tables!"<<endl
13792 <<
" Please use deepCopy() to get an exclusive parameter list for each function declaration!"<<endl;
13797 if (func->get_parameterList() != NULL)
13798 if (func->get_parameterList() != paralist)
13799 delete func->get_parameterList();
13801 func->set_parameterList(paralist);
13809 ROSE_ASSERT(paraList != NULL);
13810 ROSE_ASSERT(initName != NULL);
13812 if (isPrepend ==
true)
13813 paraList->prepend_arg(initName);
13815 paraList->append_arg(initName);
13822 ROSE_ASSERT(initName->
get_parent() == paraList);
13832 if (func_decl != NULL)
13838 ROSE_ASSERT(func_def);
13848 initName->set_declptr(func_decl);
13860 initName->set_scope(scope);
13880 return addArg(paraList,initName,
false);
13885 return addArg(paraList,initName,
true);
13891 ROSE_ASSERT(pragma);
13892 if (decl->get_pragma()!=NULL)
delete (decl->get_pragma());
13893 decl->set_pragma(pragma);
13904 void testAstForUniqueNodes (
SgNode* node );
13907 printf (
"In SageInterface::appendStatement(): stmt = %p = %s scope = %p \n",stmt,stmt->
class_name().c_str(),scope);
13916 printf (
" --- scope was not specified as input! \n");
13921 ROSE_ASSERT(stmt != NULL);
13922 ROSE_ASSERT(scope != NULL);
13925 printf (
"In SageInterface::appendStatement(): stmt = %p = %s scope = %p = %s \n",stmt,stmt->
class_name().c_str(),scope,scope->
class_name().c_str());
13932 if (declarationStatement != NULL)
13960 scope->insertStatementInScope(stmt,
false);
13964 bool skipAddingStatement =
false;
13966 if (classDeclaration != NULL)
13972 printf (
"Since the parent of this SgClassDeclaration is set, it must have been previously added to the AST: classDeclaration = %p = %s \n",classDeclaration,classDeclaration->
class_name().c_str());
13978 skipAddingStatement = (classDeclaration->get_isAutonomousDeclaration() ==
false);
13982 skipAddingStatement = (classDeclaration->get_isAutonomousDeclaration() ==
false) || (classDeclaration->
get_parent() != NULL);
13997 if (statementAlreadyExistsInScope ==
true)
13999 if (isSgTemplateInstantiationDecl(classDeclaration) != NULL)
14003#if PRINT_DEVELOPER_WARNINGS
14004 printf (
"RARE ISSUE #1: In SageInterface::appendStatement(): This template instantiation has previously been added to the scope, so avoid doing so again (see test2013_198.C): classDeclaration = %p = %s scope = %p = %s \n",
14012 printf (
"RARE ISSUE #2: In SageInterface::appendStatement(): This statement has previously been added to the scope, so avoid doing so again (see rose.h): stmt = %p = %s scope = %p = %s \n",
14017 skipAddingStatement =
true;
14024 if (enumDeclaration != NULL)
14027 skipAddingStatement = (enumDeclaration->get_isAutonomousDeclaration() ==
false);
14036 if (skipAddingStatement ==
false && statementAlreadyExistsInScope ==
true)
14039 printf (
"RARE ISSUE #2: In SageInterface::appendStatement(): This statement has previously been added to the scope, so avoid doing so again (see rose.h): stmt = %p = %s scope = %p = %s \n",
14043 printf (
"Exiting as a test! \n");
14046 skipAddingStatement =
true;
14051 printf (
" --- skipAddingStatement = %s \n",skipAddingStatement ?
"true" :
"false");
14054 if (skipAddingStatement ==
false)
14066 printf (
" --- calling insertStatementInScope(): scope = %p = %s stmt = %p = %s \n",scope,scope->
class_name().c_str(),stmt,stmt->
class_name().c_str());
14068 scope->insertStatementInScope(stmt,
false);
14095 testAstForUniqueNodes(scope);
14104 ROSE_ASSERT (stmt != NULL);
14105 ROSE_ASSERT (for_init_stmt != NULL);
14108 printf (
"In SageInterface::appendStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: stmt) \n",stmt,stmt->
class_name().c_str(),scope,scope->
class_name().c_str());
14117 printf (
"In SageInterface::appendStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: scope) \n",stmt,stmt->
class_name().c_str(),scope,scope->
class_name().c_str());
14125 for_init_stmt->append_init_stmt (stmt);
14131 for (
size_t i = 0; i < stmts.size(); ++i)
14134#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
14135 printf (
"In appendStatementList(): stmts[i = %" PRIuPTR
"] = %p = %s \n",i,stmts[i],stmts[i]->class_name().c_str());
14141 if (stmts[i]->get_parent() != NULL)
14144#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
14145 printf (
" --- In appendStatementList(): stmts[i = %" PRIuPTR
"] will be added to scope (because stmts[i]->get_parent() != NULL (= %p = %s) \n",i,stmts[i]->get_parent(),stmts[i]->get_parent()->class_name().c_str());
14152 printf (
" --- WARNING: In appendStatementList(): stmts[i = %" PRIuPTR
"] not added to scope (because stmts[i]->get_parent() == NULL) \n",i);
14161 ROSE_ASSERT (stmt != NULL);
14164 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p \n",stmt,stmt->
class_name().c_str(),scope);
14174 ROSE_ASSERT(scope != NULL);
14184 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: stmt) \n",
14196 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: scope) \n",
14208 printf (
"Calling insertStatementInScope() \n");
14214 scope->insertStatementInScope(stmt,
true);
14234 printf (
"Leaving SageInterface::prependStatement() \n");
14242 ROSE_ASSERT (stmt != NULL);
14243 ROSE_ASSERT (for_init_stmt != NULL);
14246 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: stmt) \n",stmt,stmt->
class_name().c_str(),scope,scope->
class_name().c_str());
14255 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: scope) \n",stmt,stmt->
class_name().c_str(),scope,scope->
class_name().c_str());
14263 for_init_stmt->prepend_init_stmt (stmt);
14268 for (
size_t i = stmts.size(); i > 0; --i)
14280 ROSE_ASSERT (scope != NULL);
14283 case V_SgBasicBlock:
14284 case V_SgClassDefinition:
14285 case V_SgFunctionDefinition:
14287 case V_SgNamespaceDefinitionStatement:
14291 case V_SgAssociateStatement :
14292 case V_SgBlockDataStatement :
14293 case V_SgCatchOptionStmt:
14294 case V_SgDoWhileStmt:
14295 case V_SgForAllStatement:
14296 case V_SgForStatement:
14297 case V_SgFortranDo:
14299 case V_SgSwitchStatement:
14300 case V_SgUpcForAllStatement:
14301 case V_SgWhileStmt:
14306 cout<<
"unrecognized or unhandled scope type for SageInterface::hasSimpleChildrenList() "<<endl;
14319 SgDeclarationStatementPtrList & declarationList = globalScope->
get_declarations();
14322 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
14324 while (i != declarationList.end() && (*i)->get_file_info() != NULL && (*i)->get_file_info()->isFrontendSpecific() ==
true)
14327 printf (
"(*i)->get_file_info()->get_file_id() = %d isFrontendSpecific = %s \n",(*i)->get_file_info()->get_file_id(),(*i)->get_file_info()->isFrontendSpecific() ?
"true" :
"false");
14329 last_statement = *i;
14334 ROSE_ASSERT(last_statement != NULL);
14336 printf (
"last_statement = %p = %s \n",last_statement,last_statement->
class_name().c_str());
14339 printf (
"Exiting as a test! \n");
14343 return last_statement;
14352 ROSE_ASSERT(targetStmt &&newStmt);
14353 ROSE_ASSERT(targetStmt != newStmt);
14355 if (parent == NULL)
14357 cerr <<
"Empty parent pointer for target statement. May be caused by the wrong order of target and new statements in insertStatement(targetStmt, newStmt)"<<endl;
14358 ROSE_ASSERT(parent);
14361 if (isSgLabelStatement(parent) != NULL)
14364 printf (
"In SageInterface::insertStatement(): Detected case of label statement as parent, using parent of label statement \n");
14369 ROSE_ASSERT(isSgLabelStatement(parent) == NULL);
14373 printf (
"In SageInterface::insertStatement(): insert newStmt = %p = %s before/after targetStmt = %p = %s \n",newStmt,newStmt->
class_name().c_str(),targetStmt,targetStmt->
class_name().c_str());
14391 ROSE_ASSERT(scope);
14394 printf (
"targetStmt = %p = %s \n",targetStmt,targetStmt->
class_name().c_str());
14395 printf (
"scope = %p = %s \n",scope,scope->
class_name().c_str());
14413 ROSE_ASSERT(isSgStatement(parent) != NULL);
14418 ROSE_ASSERT(targetStmt != NULL);
14422 printf (
"In SageInterface::insertStatement(): after checking for associated comments \n");
14423 reportNodesMarkedAsModified(scope);
14429 if (autoMovePreprocessingInfo)
14431 if (comments != NULL && isSgBasicBlock(newStmt) == NULL)
14433 vector<int> captureList;
14435 printf (
"Found attached comments (at %p = %s, inserting %p = %s insertBefore = %s): comments->size() = %" PRIuPTR
" \n",
14436 targetStmt,targetStmt->
class_name().c_str(),newStmt,newStmt->
class_name().c_str(),insertBefore ?
"true" :
"false",comments->size());
14443 printf (
"Warning: at present statements being inserted should not have attached comments of CPP directives (could be a problem, but comment relocation is not disabled). \n");
14448 int commentIndex = 0;
14449 AttachedPreprocessingInfoType::iterator i;
14450 for (i = comments->begin(); i != comments->end(); i++)
14452 ROSE_ASSERT ( (*i) != NULL );
14454 printf (
" Attached Comment (relativePosition=%s): %s\n",
14455 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
14456 (*i)->getString().c_str());
14457 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
14458 (*i)->get_file_info()->display(
"comment/directive location");
14461 if ((*i)->getRelativePosition() == relativePosition)
14464 captureList.push_back(commentIndex);
14471 if (captureList.empty() ==
false)
14477 ROSE_ASSERT(surroundingStatement != targetStmt);
14478 ROSE_ASSERT(surroundingStatement != NULL);
14480 if (surroundingStatement == NULL)
14483 surroundingStatement = (insertBefore ==
true) ? newStmt : newStmt;
14488 vector<int>::iterator j = captureList.begin();
14489 while (j != captureList.end())
14497 (*comments)[*j] = NULL;
14504 for (
size_t n = 0; n < captureList.size(); n++)
14506 AttachedPreprocessingInfoType::iterator k = comments->begin();
14507 while (k != comments->end())
14512 comments->erase(k);
14525 if (comments != NULL)
14527 printf (
"Warning: special rules appear to apply to the insertion of a SgBasicBlock which has attached comments and/or CPP directives (comment relocation disabled). \n");
14534 printf (
"In SageInterface::insertStatement(): after processing associated comments \n");
14535 reportNodesMarkedAsModified(scope);
14538 if (isSgIfStmt(parent))
14540 if (isSgIfStmt(parent)->get_conditional()==targetStmt)
14546 if (isSgIfStmt(parent)->get_true_body()==targetStmt)
14566 if (isSgIfStmt(parent)->get_false_body()==targetStmt)
14580 if (isSgWhileStmt(parent))
14582 if (isSgWhileStmt(parent)->get_condition()==targetStmt)
14588 if (isSgWhileStmt(parent)->get_body()==targetStmt)
14591 isSgWhileStmt(parent)->
set_body(newparent);
14601 if (isSgDoWhileStmt(parent))
14603 if (isSgDoWhileStmt(parent)->get_condition()==targetStmt)
14609 if (isSgDoWhileStmt(parent)->get_body()==targetStmt)
14612 isSgDoWhileStmt(parent)->
set_body(newparent);
14622 if (isSgForStatement(parent))
14624 if (isSgForStatement(parent)->get_loop_body()==targetStmt)
14635 if (isSgForStatement(parent)->get_test()==targetStmt)
14656 p->set_body(newparent);
14664 ROSE_ASSERT(stmnt != NULL);
14686 printf (
"In SageInterface::insertStatement(): at BASE of function \n");
14687 reportNodesMarkedAsModified(scope);
14696 for (
size_t i = 0; i < newStmts.size(); ++i)
14703 for (
size_t i = newStmts.size(); i > 0; --i)
14712 insertStatement(targetStmt,newStmt,
false, autoMovePreprocessingInfo);
14723 ROSE_ASSERT (stmt != NULL);
14724 ROSE_ASSERT (scope != NULL);
14736 ROSE_ASSERT (scope != NULL);
14737 vector <SgStatement* >::iterator iter;
14739 for (iter= stmt_list.begin(); iter != stmt_list.end(); iter++)
14741 if (iter == stmt_list.begin())
14747 ROSE_ASSERT (prev_stmt != NULL);
14756 ROSE_ASSERT(newStmt!=NULL);
14757 ROSE_ASSERT(scope!=NULL);
14759 if (!isSgDeclarationStatement(targetStmt)) {
14769 ROSE_ASSERT(scope!=NULL);
14771 if (!isSgDeclarationStatement(targetStmt)) {
14794 ROSE_ASSERT(target);
14795 ROSE_ASSERT(operand);
14796 ROSE_ASSERT(target!=operand);
14797 switch (target->variantT())
14799 case V_SgActualArgumentExpression:
14800 isSgActualArgumentExpression(target)->set_expression(operand);
14803 isSgAsmOp(target)->set_expression(operand);
14806 isSgSizeOfOp(target)->set_operand_expr(operand);
14809 isSgTypeIdOp(target)->set_operand_expr(operand);
14812 isSgVarArgOp(target)->set_operand_expr(operand);
14814 case V_SgVarArgStartOneOperandOp:
14815 isSgVarArgStartOneOperandOp(target)->set_operand_expr(operand);
14817 case V_SgAssignInitializer:
14818 isSgAssignInitializer (target)->
set_operand(operand);
14821 if (isSgUnaryOp(target)!=NULL)
14825 cerr<<
"\tSageInterface::setOperand(): unhandled case for target expression of type "
14826 <<target->class_name()<<endl;
14831 markLhsValues(target);
14837 ROSE_ASSERT(target);
14839 ROSE_ASSERT(target!=lhs);
14840 bool hasrhs =
false;
14846 if (varargcopy!=NULL)
14848 varargcopy->set_lhs_operand(lhs);
14849 if( varargcopy->get_rhs_operand()!=NULL) hasrhs=
true;
14851 else if(varargstart!=NULL)
14853 varargstart->set_lhs_operand(lhs);
14854 if( varargstart->get_rhs_operand()!=NULL) hasrhs=
true;
14856 else if(binary!=NULL)
14863 cout<<
"SageInterface::setLhsOperand(): unhandled case for target expression of type "
14864 <<target->class_name()<<endl;
14871 markLhsValues(target);
14876 ROSE_ASSERT(target);
14878 ROSE_ASSERT(target!=rhs);
14879 bool haslhs =
false;
14885 if (varargcopy!=NULL)
14887 varargcopy->set_rhs_operand(rhs);
14888 if( varargcopy->get_lhs_operand()!=NULL) haslhs=
true;
14890 else if(varargstart!=NULL)
14892 varargstart->set_rhs_operand(rhs);
14893 if( varargstart->get_lhs_operand()!=NULL) haslhs=
true;
14895 else if(binary!=NULL)
14902 cout<<
"SageInterface::setRhsOperand(): unhandled case for target expression of type "
14903 <<target->class_name()<<endl;
14909 markLhsValues(target);
14928 ROSE_ASSERT(parentFileList != NULL);
14934 if (parentDirectory != NULL)
14937 parentDirectory->get_directoryList()->get_listOfDirectories().push_back(directory);
14944 project = isSgProject(parentFileList->
get_parent());
14945 ROSE_ASSERT(project != NULL);
14948 project->get_directoryList()->get_listOfDirectories().push_back(directory);
14955 directory->get_fileList()->get_listOfFiles().push_back(file);
14958 parentFileList->get_listOfFiles().erase(find(parentFileList->get_listOfFiles().begin(),parentFileList->get_listOfFiles().end(),file));
14968 ROSE_ASSERT(structDecl != NULL);
14969 ROSE_ASSERT(scope != NULL);
14971 ROSE_ASSERT(nondefdecl != NULL);
14997 SgName name = structDecl->get_name();
15011 if (mysymbol == NULL)
15013 printf (
"Note: SageInterface::fixStructDeclaration(): structDecl = %p nondefdecl = %p (mysymbol == NULL) \n",structDecl,nondefdecl);
15017 ROSE_ASSERT(structDecl->
get_scope() != NULL);
15022 ROSE_ASSERT(mysymbol);
15025 printf (
"############## DANGER:DANGER:DANGER ################\n");
15027 printf (
"In SageInterface::fixStructDeclaration(): Adding class symbol to scope = %p = %s \n",scope,scope->
class_name().c_str());
15035 printf (
"*** WARNING: In SageInterface::fixStructDeclaration(): (mysymbol == NULL) Commented out the setting of the parent to be the same as the scope \n");
15044 printf (
"In SageInterface::fixStructDeclaration(): (mysymbol == NULL) Skipped building an associated symbol! \n");
15049 ROSE_ASSERT(nondefdecl->get_type() != NULL);
15052 ROSE_ASSERT(nondefdecl->get_type()->
variantT() != V_SgNode);
15055 ROSE_ASSERT(isSgClassType(nondefdecl->get_type()) != NULL);
15059 if (nondefdecl->get_type() == NULL)
15063 ROSE_ASSERT (nondefdecl->get_type() != NULL);
15066 if (defdecl != NULL)
15069 ROSE_ASSERT(defdecl->get_type()->
variantT() != V_SgNode);
15072 ROSE_ASSERT(isSgClassType(defdecl->get_type()) != NULL);
15076 if (defdecl != NULL)
15079 ROSE_ASSERT(defdecl->get_type() != NULL);
15080 if (defdecl->get_type() != nondefdecl->get_type())
15082 printf (
"ERROR: defdecl->get_type() != nondefdecl->get_type(): what are these: \n");
15083 printf (
" defdecl->get_type() = %p = %s \n",defdecl ->get_type(),defdecl ->get_type()->class_name().c_str());
15084 SgNamedType* namedType_definingDecl = isSgNamedType(defdecl->get_type());
15085 if (namedType_definingDecl != NULL)
15087 printf (
"namedType_definingDecl->get_declaration() = %p = %s \n",namedType_definingDecl->get_declaration(),namedType_definingDecl->get_declaration()->
class_name().c_str());
15089 printf (
" nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->
class_name().c_str());
15090 SgNamedType* namedType_nondefiningDecl = isSgNamedType(nondefdecl->get_type());
15091 if (namedType_nondefiningDecl != NULL)
15093 printf (
"namedType_nondefiningDecl->get_declaration() = %p = %s \n",namedType_nondefiningDecl->get_declaration(),namedType_nondefiningDecl->get_declaration()->
class_name().c_str());
15109 ROSE_ASSERT(structDecl);
15110 ROSE_ASSERT(scope);
15112 ROSE_ASSERT(nondefdecl);
15131 if (mysymbol==NULL)
15138 ROSE_ASSERT(mysymbol);
15140 printf (
"In SageInterface::fixNamespaceDeclaration(): inserting namespace symbol into scope = %p = %s \n",scope,scope->
class_name().c_str());
15144 ROSE_ASSERT(defdecl);
15156 ROSE_ASSERT(varDecl != NULL);
15157 ROSE_ASSERT(scope != NULL);
15159 SgInitializedNamePtrList namelist = varDecl->
get_variables();
15164 printf (
"In SageInterface::fixVariableDeclaration(): varDecl = %p scope = %p = %s \n",varDecl,scope,scope->
class_name().c_str());
15167 ROSE_ASSERT(namelist.size() > 0);
15169 SgInitializedNamePtrList::iterator i;
15170 for (i = namelist.begin(); i != namelist.end(); i++)
15173 ROSE_ASSERT(initName != NULL);
15175 SgName name = initName->get_name();
15177 printf (
" -- initName = %p : %s\n", initName, name.str());
15178 printf (
" -- initName->get_scope() = %p (%s)\n", initName->get_scope(), initName->get_scope() ? initName->get_scope()->
class_name().c_str() :
"");
15187 if (preAssociatedScope != NULL)
15190 printf (
"In SageInterface::fixVariableDeclaration(): Note that this variable already has an associated scope! preAssociatedScope = %p = %s (but will be reset below) \n",preAssociatedScope,preAssociatedScope->
class_name().c_str());
15193 requiredScope = preAssociatedScope;
15198 initName->set_scope(requiredScope);
15215 ROSE_ASSERT(requiredScope != NULL);
15216 SgVariableSymbol* varSymbol = requiredScope->lookup_variable_symbol(name);
15218 printf (
" -- varSymbol = %p (%s)\n", varSymbol, varSymbol ? varSymbol->
class_name().c_str() :
"");
15221 if (varSymbol == NULL)
15225 if (scope == initName->get_scope())
15227 if (isSgTemplateVariableDeclaration(varDecl)) {
15232 ROSE_ASSERT(varSymbol);
15244 ROSE_ASSERT(prev_decl);
15248 if (initName != prev_decl)
15249 initName->set_prev_decl_item(prev_decl);
15251 ROSE_ASSERT(initName->get_prev_decl_item() != initName);
15270 Rose_STL_Container<SgNode*> varList;
15273 Rose_STL_Container<SgNode*> reflist = NodeQuery::querySubTree(root, V_SgVarRefExp);
15274 for (Rose_STL_Container<SgNode*>::iterator i=reflist.begin();i!=reflist.end();i++)
15276 varRef= isSgVarRefExp(*i);
15277 ROSE_ASSERT(varRef->get_symbol());
15280 ROSE_ASSERT (initname != NULL);
15283 SgName varName=initname->get_name();
15294 if (varRef == arrowExp->get_rhs_operand_i())
15298 SgType* lhs_type = arrowExp->get_lhs_operand_i()->get_type() ;
15299 lhs_type = lhs_type->
stripType(SgType::STRIP_MODIFIER_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE | SgType::STRIP_TYPEDEF_TYPE);
15301 ROSE_ASSERT(ptrType);
15302 SgClassType* clsType = isSgClassType(ptrType->get_base_type()-> stripType(SgType::STRIP_MODIFIER_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE | SgType::STRIP_TYPEDEF_TYPE));
15303 ROSE_ASSERT(clsType);
15321 if (varRef == dotExp->get_rhs_operand_i())
15326 SgType* lhs_type = dotExp->get_lhs_operand_i()->get_type() ;
15327 lhs_type = lhs_type->
stripType(SgType::STRIP_MODIFIER_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE | SgType::STRIP_TYPEDEF_TYPE);
15329 ROSE_ASSERT(clsType);
15353 if (realSymbol==NULL)
15360 ROSE_ASSERT(realSymbol!=(varRef->get_symbol()));
15367 bool toDelete =
true;
15369 SgSymbol* symbolToDelete = varRef->get_symbol();
15370 varRef->set_symbol(isSgVariableSymbol(realSymbol));
15373 if (varList.empty())
15375 VariantVector vv(V_SgVarRefExp);
15376 varList = NodeQuery::queryMemoryPool(vv);
15379 for (Rose_STL_Container<SgNode*>::iterator i = varList.begin();
15380 i != varList.end(); ++i)
15384 if (var->get_symbol() == symbolToDelete)
15394 delete symbolToDelete;
15403 delete (varRef->get_symbol());
15407 varRef->set_symbol(isSgVariableSymbol(realSymbol));
15414 if (cleanUnusedSymbols)
15421 Rose_STL_Container<SgNode*> symbolList;
15422 VariantVector sym_vv(V_SgVariableSymbol);
15423 symbolList = NodeQuery::queryMemoryPool(sym_vv);
15425 Rose_STL_Container<SgNode*> varList;
15426 VariantVector var_vv(V_SgVarRefExp);
15430 varList = NodeQuery::querySubTree(root, V_SgVarRefExp);
15433 for (Rose_STL_Container<SgNode*>::iterator i = symbolList.begin();
15434 i != symbolList.end(); ++i)
15437 ROSE_ASSERT(symbolToDelete);
15441 bool toDelete =
true;
15445 for (Rose_STL_Container<SgNode*>::iterator j = varList.begin();
15446 j != varList.end(); ++j)
15451 if (var->get_symbol() == symbolToDelete)
15462 std::cout <<
"Symbol " << symbolToDelete->
get_name().str() <<
' ' << symbolToDelete <<
15463 ' ' << symbolToDelete->get_declaration() <<
" is deleted." << std::endl;
15465 delete symbolToDelete->get_declaration();
15466 delete symbolToDelete;
15479 ROSE_ASSERT(label_stmt);
15488 if (isSgFunctionDefinition(scope) !=
nullptr)
15490 ASSERT_not_null(label_scope);
15496 SgLabelSymbol* lsymbol = label_scope->lookup_label_symbol(name);
15498 if (lsymbol ==
nullptr)
15503 ASSERT_not_null(lsymbol);
15515 ROSE_ASSERT (stmt != NULL);
15516 ROSE_ASSERT (label_value >0 && label_value <=99999);
15519 if (label_scope == NULL)
15523 ROSE_ASSERT (label_scope != NULL);
15525 SgLabelSymbol * symbol = label_scope->lookup_label_symbol (label_name);
15526 if (symbol == NULL)
15532 ROSE_ASSERT(symbol != NULL);
15533 symbol->set_fortran_statement(stmt);
15534 symbol->set_numeric_label_value(label_value);
15539 cerr<<
"Error. SageInterface::setFortranNumericLabel() tries to set a duplicated label value!"<<endl;
15540 ROSE_ASSERT (
false);
15549 case SgLabelSymbol::e_start_label_type:
15551 stmt->set_numeric_label(ref_exp);
15554 case SgLabelSymbol::e_end_label_type:
15556 stmt->set_end_numeric_label(ref_exp);
15561 std::cerr <<
"SageInterface::setFortranNumericLabel: unimplemented for label_type " << label_type <<
"\n";
15573 ROSE_ASSERT (func_def != NULL);
15578 std::set<SgNode*>::iterator iter ;
15579 for (iter=symbols.begin(); iter !=symbols.end(); iter++)
15584 int cur_val = l_symbol->get_numeric_label_value();
15585 if (result <=cur_val)
15586 result = cur_val +10;
15590 ROSE_ASSERT (result <= 99999);
15601 ROSE_ASSERT(scope != NULL);
15606 ROSE_ASSERT(fTable != NULL);
15613 printf (
"WARNING: Skip setting the scope of the SgFunctionTypeTable scope = %p = %s \n",scope,scope->
class_name().c_str());
15619 printf (
"In SageInterface::fixStatement(): stmt = %p = %s \n",stmt,stmt->
class_name().c_str());
15632 if (tmfunc != NULL)
15633 assert(tmfunc->
variantT() == V_SgTemplateMemberFunctionDeclaration);
15634 else if (mfunc != NULL)
15635 assert(mfunc->
variantT() == V_SgMemberFunctionDeclaration || mfunc->
variantT() == V_SgTemplateInstantiationMemberFunctionDecl);
15636 else if (tfunc != NULL)
15637 assert(tfunc->
variantT() == V_SgTemplateFunctionDeclaration);
15638 else if (procfunc != NULL)
15639 assert(procfunc->
variantT() == V_SgProcedureHeaderStatement);
15640 else if (progfunc != NULL)
15641 assert(progfunc->
variantT() == V_SgProgramHeaderStatement);
15642 else if (func != NULL)
15643 assert(func->
variantT() == V_SgFunctionDeclaration || func->
variantT() == V_SgTemplateInstantiationFunctionDecl);
15647 printf (
"In SageInterface::fixStatement(): scope = %p = %s \n",scope,scope->
class_name().c_str());
15648 printf (
"In SageInterface::fixStatement(): stmt->get_scope() = %p \n",stmt->
get_scope());
15660 printf (
"Looking up the function symbol using name = %s and type = %p = %s \n",func->get_name().str(),func->get_type(),func->get_type()->
class_name().c_str());
15666 if (tmfunc != NULL)
15668 SgTemplateParameterPtrList & templateParameterList = tmfunc->get_templateParameters();
15671 func_symbol = scope->lookup_template_member_function_symbol (func->get_name(), func->get_type(),&templateParameterList);
15673 else if (mfunc != NULL)
15676 SgTemplateArgumentPtrList* templateArgumentList = (templateInstantiationMemberFunctionDecl != NULL) ? &(templateInstantiationMemberFunctionDecl->
get_templateArguments()) : NULL;
15678 func_symbol = scope->lookup_nontemplate_member_function_symbol (func->get_name(), func->get_type(),templateArgumentList);
15680 else if (tfunc != NULL)
15682 SgTemplateParameterPtrList & templateParameterList = tfunc->get_templateParameters();
15684 printf (
"In SageInterface::fixStatement(): templateParameterList.size() = %" PRIuPTR
" \n",templateParameterList.size());
15688 func_symbol = scope->lookup_template_function_symbol (func->get_name(), func->get_type(),&templateParameterList);
15690 else if (procfunc != NULL)
15693 printf (
"In SageInterface::fixStatement(): procfunc->get_name() = %s calling lookup_function_symbol() \n",procfunc->get_name().str());
15695 func_symbol = scope->lookup_function_symbol (procfunc->get_name(), procfunc->get_type());
15696 assert(func_symbol != NULL);
15698 else if (progfunc != NULL)
15700 func_symbol = scope->lookup_function_symbol (progfunc->get_name(), progfunc->get_type());
15701 assert(func_symbol != NULL);
15703 else if (func != NULL)
15706 printf (
"In SageInterface::fixStatement(): func->get_name() = %s calling lookup_function_symbol() \n",func->get_name().str());
15709 SgTemplateArgumentPtrList* templateArgumentList = (templateInstantiationFunctionDecl != NULL) ? &(templateInstantiationFunctionDecl->
get_templateArguments()) : NULL;
15711 func_symbol = scope->lookup_function_symbol (func->get_name(), func->get_type(),templateArgumentList);
15716 if (func_symbol == NULL)
15728 printf (
"In SageInterface::fixStatement(): func_symbol = %p \n",func_symbol);
15730 assert(func_symbol != NULL);
15741 printf (
"Need to handle SgTemplateDeclaration IR nodes as well...(implement later) \n");
15749 if (isSgVariableDeclaration(stmt))
15756 ROSE_ASSERT(classDeclaration !=
nullptr);
15759 else if (isSgClassDeclaration(stmt))
15763 else if (isSgLabelStatement(stmt))
15767 else if (isSgFunctionDeclaration(stmt))
15775 ROSE_ASSERT(fTable);
15784 printf (
"In SageInterface::fixStatement(): scope = %p = %s \n",scope,scope->
class_name().c_str());
15785 printf (
"In SageInterface::fixStatement(): stmt->get_scope() = %p \n",stmt->
get_scope());
15796 printf (
"Looking up the function symbol using name = %s and type = %p = %s \n",func->get_name().str(),func->get_type(),func->get_type()->
class_name().c_str());
15798 SgFunctionSymbol* func_symbol = scope->lookup_function_symbol (func->get_name(), func->get_type());
15800 printf (
"In SageInterface::fixStatement(): func_symbol = %p \n",func_symbol);
15801 if (func_symbol == NULL)
15813 ROSE_ASSERT (func_symbol != NULL);
15819 printf (
"In SageInterface::fixStatement(): found a valid function so no need to insert new symbol \n");
15827 if (local_symbol == NULL)
15832 if (func != src_func )
15842 else if (isSgTemplateDeclaration(stmt) != NULL)
15857 case V_SgEnumDeclaration:
15858 case V_SgTemplateDeclaration:
15859 case V_SgTypedefDeclaration:
15860 case V_SgFunctionDeclaration:
15861 case V_SgMemberFunctionDeclaration:
15862 case V_SgTemplateInstantiationFunctionDecl:
15877 printf (
"In SageInterface::fixStatement(): switch default case used (likely OK): stmt = %p = %s \n",stmt,stmt->
class_name().c_str());
15880 printf (
"switch case not handled properly: stmt = %p = %s \n",stmt,stmt->
class_name().c_str());
15912 ROSE_ASSERT(func != NULL && scope != NULL);
15914 ROSE_ASSERT(func != NULL);
15915 ROSE_ASSERT(scope != NULL);
15917 SgStatementPtrList stmtList, sameFuncList;
15924 SgDeclarationStatementPtrList::iterator i;
15925 for (i=declList.begin();i!=declList.end();i++)
15926 stmtList.push_back(*i);
15934 if (firstNondefiningFunctionDeclaration != NULL)
15939 printf (
"In SageInterface::updateDefiningNondefiningLinks(): func = %p Found a valid pointer to a firstNondefiningFunctionDeclaration = %p \n",func,firstNondefiningFunctionDeclaration);
15950 printf (
"WARNING: symbol for func->get_firstNondefiningDeclaration() = %p = %s = %s is not present in the scope = %p = %s associated with the firstNondefiningDeclaration \n",
15958 SgSymbol* functionSymbol = scope->lookup_function_symbol(func->get_name(),func->get_type());
15959 if (functionSymbol != NULL)
15961 printf (
"In SageInterface::updateDefiningNondefiningLinks(): func = %p Found a valid symbol = %p \n",func,functionSymbol);
15965 printf (
"In SageInterface::updateDefiningNondefiningLinks(): func = %p functionSymbol == NULL \n",func);
15970 SgStatementPtrList::iterator j;
15971 for (j = stmtList.begin(); j != stmtList.end(); j++)
15974 if (func_decl != NULL)
15981 sameFuncList.push_back(func_decl);
15987 printf (
"func = %p \n",func);
15991 ROSE_ASSERT(func != NULL);
15995 for (j = sameFuncList.begin(); j != sameFuncList.end(); j++)
16000 ROSE_ASSERT(func != NULL);
16003 ROSE_ASSERT(sameFuncList.empty() ==
false);
16005 if (func == isSgFunctionDeclaration(*(sameFuncList.begin())))
16007 for (j = sameFuncList.begin(); j != sameFuncList.end(); j++)
16011 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 1) Testing j = %p set_firstNondefiningDeclaration(%p) \n",*j,func);
16015 if (func_decl != func)
16022 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 1) Calling j = %p set_firstNondefiningDeclaration(%p) \n",*j,func);
16032 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 2) Testing func = %p set_firstNondefiningDeclaration(%p) \n",func,isSgFunctionDeclaration(*(sameFuncList.begin()))->
get_firstNondefiningDeclaration());
16039 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 2) Calling func = %p set_firstNondefiningDeclaration(%p) \n",func,isSgFunctionDeclaration(*(sameFuncList.begin()))->
get_firstNondefiningDeclaration());
16048 assert(source_file != NULL);
16049 assert(position == PreprocessingInfo::before || position == PreprocessingInfo::after);
16051 SgGlobal * global_scope = source_file->get_globalScope();
16054 ROSE_ASSERT(result);
16070 PreprocessingInfo::DirectiveType dtype )
16072 ASSERT_not_null(target);
16075 PreprocessingInfo::DirectiveType mytype=dtype;
16080 if (mytype == PreprocessingInfo::CpreprocessorUnknownDeclaration)
16086 mytype = PreprocessingInfo::C_StyleComment;
16091 mytype = PreprocessingInfo::CplusplusStyleComment;
16096 mytype = PreprocessingInfo::F90StyleComment;
16101 mytype = PreprocessingInfo::AdaStyleComment;
16106 mytype = PreprocessingInfo::JovialStyleComment;
16110 cout <<
"WARNING: SageInterface::attachComment(): Unknown programming language \n";
16116 bool resetPositionInfo =
false;
16119 case PreprocessingInfo::C_StyleComment: comment =
"/* " + content +
" */";
break;
16120 case PreprocessingInfo::CplusplusStyleComment: comment =
"// " + content;
break;
16121 case PreprocessingInfo::FortranStyleComment: comment =
" C " + content;
break;
16122 case PreprocessingInfo::F90StyleComment: comment =
"!" + content;
break;
16123 case PreprocessingInfo::AdaStyleComment: comment =
"-- " + content;
break;
16124 case PreprocessingInfo::JovialStyleComment:
16128 case PreprocessingInfo::CpreprocessorLineDeclaration:
16129 comment =
"#myline " + content;
16130 mytype = PreprocessingInfo::CplusplusStyleComment;
16131 resetPositionInfo =
true;
16133 case PreprocessingInfo::CpreprocessorIfndefDeclaration: comment =
"#ifndef " + content +
"\n";
break;
16134 case PreprocessingInfo::CpreprocessorDefineDeclaration: comment =
"#define " + content +
"\n";
break;
16135 case PreprocessingInfo::CpreprocessorEndifDeclaration: comment =
"#endif" + (content.empty() ?
"\n" : (
" /* " + content +
" */\n"));
break;
16136 case PreprocessingInfo::CpreprocessorEnd_ifDeclaration: comment =
"#end if" + (content.empty() ?
"\n" : (
" /* " + content +
" */\n"));
break;
16140 printf (
"Error: default in switch reached in SageInterface::attachComment() PreprocessingInfo::DirectiveType == %d \n",mytype);
16145 result =
new PreprocessingInfo (mytype,comment,
"transformation-generated", 0, 0, 0, position);
16148 if (resetPositionInfo ==
true)
16151 *(result->get_file_info()) = *(target->get_file_info());
16161 ASSERT_not_null(result);
16162 target->addToAttachedPreprocessingInfo(result);
16168 PreprocessingInfo::CpreprocessorIfDeclaration,
16170 "transformation-generated", 0, 0, 0,
16171 PreprocessingInfo::before
16173 target->addToAttachedPreprocessingInfo(if_macro);
16176 PreprocessingInfo::CpreprocessorEndifDeclaration,
16178 "transformation-generated", 0, 0, 0,
16179 PreprocessingInfo::after
16181 target->addToAttachedPreprocessingInfo(endif_macro);
16194static map<SgSourceFile*, map<string, PreprocessingInfo*> > fileHeaderDict;
16199 if (isSystemHeader)
16200 header_key=
"<"+header_file_name+
">";
16202 header_key=
"\""+header_file_name+
"\"";
16204 if (fileHeaderDict.count(source_file) && fileHeaderDict[source_file].count(header_key))
16205 return fileHeaderDict[source_file][header_key];
16207 vector<SgLocatedNode*> candidates;
16210 SgGlobal* global= source_file -> get_globalScope();
16212 candidates.push_back(global);
16215 SgDeclarationStatementPtrList decl_stmt_list = global->
get_declarations();
16216 for (SgDeclarationStatementPtrList::iterator iter= decl_stmt_list.begin(); iter!=decl_stmt_list.end(); iter++)
16217 candidates.push_back(*iter);
16219 bool found =
false;
16220 for (
size_t ci=0; ci<candidates.size(); ci++)
16225 if (comments == NULL)
continue;
16226 AttachedPreprocessingInfoType::iterator i;
16227 for (i = comments->begin (); i != comments->end (); i++)
16229 if ((*i)->getTypeOfDirective () != PreprocessingInfo::CpreprocessorIncludeDeclaration)
continue;
16230 string content = (*i)->getString ();
16231 if (content.find(header_key) != string::npos)
16233 fileHeaderDict[source_file][header_key] = *i;
16244 return fileHeaderDict[source_file][header_key];
16254 bool supportTokenUnparsing =
false;
16256 assert(source_file != NULL);
16257 assert(position == PreprocessingInfo::before || position == PreprocessingInfo::after);
16259 SgGlobal * global_scope = source_file->get_globalScope();
16262 if (isSystemHeader)
16263 content =
"#include <" + header_file_name +
"> \n";
16265 content =
"#include \"" + header_file_name +
"\" \n";
16268 ROSE_ASSERT(result);
16276 supportTokenUnparsing = source_file->get_unparse_tokens();
16277 bool supportUnparseHeaders = source_file->get_unparseHeaderFiles();
16280 printf (
"supportTokenUnparsing = %s \n",supportTokenUnparsing ?
"true" :
"false");
16281 printf (
"supportUnparseHeaders = %s \n",supportUnparseHeaders ?
"true" :
"false");
16282 printf (
"source_file = %p \n",source_file);
16283 printf (
"global_scope = %p \n",global_scope);
16286 printf (
"Exiting as a test! \n");
16291 if (supportTokenUnparsing ==
false)
16300 if (supportUnparseHeaders ==
true)
16305 printf (
"physical_file_id = %d \n",physical_file_id);
16310 printf (
"Exiting as a test! \n");
16317 global_scope->prepend_statement(emptyDeclaration);
16321 printf (
"Exiting as a test! \n");
16322 ROSE_ASSERT(
false);
16333 bool supportTokenUnparsing =
false;
16339 printf (
"In SageInterface::insertHeader(): filename = %s \n",filename.c_str());
16340 printf (
" --- position = %s \n",PreprocessingInfo::relativePositionName(position).c_str());
16346 ROSE_ASSERT(scope);
16349 ROSE_ASSERT(globalScope != NULL);
16357 if (isSystemHeader)
16358 content =
"#include <" + filename +
"> \n";
16360 content =
"#include \"" + filename +
"\" \n";
16369 ROSE_ASSERT(sourceFile != NULL);
16371 supportTokenUnparsing = sourceFile->get_unparse_tokens();
16373 bool supportUnparseHeaders = sourceFile->get_unparseHeaderFiles();
16375 if (supportUnparseHeaders)
16378 string suffix = Rose::StringUtility ::fileNameSuffix(filename);
16381 if (suffix==
"h" ||suffix==
"hpp"|| suffix==
"hh"||suffix==
"H" ||suffix==
"hxx"||suffix==
"h++" ||suffix==
"tcc")
16386 printf (
"supportTokenUnparsing = %s \n",supportTokenUnparsing ?
"true" :
"false");
16387 printf (
"supportUnparseHeaders = %s \n",supportUnparseHeaders ?
"true" :
"false");
16388 printf (
"sourceFile = %p \n",sourceFile);
16389 printf (
"globalScope = %p \n",globalScope);
16392 printf (
"supportTokenUnparsing = %s \n",supportTokenUnparsing ?
"true" :
"false");
16395 printf (
"Exiting as a test! \n");
16399 SgDeclarationStatementPtrList & stmtList = globalScope->
get_declarations();
16402 printf (
"stmtList.size() = %zu \n",stmtList.size());
16405 if (stmtList.size() > 0)
16407 for (SgDeclarationStatementPtrList::iterator j = stmtList.begin (); j != stmtList.end (); j++)
16411 if ( ((*j)->get_file_info())->isSameFile(srcScope->
get_file_info ()) || ((*j)->get_file_info ())->isTransformation() )
16413 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration, content,
"Transformation generated",0, 0, 0, PreprocessingInfo::before);
16414 ROSE_ASSERT(result != NULL);
16416 printf (
"Building a PreprocessingInfo: result = %p \n",result);
16424 if (supportTokenUnparsing ==
false)
16426 (*j)->addToAttachedPreprocessingInfo(result,position);
16430 (*j)->addToAttachedPreprocessingInfo(result,position);
16432 printf (
"In SageInterface::insertHeader(): Calling set_containsTransformationToSurroundingWhitespace(true) \n");
16436 (*j)->set_containsTransformationToSurroundingWhitespace(
true);
16445 printf (
"In SageInterface::insertHeader(): declarationStatement = %p = %s \n",declarationStatement,declarationStatement->
class_name().c_str());
16446 printf (
"In SageInterface::insertHeader(): declarationStatement->get_containsTransformationToSurroundingWhitespace() = %s \n",
16447 declarationStatement->get_containsTransformationToSurroundingWhitespace() ?
"true" :
"false");
16454 if (supportUnparseHeaders ==
true)
16459 printf (
"physical_file_id = %d \n",physical_file_id);
16461 emptyDeclaration->get_startOfConstruct()->set_physical_file_id(physical_file_id);
16462 emptyDeclaration->get_endOfConstruct()->set_physical_file_id(physical_file_id);
16464 printf (
"Exiting as a test! \n");
16465 ROSE_ASSERT(
false);
16469 emptyDeclaration->addToAttachedPreprocessingInfo(result, position);
16475 printf (
"break out of for loop: result = %p \n",result);
16485 cerr<<
"SageInterface::insertHeader() Empty file is found!"<<endl;
16486 cerr<<
"#include xxx is preprocessing information which has to be attached to some other located node (a statement for example)"<<endl;
16487 cerr<<
"You may have to insert some statement first before inserting a header"<<endl;
16488 ROSE_ASSERT(
false);
16489 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration, content,
"Transformation generated",0, 0, 0, PreprocessingInfo::after);
16490 ROSE_ASSERT(result);
16501 if (result != NULL)
16512 printf (
"Exiting as a test! \n");
16513 ROSE_ASSERT(
false);
16517 printf (
"Leaving SageInterface::insertHeader(): filename = %s \n",filename.c_str());
16521 printf (
"Exiting as a test! \n");
16522 ROSE_ASSERT(
false);
16532 ROSE_ASSERT (stmt != NULL);
16533 ROSE_ASSERT (newheader != NULL);
16536 printf (
"In SageInterface::insertHeader (SgStatement* stmt, PreprocessingInfo* newheader, bool asLastHeader) \n");
16542 position = PreprocessingInfo::after;
16544 position = PreprocessingInfo::before;
16550 if (comments != NULL)
16559 AttachedPreprocessingInfoType::iterator i, firsti, lasti;
16560 for (i = comments->begin (); i != comments->end (); i++)
16567 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration)
16570 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration)
16572 if (firstExistingHeader == NULL)
16574 firstExistingHeader = (*i);
16578 lastExistingHeader = (*i);
16584 if ( (*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration ||
16585 (*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorEndifDeclaration )
16588 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration)
16590 if (firstExistingHeader == NULL)
16592 firstExistingHeader = (*i);
16596 lastExistingHeader = (*i);
16599 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorEndifDeclaration)
16601 if (firstExistingEndif == NULL)
16603 firstExistingEndif = (*i);
16618 if (lastExistingHeader == NULL)
16622 comments->insert (lasti+1, newheader);
16627 if (firstExistingHeader == NULL)
16631 comments->insert (firsti, newheader);
16639 printf (
"Exiting as a test! \n");
16640 ROSE_ASSERT(
false);
16649 ROSE_ASSERT (source_file != NULL);
16650 SgGlobal* globalScope = source_file->get_globalScope();
16651 ROSE_ASSERT (globalScope != NULL);
16655 if (isSystemHeader)
16656 content =
"#include <" + filename +
"> \n";
16658 content =
"#include \"" + filename +
"\" \n";
16665 position = PreprocessingInfo::after;
16667 position = PreprocessingInfo::before;
16670 SgDeclarationStatementPtrList & stmtList = globalScope->
get_declarations ();
16671 if (stmtList.size()>0)
16673 for (SgDeclarationStatementPtrList::iterator j = stmtList.begin (); j != stmtList.end (); j++)
16678 if ( (*j)->get_file_info()->isSameFile(globalScope->
get_file_info()) || (*j)->get_file_info()->isTransformation() )
16681 printf (
"In SageInterface::insertHeader(): Found statement to attached #include: *j = %p = %s \n",*j,(*j)->class_name().c_str());
16682 printf (
" --- unparseToString() = %s \n",(*j)->unparseToString().c_str());
16684 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration, content,
"Transformation generated",0, 0, 0, PreprocessingInfo::before);
16685 ROSE_ASSERT(result);
16689 printf (
"Exiting as a test! \n");
16698 cerr<<
"SageInterface::insertHeader() Empty file is found!"<<endl;
16699 cerr<<
"#include xxx is preprocessing information which has to be attached to some other located node (a statement for example)"<<endl;
16700 cerr<<
"You may have to insert some statement first before inserting a header"<<endl;
16703 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,
16704 content,
"Transformation generated",0, 0, 0, PreprocessingInfo::after);
16705 ROSE_ASSERT(result);
16712 printf (
"In SageInterface::insertHeader(): Marking include file for filename = %s as a transformation \n",filename.c_str());
16722 printf (
"Exiting as a test! \n");
16723 ROSE_ASSERT(
false);
16741 ROSE_ASSERT(target != NULL);
16748 PreprocessingInfo::DirectiveType mytype = PreprocessingInfo::CpreprocessorIfDeclaration;
16751 printf (
"Warning: attachArbitraryText(): attaching arbitrary text to the AST as a #if declaration: text = %s \n",text.c_str());
16753 result =
new PreprocessingInfo (mytype,text,
"transformation-generated", 0, 0, 0, position);
16754 ROSE_ASSERT(result);
16761 target->addToAttachedPreprocessingInfo(result);
16775 ROSE_ASSERT(target != NULL);
16776 AttachedPreprocessingInfoType *info= target->getAttachedPreprocessingInfo ();
16777 if (info == NULL)
return;
16778 AttachedPreprocessingInfoType::iterator j;
16779 for (j = info->begin (); j != info->end (); j++)
16781 if ((*j)->getTypeOfDirective()==PreprocessingInfo::CMacroCall)
16783#ifndef ROSE_SKIP_COMPILATION_OF_WAVE
16785 std::ostringstream os;
16786 token_container tc = (*j)->get_macro_call()->expanded_macro;
16787 token_container::const_iterator iter;
16788 for (iter=tc.begin(); iter!=tc.end(); iter++)
16789 os<<(*iter).get_value();
16792 string pragmaText = target->get_pragma()->get_pragma();
16793 string targetString = (*j)->getString();
16794 string replacement = os.str();
16796 size_t pos1 = pragmaText.find(targetString);
16797 while (pos1 != string::npos)
16799 pragmaText.replace(pos1, targetString.size(), replacement);
16800 pos1 = pragmaText.find(targetString);
16802 delete target->get_pragma();
16816 if (isSgWhileStmt(loopOrSwitch) || isSgDoWhileStmt(loopOrSwitch) ||
16817 isSgForStatement(loopOrSwitch)) {
16819 }
else if (isSgSwitchStatement(loopOrSwitch)) {
16820 body = isSgSwitchStatement(loopOrSwitch)->
get_body();
16822 ROSE_ASSERT (body);
16824 if (!breaks.empty()) {
16825 static int breakLabelCounter = 0;
16830 isSgScopeStatement(loopOrSwitch->
get_parent()));
16832 for (
size_t j = 0; j < breaks.size(); ++j) {
16837 newGoto->
set_parent(breaks[j]->get_parent());
16844 ROSE_ASSERT(node!=NULL);
16854 ROSE_ASSERT(node!=NULL);
16867 ROSE_ASSERT(stmt_src != NULL);
16868 ROSE_ASSERT(stmt_dst != NULL);
16871 if (infoList == NULL)
16874 printf (
"In SageInterface::movePreprocessingInfo(): infoList == NULL: exiting movePreprocessingInfo() \n");
16879 AttachedPreprocessingInfoType* infoToRemoveList =
new AttachedPreprocessingInfoType();
16882 printf (
"In SageInterface::movePreprocessingInfo(): \n");
16883 printf (
" --- stmt_src = %p = %s src_position = %d \n",stmt_src,stmt_src->
class_name().c_str(),src_position);
16885 if (src_declarationStatement != NULL)
16888 printf (
"src_declarationStatement->get_definingDeclaration() = %p \n",src_declarationStatement->
get_definingDeclaration());
16890 printf (
" --- stmt_dst = %p = %s dst_position = %d \n",stmt_dst,stmt_dst->
class_name().c_str(),dst_position);
16892 if (dst_declarationStatement != NULL)
16895 printf (
"dst_declarationStatement->get_definingDeclaration() = %p \n",dst_declarationStatement->
get_definingDeclaration());
16897 printf (
" --- src_position = %s \n",PreprocessingInfo::relativePositionName(src_position).c_str());
16898 printf (
" --- dst_position = %s \n",PreprocessingInfo::relativePositionName(dst_position).c_str());
16899 printf (
" --- usePrepend = %s \n",usePrepend ?
"true" :
"false");
16901 printf (
" --- infoList = %p \n",infoList);
16902 printf (
" --- infoToRemoveList = %p \n",infoToRemoveList);
16905 printf (
" --- dst_infoList = %p \n",dst_infoList);
16908 printf (
"****************************************************************** \n");
16909 printf (
"In SageInterface::movePreprocessingInfo(): Attached comments and CPP directives: stmt_src \n");
16911 printf (
"In SageInterface::movePreprocessingInfo(): Attached comments and CPP directives: stmt_dst \n");
16913 printf (
"****************************************************************** \n");
16923 printf (
" --- infoList->size() = %zu \n",infoList->size());
16924 printf (
" --- infoToRemoveList->size() = %zu \n",infoToRemoveList->size());
16930 for (Rose_STL_Container<PreprocessingInfo*>::iterator i = (*infoList).begin(); i != (*infoList).end(); i++)
16933 ROSE_ASSERT(*i != NULL);
16938 ROSE_ASSERT(info != NULL);
16941 printf (
"counter = %d Processing PreprocessingInfo = %s \n",counter,info->getString().c_str());
16950 for (Rose_STL_Container<PreprocessingInfo*>::iterator i = (*infoList).begin(); i != (*infoList).end(); i++)
16952 ROSE_ASSERT(*i != NULL);
16955 ROSE_ASSERT(info != NULL);
16958 (info->getTypeOfDirective()==PreprocessingInfo::C_StyleComment)||
16959 (info->getTypeOfDirective()==PreprocessingInfo::CplusplusStyleComment)||
16960 (info->getTypeOfDirective()==PreprocessingInfo::FortranStyleComment)||
16961 (info->getTypeOfDirective()==PreprocessingInfo::F90StyleComment)||
16962 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIncludeDeclaration )||
16963 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIncludeNextDeclaration )||
16964 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorDefineDeclaration )||
16965 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorUndefDeclaration)||
16966 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIfdefDeclaration )||
16967 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIfndefDeclaration )||
16968 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIfDeclaration )||
16969 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorDeadIfDeclaration )||
16970 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorElseDeclaration )||
16971 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorElifDeclaration )||
16972 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorEndifDeclaration ) ||
16973 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorEnd_ifDeclaration ) ||
16974 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorLineDeclaration) ||
16975 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorErrorDeclaration) ||
16976 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorWarningDeclaration) ||
16978 (info->getTypeOfDirective()==PreprocessingInfo::ClinkageSpecificationStart) ||
16979 (info->getTypeOfDirective()==PreprocessingInfo::ClinkageSpecificationEnd)
16984 if ( src_position == PreprocessingInfo::undef || info->getRelativePosition() == src_position)
16986 if (usePrepend ==
true)
16989 if (prevItem == NULL)
17007 info->setAsTransformation();
17015 stmt_dst->set_containsTransformationToSurroundingWhitespace(
true);
17016 if (isMarkedAsModified ==
false)
17023 (*infoToRemoveList).push_back(*i);
17027 if (dst_position != PreprocessingInfo::undef)
17029 info->setRelativePosition(dst_position);
17035 AttachedPreprocessingInfoType::iterator j;
17036 for (j = (*infoToRemoveList).begin(); j != (*infoToRemoveList).end(); j++)
17038 infoList->erase( find(infoList->begin(),infoList->end(),*j) );
17074 return info && (info->getRelativePosition () != pos);
17084 return info && !isNotRelPos (info, pos);
17091 ASSERT_not_null(src_node);
17094 AttachedPreprocessingInfoType* info = src_node->get_attachedPreprocessingInfoPtr();
17098 remove_copy_if(info->begin(),
17100 back_inserter(save_buf),
17101 [pos](
auto x) {
return !isRelPos(x, pos); }
17105 AttachedPreprocessingInfoType::iterator
17106 new_end = remove_if(info->begin(),
17108 [pos](
auto x) { return isRelPos(x, pos); }
17110 info->erase(new_end, info->end());
17114static AttachedPreprocessingInfoType *
17118 AttachedPreprocessingInfoType* info_list = s->get_attachedPreprocessingInfoPtr ();
17121 info_list =
new AttachedPreprocessingInfoType;
17122 ROSE_ASSERT (info_list);
17123 s->set_attachedPreprocessingInfoPtr (info_list);
17127 ROSE_ASSERT (info_list);
17134 if (save_buf.size()==0)
return;
17136 AttachedPreprocessingInfoType* info = createInfoList (dst_node);
17137 ROSE_ASSERT (info);
17144 if (pos==PreprocessingInfo::before)
17146 for(AttachedPreprocessingInfoType::reverse_iterator i=save_buf.rbegin();i!=save_buf.rend();i++)
17147 info->insert(info->begin(),*i);
17150 else if (pos==PreprocessingInfo::after)
17151 copy (save_buf.begin (), save_buf.end (), back_inserter (*info));
17152 else if (pos==PreprocessingInfo::inside)
17154 copy (save_buf.begin (), save_buf.end (), back_inserter (*info));
17155 cerr<<
"SageInterface::pastePreprocessingInfo() pos==PreprocessingInfo::inside is not supported."<<endl;
17156 save_buf[0]->display(
"ttt");
17162 ROSE_ASSERT(locatedNode != NULL);
17163 AttachedPreprocessingInfoType *comments =
17166 if (comments != NULL)
17168 printf (
"-----------------------------------------------\n");
17169 printf (
"Found an IR node (at %p of type: %s) in file %s \n",
17170 locatedNode, locatedNode->
class_name ().c_str (),
17171 (locatedNode->
get_file_info ()->get_filenameString ()).c_str ());
17173 AttachedPreprocessingInfoType::iterator i;
17174 for (i = comments->begin (); i != comments->end (); i++)
17177 (
"with attached preprocessingInfo numbering #%d :------------- \nclassification= %s:\nString format:%s\n",
17179 PreprocessingInfo::directiveTypeName ((*i)->getTypeOfDirective ()).
17180 c_str (), (*i)->getString ().c_str ());
17181 if ((*i)->getRelativePosition () == PreprocessingInfo::inside)
17182 printf (
"relative position is: inside\n");
17184 printf (
"relative position is: %s\n", \
17185 ((*i)->getRelativePosition () == PreprocessingInfo::before) ?
"before" :
"after");
17190 printf (
"No attached preprocessing info. (at %p of type: %s): \n", locatedNode,
17206template <
class ParentNode>
17216 if (basicblock == NULL) {
17218 (stmt.*setter)(basicblock);
17222 ROSE_ASSERT (basicblock != NULL);
17229 if (!isSgBasicBlock(b)) {
17237 ROSE_ASSERT (isSgBasicBlock(b));
17238 return isSgBasicBlock(b);
17244 if (!isSgBasicBlock(b)) {
17252 ROSE_ASSERT (isSgBasicBlock(b));
17253 return isSgBasicBlock(b);
17259 if (!isSgBasicBlock(b)) {
17267 ROSE_ASSERT (isSgBasicBlock(b));
17268 return isSgBasicBlock(b);
17273 ROSE_ASSERT (fs != NULL);
17275 return ensureBasicBlock_aux(*fs, &SgUpcForAllStatement::get_loop_body, &SgUpcForAllStatement::set_loop_body);
17280 if (!isSgBasicBlock(b)) {
17288 ROSE_ASSERT (isSgBasicBlock(b));
17289 return isSgBasicBlock(b);
17294 if (!isSgBasicBlock(b)) {
17302 ROSE_ASSERT (isSgBasicBlock(b));
17303 return isSgBasicBlock(b);
17308 if (!isSgBasicBlock(b)) {
17316 ROSE_ASSERT (isSgBasicBlock(b));
17317 return isSgBasicBlock(b);
17322 if (!isSgBasicBlock(b)) {
17330 printf (
"In SageInterface::ensureBasicBlockAsTrueBodyOfIf(): Added SgBasicBlock b = %p to addedBasicBlockNodes.size() = %zu \n",b,addedBasicBlockNodes.size());
17333 ROSE_ASSERT (isSgBasicBlock(b));
17334 return isSgBasicBlock(b);
17344 ROSE_ASSERT(bb != NULL);
17345 addedBasicBlockNodes.push_back(bb);
17347 printf (
"In SageInterface::recordNormalizations(): Added SgBasicBlock = %p to addedBasicBlockNodes.size() = %zu \n",bb,addedBasicBlockNodes.size());
17358 printf (
"In SageInterface::cleanupNontransformedBasicBlockNode(): addedBasicBlockNodes.size() = %zu \n",addedBasicBlockNodes.size());
17361 for (vector<SgBasicBlock*>::iterator i = addedBasicBlockNodes.begin(); i != addedBasicBlockNodes.end(); i++)
17364 ROSE_ASSERT(b != NULL);
17368 printf (
"This SgBasicBlock can be denormalized: b = %p \n",b);
17371 ROSE_ASSERT(parentOfBlock != NULL);
17376 ROSE_ASSERT(s != NULL);
17378 switch (parentOfBlock->
variantT())
17382 SgIfStmt* ifStatement = isSgIfStmt(parentOfBlock);
17386 printf (
"Calling set_true_body on ifStatement = %p = %s \n",ifStatement,ifStatement->
class_name().c_str());
17391 printf (
"Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17396 printf (
"DONE: Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17405 printf (
"Calling set_false_body on ifStatement = %p = %s \n",ifStatement,ifStatement->
class_name().c_str());
17410 printf (
"Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17415 printf (
"DONE: Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17419 printf (
"Mark as NOT modified after calling set_false_body on ifStatement = %p = %n \n",ifStatement,ifStatement->
class_name().c_str());
17422 printf (
"Error: case not handled in case V_SgIfStmt: parentOfBlock = %p = %s \n",parentOfBlock,parentOfBlock->
class_name().c_str());
17430 case V_SgWhileStmt:
17432 SgWhileStmt* whileStatement = isSgWhileStmt(parentOfBlock);
17433 if (b == whileStatement->
get_body())
17442 case V_SgSwitchStatement:
17445 if (b == switchStatement->
get_body())
17454 case V_SgForStatement:
17466 case V_SgCaseOptionStmt:
17468 SgCaseOptionStmt* caseOptionStatement = isSgCaseOptionStmt(parentOfBlock);
17469 if (b == caseOptionStatement->
get_body())
17478 case V_SgDefaultOptionStmt:
17481 if (b == defaultOptionStatement->
get_body())
17483 defaultOptionStatement->
set_body(s);
17490 case V_SgDoWhileStmt:
17492 SgDoWhileStmt* doWhileStatement = isSgDoWhileStmt(parentOfBlock);
17493 if (b == doWhileStatement->
get_body())
17503 printf (
"Error: case not handled in switch: parentOfBlock = %p = %s \n",parentOfBlock,parentOfBlock->
class_name().c_str());
17509 if (wasPreviouslyModified ==
false)
17514 printf (
"In SageInterface::cleanupNontransformedBasicBlockNode(): parentOfBlock reset to FALSE after IR node member function call (e.g. set_body()): parentOfBlock = %p = %s \n",parentOfBlock,parentOfBlock->
class_name().c_str());
17521 printf (
"Exiting as a test! \n");
17528 printf (
"Leaving SageInterface::cleanupNontransformedBasicBlockNode(): addedBasicBlockNodes.size() = %zu \n",addedBasicBlockNodes.size());
17536 if (!createEmptyBody && (b == NULL || isSgNullStatement(b)))
17538 if (!isSgBasicBlock(b)) {
17546 ROSE_ASSERT (isSgBasicBlock(b));
17547 return isSgBasicBlock(b);
17552 if (!isSgBasicBlock(b)) {
17557 ROSE_ASSERT (isSgBasicBlock(b));
17558 return isSgBasicBlock(b);
17564 if (!isSgBasicBlock(b)) {
17569 ROSE_ASSERT (isSgBasicBlock(b));
17570 return isSgBasicBlock(b);
17582 case V_SgForStatement:
17584 if (isSgForStatement(p)->get_loop_body() == s)
17588 case V_SgUpcForAllStatement:
17591 if (upcforall.get_loop_body() == s)
17595 case V_SgWhileStmt:
17597 if (isSgWhileStmt(p)->get_body() == s)
17601 case V_SgDoWhileStmt:
17603 if (isSgDoWhileStmt(p)->get_body() == s)
17607 case V_SgSwitchStatement:
17609 if (isSgSwitchStatement(p)->get_body() == s)
17613 case V_SgCaseOptionStmt:
17615 if (isSgCaseOptionStmt(p)->get_body() == s)
17619 case V_SgDefaultOptionStmt:
17621 if (isSgDefaultOptionStmt(p)->get_body() == s)
17625 case V_SgCatchOptionStmt:
17627 if (isSgCatchOptionStmt(p)->get_body() == s)
17633 if (isSgIfStmt(p)->get_true_body() == s)
17635 else if (isSgIfStmt(p)->get_false_body() == s)
17641 if (isSgOmpBodyStatement(p))
17653 ROSE_ASSERT (singleStmt != NULL);
17654 ROSE_ASSERT (isSgBasicBlock(singleStmt) == NULL);
17666 case V_SgForStatement:
17668 if (isSgForStatement(p)->get_loop_body() == s)
17672 case V_SgUpcForAllStatement:
17676 if (upcforall.get_loop_body() == s)
17680 case V_SgWhileStmt:
17682 if (isSgWhileStmt(p)->get_body() == s)
17686 case V_SgDoWhileStmt:
17688 if (isSgDoWhileStmt(p)->get_body() == s)
17692 case V_SgSwitchStatement:
17694 if (isSgSwitchStatement(p)->get_body() == s)
17698 case V_SgCaseOptionStmt:
17700 if (isSgCaseOptionStmt(p)->get_body() == s)
17704 case V_SgDefaultOptionStmt:
17706 if (isSgDefaultOptionStmt(p)->get_body() == s)
17710 case V_SgCatchOptionStmt:
17712 if (isSgCatchOptionStmt(p)->get_body() == s)
17718 if (isSgIfStmt(p)->get_true_body() == s)
17720 else if (isSgIfStmt(p)->get_false_body() == s)
17726 if (isSgOmpBodyStatement(p))
17733 ROSE_ASSERT (rt != NULL);
17747 case V_SgBasicBlock:
return isSgBasicBlock(p);
17748 case V_SgForStatement:
17750 if (isSgForStatement(p)->get_loop_body() == s)
17752 else if (isSgForStatement(p)->get_test() == s)
17755 else if (isSgForStatement(p)->get_for_init_stmt() == s)
17761 case V_SgUpcForAllStatement:
17765 if (upcforall.get_loop_body() == s)
17768 ROSE_ASSERT( (s == upcforall.get_for_init_stmt())
17769 || (s == upcforall.get_test())
17773 case V_SgWhileStmt:
17775 if (isSgWhileStmt(p)->get_body() == s)
17777 else if (isSgWhileStmt(p)->get_condition() == s)
17783 case V_SgDoWhileStmt:
17785 if (isSgDoWhileStmt(p)->get_body() == s)
17787 else if (isSgDoWhileStmt(p)->get_condition() == s)
17793 case V_SgSwitchStatement:
17795 if (isSgSwitchStatement(p)->get_body() == s)
17797 else if (isSgSwitchStatement(p)->get_item_selector() == s)
17803 case V_SgCatchOptionStmt:
17805 if (isSgCatchOptionStmt(p)->get_body() == s)
17807 else if (isSgCatchOptionStmt(p)->get_condition() == s)
17815 if (isSgIfStmt(p)->get_true_body() == s)
17817 else if (isSgIfStmt(p)->get_false_body() == s)
17819 else if (isSgIfStmt(p)->get_conditional() == s)
17827 if (isSgOmpBodyStatement(p))
17842 void SageInterface::changeAllLoopBodiesToBlocks(
SgNode* top) {
17843 cerr<<
"Warning: SageInterface::changeAllLoopBodiesToBlocks() is being replaced by SageInterface::changeAllBodiesToBlocks()."<<endl;
17844 cerr<<
"Please use SageInterface::changeAllBodiesToBlocks() if you can."<<endl;
17852 bool allowEmptyBody;
17853 Visitor (
bool flag):allowEmptyBody(flag) {}
17854 virtual void visit(
SgNode* n) {
17859 case V_SgForStatement: {
17863 case V_SgWhileStmt: {
17867 case V_SgDoWhileStmt: {
17871 case V_SgSwitchStatement: {
17880 printf (
"In changeAllBodiesToBlocks(): case SgIfStmt: n->get_isModified() = %s \n",n->
get_isModified() ?
"true" :
"false");
17887 printf (
"In changeAllBodiesToBlocks(): AFTER RESET: case SgIfStmt: n->get_isModified() = %s \n",n->
get_isModified() ?
"true" :
"false");
17892 case V_SgCatchOptionStmt: {
17896 case V_SgUpcForAllStatement: {
17903 if (isSgOmpBodyStatement(n))
17910 if (wasPreviouslyModified ==
false)
17915 printf (
"In SageInterface::changeAllBodiesToBlocks(): parentOfBlock reset to FALSE after IR node member function call (e.g. set_body()): parentOfBlock = %p = %s \n",n,n->
class_name().c_str());
17924 Visitor(createEmptyBody).traverse(top, postorder);
17945#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
17946 SgStatement* enclosingStatement = getStatementOfExpression(from);
17947 SgExprStatement* exprStatement = isSgExprStatement(enclosingStatement);
17949 SgForStatement* forStatement = isSgForStatement(enclosingStatement);
17950 SgReturnStmt* returnStatement = isSgReturnStmt(enclosingStatement);
17956 ROSE_ASSERT (exprStatement || forStatement || returnStatement || varDeclarationStatement);
17958 if (varDeclarationStatement)
17965 ROSE_ASSERT (root);
17968 if (forStatement && forStatement->get_increment() == root)
17979 forStatement->get_increment()->
set_parent(incrStmt);
17983 forStatement->set_increment(ne);
17990 assert (enclosingStmtParent);
17991 SgWhileStmt* whileStatement = isSgWhileStmt(enclosingStmtParent);
17992 SgDoWhileStmt* doWhileStatement = isSgDoWhileStmt(enclosingStmtParent);
17993 SgIfStmt* ifStatement = isSgIfStmt(enclosingStmtParent);
17995 SgForStatement* enclosingForStatement = isSgForStatement(enclosingStmtParent);
17996 if (enclosingForStatement && enclosingForStatement->get_test() == exprStatement)
18008 pushTestIntoBody(enclosingForStatement);
18011 else if (whileStatement && whileStatement->
get_condition() == exprStatement)
18024 pushTestIntoBody(whileStatement);
18028 else if (doWhileStatement && doWhileStatement->
get_condition() == exprStatement)
18044 myStatementInsert(doWhileStatement, new_statement,
false);
18046 SgName varname =
"rose__temp1";
18051 varname,
buildBoolType(), assignInitializer, new_statement);
18054 initname->set_scope(new_statement);
18086 else if (ifStatement && ifStatement->
get_conditional() == exprStatement)
18092 myStatementInsert(ifStatement, new_statement,
false);
18094 SgName varname =
"rose__temp2";
18103 initname->set_scope(new_statement);
18128 else if (switchStatement && switchStatement->
get_item_selector() == exprStatement)
18130 SgExpression* switchCond = exprStatement->get_expression();
18131 ROSE_ASSERT (switchCond);
18136 myStatementInsert(switchStatement, new_statement,
false);
18138 SgName varname =
"rose__temp3";
18185#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
18186 SgStatement* stmt = getStatementOfExpression(from);
18188 if (isSgExprStatement(stmt))
18202 if (isSgAssignOp(top) && isSgAssignOp(top)->get_rhs_operand() == from)
18220 convertInitializerIntoAssignment(init);
18223 SgExprStatement* new_stmt = isSgExprStatement(getStatementOfExpression(from));
18224 assert (new_stmt != NULL);
18225 replaceAssignmentStmtWithStatement(new_stmt, to);
18242 ROSE_ASSERT(func&&s);
18244 Rose_STL_Container <SgNode* > stmts = NodeQuery::querySubTree(func, V_SgReturnStmt);
18246 Rose_STL_Container<SgNode*>::iterator i;
18247 for (i=stmts.begin();i!=stmts.end();i++)
18250 ROSE_ASSERT(cur_stmt);
18253 bool needRewrite = (exp != NULL) && !(isSgValueExp(exp));
18264 if (stmts.size()==0 )
18269 cout<<
"In instrumentEndOfFunction(), found an empty function body.! "<<endl;
18281 return ((stmt->get_declarationModifier()).get_storageModifier()).isStatic();
18288 return ((stmt->get_declarationModifier()).get_storageModifier()).setStatic();
18294 return ((stmt->get_declarationModifier()).get_storageModifier()).isExtern();
18302 return ((stmt->get_declarationModifier()).get_storageModifier()).setExtern();
18309 return name->get_storageModifier().isMutable();
18322 std::vector<SgInitializedName*> in_params;
18334 std::vector<SgInitializedName*> out_params;
18344 case V_SgCharVal:
return (
long long)(isSgCharVal(expr)->get_value());
18345 case V_SgUnsignedCharVal:
return isSgUnsignedCharVal(expr)->get_value();
18346 case V_SgShortVal:
return (
long long)(isSgShortVal(expr)->get_value());
18347 case V_SgUnsignedShortVal:
return isSgUnsignedShortVal(expr)->get_value();
18348 case V_SgIntVal:
return (
long long)(isSgIntVal(expr)->get_value());
18349 case V_SgUnsignedIntVal:
return isSgUnsignedIntVal(expr)->get_value();
18350 case V_SgLongIntVal:
return (
long long)(isSgLongIntVal(expr)->get_value());
18351 case V_SgUnsignedLongVal:
return isSgUnsignedLongVal(expr)->get_value();
18352 case V_SgLongLongIntVal:
return isSgLongLongIntVal(expr)->get_value();
18353 case V_SgUnsignedLongLongIntVal:
return isSgUnsignedLongLongIntVal(expr)->get_value();
18354 case V_SgBoolValExp:
return (
long long )(isSgBoolValExp(expr)->get_value());
18360 printf (
"ERROR: In SageInterface::getIntegerConstantValue(): default reached: expr = %p = %s \n",expr,expr->
class_name().c_str());
18361 ROSE_ASSERT (
false);
18366 ROSE_ASSERT (!
"Bad kind return in getIntegerConstantValue");
18371#ifdef ROSE_ENABLE_BINARY_ANALYSIS
18380 ROSE_ASSERT(binary!=NULL);
18385 if (1==headers.size()) {
18386 requisite_header = headers[0];
18388 for (SgAsmGenericHeaderPtrList::const_iterator hi=headers.begin(); hi!=headers.end(); ++hi) {
18389 if (isSgAsmPEFileHeader(*hi)) {
18390 requisite_header = isSgAsmPEFileHeader(*hi);
18395 ROSE_ASSERT(requisite_header!=NULL);
18398 const SgAsmInterpretationPtrList &interps = binary->get_interpretations()->
get_interpretations();
18399 for (SgAsmInterpretationPtrList::const_iterator ii=interps.begin(); ii!=interps.end(); ++ii) {
18400 const SgAsmGenericHeaderPtrList &headers = (*ii)->get_headers()->get_headers();
18401 for (SgAsmGenericHeaderPtrList::const_iterator hi=headers.begin(); hi!=headers.end(); ++hi) {
18402 if ((*hi)==requisite_header)
18407 ROSE_ASSERT(!
"no appropriate interpretation");
18420 SgNode* copy = n->copy(*
this);
18424 if (fileInfo != NULL)
18433 } collectDependentDeclarationsCopyType;
18441 vector<PreprocessingInfo*> cppDirectiveList;
18443 void visit(
SgNode *astNode);
18451 if (locatedNode != NULL)
18455 if (comments != NULL)
18458 printf (
"Found attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
sage_class_name());
18460 AttachedPreprocessingInfoType::iterator i;
18461 for (i = comments->begin(); i != comments->end(); i++)
18463 ROSE_ASSERT ( (*i) != NULL );
18465 printf (
" Attached Comment (relativePosition=%s): %s\n",
18466 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
18467 (*i)->getString().c_str());
18468 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
18469 (*i)->get_file_info()->display(
"comment/directive location");
18477 cppDirectiveList.push_back(*i);
18479 printf (
" Attached include directive (relativePosition=%s): %s\n",
18480 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
18481 (*i)->getString().c_str());
18489 printf (
"No attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
sage_class_name());
18500vector<PreprocessingInfo*>
18507 return t.cppDirectiveList;
18511vector<PreprocessingInfo*>
18518 return t.cppDirectiveList;
18523outputPreprocessingInfoList (
const vector<PreprocessingInfo*> & l )
18527 vector<PreprocessingInfo*>::const_iterator i = l.begin();
18528 while ( i != l.end() )
18530 printf (
" Attached include directive (relativePosition=%s): %s\n",
18531 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
18532 (*i)->getString().c_str());
18547 case V_SgNamespaceDefinitionStatement:
18550 declaration = namespaceDefinition->get_namespaceDeclaration();
18554 case V_SgClassDefinition:
18555 case V_SgTemplateInstantiationDefn:
18564 printf (
"Error: default reached in getAssociatedDeclaration(): scope = %p = %s \n",scope,scope->
class_name().c_str());
18570 ROSE_ASSERT(declaration != NULL);
18572 return declaration;
18581 vector<SgDeclarationStatement*> declarationList;
18585 vector<SgSymbol*> symbolList;
18588 set<SgDeclarationStatement*> alreadySavedDeclarations;
18591 void visit(
SgNode *astNode);
18607 ROSE_ASSERT(scope != NULL);
18612 SgGlobal* globalScope = isSgGlobal(scope);
18613 if (globalScope == NULL)
18620 ROSE_ASSERT(parentScope != NULL);
18621 while (globalScope == NULL)
18623 associatedDeclaration = getAssociatedDeclaration(parentScope);
18624 ROSE_ASSERT(associatedDeclaration != NULL);
18626 parentScope = parentScope->
get_scope();
18627 globalScope = isSgGlobal(parentScope);
18633 return returnDeclaration;
18639outputDeclarationList (
const vector<SgDeclarationStatement*> & l )
18644 vector<SgDeclarationStatement*>::const_iterator i = l.begin();
18645 while ( i != l.end() )
18647 printf (
"In outputDeclarationList(): list[%d] = %p = %s = %s \n",counter++,*i,(*i)->class_name().c_str(),
SageInterface::get_name(*i).c_str());
18655 if (declaration != NULL)
18664 if (alreadySavedDeclarations.find(dependentDeclaration) == alreadySavedDeclarations.end())
18667 printf (
"In CollectDependentDeclarationsTraversal::visit(): selected dependentDeclaration = %p = %s = %s \n",
18671 declarationList.push_back(dependentDeclaration);
18674 alreadySavedDeclarations.insert(dependentDeclaration);
18676 printf (
"In CollectDependentDeclarationsTraversal::visit(): astNode = %p = %s = %s \n",astNode,astNode->
class_name().c_str(),
SageInterface::get_name(astNode).c_str());
18677 printf (
"############### ADDING dependentDeclaration = %p = %s to alreadySavedDeclarations set (size = %" PRIuPTR
") \n",
18678 dependentDeclaration,dependentDeclaration->
class_name().c_str(),alreadySavedDeclarations.size());
18686 printf (
"In CollectDependentDeclarationsTraversal::visit(): astNode = %p = %s = %s \n",astNode,astNode->
class_name().c_str(),
SageInterface::get_name(astNode).c_str());
18687 printf (
"############### EXISTING dependentDeclaration = %p = %s found in alreadySavedDeclarations set (size = %" PRIuPTR
") \n",
18688 dependentDeclaration,dependentDeclaration->
class_name().c_str(),alreadySavedDeclarations.size());
18695static std::vector<SgTypedefDeclaration*> collectTypedefDeclarations(
SgType* type)
18697 ROSE_ASSERT(type != NULL);
18698 std::vector<SgTypedefDeclaration*> result;
18699 SgType* currentType = type;
18709 modType = isSgModifierType(currentType);
18712 currentType = modType->get_base_type();
18716 refType = isSgReferenceType(currentType);
18719 currentType = refType->get_base_type();
18723 pointType = isSgPointerType(currentType);
18726 currentType = pointType->get_base_type();
18730 arrayType = isSgArrayType(currentType);
18733 currentType = arrayType->get_base_type();
18737 typedefType = isSgTypedefType(currentType);
18748 result.push_back(decl);
18762 if (result.size()>0)
18764 cout<<
"------------Found a chain of typedef decls: count="<<result.size()<<endl;
18765 for (vector <SgTypedefDeclaration*>::const_iterator iter = result.begin();
18766 iter!=result.end(); iter ++)
18793 if (fileInfo != NULL && fileInfo->isFrontendSpecific() ==
false && (isSgStatement(astNode) != NULL) )
18795 printf (
"\n\nIn CollectDependentDeclarationsTraversal::visit(): astNode = %p = %s = %s \n",astNode,astNode->
class_name().c_str(),
SageInterface::get_name(astNode).c_str());
18798 printf (
"alreadySavedDeclarations.size() = %" PRIuPTR
" \n",alreadySavedDeclarations.size());
18799 for (set<SgDeclarationStatement*>::iterator i = alreadySavedDeclarations.begin(); i != alreadySavedDeclarations.end(); i++)
18801 printf (
"alreadySavedDeclarations %d: %p = %s \n",counter++,*i,(*i)->class_name().c_str());
18812 if (initializedname != NULL)
18814 SgType* type = initializedname->get_type();
18817 std::vector <SgTypedefDeclaration*> typedefVec = collectTypedefDeclarations(type);
18818 for (std::vector <SgTypedefDeclaration*>::const_iterator iter =typedefVec.begin();
18819 iter != typedefVec.end(); iter++)
18822 addDeclaration(typedef_decl);
18846 SgNamedType* namedType = isSgNamedType(strippedType);
18847 if (namedType != NULL)
18855 if (classDeclaration != NULL)
18862 if (declaration != NULL)
18865 addDeclaration(declaration);
18868 addDeclaration (classDeclaration);
18879 ROSE_ASSERT(classSymbol != NULL);
18882 symbolList.push_back(classSymbol);
18887 if (enum_decl != NULL)
18890 ROSE_ASSERT(declaration != NULL);
18891 addDeclaration(declaration);
18896 ROSE_ASSERT(esymbol!= NULL);
18897 symbolList.push_back(esymbol);
18901 printf (
"Found reference to type = %p = %s strippedType = %p = %s \n",type,type->
class_name().c_str(),strippedType,strippedType->
class_name().c_str());
18908 if (functionCallExp != NULL)
18913 if (declaration != NULL)
18914 addDeclaration(declaration);
18921 if (functionSymbol)
18922 symbolList.push_back(functionSymbol);
18927 SgEnumVal * eval = isSgEnumVal(astNode);
18930 declaration = eval->get_declaration();
18931 ROSE_ASSERT(declaration != NULL);
18932 addDeclaration(declaration);
18934 ROSE_ASSERT(symbol != NULL);
18935 symbolList.push_back(symbol);
18940static std::map<const SgStatement*, bool> visitedDeclMap;
18952 printf (
"\n\n********************************************************** \n");
18953 printf (
" Inside of getDependentDeclarations(stmt = %p = %s) \n",stmt,stmt->
class_name().c_str());
18954 printf (
"********************************************************** \n");
18956 visitedDeclMap[stmt]=
true;
18960 declarationList = t.declarationList;
18961 symbolList = t.symbolList;
18964 copy(t.declarationList.begin(),t.declarationList.end(), back_inserter(declarationList));
18965 copy(t.symbolList.begin(),t.symbolList.end(), back_inserter(symbolList));
18967 sort (declarationList.begin(), declarationList.end());
18968 vector<SgDeclarationStatement*>::iterator new_end = unique(declarationList.begin(), declarationList.end());
18969 declarationList.erase(new_end, declarationList.end());
18971 sort (symbolList.begin(), symbolList.end());
18972 vector<SgSymbol*>::iterator end2 = unique(symbolList.begin(), symbolList.end());
18973 symbolList.erase(end2, symbolList.end());
18977 for (vector<SgDeclarationStatement*>::const_iterator iter = t.declarationList.begin();
18978 iter !=t.declarationList.end(); iter++)
18981 SgType* base_type = NULL;
18986 if (isSgClassDeclaration(decl))
18988 base_type = isSgClassDeclaration(decl)->get_type();
18990 if (isSgTypedefDeclaration(decl))
18994 base_type = isSgTypedefDeclaration(decl)->get_base_type()->
stripType(SgType::STRIP_POINTER_TYPE|SgType::STRIP_ARRAY_TYPE|SgType::STRIP_REFERENCE_TYPE|SgType::STRIP_RVALUE_REFERENCE_TYPE|SgType::STRIP_MODIFIER_TYPE);
19002 if (isSgClassType(base_type))
19004 SgClassDeclaration* class_decl = isSgClassDeclaration(isSgClassType(base_type)->get_declaration()->get_definingDeclaration());
19005 if (class_decl!=NULL)
19007 body_stmt = class_decl->get_definition();
19011 if ((body_stmt!=NULL) &&(!visitedDeclMap[body_stmt]))
19023vector<SgDeclarationStatement*>
19026 vector<SgDeclarationStatement*> sortedNode;
19028 if (nodevec.size()==0 )
19031 if (nodevec.size() ==1)
19035 Rose_STL_Container<SgNode*> queryResult = NodeQuery::querySubTree(project,V_SgDeclarationStatement);
19036 for (Rose_STL_Container<SgNode*>::const_iterator iter = queryResult.begin();
19037 iter!= queryResult.end(); iter++)
19040 SgNode* cur_node = *iter;
19042 ROSE_ASSERT(cur_stmt!=NULL);
19054 ROSE_ASSERT (cur_stmt != func_decl);
19057 vector<SgDeclarationStatement*>::const_iterator i = find (nodevec.begin(), nodevec.end(), cur_stmt);
19058 if (i!=nodevec.end())
19062 vector<SgDeclarationStatement*>::const_iterator j = find (sortedNode.begin(), sortedNode.end(), *i);
19063 if (j == sortedNode.end())
19064 sortedNode.push_back(*i);
19068 if (nodevec.size() != sortedNode.size())
19070 cerr<<
"Fatal error in sortSgNodeListBasedOnAppearanceOrderInSource(): nodevec.size() != sortedNode.size()"<<endl;
19071 cerr<<
"nodevec() have "<< nodevec.size()<<
" elements. They are:"<<endl;
19072 for (vector<SgDeclarationStatement*>::const_iterator iter = nodevec.begin(); iter != nodevec.end(); iter++)
19074 cerr<<(*iter)<<
" "<<(*iter)->class_name() <<
" "<<(*iter)->unparseToString()<<endl;
19076 cerr<<
"sortedNode() have " << sortedNode.size() <<
" elements. They are:"<<endl;
19077 for (vector<SgDeclarationStatement*>::const_iterator iter = sortedNode.begin(); iter != sortedNode.end(); iter++)
19079 cerr<<(*iter)<<
" "<<(*iter)->class_name() <<
" "<<(*iter)->unparseToString()<<endl;
19082 ROSE_ASSERT(nodevec.size() == sortedNode.size());
19089std::vector<SgDeclarationStatement*>
19095 printf (
"\n\n********************************************************** \n");
19096 printf (
" Inside of getDependentDeclarations(stmt = %p = %s) \n",stmt,stmt->
class_name().c_str());
19097 printf (
"********************************************************** \n");
19102 return t.declarationList;
19105 visitedDeclMap.clear();
19106 vector<SgDeclarationStatement*> declarationList;
19107 vector<SgSymbol*> symbolList;
19111 printf (
"\n\n ********************************************************** \n");
19112 cout<<
"Found dependent decl: count="<<declarationList.size()<<endl;
19113 for ( vector<SgDeclarationStatement*>::const_iterator iter = declarationList.begin();
19114 iter != declarationList.end(); iter++)
19116 cout<<
"\t"<<(*iter)->class_name()<<
" at line "<<(*iter)->get_file_info()->get_line()<<endl;
19117 if ((*iter)->variantT()== V_SgFunctionDeclaration)
19118 cout<<
"func name is:"<<isSgFunctionDeclaration(*iter)->get_name().getString()<<endl;
19121 printf (
"\n ********************************************************** \n");
19124 return declarationList;
19133 bool returnValue =
false;
19136 printf (
"In SageInterface::isPrefixOperatorName(): functionName = %s (might have to check the return type to distinguish the deref operator from the multiply operator) \n",functionName.str());
19139 if (functionName.is_null() ==
false)
19142 if ( functionName ==
"operator++" || functionName ==
"operator--" || functionName ==
"operator&" ||
19143 functionName ==
"operator!" || functionName ==
"operator*" || functionName ==
"operator+" ||
19144 functionName ==
"operator-" || functionName ==
"operator+" || functionName ==
"operator~")
19146 returnValue =
true;
19150 return returnValue;
19162 bool returnValue =
false;
19169 size_t numberOfOperands = 0;
19171 if (memberFunctionRefExp != NULL)
19173 ROSE_ASSERT(functionRefExp == NULL);
19175 if (memberFunctionDeclaration != NULL)
19177 functionName = memberFunctionDeclaration->get_name();
19178 numberOfOperands = memberFunctionDeclaration->get_args().size();
19184 if (functionRefExp != NULL)
19187 if (functionDeclaration != NULL)
19189 functionName = functionDeclaration->get_name();
19190 numberOfOperands = functionDeclaration->get_args().size();
19196 printf (
"In SageInterface::isPrefixOperator(): unknown case of exp = %p = %s \n",exp,exp->
class_name().c_str());
19201 printf (
"In SageInterface::isPrefixOperator(): functionName = %s numberOfOperands = %" PRIuPTR
" (might have to check the return type to distinguish the deref operator from the multiply operator) \n",functionName.str(),numberOfOperands);
19206 if (memberFunctionRefExp != NULL)
19209 ROSE_ASSERT(functionRefExp == NULL);
19210 if (numberOfOperands == 0)
19213 returnValue =
true;
19218 returnValue =
false;
19224 ROSE_ASSERT(functionRefExp != NULL);
19225 ROSE_ASSERT(memberFunctionRefExp == NULL);
19226 if (numberOfOperands == 1)
19229 returnValue =
true;
19234 ROSE_ASSERT(numberOfOperands == 2);
19235 returnValue =
false;
19241 printf (
"Leaving SageInterface::isPrefixOperator(): returnValue = %s \n",returnValue ?
"true" :
"false");
19244 return returnValue;
19260 bool returnValue =
false;
19262 if (memberFunctionRefExp == NULL)
19266 if (memberFunctionDeclaration != NULL)
19268 SgName functionName = memberFunctionDeclaration->get_name();
19269 if ( (functionName ==
"operator[]") && (isSgType(memberFunctionDeclaration->get_type()) != NULL) )
19271 returnValue =
true;
19275 if ( (functionName ==
"operator()") && (isSgType(memberFunctionDeclaration->get_type()) != NULL) )
19277 returnValue =
true;
19281 returnValue =
false;
19286 return returnValue;
19297 ROSE_ASSERT(scope != NULL);
19300 printf (
"In SageInterface::lastStatementOfScopeWithTokenInfo(): scope = %p = %s \n",scope,scope->
class_name().c_str());
19303 SgIfStmt* ifStatement = isSgIfStmt(scope);
19304 if (ifStatement != NULL)
19307 if (lastStatement == NULL || (tokenStreamSequenceMap.find(lastStatement) == tokenStreamSequenceMap.end() || tokenStreamSequenceMap[lastStatement] == NULL))
19310 if (lastStatement == NULL || (tokenStreamSequenceMap.find(lastStatement) == tokenStreamSequenceMap.end() || tokenStreamSequenceMap[lastStatement] == NULL))
19312 lastStatement = NULL;
19316 printf (
"Note: SgIfStmt scope in SageInterface::lastStatementOfScopeWithTokenInfo(): returning lastStatement = %p \n",lastStatement);
19317 if (lastStatement != NULL)
19319 printf (
" --- lastStatement = %p = %s \n",lastStatement,lastStatement->
class_name().c_str());
19322 return lastStatement;
19326 if (statementList.rbegin() != statementList.rend())
19329 SgStatementPtrList::reverse_iterator i = statementList.rbegin();
19331 while (i != statementList.rend() && (tokenStreamSequenceMap.find(*i) == tokenStreamSequenceMap.end() || tokenStreamSequenceMap[*i] == NULL) )
19336 if (i == statementList.rend())
19338 lastStatement = NULL;
19342 lastStatement = *i;
19346 return lastStatement;
19360 void visit (
SgNode* node)
19370 printf (
"Found declaration = %p = %s name = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
19371 if (decl != definingDeclaration && decl != firstNondefiningDeclaration)
19373 otherDeclaration = decl;
19376 if (definingDeclaration != NULL)
19378 definingDeclaration->get_declarationModifier().get_accessModifier().display(
"definingDeclaration: accessModifier");
19381 if (firstNondefiningDeclaration != NULL)
19383 firstNondefiningDeclaration->get_declarationModifier().get_accessModifier().display(
"firstNondefiningDeclaration: accessModifier");
19386 if (otherDeclaration != NULL)
19388 otherDeclaration->get_declarationModifier().get_accessModifier().display(
"otherDeclaration: accessModifier");
19398 DeclarationTraversal traversal;
19399 traversal.traverse(astNode, preorder);
19411 void visit (
SgNode* node)
19417 if (functionDefinition != NULL)
19420 ROSE_ASSERT(functionDeclaration != NULL);
19422 string functionName = functionDeclaration->get_name();
19424 printf (
"functionName = %s \n",functionName.c_str());
19426 if (functionName ==
"main")
19430 ROSE_ASSERT(functionBody != NULL);
19432 ROSE_ASSERT(symbolTable != NULL);
19435 symbolTable->
print();
19440 if (namespaceDefinition != NULL)
19443 ROSE_ASSERT(namespaceDeclaration != NULL);
19445 string namespaceName = namespaceDeclaration->
get_name();
19447 printf (
"namespaceName = %s \n",namespaceName.c_str());
19449 if (namespaceName ==
"B")
19452 ROSE_ASSERT(symbolTable != NULL);
19455 symbolTable->
print();
19463 ScopeTraversal traversal;
19464 traversal.traverse(astNode, preorder);
19472 if (fileInfo != NULL)
19478 if (locatedNode != NULL)
19487 printf (
"In markNodeToBeUnparsed(): physical_file_id = %d \n",physical_file_id);
19490 locatedNode->
get_file_info()->set_physical_file_id(physical_file_id);
19492 printf (
"Note: calling node markTransformationsForOutput(): node = %p = %s \n",node,node->
class_name().c_str());
19496 markTransformationsForOutput(node);
19501 printf (
"Note: node is not a SgLocatedNode: node = %p = %s \n",node,node->
class_name().c_str());
19508 printf (
"Note: no Sg_File_Info was found: node = %p = %s \n",node,node->
class_name().c_str());
19513 if (locatedNode != NULL)
19522 printf (
"In SageInterface::markNodeToBeUnparsed(): locatedNode = %p = %s calling set_physical_file_id(%d) \n",locatedNode,locatedNode->
class_name().c_str(),physical_file_id);
19524 locatedNode->
get_file_info()->set_physical_file_id(physical_file_id);
19529 printf (
"Note: no Sg_File_Info was found: node = %p = %s \n",node,node->
class_name().c_str());
19562 class InheritedAttribute
19565 int physical_file_id;
19566 bool isCastSubtree;
19567 InheritedAttribute(
int file_id): physical_file_id(file_id), isCastSubtree(
false) {}
19568 InheritedAttribute(
const InheritedAttribute & X)
19570 isCastSubtree = X.isCastSubtree;
19571 physical_file_id = X.physical_file_id;
19582 InheritedAttribute evaluateInheritedAttribute (
SgNode* node, InheritedAttribute inheritedAttribute)
19584 InheritedAttribute returnAttribute(inheritedAttribute);
19586 SgCastExp* castExpression = isSgCastExp(node);
19587 if (castExpression != NULL)
19589 returnAttribute.isCastSubtree =
true;
19592 if (returnAttribute.isCastSubtree ==
true)
19596 printf (
"In markSubtreeToBeUnparsedTreeTraversal(): subtree of a SgCastExp: node = %p = %s physical_file_id = %d \n",
19597 node,node->
class_name().c_str(),inheritedAttribute.physical_file_id);
19603 printf (
"In markSubtreeToBeUnparsedTreeTraversal(): Calling markNodeToBeUnparsed(): node = %p = %s physical_file_id = %d \n",
19604 node,node->
class_name().c_str(),inheritedAttribute.physical_file_id);
19610 return returnAttribute;
19614 InheritedAttribute inheritedAttribute(physical_file_id);
19617 SubtreeTraversal traversal;
19620 printf (
"\nIn markSubtreeToBeUnparsedTreeTraversal(): calling traverse \n");
19623 traversal.traverse(root, inheritedAttribute);
19625 printf (
"This function does not compile with GNU 4.9 or older compilers (part of ROSE used only with more modern compilers) \n");
19634vector<SgDeclarationStatement*>
19635generateCopiesOfDependentDeclarations (
const vector<SgDeclarationStatement*>& dependentDeclarations,
SgScopeStatement* targetScope)
19646 printf (
"\n\n********************************************************** \n");
19647 printf (
" Inside of generateCopiesOfDependentDeclarations(stmt = %p = %s) \n",stmt,stmt->
class_name().c_str());
19648 printf (
"********************************************************** \n");
19651 vector<SgDeclarationStatement*> copiesOfDependentDeclarations;
19656 printf (
"Output the dependentDeclarations: dependentDeclarations.size() = %" PRIuPTR
" \n",dependentDeclarations.size());
19657 outputDeclarationList(dependentDeclarations);
19660 printf (
"************************************************ \n");
19661 printf (
"*** Make all copies of dependentDeclarations *** \n");
19662 printf (
"************************************************ \n");
19666 ROSE_ASSERT(targetScope != NULL);
19669 ROSE_ASSERT(isSgGlobal(targetScope) != NULL);
19671 for (vector<SgDeclarationStatement*>::const_iterator i = dependentDeclarations.begin(); i != dependentDeclarations.end(); i++)
19674 printf (
"Copying declaration = %p = %s = %s \n",*i,(*i)->class_name().c_str(),
SageInterface::get_name(*i).c_str());
19678 SgNode* copy_node = NULL;
19683 if (functionDeclaration != NULL)
19692 printf (
"WARNING: In SageInterface -- generateCopiesOfDependentDeclarations(): I think this is the wrong lookup symbol function that is being used here! \n");
19699 printf (
"In generateCopiesOfDependentDeclarations(): Copy mechanism appied to SgFunctionDeclaration functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->
get_firstNondefiningDeclaration());
19701 printf (
"functionDeclaration = %p \n",functionDeclaration);
19702 printf (
"functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->
get_definingDeclaration());
19704 printf (
"functionDeclaration->get_scope() = %p \n",functionDeclaration->
get_scope());
19705 printf (
"targetScope = %p \n",targetScope);
19708 assert(copy_functionDeclaration != NULL);
19710 copy_functionDeclaration->
set_parent(targetScope);
19720 assert(copy_functionDeclaration->
get_scope() != NULL);
19721 assert(copy_functionDeclaration->
get_scope() == targetScope);
19722 assert(copy_functionDeclaration->
get_scope()->lookup_function_symbol(copy_functionDeclaration->get_name(),
19723 copy_functionDeclaration->get_type()) != NULL);
19724 assert(copy_functionDeclaration->
get_scope()->lookup_function_symbol(copy_functionDeclaration->get_name(),
19727 copy_node = copy_functionDeclaration;
19729 printf (
"In generateCopiesOfDependentDeclarations(): DONE: Copy mechanism appied to SgFunctionDeclaration \n");
19743 cout<<
"Copying a defining typedef declaration:"<<tdecl->
unparseToString()<<endl;
19745 cout<<
"Copying a non-defining typedef declaration:"<<tdecl->
unparseToString()<<endl;
19749 tdecl_copy->set_typedefBaseTypeContainsDefiningDeclaration (
false);
19752 copy_node = (*i)->copy(collectDependentDeclarationsCopyType);
19756 ROSE_ASSERT(copy_declaration != NULL);
19760 copy_declaration->
set_scope(targetScope);
19772 ROSE_ASSERT(copy_node != NULL);
19781 ROSE_ASSERT(copy_definingDeclaration != NULL);
19783 ROSE_ASSERT( *i != NULL );
19784 ROSE_ASSERT(copy_definingDeclaration != NULL);
19787 if (copy_definingDeclaration->
get_parent() == NULL)
19789 copy_definingDeclaration->
set_parent(targetScope);
19791 ROSE_ASSERT(copy_definingDeclaration->
get_parent() != NULL);
19794 printf (
"DONE: Copying declaration: original scope = %p copied to scope = %p \n",(*i)->get_scope(),copy_definingDeclaration->
get_scope());
19804 ROSE_ASSERT(copy_definingDeclaration->
get_parent() == NULL);
19811 printf (
"copy_definingDeclaration = %p \n",copy_definingDeclaration);
19812 printf (
"copy_definingDeclaration->get_firstNondefiningDeclaration() == NULL \n");
19813 printf (
"copy_definingDeclaration->get_definingDeclaration() = %p \n",copy_definingDeclaration->
get_definingDeclaration());
19818 if ((*i)->get_firstNondefiningDeclaration() != NULL)
19826 copiesOfDependentDeclarations.push_back(copy_definingDeclaration);
19830 printf (
"****************************************************** \n");
19831 printf (
"*** DONE: Make all copies of dependentDeclarations *** \n");
19832 printf (
"****************************************************** \n");
19833 printf (
"copiesOfDependentDeclarations.size() = %" PRIuPTR
" \n",copiesOfDependentDeclarations.size());
19839 ROSE_ASSERT(copiesOfDependentDeclarations.size() <= dependentDeclarations.size());
19841 return copiesOfDependentDeclarations;
19846declarationContainsDependentDeclarations(
SgDeclarationStatement* decl, vector<SgDeclarationStatement*> & dependentDeclarationList )
19849 bool returnValue =
false;
19852 printf (
"\n\n********************************************************** \n");
19853 printf (
" Inside of declarationContainsDependentDeclarations(decl = %p = %s) \n",decl,decl->
class_name().c_str());
19854 printf (
"********************************************************** \n");
19862 for (
size_t i = 0; i < locallyDependentDeclarationList.size(); i++)
19868 vector<SgDeclarationStatement*>::iterator j = find(dependentDeclarationList.begin(),dependentDeclarationList.end(),d);
19869 if (j != dependentDeclarationList.end())
19874 printf (
"Found a dependent declaration buried in the class definition: locallyDependentDeclarationList[%" PRIuPTR
"] = %p = %s = %s \n",i,d,d->
class_name().c_str(),
SageInterface::get_name(d).c_str());
19876 returnValue =
true;
19881 printf (
"**************************************************************************** \n");
19882 printf (
" LEAVING: Inside of declarationContainsDependentDeclarations(decl = %p = %s) returnValue = %s \n",decl,decl->
class_name().c_str(),returnValue ?
"true" :
"false");
19883 printf (
"**************************************************************************** \n");
19886 return returnValue;
19891 ROSE_ASSERT (new_exp != NULL);
19892 ROSE_ASSERT (anchor_exp != NULL);
19893 ROSE_ASSERT (new_exp != anchor_exp);
19896 ROSE_ASSERT (parent != NULL);
19900 ROSE_ASSERT (result != NULL);
19912 ROSE_ASSERT (new_exp != NULL);
19913 ROSE_ASSERT (anchor_exp != NULL);
19914 ROSE_ASSERT (new_exp != anchor_exp);
19917 ROSE_ASSERT (parent != NULL);
19921 ROSE_ASSERT (t != NULL);
19923 ROSE_ASSERT (enclosing_stmt != NULL);
19930 ROSE_ASSERT (temp_sym != NULL);
19932 *temp_decl = t_decl;
19937 * temp_ref = first_ref;
19950 string fileName =
"separate-outlined-file";
19970 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl = %p \n",decl);
19971 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_parent() = %p \n",decl->
get_parent());
19972 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_scope() = %p \n",decl->
get_scope());
19973 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): original_statement = %p \n",original_statement);
19974 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): file (decl) = %s \n",TransformationSupport::getSourceFile(decl)->getFileName().c_str());
19975 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_firstNondefiningDeclaration() = %p \n",decl->
get_firstNondefiningDeclaration());
19977 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): file (first non-defining) = %s \n",TransformationSupport::getSourceFile(decl->
get_firstNondefiningDeclaration())->
getFileName().c_str());
19978 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_definingDeclaration() = %p \n",decl->
get_definingDeclaration());
19980 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): file (first non-defining) = %s \n",TransformationSupport::getSourceFile(decl->
get_definingDeclaration())->
getFileName().c_str());
19983#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
20015 vector<SgDeclarationStatement*> dependentDeclarationList_inOriginalFile;
20022 vector<SgDeclarationStatement*> dependentDeclarationList = generateCopiesOfDependentDeclarations(dependentDeclarationList_inOriginalFile,scope);
20023 ROSE_ASSERT(dependentDeclarationList.size() <= dependentDeclarationList_inOriginalFile.size());
20033 std::map<SgNode*, SgNode*> replacementMap;
20038 SgCopyHelp::copiedNodeMapType copyNodeMap = collectDependentDeclarationsCopyType.get_copiedNodeMap();
20039 SgCopyHelp::copiedNodeMapType::iterator copyNodeMapItrator = copyNodeMap.begin();
20040 while (copyNodeMapItrator != copyNodeMap.end())
20045 SgNode* first =
const_cast<SgNode*
>(copyNodeMapItrator->first);
20046 SgNode* second = copyNodeMapItrator->second;
20048 printf (
"copyNodeMapItrator.first = %p = %s second = %p = %s \n",first,first->
class_name().c_str(),second,second->
class_name().c_str());
20051 if (isSgSymbol(first) != NULL)
20056 replacementMap.insert(pair<SgNode*,SgNode*>(first,second));
20059 copyNodeMapItrator++;
20063 printf (
"Exiting after test of new functionality \n");
20069 SgSourceFile* sourceFile = TransformationSupport::getSourceFile(original_statement);
20070 vector<PreprocessingInfo*> requiredDirectivesList = collectCppDirectives(sourceFile);
20073 ROSE_ASSERT(outlinedFunctionDeclaration != NULL);
20074 SgGlobal* originalFileGlobalScope = TransformationSupport::getGlobalScope(original_statement);
20075 ROSE_ASSERT(originalFileGlobalScope != NULL);
20077 printf (
"WARNING: In SageInterface::appendStatementWithDependentDeclaration(): I think this is the wrong lookup symbol function that is being used here! \n");
20081 SgFunctionSymbol* outlinedFunctionSymbolFromOriginalFile = isSgFunctionSymbol(originalFileGlobalScope->lookup_symbol(outlinedFunctionDeclaration->get_name(),NULL,NULL));
20087 printf (
"outlinedFunctionSymbolFromOriginalFile = %p outlinedFunctionSymbolFromOutlinedFile = %p \n",outlinedFunctionSymbolFromOriginalFile,outlinedFunctionSymbolFromOutlinedFile);
20089 printf (
"TransformationSupport::getSourceFile(decl)->getFileName() = %s \n",TransformationSupport::getSourceFile(decl)->getFileName().c_str());
20090 printf (
"TransformationSupport::getSourceFile(decl->get_firstNondefiningDeclaration())->getFileName() = %s \n",TransformationSupport::getSourceFile(decl->
get_firstNondefiningDeclaration())->
getFileName().c_str());
20091 printf (
"TransformationSupport::getSourceFile(original_statement)->getFileName() = %s \n",TransformationSupport::getSourceFile(original_statement)->getFileName().c_str());
20094 ROSE_ASSERT(outlinedFunctionSymbolFromOriginalFile != NULL);
20095 ROSE_ASSERT(outlinedFunctionSymbolFromOutlinedFile != NULL);
20098 ROSE_ASSERT(outlinedFunctionSymbolFromOriginalFile == outlinedFunctionSymbolFromOutlinedFile);
20101 replacementMap.insert(pair<SgNode*,SgNode*>(originalFileGlobalScope,scope));
20104 SgFunctionDeclaration* outlinedNondefiningFunctionDeclarationFromOriginalFile = isSgFunctionDeclaration(outlinedFunctionSymbolFromOriginalFile->get_declaration());
20106 ROSE_ASSERT(outlinedNondefiningFunctionDeclarationFromOriginalFile != NULL);
20107 ROSE_ASSERT(outlinedNondefiningFunctionDeclarationFromOutlinedFile != NULL);
20108 replacementMap.insert(pair<SgNode*,SgNode*>(outlinedNondefiningFunctionDeclarationFromOriginalFile,outlinedNondefiningFunctionDeclarationFromOutlinedFile));
20117 for (
size_t i = 0; i < dependentDeclarationList.size(); i++)
20123 printf (
"originalDeclaration = %p \n",originalDeclaration);
20125 d->
get_file_info()->display(
"SageInterface::appendStatementWithDependentDeclaration()");
20133 ROSE_ASSERT(decl->
get_scope() == scope);
20139 printf (
"Add the required symbol information to the symbol table: scope = %p = %s \n",scope,scope->
class_name().c_str());
20146 case V_SgClassDeclaration:
20148 if ( declarationContainsDependentDeclarations(d,dependentDeclarationList) ==
true )
20149 printf (
"Warning: This class contains dependent declarations (not implemented) \n");
20153 case V_SgMemberFunctionDeclaration:
20154 printf (
"Sorry, support for dependent member function declarations not implemented! \n");
20157 case V_SgTemplateInstantiationDecl:
20158 printf (
"Sorry, not implemented: case SgTemplateInstantiationDecl not handled as dependent declaration \n");
20159 d->
get_file_info()->display(
"Sorry, not implemented: case SgTemplateInstantiationDecl not handled as dependent declaration");
20161 printf (
"Case of SgTemplateInstantiationDecl not implemented. \n");
20164 case V_SgNamespaceDeclarationStatement:
20165 if (declarationContainsDependentDeclarations(d,dependentDeclarationList) ==
true )
20166 printf (
"Warning: This namespace contains dependent declarations (not supported) \n");
20169 case V_SgFunctionDeclaration:
20170 case V_SgTypedefDeclaration:
20171 case V_SgEnumDeclaration:
20175 printf (
"default case in SageInterface::appendStatementWithDependentDeclaration() (handling dependentDeclarationList) d = %p = %s \n",d,d->
class_name().c_str());
20181 vector<PreprocessingInfo*> cppDirectivesAlreadyAttachedToDependentDeclarations = collectCppDirectives(d);
20184 printf (
"directives BEFORE excluding those already present in dependent declarations \n");
20185 outputPreprocessingInfoList(requiredDirectivesList);
20187 printf (
"directives already attached to dependent declarations \n");
20188 outputPreprocessingInfoList(cppDirectivesAlreadyAttachedToDependentDeclarations);
20192 vector<PreprocessingInfo*>::iterator j = cppDirectivesAlreadyAttachedToDependentDeclarations.begin();
20193 while ( j != cppDirectivesAlreadyAttachedToDependentDeclarations.end() )
20196 vector<PreprocessingInfo*>::iterator entry = find(requiredDirectivesList.begin(),requiredDirectivesList.end(),*j);
20197 ROSE_ASSERT(entry != requiredDirectivesList.end());
20199 requiredDirectivesList.erase(entry);
20205 printf (
"directives AFTER excluding those already present in dependent declarations \n");
20206 outputPreprocessingInfoList(requiredDirectivesList);
20215 if (dependentDeclarationList.empty() ==
true)
20217 firstStatmentInFile = decl;
20221 firstStatmentInFile = dependentDeclarationList[0];
20224 ROSE_ASSERT(firstStatmentInFile != NULL);
20232 if (excludeHeaderFiles ==
false)
20235 vector<PreprocessingInfo*>::reverse_iterator j = requiredDirectivesList.rbegin();
20236 while ( j != requiredDirectivesList.rend() )
20255 SgSourceFile* outlinedFile = TransformationSupport::getSourceFile(scope);
20256 ROSE_ASSERT(outlinedFile != NULL);
20262 printf (
"\n\n************************************************************\n");
20263 printf (
"Calling Utils::edgePointerReplacement() \n");
20269 printf (
"Calling Utils::edgePointerReplacement(): DONE \n");
20270 printf (
"************************************************************\n\n");
20272 printf (
"\n\n After replacementMapTraversal(): intermediateDeleteSet: \n");
20273 displaySet(intermediateDeleteSet,
"After Utils::edgePointerReplacement");
20277 ROSE_ASSERT(dependentDeclarationList.size() <= dependentDeclarationList_inOriginalFile.size());
20285 printf (
"replacementMap.size() = %" PRIuPTR
" dependentDeclarationList.size() = %" PRIuPTR
" \n",replacementMap.size(),dependentDeclarationList.size());
20301 int SgVariableSymbol_count;
20302 int SgFunctionSymbol_count;
20303 int SgClassDeclaration_count;
20304 int SgTypedefSymbol_count;
20305 int SgMemFuncSymbol_count;
20306 int SgTemplateSymbol_count;
20307 int SgEnumFieldSymbol_count;
20325 SgVariableSymbol_count = 0;
20326 SgVariableSymbolPtr = symbol;
20327 SgFunctionSymbolPtr =NULL;
20328 SgClassSymbolPtr =NULL;
20329 SgTypedefPtr = NULL;
20330 SgMemFuncSymbolPtr =NULL;
20331 class_defining = NULL;
20333 typedef_defining =NULL;
20334 function_decl = NULL;
20335 SgTemplateSymbolPtr = NULL;
20336 template_defining = NULL;
20337 SgEnumFieldSymbolPtr = NULL;
20338 templateInstantiate_defining =NULL;
20342 SgFunctionSymbol_count = 0;
20343 SgFunctionSymbolPtr = symbol;
20346 SgMemFuncSymbol_count =0;
20348 SgVariableSymbolPtr = NULL;
20349 SgClassSymbolPtr =NULL;
20350 SgTypedefPtr = NULL;
20351 SgMemFuncSymbolPtr =NULL;
20352 class_defining = NULL;
20354 typedef_defining =NULL;
20355 function_decl = NULL;
20356 SgTemplateSymbolPtr = NULL;
20357 template_defining = NULL;
20358 SgEnumFieldSymbolPtr = NULL;
20359 templateInstantiate_defining =NULL;
20363 SgClassDeclaration_count = 0;
20364 SgClassSymbolPtr = symbol;
20365 SgFunctionSymbolPtr = NULL;
20366 SgVariableSymbolPtr = NULL;
20367 SgTypedefPtr = NULL;
20368 SgMemFuncSymbolPtr =NULL;
20369 class_defining = NULL;
20371 typedef_defining =NULL;
20372 function_decl = NULL;
20373 SgTemplateSymbolPtr = NULL;
20374 template_defining = NULL;
20375 SgEnumFieldSymbolPtr = NULL;
20376 templateInstantiate_defining =NULL;
20380 SgTypedefSymbol_count =0;
20381 SgTypedefPtr = symbol;
20382 SgClassSymbolPtr = NULL;
20383 SgFunctionSymbolPtr = NULL;
20384 SgVariableSymbolPtr = NULL;
20385 SgMemFuncSymbolPtr =NULL;
20386 class_defining = NULL;
20388 typedef_defining =NULL;
20389 function_decl = NULL;
20390 SgTemplateSymbolPtr = NULL;
20391 template_defining = NULL;
20392 SgEnumFieldSymbolPtr = NULL;
20393 templateInstantiate_defining =NULL;
20397 SgMemFuncSymbolPtr = symbol;
20398 SgMemFuncSymbol_count =0;
20399 SgTypedefPtr = NULL;
20400 SgClassSymbolPtr = NULL;
20401 SgFunctionSymbolPtr = NULL;
20402 SgVariableSymbolPtr = NULL;
20403 class_defining = NULL;
20405 typedef_defining =NULL;
20406 function_decl = NULL;
20407 SgTemplateSymbolPtr = NULL;
20408 template_defining = NULL;
20409 SgEnumFieldSymbolPtr = NULL;
20410 templateInstantiate_defining =NULL;
20414 SgTemplateSymbolPtr = symbol;
20415 SgTemplateSymbol_count =0;
20416 SgMemFuncSymbolPtr = NULL;
20417 SgTypedefPtr = NULL;
20418 SgClassSymbolPtr = NULL;
20419 SgFunctionSymbolPtr = NULL;
20420 SgVariableSymbolPtr = NULL;
20421 class_defining = NULL;
20423 typedef_defining =NULL;
20424 function_decl = NULL;
20425 template_defining = NULL;
20426 SgEnumFieldSymbolPtr = NULL;
20427 templateInstantiate_defining =NULL;
20431 SgEnumFieldSymbolPtr = symbol;
20432 SgEnumFieldSymbol_count =0;
20433 SgTemplateSymbolPtr = NULL;
20434 SgMemFuncSymbolPtr = NULL;
20435 SgTypedefPtr = NULL;
20436 SgClassSymbolPtr = NULL;
20437 SgFunctionSymbolPtr = NULL;
20438 SgVariableSymbolPtr = NULL;
20439 class_defining = NULL;
20441 typedef_defining =NULL;
20442 function_decl = NULL;
20443 template_defining = NULL;
20444 templateInstantiate_defining =NULL;
20449 class_defining = node;
20450 SgMemFuncSymbolPtr = NULL;
20451 SgTypedefPtr = NULL;
20452 SgClassSymbolPtr = NULL;
20453 SgFunctionSymbolPtr = NULL;
20454 SgVariableSymbolPtr = NULL;
20456 typedef_defining =NULL;
20457 function_decl = NULL;
20458 SgTemplateSymbolPtr = NULL;
20459 template_defining = NULL;
20460 SgEnumFieldSymbolPtr = NULL;
20461 templateInstantiate_defining =NULL;
20465 template_defining = node;
20466 class_defining = NULL;
20467 SgMemFuncSymbolPtr = NULL;
20468 SgTypedefPtr = NULL;
20469 SgClassSymbolPtr = NULL;
20470 SgFunctionSymbolPtr = NULL;
20471 SgVariableSymbolPtr = NULL;
20473 typedef_defining =NULL;
20474 function_decl = NULL;
20475 SgTemplateSymbolPtr = NULL;
20476 SgEnumFieldSymbolPtr = NULL;
20477 templateInstantiate_defining =NULL;
20480 function_decl =node;
20481 class_defining = NULL;
20482 SgMemFuncSymbolPtr = NULL;
20483 SgTypedefPtr = NULL;
20484 SgClassSymbolPtr = NULL;
20485 SgFunctionSymbolPtr = NULL;
20486 SgVariableSymbolPtr = NULL;
20488 typedef_defining =NULL;
20489 SgTemplateSymbolPtr = NULL;
20490 template_defining = NULL;
20491 SgEnumFieldSymbolPtr = NULL;
20492 templateInstantiate_defining =NULL;
20497 function_decl =NULL;
20498 class_defining = NULL;
20499 SgMemFuncSymbolPtr = NULL;
20500 SgTypedefPtr = NULL;
20501 SgClassSymbolPtr = NULL;
20502 SgFunctionSymbolPtr = NULL;
20503 SgVariableSymbolPtr = NULL;
20504 typedef_defining =NULL;
20505 SgTemplateSymbolPtr = NULL;
20506 template_defining = NULL;
20507 SgEnumFieldSymbolPtr = NULL;
20508 templateInstantiate_defining =NULL;
20512 typedef_defining = node;
20514 function_decl =NULL;
20515 class_defining = NULL;
20516 SgMemFuncSymbolPtr = NULL;
20517 SgTypedefPtr = NULL;
20518 SgClassSymbolPtr = NULL;
20519 SgFunctionSymbolPtr = NULL;
20520 SgVariableSymbolPtr = NULL;
20521 SgTemplateSymbolPtr = NULL;
20522 template_defining = NULL;
20523 SgEnumFieldSymbolPtr = NULL;
20524 templateInstantiate_defining =NULL;
20528 templateInstantiate_defining =node;
20529 typedef_defining = NULL;
20531 function_decl =NULL;
20532 class_defining = NULL;
20533 SgMemFuncSymbolPtr = NULL;
20534 SgTypedefPtr = NULL;
20535 SgClassSymbolPtr = NULL;
20536 SgFunctionSymbolPtr = NULL;
20537 SgVariableSymbolPtr = NULL;
20538 SgTemplateSymbolPtr = NULL;
20539 template_defining = NULL;
20540 SgEnumFieldSymbolPtr = NULL;
20547 if(SgVariableSymbolPtr !=NULL)
20549 if(node->get_scope()!=NULL)
20555 if (isSgVariableSymbol(s) == SgVariableSymbolPtr) SgVariableSymbol_count++;
20560 if(SgEnumFieldSymbolPtr !=NULL)
20562 if(node->get_scope()!=NULL)
20568 if (isSgEnumFieldSymbol(s) == SgEnumFieldSymbolPtr) SgEnumFieldSymbol_count++;
20576 if(SgVariableSymbolPtr !=NULL){
20578 if (s == SgVariableSymbolPtr) SgVariableSymbol_count++;
20582 int get_num_variable_pointers(){
return SgVariableSymbol_count;}
20584 int get_num_EnumField_pointers(){
return SgEnumFieldSymbol_count;}
20589 if(SgFunctionSymbolPtr !=NULL){
20595 if ((
SgFunctionSymbol *)s == SgFunctionSymbolPtr) SgFunctionSymbol_count++;
20600 if(function_decl!=NULL){
20604 if(node!=function_decl && (define==function_decl || first_nondefine==function_decl))
delete node;
20613 printf (
"In visit(SgFunctionRefExp* node): SgFunctionSymbolPtr = %p \n",SgFunctionSymbolPtr);
20615 if (SgFunctionSymbolPtr !=NULL)
20618 if (isSgFunctionSymbol(s) == SgFunctionSymbolPtr)
20620 SgFunctionSymbol_count++;
20622 printf (
"Increment SgFunctionSymbol_count = %d \n",SgFunctionSymbol_count);
20632 printf (
"In visit(SgMemberFunctionRefExp* node): SgFunctionSymbolPtr = %p \n",SgFunctionSymbolPtr);
20634 if (SgFunctionSymbolPtr !=NULL)
20637 if (isSgFunctionSymbol(s) == SgFunctionSymbolPtr)
20639 SgFunctionSymbol_count++;
20641 printf (
"Increment SgFunctionSymbol_count = %d \n",SgFunctionSymbol_count);
20649 if (SgFunctionSymbolPtr !=NULL){
20651 if (isSgFunctionSymbol(s) == SgFunctionSymbolPtr) SgFunctionSymbol_count++;
20655 int get_num_Function_pointers(){
return SgFunctionSymbol_count;}
20660 if(SgClassSymbolPtr !=NULL){
20665 if (isSgClassSymbol(s) == SgClassSymbolPtr) SgClassDeclaration_count++;
20670 if(class_defining!=NULL) {
20674 if((class_decl==class_defining||class_decl1==class_defining) && node!=class_defining )
20682 if(SgClassSymbolPtr !=NULL){
20687 if (isSgClassSymbol(s) == SgClassSymbolPtr) SgClassDeclaration_count++;
20692 if(templateInstantiate_defining!=NULL) {
20699 if((template_decl==templateInstantiate_defining||template_decl1==templateInstantiate_defining) && node!=templateInstantiate_defining){
20719 if (SgClassSymbolPtr !=NULL){
20720 SgSymbol* s = node->get_class_symbol();
20721 if (s == SgClassSymbolPtr) SgClassDeclaration_count++;
20727 if (SgClassSymbolPtr !=NULL){
20729 if (isSgClassSymbol(s) == SgClassSymbolPtr) SgClassDeclaration_count++;
20734 int get_num_Class_pointers(){
return SgClassDeclaration_count;}
20740 if(memFunc !=NULL){
20742 if(func == memFunc){
20751 if (SgMemFuncSymbolPtr !=NULL){
20756 if(symbol == SgMemFuncSymbolPtr){
20757 SgMemFuncSymbol_count++;
20766 if (SgMemFuncSymbolPtr !=NULL){
20771 if(symbol == SgMemFuncSymbolPtr){
20772 SgMemFuncSymbol_count++;
20781 int get_num_memFunc_pointers(){
return SgMemFuncSymbol_count;}
20787 if(SgTypedefPtr!=NULL){
20796 if(typedef_defining!=NULL){
20798 if(typedef_define == typedef_defining && node != typedef_defining ) {
20804 int get_num_Typedef_pointers(){
return SgTypedefSymbol_count;}
20810 if (SgTemplateSymbolPtr !=NULL){
20815 if(symbol == SgTemplateSymbolPtr){
20816 SgTemplateSymbol_count++;
20822 if(template_defining !=NULL) {
20829 if((template_decl==template_defining||template_decl1==template_defining) && node!=template_defining) {
20839 int get_num_Template_pointers(){
return SgTemplateSymbol_count;}
20849 void visit (
SgNode* node)
20856 printf (
"In DeleteAST::visit(): node = %p = %s \n",node,node->
class_name().c_str());
20861 if (isSgScopeStatement(node) !=NULL)
20865 printf (
"Deleting the scopes type table: scope->get_type_table() = %p \n",scope->get_type_table());
20867 delete scope->get_type_table();
20873 if (isSgTypeTable(node) !=NULL)
20877 printf (
"Deleting the type table (SgSymbolTable): typeTable->get_type_table() = %p \n",typeTable->get_type_table());
20879 delete typeTable->get_type_table();
20882 if(isSgInitializedName(node) !=NULL){
20886 if(isSgVariableDefinition(var_def) !=NULL){
20893 if(isSgInitializedName(node)->get_scope()!=NULL){
20897 if(isSgVariableSymbol(symbol) !=NULL){
20899 traverseMemoryPoolVisitorPattern(visitor);
20900 if(visitor.get_num_variable_pointers()==1){
20907 if(isSgEnumFieldSymbol(symbol) !=NULL){
20909 traverseMemoryPoolVisitorPattern(visitor);
20910 if(visitor.get_num_EnumField_pointers()==1){
20921 if(isSgVarRefExp(node) !=NULL){
20923 ClassicVisitor visitor(symbol);
20924 traverseMemoryPoolVisitorPattern(visitor);
20925 if(visitor.get_num_variable_pointers()==1){
20937 SgFunctionDeclaration* funcDecl = isSgFunctionDeclaration(node);
20938 if (funcDecl != NULL){
20939 if (isSgMemberFunctionDeclaration(node) == NULL) {
20940 if (funcDecl->get_scope() != NULL) {
20941 if (funcDecl->get_scope()->get_symbol_table() != NULL) {
20942 SgSymbol* symbol = ((SgFunctionDeclaration*)node)->get_symbol_from_symbol_table();
20943 ClassicVisitor visitor((SgFunctionSymbol *)symbol);
20944 traverseMemoryPoolVisitorPattern(visitor);
20945 if (visitor.get_num_Function_pointers()==1) { //only one reference to this FunctionSymbol => safe to delete
20946 ((SgFunctionDeclaration*)node)->get_scope()->get_symbol_table()->remove(symbol);
20948 //printf("A SgFunctionSymbol was deleted\n");
20950 ClassicVisitor visitor1((SgFunctionDeclaration *)node);
20951 traverseMemoryPoolVisitorPattern(visitor1);
20958 if(isSgFunctionRefExp(node) !=NULL)
20961 SgFunctionRefExp* functionRefExp = isSgFunctionRefExp(node);
20962 ROSE_ASSERT(functionRefExp->get_symbol_i() != NULL);
20963 printf ("In DeleteAST::visit(): functionRefExp->get_symbol_i() = %p = %s \n",functionRefExp->get_symbol_i(),functionRefExp->get_symbol_i()->class_name().c_str());
20965 SgFunctionSymbol *symbol = ((SgFunctionRefExp*)node)->get_symbol_i();
20966 ClassicVisitor visitor(symbol);
20967 traverseMemoryPoolVisitorPattern(visitor);
20968 if(visitor.get_num_Function_pointers()==1)
20970 // only one reference to this FunctionSymbol => safe to delete
20971 //((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
20973 //printf("A SgFunctionSymbol was deleted\n");
20978 if(isSgUserDefinedBinaryOp(node) !=NULL){
20979 SgFunctionSymbol *symbol = ((SgUserDefinedBinaryOp*)node)->get_symbol();
20980 ClassicVisitor visitor(symbol);
20981 traverseMemoryPoolVisitorPattern(visitor);
20982 if(visitor.get_num_Function_pointers()==1){ //only one reference to this FunctionSymbol => safe to delete
20983 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
20985 //printf("A SgFunctionSymbol was deleted\n");
20993 if(isSgTypedefDeclaration(node) !=NULL){
20998 if(isSgTypedefSymbol(symbol)){
21000 traverseMemoryPoolVisitorPattern(visitor);
21001 if(visitor.get_num_Typedef_pointers()==1){
21012 traverseMemoryPoolVisitorPattern(visitor1);
21020 if(isSgNamespaceDeclarationStatement(node) !=NULL){
21021 if(((SgNamespaceDeclarationStatement*)node)->get_scope()!=NULL){
21022 if(((SgNamespaceDeclarationStatement*)node)->get_scope()->get_symbol_table()!=NULL)
21024 SgSymbol* symbol = ((SgNamespaceDeclarationStatement*)node)->get_symbol_from_symbol_table();
21025 if(isSgNamespaceSymbol(symbol)){
21026 ((SgNamespaceDeclarationStatement*)node)->get_scope()->get_symbol_table()->remove(symbol);
21028 //printf("A SgNamespaceSymbol was deleted\n");
21035 if(isSgNamespaceAliasDeclarationStatement(node) !=NULL){
21036 if(((SgNamespaceAliasDeclarationStatement*)node)->get_scope()!=NULL){
21037 if(((SgNamespaceAliasDeclarationStatement*)node)->get_scope()->get_symbol_table()!=NULL)
21039 SgSymbol* symbol = ((SgNamespaceAliasDeclarationStatement*)node)->get_symbol_from_symbol_table();
21040 if(isSgNamespaceSymbol(symbol)){
21041 ((SgNamespaceAliasDeclarationStatement*)node)->get_scope()->get_symbol_table()->remove(symbol);
21043 //printf("A SgNamespaceSymbol was deleted\n");
21054 if(isSgLabelStatement(node) !=NULL){
21059 if(isSgLabelSymbol(symbol)){
21068 if(isSgLabelRefExp(node) !=NULL){
21080 if(isSgEnumDeclaration(node) !=NULL){
21081 if(((SgEnumDeclaration*)node)->get_scope()!=NULL){
21082 if(((SgEnumDeclaration*)node)->get_scope()->get_symbol_table()!=NULL)
21084 SgSymbol* symbol = ((SgEnumDeclaration*)node)->get_symbol_from_symbol_table();
21085 if(isSgEnumSymbol(symbol) !=NULL){
21086 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21088 //printf("A SgEnumSymbol was deleted\n");
21092 SgEnumType* type= ((SgEnumDeclaration*)node)->get_type();
21095 //printf("A SgEnumType was deleted\n");
21104 if(isSgClassDeclaration(node) !=NULL && isSgTemplateInstantiationDecl(node) ==NULL){
21109 if(isSgClassSymbol(symbol) !=NULL){
21111 traverseMemoryPoolVisitorPattern(visitor);
21112 if(visitor.get_num_Class_pointers()==1){
21122 traverseMemoryPoolVisitorPattern(visitor);
21131 if(isSgThisExp(node) !=NULL){
21134 traverseMemoryPoolVisitorPattern(visitor);
21135 if(visitor.get_num_Class_pointers()==1){
21136 ((
SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21143 if(isSgClassNameRefExp(node) !=NULL){
21145 if(isSgClassSymbol(symbol) !=NULL)
21148 traverseMemoryPoolVisitorPattern(visitor);
21149 if(visitor.get_num_Class_pointers()==1){
21150 ((
SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21162 if(isSgMemberFunctionDeclaration(node) !=NULL){
21163 if(((SgMemberFunctionDeclaration*)node)->get_scope()!=NULL){
21164 if(((SgMemberFunctionDeclaration*)node)->get_scope()->get_symbol_table()!=NULL)
21166 SgSymbol* symbol = ((SgMemberFunctionDeclaration*)node)->get_symbol_from_symbol_table();
21167 if(isSgMemberFunctionSymbol(symbol)){
21168 ClassicVisitor visitor((SgMemberFunctionSymbol*)symbol);
21169 traverseMemoryPoolVisitorPattern(visitor);
21170 if(visitor.get_num_memFunc_pointers()==1){
21171 ((SgMemberFunctionDeclaration*)node)->get_scope()->get_symbol_table()->remove(symbol);
21173 //printf("A SgMemberFunctionSymbol was deleted\n");
21178 ClassicVisitor visitor((SgMemberFunctionDeclaration*) node);
21179 traverseMemoryPoolVisitorPattern(visitor);
21182//Tan: I have no idea why the codes below cannot work. Perhaps it conflicts with some prior works
21184 if(isSgMemberFunctionRefExp(node) !=NULL){
21185 SgMemberFunctionSymbol* symbol = ((SgMemberFunctionRefExp*)node)->get_symbol_i();
21186 ClassicVisitor visitor(symbol);
21187 traverseMemoryPoolVisitorPattern(visitor);
21188 if(visitor.get_num_memFunc_pointers()==1){ //only one reference to this symbol => safe to delete
21189 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21191 //printf("A SgClassSymbol was deleted\n");
21196 if(isSgFunctionType(node) !=NULL){
21197 SgSymbol* symbol = ((SgFunctionType*)node)->get_symbol_from_symbol_table();
21198 if(isSgFunctionTypeSymbol(symbol)){
21199 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21201 //printf("A SgFunctionTypeSymbol was deleted\n");
21210 if(isSgInterfaceStatement(node) !=NULL){
21215 if(isSgInterfaceSymbol(symbol)){
21226 if(isSgModuleStatement(node) !=NULL){
21231 if(isSgModuleSymbol(symbol)){
21244 if(isSgTemplateInstantiationMemberFunctionDecl(node) !=NULL){
21249 if(isSgMemberFunctionSymbol(symbol)){
21251 traverseMemoryPoolVisitorPattern(visitor);
21252 if(visitor.get_num_memFunc_pointers()==1){
21261 traverseMemoryPoolVisitorPattern(visitor);
21264 if(isSgTemplateDeclaration(node) !=NULL){
21270 traverseMemoryPoolVisitorPattern(visitor);
21271 if(visitor.get_num_Template_pointers()==1){
21274 printf(
"A SgTemplateSymbol was deleted\n");
21280 traverseMemoryPoolVisitorPattern(visitor1);
21285 if(isSgInterfaceStatement(node) !=NULL){
21290 if(isSgInterfaceSymbol(symbol)){
21301 if(isSgModuleStatement(node) !=NULL){
21306 if(isSgModuleSymbol(symbol)){
21316 if(isSgTemplateInstantiationDecl(node) !=NULL){
21321 if(isSgClassSymbol(symbol)){
21323 traverseMemoryPoolVisitorPattern(visitor);
21324 if(visitor.get_num_Class_pointers()==1){
21343 printf(
"SgTemplateArg in normal traversal\n");
21345 printf(
"SgTemplateInstantiationDecl in normal traversal\n");
21348 traverseMemoryPoolVisitorPattern(visitor);
21358 printf (
"After delete node: node = %p = %s \n",node,node->
class_name().c_str());
21364 DeleteAST deleteTree;
21367 deleteTree.traverse(n,postorder);
21370 printf (
"Leaving SageInterface::deleteAST(): n = %p = %s \n",n,n->
class_name().c_str());
21397 virtual void visit(
SgNode* n)
21400 if (expression != NULL)
21402 Visitor().traverse(expression->get_originalExpressionTree(), postorder);
21409 Visitor().traverse(root, postorder);
21421 SgSymbol* symbol = s_table->find(iname);
21422 ASSERT_not_null(symbol);
21427 ASSERT_not_null(sourceBlock);
21428 ASSERT_not_null(targetBlock);
21443 SgSymbol* symbol = s_table->find(iname);
21444 ASSERT_not_null(symbol);
21451 ASSERT_not_null(symbol);
21462 ASSERT_require(stmt->
get_parent() == targetBlock);
21477 func->set_scope(targetBlock);
21480 SgFunctionDeclaration* nondef_decl= isSgFunctionDeclaration(func->get_firstNondefiningDeclaration());
21481 if (func != nondef_decl)
21483 ASSERT_not_null(nondef_decl);
21490 else if (
auto labelStmt = isSgLabelStatement(stmt))
21492 if (labelStmt->get_scope() == sourceBlock) {
21493 labelStmt->set_scope(targetBlock);
21498 else if (isSgJovialTableStatement(stmt) || isSgTypedefDeclaration(stmt) || isSgEnumDeclaration(stmt))
21506 mlog[Rose::Diagnostics::WARN] <<
"test failing stmt->get_scope() == targetBlock in SageInterface::moveStatementsBetweenBlocks(): class: "
21513 if (declaration !=
nullptr)
21520 case V_SgVariableDeclaration:
21525 for (SgInitializedNamePtrList::iterator ii = l.begin(); ii != l.end(); ii++)
21535 SgType* var_type = init_name->get_type();
21538 var_type = mod_type->get_base_type();
21545 if (isSgEnumType(var_type))
21547 SgEnumType* enum_type = isSgEnumType(var_type);
21562 enumerator->set_scope(targetBlock);
21566 else if (isSgJovialTableType(var_type))
21582 SgVariableSymbol* var_sym = isSgVariableSymbol(init_name -> search_for_symbol_from_symbol_table ()) ;
21583 ASSERT_not_null(var_sym);
21586 if (old_scope != sourceBlock)
21588 old_scope->remove_symbol (var_sym);
21589 sourceBlock ->
insert_symbol(init_name->get_name(), var_sym);
21592 init_name->set_scope(targetBlock);
21593 initname_vec.push_back(init_name);
21597 case V_SgFunctionDeclaration:
21600 ASSERT_not_null(funcDecl);
21607 if (old_scope != sourceBlock)
21609 old_scope->remove_symbol (func_sym);
21617 case V_SgProgramHeaderStatement:
21618 case V_SgProcedureHeaderStatement:
21619 case V_SgClassDeclaration:
21620 case V_SgEnumDeclaration:
21623 ASSERT_not_null(nondef_decl);
21637 if (
auto proc = isSgProcedureHeaderStatement(nondef_decl)) {
21638 for (
auto arg : proc->get_parameterList()->get_args()) {
21639 if (arg->get_scope() != proc->get_scope()) {
21643 arg->set_scope(proc->get_scope());
21655 name->set_scope(targetBlock);
21660 case V_SgJovialTableStatement:
21664 ROSE_ASSERT (table);
21673 case V_SgTypedefDeclaration:
21677 ASSERT_not_null(typedef_decl);
21682 case V_SgAttributeSpecificationStatement:
21683 case V_SgEmptyDeclaration:
21684 case V_SgFortranIncludeLine:
21685 case V_SgImplicitStatement:
21686 case V_SgJovialDefineDeclaration:
21687 case V_SgJovialDirectiveStatement:
21688 case V_SgJovialLabelDeclaration:
21689 case V_SgJovialOverlayDeclaration:
21690 case V_SgPragmaDeclaration:
21691 case V_SgAdaAttributeClause:
21695 printf (
"Moving this declaration = %p = %s = %s between blocks is not yet supported \n",declaration,declaration->
class_name().c_str(),
SageInterface::get_name(declaration).c_str());
21704template <
class T1,
class T2>
21705void moveDeclarationsBetweenScopes( T1* sourceBlock, T2* targetBlock)
21709 ROSE_ASSERT (sourceBlock && targetBlock);
21710 ROSE_ASSERT (sourceBlock->containsOnlyDeclarations() && targetBlock->containsOnlyDeclarations());
21711 if ((
void*)sourceBlock == (
void*)targetBlock)
21713 cerr<<
"warning: SageInterface::moveStatementsBetweenScopes() is skipped, "<<endl;
21714 cerr<<
" since program is trying to move statements from and to the identical scoped block. "<<endl;
21718 SgDeclarationStatementPtrList& srcStmts = sourceBlock->get_declarations ();
21719 std::vector <SgInitializedName*> initname_vec;
21721 for (
auto stmt : srcStmts)
21723 moveOneStatement(sourceBlock, targetBlock, stmt, initname_vec);
21728 ROSE_ASSERT(srcStmts.empty() ==
true);
21729 ROSE_ASSERT(sourceBlock->get_declarations().empty() ==
true);
21732 moveSymbolTableBetweenBlocks(sourceBlock, targetBlock, initname_vec);
21745template <
class T1,
class T2>
21746void moveStatementsBetweenScopes( T1* sourceBlock, T2* targetBlock)
21749 ROSE_ASSERT (sourceBlock && targetBlock);
21750 if ((
void*)sourceBlock == (
void*)targetBlock)
21752 cerr<<
"warning: SageInterface::moveStatementsBetweenScopes() is skipped, "<<endl;
21753 cerr<<
" since program is trying to move statements from and to the identical scoped block. "<<endl;
21757 SgStatementPtrList & srcStmts = sourceBlock->get_statements();
21758 std::vector <SgInitializedName*> initname_vec;
21762 moveOneStatement(sourceBlock, targetBlock, stmt, initname_vec);
21767 ROSE_ASSERT(srcStmts.empty() ==
true);
21768 ROSE_ASSERT(sourceBlock->get_statements().empty() ==
true);
21771 moveSymbolTableBetweenBlocks(sourceBlock, targetBlock, initname_vec);
21785 ASSERT_not_null(decl);
21789 ASSERT_require(local_def && global_def && (local_def!=global_def));
21791 for (
auto symbol : local_def->get_symbol_table()->get_symbols())
21793 SgSymbol *orig_sym = isSgSymbol(symbol);
21794 ASSERT_not_null(orig_sym);
21803 moveDeclarationsBetweenScopes(sourceBlock, targetBlock);
21805 createAliasSymbols(isSgNamespaceDeclarationStatement(targetBlock->
get_parent()));
21810 moveStatementsBetweenScopes(sourceBlock, targetBlock);
21812 createAliasSymbols(isSgNamespaceDeclarationStatement(targetBlock->
get_parent()));
21817 moveDeclarationsBetweenScopes(sourceBlock, targetBlock);
21823 moveStatementsBetweenScopes (sourceBlock, targetBlock);
21831 ROSE_ASSERT (func != NULL);
21833 ROSE_ASSERT (p != NULL);
21835 if (le && le->get_lambda_function() == func)
21848 #pragma message ("WARNING: MSVC does not handle isLambdaCapturedVariable() properly.")
21850 ROSE_ASSERT (varRef!= NULL);
21854 SgThisExp* te = isSgThisExp(p->get_lhs_operand_i());
21858 ROSE_ASSERT (csym!= NULL);
21861 ROSE_ASSERT (xdecl != NULL);
21865 if (le->get_lambda_closure_class() == xdecl )
21881 ROSE_ASSERT(current != NULL);
21883 if (isSgInitializedName(current))
21885 name = isSgInitializedName(current);
21887 else if (isSgPntrArrRefExp(current) != NULL)
21891 ROSE_ASSERT(exp != NULL);
21893 ROSE_ASSERT(suc ==
true);
21897 else if (isSgVarRefExp(current) != NULL)
21903 if (isSgDotExp(parent))
21905 if (isSgDotExp(parent)->get_rhs_operand() == current)
21911 if (isSgArrowExp(parent)->get_rhs_operand() == current)
21915 name = isSgVarRefExp(current)->get_symbol()->get_declaration();
21917 else if (isSgFunctionRefExp(current) != NULL ||
21918 isSgTemplateFunctionRefExp(current) != NULL ||
21919 isSgMemberFunctionRefExp(current) != NULL ||
21920 isSgTemplateMemberFunctionRefExp(current) != NULL)
21925 else if (isSgNonrealRefExp(current) != NULL)
21930 else if (isSgDotExp(current))
21937 ROSE_ASSERT(child);
21941 else if (isSgArrowExp(current))
21962 ROSE_ASSERT(child);
21967 else if (isSgThisExp(current))
21972 else if (isSgPointerDerefExp(current))
21976 else if(isSgUnaryOp(current)) {
21979 else if (isSgCastExp(current))
21985 else if (isSgAddOp(current))
21990 else if (isSgSubtractOp(current))
22001 else if (isSgIntVal(current))
22011 if (!isSgConstructorInitializer(current))
22013 mlog[Sawyer::Message::Common::WARN] <<
22014 "convertRefToInitializedName: " <<
22017 cerr<<
"In SageInterface::convertRefToInitializedName(): unhandled reference type:"<<current->
class_name()<<endl;
22028#ifdef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22029 printf (
"AbstractHandle support is disabled for ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT \n");
22035 size_t pos = input_string.find(
"SourceFile<");
22036 ROSE_ASSERT (pos != string::npos);
22037 string trimed_string = input_string.substr(pos);
22041 if (handle->getNode()!=NULL)
22046#pragma message ("WARNING: covariant return type for get_node() not supported in MSVC.")
22047 printf (
"ERROR: covariant return type for get_node() not supported in MSVC. \n");
22070 ROSE_ASSERT(node != NULL);
22073 cout<<
"///////////// begin of SageInterface::dumpInfo() ///////////////"<<endl;
22074 cout<<
"--------------base info. for SgNode---------------"<<endl;
22080 cout<<
"--------------source location info. for SgNode---------------"<<endl;
22088 cout<<
"--------------preprocessing info. for SgNode---------------"<<endl;
22089 AttachedPreprocessingInfoType::iterator i;
22090 cout<<
"Total attached preprocessingInfo count="<<comments->size()<<endl;
22091 for (i = comments->begin (); i != comments->end (); i++)
22094 pinfo->display(
"");
22097 cout<<
"--------------name info. for SgNode---------------"<<endl;
22101 cout<<
"\tqualified name="<<decl->get_qualified_name().getString()<<endl;
22104 cout<<
"\treferenced variable name= "<<varRef->get_symbol()->
get_name().getString()<<endl;
22111 cout<<
"///////////// end of SageInterface::dumpInfo() ///////////////"<<endl;
22122 bool retVal =
true;
22124 ROSE_ASSERT(stmt !=NULL);
22126#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22133 if (funcDecl != NULL)
22136 if (funcDecl == NULL)
22138 cerr<<
"In collectReadWriteRefs(): cannot proceed without a function body!"<<endl;
22141 stmt = funcDecl->get_definition()->
get_body();
22149 ROSE_ASSERT(funcDef != NULL);
22151 ROSE_ASSERT(funcBody!= NULL);
22154 AstInterfaceImpl faImpl(funcBody);
22155 AstInterface fa(&faImpl);
22156 ArrayAnnotation* annot = ArrayAnnotation::get_inst();
22157 if( useCachedDefUse ){
22158 ArrayInterface* array_interface = ArrayInterface::get_inst(*annot, fa, funcDef, AstNodePtrImpl(funcDef));
22159 LoopTransformInterface::set_arrayInfo(array_interface);
22161 ArrayInterface array_interface(*annot);
22164 array_interface.observe(fa);
22165 LoopTransformInterface::set_arrayInfo(&array_interface);
22167 LoopTransformInterface::set_astInterface(fa);
22169 LoopTransformInterface::set_sideEffectInfo(annot);
22172 DoublyLinkedListWrap<AstNodePtr> rRef1, wRef1;
22173 CollectDoublyLinkedList<AstNodePtr> crRef1(rRef1),cwRef1(wRef1);
22174 AstNodePtr s1 = AstNodePtrImpl(stmt);
22177 if (!AnalyzeStmtRefs(fa, s1, cwRef1, crRef1))
22182 mlog[Sawyer::Message::Common::DEBUG] <<
"Function: " << funcDef->get_declaration()->get_qualified_name() <<
" calls at least one function that has not been annotated." << endl;
22187 for (DoublyLinkedEntryWrap<AstNodePtr>* p = rRef1.First(); p != 0; )
22189 DoublyLinkedEntryWrap<AstNodePtr>* p1 = p;
22191 AstNodePtr cur = p1->GetEntry();
22192 SgNode* sgRef = AstNodePtrImpl(cur).get_ptr();
22193 ROSE_ASSERT(sgRef != NULL);
22194 readRefs.push_back(sgRef);
22199 for (DoublyLinkedEntryWrap<AstNodePtr>* p = wRef1.First(); p != 0; )
22201 DoublyLinkedEntryWrap<AstNodePtr>* p1 = p;
22203 AstNodePtr cur = p1->GetEntry();
22204 SgNode* sgRef = AstNodePtrImpl(cur).get_ptr();
22205 ROSE_ASSERT(sgRef != NULL);
22206 writeRefs.push_back(sgRef);
22219static bool skipSomeRefs(
SgNode* n)
22222 return (isSgThisExp(n)||isSgArrowExp(n)||isSgDotExp(n));
22228 ROSE_ASSERT(stmt != NULL);
22229 vector <SgNode* > readRefs, writeRefs;
22233 vector<SgNode*>::iterator iter = readRefs.begin();
22234 for (; iter!=readRefs.end();iter++)
22236 SgNode* current = *iter;
22239 ROSE_ASSERT (current != NULL);
22242 if (!name)
continue;
22245 readVars.insert(name);
22248 vector<SgNode*>::iterator iterw = writeRefs.begin();
22249 for (; iterw!=writeRefs.end();iterw++)
22251 SgNode* current = *iterw;
22252 ROSE_ASSERT (current != NULL);
22254 if (!name)
continue;
22258 writeVars.insert(name);
22266 ROSE_ASSERT(stmt != NULL);
22267 set<SgInitializedName*> readVars, writeVars;
22272 set_difference(readVars.begin(), readVars.end(),
22273 writeVars.begin(), writeVars.end(),
22274 std::inserter(readOnlyVars, readOnlyVars.begin()));
22284 readOnlyVars.insert (v_ref->get_symbol()->get_declaration());
22294 set<SgInitializedName*> temp;
22297 for (set<SgInitializedName*>::const_iterator iter = temp.begin();
22298 iter!=temp.end(); iter++)
22300 SgSymbol* symbol = (*iter)->get_symbol_from_symbol_table () ;
22301 ROSE_ASSERT(symbol != NULL );
22302 ROSE_ASSERT(isSgVariableSymbol(symbol));
22303 readOnlySymbols.insert(isSgVariableSymbol(symbol));
22311 bool result =
false;
22312 ROSE_ASSERT(ref != NULL);
22324 ROSE_ASSERT(grandparent);
22325 if (isSgFunctionCallExp(grandparent))
22331 size_t param_index = 0;
22333 SgExpressionPtrList expList = isSgExprListExp(ref->
get_parent())->get_expressions();
22334 Rose_STL_Container<SgExpression*>::const_iterator iter= expList.begin();
22335 for (; iter!=expList.end(); iter++)
22343 SgExpression* func_exp = isSgFunctionCallExp(grandparent)->get_function();
22344 ROSE_ASSERT (func_exp);
22349 SgInitializedNamePtrList nameList = funcDecl->get_args();
22354 if (param_index >= nameList.size() ||isSgTypeEllipse(nameList[param_index]->get_type()) )
22356 if (isSgReferenceType(ref))
22360 if (isSgReferenceType(nameList[param_index]->get_type()))
22365 else if (isSgDotExp (func_exp) || isSgArrowExp(func_exp))
22368 ROSE_ASSERT (binOp);
22370 ROSE_ASSERT (mfuncRef);
22372 ROSE_ASSERT (mfuncDecl);
22373 SgInitializedNamePtrList nameList = mfuncDecl->get_args();
22375 if (isSgReferenceType(nameList[param_index]->get_type()))
22390 Rose_STL_Container <SgNode*> var_refs = NodeQuery::querySubTree (
const_cast<SgStatement *
> (s), V_SgVarRefExp);
22392 Rose_STL_Container<SgNode*>::iterator iter = var_refs.begin();
22393 for (; iter!=var_refs.end(); iter++)
22396 ROSE_ASSERT(ref != NULL);
22403 varSetB.insert(ref);
22409 ROSE_ASSERT(grandparent);
22410 if (isSgFunctionCallExp(grandparent))
22413 int param_index =0;
22414 SgExpressionPtrList expList = isSgExprListExp(ref->
get_parent())->get_expressions();
22415 Rose_STL_Container<SgExpression*>::const_iterator iter= expList.begin();
22416 for (; iter!=expList.end(); iter++)
22424 SgFunctionRefExp * funcRef = isSgFunctionRefExp(isSgFunctionCallExp(grandparent)->get_function());
22426 SgInitializedNamePtrList nameList = funcDecl->get_args();
22428 if (isSgReferenceType(nameList[param_index]->get_type()))
22430 varSetB.insert(ref);
22436 varSetB.insert(ref);
22440#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22445 static LivenessAnalysis* liv = NULL;
22449 static DFAnalysis * defuse = NULL;
22453 ROSE_ASSERT(project != NULL);
22454 defuse =
new DefUseAnalysis(project);
22457 ROSE_ASSERT(defuse != NULL);
22458 defuse->run(debug);
22461 defuse->dfaToDOT();
22464 liv =
new LivenessAnalysis(debug,(DefUseAnalysis*)defuse);
22465 ROSE_ASSERT(liv != NULL);
22467 std::vector <FilteredCFGNode < IsDFAFilter > > dfaFunctions;
22468 NodeQuerySynthesizedAttributeType vars =
22469 NodeQuery::querySubTree(project, V_SgFunctionDefinition);
22470 NodeQuerySynthesizedAttributeType::const_iterator i;
22471 bool abortme=
false;
22473 for (i= vars.begin(); i!=vars.end();++i)
22476 ROSE_ASSERT(func != NULL);
22480 string funcName = func->get_declaration()->get_qualified_name().str();
22481 cout<<
" .. running liveness analysis for function: " << funcName << endl;
22483 FilteredCFGNode <IsDFAFilter> rem_source = liv->run(func,abortme);
22485 liv->fixupStatementsINOUT(func);
22486 if (rem_source.getNode()!=NULL)
22487 dfaFunctions.push_back(rem_source);
22493 cout <<
"Writing out liveness analysis results into var.dot... " << endl;
22494 std::ofstream f2(
"var.dot");
22495 dfaToDot(f2,
string(
"var"), dfaFunctions, (DefUseAnalysis*)defuse, liv);
22499 cerr<<
"Error: Liveness analysis is ABORTING ." << endl;
22507#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22511 ROSE_ASSERT(liv != NULL);
22512 ROSE_ASSERT(loop != NULL);
22514 std::vector<SgInitializedName*> liveIns0, liveOuts0;
22524 CFGNode cfgnode(forstmt,2);
22525 FilteredCFGNode<IsDFAFilter> filternode= FilteredCFGNode<IsDFAFilter> (cfgnode);
22529 ROSE_ASSERT(filternode.getNode()==forstmt);
22532 vector<FilteredCFGEdge < IsDFAFilter > > out_edges = filternode.outEdges();
22533 ROSE_ASSERT(out_edges.size()==2);
22534 vector<FilteredCFGEdge < IsDFAFilter > >::iterator iter= out_edges.begin();
22536 for (; iter!=out_edges.end();iter++)
22538 FilteredCFGEdge < IsDFAFilter > edge= *iter;
22542 if (edge.condition()==eckTrue)
22544 SgNode* firstnode= edge.target().getNode();
22545 liveIns0 = liv->getIn(firstnode);
22547 for (std::vector<SgInitializedName*>::iterator iter = liveIns0.begin();
22548 iter!=liveIns0.end(); iter++)
22551 liveIns.insert(*iter);
22556 else if (edge.condition()==eckFalse)
22558 SgNode* firstnode= edge.target().getNode();
22559 liveOuts0 = liv->getIn(firstnode);
22561 for (std::vector<SgInitializedName*>::iterator iter = liveOuts0.begin();
22562 iter!=liveOuts0.end(); iter++)
22566 liveOuts.insert(*iter);
22571 cerr<<
"Unexpected CFG out edge type for SgForStmt!"<<endl;
22580static bool isAssignReduction (
SgVarRefExp* ref_exp1,
SgVarRefExp* ref_exp2, OmpSupport::omp_construct_enum& optype)
22582 bool isReduction =
false;
22584 ROSE_ASSERT (ref_exp1!= NULL);
22585 ROSE_ASSERT (ref_exp2!= NULL);
22586 ROSE_ASSERT (ref_exp1-> get_symbol() == ref_exp2-> get_symbol());
22592 if (stmt != stmt2)
return false;
22599 if (exp_stmt && isSgAssignOp(exp_stmt->get_expression()))
22602 assign_lhs = isSgAssignOp(exp_stmt->get_expression())->
get_lhs_operand();
22603 assign_rhs = isSgAssignOp(exp_stmt->get_expression())->
get_rhs_operand();
22604 ROSE_ASSERT(assign_lhs && assign_rhs);
22612 SgBinaryOp * binop = isSgBinaryOp(assign_rhs);
22618 if( !((op_lhs==ref_exp1)||(op_lhs==ref_exp2))
22619 && !((op_rhs==ref_exp1)||(op_rhs==ref_exp2)))
22622 bool isOnLeft =
false;
22623 if ((op_lhs==ref_exp1)||
22624 (op_lhs==ref_exp2))
22630 optype = OmpSupport::e_reduction_plus;
22631 isReduction =
true;
22634 case V_SgMultiplyOp:
22636 optype = OmpSupport::e_reduction_mul;
22637 isReduction =
true;
22640 case V_SgSubtractOp:
22642 optype = OmpSupport::e_reduction_minus;
22645 isReduction =
true;
22651 optype = OmpSupport::e_reduction_bitand ;
22652 isReduction =
true;
22657 optype = OmpSupport::e_reduction_bitxor;
22658 isReduction =
true;
22663 optype = OmpSupport::e_reduction_bitor;
22664 isReduction =
true;
22669 optype = OmpSupport::e_reduction_logand;
22670 isReduction =
true;
22675 optype = OmpSupport::e_reduction_logor;
22676 isReduction =
true;
22685 return isReduction;
22694 bool matchStmt1 =
false;
22695 bool matchStmt2 =
false;
22702 ROSE_ASSERT (ref1 != NULL);
22703 ROSE_ASSERT (ref2 != NULL);
22704 ROSE_ASSERT (ref1-> get_symbol() == ref2-> get_symbol());
22712 if (stmt1 == stmt2)
return false;
22735 bool matchBody =
false;
22736 bool matchCondition=
false;
22737 if (
SgIfStmt * if_stmt = isSgIfStmt (if_cond_stmt->get_parent()) )
22739 if (
SgStatement* body = if_stmt->get_true_body())
22744 ROSE_ASSERT(stmt2 != NULL);
22745 if ( ((block->get_statements()).size() == 1) && stmt2->
get_scope() == block )
22756 if (
SgExprStatement* cond_exp_stmt = isSgExprStatement (if_stmt->get_conditional()) )
22758 SgExpression* cond_exp = cond_exp_stmt->get_expression();
22759 if (
SgBinaryOp * binop = isSgBinaryOp (cond_exp))
22764 if (isSgLessThanOp (binop))
22766 optype = OmpSupport::e_reduction_max;
22767 matchCondition=
true;
22769 else if (isSgGreaterThanOp(binop))
22771 optype = OmpSupport::e_reduction_min;
22772 matchCondition=
true;
22778 if (isSgLessThanOp (binop))
22780 optype = OmpSupport::e_reduction_min;
22781 matchCondition=
true;
22783 else if (isSgGreaterThanOp(binop))
22785 optype = OmpSupport::e_reduction_max;
22786 matchCondition=
true;
22793 matchStmt1 = matchBody && matchCondition;
22797 return (matchStmt2 && matchStmt1);
22804static bool isSingleAppearanceReduction(
SgVarRefExp* ref1, OmpSupport::omp_construct_enum& optype )
22806 bool isReduction =
false;
22808 ROSE_ASSERT (ref1 != NULL);
22814 if (isSgExprStatement(stmt))
22816 SgExpression* exp = isSgExprStatement(stmt)->get_expression();
22818 if (isSgPlusPlusOp(exp))
22821 optype = OmpSupport::e_reduction_plus;
22822 isReduction =
true;
22824 else if (isSgMinusMinusOp(exp))
22826 optype = OmpSupport::e_reduction_minus;
22827 isReduction =
true;
22838 case V_SgPlusAssignOp:
22840 optype = OmpSupport::e_reduction_plus;
22841 isReduction =
true;
22844 case V_SgMultAssignOp:
22846 optype = OmpSupport::e_reduction_mul;
22847 isReduction =
true;
22850 case V_SgMinusAssignOp:
22852 optype = OmpSupport::e_reduction_minus;
22853 isReduction =
true;
22856 case V_SgAndAssignOp:
22858 optype = OmpSupport::e_reduction_bitand;
22859 isReduction =
true;
22862 case V_SgXorAssignOp:
22864 optype = OmpSupport::e_reduction_bitxor;
22865 isReduction =
true;
22868 case V_SgIorAssignOp:
22870 optype = OmpSupport::e_reduction_bitor;
22871 isReduction =
true;
22880 return isReduction;
22912 std::set<SgInitializedName*> candidateVars;
22914 std::map <SgInitializedName*, vector<SgVarRefExp* > > var_references;
22916 Rose_STL_Container<SgNode*> reflist = NodeQuery::querySubTree(loop, V_SgVarRefExp);
22918 ROSE_ASSERT(lbody != NULL);
22919 Rose_STL_Container<SgNode*>::iterator iter = reflist.begin();
22920 for (; iter!=reflist.end(); iter++)
22929 ROSE_ASSERT(var_scope != NULL);
22930 if ((
isScalarType(initname->get_type())) &&(initname !=loopindex)
22933 candidateVars.insert(initname);
22934 var_references[initname].push_back(ref_exp);
22939 std::set<SgInitializedName*>::iterator niter=candidateVars.begin();
22940 for (; niter!=candidateVars.end(); niter++)
22943 bool isReduction =
false;
22944 OmpSupport::omp_construct_enum optype;
22946 if (var_references[initname].size()==1)
22948 mlog[Sawyer::Message::Common::DEBUG] <<
"Debug: SageInterface::ReductionRecognition() A candidate used once:"<<initname->get_name().getString()<<endl;
22949 SgVarRefExp* ref_exp = *(var_references[initname].begin());
22950 if (isSingleAppearanceReduction (ref_exp, optype))
22951 isReduction =
true;
22954 else if (var_references[initname].size()==2)
22956 mlog[Sawyer::Message::Common::DEBUG] <<
"Debug: A candidate used twice:"<<initname->get_name().getString()<<endl;
22957 SgVarRefExp* ref_exp1 = *(var_references[initname].begin());
22958 SgVarRefExp* ref_exp2 = *(++var_references[initname].begin());
22961 if (isAssignReduction (ref_exp1, ref_exp2, optype) || isIfReduction (ref_exp1, ref_exp2, optype) )
22963 isReduction =
true;
22969 results.insert(make_pair(initname,optype));
22976 ROSE_ASSERT(r!=NULL);
22977#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22978 ConstantFolding::constantFoldingOptimization(r,
false);
22988 virtual void visit (
SgNode * n)
22995 ROSE_ASSERT (name_attribute != NULL);
23003 exampleTraversal.
traverse(project, preorder);
23035 const SgInitializedNamePtrList& orig_decls = params.
get_args();
23037 std::transform( orig_decls.begin(), orig_decls.end(), sg::sage_inserter(copy), sg::InitNameCloner(copy, fundef) );
23051 sg::swap_child(ll, rr, &SgFunctionDeclaration::get_definition, &SgFunctionDeclaration::set_definition);
23052 sg::swap_child(ll, rr, &SgFunctionDeclaration::get_parameterList, &SgFunctionDeclaration::set_parameterList);
23062 std::pair<SgStatement*, SgInitializedName*>
23076 SgType* result_type = definingDeclaration.get_type()->get_return_type();
23081 SgFunctionDeclaration* wrapperfn = SB::buildDefiningFunctionDeclaration(newName, result_type, ¶m_list, containing_scope);
23084 ROSE_ASSERT(wrapperdef);
23087 wrapperfn->set_exceptionSpecification(definingDeclaration.get_exceptionSpecification());
23091 swapDefiningElements(definingDeclaration, *wrapperfn);
23096 SgInitializedNamePtrList& param_decls = param_list.
get_args();
23098 std::transform( param_decls.begin(), param_decls.end(), sg::sage_inserter(*args), sg::VarRefBuilder(*wrapperdef) );
23100 SgFunctionCallExp* callWrapped = SB::buildFunctionCallExp( newName, result_type, args, body );
23105 if (!isSgTypeVoid(result_type))
23108 SgVariableDeclaration* res = SB::buildVariableDeclaration(
"res", result_type, SB::buildAssignInitializer(callWrapped), body );
23115 callStatement = res;
23122 callStatement = SB::buildExprStatement(callWrapped);
23126 ROSE_ASSERT(callStatement);
23130 SgFunctionDeclaration* wrapperfn_proto = SB::buildNondefiningFunctionDeclaration(wrapperfn, containing_scope, decorator_proto);
23136 return std::make_pair(callStatement, resultName);
23144 struct VarrefBuilder
23163 template <
class AstNode>
23164 struct VarrefCreator : VarrefBuilder
23169 VarrefCreator(AstNode& orig)
23173 SgVarRefExp*
get()
const {
return VarrefBuilder::build(origin); }
23176 template <
class AstNode>
23177 VarrefCreator<AstNode>
23178 varrefCreator(AstNode& n)
23180 return VarrefCreator<AstNode>(n);
23190 return SB::buildMultiplyOp(lhs, SI::deepCopy(rhs));
23193 std::pair<std::vector<SgExpression*>,
SgType*>
23194 get_C_array_dimensions_aux(
const SgArrayType& arr_type)
23200 std::vector<SgExpression*> indices;
23201 SgType* undertype = NULL;
23205 if (arrtype->get_index() == NULL)
23207 indices.push_back(SB::buildNullExpression());
23208 undertype = arrtype->get_base_type();
23209 arrtype = isSgArrayType(undertype);
23215 ROSE_ASSERT(indexexpr);
23217 indices.push_back(SI::deepCopy(indexexpr));
23218 undertype = arrtype->get_base_type();
23219 arrtype = isSgArrayType(undertype);
23222 ROSE_ASSERT((!indices.empty()) && undertype);
23223 return std::make_pair(indices, undertype);
23227 std::vector<SgExpression*>
23228 get_C_array_dimensions_aux(
const SgArrayType& arrtype,
const VarrefBuilder& varrefBuilder)
23232 std::pair<std::vector<SgExpression*>,
SgType*> res = get_C_array_dimensions_aux(arrtype);
23233 const std::vector<SgExpression*>::iterator first = res.first.begin();
23236 if (isSgNullExpression(*first))
23244 const std::vector<SgExpression*>::iterator aa = first+1;
23245 const std::vector<SgExpression*>::iterator zz = res.first.end();
23247 SgExpression* sz_undertype = SB::buildSizeOfOp(res.second);
23248 SgExpression* denominator = std::accumulate(aa, zz, sz_undertype, create_mulop);
23249 SgSizeOfOp* sz_var = SB::buildSizeOfOp(varrefBuilder.get());
23250 SgExpression* sz = SB::buildDivideOp(sz_var, denominator);
23252 std::swap(*first, sz);
23260 std::vector<SgExpression*>
23263 return get_C_array_dimensions_aux(arrtype).first;
23266 std::vector<SgExpression*>
23269 return get_C_array_dimensions_aux(arrtype, varrefCreator(varref));
23272 std::vector<SgExpression*>
23275 return get_C_array_dimensions_aux(arrtype, varrefCreator(initname));
23282 set<unsigned int> sourceSequenceSet;
23284 void visit (
SgNode* astNode );
23292 if (fileInfo != NULL)
23294 unsigned int source_sequence_number = fileInfo->get_source_sequence_number();
23296 printf (
"In CollectSourceSequenceNumbers::visit(): source_sequence_number = %" PRIuPTR
" \n",source_sequence_number);
23298 sourceSequenceSet.insert(source_sequence_number);
23308 traversal.
traverse(astNode,preorder);
23310 return traversal.sourceSequenceSet;
23397#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
23399 if (collapsing_factor <= 1)
23412 ROSE_ASSERT (global_scope != NULL);
23421 bool *isPlus =
new bool[collapsing_factor];
23425 std::vector<SgForStatement* > loops= SageInterface::querySubTree<SgForStatement>(target_loop,V_SgForStatement);
23426 ROSE_ASSERT(loops.size()>=collapsing_factor);
23442 ROSE_ASSERT(
getScope(target_loop)->get_parent()!= NULL);
23446 while(scope == NULL)
23448 parent = isSgStatement(parent->
get_parent());
23449 scope = isSgScopeStatement(parent);
23453 if (insert_target != NULL)
23458 ROSE_ASSERT(scope != NULL);
23461 for(
size_t i = 0; i < collapsing_factor; i ++)
23463 temp_target_loop = loops[i];
23468 if (!
isCanonicalForLoop(temp_target_loop, &ivar[i], &lb[i], &ub[i], &step[i], &orig_body[i], &isPlus[i]))
23470 cerr<<
"Error in SageInterface::loopCollapsing(): target loop is not canonical."<<endl;
23478 delete[] orig_body;
23479 delete[] total_iters;
23486 ROSE_ASSERT(ivar[i]&& lb[i] && ub[i] && step[i]);
23490 if(isPlus[i] ==
true)
23504 string iter_var_name=
"_total_iters";
23525 new_var_list->append_expression(isSgVarRefExp(ub_exp));
23528 for(
unsigned int i = 0; i < collapsing_factor; i++)
23531 for(
unsigned int j = collapsing_factor - 1; j > i; j--)
23540 new_var_list->append_expression(isSgVarRefExp(interval[i]));
23550 ROSE_ASSERT(insert_target != NULL);
23555 new_var_list->append_expression(clps_index_ref);
23561 ROSE_ASSERT(body != NULL);
23564 std::vector<SgStatement*> new_stmt_list;
23575 for(
unsigned int i = 0; i < collapsing_factor - 1; i ++)
23577 if(isPlus[i] ==
true)
23583 new_stmt_list.push_back(assign_stmt);
23586 if(i != collapsing_factor - 2){
23587 string remain_var_name=
"_remainder";
23588 remain_var_name =
"__"+ ivar[i]->get_name().getString() + remain_var_name;
23591 new_stmt_list.push_back(loop_index_decl);
23597 if(isPlus[collapsing_factor - 1] ==
true)
23601 new_stmt_list.push_back(assign_stmt);
23613 ROSE_ASSERT(cond_stmt != NULL);
23620 target_loop = new_loop;
23622 ConstantFolding::constantFoldingOptimization(scope->
get_parent(),
false);
23628 delete [] orig_body;
23629 delete [] total_iters;
23630 delete [] interval;
23635 return new_var_list;
23654 RoseAst ast_of_original(tree2);
23663 while (i_copy != ast_of_copy.
end())
23666 printf (
"*i_copy = %p = %s \n",*i_copy,(*i_copy)->class_name().c_str());
23667 printf (
"*i_original = %p = %s \n",*i_original,(*i_original)->class_name().c_str());
23671 if ((*i_copy)->variantT() != (*i_original)->variantT())
23674 printf (
"ERROR: return from SageInterface::isStructurallyEquivalentAST(): (*i_copy)->variantT() != (*i_original)->variantT() \n");
23677 printf (
"Making this an error! \n");
23687 ROSE_ASSERT(i_original != ast_of_original.
end());
23692 ROSE_ASSERT(i_copy == ast_of_copy.
end() && i_original == ast_of_original.
end());
23712 lower_bound = NULL;
23713 upper_bound = NULL;
23717 const std::vector<SgStatement *> & init_stmts = for_init_stmt->
get_init_stmt();
23718 assert(init_stmts.size() == 1);
23720 assert(init_stmt != NULL);
23723 SgAssignOp * assign_init = isSgAssignOp(init);
23724 assert(assign_init != NULL);
23726 assert(iterator_init_ref != NULL);
23727 iterator = iterator_init_ref->get_symbol();
23728 assert(iterator != NULL);
23731 SgExprStatement * test_stmt = isSgExprStatement(for_loop->get_test());
23732 assert(test_stmt != NULL);
23738 while (isSgCastExp(lhs_exp)) lhs_exp = ((
SgCastExp *)lhs_exp)->get_operand_i();
23739 SgVarRefExp * lhs_var_ref = isSgVarRefExp(lhs_exp);
23740 bool lhs_it = (lhs_var_ref != NULL) && (lhs_var_ref->get_symbol() == iterator);
23743 while (isSgCastExp(rhs_exp)) rhs_exp = ((
SgCastExp *)rhs_exp)->get_operand_i();
23744 SgVarRefExp * rhs_var_ref = isSgVarRefExp(rhs_exp);
23746 bool rhs_it = (rhs_var_ref != NULL) && (rhs_var_ref->get_symbol() == iterator);
23754 assert(lhs_it != rhs_it);
23763 case V_SgGreaterOrEqualOp:
23764 inclusive = lhs_it;
23767 case V_SgGreaterThanOp:
23768 inclusive = !lhs_it;
23771 case V_SgLessOrEqualOp:
23772 inclusive = lhs_it;
23773 reversed = !lhs_it;
23775 case V_SgLessThanOp:
23776 inclusive = !lhs_it;
23777 reversed = !lhs_it;
23779 case V_SgEqualityOp:
23780 case V_SgNotEqualOp:
23786 switch (increment->variantT()) {
23787 case V_SgPlusPlusOp:
23791 case V_SgMinusMinusOp:
23795 case V_SgPlusAssignOp:
23800 assert(var_ref_lhs != NULL && var_ref_lhs->get_symbol() == iterator);
23805 case V_SgMinusAssignOp:
23810 assert(var_ref_lhs != NULL && var_ref_lhs->get_symbol() == iterator);
23820 assert(inc_assign_lhs != NULL && inc_assign_lhs->get_symbol() == iterator);
23823 assert(inc_assign_rhs != NULL);
23825 if (inc_assign_rhs_lhs != NULL && inc_assign_rhs_lhs->get_symbol() == iterator)
23828 if (inc_assign_rhs_rhs != NULL && inc_assign_rhs_rhs->get_symbol() == iterator)
23849#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
23856 jstring temp_directory = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(::currentJavaTraversalClass, Rose::Frontend::Java::Ecj::getTempDirectoryMethod);
23858 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_directory, NULL);
23860 string directory_name = utf8;
23861 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_directory, utf8);
23863 list<string> sourcepath = project -> get_Java_sourcepath();
23864 sourcepath.push_back(directory_name);
23865 project -> set_Java_sourcepath(sourcepath);
23867 return directory_name;
23875 string command = string(
"rm -fr ") + directory_name;
23876 int status = system(command.c_str());
23877 ROSE_ASSERT(status == 0);
23888 project -> get_sourceFileNameList().push_back(filename);
23889 Rose_STL_Container<std::string> arg_list = project -> get_originalCommandLineArgumentList();
23890 arg_list.push_back(filename);
23893 int error_code = 0;
23894 SgFile *file = determineFileType(arg_list, error_code, project);
23896 ROSE_ASSERT(sourcefile);
23897 sourcefile -> set_parent(project);
23902 project -> get_fileList_ptr() -> get_listOfFiles().push_back(sourcefile);
23903 ROSE_ASSERT(sourcefile == isSgSourceFile((*project)[filename]));
23905 sourcefile -> build_Java_AST(arg_list, project -> get_originalCommandLineArgumentList());
23908 project -> get_fileList_ptr() -> get_listOfFiles().pop_back();
23909 ROSE_ASSERT(sourcefile != isSgSourceFile((*project)[filename]));
23913 ROSE_ASSERT(file->get_preprocessorDirectivesAndCommentsList() != NULL);
23924 string command =
"package " + package_name +
";";
23929 jstring temp_file = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
23930 Rose::Frontend::Java::Ecj::createTempFileMethod,
23931 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(command.c_str()));
23933 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_file, NULL);
23935 string filename = (string) utf8;
23936 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_file, utf8);
23940 return package_name;
23949 string command =
"import " + import_string +
";";
23954 jstring temp_file = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
23955 Rose::Frontend::Java::Ecj::createTempFileMethod,
23956 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(command.c_str()));
23958 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_file, NULL);
23960 string filename = (string) utf8;
23961 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_file, utf8);
23965 return import_string;
23977 jstring temp_file = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
23978 Rose::Frontend::Java::Ecj::createTempNamedFileMethod,
23979 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(file_name.c_str()),
23980 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(file_content.c_str()));
23982 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_file, NULL);
23984 string filename = (string) utf8;
23985 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_file, utf8);
23995 ROSE_ASSERT(scope);
23997 for (
int index = 0, length = package_name.size(); index < length; index++) {
23999 for (n = index; n < length; n++) {
24000 if (package_name[n] ==
'.') {
24004 string name = package_name.substr(index, n - index);
24006 SgClassSymbol *package_symbol = scope -> lookup_class_symbol(name);
24007 if (package_symbol == NULL) {
24011 SgJavaPackageDeclaration *package_declaration = isSgJavaPackageDeclaration(package_symbol -> get_declaration() -> get_definingDeclaration());
24012 ROSE_ASSERT(package_declaration);
24013 package_definition = package_declaration -> get_definition();
24014 ROSE_ASSERT(package_definition);
24015 scope = package_definition;
24020 return package_definition;
24028 SgGlobal *global_scope = project -> get_globalScopeAcrossFiles();
24030 if (package_definition == NULL) {
24036 if (create_directory) {
24037 Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
24038 Rose::Frontend::Java::Ecj::createTempNamedDirectoryMethod,
24039 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(package_name.c_str()));
24045 return package_definition;
24052 ROSE_ASSERT(package_definition);
24053 SgClassSymbol *class_symbol = package_definition -> lookup_class_symbol(class_name);
24056 : isSgClassDeclaration(class_symbol -> get_declaration() -> get_definingDeclaration()));
24057 if ((! class_declaration) || (! class_declaration -> attributeExists(
"complete"))) {
24058 string qualified_name = package_definition -> get_qualified_name().getString() +
"." + class_name;
24060 class_symbol = package_definition -> lookup_class_symbol(class_name);
24063 class_declaration = (class_symbol == NULL
24065 : isSgClassDeclaration(class_symbol -> get_declaration() -> get_definingDeclaration()));
24067 return class_declaration;
24083 SgClassDeclaration *class_declaration = isSgClassDeclaration(class_type -> get_declaration() -> get_definingDeclaration());
24084 ROSE_ASSERT(class_declaration);
24085 SgClassDefinition *scope = isSgClassDefinition(class_declaration -> get_scope());
24086 while (scope && (! isSgJavaPackageDeclaration(scope -> get_parent()))) {
24087 class_declaration = isSgClassDeclaration(scope -> get_parent());
24088 ROSE_ASSERT(class_declaration);
24089 scope = isSgClassDefinition(class_declaration -> get_scope());
24096 string class_name = class_declaration ->
get_name().getString();
24105 ROSE_ASSERT(class_definition);
24107 ROSE_ASSERT(type_list);
24109 ROSE_ASSERT(string_array_type);
24110 type_list -> append_argument(string_array_type);
24116 SgFunctionSymbol *method_symbol = class_definition -> lookup_function_symbol(
"main", member_function_type);
24118 return (method_symbol == NULL ? NULL : isSgMemberFunctionDeclaration(method_symbol -> get_declaration()));
24126 SgClassDeclaration *class_declaration = isSgClassDeclaration(class_type -> get_declaration() -> get_definingDeclaration());
24127 ROSE_ASSERT(class_declaration);
24140 ROSE_ASSERT (old_sym != NULL);
24141 ROSE_ASSERT (new_sym != NULL);
24142 ROSE_ASSERT (old_sym != new_sym);
24143 ROSE_ASSERT (scope != NULL);
24145 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(scope, V_SgVarRefExp);
24146 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
24149 if (vRef->get_symbol() == old_sym)
24150 vRef->set_symbol(new_sym);
24163 bool result =
true;
24165 bool includingSelf =
false;
24168 if (sourceFile == NULL)
24170 printf (
"In SageInterface::statementCanBeTransformed(): sourceFile not found \n");
24174 ROSE_ASSERT(sourceFile != NULL);
24176 if (sourceFile != NULL && sourceFile->get_unparse_tokens() ==
true && sourceFile->get_unparseHeaderFiles() ==
true)
24180 string source_filename = stmt->getFilenameString();
24182 printf (
"In SageInterface::statementCanBeTransformed(): source_filename = %s \n",source_filename.c_str());
24183 printf (
" --- Rose::includeFileMapForUnparsing.size() = %zu \n",Rose::includeFileMapForUnparsing.size());
24187 if (EDG_ROSE_Translation::edg_include_file_map.find(source_filename) != EDG_ROSE_Translation::edg_include_file_map.end())
24189 SgIncludeFile* include_file = EDG_ROSE_Translation::edg_include_file_map[source_filename];
24190 ROSE_ASSERT(include_file != NULL);
24192 printf (
"include_file->get_can_be_supported_using_token_based_unparsing() = %s \n",include_file->get_can_be_supported_using_token_based_unparsing() ?
"true" :
"false");
24194 if (include_file->get_can_be_supported_using_token_based_unparsing() ==
false)
24197 printf (
"NOTE: Transformations of this statement cannot be supported using the header file unparsing with token unparsing options! \n");
24207 printf (
"Not found in Rose::includeFileMapForUnparsing: source_filename = %s \n",source_filename.c_str());
24210 printf (
"Exiting as a test! \n");
24216 printf (
"Error: In statementCanBeTransformed(): this might be an issue! \n");
24229 ROSE_ASSERT (decl!= NULL);
24230 ROSE_ASSERT (target_scope != NULL);
24231 ROSE_ASSERT (target_scope != decl->
get_scope());
24238 if (isSgIfStmt (target_scope))
24241 if (target_scope == )
24251 case V_SgBasicBlock:
24263 case V_SgForStatement:
24267 ROSE_ASSERT(stmt != NULL);
24268 SgStatementPtrList& stmt_list = stmt->get_init_stmt();
24272 if (stmt_list.size() !=1)
24274 cerr<<
"Error in moveVariableDeclaration(): only single init statement is handled for SgForStatement now."<<endl;
24275 ROSE_ASSERT (stmt_list.size() ==1);
24278 ROSE_ASSERT (exp_stmt != NULL);
24279 SgAssignOp* assign_op = isSgAssignOp(exp_stmt->get_expression());
24280 ROSE_ASSERT (assign_op != NULL);
24290 if (init_name->get_initptr() != NULL)
24292 init_name->set_initptr(initor);
24295 stmt_list.insert (stmt_list.begin(), decl );
24301 cerr<<
"Error. Unhandled target scope type:"<<target_scope->
class_name()<<endl;
24302 ROSE_ASSERT (
false);
24308 ROSE_ASSERT(sym != NULL);
24310 if (orig_scope != target_scope)
24315 init_name->set_scope(target_scope);
24317 orig_scope->remove_symbol(sym);
24322 ROSE_ASSERT (target_scope->symbol_exists(sym));
24332 subtreeVal.hasValue_ =
true;
24334 if (isSgIntVal(valExp)) {
24335 subtreeVal.value_ = isSgIntVal(valExp)->get_value();
24336 }
else if (isSgLongIntVal(valExp)) {
24337 subtreeVal.value_ = isSgLongIntVal(valExp)->get_value();
24338 }
else if (isSgLongLongIntVal(valExp)) {
24339 subtreeVal.value_ = isSgLongLongIntVal(valExp)->get_value();
24340 }
else if (isSgShortVal(valExp)) {
24341 subtreeVal.value_ = isSgShortVal(valExp)->get_value();
24342 }
else if (isSgUnsignedIntVal(valExp)) {
24343 subtreeVal.value_ = isSgUnsignedIntVal(valExp)->get_value();
24344 }
else if (isSgUnsignedLongVal(valExp)) {
24345 subtreeVal.value_ = isSgUnsignedLongVal(valExp)->get_value();
24346 }
else if (isSgUnsignedLongLongIntVal(valExp)) {
24347 subtreeVal.value_ = isSgUnsignedLongLongIntVal(valExp)->get_value();
24348 }
else if (isSgUnsignedShortVal(valExp)) {
24349 subtreeVal.value_ = isSgUnsignedShortVal(valExp)->get_value();
24355 if (isSgModifierType(vRef->get_type()) == NULL) {
24358 val.hasValue_ =
false;
24361 if (isSgModifierType(vRef->get_type())->
get_typeModifier().get_constVolatileModifier().isConst()) {
24367 if (isSgAssignInitializer(ini)) {
24372 return variableEval.
traverse(rhs);
24376 val.hasValue_ =
false;
24382 if (isSgExpression(node) != NULL) {
24384 if (valueExp != NULL) {
24385 return this->getValueExpressionValue(valueExp);
24389 if (varRefExp != NULL) {
24391 return evaluateVariableReference(varRefExp);
24394 if (isSgAssignInitializer(node)) {
24395 if(synList.at(0).hasValue_){
24396 return synList.at(0);
24400 val.hasValue_ =
false;
24405 evaluatedValue.hasValue_ =
false;
24406 evaluatedValue.value_ = -1;
24408 if(synList.size() != 2){
24409 for(SynthesizedAttributesList::iterator it = synList.begin(); it != synList.end(); ++it){
24410 std::cout <<
"Node: " << node->unparseToString() <<
"\n" << (*it).value_ << std::endl;
24411 std::cout <<
"Parent: " << node->get_parent()->unparseToString() << std::endl;
24412 std::cout <<
"Parent, Parent: " << node->get_parent()->get_parent()->unparseToString() << std::endl;
24416 for (SynthesizedAttributesList::iterator it = synList.begin(); it != synList.end(); ++it) {
24417 if((*it).hasValue_){
24418 if (isSgAddOp(node)) {
24419 assert(synList.size() == 2);
24420 evaluatedValue.value_ = synList[0].value_ + synList[1].value_ ;
24421 evaluatedValue.hasValue_ =
true;
24422 }
else if (isSgSubtractOp(node)) {
24423 assert(synList.size() == 2);
24424 evaluatedValue.value_ = synList[0].value_ - synList[1].value_ ;
24425 evaluatedValue.hasValue_ =
true;
24426 }
else if (isSgMultiplyOp(node)) {
24427 assert(synList.size() == 2);
24428 evaluatedValue.value_ = synList[0].value_ * synList[1].value_ ;
24429 evaluatedValue.hasValue_ =
true;
24430 }
else if (isSgDivideOp(node)) {
24431 assert(synList.size() == 2);
24432 evaluatedValue.value_ = synList[0].value_ / synList[1].value_ ;
24433 evaluatedValue.hasValue_ =
true;
24434 }
else if (isSgModOp(node)) {
24435 assert(synList.size() == 2);
24436 evaluatedValue.value_ = synList[0].value_ % synList[1].value_ ;
24437 evaluatedValue.hasValue_ =
true;
24440 std::cerr <<
"Expression is not evaluatable" << std::endl;
24441 evaluatedValue.hasValue_ =
false;
24442 evaluatedValue.value_ = -1;
24443 return evaluatedValue;
24446 evaluatedValue.hasValue_ =
true;
24447 return evaluatedValue;
24450 evaluatedValue.hasValue_ =
false;
24451 evaluatedValue.value_ = -1;
24452 return evaluatedValue;
24465 class TypeEquivalenceChecker {
24467 TypeEquivalenceChecker(
bool profile,
bool useSemanticEquivalence)
24468 : profile_(profile), useSemanticEquivalence_(useSemanticEquivalence),
24469 namedType_(0), pointerType_(0), arrayType_(0), functionType_(0)
24475 if (isSgTypedefType(t)) {
24477 node = isSgTypedefType(t)->
stripType(SgType::STRIP_TYPEDEF_TYPE);
24479 if(useSemanticEquivalence_){
24480 if(isSgModifierType(t)){
24482 ROSE_ASSERT(modType != NULL);
24489 std::cout <<
"Hit volatile type, stripping of modifier type" << std::endl;
24490 node = modType->get_base_type();
24494 std::cout <<
"Hit restrict type, stripping of modifier type" << std::endl;
24495 node = modType->get_base_type();
24499 ROSE_ASSERT(node != NULL);
24504 bool equal =
false;
24505 if(t1 == NULL || t2 == NULL){
24506 std::string wasNull;
24512 std::cerr <<
"ERROR: " << wasNull <<
" was NULL" << std::endl;
24525 i != subT1.
end() && j != subT2.
end(); ++i, ++j) {
24530 nodeT1 = getBasetypeIfApplicable(nodeT1);
24531 nodeT2 = getBasetypeIfApplicable(nodeT2);
24535 if(isSgModifierType(nodeT1)){
24539 if(modT1.get_constVolatileModifier().isConst() != modT2.get_constVolatileModifier().isConst()){
24542 if(modT1.get_constVolatileModifier().isVolatile() != modT2.get_constVolatileModifier().isVolatile()){
24545 }
else if (isSgNamedType(nodeT1)) {
24549 i.skipChildrenOnForward();
24550 j.skipChildrenOnForward();
24556 if(!c1->get_autonomous_declaration()){
24559 if (!c2->get_autonomous_declaration()){
24568 }
else if (isSgPointerType(nodeT1)) {
24575 return typesAreEqual(t1->get_base_type(), t2->get_base_type());
24577 }
else if(isSgReferenceType(nodeT1)){
24581 return typesAreEqual(t1->get_base_type(), t2->get_base_type());
24582 }
else if (isSgArrayType(nodeT1)) {
24589 bool arrayBaseIsEqual = typesAreEqual(a1->get_base_type(), a2->get_base_type());
24593 bool arrayIndexExpressionIsEquivalent =
false;
24594 if(t1Index.hasValue_ && t2Index.hasValue_){
24595 if(t1Index.value_ == t2Index.value_){
24596 arrayIndexExpressionIsEquivalent =
true;
24599 bool arraysAreEqual = (arrayBaseIsEqual && arrayIndexExpressionIsEquivalent);
24600 return arraysAreEqual;
24601 }
else if (isSgFunctionType(nodeT1)) {
24609 if(typesAreEqual(funcTypeA->get_return_type(), funcTypeB->get_return_type())) {
24619 for(SgTypePtrList::const_iterator ii = funcTypeA->
get_arguments().begin(),
24626 if(!typesAreEqual((*ii), (*jj))) {
24646 std::cerr <<
"This feature for now is available with autotools only!" << std::endl;
24651int getNamedTypeCount() {
24655int getPointerTypeCount() {
24656 return pointerType_;
24659int getArrayTypeCount() {
24663int getFunctionTypeCount() {
24664 return functionType_;
24668 bool profile_, useSemanticEquivalence_;
24669 int namedType_, pointerType_, arrayType_, functionType_;
24672TypeEquivalenceChecker tec(
false,
false);
24673return tec.typesAreEqual(typeA, typeB);
24677std::set<SgStatement*>
24686 StatementTraversal() : count (0) {}
24687 void visit (
SgNode* node)
24692 returnset.insert(statement);
24698 std::set<SgStatement*> returnset;
24702 StatementTraversal traversal;
24703 traversal.traverse(node, preorder);
24705 return traversal.returnset;
24708std::set<SgStatement*>
24715 printf (
"In collectModifiedStatements(): node = %p = %s \n",node,node->
class_name().c_str());
24721 StatementTraversal() : count (0) {}
24722 void visit (
SgNode* node)
24727 returnset.insert(statement);
24733 std::set<SgStatement*> returnset;
24737 StatementTraversal traversal;
24738 traversal.traverse(node, preorder);
24740 return traversal.returnset;
24750 printf (
"In outputFileIds(): node = %p = %s \n",node,node->
class_name().c_str());
24756 LocatedNodeTraversal() {}
24757 void visit (
SgNode* node)
24760 if (locatedNode != NULL)
24763 printf (
"In outputFileIds(): isModified() == %s: locatedNode = %p = %s \n",locatedNode->
get_isModified() ?
"true" :
"false",locatedNode,locatedNode->
class_name().c_str());
24764 printf (
" --- file id = %d physical_file_id = %d \n",node->
get_file_info()->get_file_id(),node->
get_file_info()->get_physical_file_id());
24770 if (initializedName != NULL)
24772 printf (
"In outputFileIds(): isModified() == %s: initializedName = %p = %s \n",initializedName->
get_isModified() ?
"true" :
"false",initializedName,initializedName->
class_name().c_str());
24773 printf (
" --- file id = %d physical_file_id = %d \n",initializedName->
get_file_info()->get_file_id(),initializedName->
get_file_info()->get_physical_file_id());
24780 LocatedNodeTraversal traversal;
24781 traversal.traverse(node, preorder);
24784 printf (
"Exiting as a test! \n");
24790std::set<SgLocatedNode*>
24797 printf (
"In collectModifiedLocatedNodes(): node = %p = %s \n",node,node->
class_name().c_str());
24803 LocatedNodeTraversal() : count (0) {}
24804 void visit (
SgNode* node)
24807 if (locatedNode != NULL && locatedNode->
get_isModified() ==
true)
24810 printf (
"In collectModifiedLocatedNodes(): isModified() == true: locatedNode = %p = %s \n",locatedNode,locatedNode->
class_name().c_str());
24812 returnset.insert(locatedNode);
24818 std::set<SgLocatedNode*> returnset;
24822 LocatedNodeTraversal traversal;
24823 traversal.traverse(node, preorder);
24825 return traversal.returnset;
24836 printf (
"In resetModifiedLocatedNodes(): modifiedNodeSet.size() = %zu \n",modifiedNodeSet.size());
24839 std::set<SgLocatedNode*>::const_iterator i = modifiedNodeSet.begin();
24840 while (i != modifiedNodeSet.end())
24844 printf (
"Marking node = %p = %s as modified \n",node,node->
class_name().c_str());
24859 printf (
"\n\n##################################################### \n");
24860 printf (
"Report on modified statements: label = %s \n",label.c_str());
24863 if (sourceFile != NULL)
24865 printf (
" --- (SgSourceFile) filename = %s \n",sourceFile->
getFileName().c_str());
24869 SgGlobal* globalScope = isSgGlobal(node);
24870 if (globalScope != NULL)
24872 sourceFile = isSgSourceFile(globalScope->
get_parent());
24873 printf (
" --- (SgGlobal) filename = %s \n",sourceFile->
getFileName().c_str());
24877 ROSE_ASSERT(node != NULL);
24881 printf (
"In reportModifiedStatements(): collection.size() = %zu \n",collection.size());
24884 std::set<SgStatement*>::iterator i = collection.begin();
24885 while (i != collection.end())
24888 string filename = (*i)->get_file_info()->get_filename();
24891 if (filename ==
"transformation")
24894 printf (
" --- filename == transformation: sourceFile = %p using physical filename \n",sourceFile);
24897 SgSourceFile* sourceFile = TransformationSupport::getSourceFile(*i);
24898 if (sourceFile != NULL)
24904 printf (
" --- filename = %s modified statement = %p = %s \n",filename.c_str(),(*i),(*i)->class_name().c_str());
24912 printf (
"########################################################## \n");
24913 printf (
"reportModifiedStatements(): Called using label = %s \n",label.c_str());
24915 printf (
"########################################################## \n\n\n");
24918 printf (
"Exiting as a test! \n");
24919 ROSE_ASSERT(
false);
24931 printf (
"\n\n##################################################### \n");
24932 printf (
"Report on modified locatedNodes: label = %s \n",label.c_str());
24935 if (sourceFile != NULL)
24937 printf (
" --- (SgSourceFile) filename = %s \n",sourceFile->
getFileName().c_str());
24941 SgGlobal* globalScope = isSgGlobal(node);
24942 if (globalScope != NULL)
24944 sourceFile = isSgSourceFile(globalScope->
get_parent());
24945 printf (
" --- (SgGlobal) filename = %s \n",sourceFile->
getFileName().c_str());
24949 ROSE_ASSERT(node != NULL);
24953 printf (
"In reportModifiedLocatedNode(): collection.size() = %zu \n",collection.size());
24956 std::set<SgLocatedNode*>::iterator i = collection.begin();
24957 while (i != collection.end())
24960 string filename = (*i)->get_file_info()->get_filename();
24963 if (filename ==
"transformation")
24966 printf (
" --- filename == transformation: sourceFile = %p using physical filename \n",sourceFile);
24969 SgSourceFile* sourceFile = TransformationSupport::getSourceFile(*i);
24970 if (sourceFile != NULL)
24976 printf (
" --- filename = %s modified locatedNode = %p = %s \n",filename.c_str(),(*i),(*i)->class_name().c_str());
24984 printf (
"########################################################## \n");
24985 printf (
"reportModifiedLocatedNodes(): Called using label = %s \n",label.c_str());
24987 printf (
"########################################################## \n\n\n");
24990 printf (
"Exiting as a test! \n");
24991 ROSE_ASSERT(
false);
25005 ROSE_ASSERT(locatedNode != NULL);
25009 curprint (
"/* Inside of printOutComments() */");
25012 if (comments != NULL)
25015 printf (
"Found attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
class_name().c_str());
25016 curprint (
"/* Inside of printOutComments(): comments != NULL */");
25019 AttachedPreprocessingInfoType::iterator i;
25020 for (i = comments->begin(); i != comments->end(); i++)
25022 ROSE_ASSERT ( (*i) != NULL );
25023 printf (
" Attached Comment (relativePosition=%s): %s \n",
25026 PreprocessingInfo::relativePositionName((*i)->getRelativePosition()).c_str(),
25027 (*i)->getString().c_str());
25028 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
25032 (*i)->get_file_info()->display(
"comment/directive location");
25039 printf (
"In SageInterface::printOutComments(): No attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
class_name().c_str());
25049 bool returnValue =
false;
25051 ROSE_ASSERT(currentPreprocessingInfo != NULL);
25053 PreprocessingInfo::DirectiveType directive = currentPreprocessingInfo->getTypeOfDirective();
25055 if (directive == PreprocessingInfo::C_StyleComment ||
25056 directive == PreprocessingInfo::CplusplusStyleComment ||
25057 directive == PreprocessingInfo::FortranStyleComment ||
25058 directive == PreprocessingInfo::CpreprocessorBlankLine ||
25059 directive == PreprocessingInfo::ClinkageSpecificationStart ||
25060 directive == PreprocessingInfo::ClinkageSpecificationEnd)
25062 returnValue =
true;
25065 return returnValue;
25068std::vector<SgC_PreprocessorDirectiveStatement*>
25071 std::vector<SgC_PreprocessorDirectiveStatement*> directiveList;
25076 if (comments !=
nullptr)
25078 AttachedPreprocessingInfoType::iterator i;
25079 for (i = comments->begin (); i != comments->end(); i++)
25088 ROSE_ASSERT(directive != NULL);
25089 directiveList.push_back(directive);
25092 printf (
"directiveList.size() = %zu \n",directiveList.size());
25096 return directiveList;
25105 printf (
"In translateScopeToUseCppDeclarations(): declarationsOnly = %s scope = %p = %s \n",declarationsOnly ?
"true" :
"false",scope,scope->
class_name().c_str());
25107 std::map<SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> > directiveMap;
25109 if (declarationsOnly ==
true)
25113 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
25114 while (i != declarationList.end())
25117 ROSE_ASSERT(declaration != NULL);
25121 printf (
"attachDirectives.size() = %zu \n",attachDirectives.size());
25123 if (attachDirectives.empty() ==
false)
25125 directiveMap.insert(std::pair<
SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> >(declaration,attachDirectives));
25137 SgStatementPtrList::iterator i = statementList.begin();
25138 while (i != statementList.end())
25141 ROSE_ASSERT(statement != NULL);
25145 printf (
"attachDirectives.size() = %zu \n",attachDirectives.size());
25147 if (attachDirectives.empty() ==
false)
25149 directiveMap.insert(std::pair<
SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> >(statement,attachDirectives));
25156 printf (
"directiveMap.size() = %zu \n",directiveMap.size());
25158 printf (
"Processing the directiveMap: \n");
25159 std::map<SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> >::iterator i = directiveMap.begin();
25160 while (i != directiveMap.end())
25163 std::vector<SgC_PreprocessorDirectiveStatement*> directives = i->second;
25165 printf (
"statement = %p = %s \n",statement,statement->
class_name().c_str());
25166 printf (
"directives.size() = %zu \n",directives.size());
25168 std::vector<SgC_PreprocessorDirectiveStatement*>::iterator j = directives.begin();
25169 while (j != directives.end())
25178 ROSE_ASSERT(comments != NULL);
25180 AttachedPreprocessingInfoType deleteList;
25185 AttachedPreprocessingInfoType::iterator k;
25186 for (k = comments->begin(); k != comments->end(); k++)
25189 ROSE_ASSERT ( (*k) != NULL );
25190 printf (
" Attached Comment (relativePosition=%s): %s\n",
25191 ((*k)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
25192 (*k)->getString().c_str());
25193 printf (
"translateScopeToUseCppDeclarations(): Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*k)->getNumberOfLines(),(*k)->getColumnNumberOfEndOfString());
25200 printf (
"Do NOT delete *k = %p = %s \n",*k,(*k)->getString().c_str());
25204 printf (
"DO delete *k = %p = %s \n",*k,(*k)->getString().c_str());
25206 deleteList.push_back(*k);
25212 printf (
"Iterate over the deleteList: deleteList.size() = %zu comments->size() = %zu \n",deleteList.size(),comments->size());
25213 AttachedPreprocessingInfoType::iterator m = deleteList.begin();
25214 while (m != deleteList.end())
25218 comments->erase(std::remove(comments->begin(), comments->end(), *m), comments->end());
25220 printf (
" --- comments->size() = %zu \n",comments->size());
25232 printf (
"Leaving translateScopeToUseCppDeclarations(): scope = %p = %s \n",scope,scope->
class_name().c_str());
25242 CppTranslationTraversal() {}
25243 void visit (
SgNode* node)
25245 printf (
"In CppTranslationTraversal::visit(): node = %p = %s \n",node,node->
class_name().c_str());
25248 SgGlobal* globalScope = isSgGlobal(scope);
25249 if (globalScope != NULL)
25251 printf (
"In CppTranslationTraversal::visit(): processing scope = %p = %s \n",scope,scope->
class_name().c_str());
25258 printf (
"In SageInterface::translateToUseCppDeclarations(): Currently skipping all but global scope! \n");
25265 CppTranslationTraversal traversal;
25267 printf (
"In translateToUseCppDeclarations(): Calling traversal.traverse() \n");
25271 traversal.traverse(n, postorder);
25273 printf (
"Leaving translateToUseCppDeclarations(): DONE: Calling traversal.traverse() \n");
25280 cout<<
"--------------"<<endl;
25284 cout<<
"file info:\t ";
25285 lnode->get_file_info()->display();
25286 cout<<
"\n unparseToString:\t ";
25287 lnode->unparseToString();
25298static void serialize(SgTemplateArgumentPtrList& plist,
string& prefix,
bool hasRemaining, ostringstream& out,
string& edgeLabel)
25301 out<< (hasRemaining?
"|---":
"|___");
25304 out<<
" "<<edgeLabel<<
" ->";
25306 out<<
"@"<<&plist<<
" "<<
"SgTemplateArgumentPtrList ";
25310 int last_non_null_child_idx =-1;
25311 for (
int i = (
int) (plist.size())-1; i>=0; i--)
25315 last_non_null_child_idx = i;
25320 for (
size_t i=0; i< plist.size(); i++ )
25322 bool n_hasRemaining=
false;
25324 if (i+1 < plist.size())
25325 n_hasRemaining=
true;
25327 if ((
int)i< last_non_null_child_idx) n_hasRemaining =
true;
25329 string suffix= hasRemaining?
"| " :
" ";
25330 string n_prefix = prefix+suffix;
25331 string n_edge_label=
"";
25333 serialize (plist[i], n_prefix, n_hasRemaining, out,n_edge_label);
25346 out<< (hasRemaining?
"|---":
"|___");
25348 out<<
" "<<edgeLabel<<
" ->";
25351 out<<
" NULL "<<endl;
25356 out<<
"@"<<node<<
" "<< node->
class_name()<<
" ";
25362 out<< lnode->get_file_info()->get_filename() <<
" "<<lnode->get_file_info()->get_line()<<
":"<<lnode->get_file_info()->get_col();
25364 AttachedPreprocessingInfoType *comments =
25365 lnode->getAttachedPreprocessingInfo ();
25367 if (comments != NULL)
25370 out<<
" AttachedPreprocessingInfoType@"<<comments;
25372 AttachedPreprocessingInfoType::iterator i;
25374 for (i = comments->begin (); i != comments->end (); i++)
25376 if (i!=comments->begin ())
25379 out<<counter++<<
" ";
25388 out<<*i<<
" classification="<<PreprocessingInfo::directiveTypeName((*i)->getTypeOfDirective ()). c_str ();
25389 out<<
" string="<<(*i)->getString ().c_str ();
25390 out<<
" relative pos=" ;
25392 if ((*i)->getRelativePosition () == PreprocessingInfo::inside)
25394 else if ((*i)->getRelativePosition () == PreprocessingInfo::before)
25408 out<<
" first nondefining decl@"<< v->get_firstNondefiningDeclaration();
25409 out<<
" defining decl@"<< v->get_definingDeclaration();
25413 out<<
" value="<< f->get_value() <<
" declaration="<<f->get_declaration() <<
" name="<< f->get_name().getString();
25420 out<<
" renamed_function "<< f->get_renamed_function();
25423 out<<
" name="<< f->get_name() <<
" renamed decl "<<f->get_renamed() ;
25435 out<<
" enumType="<< f->get_enumType();
25443 out<<
" is_general_access"<< v->get_is_general_access();
25446 out<<
" is_anonymous:"<< v->get_is_anonymous ();
25451 out<<
" is_protected"<< v->get_is_protected();
25457 out<<
" type@"<< v->get_type();
25458 out<<
" initializer@"<< v->get_initializer();
25459 out<<
" scope@"<< v->get_scope();
25465 out<<
" template class decl@"<< f->get_templateDeclaration();
25468 out<<
" assoc. class decl@"<< f->get_associatedClassDeclaration();
25472 out<<
" member function decl@"<< ctor->get_declaration();
25475 if (
SgIntVal* v= isSgIntVal(node))
25476 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25479 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25482 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25485 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25488 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25491 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25494 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25497 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25500 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25503 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25506 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25509 out<<
" init name@"<< var_ref->get_symbol()->get_declaration() <<
" symbol name="<<var_ref->get_symbol()->get_name();
25512 out<<
" member func decl@"<< func_ref->get_symbol_i()->get_declaration();
25515 out<<
" template member func decl@"<< cnode->get_templateDeclaration();
25520 out<<
" func decl@"<< sym->get_declaration() <<
" func sym name="<<sym->
get_name();
25526 out<<
" ada renaming decl@"<< renaming_decl;
25532 out<<
" base_type@"<< v->get_base_type();
25537 out<<
" base_type@"<< v->get_base_type();
25540 out<<
" base_type@"<< v->get_base_type();
25543 out<<
" type@"<< v->get_type();
25546 out<<
" attribute@"<< v->get_attribute();
25549 out<<
" namespaceDeclaration="<< v->get_namespaceDeclaration();
25555 int total_count = children.size();
25556 int current_index=0;
25559 int last_non_null_child_idx =-1;
25560 for (
int i = (
int) (children.size())-1; i>=0; i--)
25564 last_non_null_child_idx = i;
25572 if (isSgTemplateInstantiationDecl (node))
25579 SgTemplateArgumentPtrList& plist = sn->get_templateArguments();
25580 bool n_hasRemaining=
false;
25581 if (last_non_null_child_idx>-1) n_hasRemaining =
true;
25582 string suffix= hasRemaining?
"| " :
" ";
25583 string n_prefix = prefix+suffix;
25584 string n_edge_label=
"";
25585 serialize_list(plist,
"SgTemplateArgumentPtrList", n_prefix, n_hasRemaining, out, n_edge_label);
25589 SgExpressionPtrList& plist = import_stmt->get_import_list();
25590 bool n_hasRemaining=
false;
25591 if (last_non_null_child_idx>-1) n_hasRemaining =
true;
25592 string suffix= hasRemaining?
"| " :
" ";
25593 string n_prefix = prefix+suffix;
25594 string n_edge_label=
"";
25595 serialize_list(plist,
"SgExpressionPtrList", n_prefix, n_hasRemaining, out, n_edge_label);
25601 for (
size_t i =0; i< children.size(); i++)
25603 bool n_hasRemaining=
false;
25605 if (current_index+1<total_count)
25606 n_hasRemaining=
true;
25609 if ((
int)i<last_non_null_child_idx) n_hasRemaining =
true;
25611 string suffix= hasRemaining?
"| " :
" ";
25612 string n_prefix = prefix+suffix;
25614 serialize (children[i], n_prefix, n_hasRemaining, out, successorNames[i]);
25623 serialize(node, prefix,
false, oss, label);
25644 serialize(node, prefix,
false, oss, label);
25646 textfile.open(filename, ios::out);
25647 textfile<<oss.str();
25652 textfile<<
"Types encountered ...."<<endl;
25653 ostringstream oss2;
25654 VariantVector vv(V_SgType);
25655 Rose_STL_Container<SgNode*> tnodes= NodeQuery::queryMemoryPool(vv);
25656 for (Rose_STL_Container<SgNode*>::const_iterator i = tnodes.begin(); i != tnodes.end(); ++i)
25658 serialize (*i, prefix,
false, oss2, label);
25660 textfile<<oss2.str();
25668 saveToPDF(node,
string(
"temp.pdf.json") );
25674 ROSE_ASSERT(node != NULL);
25681 bool rtval =
false;
25682 ROSE_ASSERT (node != NULL);
25686 string fname = finfo->get_filenameString();
25687 string buildtree_str1 = string(
"include-staging/gcc_HEADERS");
25688 string buildtree_str2 = string(
"include-staging/g++_HEADERS");
25689 string installtree_str1 = string(
"include/edg/gcc_HEADERS");
25690 string installtree_str2 = string(
"include/edg/g++_HEADERS");
25691 string system_headers = string(
"/usr/include");
25693 if ((fname.find (buildtree_str1, 0) != string::npos) ||
25694 (fname.find (buildtree_str2, 0) != string::npos) ||
25695 (fname.find (installtree_str1, 0) != string::npos) ||
25696 (fname.find (installtree_str2, 0) != string::npos) ||
25697 (fname.find (system_headers, 0) != string::npos)
25710 bool returnValue =
false;
25713 ROSE_ASSERT(fileInfo != NULL);
25714 string filename = fileInfo->get_filenameString();
25717 printf (
"In SageInterface::insideHeader(): node = %s line: %d column: %d file: %s \n",node->
class_name().c_str(),fileInfo->
get_line(),fileInfo->
get_col(),filename.c_str());
25722 if (EDG_ROSE_Translation::edg_include_file_map.find(filename) == EDG_ROSE_Translation::edg_include_file_map.end())
25725 printf (
"This is NOT in the EDG_ROSE_Translation::edg_include_file_map \n");
25731 printf (
"This IS in the EDG_ROSE_Translation::edg_include_file_map \n");
25733 returnValue =
true;
25736 return returnValue;
25743 ROSE_ASSERT(return_type != NULL);
25744 ROSE_ASSERT(typeList != NULL);
25746 ROSE_ASSERT(fTable);
25751 SgFunctionType* funcType = isSgFunctionType(fTable->lookup_function_type(typeName));
25761 ROSE_ASSERT (lhs != NULL);
25762 ROSE_ASSERT (rhs != NULL);
25767 SgType* rt1 = lhs->get_return_type();
25768 SgType* rt2 = rhs->get_return_type();
25775 if (f1_arg_types.size() == f2_arg_types.size())
25779 size_t counter = 0;
25782 for (
size_t i=0; i< f1_arg_types.size(); i++)
25790 if (counter == f1_arg_types.size())
25812 ROSE_ASSERT(lhs != NULL);
25813 ROSE_ASSERT(rhs != NULL);
25815 bool isSame =
false;
25818 static int counter = 0;
25820 const SgType & X = *lhs;
25821 const SgType & Y = *rhs;
25829#define DEBUG_TYPE_EQUIVALENCE 0
25831#if DEBUG_TYPE_EQUIVALENCE
25832 printf (
"In SageInterface::isEquivalentType(): evaluation of type equivalence for lhs and rhs: counter = %d \n",counter);
25837#if DEBUG_TYPE_EQUIVALENCE || 0
25840 printf (
"In SageInterface::isEquivalentType(): evaluation of type equivalence for lhs and rhs: counter = %d \n",counter);
25846#if DEBUG_TYPE_EQUIVALENCE || 0
25852 printf (
"Output of type chain for lhs: \n");
25853 for (
size_t i = 0; i < X_typeChain.size(); i++)
25855 SgType* element_type = X_typeChain[i];
25856 printf (
"X_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
25857 printf (
" --- X_element_type unparseToString: = %s \n",element_type->
unparseToString().c_str());
25859 if (modifierType != NULL)
25863 printf (
" --- type chain modifier: %s \n",s.c_str());
25864 printf (
" --- type chain modifier: unparseToString: %s \n",modifierType->
unparseToString().c_str());
25868 printf (
"Output of type chain for rhs: \n");
25869 for (
size_t i = 0; i < Y_typeChain.size(); i++)
25871 SgType* element_type = Y_typeChain[i];
25872 printf (
"Y_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
25873 printf (
" --- Y_element_type unparseToString: = %s \n",element_type->
unparseToString().c_str());
25875 if (modifierType != NULL)
25879 printf (
" --- type chain modifier: %s \n",s.c_str());
25880 printf (
" --- type chain modifier: unparseToString: %s \n",modifierType->
unparseToString().c_str());
25891 if (counter >= 280)
25894 printf (
"In SageInterface::isEquivalentType(): counter = %d: type chain X_element_type = %s = %p Y_element_type = %s = %p \n",counter,X.
class_name().c_str(),lhs,Y.
class_name().c_str(),rhs);
25906 printf (
"ERROR: In SageInterface::isEquivalentType(): recursive limit exceeded for : counter = %d \n",counter);
25917 SgReferenceType* X_referenceType = isSgReferenceType(X_element_type);
25918 SgReferenceType* Y_referenceType = isSgReferenceType(Y_element_type);
25920 if (X_referenceType != NULL && Y_referenceType != NULL)
25922 X_element_type = X_referenceType->get_base_type();
25923 Y_element_type = Y_referenceType->get_base_type();
25934 SgPointerType* X_pointerType = isSgPointerType(X_element_type);
25935 SgPointerType* Y_pointerType = isSgPointerType(Y_element_type);
25937 if (X_pointerType != NULL && Y_pointerType != NULL)
25939 X_element_type = X_pointerType->get_base_type();
25940 Y_element_type = Y_pointerType->get_base_type();
25951 SgArrayType* X_arrayType = isSgArrayType(X_element_type);
25952 SgArrayType* Y_arrayType = isSgArrayType(Y_element_type);
25955 if (X_arrayType != NULL && Y_arrayType != NULL)
25957 X_element_type = X_arrayType->get_base_type();
25958 Y_element_type = Y_arrayType->get_base_type();
25960 SgExpression* X_array_index_expression = X_arrayType->get_index();
25961 SgExpression* Y_array_index_expression = Y_arrayType->get_index();
25963 if (X_array_index_expression == Y_array_index_expression)
25965#if DEBUG_TYPE_EQUIVALENCE || 0
25966 printf (
"In SageInterface::isEquivalentType(): counter = %d: Need to check the array size for static equivalence \n",counter);
25977#if DEBUG_TYPE_EQUIVALENCE || 0
25978 printf (
"In SageInterface::isEquivalentType(): counter = %d Need more complex test for expression equivalence \n",counter);
25981 printf (
" --- array index expressions: str1 = %s str2 = %s \n",str1.c_str(),str2.c_str());
25993 SgNonrealType* X_templateType = isSgNonrealType(X_element_type);
25994 SgNonrealType* Y_templateType = isSgNonrealType(Y_element_type);
25997 if (X_templateType != NULL && Y_templateType != NULL)
25999 string X_name = X_templateType->
get_name();
26000 string Y_name = Y_templateType->
get_name();
26002 SgNonrealDecl* X_templateDecl = isSgNonrealDecl(X_templateType->get_declaration());
26003 ROSE_ASSERT(X_templateDecl != NULL);
26004 SgNonrealDecl* Y_templateDecl = isSgNonrealDecl(Y_templateType->get_declaration());
26005 ROSE_ASSERT(Y_templateDecl != NULL);
26007 int X_template_parameter_position = X_templateDecl->get_template_parameter_position();
26008 int Y_template_parameter_position = Y_templateDecl->get_template_parameter_position();
26013#if DEBUG_TYPE_EQUIVALENCE
26016 printf (
"In SageInterface::isEquivalentType(): case SgNonrealType:\n");
26017 printf (
" -- X_name = %s Y_name = %s\n", X_name.c_str(),Y_name.c_str());
26018 printf (
" -- X_template_parameter_position = %d Y_template_parameter_position = %d\n", X_template_parameter_position,Y_template_parameter_position);
26019 printf (
" -- X_parent = %p (%s) Y_parent = %p (%s)\n", X_parent, X_parent ? X_parent->
class_name().c_str() :
"", Y_parent, Y_parent ? Y_parent->
class_name().c_str() :
"");
26020 printf (
" -- X_parent_parent = %p (%s) Y_parent_parent = %p (%s)\n", X_parent_parent, X_parent_parent ? X_parent_parent->
class_name().c_str() :
"", Y_parent_parent, Y_parent_parent ? Y_parent_parent->
class_name().c_str() :
"");
26021 printf (
" -- X_templateDecl->get_mangled_name() = %s\n", X_templateDecl->get_mangled_name().str());
26022 printf (
" -- Y_templateDecl->get_mangled_name() = %s\n", Y_templateDecl->get_mangled_name().str());
26024 bool value = (X_parent == Y_parent);
26026 if (value && X_templateDecl->get_is_template_param() && Y_templateDecl->get_is_template_param()) {
26027 value = (X_template_parameter_position == Y_template_parameter_position);
26028 }
else if (value && X_templateDecl->get_is_class_member() && Y_templateDecl->get_is_class_member()) {
26029 value = (X_name == Y_name);
26041 printf (
"Nothing to do here since we have explored all uniform pairs of intermediate types possible: isSame = %s \n",isSame ?
"true" :
"false");
26047#if DEBUG_TYPE_EQUIVALENCE
26048 printf (
"In SageInterface::isEquivalentType(): loop: Nothing to do here since we have explored all uniform pairs of intermediate types possible: isSame = %s \n",isSame ?
"true" :
"false");
26055 SgModifierType* X_modifierType = isSgModifierType(X_element_type);
26056 SgModifierType* Y_modifierType = isSgModifierType(Y_element_type);
26058#if DEBUG_TYPE_EQUIVALENCE
26059 printf (
"In SageInterface::isEquivalentType(): counter = %d: type chain X_element_type = %p = %s Y_element_type = %p = %s \n",
26060 counter,X_element_type,X_element_type->
class_name().c_str(),Y_element_type,Y_element_type->
class_name().c_str());
26063 if (X_modifierType != NULL && Y_modifierType != NULL)
26066#if DEBUG_TYPE_EQUIVALENCE
26067 printf (
"In SageInterface::isEquivalentType(): loop: these are the both SgModifierType nodes: isSame = %s \n",isSame ?
"true" :
"false");
26069 if (X_modifierType == Y_modifierType)
26072#if DEBUG_TYPE_EQUIVALENCE
26073 printf (
"In SageInterface::isEquivalentType(): loop: these are the same modifier type: isSame = %s \n",isSame ?
"true" :
"false");
26080#if DEBUG_TYPE_EQUIVALENCE
26081 printf (
"In SageInterface::isEquivalentType(): loop: these are equivalent modifiers: check the base type: isSame = %s \n",isSame ?
"true" :
"false");
26085 isSame =
isEquivalentType(X_modifierType->get_base_type(),Y_modifierType->get_base_type());
26089#if DEBUG_TYPE_EQUIVALENCE
26090 printf (
"In SageInterface::isEquivalentType(): loop: these are not equivalent modifier types: check for default settings: isSame = %s \n",isSame ?
"true" :
"false");
26093 bool skippingOverIdentityModifier =
false;
26097#if DEBUG_TYPE_EQUIVALENCE
26098 printf (
"In SageInterface::isEquivalentType(): loop: found self-similar setting for lhs: isSame = %s \n",isSame ?
"true" :
"false");
26100 X_element_type = X_modifierType->get_base_type();
26103 skippingOverIdentityModifier =
true;
26108#if DEBUG_TYPE_EQUIVALENCE
26109 printf (
"In SageInterface::isEquivalentType(): loop: found self-similar setting for rhs: isSame = %s \n",isSame ?
"true" :
"false");
26111 Y_element_type = Y_modifierType->get_base_type();
26114 skippingOverIdentityModifier =
true;
26118#if DEBUG_TYPE_EQUIVALENCE
26119 printf (
"In SageInterface::isEquivalentType(): loop: skippingOverIdentityModifier = %s \n",skippingOverIdentityModifier ?
"true" :
"false");
26124 if (skippingOverIdentityModifier ==
true)
26126#if DEBUG_TYPE_EQUIVALENCE
26127 printf (
"In SageInterface::isEquivalentType(): loop: recursive call on different adjusted modifier types: before recursive call to compare base types: isSame = %s \n",isSame ?
"true" :
"false");
26136#if DEBUG_TYPE_EQUIVALENCE
26137 printf (
"In SageInterface::isEquivalentType(): loop: no progress was made in resolving the base type, so returning isSame set to false: isSame = %s \n",isSame ?
"true" :
"false");
26141#if DEBUG_TYPE_EQUIVALENCE
26142 printf (
"In SageInterface::isEquivalentType(): loop: these are different modifier types: after recursive call to compare base types: isSame = %s \n",isSame ?
"true" :
"false");
26151 if (X_modifierType != NULL || Y_modifierType != NULL)
26153 bool isReduceable =
false;
26155 if (X_modifierType != NULL && X_modifierType->
get_typeModifier().isIdentity() ==
true)
26157#if DEBUG_TYPE_EQUIVALENCE
26158 printf (
"In SageInterface::isEquivalentType(): loop: found default setting for lhs: isSame = %s \n",isSame ?
"true" :
"false");
26160 X_element_type = X_modifierType->get_base_type();
26161 isReduceable =
true;
26164 if (Y_modifierType != NULL && Y_modifierType->
get_typeModifier().isIdentity() ==
true)
26166#if DEBUG_TYPE_EQUIVALENCE
26167 printf (
"In SageInterface::isEquivalentType(): loop: found default setting for rhs: isSame = %s \n",isSame ?
"true" :
"false");
26169 Y_element_type = Y_modifierType->get_base_type();
26170 isReduceable =
true;
26174#if DEBUG_TYPE_EQUIVALENCE
26175 printf (
"In SageInterface::isEquivalentType(): loop: these are different modifier types: after recursive call to compare base types: isReduceable = %s \n",isReduceable ?
"true" :
"false");
26177 if (isReduceable ==
true)
26189#if DEBUG_TYPE_EQUIVALENCE
26190 printf (
"In SageInterface::isEquivalentType(): loop: these are different modifier types: after recursive call to compare base types: isReduceable = %s isSame = %s \n",
26191 isReduceable ?
"true" :
"false",isSame ?
"true" :
"false");
26200 if (X_element_type == Y_element_type)
26203#if DEBUG_TYPE_EQUIVALENCE || 0
26205 printf (
"In SageInterface::isEquivalentType(): resolved to equal types: isSame = %s lhs = %p = %s rhs = %p = %s \n",
26208#if DEBUG_TYPE_EQUIVALENCE || 0
26211 const SgTypedefType* lhs_typedefType = isSgTypedefType(lhs);
26212 const SgTypedefType* rhs_typedefType = isSgTypedefType(rhs);
26214 if (lhs_typedefType != NULL || rhs_typedefType != NULL)
26217 if (lhs_typedefType != NULL)
26219 printf (
"lhs was a typedef: lhs = %p = %s \n",lhs,lhs->
unparseToString().c_str());
26221 if (rhs_typedefType != NULL)
26223 printf (
"rhs was a typedef: rhs = %p = %s \n",rhs,rhs->
unparseToString().c_str());
26226 printf (
" --- one was a typedef: lhs = %p = %s \n",lhs,lhs->
unparseToString().c_str());
26227 printf (
" --- one was a typedef: rhs = %p = %s \n",rhs,rhs->
unparseToString().c_str());
26238 SgReferenceType* X_referenceType = isSgReferenceType(X_element_type);
26239 SgReferenceType* Y_referenceType = isSgReferenceType(Y_element_type);
26241 if (X_referenceType != NULL || Y_referenceType != NULL)
26244 if (X_referenceType != NULL)
26246 X_element_type = X_referenceType->get_base_type();
26250 isReduceable =
false;
26253 if (Y_referenceType != NULL)
26255 Y_element_type = Y_referenceType->get_base_type();
26259 isReduceable =
false;
26262 if (isReduceable ==
true)
26283#if DEBUG_TYPE_EQUIVALENCE
26284 printf (
"In SageInterface::isEquivalentType(): loop: evaluation of inner types: isSame = %s \n",isSame ?
"true" :
"false");
26288 SgPointerType* X_pointerType = isSgPointerType(X_element_type);
26289 SgPointerType* Y_pointerType = isSgPointerType(Y_element_type);
26291 if (X_pointerType != NULL || Y_pointerType != NULL)
26294 if (X_pointerType != NULL)
26296 X_element_type = X_pointerType->get_base_type();
26300 isReduceable =
false;
26303 if (Y_pointerType != NULL)
26305 Y_element_type = Y_pointerType->get_base_type();
26309 isReduceable =
false;
26312 if (isReduceable ==
true)
26333#if DEBUG_TYPE_EQUIVALENCE
26334 printf (
"In SageInterface::isEquivalentType(): loop: evaluation of inner types: isSame = %s \n",isSame ?
"true" :
"false");
26338 SgArrayType* X_arrayType = isSgArrayType(X_element_type);
26339 SgArrayType* Y_arrayType = isSgArrayType(Y_element_type);
26341 if (X_arrayType != NULL || Y_arrayType != NULL)
26344 if (X_arrayType != NULL)
26346 X_element_type = X_arrayType->get_base_type();
26350 isReduceable =
false;
26353 if (Y_arrayType != NULL)
26355 Y_element_type = Y_arrayType->get_base_type();
26359 isReduceable =
false;
26362 if (isReduceable ==
true)
26383#if DEBUG_TYPE_EQUIVALENCE
26384 printf (
"In SageInterface::isEquivalentType(): loop: evaluation of inner types: isSame = %s \n",isSame ?
"true" :
"false");
26388 SgFunctionType* X_functionType = isSgFunctionType(X_element_type);
26389 SgFunctionType* Y_functionType = isSgFunctionType(Y_element_type);
26391 if (X_functionType != NULL || Y_functionType != NULL)
26393 bool value = ( (X_functionType != NULL && Y_functionType != NULL) && (X_functionType == Y_functionType) );
26396#if DEBUG_TYPE_EQUIVALENCE || 0
26397 printf (
"In SageInterface::isEquivalentType(): loop: Process case of SgFunctionType: value = %s \n",value ?
"true" :
"false");
26415 if (X_memberFunctionType != NULL || Y_memberFunctionType != NULL)
26418 printf (
"This should be unreachable code \n");
26422 bool value = ( (X_memberFunctionType != NULL && Y_memberFunctionType != NULL) && (X_memberFunctionType == Y_memberFunctionType) );
26423#if DEBUG_TYPE_EQUIVALENCE || 0
26424 printf (
"In SageInterface::isEquivalentType(): loop: Process case of SgMemberFunctionType: value = %s \n",value ?
"true" :
"false");
26437 bool X_isReduceable =
true;
26438 if (isSgTypeSignedLong(X_element_type) != NULL ||
26439 isSgTypeUnsignedInt(X_element_type) != NULL ||
26440 isSgTypeBool(X_element_type) != NULL ||
26441 isSgTypeInt(X_element_type) != NULL)
26443 X_isReduceable =
false;
26446 bool Y_isReduceable =
true;
26447 if (isSgTypeSignedLong(Y_element_type) != NULL ||
26448 isSgTypeUnsignedInt(Y_element_type) != NULL ||
26449 isSgTypeBool(Y_element_type) != NULL ||
26450 isSgTypeInt(Y_element_type) != NULL)
26452 Y_isReduceable =
false;
26454#if DEBUG_TYPE_EQUIVALENCE || 0
26455 printf (
"In SageInterface::isEquivalentType(): loop: Process default case: X_isReduceable = %s Y_isReduceable = %s \n",
26456 X_isReduceable ?
"true" :
"false",Y_isReduceable ?
"true" :
"false");
26458 if (X_isReduceable ==
true || Y_isReduceable ==
true)
26472#if DEBUG_TYPE_EQUIVALENCE || 0
26473 printf (
"In SageInterface::isEquivalentType(): loop: Process default case: X_element_type = %p = %s Y_element_type = %p = %s \n",
26474 X_element_type,X_element_type->
class_name().c_str(),Y_element_type,Y_element_type->
class_name().c_str());
26479 isSame = (X_element_type == Y_element_type);
26499#if DEBUG_TYPE_EQUIVALENCE || 0
26500 printf (
"In SageInterface::isEquivalentType(): isSame = %s \n",isSame ?
"true" :
"false");
26503#if DEBUG_TYPE_EQUIVALENCE || 0
26504 if (counter == 1 && isSame ==
true)
26506 printf (
"In SageInterface::isEquivalentType(): counter = %d: isSame = %s type chain X_element_type = %s Y_element_type = %s \n",counter,isSame ?
"true" :
"false",X.
class_name().c_str(),Y.
class_name().c_str());
26513 printf (
" --- Output of type chain for lhs: \n");
26514 for (
size_t i = 0; i < X_typeChain.size(); i++)
26516 SgType* element_type = X_typeChain[i];
26517 printf (
" --- --- X_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
26519 if (modifierType != NULL)
26523 printf (
" --- type chain modifier: %s \n",s.c_str());
26527 printf (
" --- Output of type chain for rhs: \n");
26528 for (
size_t i = 0; i < Y_typeChain.size(); i++)
26530 SgType* element_type = Y_typeChain[i];
26531 printf (
" --- --- Y_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
26533 if (modifierType != NULL)
26537 printf (
" --- --- type chain modifier: %s \n",s.c_str());
26546 if (isSame ==
true)
26549 printf (
" --- isSame = %s \n",isSame ?
"true" :
"false");
26552 printf (
" --- --- X_element_type = %p = %s = %s \n",X_element_type,X_element_type->
class_name().c_str(),X_element_type->
unparseToString().c_str());
26553 printf (
" --- --- Y_element_type = %p = %s = %s \n",Y_element_type,Y_element_type->
class_name().c_str(),Y_element_type->
unparseToString().c_str());
26558 printf (
" --- isSame = %s \n",isSame ?
"true" :
"false");
26563 printf (
" --- counter = %d \n",counter);
26580 bool retval =
false;
26589 retval = function->get_marked_as_edg_normalization();
26597 if (templateInstantiationFunction != NULL)
26602 if (templateFunctionDeclaration != NULL)
26613 printf (
" --- case of templateInstantiationFunction: retval = %s \n",retval ?
"true" :
"false");
26618 if (templateInstantiationMemberFunction != NULL)
26621 templateInstantiationMemberFunction = isSgTemplateInstantiationMemberFunctionDecl(templateInstantiationMemberFunction->
get_firstNondefiningDeclaration());
26623 if (templateMemberFunctionDeclaration != NULL)
26634 printf (
" --- case of templateInstantiationMemberFunction: retval = %s \n",retval ?
"true" :
"false");
26646 printf(
"In detectCycleInType():\n");
26647 printf(
" -- from = %s\n", from.c_str());
26648 printf(
" -- type = %p (%s)\n", type, type->
class_name().c_str());
26650 std::vector<SgType *> seen_types;
26652 while (type != NULL) {
26655 ROSE_ASSERT(type != NULL);
26657 std::vector<SgType *>::const_iterator it = std::find(seen_types.begin(), seen_types.end(), type);
26658 if (it != seen_types.end()) {
26659 printf(
"ERROR: Cycle found in type = %p (%s):\n", type, type->
class_name().c_str());
26661 for (; it != seen_types.end(); it++) {
26662 printf(
" [%zd] %p (%s)\n", i, *it, (*it)->class_name().c_str());
26665 printf(
"-> detectCycleInType() was called from: %s\n", from.c_str());
26668 seen_types.push_back(type);
26678 if (isSgPointerMemberType(type) != NULL)
26685 type = modType->get_base_type();
26686 }
else if ( refType ) {
26687 type = refType->get_base_type();
26688 }
else if ( pointType ) {
26689 type = pointType->get_base_type();
26692 }
else if ( arrayType ) {
26693 type = arrayType->get_base_type();
26694 }
else if ( typedefType ) {
26699 ROSE_ASSERT(type != NULL);
26720 std::vector<SgFunctionDeclaration*> functionList;
26723 string filenameWithPath;
26726 TransformFunctionDefinitionsTraversal(): sourceFile(NULL), sourceFileId(-99) {}
26728 void visit (
SgNode* node)
26731 printf (
"In convertFunctionDefinitionsToFunctionPrototypes visit(): node = %p = %s \n",node,node->
class_name().c_str());
26734 if (temp_sourceFile != NULL)
26736 sourceFile = temp_sourceFile;
26740 filenameWithPath = sourceFile->get_sourceFileNameWithPath();
26742 printf (
"Found source file: id = %d name = %s \n",sourceFileId,sourceFile->get_sourceFileNameWithPath().c_str());
26747 if (functionDeclaration != NULL)
26750 ROSE_ASSERT(sourceFile != NULL);
26753 if (functionDeclaration == definingFunctionDeclaration)
26756 printf (
"Found a defining function declaration: functionDeclaration = %p = %s name = %s \n",
26757 functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
26759 printf (
" --- recorded source file: id = %d name = %s \n",sourceFileId,sourceFile->get_sourceFileNameWithPath().c_str());
26760 printf (
" --- source file: file_info: id = %d name = %s \n",
26765 bool isInSourceFile = (filenameWithPath == functionDeclaration->
get_file_info()->get_filenameString());
26767 printf (
" --- isInSourceFile = %s \n",isInSourceFile ?
"true" :
"false");
26771 if (isInSourceFile ==
true && functionDeclarationScope != NULL)
26774 printf (
" --- Found a defining function declaration: functionDeclarationScope = %p = %s \n",
26775 functionDeclarationScope,functionDeclarationScope->
class_name().c_str());
26779 functionList.push_back(functionDeclaration);
26787 TransformFunctionDefinitionsTraversal traversal;
26788 traversal.traverse(node, preorder);
26790 std::vector<SgFunctionDeclaration*> & functionList = traversal.functionList;
26793 printf (
"In convertFunctionDefinitionsToFunctionPrototypes(): functionList.size() = %zu \n",functionList.size());
26796 std::vector<SgFunctionDeclaration*>::iterator i = functionList.begin();
26797 while (i != functionList.end())
26800 ROSE_ASSERT(functionDeclaration != NULL);
26803 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
26806 printf (
" --- Removing function declaration: functionDeclaration = %p = %s name = %s \n",
26807 functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
26817 printf (
"In convertFunctionDefinitionsToFunctionPrototypes(): exiting as a test! \n");
26828 ROSE_ASSERT(scope != NULL);
26830 printf (
"Output the statements in scope = %p = %s \n",scope,scope->
class_name().c_str());
26834 for (
size_t i = 0; i < statementList.size(); i++)
26841 printf (
"Exiting as a test at the end of evaluation of global scope! \n");
26854 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration = %p = %s name = %s \n",
26855 functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
26859 bool isConstructor =
false;
26861 if (tmp_memberFunctionDeclaration != NULL)
26863 isConstructor = tmp_memberFunctionDeclaration->get_specialFunctionModifier().isConstructor();
26866 if (isConstructor ==
true)
26868 printf (
"Skipping case of constructors (in building prototype from defining function declaration) \n");
26878 SgName name = functionDeclaration->get_name();
26879 SgType* return_type = functionDeclaration->get_type()->get_return_type();
26887 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration = %p \n",functionDeclaration);
26888 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->
get_firstNondefiningDeclaration());
26889 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->
get_definingDeclaration());
26893 for (
size_t i = 0; i < functionDeclaration->get_args().size(); i++)
26897 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration->get_args(): (i = %zu) arg = %p = %s isDefaultArgument = %s \n",
26898 i,arg,arg->get_name().str(),arg->
get_file_info()->isDefaultArgument() ?
"true" :
"false");
26899 printf (
" --- arg->get_initializer() = %p \n",arg->get_initializer());
26903 printf (
"NOTE: default argument (i = %zu) not reproduced in function prototype: arg = %p = %s \n",i,arg,arg->get_name().str());
26916 if (templateInstantiationFunctionDecl == NULL)
26923 if (templateInstantiationMemberFunctionDecl == NULL)
26932 bool isTemplateInstantiationMemberFunctionDecl =
false;
26937 bool buildTemplateInstantiation =
false;
26938 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
26943 ROSE_ASSERT(param_list == NULL || param_list->
get_parent() == NULL);
26945 switch (functionDeclaration->
variantT())
26947 case V_SgTemplateMemberFunctionDeclaration:
26950 printf (
"This function to replace the defining declaration with a non-defining declaration does not yet support template member functions \n");
26953 ROSE_ASSERT(original_templateMemberFunctionDeclaration != NULL);
26957 unsigned int functionConstVolatileFlags = 0;
26959 ROSE_ASSERT(original_templateMemberFunctionDeclaration->get_type() != NULL);
26964 SgMemberFunctionType* memberFunctionType = isSgMemberFunctionType(original_templateMemberFunctionDeclaration->get_type());
26965 ROSE_ASSERT(memberFunctionType != NULL);
26967 functionConstVolatileFlags = memberFunctionType->get_mfunc_specifier();
26973 SgTemplateParameterPtrList templateParameterList = original_templateMemberFunctionDeclaration->get_templateParameters();
26976 templateMemberFunctionDeclaration =
26979 printf (
"ERROR: Template functions are not yet supported! \n");
26982 nondefiningFunctionDeclaration = templateMemberFunctionDeclaration;
26984 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
26987 if (isConstructor ==
true)
26989 templateMemberFunctionDeclaration->get_specialFunctionModifier().setConstructor();
26995 case V_SgTemplateFunctionDeclaration:
26998 printf (
"This function to replace the defining declaration with a non-defining declaration does not yet support template functions \n");
27001 ROSE_ASSERT(original_templateFunctionDeclaration != NULL);
27009 SgTemplateParameterPtrList templateParameterList = original_templateFunctionDeclaration->get_templateParameters();
27013 printf (
"ERROR: Template functions are not yet supported! \n");
27016 nondefiningFunctionDeclaration = templateFunctionDeclaration;
27018 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27024 case V_SgTemplateInstantiationMemberFunctionDecl:
27026 buildTemplateInstantiation =
true;
27028 isTemplateInstantiationMemberFunctionDecl =
true;
27031 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
27034 printf (
"name from functionDeclaration->get_name(): name = %s \n",name.str());
27036 printf (
"name from templateInstantiationMemberFunctionDecl->get_templateName(): template_name = %s \n",templateInstantiationMemberFunctionDecl->
get_templateName().str());
27038 if (templateDeclaration != NULL)
27040 printf (
"name from templateInstantiationMemberFunctionDecl->get_template_declaration()->get_name(): template_name = %s \n",templateDeclaration->get_name().str());
27041 printf (
"name from templateInstantiationMemberFunctionDecl->get_template_declaration()->get_template_name(): template_name = %s \n",templateDeclaration->
get_template_name().str());
27048 printf (
"In case V_SgTemplateInstantiationMemberFunctionDecl: using name = %s \n",name.str());
27053 case V_SgMemberFunctionDeclaration:
27056 printf (
"This function to replace the defining declaration with a non-defining declaration does not yet support member functions \n");
27059 ROSE_ASSERT(original_memberFunctionDeclaration != NULL);
27067 unsigned int functionConstVolatileFlags = 0;
27069 ROSE_ASSERT(original_memberFunctionDeclaration->get_type() != NULL);
27078 bool buildPrototype = isTemplateInstantiationMemberFunctionDecl || original_memberFunctionDeclaration->
get_parent() == original_memberFunctionDeclaration->
get_scope();
27080 printf (
"In SageInterface::buildFunctionPrototype(): buildPrototype = %s \n",buildPrototype ?
"true" :
"false");
27082 if (buildPrototype ==
true)
27084 SgMemberFunctionType* memberFunctionType = isSgMemberFunctionType(original_memberFunctionDeclaration->get_type());
27085 ROSE_ASSERT(memberFunctionType != NULL);
27087 printf (
"original_memberFunctionDeclaration->get_parent() == original_memberFunctionDeclaration->get_scope() \n");
27089 functionConstVolatileFlags = memberFunctionType->get_mfunc_specifier();
27091 memberFunctionDeclaration =
27093 ( name, return_type, param_list, scope, python_decoratorList, functionConstVolatileFlags,
27094 buildTemplateInstantiation,templateArgumentsList );
27096 printf (
"ERROR: Member functions are not yet supported! \n");
27100 if (isConstructor ==
true)
27102 memberFunctionDeclaration->get_specialFunctionModifier().setConstructor();
27105 nondefiningFunctionDeclaration = memberFunctionDeclaration;
27107 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27113 printf (
"NOTE: Member functions defined outside of their class can not be output as member function prototypes (not allowed in C++) \n");
27117 nondefiningFunctionDeclaration = NULL;
27119 nondefiningFunctionDeclaration = NULL;
27121 replaceWithEmptyDeclaration =
true;
27123 ROSE_ASSERT(emptyDeclaration != NULL);
27132 printf (
"Exiting as a test! \n");
27142 case V_SgFunctionDeclaration:
27145 nondefiningFunctionDeclaration =
buildNondefiningFunctionDeclaration (name, return_type, param_list, scope, python_decoratorList, buildTemplateInstantiation,templateArgumentsList);
27146 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27151 case V_SgTemplateInstantiationFunctionDecl:
27154 buildTemplateInstantiation =
true;
27156 ROSE_ASSERT(templateInstantiationFunctionDecl != NULL);
27159 printf (
"name from functionDeclaration->get_name(): name = %s \n",name.str());
27161 printf (
"name from templateInstantiationFunctionDecl->get_templateName(): template_name = %s \n",templateInstantiationFunctionDecl->
get_templateName().str());
27163 if (templateDeclaration != NULL)
27165 printf (
"name from templateInstantiationFunctionDecl->get_template_declaration()->get_name(): template_name = %s \n",templateDeclaration->get_name().str());
27166 printf (
"name from templateInstantiationFunctionDecl->get_template_declaration()->get_template_name(): template_name = %s \n",templateDeclaration->
get_template_name().str());
27171 printf (
"In case V_SgTemplateInstantiationFunctionDecl: using name = %s \n",name.str());
27173 nondefiningFunctionDeclaration =
buildNondefiningFunctionDeclaration (name, return_type, param_list, scope, python_decoratorList, buildTemplateInstantiation,templateArgumentsList);
27174 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27193 ROSE_ASSERT(param_list == NULL || param_list->
get_parent() != NULL);
27199 if (nondefiningFunctionDeclaration != NULL)
27204 printf (
"Setting the firstNondefiningDeclaration \n");
27212 printf (
"Setting the definingDeclaration \n");
27221 if (nondefiningFunctionDeclaration != NULL)
27231 return nondefiningFunctionDeclaration;
27240 ROSE_ASSERT(functionDeclaration != NULL);
27243 printf (
"****************************************************************** \n");
27244 printf (
"Attached comments and CPP directives: defining functionDeclaration \n");
27246 printf (
"****************************************************************** \n");
27254 if (nondefiningFunctionDeclaration != NULL)
27265 if (templateInstantiationFunctionDecl == NULL)
27267 if (nondefiningFunctionDeclaration != NULL)
27270 nondefiningFunctionDeclaration->get_declarationModifier() = functionDeclaration->get_declarationModifier();
27273 nondefiningFunctionDeclaration->get_functionModifier() = functionDeclaration->get_functionModifier();
27274 nondefiningFunctionDeclaration->get_specialFunctionModifier() = functionDeclaration->get_specialFunctionModifier();
27276 nondefiningFunctionDeclaration->set_linkage( functionDeclaration->get_linkage() );
27277 nondefiningFunctionDeclaration->set_externBrace( functionDeclaration->get_externBrace() );
27279 ROSE_ASSERT(nondefiningFunctionDeclaration->get_forward() ==
true);
27282 int file_id = functionDeclaration->
get_file_info()->get_physical_file_id();
27283 nondefiningFunctionDeclaration->
get_file_info()->set_physical_file_id(file_id);
27299 ROSE_ASSERT(nondefiningFunctionDeclaration->
get_parent() != NULL);
27305 nondefiningFunctionDeclaration = NULL;
27309 if (functionDeclaration->get_declarationModifier().get_storageModifier().
isStatic() ==
true)
27311 ROSE_ASSERT(nondefiningFunctionDeclaration->get_declarationModifier().get_storageModifier().
isStatic() ==
true);
27315 return nondefiningFunctionDeclaration;
27319std::vector<SgFunctionDeclaration*>
27331 std::vector<SgFunctionDeclaration*> functionList;
27332 FunctionDefinitionsTraversal() {}
27334 void visit (
SgNode* node)
27337 if (functionDeclaration != NULL)
27343 if (functionDeclaration == definingFunctionDeclaration)
27347 if (functionDeclarationScope != NULL)
27349 functionList.push_back(functionDeclaration);
27357 FunctionDefinitionsTraversal traversal;
27359 traversal.traverseWithinFile(node, preorder);
27361 std::vector<SgFunctionDeclaration*> & functionList = traversal.functionList;
27363 return functionList;
27370 ROSE_ASSERT(node != NULL);
27373 std::vector<SgFunctionDeclaration*>::iterator i = functionList.begin();
27375 while (i != functionList.end())
27378 ROSE_ASSERT(functionDeclaration != NULL);
27396 ROSE_ASSERT(node !=
nullptr);
27402 void visit (
SgNode* node)
27405 if (variableDeclaration != NULL)
27408 SgExpression* initializer = initializedName->get_initializer();
27410 printf (
"variableDeclaration = %p initializedName = %p = %s initializer = %p \n",
27411 variableDeclaration,initializedName,initializedName->get_name().str(),initializer);
27413 if (initializer != NULL)
27415 printf (
" --- initializer = %s \n",initializer->
class_name().c_str());
27422 CheckInitializerTraversal traversal;
27423 traversal.traverse(node, preorder);
27431 void setResult(
SgType*) { }
27433 void handle(
SgNode& n,
SgNode&) { SG_UNEXPECTED_NODE(n); }
27435 template <
class SageDeclarationStatement>
27441 setResult(n.get_type());
27444 template <
class SageNode>
27445 void handle(SageNode& n)
27458 SgGlobal * gsaf = project->get_globalScopeAcrossFiles();
27459 ROSE_ASSERT(gsaf !=
nullptr);
27461 ROSE_ASSERT(st !=
nullptr);
27463 ROSE_ASSERT(hmm !=
nullptr);
27467 ROSE_ASSERT(st !=
nullptr);
27468 hmm = st->get_table();
27469 ROSE_ASSERT(hmm !=
nullptr);
27473 ROSE_ASSERT(st !=
nullptr);
27474 hmm = st->get_table();
27475 ROSE_ASSERT(hmm !=
nullptr);
27495 int match_count = 0;
27496 ROSE_ASSERT (root);
27500 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(root, V_SgArrowExp);
27504 boost::unordered::unordered_map <SgNode*, bool> visited;
27507 for (Rose_STL_Container<SgNode *>::reverse_iterator i = nodeList.rbegin(); i != nodeList.rend(); i++)
27510 if (visited.count(*i)==1)
27519 cerr<<
"SageInterface::normalizeArrowExpWithAddressOfLeftOperand() expects SgArrowExp while encountering "<<(*i)->class_name()<<
"@"<<(*i) <<endl;
27520 ROSE_ASSERT (a_exp);
27523 if (transformationGeneratedOnly)
27531 if (
SgVarRefExp* left = isSgVarRefExp(address_op->get_operand()))
27544 return match_count;
27554 Traversal() : found(
false) {}
27555 void visit (
SgNode* node)
27557 SgCastExp* castExpression = isSgCastExp(node);
27558 if (castExpression != NULL)
27562 if (initializer == NULL)
27567 printf (
" --- Found a SgCastExp marked as a transformation: castExpression = %p \n",castExpression);
27570 printf (
"Exiting as a test! \n");
27571 ROSE_ASSERT(
false);
27577 printf (
" --- SgCastExp (but not marked as a transformation) node = %p = %s \n",node,node->
class_name().c_str());
27585 printf (
" --- SgCastExp (but from an initializer) node = %p = %s \n",node,node->
class_name().c_str());
27592 printf (
" --- node = %p = %s \n",node,node->
class_name().c_str());
27599 printf (
"In findFirstSgCastExpMarkedAsTransformation(): s = %s \n",s.c_str());
27603 Traversal traversal;
27604 traversal.traverse(n, preorder);
27607 printf (
"In findFirstSgCastExpMarkedAsTransformation(): s = %s traversal.found = %s \n",s.c_str(),traversal.found ?
"true" :
"false");
27611 if (traversal.found ==
true)
27613 printf (
"In findFirstSgCastExpMarkedAsTransformation(): returning false \n");
27618 return traversal.found;
27629 ROSE_ASSERT (info != NULL);
27630 PreprocessingInfo::DirectiveType dtype= info->getTypeOfDirective();
27631 if (dtype == PreprocessingInfo::CpreprocessorIfdefDeclaration ||
27632 dtype == PreprocessingInfo::CpreprocessorIfndefDeclaration ||
27633 dtype == PreprocessingInfo::CpreprocessorIfDeclaration )
27637 else if (dtype==PreprocessingInfo::CpreprocessorElseDeclaration||
27638 dtype==PreprocessingInfo::CpreprocessorElifDeclaration)
27642 else if (dtype==PreprocessingInfo::CpreprocessorEndifDeclaration)
27651static void moveInofListToNewPlace(AttachedPreprocessingInfoType* infoList,
int cidx, set <AttachedPreprocessingInfoType*>& relatedInfoList,
SgLocatedNode* lnode,
int &retVal)
27656 relatedInfoList.insert (infoList);
27660 info->setRelativePosition(PreprocessingInfo::after);
27667 (*infoList)[cidx]= NULL;
27674 ROSE_ASSERT(lnode);
27680 vector < pair< AttachedPreprocessingInfoType*, int> > empty_entries;
27681 for(;ast_i!=ast.
end();++ast_i) {
27683 if (current ==NULL )
27687 if (infoList == NULL)
continue;
27689 int commentIndex=0;
27690 for (Rose_STL_Container<PreprocessingInfo*>::iterator ci = (*infoList).begin(); ci != (*infoList).end(); ci++)
27696 empty_entries.push_back( make_pair (infoList, commentIndex) );
27702 for (
auto ki = empty_entries.rbegin(); ki != empty_entries.rend(); ki ++)
27704 AttachedPreprocessingInfoType* infoList = (*ki).first;
27705 int cidx= (*ki).second;
27708 ROSE_ASSERT (info==NULL);
27711 AttachedPreprocessingInfoType::iterator k = infoList->begin();
27712 infoList->erase(k+cidx);
27722static std::unordered_map <PreprocessingInfo*, SageInterface::PreprocessingInfoData> infoMap;
27727 if (current == NULL)
27733 vector<PreprocessingInfo*> afterList;
27736 AttachedPreprocessingInfoType* comments = locatedNode->getAttachedPreprocessingInfo();
27738 if (comments !=
nullptr)
27740 AttachedPreprocessingInfoType::iterator i;
27742 for (i = comments->begin (); i != comments->end (); i++)
27748 data.container=comments;
27750 data.depth = depth;
27753 if (info->getRelativePosition () == PreprocessingInfo::before||
27754 info->getRelativePosition () == PreprocessingInfo::inside)
27756 infoList.push_back (info);
27757 infoMap[info] = data;
27759 else if (info->getRelativePosition () == PreprocessingInfo::after)
27761 afterList.push_back (info);
27762 infoMap[info] = data;
27766 cerr<<
"Warning: unhandled relative position value:" <<info->getRelativePosition () <<endl;
27777 for (
auto c: children)
27781 for (
auto fi : afterList)
27782 infoList.push_back(fi);
27796 ROSE_ASSERT(lnode);
27812 vector < pair< AttachedPreprocessingInfoType*, int> > keepers;
27816 unordered_map < PreprocessingInfo * , vector< pair<AttachedPreprocessingInfoType*, int>> > associated_directives;
27821 vector< pair<AttachedPreprocessingInfoType*, int>> associated_erase;
27829 vector<PreprocessingInfo*> candidateInfoList;
27834 for (
auto candidate: candidateInfoList)
27841 if (infoMap[info].depth ==0)
27844 int commentIndex = infoMap[info].index;
27845 AttachedPreprocessingInfoType* infoList = infoMap[info].container;
27848 if ( isBeginDirective(info) == 1)
27850 keepers.push_back(make_pair (infoList,commentIndex));
27853 else if (isBeginDirective(info) == 2)
27858 if (keepers.size()==0)
27859 keepers.push_back(make_pair (infoList, commentIndex));
27860 else if (isBeginDirective( (*(keepers.back().first))[keepers.back().second] )!=1 )
27862 keepers.push_back(make_pair (infoList,commentIndex));
27864 else if(isBeginDirective( (*(keepers.back().first))[keepers.back().second] )==1 )
27866 PreprocessingInfo* begin_info = (*(keepers.back().first))[keepers.back().second];
27868 associated_directives[begin_info].push_back(make_pair (infoList,commentIndex));
27872 else if ( isBeginDirective(info) == -1)
27874 bool neutralized =
false;
27876 if (keepers.size()>0)
27878 AttachedPreprocessingInfoType* comments = keepers.back().first;
27879 int idx = keepers.back().second;
27881 if(isBeginDirective( (*comments)[idx] )==1)
27883 keepers.pop_back();
27884 neutralized =
true;
27889 keepers.push_back(make_pair (infoList,commentIndex));
27897 for(;ast_i!=ast.
end();++ast_i) {
27899 if (current ==NULL )
27903 if (infoList == NULL)
continue;
27905 int commentIndex=0;
27906 for (Rose_STL_Container<PreprocessingInfo*>::iterator ci = (*infoList).begin(); ci != (*infoList).end(); ci++)
27908 ROSE_ASSERT(*ci != NULL);
27914 if ( isBeginDirective(info) == 1)
27916 keepers.push_back(make_pair (infoList,commentIndex));
27919 else if (isBeginDirective(info) == 2)
27924 if (keepers.size()==0)
27925 keepers.push_back(make_pair (infoList,commentIndex));
27926 else if (isBeginDirective( (*(keepers.back().first))[keepers.back().second] )!=1 )
27928 keepers.push_back(make_pair (infoList,commentIndex));
27930 else if(isBeginDirective( (*(keepers.back().first))[keepers.back().second] )==1 )
27932 PreprocessingInfo* begin_info = (*(keepers.back().first))[keepers.back().second];
27934 associated_directives[begin_info].push_back(make_pair (infoList,commentIndex));
27938 else if ( isBeginDirective(info) == -1)
27940 bool neutralized =
false;
27942 if (keepers.size()>0)
27944 AttachedPreprocessingInfoType* comments = keepers.back().first;
27945 int idx = keepers.back().second;
27947 if(isBeginDirective( (*comments)[idx] )==1)
27949 keepers.pop_back();
27950 neutralized =
true;
27955 keepers.push_back(make_pair (infoList,commentIndex));
27962 set <AttachedPreprocessingInfoType*> relatedInfoList;
27965 for (
auto ki = keepers.begin(); ki != keepers.end(); ki ++)
27967 AttachedPreprocessingInfoType* infoList = (*ki).first;
27968 int cidx= (*ki).second;
27970 relatedInfoList.insert (infoList);
27974 info->setRelativePosition(PreprocessingInfo::after);
27981 if (associated_directives.count (info)!=0)
27983 vector<pair<AttachedPreprocessingInfoType*,int>> a_list_vec = associated_directives[info];
27984 for (
auto vec_i = a_list_vec.rbegin(); vec_i != a_list_vec.rend(); vec_i ++ )
27986 AttachedPreprocessingInfoType* a_infoList = (*vec_i).first;
27987 int aidx= (*vec_i).second;
27988 moveInofListToNewPlace (a_infoList, aidx, relatedInfoList, lnode, retVal);
27989 associated_erase.push_back(make_pair (a_infoList, aidx));
27995 (*infoList)[cidx]= NULL;
to specify a construct using a specifier Can be used alone or with parent handles when relative speci...
virtual void * getNode() const
Get the raw IR node associated with the current abstract node.
Base class for all IR node attribute values.
Attribute Evaluator for synthesized attributes.
SynthesizedAttributeType traverse(SgNode *node)
evaluates attributes on the entire AST
Attribute storing an SgNode.
Class for traversing the AST.
void traverse(SgNode *node, Order treeTraversalOrder)
traverse the entire AST. Order defines preorder (preorder) or postorder (postorder) traversal....
void visit(SgNode *astNode)
this method is called at every traversed node.
void visit(SgNode *astNode)
visitor function for each node to collect non-builtin types' declarations
void visit(SgNode *astNode)
this method is called at every traversed node.
For preprocessing information including source comments, include , if, define, etc.
RelativePositionType
MK: Enum type to store if the directive goes before or after the corresponding line of source code.
Interface for iterating over an AST.
iterator begin()
Iterator positioned at root of subtree.
iterator end()
Iterator positioned at the end of the traversal.
const Digest & digest() override
Return the digest.
void insert(const std::string &x)
Insert data into the digest.
uint64_t make64Bits()
Returns the hash as a 64 bit int.
void visit(SgNode *node)
this method is called at every traversed node.
Interface for creating a statement whose computation writes its answer into a given variable.
A persistent attribute to represent a unique name for an expression.
SgName get_name() const override
Access function for getting name from declarations or types internally.
Base class for binary files.
SgAsmGenericHeaderList *const & get_headers() const
Property: List of all headers in file.
SgAsmInterpretationPtrList const & get_interpretations() const
Property: Interpretation list.
Represents an interpretation of a binary container.
This class represents the concept of a C Assembler statement.
This class represents the rhs of a variable declaration which includes an optional assignment (e....
void set_operand(SgExpression *exp)
This sets the rhs expression.
SgExpression * get_operand() const
Returns the rhs.
This class represents the concept of a block (not a basic block from control flow analysis).
const SgStatementPtrList & get_statements() const
Returns a const STL list by reference.
static void traverseMemoryPoolNodes(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
This class represents the notion of a binary operator. It is derived from a SgExpression because oper...
SgExpression * get_lhs_operand() const
returns SgExpression pointer to the lhs operand associated with this binary operator.
void set_rhs_operand(SgExpression *exp)
This function allows the p_rhs_operand pointer to be set (used internally).
void set_lhs_operand(SgExpression *exp)
This function allows the p_lhs_operand pointer to be set (used internally).
SgExpression * get_rhs_operand_i() const
returns SgExpression pointer to the operand associated with this binary operator.
SgExpression * get_lhs_operand_i() const
returns SgExpression pointer to the operand associated with this binary operator.
virtual VariantT variantT() const override
returns new style SageIII enum values
SgExpression * get_rhs_operand() const
returns SgExpression pointer to the rhs operand associated with this binary operator.
This class represents a boolean value (expression value).
This class represents the notion of a break statement (typically used in a switch statment).
virtual std::string class_name() const override
returns a string representing the class name
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of a C and C++ case option (used within a switch statement).
SgStatement * get_body() const
Returns pointer to a SgBasicBlock object.
void set_key(SgExpression *key)
Access function for pointer to SgExpression object wrapped by SgExpressionRoot in p_key_root.
void set_body(SgStatement *body)
Access function for p_body.
SgExpression * get_key() const
Returns pointer to a SgExpression object wrapped by SgExpressionRoot in p_key_root.
This class represents a cast of one type to another.
SgType * get_type() const override
unparsing support for pragmas
This class represents the concept of a catch within a try-catch construct used in C++ exception handl...
void set_body(SgStatement *body)
Access function for p_body.
SgStatement * get_body() const
Access function for p_body.
This class represents the concept of a class declaration statement. It includes the concept of an ins...
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual std::string class_name() const override
returns a string representing the class name
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
SgScopeStatement * get_scope() const override
Returns scope of current statement.
This class represents the concept of a class definition in C++.
SgClassDeclaration * get_declaration() const
returns the class declaration associated with this class decinition.
const SgDeclarationStatementPtrList & get_members() const
Returns a const list to the data member declarations.
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a C++ expression built from a class name.
SgClassSymbol * get_symbol() const
Returns pointer to SgSymbol.
This class represents the concept of a class name within the compiler.
SgName get_name() const override
Access function for getting name from declarations or types internally.
virtual std::string class_name() const override
returns a string representing the class name
virtual VariantT variantT() const override
returns new style SageIII enum values
static SgClassType * createType(SgDeclarationStatement *decl=NULL, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgClassType (types whose constructors take par...
This class represents the concept of a C trinary conditional expression (e.g. "test ?...
SgExpression * get_true_exp() const
Access function for p_true_exp.
void set_false_exp(SgExpression *false_exp)
Access function for p_false_exp.
SgExpression * get_conditional_exp() const
Access function for p_conditional_exp.
SgExpression * get_false_exp() const
Access function for p_false_exp.
void set_true_exp(SgExpression *true_exp)
Access function for p_true_exp.
void set_conditional_exp(SgExpression *conditional_exp)
Access function for p_conditional_exp.
This class represents the call of a class constructor to initialize a variable. For example "Foo foo;...
SgType * get_expression_type() const
Access function for p_expression_type, returns pointer to SgType associated with constructor.
This class represents the concept of a C or C++ continue statement.
Supporting class from copy mechanism within ROSE.
This class represents the concept of a contructor initializer list (used in constructor (member funct...
bool isFriend() const
declaration modifier is friend.
This class represents the concept of a declaration statement.
SgSymbol * search_for_symbol_from_symbol_table() const
User interface for retrieving the associated symbol from the declaration.
void set_definingDeclaration(SgDeclarationStatement *definingDeclaration)
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
void set_firstNondefiningDeclaration(SgDeclarationStatement *firstNondefiningDeclaration)
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
SgDeclarationStatement * get_definingDeclaration() const
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
virtual VariantT variantT() const override
returns new style SageIII enum values
virtual std::string class_name() const override
returns a string representing the class name
bool isForward() const
Returns boolean value indicating if this is a forward declaration.
SgDeclarationStatement * get_firstNondefiningDeclaration() const
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
bool hasAssociatedSymbol() const
Returns boolean value true of this type of declaration has an associated sysmbol.
SgName get_template_name() const
This function returns the template name (taken from the template declaration for the class,...
This class represents the concept of a C or C++ default case within a switch statement.
void set_body(SgStatement *body)
Access function for p_body.
SgStatement * get_body() const
Returns pointer to SgBasicBlock.
This class represents a directory within a projects file structure of files and directories.
This class represents the concept of a do-while statement.
SgStatement * get_condition() const
Access function for p_condition.
SgStatement * get_body() const
Access function for p_body.
void set_condition(SgStatement *condition)
Access function for p_condition.
void set_body(SgStatement *body)
Access function for p_body.
This class represents the notion of an value (expression value).
This class represents the concept of an enum declaration.
SgScopeStatement * get_scope() const override
Access function for p_scope.
SgName get_name() const
Access function for p_name.
void set_scope(SgScopeStatement *scope) override
Access function for p_scope.
const SgInitializedNamePtrList & get_enumerators() const
Access function for p_enumerators.
This class represents the concept of a C and C++ expression list.
int replace_expression(SgExpression *o, SgExpression *n) override
This class represents the base class of all the expressions within this grammar.
This class represents the concept of a C or C++ statement which contains a expression.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
virtual std::string class_name() const override
returns a string representing the class name
void set_need_paren(bool need_paren)
This function allows the p_need_paren flag to be set (used internally).
virtual VariantT variantT() const override
returns new style SageIII enum values
virtual SgType * get_type() const
unparsing support for pragmas
virtual int replace_expression(SgExpression *oldChild, SgExpression *newChild)
This class represents the base class of all the expressions within this grammar.
virtual const char * sage_class_name() const override
virtual Sg_File_Info * get_file_info(void) const override
Interface function to implement original SAGE interface to SgFile_Info objects.
void set_lvalue(bool lvalue)
This function allows the p_lvalue flag to be set (used internally).
bool get_lvalue() const
Returns a bool value if the current expression is assigned to.
This class represents a source file for a project (which may contian many source files and or directo...
std::string getFileName() const
associated filename
Sg_File_Info * get_file_info() const override
Access function calling get_startOfConstruct(), provided to support older interface.
This class represents the notion of an value (expression value).
This class represents the variable declaration or variable initialization withn a for loop.
const SgStatementPtrList & get_init_stmt() const
Returns const reference to a SgStatementPtrList (typedef to a STL list).
This class represents the concept of a for loop.
SgExpression * get_test_expr() const
Access function for p_test_expr_root.
SgForInitStatement * get_for_init_stmt() const
Access function for p_for_init_stmt.
void set_loop_body(SgStatement *loop_body)
Access function for p_loop_body.
SgStatement * get_loop_body() const
Access function for p_loop_body.
void set_for_init_stmt(SgForInitStatement *for_init_stmt)
Access function for p_for_init_stmt.
This class represents the concept of a C++ function call (which is an expression).
SgFunctionSymbol * getAssociatedFunctionSymbol() const
Returns the associated function symbol, if it can be resolved statically.
SgFunctionDeclaration * getAssociatedFunctionDeclaration() const
Returns the associated function declaration, if it can be resolved statically.
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a function declaration statement.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
bool isTemplateFunction() const
Determines if function is a template or non-template function.
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual std::string class_name() const override
returns a string representing the class name
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
virtual std::string class_name() const override
returns a string representing the class name
SgBasicBlock * get_body() const
Access function for p_body.
This class represents the concept of a declaration list.
const SgInitializedNamePtrList & get_args() const
Access function for p_args.
const SgTypePtrList & get_arguments() const
Get a const list of input types (types of the parameters list) to this function type (from a cost fun...
This class represents the function being called and must be assembled in the SgFunctionCall with the ...
SgFunctionDeclaration * getAssociatedFunctionDeclaration() const
Returns the associated function declaration, if it can be resolved statically.
SgName get_name() const override
Access function for getting name from declarations or types internally.
This class represents the function type table (stores all function types so that they can be shared i...
SgSymbolTable * get_function_type_table() const
Returns pointer to SgSymbolTable used for function type symbols only.
This class represents a type for all functions.
virtual std::string class_name() const override
returns a string representing the class name
const SgTypePtrList & get_arguments() const
This is a const convience access function to the STL container of types in the child IR node (SgFunct...
virtual SgName get_mangled(void) const override
Mangled name support for unparser support.
This class represents the concept of a namespace definition.
virtual std::string class_name() const override
returns a string representing the class name
const SgDeclarationStatementPtrList & get_declarations() const
Returns a const list to the global scope declarations.
This class represents the concept of a C or C++ goto statement.
SgLabelStatement * get_label() const
Returns pointer to SgLabelStatement where control flow will be transfered during execution.
void set_label(SgLabelStatement *label)
Access function for p_label.
InheritedAttributeType traverse(SgGraphNode *basenode, SgIncidenceDirectedGraph *g, InheritedAttributeType inheritedValue, InheritedAttributeType nullInherit, SgGraphNode *endnode, bool insep=false, bool pcHk=false)
This is the function that is used by the user directly to start the algorithm.
This class represents the concept of an "if" construct.
void set_false_body(SgStatement *false_body)
Access function for p_false_body.
virtual std::string class_name() const override
returns a string representing the class name
void set_true_body(SgStatement *true_body)
Access function for p_true_body.
SgStatement * get_conditional() const
Access function for p_conditional.
SgStatement * get_true_body() const
Access function for p_true_body.
SgStatement * get_false_body() const
Access function for p_false_body.
void set_conditional(SgStatement *conditional)
Access function for p_conditional.
This class represents the notion of a declared variable.
SgName get_qualified_name() const
Returns the name with appropriate qualified names representing nested scopes.
SgSymbol * get_symbol_from_symbol_table() const
Get the associated SgSymbol from the symbol table located in the scope, without considering possible ...
virtual std::string class_name() const override
returns a string representing the class name
SgDeclarationStatement * get_declaration() const
Equal operator : it checks if all the data members are the same or point to the same objects.
This class represents the notion of an initializer for a variable declaration or expression in a func...
This class represents the concept of a C or C++ label statement.
SgName get_label() const
Returns SgName by value.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
label_type_enum
Type of label used (fortran only)
SgName get_name() const override
Access function for getting name from declarations or types internally.
virtual std::string class_name() const override
returns a string representing the class name
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the notion of an expression or statement which has a position within the source...
virtual std::string class_name() const override
returns a string representing the class name
virtual const char * sage_class_name() const override
Sg_File_Info * get_endOfConstruct() const override
New function interface for Sg_File_Info data stores ending location of contruct (typically the closin...
void setTransformation()
Allow IR nodes (mostly SgLocatedNode) to be marked as a transformation.
virtual void addNewAttribute(std::string s, AstAttribute *a) override
Add a new attribute represented by the named string.
void set_endOfConstruct(Sg_File_Info *endOfConstruct)
This function sets the current source location position of the end of the current construct.
Sg_File_Info * get_startOfConstruct() const override
New function interface for Sg_File_Info data stores starting location of contruct (typically the open...
void addToAttachedPreprocessingInfo(PreprocessingInfo *prepInfoPtr, PreprocessingInfo::RelativePositionType locationInList=PreprocessingInfo::after)
This function adds comment or CPP directives to the current IR node.
virtual AstAttribute * getAttribute(std::string s) const override
Returns attribute of name 's'.
void set_startOfConstruct(Sg_File_Info *startOfConstruct)
This function sets the current source location position of the start of the current construct.
bool isCompilerGenerated() const
Simple test for if this is a compiler generated node.
void insertToAttachedPreprocessingInfo(PreprocessingInfo *prepInfoPtr, PreprocessingInfo *anchorInfoPtr, bool insertAfter=true)
Insert prepInfo After (or before if last parameter is false) an anchor info ptr in the list of prepro...
virtual VariantT variantT() const override
returns new style SageIII enum values
void setOutputInCodeGeneration()
Allow IR nodes (mostly SgLocatedNode) to be marked as to when the information was unavilable in the f...
virtual Sg_File_Info * get_file_info() const override
Interface function to implement original SAGE interface to SgFile_Info objects.
bool isTransformation() const
Simple test for if this is a part of a transformation.
AttachedPreprocessingInfoType *& getAttachedPreprocessingInfo(void)
Computes the number of nodes in the defined subtree of the AST.
This class represents the notion of an value (expression value).
This class represents the concept of a member function declaration statement.
virtual std::string class_name() const override
returns a string representing the class name
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the member function being called and must be assembled in the SgFunctionCall wi...
SgMemberFunctionDeclaration * getAssociatedMemberFunctionDeclaration() const
This is helpful in chasing down the associated declaration to this member function reference.
SgName get_name() const override
Access function for getting name from declarations or types internally.
SgTypeModifier & get_typeModifier()
Access function for modifier.
This class represents strings within the IR nodes.
virtual SgName get_name() const
Gets name of the type (useful for debugging, unparsing, etc.)
SgName get_qualified_name() const
Used for the SgNamedType object (base class for the SgClassType, SgTypedefType and the SgEnumType obj...
This class represents the concept of a C++ namespace alias declaration statement.
SgName get_name() const
Access function for p_name.
SgNamespaceDeclarationStatement * get_namespaceDeclaration() const
Access function for p_namespaceDeclaration.
This class represents the concept of a C++ namespace declaration.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
SgName get_name() const
Access function for p_name.
SgNamespaceDefinitionStatement * get_definition() const
Returns pointer to SgNamespaceDefinitionStatement.
This class represents the concept of a namespace definition.
This class represents the concept of a namespace name within the compiler.
This class represents the base class for all IR nodes within Sage III.
static SgTypeTable * get_globalTypeTable()
Access function for symbol table specific to non-function types.
virtual std::vector< std::string > get_traversalSuccessorNamesContainer()
container of names of variables or container indices used used in the traversal to access AST success...
SgNode * get_parent() const
Access function for parent node.
void set_isModified(bool isModified)
All nodes in the AST contain a isModified flag used to track changes to the AST.
virtual VariantT variantT() const
returns new style SageIII enum values
void set_parent(SgNode *parent)
All nodes in the AST contain a reference to a parent node.
virtual std::string unparseToString(SgUnparse_Info *info) const
This function unparses the AST node (excluding comments and unnecessary white space)
virtual std::vector< SgNode * > get_traversalSuccessorContainer()
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
virtual std::string class_name() const
returns a string representing the class name
static std::map< SgNode *, std::string > & get_globalMangledNameMap()
Access function for performance optimizing global mangled name map.
virtual void checkDataMemberPointersIfInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
virtual AstAttribute * getAttribute(std::string s) const
Returns attribute of name 's'.
static SgFunctionTypeTable * get_globalFunctionTypeTable()
Access function for symbol table specific to function types.
virtual Sg_File_Info * get_file_info(void) const
File information containing filename, line number, column number, and if the SgNode is a part of a ne...
virtual bool attributeExists(std::string s) const
Tests if attribute of name 's' is present.
virtual std::vector< std::pair< SgNode *, std::string > > returnDataMemberPointers() const
FOR INTERNAL USE Returns STL vector of pairs of SgNode* and strings for use in AST tools
virtual void addNewAttribute(std::string s, AstAttribute *a)
Add a new attribute represented by the named string.
static std::map< std::string, uint64_t > & get_shortMangledNameCache()
Access function for lower level optimizing of global mangled name map.
bool get_isModified() const
Acess function for isModified flag.
SgName get_name() const override
Support for some classes which have pure virtual function in base classes.
This class represents the concept of a C Assembler statement (untested).
Sg_File_Info * get_startOfConstruct() const override
New function interface for Sg_File_Info data stores starting location of contruct (typically the open...
This class represents a source project, with a list of SgFile objects and global information about th...
std::vector< std::string > getAbsolutePathFileNames() const
This function generates a list of files resolved to absolute paths (symbolic links should not be reso...
static void visitRepresentativeNode(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for type-based traversal.
static int get_verbose(void)
DQ: Modified to accept a value on the command line (no longer a boolean variable) value of 0 means qu...
This class represents a OLD concept of the structure require for qualified names when they were in th...
This class represents the concept of a C Assembler statement (untested).
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
bool supportsDefiningFunctionDeclaration()
Reports if scope can support defining function declarations. Not all scopes permit function declarati...
const SgStatementPtrList generateStatementList() const
Generate s list of statements from either the existing list of statements or the list of declarations...
bool isNamedScope()
Some scopes have associated names for purposed of name qualification. This returns true if the scope ...
SgSymbolTable * get_symbol_table() const
Returns a pointer to the locally strored SgSymbolTable.
virtual const char * sage_class_name() const override
SgDeclarationStatementPtrList & getDeclarationList()
Gets reference to internal STL list of pointers to SgDeclarationStatement objects (only defined for s...
SgStatementPtrList & getStatementList()
Gets reference to internal STL list of pointers to SgStatement objects (only defined for scopes conta...
void append_statement(SgStatement *stmt)
Higher level function to handle statements and declarations is scopes.
void set_symbol_table(SgSymbolTable *symbol_table)
Sets the pointer to the locally strored SgSymbolTable.
virtual std::string class_name() const override
returns a string representing the class name
bool statementExistsInScope(SgStatement *statement)
Test for existence of statement is scope.
bool containsOnlyDeclarations() const
This function is used to indicate if either the getDeclarationList() or getStatementList() can be cal...
void insert_symbol(const SgName &n, SgSymbol *s)
Puts a SgSymbol object into the local symbol table.
virtual VariantT variantT() const override
returns new style SageIII enum values
virtual SgName get_qualified_name() const
Returns SgName (a string) representing the name of the current scope.
This class represents the "sizeof()" operator (applied to any type).
static void traverseMemoryPoolNodes(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
This class represents the notion of a statement.
virtual std::string class_name() const override
returns a string representing the class name
void insert_statement(SgStatement *target, SgStatement *newstmt, bool inFront=true)
This function inserts a single statement at the position indicated by target.
virtual std::vector< SgNode * > get_traversalSuccessorContainer() override
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
virtual void set_scope(SgScopeStatement *newScope)
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
virtual bool hasExplicitScope() const
Support for where the scope is explicitly required.
virtual SgSymbol * get_symbol_from_symbol_table() const
Get the associated symbol from the symbol table in the stored scope.
virtual SgScopeStatement * get_scope(void) const
Returns scope of current statement.
void remove_statement(SgStatement *)
This function removes the target statement from the AST.
void replace_statement(SgStatement *target, SgStatement *newstmt)
This function replaces the target statement with a single statement.
virtual VariantT variantT() const override
returns new style SageIII enum values
bool isStatic() const
Storage modifier is static (always false for the SgStorageModifier in the SgInitializedName).
This class represents the base class of a numbr of IR nodes that don't otherwise fit into the existin...
virtual std::string class_name() const override
returns a string representing the class name
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of a switch.
void set_item_selector(SgStatement *item_selector)
Access function for p_item_selector.
SgStatement * get_body() const
Access function for p_body.
SgStatement * get_item_selector() const
Access function for p_item_selector_root.
void set_body(SgStatement *body)
Access function for p_body.
This class represents the symbol tables used in both SgScopeStatement and the SgFunctionTypeSymbolTab...
std::set< SgNode * > get_symbols() const
Complexity O(n)
void print(std::string label, VariantT nodeType=V_SgSymbol)
Outputs symbol table information (useful for debugging)
int size() const
Computes the number of symbols in the symbol table (forced to count them, I think,...
void remove(const SgSymbol *symbol)
Complexity O(n)
This class represents the concept of a name within the compiler.
virtual std::string class_name() const override
returns a string representing the class name
virtual VariantT variantT() const override
returns new style SageIII enum values
virtual SgName get_name() const =0
Access function for getting name from declarations or types internally.
virtual SgType * get_type() const =0
This function returns the type associated with the named entity.
This class represents template argument within the use of a template to build an instantiation.
SgExpression * get_expression() const
This function returns argumentExpression.
SgType * get_type() const
This function returns argumentType.
SgTemplateArgument::template_argument_enum get_argumentType() const
This function returns argumentType.
@ template_template_argument
@ start_of_pack_expansion_argument
This class represents the concept of a template declaration.
SgName get_string() const
Returns stringified template declaration.
virtual std::string class_name() const override
returns a string representing the class name
SgName get_name() const
Returns name of template declaration.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the concept of an instantiated class template.
virtual std::string class_name() const override
returns a string representing the class name
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
SgName get_templateName() const
Returns name of class template, the name excludes template arguments.
SgTemplateClassDeclaration * get_templateDeclaration() const
Returns pointer to SgTemplateDeclaration from which instantiation is generated.
This class represents the concept of a class definition in C++.
This class represents the concept of a C++ template instantiation directive.
SgDeclarationStatement * get_declaration() const
Returns pointer to SgDeclarationStatement.
This class represents the concept of an instantiation of function template.
virtual std::string class_name() const override
returns a string representing the class name
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgTemplateFunctionDeclaration * get_templateDeclaration() const
Returns pointer to SgTemplateDeclaration from which instantiation is generated.
SgName get_templateName() const
Returns name of instantiated function template, name includes template arguments.
This class represents the concept of an instantiation of member function template or a member functio...
virtual std::string class_name() const override
returns a string representing the class name
const SgTemplateArgumentPtrList & get_templateArguments() const
Returns pointer to STL list of pointers to SgTemplateArgument objects.
SgName get_templateName() const
Returns name of instantiated function template, name includes template arguments.
SgTemplateMemberFunctionDeclaration * get_templateDeclaration() const
Returns pointer to SgTemplateDeclaration from which instantiation is generated.
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the "this" operator (can be applied to any member data).
Supporting class for "Deep" copies of the AST.
static SgTypeBool * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeInt * createType(int sz=0, SgExpression *optional_fortran_type_kind=NULL)
more sophisticated version for more complex types like SgTypeInt (types whose constructors take param...
static SgTypeUnknown * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
static SgTypeVoid * createType(SgExpression *optional_fortran_type_kind=nullptr)
example of type used where construction is particularly simple
This class represents the base class for all types.
std::vector< SgType * > getInternalTypes() const
Generate a container of types hidden in the input type.
SgType * stripType(unsigned char bit_array=STRIP_MODIFIER_TYPE|STRIP_REFERENCE_TYPE|STRIP_RVALUE_REFERENCE_TYPE|STRIP_POINTER_TYPE|STRIP_ARRAY_TYPE|STRIP_TYPEDEF_TYPE|STRIP_POINTER_MEMBER_TYPE) const
Returns hidden type beneath layers of typedefs, pointers, references, modifiers, array representation...
virtual std::string class_name() const override
returns a string representing the class name
virtual VariantT variantT() const override
returns new style SageIII enum values
This class represents the notion of a typedef declaration.
SgScopeStatement * get_scope() const override
Returns scope of current statement.
virtual SgSymbol * get_symbol_from_symbol_table() const override
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope....
SgDeclarationStatement * get_baseTypeDefiningDeclaration() const
Returns the defining declaration if get_typedefBaseTypeContainsDefiningDeclaration() is true,...
void set_scope(SgScopeStatement *scope) override
Support for setting scopes (only meaningful on IR statements that store the scope explicitly).
SgType * get_base_type() const
This is used in the SgTypedefType object (is not associated with a base_type data field)
void set_operand_i(SgExpression *operand_i)
This function allows the p_operand_i pointer to be set (used internally).
SgExpression * get_operand() const
returns SgExpression pointer to the operand associated with this unary operator.
This class represents the concept of a C++ using declaration.
SgDeclarationStatement * get_declaration() const
Access function for p_declaration.
SgInitializedName * get_initializedName() const
Access function for p_initializedName.
This class represents the concept of a C++ using directive.
SgNamespaceDeclarationStatement * get_namespaceDeclaration() const
Access function for p_namespaceDeclaration.
This class represents the notion of an value (expression value).
virtual VariantT variantT() const override
returns new style SageIII enum values
virtual std::string class_name() const override
returns a string representing the class name
This class represents the variable refernece in expressions.
static void traverseMemoryPoolNodes(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
This class represents the concept of a C or C++ variable declaration.
const SgInitializedNamePtrList & get_variables() const
Access function for p_variables.
SgDeclarationStatement * get_baseTypeDefiningDeclaration() const
Returns the defining declaration if get_variableDeclarationContainsBaseTypeDefiningDeclaration() is t...
bool get_variableDeclarationContainsBaseTypeDefiningDeclaration() const
Access function for p_variableDeclarationContainsBaseTypeDefiningDeclaration.
This class represents the definition (initialization) of a variable.
SgInitializedName * get_vardefn() const
Access function for SgInitializedName stored in p_vardefn.
This class represents the concept of a variable name within the compiler (a shared container for the ...
virtual std::string class_name() const override
returns a string representing the class name
SgName get_name() const override
Access function for getting name from declarations or types internally.
This class represents the concept of a do-while statement.
SgStatement * get_condition() const
Access function for p_condition.
void set_condition(SgStatement *condition)
Access function for p_condition.
SgStatement * get_body() const
Access function for p_body.
void set_body(SgStatement *body)
Access function for p_body.
This class represents the location of the code associated with the IR node in the original source cod...
void setTransformation()
Marks an IR node to be a transformation if it is not one already.
const char * get_filename() const
Returns filename of source code associated with IR node.
bool isOutputInCodeGeneration() const
Returns true only if required to be unparsed in generated code.
int get_line() const
Returns the line number of the associated code for this IR node.
bool isCompilerGenerated() const
Returns true only if compiler generated (either by the front-end or by ROSE).
int get_col() const
Returns the column number of the associated code for this IR node.
static Sg_File_Info * generateDefaultFileInfoForTransformationNode()
Static function to return new Sg_File_Info object set to default values appropriate for transformatio...
bool isTransformation() const
Access function for classification bit field.
bool isShared() const
Returns true only if shared internally (either by the front-end or by ROSE).
static Sg_File_Info * generateDefaultFileInfo()
Static function to return new Sg_File_Info object set to default values.
void setOutputInCodeGeneration()
Marks IR node as compiler generated but required in the generated source (e.g. requied templates).
Hash table support for symbol tables within ROSE.
ROSE_DLL_API abstract_handle * buildAbstractHandle(SgNode *snode)
A default builder function handles all details: file use name, others use numbering
ROSE_DLL_API std::vector< std::string > generateSourceFilenames(std::vector< std::string > argList, bool binaryMode)
Build the list of isolated file names from the command line.
ROSE_UTIL_API void removeAllFileNamesExcept(std::vector< std::string > &argv, std::vector< std::string > filenameList, std::string exceptFilename)
Remove file names specified in filenameList from argv, except for 'exceptFilename'.
void edgePointerReplacement(replacement_map_t const &)
For all nodes in the memory pool, it looks for the edges in the replacement map. If a match is found ...
ROSE_DLL_API std::string toBase62String(uint64_t num)
Converts a 64 bit in to base 62 (All letters and numbers).
ROSE_DLL_API Sawyer::Message::Facility mlog
Diagnostic facility for the ROSE library as a whole.
void serialize(std::ostream &output, Graph &graph)
Serialize a graph into a stream of bytes.
ROSE_UTIL_API std::string stripFileSuffixFromFileName(const std::string &fileNameWithSuffix)
Get the file name without the ".suffix".
ROSE_UTIL_API std::string numberToString(long long)
Convert an integer to a string.
ROSE_UTIL_API std::string copyEdit(const std::string &inputString, const std::string &oldToken, const std::string &newToken)
Replace all occurrences of a string with another string.
ROSE_UTIL_API std::string stripPathFromFileName(const std::string &fileNameWithPath)
Returns the last component of a path in a filesystem.
SgStatement * getPreviousStatement(SgStatement *targetStatement, bool climbOutScope=true)
Functions to move to SgStatement object in SAGE III later.
Functions that build an AST.
ROSE_DLL_API SgAddOp * buildAddOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgFunctionDeclaration * buildNondefiningFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope=NULL, SgExprListExp *decoratorList=NULL, bool buildTemplateInstantiation=false, SgTemplateArgumentPtrList *templateArgumentsList=NULL, SgStorageModifier::storage_modifier_enum sm=SgStorageModifier::e_default)
Build a prototype for a function, handle function type, symbol etc transparently.
SourcePositionClassification
intended to be a private member, don't access it directly. could be changed any time
@ e_sourcePosition_last
Specify as source position to be filled in as part of AST construction in the front-end.
@ e_sourcePositionNullPointers
Classify as compiler generated code (e.g. template instantiation).
@ e_sourcePositionCompilerGenerated
Classify as a transformation.
@ e_sourcePositionFrontendConstruction
Set pointers to Sg_File_Info objects to NULL.
@ e_sourcePositionDefault
Error value for enum.
@ e_sourcePositionTransformation
Default source position.
ROSE_DLL_API SgPragma * buildPragma(const std::string &name)
Build SgPragma.
ROSE_DLL_API SourcePositionClassification getSourcePositionClassificationMode()
Get the current source position classification (defines how IR nodes built by the SageBuilder interfa...
ROSE_DLL_API SgEqualityOp * buildEqualityOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgTemplateMemberFunctionDeclaration * buildNondefiningTemplateMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, SgTemplateParameterPtrList *templateParameterList)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgLabelStatement * buildLabelStatement(const SgName &name, SgStatement *stmt=NULL, SgScopeStatement *scope=NULL)
Build a label statement, name is the label's name. Handling label symbol and scope internally.
ROSE_DLL_API SgAddressOfOp * buildAddressOfOp(SgExpression *op=NULL)
ROSE_DLL_API SgTemplateFunctionDeclaration * buildNondefiningTemplateFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope=NULL, SgExprListExp *decoratorList=NULL, SgTemplateParameterPtrList *templateParameterList=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgMultiplyOp * buildMultiplyOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgGotoStatement * buildGotoStatement(SgLabelStatement *label=NULL)
Build a goto statement.
ROSE_DLL_API std::string display(SourcePositionClassification &scp)
display function for debugging
ROSE_DLL_API SgLabelRefExp * buildLabelRefExp(SgLabelSymbol *s)
Build a Fortran numeric label ref exp.
ROSE_DLL_API SgLessOrEqualOp * buildLessOrEqualOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgSubtractOp * buildSubtractOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgMemberFunctionType * buildMemberFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList, SgScopeStatement *struct_name, unsigned int mfunc_specifier)
Built in simple types.
ROSE_DLL_API SgWhileStmt * buildWhileStmt(SgStatement *condition, SgStatement *body, SgStatement *else_body=NULL)
Build while statement.
ROSE_DLL_API SgForStatement * buildForStatement(SgStatement *initialize_stmt, SgStatement *test, SgExpression *increment, SgStatement *loop_body, SgStatement *else_body=NULL)
Build a for statement, assume none of the arguments is NULL.
ROSE_DLL_API SgEmptyDeclaration * buildEmptyDeclaration()
Build an empty declaration (useful for adding precission to comments and CPP handling under token-bas...
ROSE_DLL_API SgConditionalExp * buildConditionalExp(SgExpression *test=NULL, SgExpression *a=NULL, SgExpression *b=NULL)
Build a conditional expression ?:
ROSE_DLL_API SgTypeInt * buildIntType()
Built in simple types.
SourcePositionClassification SourcePositionClassificationMode
C++ SageBuilder namespace specific state for storage of the source code position state (used to contr...
ROSE_DLL_API SgMinusOp * buildMinusOp(SgExpression *op=NULL)
ROSE_DLL_API SgExprListExp * buildExprListExp(SgExpression *expr1=NULL, SgExpression *expr2=NULL, SgExpression *expr3=NULL, SgExpression *expr4=NULL, SgExpression *expr5=NULL, SgExpression *expr6=NULL, SgExpression *expr7=NULL, SgExpression *expr8=NULL, SgExpression *expr9=NULL, SgExpression *expr10=NULL)
Build a SgExprListExp, used for function call parameter list etc.
ROSE_DLL_API SgPlusAssignOp * buildPlusAssignOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgVarRefExp * buildVarRefExp(const SgName &name, SgScopeStatement *scope=NULL)
Build SgVarRefExp based on a variable's Sage name. It will lookup the name in the symbol table intern...
bool symbol_table_case_insensitive_semantics
Support for construction of case sensitive/insensitive symbol table handling in scopes.
ROSE_DLL_API SgDotExp * buildDotExp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgAssignInitializer * buildAssignInitializer(SgExpression *operand_i=NULL, SgType *expression_type=NULL)
Build the rhs of a variable declaration which includes an assignment.
ROSE_DLL_API SgArrayType * getUniqueJavaArrayType(SgType *, int)
Build a SgFile node and attach it to SgProject.
ROSE_DLL_API SgVariableDeclaration * buildVariableDeclaration(const SgName &name, SgType *type, SgInitializer *varInit=NULL, SgScopeStatement *scope=NULL)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgScopeStatement * topScopeStack()
intended to be a private member, don't access it directly. could be changed any time
ROSE_DLL_API SgNullExpression * buildNullExpression()
Build a null expression, set file info as the default one.
ROSE_DLL_API SgGreaterOrEqualOp * buildGreaterOrEqualOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgReferenceType * buildReferenceType(SgType *base_type=nullptr)
Build a reference type.
ROSE_DLL_API SgExprStatement * buildExprStatement(SgExpression *exp=NULL)
Build a SgExprStatement, set File_Info automatically.
ROSE_DLL_API SgIfStmt * buildIfStmt(SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Build if statement.
ROSE_DLL_API SgFunctionParameterList * buildFunctionParameterList(SgInitializedName *in1=NULL, SgInitializedName *in2=NULL, SgInitializedName *in3=NULL, SgInitializedName *in4=NULL, SgInitializedName *in5=NULL, SgInitializedName *in6=NULL, SgInitializedName *in7=NULL, SgInitializedName *in8=NULL, SgInitializedName *in9=NULL, SgInitializedName *in10=NULL)
Build an empty SgFunctionParameterList, possibly with some initialized names filled in.
ROSE_DLL_API SgPointerDerefExp * buildPointerDerefExp(SgExpression *op=NULL)
ROSE_DLL_API SgTypeBool * buildBoolType()
Built in simple types.
ROSE_DLL_API SgAssignOp * buildAssignOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgPointerType * buildPointerType(SgType *base_type=nullptr)
Build a pointer type.
ROSE_DLL_API SgBoolValExp * buildBoolValExp(int value=0)
Build a bool value expression, the name convention of SgBoolValExp is little different from others fo...
ROSE_DLL_API SgFunctionParameterTypeList * buildFunctionParameterTypeList(SgFunctionParameterList *paralist)
Build SgFunctionParameterTypeList from SgFunctionParameterList.
ROSE_DLL_API SgLessThanOp * buildLessThanOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgCastExp * buildCastExp(SgExpression *operand_i=NULL, SgType *expression_type=NULL, SgCastExp::cast_type_enum cast_type=SgCastExp::e_C_style_cast)
Build a type casting expression.
ROSE_DLL_API SgMinusAssignOp * buildMinusAssignOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgDivideOp * buildDivideOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgBasicBlock * buildBasicBlock(SgStatement *stmt1=NULL, SgStatement *stmt2=NULL, SgStatement *stmt3=NULL, SgStatement *stmt4=NULL, SgStatement *stmt5=NULL, SgStatement *stmt6=NULL, SgStatement *stmt7=NULL, SgStatement *stmt8=NULL, SgStatement *stmt9=NULL, SgStatement *stmt10=NULL)
Build a SgBasicBlock, setting file info internally.
ROSE_DLL_API SgModOp * buildModOp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgExprStatement * buildAssignStatement(SgExpression *lhs, SgExpression *rhs)
Build an assignment statement from lefthand operand and right hand operand.
ROSE_DLL_API SgMemberFunctionDeclaration * buildNondefiningMemberFunctionDeclaration(const SgName &name, SgType *return_type, SgFunctionParameterList *parlist, SgScopeStatement *scope, SgExprListExp *decoratorList, unsigned int functionConstVolatileFlags, bool buildTemplateInstantiation, SgTemplateArgumentPtrList *templateArgumentsList)
Build a prototype member function declaration.
ROSE_DLL_API SgMemberFunctionDeclaration * buildDefaultConstructor(SgClassType *classType)
Build a variable declaration, handle symbol table transparently.
ROSE_DLL_API SgCommaOpExp * buildCommaOpExp(SgExpression *lhs=NULL, SgExpression *rhs=NULL)
ROSE_DLL_API SgIntVal * buildIntVal(int value=0)
Build an integer value expression.
SgDeclarationStatement * associatedDeclaration(const SgSymbol &n)
returns the associated declaration for symbol n or nullptr if there is none.
Functions that are useful when operating on the AST.
ROSE_DLL_API void checkSgNodePointers()
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API bool isLastStatement(SgStatement *stmt)
Check if a statement is the last statement within its closed scope.
ROSE_DLL_API bool isUnionDeclaration(SgNode *node)
Check if a SgNode is a declaration for a union.
ROSE_DLL_API void translateScopeToUseCppDeclarations(SgScopeStatement *scope)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
void initializeIfStmt(SgIfStmt *ifstmt, SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void deepDelete(SgNode *root)
Deep delete a sub AST tree. It uses postorder traversal to delete each child node....
void annotateExpressionsWithUniqueNames(SgProject *project)
Generate unique names for expressions and attach the names as persistent attributes ("UniqueNameAttri...
ROSE_DLL_API bool hasMultipleInitStatmentsOrExpressions(SgForStatement *for_loop)
Check if a for loop uses C99 style initialization statement with multiple expressions like for (int i...
ROSE_DLL_API void fixNamespaceDeclaration(SgNamespaceDeclarationStatement *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
void serialize(SgNode *node, std::string &prefix, bool hasRemaining, std::ostringstream &out, std::string &edgeLabel)
we have two serialize() functions, one for a single node, the other for a list of pointers
ROSE_DLL_API void deleteExpressionTreeWithOriginalExpressionSubtrees(SgNode *root)
Special purpose function for deleting AST expression tress containing valid original expression trees...
void setSourcePositionAsTransformation(SgNode *node)
DQ (5/1/2012): New function with improved name.
ROSE_DLL_API void insertStatementList(SgStatement *targetStmt, const std::vector< SgStatement * > &newStmts, bool insertBefore=true)
Insert a list of statements before or after the target statement within the.
void whereAmI(SgNode *node)
Diagnostic function for tracing back through the parent list to understand at runtime where in the AS...
ROSE_DLL_API SgStatement * getLastStatement(SgScopeStatement *scope)
get the last statement within a scope, return NULL if it does not exit
ROSE_DLL_API void addStepToLoopBody(SgScopeStatement *loopStmt, SgStatement *step)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API bool is_UPC_dynamic_threads()
ROSE_DLL_API SgFunctionDeclaration * getFunctionDeclaration(SgFunctionCallExp *functionCallExp)
Find a node by type using upward traversal.
ROSE_DLL_API bool is_mixed_Fortran_and_C_language()
ROSE_DLL_API void addTextForUnparser(SgNode *astNode, std::string s, AstUnparseAttribute::RelativePositionType inputlocation)
Add a string to be unparsed to support code generation for back-end specific tools or compilers.
ROSE_DLL_API std::string getTempDirectory(SgProject *project)
Create a temporary directory if it does not yet exist and return its name.
ROSE_DLL_API void displayScope(SgScopeStatement *scope)
Find a node by type using upward traversal.
ROSE_DLL_API bool is_Jovial_language()
ROSE_DLL_API SgMemberFunctionDeclaration * findJavaMain(SgClassDefinition *)
Find a main method in a Java class.
ROSE_DLL_API bool is_Cxx_language()
void resetScopeNumbers(SgFunctionDefinition *functionDeclaration)
Assigns unique numbers to each SgScopeStatement of a function.
ROSE_DLL_API SgFunctionDeclaration * replaceDefiningFunctionDeclarationWithFunctionPrototype(SgFunctionDeclaration *functionDeclaration)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API bool hasSameGlobalScope(SgStatement *statement_1, SgStatement *statement_2)
This is supporting the recognition of functions in header files from two different ASTs.
SgCommaOpExp * insertBeforeUsingCommaOp(SgExpression *new_exp, SgExpression *anchor_exp)
Insert an expression (new_exp )before another expression (anchor_exp) has possible side effects,...
ROSE_DLL_API void fixFunctionDeclaration(SgFunctionDeclaration *stmt, SgScopeStatement *scope)
Fix the symbol table and set scope (only if scope in declaration is not already set).
ROSE_DLL_API std::string preprocessImport(SgProject *, std::string)
Using the import_string parameter, create a file with the relevant import statement; translate the fi...
ROSE_DLL_API bool collectReadWriteRefs(SgStatement *stmt, std::vector< SgNode * > &readRefs, std::vector< SgNode * > &writeRefs, bool useCachedDefUse=false)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void prependStatementList(const std::vector< SgStatement * > &stmt, SgScopeStatement *scope=NULL)
prepend a list of statements to the beginning of the current scope, handling side effects as appropri...
ROSE_DLL_API SgInitializer * getInitializerOfExpression(SgExpression *n)
Get the initializer containing an expression if it is within an initializer.
ROSE_DLL_API std::vector< SgInitializedName * > getInParameters(const SgInitializedNamePtrList ¶ms)
Get a vector of Jovial input parameters from the function parameter list (may work for Fortran in the...
ROSE_DLL_API bool language_may_contain_nondeclarations_in_scope()
ROSE_DLL_API std::set< SgStatement * > collectTransformedStatements(SgNode *node)
This collects the statements that are marked as transformed (useful in debugging).
ROSE_DLL_API void cleanupNontransformedBasicBlockNode()
Remove unused basic block IR nodes added as part of normalization.
ROSE_DLL_API bool skipTranslateToUseCppDeclaration(PreprocessingInfo *currentPreprocessingInfo)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API AbstractHandle::abstract_handle * buildAbstractHandle(SgNode *)
Build an abstract handle from an AST node, reuse previously built handle when possible.
ROSE_DLL_API void insertStatementListBefore(SgStatement *targetStmt, const std::vector< SgStatement * > &newStmts)
Insert a list of statements before a target statement.
ROSE_DLL_API void fixStructDeclaration(SgClassDeclaration *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
void recursivePrintCurrentAndParent(SgNode *n)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API void appendExpressionList(SgExprListExp *, const std::vector< SgExpression * > &)
Append an expression list to a SgExprListExp, set the parent pointers also.
ROSE_DLL_API void collectReadOnlySymbols(SgStatement *stmt, std::set< SgVariableSymbol * > &readOnlySymbols, bool coarseGrain=true)
Collect read only variable symbols within a statement. The statement can be either of a function,...
bool isOverloaded(SgFunctionDeclaration *functionDeclaration)
Return true if function is overloaded.
ROSE_DLL_API int set_name(SgInitializedName *initializedNameNode, SgName new_name)
set_name of symbol in symbol table.
ROSE_DLL_API SgClassDefinition * findOrInsertJavaPackage(SgProject *, std::string, bool create_directory=false)
Process a qualified package name, if needed, and return its package definition.
ROSE_DLL_API SgClassDeclaration * findOrImportJavaClass(SgProject *, SgClassDefinition *package_definition, std::string)
If the class_name already exists in the scope, return it.
ROSE_DLL_API SgVariableSymbol * getFirstVarSym(SgVariableDeclaration *decl)
Get the variable symbol for the first initialized name of a declaration stmt.
ROSE_DLL_API bool templateArgumentEquivalence(SgTemplateArgument *arg1, SgTemplateArgument *arg2)
Verify that 2 SgTemplateArgument are equivalent (same type, same expression, or same template declara...
ROSE_DLL_API SgFunctionDeclaration * findFirstDefiningFunctionDecl(SgScopeStatement *scope)
Find the first defining function declaration statement in a scope.
ROSE_DLL_API bool is_Jvm_language()
void addMessageStatement(SgStatement *stmt, std::string message)
Function to add "C" style comment to statement.
ROSE_DLL_API bool isLoopIndexVariable(SgInitializedName *ivar, SgNode *subtree_root)
Check if a SgInitializedName is used as a loop index within a AST subtree This function will use a bo...
SgInitializedName & getFirstVariable(SgVariableDeclaration &vardecl)
convenience function that returns the first initialized name in a list of variable declarations.
void initializeSwitchStatement(SgSwitchStatement *switchStatement, SgStatement *item_selector, SgStatement *body)
Support function used for variable declarations in conditionals.
SgExprListExp * loopCollapsing(SgForStatement *target_loop, size_t collapsing_factor)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API void fixStatement(SgStatement *stmt, SgScopeStatement *scope)
A wrapper containing fixes (fixVariableDeclaration(),fixStructDeclaration(), fixLabelStatement(),...
ROSE_DLL_API SgStatement * copyStatement(SgStatement *s)
Deep copy a statement.
ROSE_DLL_API int eraseNullPreprocessingInfo(SgLocatedNode *lnode)
Dumps a located node's preprocessing information.
ROSE_DLL_API bool isCanonicalDoLoop(SgFortranDo *loop, SgInitializedName **ivar, SgExpression **lb, SgExpression **ub, SgExpression **step, SgStatement **body, bool *hasIncrementalIterationSpace, bool *isInclusiveUpperBound)
Check if a Fortran Do loop has a complete canonical form: Do I=1, 10, 1.
SgCommaOpExp * insertAfterUsingCommaOp(SgExpression *new_exp, SgExpression *anchor_exp, SgStatement **temp_decl=NULL, SgVarRefExp **temp_ref=NULL)
Insert an expression (new_exp ) after another expression (anchor_exp) has possible side effects,...
ROSE_DLL_API SgTemplateVariableSymbol * lookupTemplateVariableSymbolInParentScopes(const SgName &name, SgTemplateParameterPtrList *tplparams, SgTemplateArgumentPtrList *tplargs, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void moveUpPreprocessingInfo(SgStatement *stmt_dst, SgStatement *stmt_src, PreprocessingInfo::RelativePositionType src_position=PreprocessingInfo::undef, PreprocessingInfo::RelativePositionType dst_position=PreprocessingInfo::undef, bool usePrepend=false)
Identical to movePreprocessingInfo(), except for the stale name and confusing order of parameters....
ROSE_DLL_API SgStatement * lastStatementOfScopeWithTokenInfo(SgScopeStatement *scope, std::map< SgNode *, TokenStreamSequenceToNodeMapping * > &tokenStreamSequenceMap)
Used to support token unparsing (when the output the trailing token sequence).
ROSE_DLL_API void cutPreprocessingInfo(SgLocatedNode *src_node, PreprocessingInfo::RelativePositionType pos, AttachedPreprocessingInfoType &save_buf)
Cut preprocessing information from a source node and save it into a buffer. Used in combination of pa...
ROSE_DLL_API bool normalizeForLoopTest(SgForStatement *loop)
Normalize a for loop's test expression i<x is normalized to i<= (x-1) and i>x is normalized to i>= (x...
bool declarationPreceedsDefinition(SgDeclarationStatement *nonDefiningDeclaration, SgDeclarationStatement *definingDeclaration)
Check if a defining declaration comes before of after the non-defining declaration.
ROSE_DLL_API bool isSameFunction(SgFunctionDeclaration *func1, SgFunctionDeclaration *func2)
Check if two function declarations refer to the same one. Two function declarations are the same when...
std::vector< SgVariableSymbol * > getSymbolsUsedInExpression(SgExpression *expr)
Find referenced symbols within an expression.
ROSE_DLL_API bool isStructDeclaration(SgNode *node)
Check if a SgNode is a declaration for a structure.
ROSE_DLL_API void moveVariableDeclaration(SgVariableDeclaration *decl, SgScopeStatement *target_scope)
Move a variable declaration to a new scope, handle symbol, special scopes like For loop,...
ROSE_DLL_API std::string preprocessPackage(SgProject *, std::string)
Using the package_name, create a file with a package statement, translate it in order to load the pac...
ROSE_DLL_API void setOneSourcePositionForTransformation(SgNode *root)
Set current node's source position as transformation generated.
NodeType * deepCopy(const NodeType *subtree)
A template function for deep copying a subtree. It is also used to create deepcopy functions with spe...
void clearMangledNameCache(SgGlobal *globalScope)
Support for faster mangled name generation (caching avoids recomputation).
std::vector< SgStatement * > getSwitchCases(SgSwitchStatement *sw)
Query a subtree to get all nodes of a given type, with an appropriate downcast.
ROSE_DLL_API bool isScalarType(SgType *t)
Is this a scalar type?
ROSE_DLL_API void changeBreakStatementsToGotos(SgStatement *loopOrSwitch)
If the given statement contains any break statements in its body, add a new label below the statement...
ROSE_DLL_API SgFunctionDefinition * getEnclosingFunctionDefinition(SgNode *astNode, const bool includingSelf=false)
Find a node by type using upward traversal.
ROSE_DLL_API bool is_CAF_language()
ROSE_DLL_API void printOutComments(SgLocatedNode *locatedNode)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void ReductionRecognition(SgForStatement *loop, std::set< std::pair< SgInitializedName *, OmpSupport::omp_construct_enum > > &results)
Recognize and collect reduction variables and operations within a C/C++ loop, following OpenMP 3....
ROSE_DLL_API bool loopUnrolling(SgForStatement *loop, size_t unrolling_factor)
Unroll a target loop with a specified unrolling factor. It handles steps larger than 1 and adds a fri...
ROSE_DLL_API void setLoopCondition(SgScopeStatement *loop, SgStatement *cond)
Set the condition statement of a loop, including While-loop, For-loop, and Do-While-loop.
bool ROSE_DLL_API isStatic(SgDeclarationStatement *stmt)
Check if a declaration has a "static' modifier.
PreprocessingInfo * attachComment(SgSourceFile *source_file, const std::string &content, PreprocessingInfo::DirectiveType directive_type=PreprocessingInfo::C_StyleComment, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Build and attach comment onto the global scope of a source file.
ROSE_DLL_API SgClassDefinition * getEnclosingClassDefinition(SgNode *astnode, const bool includingSelf=false)
Get the closest class definition enclosing the specified AST node,.
ROSE_DLL_API bool mergeDeclarationAndAssignment(SgVariableDeclaration *decl, SgExprStatement *assign_stmt, bool removeAssignStmt=true)
Merge a variable assignment statement into a matching variable declaration statement....
ROSE_DLL_API void checkAccessPermissions(SgNode *)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API std::vector< SgFunctionDeclaration * > generateFunctionDefinitionsList(SgNode *node)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API void replaceMacroCallsWithExpandedStrings(SgPragmaDeclaration *target)
Check if a pragma declaration node has macro calls attached, if yes, replace macro calls within the p...
std::string generateUniqueNameForUseAsIdentifier(SgDeclarationStatement *declaration)
Generate a useful name to support construction of identifiers from declarations.
ROSE_DLL_API bool isRestrictType(SgType *t)
Is this a restrict type?
ROSE_DLL_API std::string generateProjectName(const SgProject *project, bool supressSuffix=false)
Added mechanism to generate project name from list of file names.
ROSE_DLL_API void resetInternalMapsForTargetStatement(SgStatement *sourceStatement)
Reset internal data structures used for token-based unparsing and macro summaries based on modificati...
ROSE_DLL_API bool is_Cuda_language()
ROSE_DLL_API bool isLambdaCapturedVariable(SgVarRefExp *varRef)
check if a variable reference is this->a[i] inside of a lambda function
ROSE_DLL_API int instrumentEndOfFunction(SgFunctionDeclaration *func, SgStatement *s)
Instrument(Add a statement, often a function call) into a function right before the return points,...
ROSE_DLL_API SgInitializedName * getFirstInitializedName(SgVariableDeclaration *decl)
Get the first initialized name of a declaration statement.
void setSourcePositionPointersToNull(SgNode *node)
Set the source code positon for the current (input) node.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfDoWhile(SgDoWhileStmt *ws)
Check if the body of a 'do .. while' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API void reportModifiedStatements(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API std::vector< SgInitializedName * > getOutParameters(const SgInitializedNamePtrList ¶ms)
Get a vector of Jovial output parameters from the function parameter list (may work for Fortran in th...
ROSE_DLL_API void setSourcePositionForTransformation(SgNode *root)
Recursively set source position info(Sg_File_Info) as transformation generated.
ROSE_DLL_API SgGlobal * getGlobalScope(const SgNode *astNode)
Traverse back through a node's parents to find the enclosing global scope.
ROSE_DLL_API void insertStatementListAfter(SgStatement *targetStmt, const std::vector< SgStatement * > &newStmt)
Insert a list of statements after a target statement.
ROSE_DLL_API bool isMain(const SgNode *node)
Check if a SgNode is a main() function declaration.
std::map< std::string, int > local_name_collision_map
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function.
ROSE_DLL_API void fixClassDeclaration(SgClassDeclaration *classDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
ROSE_DLL_API int collectVariableReferencesInArrayTypes(SgLocatedNode *root, Rose_STL_Container< SgNode * > ¤tVarRefList)
Collect variable references in array types. The default NodeQuery::querySubTree() will miss variables...
SgBasicBlock * ensureBasicBlockAsBodyOfCaseOption(SgCaseOptionStmt *cs)
Check if the body of a 'case option' statement is a SgBasicBlock, create one if not.
void checkForInitializers(SgNode *node)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void removeUnusedLabels(SgNode *top, bool keepChild=false)
Remove labels which are not targets of any goto statements: its child statement is also removed by de...
ROSE_DLL_API SgProject * getProject()
Get the current SgProject IR Node.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfUpcForAll(SgUpcForAllStatement *fs)
Check if the body of a 'upc_forall' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API SgClassDeclaration * getEnclosingClassDeclaration(SgNode *astNode)
Get the closest class declaration enclosing the specified AST node,.
ROSE_DLL_API void insertStatement(SgStatement *targetStmt, SgStatement *newStmt, bool insertBefore=true, bool autoMovePreprocessingInfo=true)
Insert a statement before or after the target statement within the target's scope....
ROSE_DLL_API void listHeaderFiles(SgIncludeFile *includeFile)
return path prefix for subtree of include files.
ROSE_DLL_API void markSubtreeToBeUnparsedTreeTraversal(SgNode *root, int physical_file_id)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
void saveToPDF(SgNode *node, std::string filename)
Save AST into a pdf file. Start from a node to find its enclosing file node. The entire file's AST wi...
ROSE_DLL_API bool normalizeForLoopInitDeclaration(SgForStatement *loop)
Normalize loop init stmt by promoting the single variable declaration statement outside of the for lo...
void detectCycleInType(SgType *type, const std::string &from)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void deleteAST(SgNode *node)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API bool statementCanBeTransformed(SgStatement *stmt)
If header file unparsing and token-based unparsing are used, then some statements in header files use...
ROSE_DLL_API SgStatement * getNextStatement(SgStatement *currentStmt)
Get next statement within the same scope of current statement.
ROSE_DLL_API std::set< SgLabelStatement * > findUnusedLabels(SgNode *top)
Find unused labels which are not targets of any goto statements.
ROSE_DLL_API void setExtern(SgDeclarationStatement *stmt)
Set a declaration as extern.
ROSE_DLL_API void deleteAllNodes()
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API bool templateArgumentListEquivalence(const SgTemplateArgumentPtrList &list1, const SgTemplateArgumentPtrList &list2)
Verify that 2 SgTemplateArgumentPtrList are equivalent.
ROSE_DLL_API LivenessAnalysis * call_liveness_analysis(SgProject *project, bool debug=false)
Call liveness analysis on an entire project.
ROSE_DLL_API void reportModifiedLocatedNodes(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void fixTemplateDeclaration(SgTemplateDeclaration *stmt, SgScopeStatement *scope)
Fix the symbol table and set scope (only if scope in declaration is not already set).
SgType * getBoolType(SgNode *n)
Get the right bool type according to C or C++ language input.
void clearSharedGlobalScopes(SgProject *project)
Collect all read and write references within stmt, which can be a function, a scope statement,...
void initializeWhileStatement(SgWhileStmt *whileStatement, SgStatement *condition, SgStatement *body, SgStatement *else_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void setSourcePosition(SgNode *node)
Set the source code positon for the current (input) node.
ROSE_DLL_API void setPragma(SgPragmaDeclaration *decl, SgPragma *pragma)
Set a pragma of a pragma declaration. handle memory release for preexisting pragma,...
ROSE_DLL_API void insertStatementListBeforeFirstNonDeclaration(const std::vector< SgStatement * > &newStmts, SgScopeStatement *scope)
Insert statements before the first non-declaration statement in a scope. If the scope has no non-decl...
ROSE_DLL_API bool isPostfixOperator(SgExpression *exp)
Is an overloaded operator a postfix operator. (e.g. ).
ROSE_DLL_API SgStatement * findSurroundingStatementFromSameFile(SgStatement *targetStmt, bool &surroundingStatementPreceedsTargetStatement)
Supporting function to comment relocation in insertStatement() and removeStatement().
SgNamespaceDefinitionStatement * enclosingNamespaceScope(SgDeclarationStatement *declaration)
Find the enclosing namespace of a declaration.
ROSE_DLL_API SgStatement * getLoopBody(SgScopeStatement *loop)
Routines to get and set the body of a loop.
ROSE_DLL_API bool is_mixed_C_and_Cxx_language()
bool isStructurallyEquivalentAST(SgNode *tree1, SgNode *tree2)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API PreprocessingInfo * insertHeader(SgSourceFile *source_file, const std::string &header_file_name, bool isSystemHeader, bool asLastHeader)
Insert #include "filename" or #include <filename> (system header) onto the global scope of a source f...
void printAST2TextFile(SgNode *node, const char *filename, bool printType=true)
Pretty print AST horizontally, output to a specified text file. If printType is set to false,...
ROSE_DLL_API SgFunctionSymbol * lookupTemplateFunctionSymbolInParentScopes(const SgName &functionName, SgFunctionType *ftype, SgTemplateParameterPtrList *tplparams, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool is_language_case_insensitive()
ROSE_DLL_API void replaceStatement(SgStatement *oldStmt, SgStatement *newStmt, bool movePreprocessinInfo=false)
Replace a statement with another. Move preprocessing information from oldStmt to newStmt if requested...
ROSE_DLL_API void recordNormalizations(SgStatement *s)
Record where normalization have been done so that we can preform denormalizations as required for the...
ROSE_DLL_API bool loopInterchange(SgForStatement *loop, size_t depth, size_t lexicoOrder)
Interchange/permutate a n-level perfectly-nested loop rooted at 'loop' using a lexicographical order ...
void printAST(SgNode *node)
Pretty print AST horizontally, output to std output.
ROSE_DLL_API SgFunctionSymbol * lookupTemplateMemberFunctionSymbolInParentScopes(const SgName &functionName, SgFunctionType *ftype, SgTemplateParameterPtrList *tplparams, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool is_PHP_language()
ROSE_DLL_API bool isEqualToIntConst(SgExpression *e, int value)
Check if a SgIntVal node has a given value.
ROSE_DLL_API void insertStatementBeforeFirstNonDeclaration(SgStatement *newStmt, SgScopeStatement *scope, bool movePreprocessingInfo=true)
Insert a statement before the first non-declaration statement in a scope. If the scope has no non-dec...
ROSE_DLL_API SgFunctionSymbol * lookupFunctionSymbolInParentScopes(const SgName &functionName, SgScopeStatement *currentScope=NULL)
look up the first matched function symbol in parent scopes given only a function name,...
ROSE_DLL_API void appendStatementWithDependentDeclaration(SgDeclarationStatement *decl, SgGlobal *scope, SgStatement *original_statement, bool excludeHeaderFiles)
Append a copy ('decl') of a function ('original_statement') into a 'scope', include any referenced de...
ROSE_DLL_API bool insideHeader(SgLocatedNode *node)
Check if a node is from a header file.
ROSE_DLL_API void markSubtreeToBeUnparsed(SgNode *root, int physical_file_id)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool isDataMemberReference(SgVarRefExp *varRefExp)
Find a node by type using upward traversal.
ROSE_DLL_API bool collectReadWriteVariables(SgStatement *stmt, std::set< SgInitializedName * > &readVars, std::set< SgInitializedName * > &writeVars, bool coarseGrain=true)
Collect unique variables which are read or written within a statement. Note that a variable can be bo...
ROSE_DLL_API void constantFolding(SgNode *r)
Constant folding an AST subtree rooted at 'r' (replacing its children with their constant values,...
std::vector< SgBreakStmt * > findBreakStmts(SgStatement *code, const std::string &fortranLabel="")
Find break statements inside a particular statement, stopping at nested loops or switches.
ROSE_DLL_API SgFile * getEnclosingFileNode(SgNode *astNode)
get the SgFile node from current node
ROSE_DLL_API void setStatic(SgDeclarationStatement *stmt)
Set a declaration as static.
ROSE_DLL_API bool doLoopNormalization(SgFortranDo *loop)
Normalize a Fortran Do loop. Make the default increment expression (1) explicit.
ROSE_DLL_API SgFile * preprocessCompilationUnit(SgProject *, std::string, std::string, bool unparse=true)
Using the file_content string, create a file with the content in question; build its AST and add it t...
ROSE_DLL_API void removeLabeledGotos(SgNode *top)
Remove labeled goto statements.
std::map< SgNode *, std::string > local_node_to_name_map
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function.
std::vector< SgGotoStatement * > findGotoStmts(SgStatement *scope, SgLabelStatement *l)
Query a subtree to get all nodes of a given type, with an appropriate downcast.
ROSE_DLL_API bool mergeDeclarationWithAssignment(SgVariableDeclaration *decl, SgExprStatement *assign_stmt)
Merge a declaration statement into a matching followed variable assignment. Callers should make sure ...
ROSE_DLL_API bool isAssignmentStatement(SgNode *_s, SgExpression **lhs=NULL, SgExpression **rhs=NULL, bool *readlhs=NULL)
Check if a SgNode _s is an assignment statement (any of =,+=,-=,&=,/=, ^=, etc)
ROSE_DLL_API void outputSharedNodes(SgNode *node)
Find a node by type using upward traversal.
bool ROSE_DLL_API isAncestor(SgNode *node1, SgNode *node2)
check if node1 is a strict ancestor of node 2. (a node is not considered its own ancestor)
ROSE_DLL_API SgScopeStatement * getEnclosingScope(SgNode *n, const bool includingSelf=false)
Get the enclosing scope from a node n.
ROSE_DLL_API SgNonrealSymbol * lookupNonrealSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateParameterPtrList *templateParameterList=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API SgSwitchStatement * findEnclosingSwitch(SgStatement *s)
Find the closest switch outside a given statement (normally used for case and default statements)
ROSE_DLL_API void removeAllOriginalExpressionTrees(SgNode *top)
Set original expression trees to NULL for SgValueExp or SgCastExp expressions, so you can change the ...
ROSE_DLL_API std::vector< SgNode * > astIntersection(SgNode *original, SgNode *copy, SgCopyHelp *help=NULL)
Compute the intersection set for two ASTs.
ROSE_DLL_API bool isPrefixOperator(SgExpression *exp)
Is an overloaded operator a prefix operator (e.g. address operator X * operator&(),...
ROSE_DLL_API void setLhsOperand(SgExpression *target, SgExpression *lhs)
set left hand operand for binary expressions, transparently downcasting target expressions when neces...
ROSE_DLL_API std::vector< SgC_PreprocessorDirectiveStatement * > translateStatementToUseCppDeclarations(SgStatement *statement, SgScopeStatement *scope)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API int suggestNextNumericLabel(SgFunctionDefinition *func_def)
Suggest next usable (non-conflicting) numeric label value for a Fortran function definition scope.
ROSE_DLL_API std::set< SgStatement * > collectModifiedStatements(SgNode *node)
This collects the statements that are marked as modified (a flag automatically set by all set_* gener...
ROSE_DLL_API SgFunctionDeclaration * getEnclosingFunctionDeclaration(SgNode *astNode, const bool includingSelf=false)
Find the enclosing function declaration, including its derived instances like isSgProcedureHeaderStat...
SgFunctionDeclaration * findFunctionDeclaration(SgNode *root, std::string name, SgScopeStatement *scope, bool isDefining)
Topdown traverse a subtree from root to find the first function declaration matching the given name,...
ROSE_DLL_API bool isPrefixOperatorName(const SgName &functionName)
Check for proper names of possible prefix operators (used in isPrefixOperator()).
ROSE_DLL_API void setLoopStride(SgNode *loop, SgExpression *stride)
Set the stride(step) of a loop 's incremental expression, regardless the expression types (i+=s; i= i...
ROSE_DLL_API bool isInSubTree(SgExpression *subtree, SgExpression *exp)
Find a node by type using upward traversal.
ROSE_DLL_API bool forLoopNormalization(SgForStatement *loop, bool foldConstant=true)
Normalize a for loop, return true if successful.
unsigned long long getIntegerConstantValue(SgValueExp *expr)
Get the constant value from a constant integer expression; abort on everything else.
ROSE_DLL_API bool is_UPC_language()
ROSE_DLL_API void checkSymbolTables(SgNode *)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API void updateDefiningNondefiningLinks(SgFunctionDeclaration *func, SgScopeStatement *scope)
Update defining and nondefining links due to a newly introduced function declaration....
ROSE_DLL_API SgNode * deepCopyNode(const SgNode *subtree)
Deep copy an arbitrary subtree.
SgBasicBlock * ensureBasicBlockAsBodyOfDefaultOption(SgDefaultOptionStmt *cs)
Check if the body of a 'default option' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API void getLiveVariables(LivenessAnalysis *liv, SgForStatement *loop, std::set< SgInitializedName * > &liveIns, std::set< SgInitializedName * > &liveOuts)
get liveIn and liveOut variables for a for loop from liveness analysis result liv.
ROSE_DLL_API void resetModifiedLocatedNodes(const std::set< SgLocatedNode * > &modifiedNodeSet)
Use the set of IR nodes and set the isModified flag in each IR node to true.
ROSE_DLL_API SgNode * replaceWithPattern(SgNode *anchor, SgNode *new_pattern)
Replace an anchor node with a specified pattern subtree with optional SgVariantExpression....
ROSE_DLL_API bool ROSE_DLL_API isJovialOutParam(SgInitializedName *name)
True if a parameter name is a Jovial output parameter.
ROSE_DLL_API void moveForStatementIncrementIntoBody(SgForStatement *f)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfOmpBodyStmt(SgOmpBodyStatement *ompbodyStmt)
Check if the body of a SgOmpBodyStatement is a SgBasicBlock, create one if not.
ROSE_DLL_API bool is_Python_language()
ROSE_DLL_API bool is_mixed_Fortran_and_Cxx_language()
ROSE_DLL_API SgStatement * getLoopCondition(SgScopeStatement *loop)
Routines to get the condition of a loop. It recognize While-loop, For-loop, and Do-While-loop.
ROSE_DLL_API SgEnumSymbol * lookupEnumSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
std::pair< SgVariableDeclaration *, SgExpression * > createTempVariableAndReferenceForExpression(SgExpression *expression, SgScopeStatement *scope)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API SgTypedefSymbol * lookupTypedefSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfWhile(SgWhileStmt *ws)
Check if the body of a 'while' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfFor(SgForStatement *fs)
Check if the body of a 'for' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API PreprocessingInfo * attachArbitraryText(SgLocatedNode *target, const std::string &text, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Attach an arbitrary string to a located node. A workaround to insert irregular statements or vendor-s...
ROSE_DLL_API void markNodeToBeUnparsed(SgNode *node, int physical_file_id)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool isConstantTrue(SgExpression *e)
Check if a bool or int constant expression evaluates to be a true value.
std::map< std::string, SgNode * > local_name_to_node_map
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function.
ROSE_DLL_API bool is_binary_executable()
void changeAllBodiesToBlocks(SgNode *top, bool createEmptyBody=true)
Fix up ifs, loops, while, switch, Catch, OmpBodyStatement, etc. to have blocks as body components....
void dumpPreprocInfo(SgLocatedNode *locatedNode)
Dumps a located node's preprocessing information.
void fixupReferencesToSymbols(const SgScopeStatement *this_scope, SgScopeStatement *copy_scope, SgCopyHelp &help)
All the symbol table references in the copied AST need to be reset after rebuilding the copied scope'...
ROSE_DLL_API void moveDeclarationToAssociatedNamespace(SgDeclarationStatement *declarationStatement)
Relocate the declaration to be explicitly represented in its associated namespace (required for some ...
ROSE_DLL_API bool isCanonicalForLoop(SgNode *loop, SgInitializedName **ivar=NULL, SgExpression **lb=NULL, SgExpression **ub=NULL, SgExpression **step=NULL, SgStatement **body=NULL, bool *hasIncrementalIterationSpace=NULL, bool *isInclusiveUpperBound=NULL)
Check if a for-loop has a canonical form, return loop index, bounds, step, and body if requested.
ROSE_DLL_API bool isArrayReference(SgExpression *ref, SgExpression **arrayNameExp=NULL, std::vector< SgExpression * > **subscripts=NULL)
Check if an expression is an array access (SgPntrArrRefExp). If so, return its name expression and su...
ROSE_DLL_API void insertStatementAfterLastDeclaration(SgStatement *stmt, SgScopeStatement *scope)
Insert a statement after the last declaration within a scope. The statement will be prepended to the ...
ROSE_DLL_API void destroyTempDirectory(std::string)
Use the system command to remove a temporary directory and all its containing files.
void serialize_list(T &plist, std::string T_name, std::string &prefix, bool hasRemaining, std::ostringstream &out, std::string &edgeLabel)
Query a subtree to get all nodes of a given type, with an appropriate downcast.
void resetMangledNameCache(SgGlobal *globalScope)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API SgTemplateInstantiationMemberFunctionDecl * buildForwardFunctionDeclaration(SgTemplateInstantiationMemberFunctionDecl *memberFunctionInstantiation)
Generate a non-defining (forward) declaration from a defining function declaration.
ROSE_DLL_API bool is_Fortran_language()
ROSE_DLL_API SgVariableSymbol * lookupVariableSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void outputFileIds(SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API SgExprStatement * splitVariableDeclaration(SgVariableDeclaration *decl)
Split a variable declaration with an rhs assignment into two statements: a declaration and an assignm...
ROSE_DLL_API SgStatement * getFirstStatement(SgScopeStatement *scope, bool includingCompilerGenerated=false)
Get the first statement within a scope, return NULL if it does not exist. Skip compiler-generated sta...
ROSE_DLL_API SgNamespaceSymbol * lookupNamespaceSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool isExtern(SgDeclarationStatement *stmt)
Check if a declaration has an "extern" modifier.
std::string extractPragmaKeyword(const SgPragmaDeclaration *)
Extract a SgPragmaDeclaration's leading keyword . For example "#pragma omp parallel" has a keyword of...
ROSE_DLL_API SgTemplateClassSymbol * lookupTemplateClassSymbolInParentScopes(const SgName &name, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateArgumentList, SgScopeStatement *cscope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool isEquivalentFunctionType(const SgFunctionType *lhs, const SgFunctionType *rhs)
Test if two types are equivalent SgFunctionType nodes.
ROSE_DLL_API void setLoopLowerBound(SgNode *loop, SgExpression *lb)
Set the lower bound of a loop header for (i=lb; ...)
void guardNode(SgLocatedNode *target, std::string guard)
Add preproccessor guard around a given node.
bool checkTypesAreEqual(SgType *typeA, SgType *typeB)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool isReferenceType(SgType *t)
Is this type a const or non-const reference type? (Handles typedefs correctly)
ROSE_DLL_API SgStatement * getEnclosingStatement(SgNode *n)
Find the closest enclosing statement, including the given node.
ROSE_DLL_API void translateToUseCppDeclarations(SgNode *n)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void changeContinuesToGotos(SgStatement *stmt, SgLabelStatement *label)
Change continue statements in a given block of code to gotos to a label.
void outputGlobalFunctionTypeSymbolTable()
Output function type symbols in global function type symbol table.
ROSE_DLL_API SgScopeStatement * findEnclosingLoop(SgStatement *s, const std::string &fortranLabel="", bool stopOnSwitches=false)
Find the closest loop outside the given statement; if fortranLabel is not empty, the Fortran label of...
std::pair< SgVariableDeclaration *, SgExpression * > createTempVariableForExpression(SgExpression *expression, SgScopeStatement *scope, bool initializeInDeclaration, SgAssignOp **reEvaluate=NULL)
Given an expression, generates a temporary variable whose initializer optionally evaluates that expre...
bool isBodyStatement(SgStatement *s)
Check if a statement is a (true or false) body of a container-like parent, such as For,...
bool functionCallExpressionPreceedsDeclarationWhichAssociatesScope(SgFunctionCallExp *functionCall)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API void convertAllForsToWhiles(SgNode *top)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API bool isConstantFalse(SgExpression *e)
Check if a bool or int constant expression evaluates to be a false value.
ROSE_DLL_API void outputLocalSymbolTables(SgNode *node)
Output the local symbol tables.
ROSE_DLL_API void preOrderCollectPreprocessingInfo(SgNode *current, std::vector< PreprocessingInfo * > &infoList, int depth)
Dumps a located node's preprocessing information.
ROSE_DLL_API SgMemberFunctionDeclaration * getDefaultDestructor(SgClassDeclaration *classDeclaration)
Get the default destructor from the class declaration.
void collectVarRefs(SgLocatedNode *root, std::vector< SgVarRefExp * > &result)
Collect all variable references in a subtree.
ROSE_DLL_API void setOperand(SgExpression *target, SgExpression *operand)
Set operands for expressions with single operand, such as unary expressions. handle file info,...
ROSE_DLL_API SgMemberFunctionDeclaration * getDefaultConstructor(SgClassDeclaration *classDeclaration)
Get the default constructor from the class declaration.
ROSE_DLL_API SgInitializedName * getLoopIndexVariable(SgNode *loop)
Return the loop index variable for a for loop.
ROSE_DLL_API void moveCommentsToNewStatement(SgStatement *sourceStatement, const std::vector< int > &indexList, SgStatement *targetStatement, bool surroundingStatementPreceedsTargetStatement)
Relocate comments and CPP directives from one statement to another.
ROSE_DLL_API SgAssignInitializer * splitExpression(SgExpression *from, std::string newName="")
Replace an expression with a temporary variable and an assignment statement.
ROSE_DLL_API void replaceVariableReferences(SgVariableSymbol *old_sym, SgVariableSymbol *new_sym, SgScopeStatement *scope)
Replace all variable references to an old symbol in a scope to being references to a new symbol.
ROSE_DLL_API bool is_OpenCL_language()
ROSE_DLL_API bool normalizeForLoopIncrement(SgForStatement *loop)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API SgVariableSymbol * appendArg(SgFunctionParameterList *, SgInitializedName *)
Append an argument to SgFunctionParameterList, transparently set parent,scope, and symbols for argume...
ROSE_DLL_API bool unnormalizeForLoopInitDeclaration(SgForStatement *loop)
Undo the normalization of for loop's C99 init declaration. Previous record of normalization is used t...
ROSE_DLL_API SgStatement * getPreviousStatement(SgStatement *currentStmt, bool climbOutScope=true)
Get previous statement of the current statement. It may return a previous statement of a parent scope...
ROSE_DLL_API void removeJumpsToNextStatement(SgNode *)
Remove jumps whose label is immediately after the jump. Used to clean up inlined code fragments.
bool isPrototypeInScope(SgScopeStatement *scope, SgFunctionDeclaration *functionDeclaration, SgDeclarationStatement *startingAtDeclaration)
Assigns unique numbers to each SgScopeStatement of a function.
ROSE_DLL_API int moveUpInnerDanglingIfEndifDirective(SgLocatedNode *lnode)
Extract sequences like " #endif #endif ... #if | #ifdef| #ifndef" buried inside subtree of lnode.
SgDeclarationStatement * getNonInstantiatonDeclarationForClass(SgTemplateInstantiationMemberFunctionDecl *memberFunctionInstantiation)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool isConstType(SgType *t)
Is this a const type?
SgFunctionDeclaration * getDeclarationOfNamedFunction(SgExpression *func)
Given a SgExpression that represents a named function (or bound member function), return the mentione...
ROSE_DLL_API bool is_C99_language()
ROSE_DLL_API bool addDefaultConstructorIfRequired(SgClassType *classType, int physical_file_id=Sg_File_Info::TRANSFORMATION_FILE_ID)
Get the default destructor from the class declaration.
ROSE_DLL_API void movePreprocessingInfo(SgStatement *stmt_src, SgStatement *stmt_dst, PreprocessingInfo::RelativePositionType src_position=PreprocessingInfo::undef, PreprocessingInfo::RelativePositionType dst_position=PreprocessingInfo::undef, bool usePrepend=false)
Move preprocessing information of stmt_src to stmt_dst, Only move preprocessing information from the ...
ROSE_DLL_API int fixVariableReferences(SgNode *root, bool cleanUnusedSymbol=true)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API bool isUseByAddressVariableRef(SgVarRefExp *ref)
Check if a variable reference is used by its address: including &a expression and foo(a) when type2 f...
struct const_int_expr_t evaluateConstIntegerExpression(SgExpression *expr)
The function tries to evaluate const integer expressions (such as are used in array dimension sizes)....
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsTrueBodyOfIf(SgIfStmt *ifs)
Check if the true body of a 'if' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API void replaceExpression(SgExpression *oldExp, SgExpression *newExp, bool keepOldExp=false)
Replace an expression with another, used for variable reference substitution and others....
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsFalseBodyOfIf(SgIfStmt *ifs, bool createEmptyBody=true)
Check if the false body of a 'if' statement is a SgBasicBlock, create one if not when the flag is tru...
ROSE_DLL_API SgExprListExp * getEnclosingExprListExp(SgNode *astNode, const bool includingSelf=false)
Get the enclosing SgExprListExp (used as part of function argument index evaluation in subexpressions...
ROSE_DLL_API void appendStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Append a statement to the end of the current scope, handle side effect of appending statements,...
ROSE_DLL_API SgFunctionDeclaration * buildFunctionPrototype(SgFunctionDeclaration *functionDeclaration)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
void addVarRefExpFromArrayDimInfo(SgNode *astNode, Rose_STL_Container< SgNode * > &NodeList_t)
Find all SgPntrArrRefExp under astNode, then add SgVarRefExp (if any) of SgPntrArrRefExp's dim_info i...
ROSE_DLL_API bool loopTiling(SgForStatement *loopNest, size_t targetLevel, size_t tileSize)
Tile the n-level (starting from 1) loop of a perfectly nested loop nest using tiling size s.
std::string generateUniqueName(const SgNode *node, bool ignoreDifferenceBetweenDefiningAndNondefiningDeclarations)
Generate unique name from C and C++ constructs. The name may contain space.
ROSE_DLL_API SgGlobal * getFirstGlobalScope(SgProject *project)
return the first global scope under current project
ROSE_DLL_API void setOneSourcePositionNull(SgNode *node)
Set current node's source position as NULL.
ROSE_DLL_API void setRhsOperand(SgExpression *target, SgExpression *rhs)
set left hand operand for binary expression
std::pair< SgStatement *, SgInitializedName * > wrapFunction(SgFunctionDeclaration &definingDeclaration, SgName newName)
moves the body of a function f to a new function f; f's body is replaced with code that forwards the ...
ROSE_DLL_API bool is_mixed_Fortran_and_C_and_Cxx_language()
ROSE_DLL_API bool isVolatileType(SgType *t)
Is this a volatile type?
void clearUnusedVariableSymbols(SgNode *root=NULL)
Clear those variable symbols with unknown type (together with initialized names) which are also not r...
ROSE_DLL_API void fixVariableDeclaration(SgVariableDeclaration *varDecl, SgScopeStatement *scope)
Patch up symbol, scope, and parent information when a SgVariableDeclaration's scope is known.
ROSE_DLL_API SgSymbol * lookupSymbolInParentScopesIgnoringAliasSymbols(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateParameterPtrList *templateParameterList=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
std::string generateUniqueVariableName(SgScopeStatement *scope, std::string baseName="temp")
Generate a name like temp# that is unique in the current scope and any parent and children scopes.
ROSE_DLL_API int gensym_counter
An internal counter for generating unique SgName.
ROSE_DLL_API void splitExpressionIntoBasicBlock(SgExpression *expr)
Split long expressions into blocks of statements.
void reset_name_collision_map()
Reset map variables used to support generateUniqueNameForUseAsIdentifier() function.
ROSE_DLL_API SgFunctionDefinition * getEnclosingProcedure(SgNode *n, const bool includingSelf=false)
Find the function definition.
std::vector< SgExpression * > get_C_array_dimensions(const SgArrayType &arrtype)
returns the array dimensions in an array as defined for arrtype
ROSE_DLL_API void replaceSubexpressionWithStatement(SgExpression *from, SageInterface::StatementGenerator *to)
Similar to replaceExpressionWithStatement, but with more restrictions.
ROSE_DLL_API void wrapAllTemplateInstantiationsInAssociatedNamespaces(SgProject *root)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
std::string get_name(const SgNode *node)
Generate a useful name to describe the SgNode.
ROSE_DLL_API void setLoopUpperBound(SgNode *loop, SgExpression *ub)
Set the upper bound of a loop header,regardless the condition expression type. for (i=lb; i op up,...
ROSE_DLL_API bool isMemberFunctionMemberReference(SgMemberFunctionRefExp *memberFunctionRefExp)
Find a node by type using upward traversal.
ROSE_DLL_API SgClassDefinition * findJavaPackage(SgScopeStatement *, std::string)
Look for a qualified package name in the given scope and return its package definition.
ROSE_DLL_API bool isOmpStatement(SgNode *)
Check if a node is SgOmp*Statement.
ROSE_DLL_API bool is_Ada_language()
std::string addMangledNameToCache(SgNode *astNode, const std::string &mangledName)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool is_C_language()
ROSE_DLL_API std::list< SgClassType * > getClassTypeChainForMemberReference(SgExpression *refExp)
Find a node by type using upward traversal.
ROSE_DLL_API void collectUseByAddressVariableRefs(const SgStatement *s, std::set< SgVarRefExp * > &varSetB)
Collect variable references involving use by address: including &a expression and foo(a) when type2 f...
std::vector< SgContinueStmt * > findContinueStmts(SgStatement *code, const std::string &fortranLabel="")
Find all continue statements inside a particular statement, stopping at nested loops.
std::string getMangledNameFromCache(SgNode *astNode)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API std::vector< SgDeclarationStatement * > sortSgNodeListBasedOnAppearanceOrderInSource(const std::vector< SgDeclarationStatement * > &nodevec)
Reorder a list of declaration statements based on their appearance order in source files.
ROSE_DLL_API std::set< SgLocatedNode * > collectModifiedLocatedNodes(SgNode *node)
This collects the SgLocatedNodes that are marked as modified (a flag automatically set by all set_* g...
SgExpression * forallMaskExpression(SgForAllStatement *stmt)
Get the mask expression from the header of a SgForAllStatement.
void clearScopeNumbers(SgFunctionDefinition *functionDefinition)
Clears the cache of scope,integer pairs for the input function.
ROSE_DLL_API SgInitializedName * convertRefToInitializedName(SgNode *current, bool coarseGrain=true)
Variable references can be introduced by SgVarRef, SgPntrArrRefExp, SgInitializedName,...
ROSE_DLL_API SgNode * getSgNodeFromAbstractHandleString(const std::string &input_string)
Obtain a matching SgNode from an abstract handle string.
ROSE_DLL_API void moveStatementsBetweenBlocks(SgBasicBlock *sourceBlock, SgBasicBlock *targetBlock)
Move statements in first block to the second block (preserves order and rebuilds the symbol table).
ROSE_DLL_API bool templateDefinitionIsInClass(SgTemplateInstantiationMemberFunctionDecl *memberFunctionDeclaration)
Return true if template definition is in the class, false if outside of class.
ROSE_DLL_API void fixLabelStatement(SgLabelStatement *label_stmt, SgScopeStatement *scope)
Fix symbol table for SgLabelStatement. Used Internally when the label is built without knowing its ta...
ROSE_DLL_API void replaceExpressionWithStatement(SgExpression *from, SageInterface::StatementGenerator *to)
Replace a given expression with a list of statements produced by a generator.
ROSE_DLL_API void convertForToWhile(SgForStatement *f)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API void insertStatementBefore(SgStatement *targetStmt, SgStatement *newStmt, bool autoMovePreprocessingInfo=true)
Insert a statement before a target statement.
ROSE_DLL_API bool findFirstSgCastExpMarkedAsTransformation(SgNode *n, const std::string &s)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API void dumpInfo(SgNode *node, std::string desc="")
Dump information about a SgNode for debugging.
ROSE_DLL_API void convertFunctionDefinitionsToFunctionPrototypes(SgNode *node)
XXX This function operates on the new file used to support outlined function definitions....
ROSE_DLL_API void appendStatementList(const std::vector< SgStatement * > &stmt, SgScopeStatement *scope=NULL)
Append a list of statements to the end of the current scope, handle side effect of appending statemen...
SgNamedType * getDeclaredType(const SgDeclarationStatement *declaration)
Returns the type introduced by a declaration.
ROSE_DLL_API bool isIndexOperator(SgExpression *exp)
Is an overloaded operator an index operator (also referred to as call or subscript operators)....
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfCatch(SgCatchOptionStmt *cos)
Check if the body of a 'catch' statement is a SgBasicBlock, create one if not.
std::vector< SgFile * > generateFileList()
Returns STL vector of SgFile IR node pointers.
ROSE_DLL_API int normalizeArrowExpWithAddressOfLeftOperand(SgNode *root, bool transformationGeneratedOnly=true)
Convert all code within root matching the patern of (&left)->right, and translate them into left....
bool hasTemplateSyntax(const SgName &name)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void moveToSubdirectory(std::string directoryName, SgFile *file)
Move file to be generated in a subdirectory (will be generated by the unparser).
ROSE_DLL_API bool isAddressTaken(SgExpression *refExp)
Find a node by type using upward traversal.
ROSE_DLL_API bool hasSimpleChildrenList(SgScopeStatement *scope)
Check if a scope statement has a simple children statement list so insert additional statements under...
ROSE_DLL_API SgFunctionDeclaration * findMain(SgNode *currentNode)
top-down traversal from current node to find the main() function declaration
ROSE_DLL_API SgClassSymbol * lookupClassSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void removeConsecutiveLabels(SgNode *top)
Remove consecutive labels.
ROSE_DLL_API void setLoopBody(SgScopeStatement *loop, SgStatement *body)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
bool getForLoopInformations(SgForStatement *for_loop, SgVariableSymbol *&iterator, SgExpression *&lower_bound, SgExpression *&upper_bound, SgExpression *&stride)
ROSE_DLL_API void appendExpression(SgExprListExp *, SgExpression *)
Append an expression to a SgExprListExp, set the parent pointer also.
ROSE_DLL_API bool isLambdaFunction(SgFunctionDeclaration *func)
Check if a function declaration is a C++11 lambda function.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfSwitch(SgSwitchStatement *ws)
Check if the body of a 'switch' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API void prependStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Prepend a statement to the beginning of the current scope, handling side effects as appropriate.
ROSE_DLL_API bool isCallToParticularFunction(SgFunctionDeclaration *decl, SgExpression *e)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool ROSE_DLL_API isMutable(SgInitializedName *name)
True if an SgInitializedName is "mutable' (has storage modifier set)
ROSE_DLL_API bool isCopyConstructible(SgType *type)
Is a type copy constructible? This may not quite work properly.
ROSE_DLL_API SgVariableSymbol * prependArg(SgFunctionParameterList *, SgInitializedName *)
Prepend an argument to SgFunctionParameterList.
ROSE_DLL_API void setSourcePositionAtRootAndAllChildren(SgNode *root)
Set the source code positon for the subtree (including the root).
ROSE_DLL_API SgExpression * copyExpression(SgExpression *e)
Deep copy an expression.
void setParameterList(actualFunction *func, SgFunctionParameterList *paralist)
Set parameter list for a function declaration, considering existing parameter list etc.
SgStatement * findLastDeclarationStatement(SgScopeStatement *scope, bool includePragma=false)
Find the last declaration statement within a scope (if any). This is often useful to decide where to ...
ROSE_DLL_API bool insideSystemHeader(SgLocatedNode *node)
Set source position info(Sg_File_Info) as transformation generated for all SgNodes in memory pool.
std::vector< SgDeclarationStatement * > getDependentDeclarations(SgStatement *stmt)
Get a statement's dependent declarations which declares the types used in the statement....
SgBasicBlock * makeSingleStatementBodyToBlock(SgStatement *singleStmt)
Make a single statement body to be a basic block. Its parent is if, while, catch, or upc_forall etc.
void computeUniqueNameForUseAsIdentifier(SgNode *astNode)
Traversal to set the global map of names to node and node to names.collisions to support generateUniq...
ROSE_DLL_API void collectReadOnlyVariables(SgStatement *stmt, std::set< SgInitializedName * > &readOnlyVars, bool coarseGrain=true)
Collect read only variables within a statement. The statement can be either of a function,...
std::string generateUniqueNameForUseAsIdentifier_support(SgDeclarationStatement *declaration)
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function.
ROSE_DLL_API PreprocessingInfo * findHeader(SgSourceFile *source_file, const std::string &header_file_name, bool isSystemHeader)
Find the preprocessingInfo node representing #include <header.h> or #include "header....
ROSE_DLL_API void myRemoveStatement(SgStatement *stmt)
A special purpose statement removal function, originally from inlinerSupport.h, Need Jeremiah's atten...
ROSE_DLL_API SgScopeStatement * getScope(const SgNode *astNode)
Get the closest scope from astNode. Return astNode if it is already a scope.
ROSE_DLL_API bool isStrictIntegerType(SgType *t)
Check if a type is an integral type, only allowing signed/unsigned short, int, long,...
ROSE_DLL_API bool is_Java_language()
ROSE_DLL_API void insertStatementAfter(SgStatement *targetStmt, SgStatement *newStmt, bool autoMovePreprocessingInfo=true)
Insert a statement after a target statement, Move around preprocessing info automatically by default.
ROSE_DLL_API bool isEquivalentType(const SgType *lhs, const SgType *rhs)
Test for equivalence of types independent of access permissions (private or protected modes for membe...
ROSE_DLL_API bool isTemplateInstantiationNode(SgNode *node)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API void removeStatement(SgStatement *stmt, bool autoRelocatePreprocessingInfo=true)
Remove a statement from its attach point of the AST. Automatically keep its associated preprocessing ...
ROSE_DLL_API SgOmpClauseBodyStatement * findEnclosingOmpClauseBodyStatement(SgStatement *s)
Find enclosing OpenMP clause body statement from s. If s is already one, return it directly.
ROSE_DLL_API bool scopeHasStatementsFromSameFile(SgScopeStatement *scope)
This function supports the token-based unparsing when used with unparsing of header files to know whe...
ROSE_DLL_API SgSourceFile * getEnclosingSourceFile(SgNode *n, const bool includingSelf=false)
Find enclosing source file node.
void rebuildSymbolTable(SgScopeStatement *scope)
Regenerate the symbol table.
ROSE_DLL_API SgSymbol * lookupSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateParameterPtrList *templateParameterList=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
void setBaseTypeDefiningDeclaration(SgVariableDeclaration *var_decl, SgDeclarationStatement *base_decl)
a better version for SgVariableDeclaration::set_baseTypeDefininingDeclaration(), handling all side ef...
ROSE_DLL_API void pastePreprocessingInfo(SgLocatedNode *dst_node, PreprocessingInfo::RelativePositionType pos, AttachedPreprocessingInfoType &saved_buf)
Paste preprocessing information from a buffer to a destination node. Used in combination of cutPrepro...
ROSE_DLL_API SgStatement * lastFrontEndSpecificStatement(SgGlobal *globalScope)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API SgFunctionType * findFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList)
Find the function type matching a function signature plus a given return type.
std::set< unsigned int > collectSourceSequenceNumbers(SgNode *astNode)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool is_OpenMP_language()
ROSE_DLL_API std::set< SgNode * > getFrontendSpecificNodes()
Find a node by type using upward traversal.
ROSE_DLL_API bool mergeAssignmentWithDeclaration(SgExprStatement *assign_stmt, SgVariableDeclaration *decl, bool removeAssignStmt=true)
Merge an assignment into its upstream declaration statement. Callers should make sure the merge is se...
ROSE_DLL_API void setFortranNumericLabel(SgStatement *stmt, int label_value, SgLabelSymbol::label_type_enum label_type=SgLabelSymbol::e_start_label_type, SgScopeStatement *label_scope=NULL)
Set a numerical label for a Fortran statement. The statement should have a enclosing function definit...
ROSE_DLL_API SgType * lookupNamedTypeInParentScopes(const std::string &type_name, SgScopeStatement *scope=NULL)
Lookup a named type based on its name, bottomup searching from a specified scope. Note name collison ...
ROSE_DLL_API SgFile * processFile(SgProject *, std::string, bool unparse=false)
Invoke JavaRose to translate a given file and put the resulting AST in the global space of the projec...
bool get(const Word *words, size_t idx)
Return a single bit.
void swap_child(SageNode &lhs, SageNode &rhs, SageChild *(SageNode::*getter)() const, void(SageNode::*setter)(SageChild *))
swaps children (of equal kind) between two ancestor nodes of the same type
std::remove_const< typenamestd::remove_reference< RoseVisitor >::type >::type dispatch(RoseVisitor &&rv, SgNode *n)
uncovers the type of SgNode and passes it to an function "handle" in RoseVisitor.
This file implements generic (template) sage query functions Currently this includes functions for: