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;
85#include "rose_config.h"
88namespace EDG_ROSE_Translation
91#if defined(ROSE_BUILD_CXX_LANGUAGE_SUPPORT) && !defined(ROSE_USE_CLANG_FRONTEND)
93 extern std::map<std::string, SgIncludeFile*> edg_include_file_map;
96 std::map<std::string, SgIncludeFile*> edg_include_file_map;
103#include "detectMacroOrIncludeFileExpansions.h"
106 template<
class T>
void setSourcePositionToDefault( T* node );
110#ifdef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
111 #include "transformationSupport.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:
1695 case V_SgTemplateVariableInstantiation:
1698 case V_SgVariableDeclaration:
1702 name =
"_variable_declaration_";
1704 ROSE_ASSERT(variableDeclaration != NULL);
1705 SgInitializedNamePtrList::const_iterator i = variableDeclaration->
get_variables().begin();
1708 ROSE_ASSERT(i != variableDeclaration->
get_variables().end());
1711 name += string((*i)->get_name().str());
1720 case V_SgVariableDefinition:
1724 name =
"_variable_definition_";
1726 ROSE_ASSERT(variableDefinition != NULL);
1729 ROSE_ASSERT(variableDefinition->
get_vardefn() != NULL);
1735 case V_SgPragmaDeclaration:
1737 name =
"_pragma_declaration_";
1739 ROSE_ASSERT(pragmaDeclaration != NULL);
1740 ROSE_ASSERT(pragmaDeclaration->get_pragma() != NULL);
1741 name +=
get_name(pragmaDeclaration->get_pragma());
1746 case V_SgUsingDirectiveStatement:
1748 name =
"_using_directive_statement_";
1750 ROSE_ASSERT(usingDeclaration != NULL);
1757 case V_SgNamespaceAliasDeclarationStatement:
1759 name =
"_namespace_alias_directive_statement_";
1761 ROSE_ASSERT(namespaceAliasDeclaration != NULL);
1762 ROSE_ASSERT(namespaceAliasDeclaration->
get_name().is_null() ==
false);
1763 name += namespaceAliasDeclaration->
get_name();
1768 case V_SgUsingDeclarationStatement:
1770 name =
"_using_declaration_statement_";
1772 ROSE_ASSERT(usingDeclaration != NULL);
1786 case V_SgTemplateInstantiationDirectiveStatement:
1788 name =
"_template_instantiation_directive_statement_";
1789 ROSE_ASSERT(declaration != NULL);
1791 ROSE_ASSERT(templateInstantiationDirective != NULL);
1792 ROSE_ASSERT(templateInstantiationDirective->
get_declaration() != NULL);
1800 case V_SgCtorInitializerList:
1802 name =
"_ctor_list_";
1804 ROSE_ASSERT(ctorDeclaration != NULL);
1805 ROSE_ASSERT(ctorDeclaration->
get_parent() != NULL);
1813 name =
"_asm_stmt_";
1814 const SgAsmStmt* asmStatement = isSgAsmStmt(declaration);
1815 ROSE_ASSERT(asmStatement != NULL);
1816 ROSE_ASSERT(asmStatement->
get_parent() != NULL);
1822 case V_SgImplicitStatement:
1824 name =
"_fortran_implicit_";
1826 ROSE_ASSERT(implicitStatement != NULL);
1827 ROSE_ASSERT(implicitStatement->
get_parent() != NULL);
1833 case V_SgNamelistStatement:
1835 name =
"_fortran_namelist_";
1837 ROSE_ASSERT(namelistStatement != NULL);
1838 ROSE_ASSERT(namelistStatement->
get_parent() != NULL);
1844 case V_SgEquivalenceStatement:
1846 name =
"_fortran_equivalence_";
1848 ROSE_ASSERT(equivalenceStatement != NULL);
1849 ROSE_ASSERT(equivalenceStatement->
get_parent() != NULL);
1856 case V_SgCommonBlock:
1858 name =
"_fortran_common_block_";
1859 const SgCommonBlock* commonBlockStatement = isSgCommonBlock(declaration);
1860 ROSE_ASSERT(commonBlockStatement != NULL);
1861 ROSE_ASSERT(commonBlockStatement->
get_parent() != NULL);
1867 case V_SgImportStatement:
1869 name =
"_fortran_import_stmt_";
1871 ROSE_ASSERT(importStatement != NULL);
1872 ROSE_ASSERT(importStatement->
get_parent() != NULL);
1878 case V_SgFormatStatement:
1880 name =
"_fortran_format_stmt_";
1882 ROSE_ASSERT(formatStatement != NULL);
1883 ROSE_ASSERT(formatStatement->
get_parent() != NULL);
1889 case V_SgModuleStatement:
1891 name =
"_fortran_module_stmt_";
1893 ROSE_ASSERT(moduleStatement != NULL);
1894 ROSE_ASSERT(moduleStatement->
get_parent() != NULL);
1900 case V_SgUseStatement:
1902 name =
"_fortran_use_stmt_";
1903 const SgUseStatement* useStatement = isSgUseStatement(declaration);
1904 ROSE_ASSERT(useStatement != NULL);
1905 ROSE_ASSERT(useStatement->
get_parent() != NULL);
1911 case V_SgContainsStatement:
1913 name =
"_fortran_contains_stmt_";
1915 ROSE_ASSERT(containsStatement != NULL);
1916 ROSE_ASSERT(containsStatement->
get_parent() != NULL);
1922 case V_SgEntryStatement:
1924 name =
"_fortran_entry_stmt_";
1926 ROSE_ASSERT(entryStatement != NULL);
1927 ROSE_ASSERT(entryStatement->
get_parent() != NULL);
1933 case V_SgAttributeSpecificationStatement:
1935 name =
"_fortran_attribute_specification_stmt_";
1937 ROSE_ASSERT(statement != NULL);
1938 ROSE_ASSERT(statement->
get_parent() != NULL);
1943 case V_SgInterfaceStatement:
1945 name =
"_fortran_interface_stmt_";
1947 ROSE_ASSERT(statement != NULL);
1948 ROSE_ASSERT(statement->
get_parent() != NULL);
1953 case V_SgFortranIncludeLine:
1955 name =
"_fortran_include_line_stmt_";
1957 ROSE_ASSERT(statement != NULL);
1958 ROSE_ASSERT(statement->
get_parent() != NULL);
1964 case V_SgJavaImportStatement:
1966 name =
"_java_import_stmt_";
1968 ROSE_ASSERT(statement != NULL);
1969 ROSE_ASSERT(statement->
get_parent() != NULL);
1974 case V_SgJavaPackageDeclaration:
1976 name =
"_java_package_declaration_";
1978 ROSE_ASSERT(package_declaration != NULL);
1979 ROSE_ASSERT(package_declaration->
get_parent() != NULL);
1984 case V_SgJavaPackageStatement:
1986 name =
"_java_package_stmt_";
1988 ROSE_ASSERT(statement != NULL);
1989 ROSE_ASSERT(statement->
get_parent() != NULL);
1995 case V_SgStaticAssertionDeclaration:
1997 name =
"_static_assertion_declaration_stmt_";
1999 ROSE_ASSERT(statement != NULL);
2000 ROSE_ASSERT(statement->
get_parent() != NULL);
2005 case V_SgNonrealDecl:
2007 const SgNonrealDecl * nrdecl = isSgNonrealDecl(declaration);
2008 ROSE_ASSERT(nrdecl != NULL);
2009 name = nrdecl->get_name();
2014 case V_SgEmptyDeclaration:
2017 ROSE_ASSERT(emptyDeclaration != NULL);
2022 case V_SgAdaPackageSpecDecl:
2024 name = genericGetName(isSgAdaPackageSpecDecl(declaration));
2028 case V_SgAdaPackageBodyDecl:
2030 name = genericGetName(isSgAdaPackageBodyDecl(declaration));
2034 case V_SgAdaFormalTypeDecl:
2036 name = genericGetName(isSgAdaFormalTypeDecl(declaration));
2040 case V_SgAdaGenericDecl:
2044 name =
get_name(gendcl->get_declaration());
2047 if (isSgFunctionDeclaration(dcl->get_declaration())) {
2048 name =
"_ada_generic_decl_" + genericGetName(isSgFunctionDeclaration(dcl->get_declaration()));
2051 if (isSgAdaPackageSpecDecl(dcl->get_declaration())) {
2052 name =
"_ada_generic_decl_" + genericGetName(isSgAdaPackageSpecDecl(dcl->get_declaration()));
2062 case V_SgAdaDiscriminatedTypeDecl:
2073 name =
"_incomplete_Ada_discriminated_type_";
2079 case V_SgAdaVariantDecl:
2081 name =
"_ada_variant_decl_";
2085 case V_SgAdaAttributeClause:
2087 name =
"_ada_attribute_clause_";
2091 case V_SgAdaRepresentationClause:
2093 name =
"_ada_representation_clause_";
2097 case V_SgAdaEnumRepresentationClause:
2099 name =
"_ada_enum_representation_clause_";
2103 case V_SgAdaComponentClause:
2105 name =
"_ada_component_clause_";
2109 case V_SgAdaTaskTypeDecl:
2111 name = genericGetName(isSgAdaTaskTypeDecl(declaration));
2115 case V_SgAdaProtectedTypeDecl:
2117 name = genericGetName(isSgAdaProtectedTypeDecl(declaration));
2121 case V_SgAdaTaskBodyDecl:
2123 name = genericGetName(isSgAdaTaskBodyDecl(declaration));
2127 case V_SgAdaProtectedBodyDecl:
2129 name = genericGetName(isSgAdaProtectedBodyDecl(declaration));
2133 case V_SgAdaRenamingDecl:
2135 name = genericGetName(isSgAdaRenamingDecl(declaration));
2139 case V_SgAdaTaskSpecDecl:
2141 name = genericGetName(isSgAdaTaskSpecDecl(declaration));
2145 case V_SgAdaProtectedSpecDecl:
2147 name = genericGetName(isSgAdaProtectedSpecDecl(declaration));
2151 case V_SgAdaGenericInstanceDecl:
2153 name = genericGetName(isSgAdaGenericInstanceDecl(declaration));
2157 case V_SgAdaFormalPackageDecl:
2159 name = genericGetName(isSgAdaFormalPackageDecl(declaration));
2163 case V_SgAdaParameterList:
2168 name = std::accumulate( plst->get_parameters().begin(), plst->get_parameters().end(),
2169 std::string{
"_ada_parameter_list_"},
2172 n += SageInterface::get_name(rhs);
2181 printf (
"Warning: default case reached in SageInterface::get_name ( const SgDeclarationStatement* declaration ), declaration = %p = %s \n",
2182 declaration,declaration->
class_name().c_str());
2192 string name =
"undefined_name";
2194 ROSE_ASSERT(scope != NULL);
2199 case V_SgTemplateClassDefinition:
2200 name =
get_name(isSgTemplateClassDefinition(scope)->get_declaration());
2203 case V_SgClassDefinition:
2204 case V_SgTemplateInstantiationDefn:
2205 name =
get_name(isSgClassDefinition(scope)->get_declaration());
2209 case V_SgTemplateFunctionDefinition:
2210 case V_SgFunctionDefinition:
2211 name =
get_name(isSgFunctionDefinition(scope)->get_declaration());
2214 case V_SgNamespaceDefinitionStatement:
2215 name =
get_name(isSgNamespaceDefinitionStatement(scope)->get_namespaceDeclaration());
2217 case V_SgJavaLabelStatement:
2218 name = (isSgJavaLabelStatement(scope)->get_label()).getString();
2222 case V_SgDeclarationScope:
2225 case V_SgAssociateStatement:
2226 case V_SgJavaForEachStatement:
2228 case V_SgFunctionParameterScope:
2229 case V_SgAdaPackageSpec:
2230 case V_SgAdaPackageBody:
2231 case V_SgAdaTaskSpec:
2232 case V_SgAdaTaskBody:
2233 case V_SgAdaProtectedSpec:
2234 case V_SgAdaProtectedBody:
2235 case V_SgAdaGenericDefn:
2236 case V_SgAdaAcceptStmt:
2237 case V_SgJovialForThenStatement:
2238 case V_SgMatlabForStatement:
2239 case V_SgBasicBlock:
2240 case V_SgCatchOptionStmt:
2241 case V_SgDoWhileStmt:
2242 case V_SgForStatement:
2245 case V_SgSwitchStatement:
2248 case V_SgForAllStatement:
2249 case V_SgRangeBasedForStatement:
2254 printf (
"Error: undefined case (SgScopeStatement) in SageInterface::get_name(): node = %s \n",scope->
class_name().c_str());
2264 string name =
"undefined_name";
2266 ROSE_ASSERT(stmt != NULL);
2269 if (declaration != NULL)
2287 case V_SgCaseOptionStmt:
2288 case V_SgCatchStatementSeq:
2289 case V_SgClinkageStartStatement:
2290 case V_SgContinueStmt:
2291 case V_SgDefaultOptionStmt:
2293 case V_SgForInitStmt:
2294 case V_SgFunctionTypeTable:
2295 case V_SgGotoStatement:
2296 case V_SgReturnStmt:
2302 case V_SgLabelStatement:
2305 name = labelStatement->
get_label().str();
2328 ROSE_ASSERT(node != NULL);
2330 string name =
"undefined_name";
2332 ROSE_ASSERT(node != NULL);
2336 case V_SgInitializedName:
2339 if (initializedName != NULL)
2341 name = initializedName->get_name().str();
2349 name =
"_pragma_string_";
2350 const SgPragma* pragma = isSgPragma(node);
2351 ROSE_ASSERT(pragma != NULL);
2352 name += pragma->get_pragma();
2366 case V_SgSourceFile:
2367#ifdef ROSE_ENABLE_BINARY_ANALYSIS
2368 case V_SgBinaryComposite:
2374 const SgFile* file = isSgFile(node);
2375 ROSE_ASSERT(file != NULL);
2382 case V_SgSymbolTable:
2384 name =
"_symbol_table_";
2389 case V_SgStorageModifier:
2391 name =
"_storage_modifier_";
2397 case V_Sg_File_Info:
2399 name =
"_file_info_";
2404 case V_SgTemplateArgument:
2406 name =
"_template_argument_";
2408 ROSE_ASSERT(templateArgument != NULL);
2414 ROSE_ASSERT(t != NULL);
2428 ROSE_ASSERT(templateArgument->get_initializedName() == NULL);
2433 ROSE_ASSERT(t == NULL);
2435 ROSE_ASSERT(initializedName != NULL);
2446 ROSE_ASSERT(t != NULL);
2453 printf (
"Error: default case reached in switch on templateArgument->get_argumentType() \n");
2462 case V_SgTypeModifier:
2465 ROSE_ASSERT(typeModifier != NULL);
2466 name =
"_type_modifier_" + typeModifier->displayString();
2473 const SgNameGroup* nameGroup = isSgNameGroup(node);
2474 ROSE_ASSERT(nameGroup != NULL);
2475 name =
"_name_group_" + nameGroup->get_group_name();
2480 case V_SgDataStatementGroup:
2483 ROSE_ASSERT(dataGroup != NULL);
2484 name =
"_data_statement_group_";
2489 case V_SgDataStatementObject:
2492 ROSE_ASSERT(dataObject != NULL);
2493 name =
"_data_statement_object_";
2498 case V_SgDataStatementValue:
2501 ROSE_ASSERT(dataValue != NULL);
2502 name =
"_data_statement_value_";
2507 case V_SgCommonBlockObject:
2510 ROSE_ASSERT(commonBlockObject != NULL);
2511 name =
"_common_block_object_" + commonBlockObject->get_block_name();
2516 case V_SgFormatItem:
2519 ROSE_ASSERT(formatItem != NULL);
2520 name =
"_format_item_";
2525 case V_SgFormatItemList:
2528 ROSE_ASSERT(formatItemList != NULL);
2529 name =
"_format_item_list_";
2534 case V_SgRenamePair:
2537 ROSE_ASSERT(renamePair != NULL);
2538 name = renamePair->get_local_name() +
"__" + renamePair->get_use_name() +
"_rename_pair_";
2545 const SgName* name_node = isSgName(node);
2546 ROSE_ASSERT(name_node != NULL);
2547 name =
"_name_" + name_node->getString();
2552 case V_SgTemplateParameter:
2555 ROSE_ASSERT(template_parameter_node != NULL);
2556 name =
"_template_parameter_";
2558 switch(template_parameter_node->get_parameterType())
2562 name +=
"type_parameter_";
2568 name +=
"nontype_parameter_";
2572 if (template_parameter_node->get_expression() != NULL)
2578 ROSE_ASSERT(template_parameter_node->get_initializedName() != NULL);
2584 name += template_parameter_node->get_initializedName()->
unparseToString();
2592 name +=
"template_parameter_";
2598 printf (
"Error: default reached \n");
2608 const SgBaseClass* base_class_node = isSgBaseClass(node);
2609 ROSE_ASSERT(base_class_node != NULL);
2610 ROSE_ASSERT(base_class_node->get_base_class() != NULL);
2615 ROSE_ASSERT(baseClassModifier != NULL);
2616 access = baseClassModifier->displayString();
2618 name =
"_base_class_" + access +
"_" +
get_name(base_class_node->get_base_class());
2624 printf (
"Default reached in switch for SgSupport IR node = %s \n",node->
class_name().c_str());
2625 name =
"default name";
2640 ROSE_ASSERT(symbol != NULL);
2642 string aliasSymbolPrefix =
"";
2643 if (isSgAliasSymbol(symbol) != NULL)
2645 aliasSymbolPrefix =
"_ALIAS";
2652 return symbol->
get_name() + aliasSymbolPrefix +
"_symbol_";
2660 ROSE_ASSERT(type != NULL);
2664 const SgNamedType* namedType = isSgNamedType(type);
2665 if (namedType != NULL)
2667 returnName =
"named_type_";
2668 returnName = namedType->
get_name().getString();
2674 case V_SgPointerType:
2677 returnName =
"pointer_to_";
2678 returnName +=
get_name(pointerType->get_base_type());
2682 case V_SgReferenceType:
2685 returnName =
"reference_to_";
2686 returnName +=
get_name(referenceType->get_base_type());
2692 const SgArrayType* arrayType = isSgArrayType(type);
2693 returnName =
"array_of_";
2694 returnName +=
get_name(arrayType->get_base_type());
2698 case V_SgModifierType:
2702 returnName +=
get_name(modifierType->get_base_type());
2707 case V_SgTemplateType:
2710 returnName =
"templateType_";
2711 returnName += templateType->get_name();
2728 string name =
"undefined_name";
2736 name =
"var_ref_of_";
2737 ROSE_ASSERT(varRef != NULL);
2738 ROSE_ASSERT(varRef->get_symbol() != NULL);
2739 name += varRef->get_symbol()->
get_name();
2744 case V_SgLabelRefExp:
2747 name =
"label_ref_of_";
2748 ROSE_ASSERT(labelRef != NULL);
2749 ROSE_ASSERT(labelRef->get_symbol() != NULL);
2750 name += labelRef->get_symbol()->
get_name();
2754 case V_SgPntrArrRefExp:
2757 name =
"array_ref_of_";
2764 case V_SgFunctionCallExp:
2767 name =
"function_call_";
2768 name +=
get_name(functionCall->get_function());
2772 case V_SgFunctionRefExp:
2775 name =
"function_ref_";
2776 name += functionRefExp->get_symbol()->
get_name();
2781 case V_SgMemberFunctionRefExp:
2784 name =
"member_function_ref_";
2785 name += memberFunctionRefExp->get_symbol()->
get_name();
2791 const SgIntVal* valueExp = isSgIntVal(expr);
2792 name =
"integer_value_exp_";
2799 const SgStringVal* valueExp = isSgStringVal(expr);
2800 name =
"string_value_exp_";
2801 name += valueExp->get_value();
2805 case V_SgSubscriptExpression:
2808 name =
"subscript_exp_";
2810 name +=
get_name(subscriptExpression->get_lowerBound());
2813 name +=
get_name(subscriptExpression->get_upperBound());
2816 name +=
get_name(subscriptExpression->get_stride());
2820 case V_SgNullExpression:
2822 name =
"null_expression";
2827 case V_SgExprListExp:
2830 name =
"expr_list_exp_";
2831 for (
size_t i = 0; i < exprListExp->get_expressions().size(); i++)
2833 name +=
get_name(exprListExp->get_expressions()[i]);
2839 case V_SgActualArgumentExpression:
2842 name =
"actual_arg_exp_name_";
2843 name += actualArgExp->get_argument_name();
2845 name +=
get_name(actualArgExp->get_expression());
2850 case V_SgTemplateParameterVal:
2853 name =
"template_parameter_value_expression_number_";
2863 const SgDotExp* dotExp = isSgDotExp(expr);
2864 ROSE_ASSERT(dotExp != NULL);
2866 name =
"_dot_exp_lhs_";
2868 name +=
"_dot_exp_rhs_";
2877 const SgLambdaExp* lambdaExp = isSgLambdaExp(expr);
2878 ROSE_ASSERT (lambdaExp != NULL);
2879 name =
"lambda_expression_";
2886 const SgThisExp* thisExp = isSgThisExp(expr);
2887 ROSE_ASSERT(thisExp != NULL);
2889 name =
"_this_exp_for_";
2892 ROSE_ASSERT(classSymbol != NULL);
2905 printf (
"Note: default reached in get_name() expr = %p = %s \n",expr,expr->
class_name().c_str());
2924 ROSE_ASSERT(node != NULL);
2930 case V_SgRenamePair:
2933 returnName =
"rename_pair_";
2934 returnName += n->get_local_name().str();
2935 returnName +=
"_from_";
2936 returnName += n->get_use_name().str();
2940 case V_SgInitializedName:
2943 ROSE_ASSERT (n != NULL);
2944 returnName =
"initialized_name_";
2945 returnName += n->get_name().str();
2950 case V_SgLambdaCapture:
2953 ROSE_ASSERT (n != NULL);
2954 returnName =
"lambda_capture_";
2960 case V_SgInterfaceBody:
2963 returnName =
"interface_body";
2983 string name =
"undefined_name";
2985 ROSE_ASSERT(node != NULL);
2988 if (locatedNode != NULL)
2990 const SgStatement* statement = isSgStatement(node);
2991 if (statement != NULL)
2998 if (expression != NULL)
3005 if (locatedNodeSupport != NULL)
3007 name =
get_name(locatedNodeSupport);
3011 const SgToken* token = isSgToken(node);
3018 printf (
"Unknown SgLocatedNode = %p = %s \n",node,node->
class_name().c_str());
3027 const SgSupport* supportNode = isSgSupport(node);
3028 if (supportNode != NULL)
3035 const SgSymbol* symbol = isSgSymbol(node);
3043 const SgType* type = isSgType(node);
3064 string name =
"undefined_name";
3066 ROSE_ASSERT(token != NULL);
3067 name = token->get_lexeme_string();
3072 else if (name ==
"\n")
3074 else if (name ==
"\t")
3116 case V_SgClassDeclaration:
3117 case V_SgTemplateClassDeclaration:
3121 ROSE_ASSERT(classDeclaration != NULL);
3123 string type_name = classDeclaration->get_name();
3125 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case class or template type: type_name = %s \n",type_name.c_str());
3127 string className = string(
"scope_") + scope +
"_type_name_" + type_name;
3129 printf (
"classDeclaration->get_scope() = %p = %s scope = %s \n",classDeclaration->
get_scope(),classDeclaration->
get_scope()->
class_name().c_str(),scope.c_str());
3136 case V_SgTemplateInstantiationDecl:
3139 ROSE_ASSERT(templateInstantiationDeclaration != NULL);
3145 string type_name = templateInstantiationDeclaration->get_name();
3147 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgTemplateInstantiationDecl: type_name = %s \n",type_name.c_str());
3149 string className = string(
"scope_") + scope +
"_type_name_" + type_name;
3164 printf (
"className = %s compressedClassName = %s \n",className.c_str(),compressedClassName.c_str());
3167 printf (
"templateInstantiationDeclaration->get_scope() = %p = %s scope = %s \n",
3171 s = compressedClassName;
3173 printf (
"Exiting as a test! \n");
3179 case V_SgFunctionDeclaration:
3180 case V_SgTemplateFunctionDeclaration:
3181 case V_SgTemplateInstantiationFunctionDecl:
3184 ROSE_ASSERT(functionDeclaration != NULL);
3186 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgFunctionDeclaration: not implemented \n");
3189 string original_name = functionDeclaration->get_name();
3191 string function_name_part = mangleFunctionName(original_name,
"return_type");
3192 string function_name = string(
"scope_") + scope +
"_function_name_" + function_name_part;
3206 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): Collision count = %d \n",count);
3213 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): case SgFunctionDeclaration: Exiting as a test! \n");
3219 case V_SgMemberFunctionDeclaration:
3220 case V_SgTemplateMemberFunctionDeclaration:
3221 case V_SgTemplateInstantiationMemberFunctionDecl:
3224 ROSE_ASSERT(memberFunctionDeclaration != NULL);
3226 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgMemberFunctionDeclaration: not implemented \n");
3229 string original_name = memberFunctionDeclaration->get_name();
3235 string member_function_name_part = mangleFunctionName(original_name,
"return_type");
3237 string member_function_name = string(
"scope_") + scope +
"_member_function_name_" + member_function_name_part;
3251 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): Collision count = %d \n",count);
3256 s = member_function_name;
3258 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): case SgMemberFunctionDeclaration: Exiting as a test! \n");
3266 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): Unsupported declaration = %p = %s \n",declaration,declaration->
class_name().c_str());
3272 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): s = %s \n",s.c_str());
3277 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): s = %s \n",s.c_str());
3282 printf (
"Exiting as a test! \n");
3301 printf (
"In generateUniqueNameForUseAsIdentifier(): evaluating declaration = %p = %s \n",declaration,declaration->
class_name().c_str());
3314 if (definingDeclaration != NULL)
3317 printf (
"In generateUniqueName(): Using the defining declaration = %p since %p was not in the map \n",definingDeclaration,declaration);
3325 printf (
"Warning: defining declaration not in SageInterface::local_node_to_name_map: declaration = %p = %s using name = %s \n",
3332 ROSE_ASSERT(nondefiningDeclaration != NULL);
3338 printf (
"Exiting as a test! \n");
3349 ROSE_ASSERT(astNode != NULL);
3359 void visit (
SgNode* node)
3366 if (classDeclaration != NULL || functionDeclaration != NULL)
3377 UniqueNameTraversal traversal;
3378 traversal.traverse(astNode, preorder);
3388 ROSE_ASSERT(classDeclaration != NULL);
3390 ROSE_ASSERT(definingDeclaration != NULL);
3391 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(definingDeclaration);
3395 if (definingClassDeclaration != NULL)
3397 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3398 ROSE_ASSERT(classDefinition != NULL);
3400 SgDeclarationStatementPtrList::iterator i = classDefinition->
get_members().begin();
3401 while ( i != classDefinition->
get_members().end() )
3404 ROSE_ASSERT( (*i)->get_parent() != NULL);
3405 ROSE_ASSERT( (*i)->get_parent() == classDefinition);
3408 if (memberFunction != NULL)
3411 if ( memberFunction->get_specialFunctionModifier().isConstructor() ==
true )
3412 defaultConstructor = memberFunction;
3423 return defaultConstructor;
3431 ROSE_ASSERT(classDeclaration != NULL);
3433 if (definingDeclaration != NULL)
3435 ROSE_ASSERT(definingDeclaration != NULL);
3436 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(definingDeclaration);
3440 if (definingClassDeclaration != NULL)
3442 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3443 ROSE_ASSERT(classDefinition != NULL);
3445 SgDeclarationStatementPtrList::iterator i = classDefinition->
get_members().begin();
3446 while ( i != classDefinition->
get_members().end() )
3450 ROSE_ASSERT(i_parent != NULL);
3455 if ( i_parent != classDefinition )
3457 printf (
"Error: (*i)->get_parent() = %p = %s \n",i_parent,i_parent->
class_name().c_str());
3458 printf (
"(*i) = %p = %s = %s \n",*i,(*i)->class_name().c_str(),(*i)->unparseToString().c_str());
3459 (*i)->get_file_info()->display(
"Called from SageInterface::getDefaultDestructor: debug");
3461 ROSE_ASSERT( i_parent == classDefinition);
3464 if (memberFunction != NULL)
3466 if ( memberFunction->get_specialFunctionModifier().isDestructor() ==
true )
3467 defaultDestructor = memberFunction;
3476 return defaultDestructor;
3488#define DEBUG_ADD_DEFAULT_CONSTRUCTOR 0
3492 ASSERT_not_null(classType);
3494 bool returnValue =
false;
3497 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
3498 ROSE_ASSERT(classDeclaration != NULL);
3500 ROSE_ASSERT(definingClassDeclaration != NULL);
3501 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3502 ROSE_ASSERT(classDefinition != NULL);
3504 SgDeclarationStatementPtrList & declarationList = classDefinition->
get_members();
3506 bool foundConstructor =
false;
3507 bool foundDefaultConstructor =
false;
3509#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3510 printf (
"In addDefaultConstructorIfRequired(): class name = %s \n",classDeclaration->get_name().str());
3513 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
3514 while (i != declarationList.end())
3517 if (memberFunctionDeclaration != NULL)
3519 bool isConstructor = memberFunctionDeclaration->get_specialFunctionModifier().isConstructor();
3520 if (isConstructor ==
true)
3522 foundConstructor =
true;
3524#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3525 printf (
"Found a constructor! \n");
3528 ROSE_ASSERT(functionParameterList != NULL);
3532 foundDefaultConstructor = ((foundDefaultConstructor ==
true) || (functionParameterList->
get_args().size() == 0));
3534#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3535 if (foundDefaultConstructor ==
true)
3537 printf (
"Found a default constructor! \n");
3541 printf (
"This is not a default constructor: functionParameterList->get_args().size() = %zu \n",functionParameterList->
get_args().size());
3547#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3548 printf (
"This is not a constructor \n");
3556#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3557 printf (
"foundConstructor = %s \n",foundConstructor ?
"true" :
"false");
3558 printf (
"foundDefaultConstructor = %s \n",foundDefaultConstructor ?
"true" :
"false");
3561 if (foundConstructor ==
true)
3564#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3565 printf (
"Since there is at least one constructor, we can't rely on compiler generated constructors \n");
3567 if (foundDefaultConstructor ==
true)
3570#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3571 printf (
"We can use the existing default constructor (no need to build one) \n");
3578#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3579 printf (
"########################################################### \n");
3580 printf (
"Need to build a default constructor in the associated class \n");
3583 ROSE_ASSERT(constructorDeclaration != NULL);
3585#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3586 printf (
" --- constructorDeclaration = %p = %s name = %s \n",constructorDeclaration,constructorDeclaration->
class_name().c_str(),constructorDeclaration->get_name().str());
3588 ROSE_ASSERT (constructorDeclaration->get_declarationModifier().get_accessModifier().isPublic() ==
true);
3590 classDefinition->prepend_statement(constructorDeclaration);
3593 ROSE_ASSERT(constructorDeclaration->
get_parent() != NULL);
3601 constructorDeclaration->
get_endOfConstruct ()->set_physical_file_id(physical_file_id);
3605 ROSE_ASSERT(constructorDeclaration->get_definition() != NULL);
3608 constructorDeclaration->get_definition()->
get_startOfConstruct()->set_physical_file_id(physical_file_id);
3609 constructorDeclaration->get_definition()->
get_endOfConstruct ()->set_physical_file_id(physical_file_id);
3612#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3613 printf (
"DONE: Need to build a default constructor in the associated class \n");
3614 printf (
"################################################################# \n");
3617 printf (
"Exiting as a test! \n");
3626#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3627 printf (
"No constructors found, so we don't need to add an explicit default constructor \n");
3631#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3632 printf (
"Leaving addDefaultConstructorIfRequired(): returnValue = %s \n",returnValue ?
"true" :
"false");
3664 astTraversal.
traverse(node,preorder);
3674 printf (
"Exiting as a test! \n");
3684 printf (
"Symbol Table from %p = %s at: \n",scope,scope->
sage_class_name());
3685 scope->
get_file_info()->display(
"Symbol Table Location (Called from SageInterface::OutputLocalSymbolTables::visit())");
3687 scope->print_symboltable(
"Called from SageInterface::OutputLocalSymbolTables::visit()");
3702 bool result =
false;
3717 bool result =
false;
3721 if (isTemplateMemberFunction(memberFunctionDeclaration) ==
true)
3724 printf (
"templateDeclaration = %p parent of templateDeclaration = %p \n",templateDeclaration,templateDeclaration->
get_parent());
3727 SgClassDeclaration* classDeclaration = memberFunctionDeclaration->get_class_scope()->get_declaration();
3728 ROSE_ASSERT(classDeclaration != NULL);
3731 if (classTemplateInstantiation != NULL)
3734 if (classTemplateDeclaration != NULL && classTemplateDeclaration != templateDeclaration)
3748 if (templateDeclaration != NULL && templateDeclaration->
get_parent() != NULL)
3751 if (isSgClassDefinition(parentScope) != NULL)
3764 printf (
"Error: This is no longer used. \n");
3777 if (firstNondefiningDeclaration != NULL)
3778 keyDeclaration = firstNondefiningDeclaration;
3780 keyDeclaration = definingDeclaration;
3781 ROSE_ASSERT(keyDeclaration != NULL);
3783 return keyDeclaration;
3789 string pragmaString = pragmaDeclaration->get_pragma()->get_pragma();
3790 istringstream istr(pragmaString);
3800 ROSE_ASSERT (n != NULL);
3801 bool result =
false;
3802 if (isSgOmpBarrierStatement(n)||
3803 isSgOmpBodyStatement(n)||
3804 isSgOmpDeclareSimdStatement(n) ||
3805 isSgOmpFlushStatement(n)||
3806 isSgOmpThreadprivateStatement(n)||
3807 isSgOmpTaskwaitStatement(n) )
3835 if (memberFunctionDeclaration != NULL)
3845 ROSE_ASSERT(scope != NULL);
3848 if (isSgDeclarationScope(scope)) {
3849 printf(
"TODO SageInterface::isOverloaded case when scope is SgDeclarationScope. See ROSE-1378.\n");
3855 isSgClassDefinition(memberFunctionDeclaration->
get_scope());
3856 ROSE_ASSERT(classDefinition != NULL);
3860 ROSE_ASSERT(classDeclaration != NULL);
3863 SgDeclarationStatementPtrList & memberList = classDefinition->
get_members();
3866 printf (
" memberList.size() = %" PRIuPTR
" \n",memberList.size());
3868 for (SgDeclarationStatementPtrList::iterator i = memberList.begin(); i != memberList.end(); i++)
3871 printf (
" counter = %d declaration = %p = %s \n",counter,*i,(*i)->class_name().c_str());
3877 if (tempMemberFunction != NULL)
3882 if ( keyDeclaration == generateUniqueDeclaration(tempMemberFunction) )
3885 printf (
"Skipping the case of keyDeclaration == generateUniqueDeclaration(tempMemberFunction) = %p \n",keyDeclaration);
3890 ROSE_ASSERT(tempMemberFunction->get_name() !=
"");
3892 printf (
" tempMemberFunction = (name) %s = (qualified) %s \n",
3893 tempMemberFunction->get_name().str(),
3894 tempMemberFunction->get_qualified_name().str());
3896 if (tempMemberFunction->get_name() == memberFunctionDeclaration->get_name())
3899 printf (
" Found a matching overloaded member function! \n");
3908 if (tempTemplateDeclaration != NULL)
3914 printf (
"tempTemplateDeclaration->get_name() = %s \n",tempTemplateDeclaration->
get_name().str());
3916 if (memberFunctionDeclaration->get_name() == tempTemplateDeclaration->
get_name())
3919 printf (
" Found a matching overloaded member function! \n");
3928 if (functionDeclaration->
variantT() == V_SgFunctionDeclaration)
3930 printf (
"In SageInterface::isOverloaded(): could friend functions be overloaded in a class? \n");
3943 printf (
"In SageInterface::isOverloaded(): case of non-member function not yet implemented! \n");
3950 return (counter > 1);
3965 ROSE_ASSERT(memberFunctionInstantiation != NULL);
3968 printf (
"buildForwardFunctionDeclaration: Member function = %p = %s = definition = %p \n",
3969 memberFunctionInstantiation,
3970 memberFunctionInstantiation->get_name().str(),
3971 memberFunctionInstantiation->get_definition());
3972 memberFunctionInstantiation->
get_file_info()->display(
"memberFunctionInstantiation: debug");
3978 class NondefiningFunctionDeclarationCopyType :
public SgCopyHelp
3988 SgNode* returnValue = NULL;
3996 case V_SgFunctionDeclaration:
3997 case V_SgMemberFunctionDeclaration:
3998 case V_SgTemplateInstantiationFunctionDecl:
3999 case V_SgTemplateInstantiationMemberFunctionDecl:
4003 ROSE_ASSERT(functionDeclaration != NULL);
4009 returnValue =
const_cast<SgNode *
>(n);
4021 case V_SgFunctionDefinition:
4023 printf (
"Skip copying the function definition if it is present \n");
4025 returnValue =
const_cast<SgNode *
>(n);
4039 if (returnValue == NULL)
4040 returnValue = n->copy(*
this);
4042 ROSE_ASSERT(returnValue != NULL);
4045 } nondefiningFunctionDeclarationCopy;
4050 if (memberFunctionInstantiation->get_definition() != NULL)
4052 printf (
"\n\nNEED TO REMOVE POINTERS IN THE NON-DEFINING DECLARATION TO THE SgClassDefinition objects. \n");
4057 memberFunctionInstantiation->set_definition(NULL);
4059 SgNode* copyOfMemberFunctionNode = memberFunctionInstantiation->copy(nondefiningFunctionDeclarationCopy);
4078 printf (
"copyOfMemberFunction->isForward() = %s \n",copyOfMemberFunction->
isForward() ?
"true" :
"false");
4079 printf (
"memberFunctionInstantiation->isForward() = %s \n",memberFunctionInstantiation->
isForward() ?
"true" :
"false");
4082 printf (
"memberFunctionInstantiation->isSpecialization() = %s \n",memberFunctionInstantiation->isSpecialization() ?
"true" :
"false");
4083 printf (
"copyOfMemberFunctionNode = %p = %s = %s memberFunctionInstantiation->isSpecialization() = %s \n",
4084 copyOfMemberFunction,copyOfMemberFunction->
class_name().c_str(),
SageInterface::get_name(copyOfMemberFunction).c_str(),copyOfMemberFunction->isSpecialization() ?
"true" :
"false");
4085 copyOfMemberFunction->
get_file_info()->display(
"copyOfMemberFunction: debug");
4089 ROSE_ASSERT(memberFunctionInstantiation->get_args().size() == copyOfMemberFunction->get_args().size());
4095 ROSE_ASSERT(copyOfMemberFunction != NULL);
4096 return copyOfMemberFunction;
4105 ROSE_ASSERT(declarationForType != NULL);
4108 switch(declarationForType->
variantT())
4111 case V_SgTemplateInstantiationDecl:
4112 case V_SgTemplateClassDeclaration:
4114 case V_SgClassDeclaration:
4119 if (isSgTemplateClassDeclaration(declarationForType) != NULL)
4128 ROSE_ASSERT(symbol != NULL);
4129 SgName name = classDeclaration->get_name();
4130 symbolTable->insert(name,symbol);
4134 case V_SgEnumDeclaration:
4138 ROSE_ASSERT(symbol != NULL);
4140 symbolTable->insert(name,symbol);
4144 case V_SgFunctionDeclaration:
4148 ROSE_ASSERT(symbol != NULL);
4149 SgName name = functionDeclaration->get_name();
4150 symbolTable->insert(name,symbol);
4154 case V_SgMemberFunctionDeclaration:
4158 ROSE_ASSERT(symbol != NULL);
4162 SgName name = functionDeclaration->get_name();
4163 symbolTable->insert(name,symbol);
4169 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());
4180 SgInitializedNamePtrList::iterator i = variableList.begin();
4181 while (i != variableList.end())
4185 if (
variable->get_scope() == scope)
4193 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());
4198 ROSE_ASSERT(symbol != NULL);
4200 symbolTable->insert(name,symbol);
4208SageInterface::supportForInitializedNameLists (
SgScopeStatement* scope, SgInitializedNamePtrList & variableList )
4211 ROSE_ASSERT(symbolTable != NULL);
4213 supportForVariableLists(scope,symbolTable,variableList);
4221 SgInitializedNamePtrList & variableList = variableDeclaration->
get_variables();
4222 supportForVariableLists(scope,symbolTable,variableList);
4230 ROSE_ASSERT(symbolTable != NULL);
4241 std::vector<SgNode*> labelList = NodeQuery::querySubTree (scope,V_SgLabelStatement);
4243 int numberOfLabels = labelList.size();
4244 for (
int i=0; i < numberOfLabels; i++)
4248 ROSE_ASSERT(labelStatement != NULL);
4249 ROSE_ASSERT(labelStatement->
get_scope() == scope);
4252 ROSE_ASSERT(symbol != NULL);
4256 SgName name = labelStatement->get_name();
4257 symbolTable->insert(name,symbol);
4267 ROSE_ASSERT(scope != NULL);
4269 printf (
"In SageInterface::rebuildSymbolTable(): Symbol Table from %p = %s \n",scope,scope->
class_name().c_str());
4272 printf (
"Exiting as a test \n");
4278 if (symbolTable != NULL)
4281 if (symbolTable->
size() != 0)
4283 printf (
"symbolTable->size() = %d \n",symbolTable->
size());
4285 ROSE_ASSERT(symbolTable->
size() == 0);
4287 printf (
"Symbol Table from %p = %s of size = %" PRIuPTR
" \n",scope,scope->
class_name().c_str(),symbolTable->
size());
4288 symbolTable->
print(
"Called from SageInterface::rebuildSymbolTable()");
4294 printf (
"In SageInterface::rebuildSymbolTable(): No symbol table found \n");
4296 ROSE_ASSERT(symbolTable == NULL);
4301 ROSE_ASSERT(symbolTable != NULL);
4302 ROSE_ASSERT(symbolTable->get_table() != NULL);
4306 ROSE_ASSERT(symbolTable->
get_parent() != NULL);
4319 case V_SgForStatement:
4326 SgStatementPtrList::iterator i = forStatement->get_init_stmt().begin();
4330 while (i != forStatement->get_init_stmt().end())
4334 if (variableDeclarationInitializer != NULL)
4339 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationInitializer );
4345 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(forStatement->get_test());
4346 if (variableDeclarationCondition != NULL)
4351 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4358 case V_SgJovialForThenStatement:
4359 case V_SgMatlabForStatement:
4367 case V_SgTemplateFunctionDefinition:
4369 case V_SgFunctionDefinition:
4376 if (functionDefinition != NULL)
4382 if (functionDeclaration != NULL)
4385 if (functionDeclaration->
isForward() ==
true)
4387 printf (
"ERROR: functionDeclaration = %p = %s = %s \n",functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
4388 printf (
" --- functionDeclaration (get_name()) = %s \n",
get_name(functionDeclaration).c_str());
4389 printf (
" --- functionDeclaration (mangled name) = %s \n",functionDeclaration->get_mangled_name().str());
4391 if (memberFunctionDeclaration != NULL)
4393 printf (
"memberFunctionDeclaration != NULL \n");
4396 ROSE_ASSERT(functionDeclaration->
isForward() ==
false);
4397 SgInitializedNamePtrList & argumentList = functionDeclaration->get_args();
4398 supportForVariableLists(scope,symbolTable,argumentList);
4411 supportForLabelStatements(scope,symbolTable);
4422 SgIfStmt* ifStatement = isSgIfStmt(scope);
4424 if (variableDeclarationCondition != NULL)
4429 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4435 case V_SgSwitchStatement:
4442 if (variableDeclarationSelector != NULL)
4447 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationSelector );
4459 SgWhileStmt* whileStatement = isSgWhileStmt(scope);
4461 if (variableDeclarationCondition != NULL)
4467 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4473 case V_SgCatchOptionStmt:
4474 case V_SgDoWhileStmt:
4483 case V_SgTemplateClassDefinition:
4485 case V_SgBasicBlock:
4486 case V_SgClassDefinition:
4487 case V_SgTemplateInstantiationDefn:
4489 case V_SgNamespaceDefinitionStatement:
4497 case V_SgJavaForEachStatement:
4500 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(javaForEachStatement->get_element());
4501 if (variableDeclarationCondition != NULL)
4507 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4515 printf (
"Default reached in SageInterface::rebuildSymbolTable() scope = %p = %s \n",scope,scope->
class_name().c_str());
4521 printf (
"In SageInterface::rebuildSymbolTable(): fixup declarations in Symbol Table from %p = %s \n",scope,scope->
class_name().c_str());
4529 for (SgStatementPtrList::iterator i = statementList.begin(); i != statementList.end(); i++)
4536 if (declaration != NULL)
4542 list<SgSymbol*> symbolList;
4545 case V_SgTemplateInstantiationMemberFunctionDecl:
4549 if (scope == derivedDeclaration->
get_scope())
4552 ROSE_ASSERT(symbol != NULL);
4558 SgName name = derivedDeclaration->get_name();
4559 symbolTable->insert(name,symbol);
4570 ROSE_ASSERT(derivedDeclarationScope != NULL);
4577 ROSE_ASSERT(templateDeclaration != NULL);
4585 SgType* functionType = templateDeclaration->get_type();
4586 SgTemplateParameterPtrList & templateParameterList = templateDeclaration->get_templateParameters();
4589 if (templateSymbol != NULL)
4593 printf (
"Building a symbol for derivedDeclaration = %p = %s to an alternative symbol table in derivedDeclarationScope = %p \n",
4594 derivedDeclaration,
get_name(derivedDeclaration).c_str(),derivedDeclarationScope);
4597 ROSE_ASSERT(symbol != NULL);
4598 SgName name = derivedDeclaration->get_name();
4610 case V_SgTemplateMemberFunctionDeclaration:
4612 case V_SgMemberFunctionDeclaration:
4617 if (scope == derivedDeclaration->
get_scope())
4621 if (isSgTemplateFunctionDeclaration(declaration) != NULL)
4626 ROSE_ASSERT(symbol != NULL);
4630 SgName name = derivedDeclaration->get_name();
4631 symbolTable->insert(name,symbol);
4642 case V_SgTemplateInstantiationFunctionDecl:
4646 if (scope == derivedDeclaration->
get_scope())
4649 ROSE_ASSERT(symbol != NULL);
4650 SgName name = derivedDeclaration->get_name();
4651 symbolTable->insert(name,symbol);
4655 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4657#if PRINT_DEVELOPER_WARNINGS
4658 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4667 case V_SgTemplateFunctionDeclaration:
4669 case V_SgFunctionDeclaration:
4675 if (useThisDeclaration ==
true)
4677 if (scope == derivedDeclaration->
get_scope())
4682 if (isSgTemplateFunctionDeclaration(declaration) != NULL)
4687 ROSE_ASSERT(symbol != NULL);
4688 SgName name = derivedDeclaration->get_name();
4689 symbolTable->insert(name,symbol);
4693 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4695#if PRINT_DEVELOPER_WARNINGS
4696 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4705 case V_SgTemplateVariableDeclaration:
4707 case V_SgVariableDeclaration:
4710 SgInitializedNamePtrList & variableList = derivedDeclaration->
get_variables();
4711 SgInitializedNamePtrList::iterator i = variableList.begin();
4712 while ( i != variableList.end() )
4718 if (
variable->get_scope() == scope)
4721 ROSE_ASSERT(symbol != NULL);
4726 symbolTable->insert(name,symbol);
4743 ROSE_ASSERT(symbolTable != NULL);
4752 case V_SgTemplateInstantiationDecl:
4759 if (scope == derivedDeclaration->
get_scope())
4763 ROSE_ASSERT(symbol != NULL);
4764 SgName name = derivedDeclaration->get_name();
4767 if (scope != derivedDeclaration->
get_scope())
4769 printf (
"Error: scopes don't match for derivedDeclaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4771 ROSE_ASSERT(scope == derivedDeclaration->
get_scope());
4773 symbolTable->insert(name,symbol);
4779 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4781#if PRINT_DEVELOPER_WARNINGS
4782 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4788 ROSE_ASSERT(symbol != NULL);
4789 SgName name = derivedDeclaration->get_name();
4790 symbolTable->insert(name,symbol);
4797 case V_SgTemplateClassDeclaration:
4799 case V_SgClassDeclaration:
4803 if (scope == derivedDeclaration->
get_scope())
4806 if (isSgTemplateClassDeclaration(declaration) != NULL)
4811 ROSE_ASSERT(symbol != NULL);
4812 SgName name = derivedDeclaration->get_name();
4813 symbolTable->insert(name,symbol);
4817 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4819#if PRINT_DEVELOPER_WARNINGS
4820 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4826 ROSE_ASSERT(symbol != NULL);
4827 SgName name = derivedDeclaration->get_name();
4828 symbolTable->insert(name,symbol);
4833 case V_SgEnumDeclaration:
4836 ROSE_ASSERT(derivedDeclaration != NULL);
4838 ROSE_ASSERT(symbol != NULL);
4840 symbolTable->insert(name,symbol);
4843 SgInitializedNamePtrList & enumFieldList = derivedDeclaration->
get_enumerators();
4844 SgInitializedNamePtrList::iterator i = enumFieldList.begin();
4847 while (i != enumFieldList.end())
4850 ROSE_ASSERT(enum_field_symbol != NULL);
4851 SgName enum_field_name = (*i)->get_name();
4852 symbolTable->insert(enum_field_name,enum_field_symbol);
4862 case V_SgTemplateTypedefDeclaration:
4864 case V_SgTypedefDeclaration:
4868 ROSE_ASSERT(symbol != NULL);
4869 SgName name = derivedDeclaration->get_name();
4870 symbolTable->insert(name,symbol);
4872 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration \n");
4877 if (derivedDeclaration->get_typedefBaseTypeContainsDefiningDeclaration() ==
true)
4880 ROSE_ASSERT(symbolTable != NULL);
4883 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == true calling supportForBaseTypeDefiningDeclaration() \n");
4891 if (declaration != NULL)
4894 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == false calling supportForBaseTypeDefiningDeclaration() \n");
4899 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == false: skipping call to supportForBaseTypeDefiningDeclaration() \n");
4903 printf (
"In SageInterface::rebuildSymbolTable(): Leaving case of SgTypedefDeclaration \n");
4908 case V_SgTemplateDeclaration:
4914 printf (
"case V_SgTemplateDeclaration: derivedDeclaration = %p \n",derivedDeclaration);
4915 printf (
"case V_SgTemplateDeclaration: derivedDeclaration->get_declarationModifier().isFriend() = %s \n",derivedDeclaration->get_declarationModifier().
isFriend() ?
"true" :
"false");
4916 printf (
"case V_SgTemplateDeclaration: derivedDeclaration->get_name() = %s \n",derivedDeclaration->
get_name().str());
4917 printf (
"case V_SgTemplateDeclaration: derivedDeclaration->get_string() = %s \n",derivedDeclaration->
get_string().str());
4919 if (scope == derivedDeclaration->
get_scope())
4922 ROSE_ASSERT(symbol != NULL);
4924 symbolTable->insert(name,symbol);
4928 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4930#if PRINT_DEVELOPER_WARNINGS
4931 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4938 ROSE_ASSERT(symbol != NULL);
4940 symbolTable->insert(name,symbol);
4947 case V_SgNamespaceAliasDeclarationStatement:
4950 ROSE_ASSERT(aliasDeclaration != NULL);
4954 ROSE_ASSERT(derivedDeclaration != NULL);
4958 ROSE_ASSERT(symbol != NULL);
4960 symbolTable->insert(name,symbol);
4968 case V_SgNamespaceDeclarationStatement:
4971 ROSE_ASSERT(derivedDeclaration != NULL);
4975 ROSE_ASSERT(symbol != NULL);
4977 symbolTable->insert(name,symbol);
4983 case V_SgUsingDirectiveStatement:
4984 case V_SgPragmaDeclaration:
4985 case V_SgTemplateInstantiationDirectiveStatement:
4986 case V_SgUsingDeclarationStatement:
4990 printf (
"This declaration is ignored in rebuilding symbol table %p = %s = %s \n",*i,(*i)->class_name().c_str(),
get_name(*i).c_str());
4999 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());
5005 case V_SgVariableDefinition:
5006 case V_SgFunctionParameterList:
5007 case V_SgCtorInitializerList:
5010 printf (
"Special cases not handled %p = %s = %s \n",*i,(*i)->class_name().c_str(),
get_name(*i).c_str());
5014 case V_SgStaticAssertionDeclaration:
5018 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());
5025 printf (
"Error: Default reached in rebuildSymbolTable declaration = %p = %s \n",declaration,declaration->
class_name().c_str());
5030 ROSE_ASSERT(symbolTable != NULL);
5031 ROSE_ASSERT(symbolTable->get_table() != NULL);
5037 ROSE_ASSERT(symbolTable != NULL);
5038 ROSE_ASSERT(symbolTable->get_table() != NULL);
5041 printf (
"Leaving SageInterface::rebuildSymbolTable(): fixup declarations in Symbol Table from %p = %s \n",scope,scope->
class_name().c_str());
5045 printf (
"Symbol Table from %p = %s at: \n",scope,scope->
class_name().c_str());
5047 symbolTable->
print(
"Called from SageInterface::rebuildSymbolTable()");
5062#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
5063 ROSE_ASSERT(this_scope != NULL);
5064 ROSE_ASSERT(copy_scope != NULL);
5067 printf (
"In fixupReferencesToSymbols(this_scope = %p = %s = %s, copy_scope = %p = %s = %s) \n",
5075 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());
5076 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());
5082 if (this_symbolTable->get_table()->size() != copy_symbolTable->get_table()->size())
5086 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());
5087 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());
5088 printf (
"Warning the symbols tables in these different scopes are different sizes \n");
5093 SgSymbolTable::hash_iterator i = this_symbolTable->get_table()->begin();
5096 std::map<SgNode*, SgNode*> replacementMap;
5098 while (i != this_symbolTable->get_table()->end())
5100 ROSE_ASSERT ( isSgSymbol( (*i).second ) != NULL );
5102 SgName name = (*i).first;
5105 ROSE_ASSERT ( symbol != NULL );
5107 SgSymbol* associated_symbol = NULL;
5109 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());
5112 SgSymbolTable::hash_iterator associated_symbol_iterator = copy_symbolTable->get_table()->find(name);
5117 while (associated_symbol_iterator != copy_symbolTable->get_table()->end() && associated_symbol_iterator->first == name)
5119 if ( associated_symbol_iterator->second->variantT() == symbol->
variantT() )
5121 associated_symbol = associated_symbol_iterator->second;
5124 associated_symbol_iterator++;
5127 if (associated_symbol != NULL)
5129 ROSE_ASSERT ( associated_symbol != NULL );
5132 ROSE_ASSERT(copy_scope->symbol_exists(associated_symbol) ==
true);
5137 replacementMap.insert(pair<SgNode*,SgNode*>(symbol,associated_symbol));
5144 help.get_copiedNodeMap().insert(pair<const SgNode*,SgNode*>(symbol,associated_symbol));
5151 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());
5152 printf (
"Warning: associated_symbol == NULL, need to investigate this (ignoring for now) \n");
5162 printf (
"\n\n************************************************************\n");
5163 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());
5169 printf (
"fixupReferencesToSymbols(): calling Utils::edgePointerReplacement(): DONE \n");
5170 printf (
"************************************************************\n\n");
5172 printf (
"\n\n After replacementMapTraversal(): intermediateDeleteSet: \n");
5173 displaySet(intermediateDeleteSet,
"After Utils::edgePointerReplacement");
5175 printf (
"After fixup: this_symbolTable->get_table()->size() = %" PRIuPTR
" \n",this_symbolTable->get_table()->size());
5176 printf (
"After fixup: copy_symbolTable->get_table()->size() = %" PRIuPTR
" \n",copy_symbolTable->get_table()->size());
5185 printf (
"Exiting as a test in fixupReferencesToSymbols() \n");
5201 vector<SgFile*> fileList;
5202 void visit (
SgNode* node)
5204 SgFile* file = isSgFile(node);
5205 ROSE_ASSERT(file != NULL);
5208 fileList.push_back(file);
5212 virtual ~FileTraversal() {}
5215 FileTraversal fileTraversal;
5220#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5231 return fileTraversal.fileList;
5249 void visit (
SgNode* node)
5251 project = isSgProject(node);
5252 ROSE_ASSERT(project!= NULL);
5254 virtual ~ProjectTraversal() {}
5257 ProjectTraversal projectTraversal;
5259 return projectTraversal.project;
5261 std::vector<SgProject* > resultlist = getSgNodeListFromMemoryPool<SgProject>();
5262 if (resultlist.empty())
5264 ROSE_ASSERT(resultlist.size()==1);
5265 return resultlist[0];
5270 return getEnclosingNode<SgProject>(node,
true );
5275 if (isSgFunctionRefExp(func))
5277 return isSgFunctionRefExp(func)->get_symbol()->get_declaration();
5279 else if (isSgDotExp(func) || isSgArrowExp(func))
5282 if (isSgMemberFunctionRefExp(func2))
5283 return isSgMemberFunctionRefExp(func2)->get_symbol()->get_declaration();
5286 cerr<<
"Warning in SageInterface::getDeclarationOfNamedFunction(): rhs operand of dot or arrow operations is not a member function, but a "<<func2->
class_name()<<endl;
5295 const SgExpressionPtrList& ls = el->get_expressions();
5296 if (ls.empty())
return 0;
5297 if (isSgAssignOp(ls.back()))
return 0;
5304 ASSERT_not_null(astNode);
5305 Rose_STL_Container<SgNode*> arr_exp_list = NodeQuery::querySubTree(astNode,V_SgPntrArrRefExp);
5306 for (
SgNode* expr : arr_exp_list)
5309 ASSERT_not_null(arr_exp);
5310 Rose_STL_Container<SgNode*> refList = NodeQuery::querySubTree(arr_exp->
get_lhs_operand(),V_SgVarRefExp);
5311 for (
SgNode* ref : refList)
5314 ASSERT_not_null(cur_ref);
5316 ASSERT_not_null(sym);
5318 ASSERT_not_null(iname);
5319 SgArrayType * a_type = isSgArrayType(iname->get_typeptr());
5320 if (a_type && a_type->get_dim_info())
5322 Rose_STL_Container<SgNode*> dim_ref_list = NodeQuery::querySubTree(a_type->get_dim_info(),V_SgVarRefExp);
5323 for (Rose_STL_Container<SgNode*>::iterator iter2 = dim_ref_list.begin(); iter2 != dim_ref_list.end(); iter2++)
5326 NodeList_t.push_back(dim_ref);
5336#if (INLINE_OPTIMIZED_IS_LANGUAGE_KIND_FUNCTIONS == 0)
5340#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5342 return Rose::is_Ada_language;
5344 bool returnValue =
false;
5348 int size = (int)fileList.size();
5349 for (
int i = 0; i < size; i++)
5351 if (fileList[i]->get_Ada_only() ==
true)
5362#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5364 return Rose::is_C_language;
5366 bool returnValue =
false;
5370 int size = (int)fileList.size();
5371 for (
int i = 0; i < size; i++)
5373 if (fileList[i]->get_C_only() ==
true)
5384#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5386 return Rose::is_OpenMP_language;
5388 bool returnValue =
false;
5392 int size = (int)fileList.size();
5393 for (
int i = 0; i < size; i++)
5395 if (fileList[i]->get_openmp() ==
true)
5406#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5408 return Rose::is_UPC_language;
5410 bool returnValue =
false;
5414 int size = (int)fileList.size();
5415 for (
int i = 0; i < size; i++)
5417 if (fileList[i]->get_UPC_only() ==
true)
5429#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5431 return Rose::is_CAF_language;
5433 bool returnValue =
false;
5437 int size = (int)fileList.size();
5438 for (
int i = 0; i < size; i++)
5440 if (fileList[i]->get_CoArrayFortran_only()==
true)
5453#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5455 return Rose::is_UPC_dynamic_threads;
5457 bool returnValue =
false;
5461 int size = (int)fileList.size();
5462 for (
int i = 0; i < size; i++)
5464 if (fileList[i]->get_upc_threads() > 0)
5477#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5479 return Rose::is_C99_language;
5481 bool returnValue =
false;
5485 int size = (int)fileList.size();
5486 for (
int i = 0; i < size; i++)
5488 if (fileList[i]->get_C99_only() ==
true)
5499#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5501 return Rose::is_Cxx_language;
5503 bool returnValue =
false;
5507 int size = (int)fileList.size();
5508 for (
int i = 0; i < size; i++)
5511 if (fileList[i]->get_Cxx_only() ==
true)
5513 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);
5526#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5528 return Rose::is_Java_language;
5530 bool returnValue =
false;
5534 int size = (int)fileList.size();
5535 for (
int i = 0; i < size; i++)
5537 if (fileList[i]->get_Java_only() ==
true)
5548#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5550 return Rose::is_Jvm_language;
5552 bool returnValue =
false;
5556 int size = (int)fileList.size();
5557 for (
int i = 0; i < size; i++)
5559 if (fileList[i]->get_Jvm_only() ==
true)
5571#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5573 return Rose::is_Jovial_language;
5575 bool returnValue =
false;
5579 int size = (int)fileList.size();
5580 for (
int i = 0; i < size; i++)
5582 if (fileList[i]->get_Jovial_only() ==
true)
5594#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5596 return Rose::is_Fortran_language;
5598 bool returnValue =
false;
5602 int size = (int)fileList.size();
5603 for (
int i = 0; i < size; i++)
5605 if (fileList[i]->get_Fortran_only() ==
true)
5617#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5619 return Rose::is_binary_executable;
5621 bool returnValue =
false;
5625 int size = (int)fileList.size();
5626 for (
int i = 0; i < size; i++)
5628 if (fileList[i]->get_binary_only() ==
true)
5639#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5641 return Rose::is_PHP_language;
5643 bool returnValue =
false;
5647 int size = (int)fileList.size();
5648 for (
int i = 0; i < size; i++)
5650 if (fileList[i]->get_PHP_only() ==
true)
5661#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5663 return Rose::is_Python_language;
5665 bool returnValue =
false;
5669 int size = (int)fileList.size();
5670 for (
int i = 0; i < size; i++)
5672 if (fileList[i]->get_Python_only() ==
true)
5683#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5685 return Rose::is_Cuda_language;
5687 bool returnValue =
false;
5691 int size = (int)fileList.size();
5692 for (
int i = 0; i < size; i++)
5694 if (fileList[i]->get_Cuda_only() ==
true)
5705#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5707 return Rose::is_OpenCL_language;
5709 bool returnValue =
false;
5713 int size = (int)fileList.size();
5714 for (
int i = 0; i < size; i++)
5716 if (fileList[i]->get_OpenCL_only() ==
true)
5764 ASSERT_not_null(functionDefinition);
5765 std::map<SgNode*,int> & scopeMap = functionDefinition->get_scope_number_list();
5768 scopeMap.erase(scopeMap.begin(),scopeMap.end());
5770 ASSERT_require(scopeMap.empty() ==
true);
5771 ASSERT_require(functionDefinition->get_scope_number_list().empty() ==
true);
5781 ROSE_ASSERT(functionDefinition != NULL);
5784 ROSE_ASSERT(functionDefinition->get_scope_number_list().empty() ==
true);
5790 ScopeNumberingTraversal() : count (0), storedFunctionDefinition(NULL) {}
5791 void visit (
SgNode* node)
5798 if (testFunctionDefinition != NULL && storedFunctionDefinition == NULL)
5800 ROSE_ASSERT(storedFunctionDefinition == NULL);
5801 storedFunctionDefinition = testFunctionDefinition;
5805 ROSE_ASSERT(storedFunctionDefinition != NULL);
5809 std::map<SgNode*,int> & scopeMap = storedFunctionDefinition->get_scope_number_list();
5810 scopeMap.insert(pair<SgNode*,int>(scope,count));
5812 string functionName = storedFunctionDefinition->get_declaration()->get_name().str();
5813 printf (
"In function = %s insert scope = %p = %s with count = %d into local map (size = %d) \n",
5814 functionName.c_str(),scope,scope->
class_name().c_str(),count,scopeMap.size());
5825 ScopeNumberingTraversal traversal;
5826 traversal.traverse(functionDefinition, preorder);
5840 ROSE_ASSERT(globalScope != NULL);
5841 std::map<SgNode*,std::string> & mangledNameCache = globalScope->get_mangledNameCache();
5844 mangledNameCache.erase(mangledNameCache.begin(),mangledNameCache.end());
5846 ROSE_ASSERT(mangledNameCache.empty() ==
true);
5847 ROSE_ASSERT(globalScope->get_mangledNameCache().empty() ==
true);
5855 ROSE_ASSERT(globalScope != NULL);
5856 ROSE_ASSERT(globalScope->get_mangledNameCache().empty() ==
true);
5862 MangledNameTraversal() : storedGlobalScope(NULL) {}
5863 void visit (
SgNode* node)
5866 if ( (mangleableNode != NULL) || (isSgGlobal(node) != NULL) )
5869 SgGlobal* testGlobalScope = isSgGlobal(mangleableNode);
5870 if (testGlobalScope != NULL && storedGlobalScope == NULL)
5872 ROSE_ASSERT(storedGlobalScope == NULL);
5873 storedGlobalScope = testGlobalScope;
5877 ROSE_ASSERT(storedGlobalScope != NULL);
5879 string mangledName = mangleableNode->get_mangled_name();
5882 std::map<SgNode*,std::string> & mangledNameCache = storedGlobalScope->get_mangledNameCache();
5883 mangledNameCache.insert(pair<SgNode*,std::string>(mangleableNode,mangledName));
5885 string nodeName =
get_name(mangleableNode);
5886 printf (
"At node = %p = %s = %s in local map (size = %d) \n",
5887 mangleableNode,mangleableNode->
class_name().c_str(),nodeName.c_str(),mangledNameCache.size());
5897 MangledNameTraversal traversal;
5898 traversal.traverse(globalScope, preorder);
5910 SgGlobal* globalScope = isSgGlobal(astNode);
5912 if (globalScope == NULL && isSgFile(astNode) != NULL)
5914 globalScope = isSgFile(astNode)->get_globalScope();
5915 ROSE_ASSERT(globalScope != NULL);
5918 if (globalScope == NULL && isSgProject(astNode) != NULL)
5921 ROSE_ASSERT( isSgProject(astNode)->get_fileList()->size() == 1 );
5922 globalScope = isSgProject(astNode)->get_fileList()->operator[](0)->get_globalScope();
5923 ROSE_ASSERT(globalScope != NULL);
5927 while (temp->
get_parent() != NULL && globalScope == NULL)
5930 globalScope = isSgGlobal(temp);
5932 ROSE_ASSERT(globalScope != NULL);
5939 std::map<SgNode*,std::string>::iterator i = mangledNameCache.find(astNode);
5942 if (i != mangledNameCache.end())
5946 mangledName = i->second;
5957#define DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE 0
5958#define DEBUG_MANGLED_SHORTNAME 1
5967#if DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE
5968 printf (
"In SageInterface::addMangledNameToCache(): TOP: astNode = %p = %s oldMangledName = %s \n",astNode,astNode->
class_name().c_str(),oldMangledName.c_str());
5972#ifdef DEBUG_MANGLED_SHORTNAME
5973 static std::unordered_map<uint64_t, std::string> mangledNameHashCollisionCheckMap;
5978 SgGlobal* globalScope = isSgGlobal(astNode);
5980 if (globalScope == NULL && isSgFile(astNode) != NULL)
5982 globalScope = isSgFile(astNode)->get_globalScope();
5983 ROSE_ASSERT(globalScope != NULL);
5986 if (globalScope == NULL && isSgProject(astNode) != NULL)
5989 ROSE_ASSERT( isSgProject(astNode)->get_fileList()->size() == 1 );
5990 globalScope = isSgProject(astNode)->get_fileList()->operator[](0)->get_globalScope();
5991 ROSE_ASSERT(globalScope != NULL);
5995 while (temp->
get_parent() != NULL && globalScope == NULL)
5998 globalScope = isSgGlobal(temp);
6000 ROSE_ASSERT(globalScope != NULL);
6005 std::string mangledName;
6007 if (SgProject::get_mangled_noshortname() ==
false) {
6010 if (oldMangledName.size() > 40) {
6011 std::map<std::string, uint64_t>::const_iterator shortMNIter = shortMangledNameCache.find(oldMangledName);
6012 uint64_t idNumber = 0;
6013 if (shortMNIter != shortMangledNameCache.end())
6015 idNumber = shortMNIter->second;
6017#ifdef DEBUG_MANGLED_SHORTNAME
6019 auto collisionIt = mangledNameHashCollisionCheckMap.find(idNumber);
6020 if(collisionIt != mangledNameHashCollisionCheckMap.end() &&
6021 oldMangledName != shortMNIter->first)
6023 mlog[Sawyer::Message::Common::ERROR] <<
" Got a short mangled name collision. \n "<<
6024 oldMangledName <<
" and \n " << shortMNIter->first <<
" \n" <<
6028 mangledNameHashCollisionCheckMap[idNumber] = oldMangledName;
6036 hasher.
insert(oldMangledName);
6038 idNumber = hasher.
toU64();
6039 shortMangledNameCache.insert(std::pair<std::string, uint64_t>(oldMangledName, idNumber));
6042 std::ostringstream mn;
6044 mangledName = mn.str();
6046 mangledName = oldMangledName;
6057 static unsigned long counter = 0;
6061 if (counter++ % 500 == 0)
6063 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");
6065 mangledName = oldMangledName;
6072 printf (
"Updating mangled name cache for node = %p = %s with mangledName = %s \n",astNode,astNode->
class_name().c_str(),mangledName.c_str());
6075#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
6081 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",
6082 statement,statement->
class_name().c_str(),oldMangledName.c_str());
6087 mangledNameCache.insert(pair<SgNode*,string>(astNode,mangledName));
6089#if DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE
6090 printf (
"In SageInterface::addMangledNameToCache(): returning mangledName = %s \n",mangledName.c_str());
6114 : storedNondefiningDeclaration(nonDefiningDeclaration),
6115 storedDefiningDeclaration(definingDeclaration)
6117 storedDeclarationFound =
false;
6118 nonDefiningDeclarationPreceedsDefiningDeclaration =
false;
6121 void visit (
SgNode* node)
6123 ROSE_ASSERT(storedNondefiningDeclaration != NULL);
6124 ROSE_ASSERT(storedDefiningDeclaration != NULL);
6125 ROSE_ASSERT(storedNondefiningDeclaration != storedDefiningDeclaration);
6133 if ( declaration != NULL )
6135 if (storedDeclarationFound ==
false)
6137 if (declaration == storedDefiningDeclaration)
6139 storedDeclarationFound =
true;
6140 nonDefiningDeclarationPreceedsDefiningDeclaration =
false;
6142 if (declaration == storedNondefiningDeclaration)
6144 storedDeclarationFound =
true;
6145 nonDefiningDeclarationPreceedsDefiningDeclaration =
true;
6152 bool storedDeclarationFound;
6153 bool nonDefiningDeclarationPreceedsDefiningDeclaration;
6160 ROSE_ASSERT(nonDefiningDeclaration != NULL);
6162 printf (
"In SageInterface::declarationPreceedsDefinition(): \n");
6163 printf (
" nondefiningDeclaration = %p = %s \n",nonDefiningDeclaration,nonDefiningDeclaration->
class_name().c_str());
6164 nonDefiningDeclaration->
get_file_info()->display(
"nonDefiningDeclaration");
6165 printf (
" nondefiningDeclaration->get_definingDeclaration() = %p \n",nonDefiningDeclaration->
get_definingDeclaration());
6166 printf (
" definingDeclaration = %p = %s \n",definingDeclaration,definingDeclaration->
class_name().c_str());
6167 definingDeclaration->
get_file_info()->display(
"definingDeclaration");
6168 printf (
"************************************************************* \n");
6175 printf (
"In SageInterface::declarationPreceedsDefinition() (warning): \n");
6176 printf (
" nondefiningDeclaration = %p \n",nonDefiningDeclaration);
6177 printf (
" nondefiningDeclaration->get_definingDeclaration() = %p \n",nonDefiningDeclaration->
get_definingDeclaration());
6178 printf (
" definingDeclaration = %p \n",definingDeclaration);
6183 bool returnResult =
false;
6184 if (nonDefiningDeclaration != definingDeclaration)
6187 SgGlobal* globalScope = TransformationSupport::getGlobalScope(definingDeclaration);
6188 ROSE_ASSERT(globalScope != NULL);
6191 DeclarationOrderTraversal traversal (nonDefiningDeclaration,definingDeclaration);
6194 traversal.traverse(globalScope, preorder);
6197 printf (
"Skipping traversal within SageInterface::declarationPreceedsDefinition() \n");
6198 traversal.storedDeclarationFound =
true;
6199 traversal.nonDefiningDeclarationPreceedsDefiningDeclaration =
false;
6206 if (traversal.storedDeclarationFound ==
false)
6209 printf (
"In SageInterface::declarationPreceedsDefinition(): warning, nonDefiningDeclaration not found in the AST \n");
6210 nonDefiningDeclaration->
get_file_info()->display(
"nonDefiningDeclaration");
6211 definingDeclaration->
get_file_info()->display(
"definingDeclaration");
6212 printf (
"---------------------------------------------------- \n\n");
6216 returnResult =
true;
6220 returnResult = traversal.nonDefiningDeclarationPreceedsDefiningDeclaration;
6226 printf (
"returnResult = %s \n",returnResult ?
"true" :
"false");
6227 printf (
"************************************************************* \n\n");
6229 return returnResult;
6246 : storedFunctionCall(functionCall)
6248 ROSE_ASSERT(functionCall != NULL);
6249 ROSE_ASSERT(functionCall->get_function() != NULL);
6250 SgExpression* functionExpression = functionCall->get_function();
6252 switch (functionExpression->
variantT())
6258 case V_SgArrowStarOp:
6259 case V_SgPointerDerefExp:
6262 printf (
"These are the acceptable cases, but not handled yet... \n");
6266 case V_SgFunctionRefExp:
6269 ROSE_ASSERT(functionRefExp != NULL);
6271 ROSE_ASSERT(functionSymbol != NULL);
6274 ROSE_ASSERT(functionSymbol->get_declaration() != NULL);
6275 storedFunctionDeclaration = functionSymbol->get_declaration();
6279 case V_SgMemberFunctionRefExp:
6282 ROSE_ASSERT(memberFunctionRefExp != NULL);
6284 ROSE_ASSERT(memberFunctionSymbol != NULL);
6286 storedFunctionDeclaration = memberFunctionSymbol->get_declaration();
6288 printf (
"V_SgMemberFunctionRefExp case not handled yet... \n");
6294 printf (
"default reached in SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope() functionExpression = %s \n",
6302 ROSE_ASSERT(storedFunctionDeclaration != NULL);
6304 storedFunctionCallFound =
false;
6308 void visit (
SgNode* node)
6310 ROSE_ASSERT(storedFunctionCall != NULL);
6311 ROSE_ASSERT(storedFunctionDeclaration != NULL);
6314 if (storedFunctionCallFound ==
false)
6317 if ( functionCall != NULL )
6319 if (functionCall == storedFunctionCall)
6321 storedFunctionCallFound =
true;
6331 ROSE_ASSERT(storedFunctionDeclaration != NULL);
6344 storedFunctionCallFound =
true;
6350 printf (
"Found a declaration which preceeds the function \n");
6351 declaration->
get_file_info()->display(
"Found a declaration which preceeds the function: declaration");
6352 storedFunctionCall->get_file_info()->display(
"Found a declaration which preceeds the function: storedFunctionCall");
6353 storedFunctionDeclaration->get_file_info()->display(
"Found a declaration which preceeds the function: storedFunctionDeclaration");
6359 if (parentScopeOfDeclaration == NULL)
6362 printf (
"Strange case of parentScopeOfDeclaration == NULL in SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope() \n");
6364 if (parent != NULL) {
6365 printf (
"declaration->get_parent() = %s \n",parent->
class_name().c_str());
6368 printf (
"declaration->get_parent() = NULL \n");
6370 declaration->
get_file_info()->display(
"case of parentScopeOfDeclaration == NULL");
6379 bool storedFunctionCallFound;
6387 ROSE_ASSERT(functionCall != NULL);
6389 printf (
"In SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope(): \n");
6390 printf (
" storedFunctionCall = %p = %s \n",functionCall,functionCall->
class_name().c_str());
6391 functionCall->
get_file_info()->display(
"storedFunctionCall");
6392 printf (
" storedFunctionCall->get_function() = %p = %s \n",functionCall->get_function(),functionCall->get_function()->
class_name().c_str());
6393 printf (
"************************************************************* \n");
6397 bool returnResult =
false;
6400 SgGlobal* globalScope = TransformationSupport::getGlobalScope(functionCall);
6401 ROSE_ASSERT(globalScope != NULL);
6404 DeclarationOrderTraversal traversal (functionCall);
6407 traversal.traverse(globalScope, preorder);
6410 printf (
"Skipping traversal within SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope() \n");
6411 traversal.storedFunctionCallFound =
true;
6412 traversal.functionCallExpressionPreceedsDeclarationWhichAssociatesScope =
false;
6419 if (traversal.storedFunctionCallFound ==
false)
6422 printf (
"In SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope(): warning, storedFunctionCall not found in the AST \n");
6424 printf (
"---------------------------------------------------- \n\n");
6429 returnResult =
true;
6433 returnResult = traversal.functionCallExpressionPreceedsDeclarationWhichAssociatesScope;
6437 ROSE_ASSERT(traversal.storedFunctionCallFound ==
true);
6439 printf (
"returnResult = %s \n",returnResult ?
"true" :
"false");
6440 printf (
"************************************************************* \n\n");
6442 return returnResult;
6463 ROSE_ASSERT(project != NULL);
6470 Rose_STL_Container<string>::iterator i = fileList.begin();
6473 if ( fileList.empty() ==
true )
6475 return "empty_file_list";
6479 string filename = *i;
6485 if (i != fileList.begin())
6486 projectName +=
"--";
6490 string filenameWithoutSuffix;
6491 if ( i != fileList.end() || supressSuffix ==
true )
6494 filenameWithoutSuffix = filename;
6501 filename = filenameWithoutPathOrSuffix;
6503 unsigned long int n = 0;
6504 while (n < filename.size())
6506 if (filename[n] ==
'/')
6513 projectName += filename;
6517 while (i != fileList.end());
6536 if (currentScope == NULL)
6538 ROSE_ASSERT(currentScope != NULL);
6541 while ((functionSymbol == NULL) && (tempScope != NULL))
6543 functionSymbol = tempScope->lookup_function_symbol(functionName);
6545 printf (
"In lookupFunctionSymbolInParentScopes(): Searching scope = %p = %s functionName = %s functionSymbol = %p \n",tempScope,tempScope->
class_name().c_str(),functionName.str(),functionSymbol);
6548 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6552 return functionSymbol;
6563 if (currentScope == NULL)
6565 ROSE_ASSERT(currentScope != NULL);
6568 while ((functionSymbol == NULL) && (tempScope != NULL))
6570 functionSymbol = tempScope->lookup_template_function_symbol(functionName, ftype, tplparams);
6572 printf (
"In lookupTemplateFunctionSymbolInParentScopes(): Searching scope = %p = %s functionName = %s functionSymbol = %p \n",tempScope,tempScope->
class_name().c_str(),functionName.str(),functionSymbol);
6575 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6579 return functionSymbol;
6590 if (currentScope == NULL)
6592 ROSE_ASSERT(currentScope != NULL);
6595 while ((functionSymbol == NULL) && (tempScope != NULL))
6597 functionSymbol = tempScope->lookup_template_member_function_symbol(functionName, ftype, tplparams);
6599 printf (
"In lookupTemplateMemberFunctionSymbolInParentScopes(): Searching scope = %p = %s functionName = %s functionSymbol = %p \n",tempScope,tempScope->
class_name().c_str(),functionName.str(),functionSymbol);
6602 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6606 return functionSymbol;
6614 if (isSgType(astNode) != NULL)
6616 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");
6620 if (astNode->
attributeExists(AstUnparseAttribute::markerName) ==
true)
6622 AstUnparseAttribute* code =
dynamic_cast<AstUnparseAttribute*
>(astNode->
getAttribute(AstUnparseAttribute::markerName));
6623 ROSE_ASSERT(code != NULL);
6627 code->addString(s,inputlocation);
6636 AstUnparseAttribute* code =
new AstUnparseAttribute(s,inputlocation);
6637 ROSE_ASSERT(code != NULL);
6654 ROSE_ASSERT(cscope != NULL);
6656 while ((cscope != NULL) && (symbol == NULL))
6659 symbol = cscope->lookup_class_symbol(name,NULL);
6662 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6693 if (currentScope == NULL)
6695 ROSE_ASSERT(currentScope != NULL);
6697 while (functionSymbol == NULL && tempScope != NULL)
6699 functionSymbol = tempScope->lookup_function_symbol(functionName,t);
6701 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6702 else tempScope = NULL;
6704 return functionSymbol;
6711 if (cscope ==
nullptr) {
6714 ASSERT_not_null(cscope);
6716 while ((cscope !=
nullptr) && (symbol ==
nullptr))
6718 symbol = cscope->lookup_symbol(name,templateParameterList,templateArgumentList);
6720 cscope = isSgGlobal(cscope) ? nullptr : cscope->
get_scope();
6739#define USING_PERFORMANCE_TRACING 0
6743#if USING_PERFORMANCE_TRACING
6745 TimingPerformance timer1 (
"SageInterface::lookupSymbolInParentScopesIgnoringAliasSymbols: whole function:");
6748 if (currentScope == NULL)
6753 ROSE_ASSERT(currentScope != NULL);
6755#define DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS 0
6757#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6758 printf (
"In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): currentScope = %p = %s (templateParameterList = %p templateArgumentList = %p) \n",
6759 currentScope,currentScope->
class_name().c_str(),templateParameterList,templateArgumentList);
6762 while ((currentScope != NULL) && (symbol == NULL))
6764#if USING_PERFORMANCE_TRACING
6766 TimingPerformance timer1 (
"SageInterface::lookupSymbolInParentScopesIgnoringAliasSymbols: in loop:");
6769#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6770 printf(
" --- In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): name = %s currentScope = %p = %s \n",
6771 name.str(),currentScope,currentScope->
class_name().c_str());
6776 symbol = currentScope->lookup_symbol(name,templateParameterList,templateArgumentList);
6778 if (isSgAliasSymbol(symbol) != NULL)
6780#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6781 printf (
"Found a SgAliasSymbol: reset to NULL: symbol = %p = %s \n",symbol,symbol->
class_name().c_str());
6786#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS && 1
6788 printf(
" --- In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): symbol = %p \n",symbol);
6789 currentScope->print_symboltable(
"In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): debug");
6792 currentScope = isSgGlobal(currentScope) ? NULL : currentScope->
get_scope();
6794 currentScope = NULL;
6796#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6797 printf (
" --- In SageInterface:: (base of loop) lookupSymbolInParentScopesIgnoringAliasSymbols(): cscope = %p symbol = %p \n\n",currentScope,symbol);
6803#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6804 printf (
"Warning: In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): could not locate the specified name %s in any outer symbol table (templateParameterList = %p templateArgumentList = %p) \n",
6805 name.str(),templateParameterList,templateArgumentList);
6811 printf (
"Support for lookupSymbolInParentScopesIgnoringAliasSymbols() is not yet implemented \n");
6833 ROSE_ASSERT(cscope);
6835 while ((cscope!=NULL)&&(symbol==NULL))
6837 symbol = cscope->lookup_symbol(name);
6841 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6867 printf (
"WARNING: SageInterface::lookupVariableSymbolInParentScopes() should be implemented similar to SageInterface::lookupClassSymbolInParentScopes() \n");
6873 if (isSgAliasSymbol(symbol) != NULL)
6875 printf (
"Error: This SageInterface::lookupVariableSymbolInParentScopes() function does not handle SgAliasSymbols \n");
6878 result = isSgVariableSymbol(symbol);
6886 ROSE_ASSERT(cscope != NULL);
6888 while ((cscope != NULL) && (symbol == NULL))
6891 symbol = cscope->lookup_variable_symbol(name);
6894 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6903#define DEBUG_LOOKUP_TEMPLATE_VARIABLE 0
6908#if DEBUG_LOOKUP_TEMPLATE_VARIABLE
6909 printf (
"In SageInterface::lookupTemplateVariableSymbolInParentScopes():\n");
6910 printf (
" -- name = %s\n", name.str());
6911 printf (
" -- tplparams = %p [%zd]\n", tplparams, tplparams ? tplparams->size() : 0);
6912 printf (
" -- tplargs = %p [%zd]\n", tplargs, tplargs ? tplargs->size() : 0);
6913 printf (
" -- cscope = %p (%s)\n", cscope, cscope ? cscope->
class_name().c_str() :
"");
6919 ROSE_ASSERT(cscope != NULL);
6921 while ((cscope != NULL) && (symbol == NULL))
6924 symbol = cscope->lookup_template_variable_symbol(name, tplparams, tplargs);
6927 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6943 ROSE_ASSERT(cscope != NULL);
6945 while ((cscope != NULL) && (symbol == NULL))
6949 symbol = cscope->lookup_class_symbol(name,templateArgumentList);
6952 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6966 ROSE_ASSERT(cscope != NULL);
6968 while ((cscope != NULL) && (symbol == NULL))
6970 symbol = cscope->lookup_nonreal_symbol(name,templateParameterList,templateArgumentList);
6973 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6988 ROSE_ASSERT(cscope != NULL);
6991 printf (
"In lookupTypedefSymbolInParentScopes(): name = %s starting with cscope = %p = %s \n",name.str(),cscope,cscope->
class_name().c_str());
6995 while ((cscope != NULL) && (symbol == NULL))
6998 symbol = cscope->lookup_typedef_symbol(name);
7001 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7006 printf (
"In lookupTypedefSymbolInParentScopes(): symbol = %p next cscope = %p = %s \n",symbol,cscope,(cscope != NULL) ? cscope->
class_name().c_str() :
"null");
7011 printf (
"Leaving lookupTypedefSymbolInParentScopes(): symbol = %p \n",symbol);
7029 ROSE_ASSERT(cscope != NULL);
7031 while ((cscope != NULL) && (symbol == NULL))
7037 symbol = cscope->lookup_template_symbol(name,NULL,NULL);
7039 printf (
"In lookupTemplateSymbolInParentScopes(): Searching scope = %p = %s name = %s symbol = %p \n",cscope,cscope->
class_name().c_str(),name.str(),symbol);
7042 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7059 ROSE_ASSERT(cscope != NULL);
7061 while ((cscope != NULL) && (symbol == NULL))
7067 symbol = cscope->lookup_template_class_symbol(name,templateParameterList,templateArgumentList);
7069 printf (
"In lookupTemplateSymbolInParentScopes(): Searching scope = %p = %s name = %s symbol = %p \n",cscope,cscope->
class_name().c_str(),name.str(),symbol);
7072 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7089 ROSE_ASSERT(cscope != NULL);
7091 while ((cscope != NULL) && (symbol == NULL))
7094 symbol = cscope->lookup_enum_symbol(name);
7097 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7112 ROSE_ASSERT(cscope != NULL);
7114 while ((cscope != NULL) && (symbol == NULL))
7117 symbol = cscope->lookup_namespace_symbol(name);
7120 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7130SageInterface::setSourcePositionToDefault( T* node )
7148 ROSE_ASSERT(node != NULL);
7151 if (node->get_endOfConstruct() == NULL && node->get_startOfConstruct() == NULL)
7154 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());
7157 ROSE_ASSERT(node->get_endOfConstruct() == NULL);
7158 ROSE_ASSERT(node->get_startOfConstruct() == NULL);
7165 printf (
"In SageInterface::setSourcePositionToDefault(): Calling setSourcePositionUnavailableInFrontend() \n");
7167 start_fileInfo->setSourcePositionUnavailableInFrontend();
7168 end_fileInfo->setSourcePositionUnavailableInFrontend();
7172 printf (
"In SageInterface::setSourcePositionToDefault(): Calling setOutputInCodeGeneration() \n");
7178 node->set_startOfConstruct(start_fileInfo);
7179 node->set_endOfConstruct (end_fileInfo);
7181 node->get_startOfConstruct()->set_parent(node);
7182 node->get_endOfConstruct ()->set_parent(node);
7189 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());
7191 if (node->get_startOfConstruct() == NULL)
7193 printf (
"ERROR: startOfConstruct not set for locatedNode = %p = %s \n",node,node->class_name().c_str());
7195 if (node->get_endOfConstruct() == NULL)
7197 printf (
"ERROR: endOfConstruct not set for locatedNode = %p = %s \n",node,node->class_name().c_str());
7200 ROSE_ASSERT(node->get_startOfConstruct() != NULL);
7201 ROSE_ASSERT(node->get_endOfConstruct() != NULL);
7202 ROSE_ASSERT(node->get_endOfConstruct() != NULL && node->get_startOfConstruct() != NULL);
7223 if (expression != NULL)
7226 SgBinaryOp* binaryOp = isSgBinaryOp(expression);
7227 if (binaryOp != NULL)
7229 if (binaryOp->get_operatorPosition() == NULL)
7232 operator_fileInfo->setSourcePositionUnavailableInFrontend();
7234 binaryOp->set_operatorPosition(operator_fileInfo);
7237 binaryOp->get_operatorPosition()->
set_parent(binaryOp);
7242 if (expression->get_operatorPosition() == NULL)
7245 operator_fileInfo->setSourcePositionUnavailableInFrontend();
7247 expression->set_operatorPosition(operator_fileInfo);
7252 ROSE_ASSERT(expression->get_operatorPosition()->
get_parent() == expression);
7263#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
7264 printf (
"+++++ Depricated function (use setSourcePositionAsTransformation() instead) (no using internal source position mode) \n");
7283 ROSE_ASSERT(node != NULL);
7292 SgPragma* pragma = isSgPragma(node);
7293 SgGlobal* global = isSgGlobal(node);
7298 printf (
"Debug, Found a variable definition: %p\n", v_d);
7301 if (locatedNode != NULL)
7313 if (expression!=NULL)
7316 expression->get_operatorPosition()->
set_parent(expression);
7335 printf (
"+++++ Depricated name setOneSourcePositionNull() (use setSourcePositionPointersToNull() instead) (no using internal source position mode) \n");
7353 ROSE_ASSERT(node != NULL);
7357 SgPragma* pragma = isSgPragma(node);
7358 SgGlobal* global = isSgGlobal(node);
7364 if (locatedNode != NULL)
7367 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of startOfConstruct Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7375 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of endOfConstruct Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7381 if (expression != NULL)
7383 if (expression->get_operatorPosition() != NULL)
7384 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of operatorPosition Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7386 expression->set_operatorPosition(NULL);
7393 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7395 pragma->set_startOfConstruct(NULL);
7406 printf (
"+++++ Depricated name setSourcePositionForTransformation() (use setSourcePositionAtRootAndAllChildrenAsTransformation() instead) \n");
7419 Rose_STL_Container <SgNode*> nodeList = NodeQuery::querySubTree(root,V_SgNode);
7420 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i!=nodeList.end(); i++ )
7431SageInterface::setSourcePositionAtRootAndAllChildrenAsTransformation(
SgNode *root)
7433 Rose_STL_Container <SgNode*> nodeList= NodeQuery::querySubTree(root,V_SgNode);
7434 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i!=nodeList.end(); i++ )
7443SageInterface::setSourcePositionAtRootAndAllChildrenAsDefault(
SgNode *root)
7445 Rose_STL_Container <SgNode*> nodeList= NodeQuery::querySubTree(root,V_SgNode);
7446 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i!=nodeList.end(); i++ )
7448 setSourcePositionAsDefault(*i);
7458 Rose_STL_Container <SgNode*> nodeList = NodeQuery::querySubTree(root,V_SgNode);
7461 printf (
"In setSourcePositionAtRootAndAllChildren(): nodeList.size() = %" PRIuPTR
" \n",nodeList.size());
7464 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
7467 printf (
"In setSourcePositionAtRootAndAllChildren(): *i = %p = %s \n",*i,(*i)->class_name().c_str());
7486 printf (
"In SageInterface::setSourcePosition(): SourcePositionClassification scp = %s \n",
display(scp).c_str());
7491 case e_sourcePositionError:
7493 printf (
"Error: error value e_sourcePositionError in SageInterface::setSourcePosition() \n");
7500 printf (
"e_sourcePositionDefault in SageInterface::setSourcePosition() \n");
7503 if (locatedNode != NULL)
7505 setSourcePositionToDefault(locatedNode);
7510 printf (
"Error: can't call setSourcePosition() in mode e_sourcePositionDefault with non SgLocatedNode (node = %p = %s) \n",node,node->
class_name().c_str());
7519 printf (
"e_sourcePositionTransformation in SageInterface::setSourcePosition() \n");
7528 printf (
"e_sourcePositionCompilerGenerated in SageInterface::setSourcePosition() \n");
7530 printf (
"Sorry, not implemented \n");
7539 printf (
"e_sourcePositionNullPointers in SageInterface::setSourcePosition() \n");
7556 printf (
"e_sourcePositionFrontendConstruction in SageInterface::setSourcePosition() \n");
7559 if (locatedNode != NULL)
7562 setSourcePositionToDefault(locatedNode);
7567 SgPragma* pragma = isSgPragma(node);
7570 setSourcePositionToDefault(pragma);
7576 SgType* type = isSgType(node);
7584 if (functionParameterTypeList != NULL)
7590 printf (
"Error: can't call setSourcePosition() in mode e_sourcePositionFrontendConstruction with non SgLocatedNode (node = %p = %s) \n",node,node->
class_name().c_str());
7603 printf (
"Error: error value e_sourcePositionError in SageInterface::setSourcePosition() \n");
7609 printf (
"Error: default reached in SageInterface::setSourcePosition() \n");
7617 node->
get_file_info()->display(
"Leaving SageInterface::setSourcePosition()");
7624SageInterface::setSourcePositionForTransformation_memoryPool()
7629 printf (
"ERROR: In setSourcePositionForTransformation_memoryPool(): This seems like a very dangerous function to have, is it required? \n");
7632 VariantVector vv(V_SgNode);
7633 Rose_STL_Container<SgNode*> nodeList = NodeQuery::queryMemoryPool(vv);
7634 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++ )
7645 ROSE_ASSERT(project != NULL);
7648 ROSE_ASSERT(project->get_fileList().empty() ==
false);
7651 SgSourceFile* file = isSgSourceFile(project->get_fileList()[0]);
7652 SgGlobal* global = file->get_globalScope();
7655 SgFilePtrListPtr fileList = project->get_fileList();
7656 SgFilePtrList::const_iterator i= fileList->begin();
7658 SgGlobal* global = (*i)->get_globalScope();
7660 ROSE_ASSERT(global != NULL);
7681 if (declList.empty() ==
false)
7683 stmt = isSgStatement(declList.back());
7692 if (stmtList.empty() ==
false)
7694 stmt = stmtList.back();
7716 if (includingCompilerGenerated)
7720 if (declList.empty() ==
false)
7722 stmt = isSgStatement(declList.front());
7728 SgDeclarationStatementPtrList::iterator i=declList.begin();
7729 while (i != declList.end())
7756 if (includingCompilerGenerated)
7760 if (stmtList.empty() ==
false)
7762 stmt = stmtList.front();
7768 SgStatementPtrList::iterator i = stmtList.begin();
7769 while (i!=stmtList.end())
7804 SgDeclarationStatementPtrList::iterator i=declList.begin();
7805 while (i!=declList.end())
7829 SgStatementPtrList::iterator i=stmtList.begin();
7830 while (i!=stmtList.end())
7857 bool result =
false;
7860 if (isSgProgramHeaderStatement(n)) {
7865 if (isSgFunctionDeclaration(n) !=
nullptr) {
7866 bool either =
false;
7872 ROSE_ASSERT(stmnt !=
nullptr);
7879 ROSE_ASSERT(funcDefn !=
nullptr);
7880 if (funcDefn->get_name() ==
"main") {
7904 return isSgFunctionDeclaration(n);
7907 for (vector<SgNode*>::const_iterator i = children.begin();
7908 i != children.end(); ++i) {
7926 ROSE_ASSERT (scope != NULL);
7930 for (
size_t i = 0; i<stmt_list.size(); i++)
7934 if (isSgDeclarationStatement(cur_stmt))
7936 if (isSgPragmaDeclaration (cur_stmt))
7956 rt = n->copy (g_treeCopy);
7966 bool isC = TransformationSupport::getSourceFile(n)->get_outputLanguage() ==
SgFile::e_C_language;
7978#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
7980 for (std::vector<SgContinueStmt*>::iterator i = continues.begin(); i != continues.end(); ++i)
7985 LowLevelRewrite::replace(*i, make_unit_list( gotoStatement ) );
7991 printf (
"Not supported in mode: ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT (LowLevelRewrite::replace() is unavailable)");
7996#define DEBUG_TEMPLATE_ARG_EQUIVALENCE 0
8002#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8003 printf (
"In templateArgumentEquivalence(): same pointer to template argument: returning true \n");
8010#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8011 printf (
"In templateArgumentEquivalence(): different argumentType(): returning false \n");
8020 ROSE_ASSERT(arg1->
get_type() != NULL);
8021 ROSE_ASSERT(arg2->
get_type() != NULL);
8023#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8024 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::type_argument: checking for the same type: arg1->get_type() = %p = %s arg2->get_type() = %p = %s \n",
8032#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8033 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::type_argument: checking for the same type: returning true \n");
8046#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8047 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::type_argument: checking for the same type: pointers are different: returning typesAreEqual = %s \n",typesAreEqual ?
"true" :
"false");
8049 return typesAreEqual;
8057 if (expr1 == expr2) {
8058#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8059 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: checking for the same expression: returning true \n");
8063#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8064 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: same variant of expression: %s\n", expr1->
class_name().c_str());
8067 case V_SgLongIntVal: {
8071 case V_SgUnsignedLongVal:
8076 case V_SgBoolValExp:
8081 mlog[Sawyer::Message::Common::FATAL]
8082 <<
"FATAL: In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: expression have the same variant "
8084 <<
" but comparison is not NIY!"
8090#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8091 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: different variant of expression: returning false \n");
8099 if (arg1->get_templateDeclaration() == arg2->get_templateDeclaration())
8101#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
8102 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::template_template_argument: checking for the same templateDeclaration: returning true \n");
8108 ROSE_ASSERT(!
"NIY: template template argument comparaison.");
8114 ROSE_ASSERT(!
"Try to compare template arguments of unknown type...");
8123 ROSE_ASSERT(!
"Try to compare template arguments of unknown type start_of_pack_expansion_argument");
8129 printf (
"Error: default case not handled! \n");
8137#define DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE 0
8141 if (list1.size() != list2.size())
8143#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8144 printf (
"In templateArgumentListEquivalence(): different list sizes: returning false \n");
8145 printf (
" --- list1.size() = %zu \n",list1.size());
8146 printf (
" --- list2.size() = %zu \n",list2.size());
8153#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8154 printf (
"In templateArgumentListEquivalence(): same list using STL equality operator: returning true \n");
8160 for (
size_t i = 0; i < list1.size(); i++)
8162#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8163 printf (
"In templateArgumentListEquivalence(): calling templateArgumentEquivalence() for i = %zu \n",i);
8168#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8169 printf (
"In templateArgumentListEquivalence(): calling templateArgumentEquivalence() for i = %zu --- returned false: returning false \n",i);
8175#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8176 printf (
"In templateArgumentListEquivalence(): reached base of function: returning true \n");
8196 SgName labelname =
"rose_label__";
8209 if (isSgNullExpression(f->get_increment()))
return;
8214 f->set_increment(ne);
8224 ROSE_ASSERT(condstmt);
8226 if (isSgNullStatement(condstmt))
return true;
8230 return isSgNullExpression(exprStmt->get_expression());
8239 bbStmts = initStmts;
8240 for (
size_t i = 0; i < bbStmts.size(); ++i) {
8241 bbStmts[i]->set_parent(bb);
8244 const bool testIsNull = hasEmptyCondition(f);
8254 Rose_STL_Container<SgNode*> fors = NodeQuery::querySubTree(top,
8256 for (
size_t i = 0; i < fors.size(); ++i) {
8264 Rose_STL_Container<SgNode*> allGotos = NodeQuery::querySubTree(scope, V_SgGotoStatement);
8266 vector<SgGotoStatement*> result;
8267 for (Rose_STL_Container<SgNode*>::const_iterator i = allGotos.begin(); i != allGotos.end(); ++i) {
8268 if (isSgGotoStatement(*i)->
get_label() == l) {
8269 result.push_back(isSgGotoStatement(*i));
8277 vector<SgReturnStmt*> SageInterface::findReturnStmts(
SgStatement* scope) {
8280 Rose_STL_Container<SgNode*> returns = NodeQuery::querySubTree(scope, V_SgReturnStmt);
8282 vector<SgReturnStmt*> result;
8283 for (Rose_STL_Container<SgNode*>::const_iterator i = returns.begin(); i != returns.end(); ++i) {
8284 result.push_back(isSgReturnStmt(*i));
8290static void getSwitchCasesHelper(
SgStatement* top, vector<SgStatement*>& result) {
8292 if (isSgSwitchStatement(top))
return;
8293 if (isSgCaseOptionStmt(top) || isSgDefaultOptionStmt(top)) {
8294 result.push_back(top);
8297 for (
unsigned int i = 0; i < children.size(); ++i) {
8298 if (isSgStatement(children[i])) {
8299 getSwitchCasesHelper(isSgStatement(children[i]), result);
8305 vector<SgStatement*> result;
8306 getSwitchCasesHelper(sw->
get_body(), result);
8336 if (
const SgSymbol* symbol = isSgSymbol(astNode))
8337 return symbol->get_scope();
8342 else if (
const SgQualifiedName* qualifiedName = isSgQualifiedName(astNode))
8346 const SgNode* parentNode = astNode;
8347 while (!isSgScopeStatement(parentNode))
8352 if (isSgFunctionParameterList(parentNode) || isSgCtorInitializerList(parentNode))
8355 ROSE_ASSERT(funcDeclaration != NULL);
8357 if (funcDeclaration != NULL)
8359 return funcDeclaration->get_definition();
8364 if (parentNode == NULL)
8372 if ( isSgScopeStatement(parentNode) == NULL &&
8373 dynamic_cast<const SgType*
>(parentNode) == NULL &&
8374 dynamic_cast<const SgSymbol*
>(parentNode) == NULL )
8376 printf (
"Error: In SageInterface::getScope(): could not trace back to SgScopeStatement node \n");
8381 if (
dynamic_cast<const SgType*
>(parentNode) != NULL ||
dynamic_cast<const SgSymbol*
>(parentNode) != NULL )
8383 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());
8391 ROSE_ASSERT (scopeStatement != NULL);
8394 if (isSgScopeStatement(astNode))
8395 if (isSgScopeStatement(parentNode))
8397 ROSE_ASSERT (astNode == parentNode);
8424 printf (
"In getVarSymFromName(): name->get_name() = %s \n",name->get_name().str());
8427 ROSE_ASSERT (scope != NULL);
8429 printf (
"In getVarSymFromName(): name->get_name() = %s scope = %p = %s \n",name->get_name().str(),scope,scope->
class_name().c_str());
8431 v_sym = scope->lookup_var_symbol (name->get_name());
8440 if (decl_scope != NULL)
8441 v_sym = decl_scope->lookup_var_symbol (name->get_name());
8444 cerr <<
"\t\t*** WARNING: Can't seem to find a symbol for '"
8445 << name->get_name ().str ()
8475getVarSym_const (
const SgNode* n)
8481 v_sym = isSgVarRefExp (n)->get_symbol ();
8483 case V_SgInitializedName:
8484 v_sym = getVarSymFromName_const (isSgInitializedName (n));
8510 if (!decl)
return 0;
8511 const SgInitializedNamePtrList& names = decl->
get_variables ();
8512 if (names.begin () != names.end ())
8515 return getVarSym_const (name);
8534 if (names.begin () != names.end ())
8535 return *(names.begin ());
8541static void findBreakStmtsHelper(
SgStatement* code,
const std::string& fortranLabel,
bool inOutermostBody, vector<SgBreakStmt*>& breakStmts) {
8542 if (isSgWhileStmt(code) || isSgDoWhileStmt(code) || isSgForStatement(code) || isSgSwitchStatement(code)) {
8543 if (fortranLabel ==
"") {
8548 inOutermostBody =
false;
8551 if (isSgBreakStmt(code)) {
8553 bool breakMatchesThisConstruct =
false;
8554 if (bs->get_do_string_label() ==
"") {
8556 breakMatchesThisConstruct = inOutermostBody;
8558 breakMatchesThisConstruct = (fortranLabel == bs->get_do_string_label());
8560 if (breakMatchesThisConstruct) {
8561 breakStmts.push_back(bs);
8566 for (
unsigned int i = 0; i < children.size(); ++i) {
8567 if (isSgStatement(children[i])) {
8568 findBreakStmtsHelper(isSgStatement(children[i]), fortranLabel, inOutermostBody, breakStmts);
8576 vector<SgBreakStmt*> result;
8577 findBreakStmtsHelper(code, fortranLabel,
true, result);
8582static void findContinueStmtsHelper(
SgStatement* code,
const std::string& fortranLabel,
bool inOutermostBody, vector<SgContinueStmt*>& continueStmts) {
8583 if (isSgWhileStmt(code) || isSgDoWhileStmt(code) || isSgForStatement(code)) {
8584 if (fortranLabel ==
"") {
8589 inOutermostBody =
false;
8592 if (isSgContinueStmt(code)) {
8594 bool continueMatchesThisConstruct =
false;
8595 if (cs->get_do_string_label() ==
"") {
8597 continueMatchesThisConstruct = inOutermostBody;
8599 continueMatchesThisConstruct = (fortranLabel == cs->get_do_string_label());
8601 if (continueMatchesThisConstruct) {
8602 continueStmts.push_back(cs);
8607 for (
unsigned int i = 0; i < children.size(); ++i) {
8609 if (stmnt != NULL) {
8610 findContinueStmtsHelper(stmnt, fortranLabel, inOutermostBody, continueStmts);
8618 vector<SgContinueStmt*> result;
8619 findContinueStmtsHelper(code, fortranLabel,
true, result);
8630 std::cout <<
"Starting getInitializerOfExpression on 0x" << std::hex << (int)n <<
", which has type " << n->
sage_class_name() << std::endl;
8632 while (!isSgInitializer(n)) {
8635 std::cout <<
"Continuing getInitializerOfExpression on 0x" << std::hex << (int)n;
8637 std::cout << std::endl;
8641 return isSgInitializer(n);
8649 std::vector<SgVariableSymbol*> symbols;
8651 virtual void visit(
SgNode* n) {
8652 if (isSgVarRefExp(n))
8653 symbols.push_back(isSgVarRefExp(n)->get_symbol());
8657 GetSymbolsUsedInExpressionVisitor vis;
8658 vis.traverse(expr, preorder);
8665 return getEnclosingNode<SgSourceFile>(n, includingSelf);
8671 return findDeclarationStatement<SgFunctionDeclaration> (root, name, scope, isDefining);
8682 return getEnclosingNode<SgFunctionDefinition>(n, includingSelf);
8688 return getEnclosingNode<SgFunctionDeclaration>(astNode, includingSelf);
8698 return getEnclosingNode<SgGlobal>(astNode,
true );
8703 return getEnclosingNode<SgClassDefinition>(astNode, includingSelf);
8711 return getEnclosingNode<SgClassDeclaration>(astNode,
true);
8716 return getEnclosingNode<SgExprListExp>(astNode, includingSelf);
8722 bool returnValue =
false;
8728 virtual void visit(
SgNode* n)
8730 if (n == expression_target)
8736 Visitor(
SgExpression* expr) : expression_target(expr), in_subtree(
false) {}
8739 Visitor traversal(exp);
8741 traversal.traverse(subtree, preorder);
8743 returnValue = traversal.in_subtree;
8757 ROSE_ASSERT (functionCallExp != NULL);
8759 SgExpression* expression = functionCallExp->get_function();
8760 ROSE_ASSERT (expression != NULL);
8764 SgDotExp* dotExp = isSgDotExp(expression);
8767 ROSE_ASSERT (dotExp != NULL);
8770 ROSE_ASSERT (rhsOperand != NULL);
8775 if (memberFunctionRefExp != NULL)
8782 if (functionReferenceExp != NULL)
8787 SgArrowExp* arrowExp = isSgArrowExp(expression);
8788 if ( arrowExp != NULL)
8790 ROSE_ASSERT (arrowExp != NULL);
8793 ROSE_ASSERT (rhsOperand != NULL);
8798 if (memberFunctionRefExp != NULL)
8804 return returnDeclaration;
8809std::list<SgClassType*>
8814#define DEBUG_DATA_MEMBER_TYPE_CHAIN 0
8820 ROSE_ASSERT(varRefExp != NULL || memberFunctionRefExp != NULL);
8822 std::list<SgClassType*> returnTypeChain;
8825 std::list<SgClassType*> classChain;
8830 if (varRefExp != NULL)
8836 ROSE_ASSERT(memberFunctionRefExp != NULL);
8841 ROSE_ASSERT(parent != NULL);
8843#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8844 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): parent = %p = %s \n",parent,parent->
class_name().c_str());
8848 SgDotExp* dotExp = isSgDotExp(parent);
8852 if (arrowExp != NULL)
8854#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8855 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): Found an arrow expression \n");
8857 binaryOperator = arrowExp;
8862#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8863 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): Found an dot expression \n");
8865 binaryOperator = dotExp;
8869 if (binaryOperator != NULL)
8872 ROSE_ASSERT(lhs != NULL);
8874#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8875 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs = %p = %s \n",lhs,lhs->
class_name().c_str());
8881 while (isSgCastExp(temp_lhs) != NULL)
8883 cast = isSgCastExp(temp_lhs);
8884 ROSE_ASSERT(cast != NULL);
8887#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8888 printf (
"Top of loop: processing cast = %p temp_lhs = %p = %s \n",cast,temp_lhs,temp_lhs->
class_name().c_str());
8890 ROSE_ASSERT(cast->
get_type() != NULL);
8892 if (classType == NULL)
8894#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8895 printf (
" --- looking for base type: In SageInterface::getClassTypeChainForDataMemberReference(): classType == NULL: cast->get_type() = %p = %s \n",
8898 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);
8899 ROSE_ASSERT(baseType != NULL);
8901#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8902 printf (
" --- baseType = %p = %s name = %s \n",baseType,baseType->
class_name().c_str(),
get_name(baseType).c_str());
8904 classType = isSgClassType(baseType);
8908 ROSE_ASSERT(temp_lhs != NULL);
8910#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8911 printf (
" --- temp_lhs = %p = %s name = %s \n",temp_lhs,temp_lhs->
class_name().c_str(),
get_name(temp_lhs).c_str());
8917 if (classType != NULL)
8919 classChain.push_front(classType);
8923 if (classType != NULL)
8934 ROSE_ASSERT(target_type != NULL);
8935 SgClassType* target_classType = isSgClassType(target_type);
8937 if (target_classType != NULL)
8940 ROSE_ASSERT(target_declaration != NULL);
8941 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(target_declaration);
8942 ROSE_ASSERT(target_classDeclaration != NULL);
8944 ROSE_ASSERT(target_definingClassDeclaration != NULL);
8945 SgScopeStatement* target_scope = target_definingClassDeclaration->get_definition();
8946 ROSE_ASSERT(target_scope != NULL);
8948#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8949 printf (
"target_classDeclaration = %p = %s name = %s target_scope = %p = %s \n",
8950 target_classDeclaration,target_classDeclaration->
class_name().c_str(),target_classDeclaration->get_name().str(),target_scope,target_scope->
class_name().c_str());
8953 ROSE_ASSERT(source_classType != NULL);
8955 ROSE_ASSERT(source_declaration != NULL);
8956 SgClassDeclaration* source_classDeclaration = isSgClassDeclaration(source_declaration);
8957 ROSE_ASSERT(source_classDeclaration != NULL);
8959 ROSE_ASSERT(source_definingClassDeclaration != NULL);
8960 SgScopeStatement* source_scope = source_definingClassDeclaration->get_definition();
8961 ROSE_ASSERT(source_scope != NULL);
8963#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8964 printf (
"source_classDeclaration = %p = %s name = %s source_scope = %p = %s \n",
8965 source_classDeclaration,source_classDeclaration->
class_name().c_str(),source_classDeclaration->get_name().str(),source_scope,source_scope->
class_name().c_str());
8968 while (tmp_scope != NULL && tmp_scope != target_scope)
8970#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8971 printf (
"tmp_scope = %p = %s \n",tmp_scope,tmp_scope->
class_name().c_str());
8974 ROSE_ASSERT(tmp_classDefinition != NULL);
8976 ROSE_ASSERT(tmp_classDeclaration != NULL);
8978#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8979 SgName scope_name = tmp_classDeclaration->get_name();
8980 printf (
"scope_name = %s \n",scope_name.str());
8982 SgClassType* tmp_classType = tmp_classDeclaration->get_type();
8983 ROSE_ASSERT(tmp_classType != NULL);
8986 classChain.push_front(tmp_classType);
8990 if (isSgGlobal(tmp_scope) != NULL)
8999 printf (
"In loop processing cast: target_type = %p = %s \n",target_type,target_type->
class_name().c_str());
9005#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9006 printf (
"Bottom of loop: processing cast = %p temp_lhs = %p = %s \n",cast,temp_lhs,temp_lhs->
class_name().c_str());
9012 ROSE_ASSERT(temp_lhs != NULL);
9014#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9015 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): temp_lhs = %p = %s \n",temp_lhs,temp_lhs->
class_name().c_str());
9018 SgVarRefExp* derivedClassVarRefExp = isSgVarRefExp(temp_lhs);
9019 if (derivedClassVarRefExp != NULL)
9021 SgVariableSymbol* derivedClassVariableSymbol = derivedClassVarRefExp->get_symbol();
9022 ROSE_ASSERT(derivedClassVariableSymbol != NULL);
9024 SgName derivedClassVariableName = derivedClassVariableSymbol->
get_name();
9026#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9027 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): derivedClassVariableName = %s \n",derivedClassVariableName.str());
9031 ROSE_ASSERT(type != NULL);
9033#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9034 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs type = %p = %s \n",type,type->
class_name().c_str());
9038 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);
9040#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9041 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs stripped_type = %p = %s \n",stripped_type,stripped_type->
class_name().c_str());
9045 SgClassType* classType = isSgClassType(stripped_type);
9048 if (classType != NULL)
9050#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9051 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs classType = %p = %s \n",classType,classType->
class_name().c_str());
9052 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
9053 ROSE_ASSERT(classDeclaration != NULL);
9054 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs classDeclaration = %p = %s name = %s \n",
9055 classDeclaration,classDeclaration->
class_name().c_str(),classDeclaration->get_name().str());
9060 classChain.push_front(classType);
9064#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9065 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs stripped_type is not a SgClassType \n");
9071#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9072 printf (
"Need to support alternative to SgVarRefExp: temp_lhs = %p = %s \n",temp_lhs,temp_lhs->
class_name().c_str());
9075 ROSE_ASSERT(type != NULL);
9077#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9078 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs type = %p = %s name = %s \n",type,type->
class_name().c_str(),
get_name(type).c_str());
9082 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);
9084#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9085 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());
9088 SgClassType* classType = isSgClassType(stripped_type);
9090 if (classType != NULL)
9092 classChain.push_front(classType);
9096#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9097 printf (
"classChain.size() = %zu \n",classChain.size());
9098 std::list<SgClassType*>::iterator iter = classChain.begin();
9099 while(iter != classChain.end())
9101 printf (
" --- *iter = %p = %s name = %s \n",*iter,(*iter)->class_name().c_str(),(*iter)->get_name().str());
9114 if (varRefExp != NULL)
9116 ROSE_ASSERT(varRefExp != NULL);
9117 ROSE_ASSERT(memberFunctionRefExp == NULL);
9119 referenceSymbol = varRefExp->get_symbol();
9123 ROSE_ASSERT(varRefExp == NULL);
9124 ROSE_ASSERT(memberFunctionRefExp != NULL);
9126 referenceSymbol = memberFunctionRefExp->get_symbol();
9128 ROSE_ASSERT(referenceSymbol != NULL);
9131#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9132 printf (
"referenceSymbol = %p = %s \n",referenceSymbol,referenceSymbol->
class_name().c_str());
9133 printf (
"symbolName = %s \n",symbolName.str());
9138 if (functionSymbol != NULL)
9143 if (templateInstantiationMemberFunctionDeclaration != NULL)
9145#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9146 printf (
"This is a template name, we want the name without template arguments \n");
9147 printf (
"templateInstantiationMemberFunctionDeclaration = %p \n",templateInstantiationMemberFunctionDeclaration);
9148 printf (
"templateInstantiationMemberFunctionDeclaration->get_name() = %s \n",templateInstantiationMemberFunctionDeclaration->get_name().str());
9155 isSgTemplateMemberFunctionDeclaration(templateInstantiationMemberFunctionDeclaration->
get_templateDeclaration());
9156 if (templateMemberFunctionDeclaration != NULL)
9158#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9159 printf (
"templateMemberFunctionDeclaration = %p \n",templateMemberFunctionDeclaration);
9160 printf (
"templateMemberFunctionDeclaration->get_name() = %s \n",templateMemberFunctionDeclaration->get_name().str());
9163 symbolName = templateMemberFunctionDeclaration->get_name();
9167#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9168 printf (
"templateMemberFunctionDeclaration == NULL: template declaration not available from template instantiation (rare, I think) \n");
9172 printf (
"Exiting as a test! \n");
9180 ROSE_ASSERT(declarationStatement != NULL);
9181#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9182 printf (
"functionSymbol != NULL: but declaration is not a member function: declarationStatement = %p = %s \n",declarationStatement,declarationStatement->
class_name().c_str());
9189 if (variableSymbol != NULL)
9195#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9196 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): NOTE: referenceSymbol is not a SgFunctionSymbol or SgVariableSymbol \n");
9199 printf (
"Exiting as a test! \n");
9206#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9207 printf (
"symbolName = %s \n",symbolName.str());
9216 std::list<SgClassType*> saveList;
9218#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9219 printf (
"classChain.size() = %zu \n",classChain.size());
9222 std::list<SgClassType*>::iterator i = classChain.begin();
9223 std::list<SgClassType*>::iterator save_iter = i;
9229 bool ambiguityDetectedSoSaveWholeChain =
false;
9231 while(i != classChain.end())
9233#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9234 printf (
"******** TOP OF WHILE LOOP ******** \n");
9235 printf (
" --- *i = %p = %s name = %s \n",*i,(*i)->class_name().c_str(),(*i)->get_name().str());
9236 printf (
" --- --- referenceSymbol = %p = %s \n",referenceSymbol,referenceSymbol->
class_name().c_str());
9238 bool ambiguityDetected =
false;
9241 ROSE_ASSERT(declarationStatement != NULL);
9243 if (definingDeclarationStatement != NULL)
9245 SgClassDeclaration* classDeclaration = isSgClassDeclaration(definingDeclarationStatement);
9246 ROSE_ASSERT(classDeclaration != NULL);
9249#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9250 printf (
" --- classDeclaration = %p = %s name = %s \n",classDeclaration,classDeclaration->
class_name().c_str(),classDeclaration->get_name().str());
9251 printf (
" --- classDefinition = %p = %s \n",classDefinition,classDefinition->
class_name().c_str());
9254 ambiguityDetected = classDefinition->hasAmbiguity(symbolName,referenceSymbol);
9256#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9257 printf (
" --- ambiguityDetected = %s \n",ambiguityDetected ?
"true" :
"false");
9262 if (ambiguityDetected ==
true || ambiguityDetectedSoSaveWholeChain ==
true)
9264 ambiguityDetectedSoSaveWholeChain =
true;
9266 if (save_iter != classChain.end())
9268#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9269 printf (
" --- add to saveList: *save_iter = %p \n",*save_iter);
9271 saveList.push_back(*save_iter);
9275#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9276 printf (
" --- save_iter == classChain.end() \n");
9281#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9282 printf (
"******** BOTTOM OF WHILE LOOP ******** \n");
9292#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9293 printf (
"saveList.size() = %zu \n",saveList.size());
9294 std::list<SgClassType*>::iterator saveList_iterator = saveList.begin();
9295 while (saveList_iterator != saveList.end())
9297 printf (
" --- *saveList_iterator = %p = %s name = %s \n",*saveList_iterator,(*saveList_iterator)->class_name().c_str(),(*saveList_iterator)->get_name().str());
9299 saveList_iterator++;
9303 returnTypeChain = saveList;
9308 return returnTypeChain;
9318#define DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE 0
9320 ROSE_ASSERT(memberFunctionRefExp != NULL);
9322 bool returnValue =
false;
9328 SgDotExp* dotExp = isSgDotExp(parent);
9335 if (arrowExp != NULL || dotExp != NULL || addressOfOp != NULL)
9339 ROSE_ASSERT(symbol != NULL);
9342 ROSE_ASSERT(functionDeclaration != NULL);
9345 if (functionDeclaration != NULL)
9347 bool isStatic = functionDeclaration->get_declarationModifier().get_storageModifier().
isStatic();
9348#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9349 printf (
"isStatic = %s \n",
isStatic ?
"true" :
"false");
9354 ROSE_ASSERT(scope != NULL);
9357 if (classDefinition != NULL)
9365#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9366 printf (
"In SageInterface::isMemberFunctionMemberReference(): memberFunctionRefExp is not associated with variableDeclaration (could not compute if it is static data member) \n");
9372#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9373 printf (
"In SageInterface::isMemberFunctionMemberReference(): memberFunctionRefExp parent is not a is not SgArrowExp or SgDotExp expression \n");
9377#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9378 printf (
"Leaving SageInterface::isMemberFunctionMemberReference(): returnValue = %s \n",returnValue ?
"true" :
"false");
9397#define DEBUG_IS_DATA_MEMBER_REFERENCE 0
9399 ROSE_ASSERT(varRefExp != NULL);
9401 bool returnValue =
false;
9407 SgDotExp* dotExp = isSgDotExp(parent);
9411 if (arrowExp != NULL || dotExp != NULL || addressOfOp != NULL)
9413 if (arrowExp != NULL)
9417 ROSE_ASSERT(parentOfArrowExp != NULL);
9418 SgSizeOfOp* sizeOfOp = isSgSizeOfOp(parentOfArrowExp);
9419 if (sizeOfOp != NULL && sizeOfOp->get_is_objectless_nonstatic_data_member_reference() ==
true)
9422#if DEBUG_IS_DATA_MEMBER_REFERENCE
9423 printf (
"In SageInterface::isDataMemberReference(): Found case of expression used in sizeof with objectless_nonstatic_data_member_reference \n");
9430 ROSE_ASSERT(symbol != NULL);
9433 ROSE_ASSERT(initializedName != NULL);
9437 if (variableDeclaration != NULL)
9439 bool isStatic = variableDeclaration->get_declarationModifier().get_storageModifier().
isStatic();
9443 ROSE_ASSERT(scope != NULL);
9446 if (classDefinition != NULL)
9454#if DEBUG_IS_DATA_MEMBER_REFERENCE
9455 printf (
"In SageInterface::isDataMemberReference(): varRefExp is not associated with variableDeclaration (could not compute if it is static data member) \n");
9461#if DEBUG_IS_DATA_MEMBER_REFERENCE
9462 printf (
"In SageInterface::isDataMemberReference(): varRefExp parent is not a is not SgArrowExp or SgDotExp expression \n");
9466#if DEBUG_IS_DATA_MEMBER_REFERENCE
9467 printf (
"Leaving SageInterface::isDataMemberReference(): returnValue = %s \n",returnValue ?
"true" :
"false");
9479 ROSE_ASSERT(varRefExp != NULL);
9481 bool returnValue =
false;
9485 if (addressOfOp != NULL)
9503 ROSE_ASSERT(varRefExp != NULL || memberFunctionRefExp != NULL);
9507 ROSE_ASSERT(refExp != NULL);
9509 bool returnValue =
false;
9514 if (addressOfOp != NULL)
9532 ROSE_ASSERT (astNode != NULL);
9536 ROSE_ASSERT (isSgProject(astNode) == NULL);
9538 SgNode* previous_parent = NULL;
9539 SgNode* previous_previous_parent = NULL;
9541 SgNode* parent = astNode;
9543 while ( (parent != NULL) && (isSgFile(parent) == NULL) && isSgJavaPackageDeclaration(parent) == NULL)
9546 printf (
"In getEnclosingFileNode(): parent = %p = %s \n",parent,parent->
class_name().c_str());
9548 previous_previous_parent = previous_parent;
9549 previous_parent = parent;
9554 if (previous_previous_parent != NULL && previous_parent != NULL && isSgJavaPackageDeclaration(parent) != NULL)
9558 printf (
"parent = %p = %s \n",parent,parent->
class_name().c_str());
9559 printf (
"previous_parent = %p = %s \n",previous_parent,previous_parent->
class_name().c_str());
9560 printf (
"previous_previous_parent = %p = %s \n",previous_previous_parent,previous_previous_parent->
class_name().c_str());
9562 SgClassDeclaration* classDeclaration = isSgClassDeclaration(previous_previous_parent);
9563 if (classDeclaration != NULL)
9566 printf (
"Class name = %p = %s = %s \n",classDeclaration,classDeclaration->
class_name().c_str(),classDeclaration->get_name().str());
9571 SgProject* project = TransformationSupport::getProject(parent);
9572 ROSE_ASSERT(project != NULL);
9573 SgFileList* fileList = project->get_fileList_ptr();
9574 ROSE_ASSERT(fileList != NULL);
9575 SgFilePtrList & vectorFile = fileList->get_listOfFiles();
9577 printf (
"Output list of files: \n");
9579 SgFilePtrList::iterator i = vectorFile.begin();
9580 while (i != vectorFile.end())
9583 ROSE_ASSERT(file != NULL);
9585 printf (
" --- filename = %s \n",file->
getFileName().c_str());
9588 string filenameWithoutPath = file->get_sourceFileNameWithoutPath();
9589 string classname = classDeclaration->get_name();
9590 string matchingfilename = classname +
".java";
9592 printf (
" --- --- filename = %s \n",filename.c_str());
9593 printf (
" --- --- filenameWithoutPath = %s \n",filenameWithoutPath.c_str());
9594 printf (
" --- --- classname = %s \n",classname.c_str());
9595 printf (
" --- --- matchingfilename = %s \n",matchingfilename.c_str());
9597 if (filenameWithoutPath == matchingfilename)
9600 printf (
" return file = %p \n",file);
9616 SgSourceFile *sourcefile = isSgSourceFile(attribute->getNode());
9617 ROSE_ASSERT(sourcefile != NULL);
9626 if (previous_parent == NULL && isSgJavaPackageDeclaration(parent) != NULL)
9629 ROSE_ASSERT(isSgJavaPackageDeclaration(astNode) != NULL);
9634 if (previous_previous_parent == NULL && isSgJavaPackageDeclaration(parent) != NULL)
9637 ROSE_ASSERT(isSgClassDefinition(astNode) != NULL);
9648 if (parent ==
nullptr)
9654 return isSgFile(parent);
9660 std::set<SgNode*> specific;
9661 std::set<SgNode*> non_specific;
9663 static void recursive_collect(
SgNode* node , std::set<SgNode *> & collection ) {
9665 if (node == NULL || !collection.insert(node).second)
return;
9668 for (std::vector<std::pair<SgNode*, std::string> >::iterator i = data_members.begin(); i != data_members.end(); ++i) {
9669 recursive_collect(i->first, collection);
9676 if (fileInfo != NULL) {
9677 if (fileInfo->isFrontendSpecific()) {
9679 recursive_collect(n, specific);
9681 non_specific.insert(n);
9682 recursive_collect(n, non_specific);
9685 fileInfo = isSg_File_Info(n);
9686 if (fileInfo != NULL) {
9687 if (fileInfo->isFrontendSpecific()) {
9690 non_specific.insert(n);
9696 std::set<SgNode*> apply() {
9697 traverseMemoryPool();
9699 std::set<SgNode*> result;
9701 std::set_difference(
9702 specific.begin(), specific.end(),
9703 non_specific.begin(), non_specific.end(),
9704 std::insert_iterator<set<SgNode*> >(result, result.begin())
9711 FrontendSpecificTraversal fst;
9724 void visit(
SgNode *astNode)
9726 ROSE_ASSERT(astNode != NULL);
9728 if (file_info != NULL)
9732 printf (
"Found shared node: astNode = %p = %s \n",astNode,astNode->
class_name().c_str());
9738 OutputSharedNodesTraversal tt;
9739 tt.traverse(node,preorder);
9747 while (n && !isSgStatement(n)) n = n->
get_parent();
9748 return isSgStatement(n);
9757SageInterface::DeferredTransformation::DeferredTransformation()
9758 : deferredTransformationKind(e_default),
9759 statementToRemove(NULL),
9760 statementToAdd(NULL),
9761 class_definition(NULL),
9762 target_class_member(NULL),
9763 new_function_prototype(NULL),
9765 locationToOverwriteWithTransformation(NULL),
9766 transformationToOverwriteFirstStatementInInterval(NULL),
9767 blockOfStatementsToOutline(NULL)
9771 printf (
"In SageInterface::DeferredTransformation default constructor called \n");
9779SageInterface::DeferredTransformation::DeferredTransformation(
9783 : deferredTransformationKind(e_outliner),
9784 statementToRemove(NULL),
9785 statementToAdd(NULL),
9786 class_definition(input_class_definition),
9787 target_class_member(input_target_class_member),
9788 new_function_prototype(input_new_function_prototype),
9790 locationToOverwriteWithTransformation(NULL),
9791 transformationToOverwriteFirstStatementInInterval(NULL),
9792 blockOfStatementsToOutline(NULL)
9796 printf (
"In SageInterface::DeferredTransformation constructor for outliner called \n");
9804 printf (
"In SageInterface::DeferredTransformation constructor for replaceDefiningFunctionDeclarationWithFunctionPrototype called \n");
9810 X.deferredTransformationKind = e_replaceDefiningFunctionDeclarationWithFunctionPrototype;
9811 X.statementToRemove = functionDeclaration;
9812 X.statementToAdd = NULL;
9813 X.class_definition = NULL;
9814 X.target_class_member = NULL;
9815 X.new_function_prototype = NULL;
9818 X.locationToOverwriteWithTransformation = NULL;
9819 X.transformationToOverwriteFirstStatementInInterval = NULL;
9820 X.blockOfStatementsToOutline = NULL;
9826SageInterface::DeferredTransformation::replaceStatement(
SgStatement* oldStmt,
SgStatement* newStmt,
bool )
9829 printf (
"In SageInterface::DeferredTransformation constructor for replaceStatement called \n");
9835 X.deferredTransformationKind = e_replaceStatement;
9836 X.statementToRemove = oldStmt;
9837 X.statementToAdd = newStmt;
9838 X.class_definition = NULL;
9839 X.target_class_member = NULL;
9840 X.new_function_prototype = NULL;
9843 X.locationToOverwriteWithTransformation = NULL;
9844 X.transformationToOverwriteFirstStatementInInterval = NULL;
9845 X.blockOfStatementsToOutline = NULL;
9850SageInterface::DeferredTransformation::DeferredTransformation (
const DeferredTransformation& X)
9852 : deferredTransformationKind(X.deferredTransformationKind),
9853 statementToRemove(X.statementToRemove),
9854 statementToAdd(X.StatementToAdd),
9855 class_definition(X.class_definition),
9856 target_class_member(X.target_class_member),
9857 new_function_prototype(X.new_function_prototype),
9858 targetClasses(X.targetClasses),
9859 targetFriends(X.targetFriends)
9865 printf (
"In SageInterface::DeferredTransformation copy constructor called \n");
9875 printf (
"Inside of SageInterface::DeferredTransformation::operator= (const DeferredTransformation& X) \n");
9880 targetFriends = X.targetFriends;
9881 targetClasses = X.targetClasses;
9887 transformationLabel = X.transformationLabel;
9890 deferredTransformationKind = X.deferredTransformationKind;
9891 statementToRemove = X.statementToRemove;
9892 statementToAdd = X.statementToAdd;
9894 class_definition = X.class_definition;
9895 target_class_member = X.target_class_member;
9896 new_function_prototype = X.new_function_prototype;
9897 targetClasses = X.targetClasses;
9898 targetFriends = X.targetFriends;
9901 statementInterval = X.statementInterval;
9902 locationToOverwriteWithTransformation = X.locationToOverwriteWithTransformation;
9903 transformationToOverwriteFirstStatementInInterval = X.transformationToOverwriteFirstStatementInInterval;
9906 blockOfStatementsToOutline = X.blockOfStatementsToOutline;
9917std::string SageInterface::DeferredTransformation::outputDeferredTransformationKind(
const TransformationKind & kind)
9919 string returnValue =
"uninitialized";
9922 case e_error: returnValue =
"e_error";
break;
9923 case e_default: returnValue =
"e_default";
break;
9924 case e_outliner: returnValue =
"e_outliner";
break;
9925 case e_replaceStatement: returnValue =
"e_replaceStatement";
break;
9926 case e_removeStatement: returnValue =
"e_removeStatement";
break;
9927 case e_replaceDefiningFunctionDeclarationWithFunctionPrototype: returnValue =
"e_replaceDefiningFunctionDeclarationWithFunctionPrototype";
break;
9928 case e_last: returnValue =
"e_last";
break;
9931 printf (
"Error: SageInterface::DeferredTransformation::get_deferredTransformationKind_string(): default reached \n");
9939void SageInterface::DeferredTransformation::display ( std::string label )
const
9941 printf (
"SageInterface::DeferredTransformation::display(): label = %s \n",label.c_str());
9946 printf (
" --- transformationLabel = %s \n",transformationLabel.c_str());
9948 printf (
" --- deferredTransformationKind = %s \n",outputDeferredTransformationKind(deferredTransformationKind).c_str());
9949 if (statementToRemove != NULL)
9951 printf (
" --- statementToRemove = %p = %s name = %s \n",statementToRemove,statementToRemove->class_name().c_str(),
get_name(statementToRemove).c_str());
9955 printf (
" --- statementToRemove == NULL \n");
9958 if (statementToAdd != NULL)
9960 printf (
" --- statementToAdd = %p = %s name = %s \n",statementToAdd,statementToAdd->class_name().c_str(),
get_name(statementToAdd).c_str());
9964 printf (
" --- statementToAdd == NULL \n");
9967 if (class_definition != NULL)
9970 printf (
" --- class_definition = %p \n",class_definition);
9973 if (target_class_member != NULL)
9975 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());
9978 if (new_function_prototype != NULL)
9980 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());
9984 if (locationToOverwriteWithTransformation != NULL)
9988 printf (
" --- locationToOverwriteWithTransformation = %p \n",locationToOverwriteWithTransformation);
9992 if (transformationToOverwriteFirstStatementInInterval != NULL)
9996 printf (
" --- transformationToOverwriteFirstStatementInInterval = %p \n",transformationToOverwriteFirstStatementInInterval);
10000 if (blockOfStatementsToOutline != NULL)
10002 printf (
" --- blockOfStatementsToOutline = %p \n",blockOfStatementsToOutline);
10005 printf (
"targetClasses.size() = %zu \n",targetClasses.size());
10006 printf (
"targetFriends.size() = %zu \n",targetFriends.size());
10009 printf (
"statementInterval.size() = %zu \n",statementInterval.size());
10019#define REMOVE_STATEMENT_DEBUG 0
10024#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
10035 ASSERT_not_null(targetStmt);
10043 bool isRemovable = (parentStatement != NULL) ? LowLevelRewrite::isRemovableStatement(targetStmt) :
false;
10045#if REMOVE_STATEMENT_DEBUG || 0
10046 printf (
"In SageInterface::removeStatement(): parentStatement = %p = %s remove targetStatement = %p = %s (isRemovable = %s) \n",
10047 parentStatement,parentStatement->
class_name().c_str(),targetStmt,targetStmt->
class_name().c_str(),isRemovable ?
"true" :
"false");
10050 if (isRemovable ==
true)
10057 if (autoRelocatePreprocessingInfo ==
true)
10067 if (comments !=
nullptr && isSgBasicBlock(targetStmt) ==
nullptr )
10069 vector<int> captureList;
10070#if REMOVE_STATEMENT_DEBUG
10071 printf (
"Found attached comments (removing %p = %s): comments->size() = %" PRIuPTR
" \n",targetStmt,targetStmt->
class_name().c_str(),comments->size());
10077 int commentIndex = 0;
10078 AttachedPreprocessingInfoType::iterator i;
10079 for (i = comments->begin(); i != comments->end(); i++)
10081 ROSE_ASSERT ( (*i) != NULL );
10082#if REMOVE_STATEMENT_DEBUG
10083 printf (
" Attached Comment (relativePosition=%s): %s\n",
10084 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
10085 (*i)->getString().c_str());
10086 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
10087 (*i)->get_file_info()->display(
"comment/directive location debug");
10089 captureList.push_back(commentIndex);
10093#if REMOVE_STATEMENT_DEBUG
10094 printf (
"captureList.size() = %" PRIuPTR
" \n",captureList.size());
10097 if (captureList.empty() ==
false)
10102 bool surroundingStatementPreceedsTargetStatement =
false;
10105 if (surroundingStatement !=
nullptr)
10108#if REMOVE_STATEMENT_DEBUG
10109 printf (
"In removeStatement(): surroundingStatementPreceedsTargetStatement = %s \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false");
10110 printf (
" --- moving comments from targetStmt = %p = %s name = %s \n",targetStmt,targetStmt->
class_name().c_str(),
get_name(targetStmt).c_str());
10111 printf (
" --- moving comments to surroundingStatement = %p = %s name = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str(),
get_name(surroundingStatement).c_str());
10126 printf (
"Error: This is not supported within Microsoft Windows (I forget why). \n");
10148 printf (
"In SageInterface::resetInternalMapsForTargetStatement(SgStatement*): sourceStatement = %p = %s \n",sourceStatement,sourceStatement->
class_name().c_str());
10157 printf (
"In SageInterface::resetInternalMapsForTargetStatement(SgStatement*): sourceFile = %p \n",sourceFile);
10160 if (sourceFile != NULL)
10162 std::map<SgStatement*,MacroExpansion*> & macroExpansionMap = sourceFile->get_macroExpansionMap();
10164 if (macroExpansionMap.find(sourceStatement) != macroExpansionMap.end())
10166 MacroExpansion* macroExpansion = macroExpansionMap[sourceStatement];
10167 ROSE_ASSERT(macroExpansion != NULL);
10169 printf (
"In resetInternalMapsForTargetStatement(): macroExpansion = %p = %s \n",macroExpansion,macroExpansion->macro_name.c_str());
10171 if (macroExpansion->isTransformed ==
false)
10174 std::vector<SgStatement*> & associatedStatementVector = macroExpansion->associatedStatementVector;
10176 for (
size_t i = 0; i < associatedStatementVector.size(); i++)
10179 SgStatement* statement = associatedStatementVector[i];
10181 printf (
"Mark as transformation to be output: statement = %p = %s \n",statement,statement->
class_name().c_str());
10205 macroExpansion->isTransformed =
true;
10222#if REMOVE_STATEMENT_DEBUG || 0
10223 printf (
"In moveCommentsToNewStatement(): destinationStatementProceedsSourceStatement = %s \n",destinationStatementProceedsSourceStatement ?
"true" :
"false");
10224 printf (
" --- sourceStatement = %p = %s name = %s \n",sourceStatement,sourceStatement->
class_name().c_str(),
get_name(sourceStatement).c_str());
10225 printf (
" --- destinationStatement = %p = %s name = %s \n",destinationStatement,destinationStatement->
class_name().c_str(),
get_name(destinationStatement).c_str());
10233#if REMOVE_STATEMENT_DEBUG
10234 printf (
"Output the comments attached to sourceStatement: \n");
10236 printf (
"Output the comments attached to destinationStatement: \n");
10241 vector<int>::const_iterator j = indexList.begin();
10243 while (j != indexList.end())
10246 ROSE_ASSERT(destinationStatement->
get_file_info() != NULL);
10247#if REMOVE_STATEMENT_DEBUG || 0
10248 printf (
"Attaching comments to destinationStatement = %p = %s on file = %s line %d \n",
10249 destinationStatement,destinationStatement->
class_name().c_str(),
10250 destinationStatement->
get_file_info()->get_filenameString().c_str(),
10253 printf (
"(*comments)[*j]->getRelativePosition() = %s \n",PreprocessingInfo::relativePositionName((*comments)[*j]->getRelativePosition()).c_str());
10265 if (destinationStatementProceedsSourceStatement ==
true || isSgGlobal(destinationStatement) != NULL )
10271 auto commentPosition = (*comments)[*j]->getRelativePosition();
10272 if (commentPosition == PreprocessingInfo::before)
10275 (*comments)[*j]->setRelativePosition(PreprocessingInfo::after);
10277 else if (commentPosition == PreprocessingInfo::after ||
10278 commentPosition == PreprocessingInfo::end_of)
10284 ROSE_ASSERT(
false &&
"Comment relative position neither, before, after, nor end_of");
10296 (*comments)[*j]->setRelativePosition(PreprocessingInfo::inside);
10307 if ((*comments)[*j]->getRelativePosition() == PreprocessingInfo::before)
10315 ASSERT_require((*comments)[*j]->getRelativePosition() == PreprocessingInfo::after||
10316 (*comments)[*j]->getRelativePosition() == PreprocessingInfo::end_of);
10317 (*comments)[*j]->setRelativePosition(PreprocessingInfo::before);
10326 if (targetInfoList==NULL)
10335 if( prevTargetAnchorComment==NULL)
10348 prevTargetAnchorComment = (*comments)[*j];
10353#if REMOVE_STATEMENT_DEBUG
10354 printf (
"Marking entry from comments list as NULL on sourceStatement = %p = %s \n",sourceStatement,sourceStatement->
class_name().c_str());
10356 (*comments)[*j] =
nullptr;
10363 for (
size_t n = 0; n < indexList.size(); n++)
10365#if REMOVE_STATEMENT_DEBUG || 0
10366 printf (
"Erase entry from comments list on comments->size() %" PRIuPTR
" \n",comments->size());
10368 bool modifiedList =
false;
10369 AttachedPreprocessingInfoType::iterator k = comments->begin();
10370 while (k != comments->end() && modifiedList ==
false)
10375 k = comments->erase(k);
10376 modifiedList =
true;
10398 ROSE_ASSERT(targetStmt != NULL);
10403#if REMOVE_STATEMENT_DEBUG || 0
10404 printf (
"TOP of findSurroundingStatementFromSameFile(): surroundingStatementPreceedsTargetStatement = %s \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false");
10407 std::set<SgStatement*> previousVisitedStatementSet;
10412 surroundingStatementPreceedsTargetStatement =
true;
10414#if REMOVE_STATEMENT_DEBUG
10415 printf (
" targetStmt->get_file_info()->get_file_id() = %d \n",targetStmt->
get_file_info()->get_file_id());
10417#if REMOVE_STATEMENT_DEBUG
10418 printf (
"Before loop: surroundingStatement = %p = %s name = %s surroundingStatement_fileId = %d \n",surroundingStatement,
10421 bool returningNullSurroundingStatement =
false;
10433#if REMOVE_STATEMENT_DEBUG
10434 printf (
"In loop: after getPreviousStatement(): surroundingStatement = %p = %s name = %s \n",surroundingStatement,
10438 if (surroundingStatement == NULL)
10441#if REMOVE_STATEMENT_DEBUG
10442 printf (
" surroundingStatement_fileId set to Sg_File_Info::BAD_FILE_ID \n");
10447 surroundingStatement_fileId = surroundingStatement->
get_file_info()->get_file_id();
10448#if REMOVE_STATEMENT_DEBUG
10449 printf (
" surroundingStatement = %p = %s surroundingStatement->get_file_info()->get_file_id() = %d \n",
10450 surroundingStatement,surroundingStatement->
class_name().c_str(),surroundingStatement->
get_file_info()->get_file_id());
10454#if REMOVE_STATEMENT_DEBUG
10455 if (surroundingStatement != NULL)
10457 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",
10458 surroundingStatement,surroundingStatement->
class_name().c_str(),
10459 surroundingStatement->
get_file_info()->get_filenameString().c_str(),
10465 printf (
"surroundingStatement == NULL \n");
10470 if (previousVisitedStatementSet.find(surroundingStatement) != previousVisitedStatementSet.end())
10472 printf (
"This statement has been previously visited: surroundingStatement = %p = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str());
10474 printf (
"ERROR: SageInterface::findSurroundingStatementFromSameFile(): cannot located surrounding statement from same file (return NULL) \n");
10476 surroundingStatement = NULL;
10482 previousVisitedStatementSet.insert(surroundingStatement);
10486 if (surroundingStatement == NULL || isSgGlobal(surroundingStatement) != NULL)
10489#if REMOVE_STATEMENT_DEBUG
10490 printf (
"We just ran off the start (top) of the file... targetStmt = %p = %s \n",targetStmt,targetStmt->
class_name().c_str());
10496 surroundingStatementPreceedsTargetStatement =
false;
10499 surroundingStatement = targetStmt;
10500 SgStatement* previousStatement = surroundingStatement;
10504 std::set<SgStatement*> forwardVisitedStatementSet;
10507 while ( (surroundingStatement != NULL) && (surroundingStatement_fileId != targetStmt->
get_file_info()->get_file_id()) )
10510 if (forwardVisitedStatementSet.find(surroundingStatement) != forwardVisitedStatementSet.end())
10512 printf (
"This statement has been previously visited: surroundingStatement = %p = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str());
10514 printf (
"ERROR: SageInterface::findSurroundingStatementFromSameFile(): cannot located surrounding statement from same file (return NULL) \n");
10516 surroundingStatement = NULL;
10522 forwardVisitedStatementSet.insert(surroundingStatement);
10525 previousStatement = surroundingStatement;
10528 if (surroundingStatement == NULL)
10531#if REMOVE_STATEMENT_DEBUG
10532 printf (
"We just ran off the end (bottom) of the file... \n");
10537 returningNullSurroundingStatement =
true;
10541 surroundingStatement_fileId = surroundingStatement->
get_file_info()->get_file_id();
10542#if REMOVE_STATEMENT_DEBUG
10543 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",
10544 surroundingStatement,surroundingStatement->
class_name().c_str(),
10545 surroundingStatement->
get_file_info()->get_filenameString().c_str(),
10552 if (surroundingStatement == NULL)
10554#if REMOVE_STATEMENT_DEBUG
10555 printf (
"Resetting the surroundingStatement to the previousStatement = %p = %s \n",previousStatement,previousStatement->
class_name().c_str());
10557 surroundingStatement = previousStatement;
10560 if (surroundingStatement == targetStmt)
10564#if REMOVE_STATEMENT_DEBUG
10565 printf (
"Setting the surroundingStatement to be global scope \n");
10567 surroundingStatement = TransformationSupport::getGlobalScope(targetStmt);
10573 ROSE_ASSERT(surroundingStatement != NULL);
10577 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());
10578 surroundingStatement = NULL;
10581#if REMOVE_STATEMENT_DEBUG
10582 printf (
"BOTTOM of findSurroundingStatementFromSameFile(): surroundingStatementPreceedsTargetStatement = %s surroundingStatement = %p \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false",surroundingStatement);
10583 if (surroundingStatement != NULL)
10585 printf (
"surroundingStatement = %p = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str());
10591 return surroundingStatement;
10601 virtual void visit(
SgNode* n) {
10605 Visitor().
traverse(root, postorder);
10615 ROSE_ASSERT(oldStmt);
10616 ROSE_ASSERT(newStmt);
10618 if (oldStmt == newStmt)
return;
10629 ROSE_ASSERT (f_do->get_body() == oldStmt);
10630 if (!isSgBasicBlock(newStmt))
10632 f_do->set_body(isSgBasicBlock(newStmt));
10649 printf (
"In SageInterface::replaceStatement(): physical_file_id = %d \n",physical_file_id);
10660 if (movePreprocessingInfoValue)
10668 printf (
"In SageInterface::replaceStatement(): calling moveUpPreprocessingInfo() changed to movePreprocessingInfo() \n");
10680 bool usePrepend =
true;
10682 movePreprocessingInfo ( oldStmt, newStmt, PreprocessingInfo::undef, PreprocessingInfo::undef, usePrepend );
10703 printf (
"In SageInterface::moveDeclarationToAssociatedNamespace(): declarationStatement = %p = %s \n",declarationStatement,declarationStatement->
class_name().c_str());
10704 printf (
" --- previousDeclarationStatement = %p = %s \n",previousDeclarationStatement,previousDeclarationStatement != NULL ? previousDeclarationStatement->
class_name().c_str() :
"null");
10705 printf (
" --- nextDeclarationStatement = %p \n",nextDeclarationStatement);
10706 printf (
" --- nextDeclarationStatement = %p = %s \n",nextDeclarationStatement, nextDeclarationStatement != NULL ? nextDeclarationStatement->
class_name().c_str() :
"null");
10710 if (previousDeclarationStatement != NULL)
10716 printf (
"There is no previous statement so there is no namespace to close off! \n");
10719 printf (
"Exiting as a test! \n");
10724 if (nextDeclarationStatement != NULL)
10731 printf (
"There is no next statement so there is no namespace to reopen! \n");
10735 printf (
"Exiting as a test! \n");
10740 if (previousDeclarationStatement != NULL && nextDeclarationStatement != NULL)
10744 printf (
"Identified the most common case... \n");
10749 printf (
"declarationScope = %p = %s \n",declarationScope,declarationScope->
class_name().c_str());
10753 printf (
"Exiting as a test! \n");
10759 if (previousDeclarationStatement != NULL && nextDeclarationStatement == NULL)
10763 printf (
"Found 2nd most common case: previousDeclarationStatement != NULL && nextDeclarationStatement == NULL \n");
10767 printf (
"Exiting as a test! \n");
10773 if (previousDeclarationStatement == NULL && nextDeclarationStatement == NULL)
10775 printf (
"This case should require no special handling, unless we are still in the wrong namespace \n");
10778 printf (
"Exiting as a test! \n");
10783 printf (
"This case should have been caught above! \n");
10786 printf (
"Exiting as a test! \n");
10793 if (declarationParent == NULL)
10796 printf (
"declarationStatement->get_parent() = %p = %s \n",declarationStatement->
get_parent(), (declarationStatement->
get_parent() != NULL) ? declarationStatement->
get_parent()->
class_name().c_str() :
"null");
10802 if (declarationParent != NULL)
10805 ROSE_ASSERT(declarationScope != NULL);
10808 if (namespaceDefinition != NULL)
10811 ROSE_ASSERT(namespaceDeclaration != NULL);
10813 printf (
"The declaration has been identified to be associuated with a valid namespace = %p = %s \n",namespaceDeclaration,namespaceDeclaration->
get_name().str());
10814 printf (
" --- declarationParent = %p = %s \n",declarationParent,declarationParent->
class_name().c_str());
10815 printf (
" --- Move declaration from scope = %p = %s to namespace = %p = %s \n",declarationParent,declarationParent->
class_name().c_str(),namespaceDeclaration,namespaceDeclaration->
get_name().str());
10818 printf (
"Exiting as a test! \n");
10825 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());
10832 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");
10844 if (isSgTemplateInstantiationDefn(node) != NULL)
10847 printf (
"Note: In SageInterface::isTemplateInstantiationNode(): skipping SgTemplateInstantiationDefn \n");
10851 return isSgTemplateInstantiationDecl(node)
10854 || isSgTemplateInstantiationDefn(node)
10855 || isSgTemplateInstantiationFunctionDecl(node)
10856 || isSgTemplateInstantiationMemberFunctionDecl(node)
10857 || isSgTemplateInstantiationTypedefDeclaration(node)
10858 || isSgTemplateInstantiationDirectiveStatement(node)
10867SageInterface::isTemplateDeclarationNode(
SgNode* node)
10870 if (isSgTemplateDefinition(node) != NULL)
10873 printf (
"Note: In SageInterface::isTemplateDeclarationNode(): skipping SgTemplateDefinition \n");
10877 return isSgTemplateInstantiationDecl(node)
10880 || isSgTemplateInstantiationDefn(node)
10881 || isSgTemplateInstantiationFunctionDecl(node)
10882 || isSgTemplateInstantiationMemberFunctionDecl(node)
10883 || isSgTemplateInstantiationTypedefDeclaration(node)
10884 || isSgTemplateInstantiationDirectiveStatement(node)
10897 std::vector<SgDeclarationStatement*> templateInstantiationVector;
10909 if (declaration != NULL)
10911 templateInstantiationVector.push_back(declaration);
10920 std::cerr <<
"This feature for now is available with autotools only!" << std::endl;
10924 std::vector<SgDeclarationStatement*>::iterator j = templateInstantiationVector.begin();
10925 while (j != templateInstantiationVector.end())
10939 SgExpression * pattern_exp = isSgExpression(new_pattern);
10940 ROSE_ASSERT (anchor_exp != NULL);
10941 ROSE_ASSERT (pattern_exp != NULL);
10944 Rose_STL_Container<SgNode*> opaque_exp_list = NodeQuery::querySubTree(pattern_exp,V_SgExpression);
10945 for (
size_t i = 0; i<opaque_exp_list.size(); i++)
10947 SgExpression* opaque_exp = isSgExpression(opaque_exp_list[i]);
10948 ROSE_ASSERT (opaque_exp != NULL);
10949 if (opaque_exp->
variantT() == V_SgVariantExpression)
10958 return new_pattern;
10965 static int counter = 0;
10968 bool collision =
false;
10971 name =
"__" + baseName + boost::lexical_cast<string > (counter++) +
"__";
10977 collision = (nameSymbol != NULL);
10980 Rose_STL_Container<SgNode*> childScopes = NodeQuery::querySubTree(scope, V_SgScopeStatement);
10982 BOOST_FOREACH(
SgNode* childScope, childScopes)
10988 nameSymbol = childScopeStatement->lookup_symbol(
SgName(name),NULL,NULL);
10990 collision = collision || (nameSymbol != NULL);
10992 }
while (collision);
11002 SgType* variableType = expressionType;
11009 SgType* expressionBaseType = expressionType->
stripType(SgType::STRIP_TYPEDEF_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE);
11014 if (
SgArrayType* arrayType=isSgArrayType(expressionType)) {
11015 if(
SgArrayType* strippedArrayType = isSgArrayType(arrayType->stripType(SgType::STRIP_TYPEDEF_TYPE))) {
11016 SgType* strippedArrayBaseType = strippedArrayType->get_base_type();
11022 if (isSgPointerDerefExp(expression))
11030 ROSE_ASSERT(tempVarInitExpression != NULL);
11041 if (initializeInDeclaration)
11048 ROSE_ASSERT(tempVarDeclaration != NULL);
11051 if (reEvaluate != NULL)
11065 return std::make_pair(tempVarDeclaration, varRefExpression);
11078 SgType* variableType = expressionType;
11081 if (
SgArrayType* arrayType=isSgArrayType(expressionType))
11083 if(
SgArrayType* strippedArrayType = isSgArrayType(arrayType->stripType(SgType::STRIP_TYPEDEF_TYPE))) {
11084 SgType* strippedArrayBaseType = strippedArrayType->get_base_type();
11098 ROSE_ASSERT(tempVarDeclaration != NULL);
11102 return std::make_pair(tempVarDeclaration, varRefExpression);
11109 replaceExpressionInSgExpressionPtrList(
SgExpression* oldExp,
SgExpression* newExp, SgExpressionPtrList& lst,
bool replAll =
false)
11111 SgExpressionPtrList::iterator lim = lst.end();
11112 SgExpressionPtrList::iterator pos = lst.begin();
11117 pos = std::find(pos, lim, oldExp);
11119 if (pos != lim) { *pos = newExp; ++pos; chg =
true; }
11120 }
while (replAll && (pos != lim));
11134 ROSE_ASSERT(oldExp);
11135 ROSE_ASSERT(newExp);
11136 if (oldExp==newExp)
return;
11138 if (isSgVarRefExp(newExp))
11142 ROSE_ASSERT(parent!=NULL);
11148 if (isSgExprStatement(parent)) {
11149 isSgExprStatement(parent)->set_expression(newExp);
11150 }
else if (isSgForStatement(parent)) {
11151 ROSE_ASSERT (isSgForStatement(parent)->get_increment() == oldExp);
11152 isSgForStatement(parent)->set_increment(newExp);
11155 if(matlabFor->get_index() == oldExp)
11156 matlabFor->set_index(newExp);
11157 else if(matlabFor->get_range() == oldExp)
11158 matlabFor->set_range(newExp);
11160 ROSE_ASSERT(!
"sub-expression not found");
11162 if(jovFor->get_initialization() == oldExp)
11163 jovFor->set_initialization(newExp);
11164 else if(jovFor->get_while_expression() == oldExp)
11165 jovFor->set_while_expression(newExp);
11166 else if(jovFor->get_by_or_then_expression() == oldExp)
11167 jovFor->set_by_or_then_expression(newExp);
11169 ROSE_ASSERT(!
"sub-expression not found");
11170 }
else if (
SgRangeExp* rngexp = isSgRangeExp(parent)) {
11171 if (rngexp->get_start() == oldExp)
11172 rngexp->set_start(newExp);
11173 else if (rngexp->get_end() == oldExp)
11174 rngexp->set_end(newExp);
11175 else if (rngexp->get_stride() == oldExp)
11176 rngexp->set_stride(newExp);
11178 ROSE_ASSERT(!
"sub-expression not found");
11179 }
else if (isSgReturnStmt(parent)) {
11180 isSgReturnStmt(parent)->set_expression(newExp);
11181 }
else if (isSgBinaryOp(parent)!=NULL) {
11182 if (oldExp==isSgBinaryOp(parent)->get_lhs_operand()) {
11184 }
else if (oldExp==isSgBinaryOp(parent)->get_rhs_operand()) {
11189 }
else if (isSgUnaryOp(parent)!=NULL){
11190 if (oldExp==isSgUnaryOp(parent)->get_operand_i())
11194 }
else if (isSgConditionalExp(parent) != NULL) {
11204 }
else if (isSgExprListExp(parent) != NULL) {
11205 SgExpressionPtrList& explist = isSgExprListExp(parent)->get_expressions();
11206 for (Rose_STL_Container<SgExpression*>::iterator i=explist.begin();i!=explist.end();i++) {
11207 if (isSgExpression(*i)==oldExp) {
11213 }
else if (isSgValueExp(parent)) {
11218 ROSE_ASSERT(oldExp == actexp->get_expression());
11219 actexp->set_expression(newExp);
11221 if (oldExp == attrexp->get_object()) {
11222 attrexp->set_object(newExp);
11223 }
else if (oldExp == attrexp->get_args()) {
11225 ASSERT_not_null(newLst);
11227 attrexp->set_args(newLst);
11232 }
else if ((parentExp=isSgExpression(parent)) != NULL) {
11235 ROSE_ASSERT (worked);
11236 }
else if (isSgInitializedName(parent)) {
11238 if (oldExp == initializedNameParent->get_initializer()) {
11240 ROSE_ASSERT(isSgInitializer(newExp));
11241 initializedNameParent->set_initializer(isSgInitializer(newExp));
11246 }
else if (isSgCaseOptionStmt(parent)) {
11248 if (oldExp == case_stmt->
get_key()) {
11250 }
else if(oldExp == case_stmt->get_key_range_end()) {
11251 case_stmt->set_key_range_end(newExp);
11255 }
else if (isSgProcessControlStatement(parent)) {
11257 if (oldExp == ctrl_stmt->get_quiet()) {
11258 ctrl_stmt->set_quiet(newExp);
11259 }
else if (oldExp == ctrl_stmt->get_code()) {
11260 ctrl_stmt->set_code(newExp);
11264 }
else if (isSgFortranDo(parent)) {
11266 if (oldExp == fortranDo->get_initialization()) {
11267 fortranDo->set_initialization(newExp);
11268 }
else if(oldExp == fortranDo->get_bound()) {
11269 fortranDo->set_bound(newExp);
11270 }
else if (oldExp == fortranDo->get_increment()) {
11271 fortranDo->set_increment(newExp);
11277 ROSE_ASSERT(oldExp == stm->get_condition());
11278 stm->set_condition(newExp);
11281 ROSE_ASSERT(oldExp == ptype->get_modexpr());
11282 ptype->set_modexpr(newExp);
11285 ROSE_ASSERT(oldExp == stm->get_time());
11286 stm->set_time(newExp);
11288 ROSE_ASSERT(oldExp == clause->get_size());
11289 clause->set_size(newExp);
11291 ROSE_ASSERT(oldExp == dcl->get_renamed());
11292 dcl->set_renamed(newExp);
11294 ROSE_ASSERT(oldExp == dcl->get_entryBarrier());
11295 dcl->set_entryBarrier(newExp);
11297 ROSE_ASSERT(oldExp == stm->get_guard());
11298 stm->set_guard(newExp);
11300 ROSE_ASSERT(oldExp == delc->get_delta());
11301 delc->set_delta(newExp);
11303 ROSE_ASSERT(oldExp == digc->get_digits());
11304 digc->set_digits(newExp);
11306 replaceExpressionInSgExpressionPtrList(oldExp, newExp, disc->get_discriminants());
11308 ROSE_ASSERT(oldExp == rngc->get_range());
11309 rngc->set_range(newExp);
11311 replaceExpressionInSgExpressionPtrList(oldExp, newExp, idxc->get_indexRanges());
11313 ROSE_ASSERT(oldExp == vtdcl->get_discriminant());
11314 vtdcl->set_discriminant(newExp);
11316 ROSE_ASSERT(oldExp == clause->get_alignment());
11317 clause->set_alignment(newExp);
11320 if (newLst && (oldExp == vtwhen->get_choices()))
11321 vtwhen->set_choices(newLst);
11325 if (oldExp == clause->get_offset())
11326 clause->set_offset(newExp);
11327 else if (oldExp == clause->get_range() && isSgRangeExp(newExp))
11328 clause->set_range(isSgRangeExp(newExp));
11329 else if (oldExp == clause->get_component() && isSgVarRefExp(newExp))
11330 clause->set_component(isSgVarRefExp(newExp));
11334 if (oldExp == rendcl->get_renamed_function())
11335 rendcl->set_renamed_function(newExp);
11339 cerr<<
"SageInterface::replaceExpression(). Unhandled parent expression type of SageIII enum value: " <<parent->
class_name()<<endl;
11354 return Rose::getNextStatement(currentStmt);
11363 return isSgIntVal(e) && isSgIntVal(e)->get_value() == value;
11368 ROSE_ASSERT(func1&& func2);
11369 bool result =
false;
11370 if (func1 == func2)
11376 if (func1->get_name() == func2->get_name())
11381 if (func1->get_qualified_name().getString() +
11382 func1->get_mangled_name().getString() ==
11383 func2->get_qualified_name().getString() +
11384 func2->get_mangled_name().getString()
11390 if (func1->get_name() == func2->get_name())
11395 cout<<
"Error: SageInterface::isSameFunction(): unhandled language"<<endl;
11406 bool result =
false;
11407 ROSE_ASSERT(stmt != NULL);
11409 ROSE_ASSERT(p_scope != NULL);
11414 if (stmtlist[stmtlist.size()-1] == stmt)
11420 if (stmtlist[stmtlist.size()-1] == stmt)
11425 if (stmtlist[stmtlist.size()-1] == stmt)
11437 virtual void visit(
SgNode* n) {
11439 if (valueExp != NULL) {
11440 valueExp->set_originalExpressionTree(NULL);
11444 if (cast_exp != NULL) {
11445 cast_exp->set_originalExpressionTree(NULL);
11450 Visitor().traverse(top, preorder);
11455 while (s && !isSgSwitchStatement(s)) {
11459 return isSgSwitchStatement(s);
11464 while (s && !isSgOmpClauseBodyStatement(s)) {
11470 return isSgOmpClauseBodyStatement(s);
11476 for (; s; s = isSgStatement(s->
get_parent())) {
11481 case V_SgDoWhileStmt: {
11482 if (label.empty()) {
11487 case V_SgForStatement: {
11488 if (label.empty()) {
11493 case V_SgFortranDo:
11494 case V_SgFortranNonblockedDo: {
11495 if (label.empty() ||
11496 label == isSgFortranDo(sc)->get_string_label()) {
11501 case V_SgWhileStmt: {
11502 if (label.empty() ||
11503 label == isSgWhileStmt(sc)->get_string_label()) {
11508 case V_SgSwitchStatement: {
11509 if (stopOnSwitches)
return sc;
11512 case V_SgJavaForEachStatement: {
11513 if (label.empty()) {
11518 case V_SgJavaLabelStatement: {
11519 if (label.empty() ||
11520 label == isSgJavaLabelStatement(sc)->get_label().getString()) {
11536 virtual void visit(
SgNode* n) {
11537 if (isSgBasicBlock(n)) {
11539 bool changes =
true;
11542 for (SgStatementPtrList::iterator i = bb->
get_statements().begin();
11544 if (isSgGotoStatement(*i)) {
11546 SgStatementPtrList::iterator inext = i;
11550 if (!isSgLabelStatement(*inext))
11565 RemoveJumpsToNextStatementVisitor().traverse(top, postorder);
11574 ROSE_ASSERT (parent);
11578 ROSE_ASSERT (bb || fis);
11579 SgStatementPtrList& siblings =
11581 SgStatementPtrList::iterator j =
11582 std::find(siblings.begin(), siblings.end(), stmt);
11583 ROSE_ASSERT (j != siblings.end());
11596 SgLabelStatementPtrSet& used;
11597 SgLabelStatementPtrSet& all;
11600 FindUsedAndAllLabelsVisitor(SgLabelStatementPtrSet& used,
11601 SgLabelStatementPtrSet& all):
11602 used(used), all(all) {}
11604 virtual void visit(
SgNode* n) {
11605 if (isSgGotoStatement(n)) {
11606 used.insert(isSgGotoStatement(n)->get_label());
11608 if (isSgLabelStatement(n)) {
11609 all.insert(isSgLabelStatement(n));
11614 SgLabelStatementPtrSet used;
11615 SgLabelStatementPtrSet unused;
11616 FindUsedAndAllLabelsVisitor(used, unused).traverse(top, preorder);
11618 for (SgLabelStatementPtrSet::iterator i = used.begin();
11619 i != used.end(); ++i) {
11620 assert (unused.find(*i) != unused.end());
11633 for (SgLabelStatementPtrSet::iterator i = unused.begin();
11634 i != unused.end(); ++i) {
11642 l_stmt->set_statement(NULL);
11652 if (isSgWhileStmt(loopStmt))
return isSgWhileStmt(loopStmt)->
get_body();
11653 if (isSgForStatement(loopStmt))
return isSgForStatement(loopStmt)->
get_loop_body();
11654 if (isSgDoWhileStmt(loopStmt))
return isSgDoWhileStmt(loopStmt)->
get_body();
11656 ROSE_ASSERT (!
"Bad loop kind");
11661 if (isSgWhileStmt(loopStmt)) {
11662 isSgWhileStmt(loopStmt)->
set_body(body);
11663 }
else if (isSgForStatement(loopStmt)) {
11665 }
else if (isSgDoWhileStmt(loopStmt)) {
11666 isSgDoWhileStmt(loopStmt)->
set_body(body);
11668 ROSE_ASSERT (!
"Bad loop kind");
11674 if (isSgWhileStmt(loopStmt))
return isSgWhileStmt(loopStmt)->
get_condition();
11675 if (isSgForStatement(loopStmt))
return isSgForStatement(loopStmt)->get_test();
11676 if (isSgDoWhileStmt(loopStmt))
return isSgDoWhileStmt(loopStmt)->
get_condition();
11678 ROSE_ASSERT (!
"Bad loop kind");
11683 if (isSgWhileStmt(loopStmt)) {
11685 }
else if (isSgForStatement(loopStmt)) {
11686 isSgForStatement(loopStmt)->set_test(cond);
11687 }
else if (isSgDoWhileStmt(loopStmt)) {
11690 ROSE_ASSERT (!
"Bad loop kind");
11699 SgCastExp* cast_exp = isSgCastExp(exp);
11700 if (cast_exp != NULL)
11703 assert(operand != 0);
11704 return SkipCasting(operand);
11713 ROSE_ASSERT(loop!=NULL);
11715 SgStatementPtrList &init = loop ->get_init_stmt();
11716 if (init.size() !=1)
11727 ROSE_ASSERT(ivarname != NULL);
11729 if (isSgAssignInitializer(initor))
11731 lbast = isSgAssignInitializer(initor)->
get_operand();
11746 ROSE_ASSERT(funcDef!=NULL);
11748 ROSE_ASSERT(funcBody!=NULL);
11750 std::ostringstream os;
11751 os<<ivarname->get_name().getString();
11756 if (visibleSym != NULL)
11767 Rose_STL_Container<SgNode*> varRefs = NodeQuery::querySubTree(loop,V_SgVarRefExp);
11768 for (Rose_STL_Container<SgNode *>::iterator i = varRefs.begin(); i != varRefs.end(); i++)
11771 if (vRef->get_symbol()==osymbol)
11772 vRef->set_symbol(nsymbol);
11777 init.push_back(ninit);
11784 trans_records.forLoopInitNormalizationTable[loop] =
true;
11785 trans_records.forLoopInitNormalizationRecord[loop] = make_pair (decl, ndecl) ;
11798 ROSE_ASSERT (loop != NULL);
11800 if (!trans_records.forLoopInitNormalizationTable[loop])
11805 ROSE_ASSERT (decl!= NULL);
11806 ROSE_ASSERT (ndecl!= NULL);
11810 SgStatementPtrList &init = loop ->get_init_stmt();
11811 ROSE_ASSERT(init.size() ==1);
11816 ROSE_ASSERT (exp_stmt != NULL);
11817 SgAssignOp* assign_op = isSgAssignOp(exp_stmt->get_expression());
11818 ROSE_ASSERT (assign_op != NULL);
11825 init.push_back(decl);
11836 Rose_STL_Container<SgNode*> varRefs = NodeQuery::querySubTree(loop,V_SgVarRefExp);
11837 for (Rose_STL_Container<SgNode *>::iterator i = varRefs.begin(); i != varRefs.end(); i++)
11840 if (vRef->get_symbol()==osymbol)
11841 vRef->set_symbol(nsymbol);
11845 trans_records.forLoopInitNormalizationTable[loop] =
false;
11851 ROSE_ASSERT(loop != NULL);
11858 if (test_stmt!=NULL)
11860 if (isSgNullStatement(test_stmt))
11866 if (isSgBinaryOp(test))
11870 ROSE_ASSERT(testlhs && testrhs);
11875 SgVarRefExp* testlhs_var = isSgVarRefExp(SkipCasting(testlhs));
11876 if (testlhs_var == NULL )
11879 if (var_symbol==NULL)
11883 case V_SgLessThanOp:
11888 case V_SgGreaterThanOp:
11892 case V_SgLessOrEqualOp:
11893 case V_SgGreaterOrEqualOp:
11894 case V_SgNotEqualOp:
11903 ROSE_ASSERT(loop != NULL);
11907 if (isSgBinaryOp(test))
11911 ROSE_ASSERT(testlhs && testrhs);
11916 SgVarRefExp* testlhs_var = isSgVarRefExp(SkipCasting(testlhs));
11917 if (testlhs_var == NULL )
11920 if (var_symbol==NULL)
11926 ROSE_ASSERT(incr != NULL);
11928 case V_SgPlusPlusOp:
11931 SgVarRefExp* incr_var = isSgVarRefExp(SkipCasting(isSgPlusPlusOp(incr)->get_operand()));
11932 if (incr_var == NULL)
return false;
11933 if ( incr_var->get_symbol() != var_symbol)
11939 case V_SgMinusMinusOp:
11942 SgVarRefExp* incr_var = isSgVarRefExp(SkipCasting(isSgMinusMinusOp(incr)->get_operand()));
11943 if (incr_var == NULL)
return false;
11944 if ( incr_var->get_symbol() != var_symbol)
11950 case V_SgMinusAssignOp:
11952 SgVarRefExp* incr_var = isSgVarRefExp(SkipCasting(isSgMinusAssignOp(incr)->get_lhs_operand()));
11954 ROSE_ASSERT (rhs != NULL);
11955 if (incr_var == NULL)
return false;
11956 if ( incr_var->get_symbol() != var_symbol)
11963 case V_SgPlusAssignOp:
12018 bool changed =
false;
12020 if (!switchStmt)
return changed;
12024 if (!bodyBlock)
return changed;
12028 std::vector<SgStatement*> stmts(stmtList.begin(), stmtList.end());
12029 int n =
static_cast<int>(stmts.size());
12033 for (
int i = 0; i < n; ) {
12038 auto processLabel = [&](
SgStatement* labelStmt) {
12042 std::vector<SgStatement*> toWrap;
12044 while (j < n && !isSgCaseOptionStmt(stmts[j]) && !isSgDefaultOptionStmt(stmts[j])) {
12045 toWrap.push_back(stmts[j]);
12052 if (toWrap.size() == 1
12053 && isSgBasicBlock(toWrap[0])
12054 && ((isSgCaseOptionStmt(labelStmt) && !isSgBasicBlock(isSgCaseOptionStmt(labelStmt)->get_body()))
12055 || (isSgDefaultOptionStmt(labelStmt) && !isSgBasicBlock(isSgDefaultOptionStmt(labelStmt)->get_body()))))
12061 if (
auto c = isSgCaseOptionStmt(labelStmt)) {
12062 c->set_body(moved);
12063 }
else if (
auto d = isSgDefaultOptionStmt(labelStmt)) {
12064 d->set_body(moved);
12070 else if (!toWrap.empty()) {
12085 if (
auto caseLabel = isSgCaseOptionStmt(labelStmt)) {
12086 caseLabel->set_body(newBlock);
12087 }
else if (
auto defaultLabel = isSgDefaultOptionStmt(labelStmt)) {
12088 defaultLabel->set_body(newBlock);
12092 for (
auto* w: toWrap) {
12105 if (
auto caseLabel = isSgCaseOptionStmt(curr)) {
12106 i = processLabel(caseLabel);
12107 }
else if (
auto defaultLabel = isSgDefaultOptionStmt(curr)) {
12108 i = processLabel(defaultLabel);
12122 ROSE_ASSERT(loop != NULL);
12140 ROSE_ASSERT(body!=NULL);
12158 ROSE_ASSERT (loop != NULL);
12160 if (isSgNullExpression(e_3))
12163 loop->set_increment(iv);
12178 ROSE_ASSERT(func!=NULL);
12179 AstInterfaceImpl faImpl(func->get_definition()->
get_body());
12180 AstInterface fa(&faImpl);
12181 ArrayAnnotation* annot = ArrayAnnotation::get_inst();
12182 ArrayInterface array_interface (*annot);
12183 array_interface.initialize(fa, AstNodePtrImpl(func->get_definition()));
12184 array_interface.observe(fa);
12185 LoopTransformInterface :: set_astInterface(fa);
12186 LoopTransformInterface :: set_arrayInterface(&array_interface);
12190 AstNodePtr result = AstNodePtrImpl(loop->
get_parent()) ;
12192 LoopUnrolling lu(unrolling_factor);
12195 result = lu(lpTrans, result);
12239#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
12241 if (unrolling_factor <= 1)
12262 cerr<<
"Error in SageInterface::loopUnrolling(): target loop is not canonical."<<endl;
12266 ROSE_ASSERT(ivar&& lb && ub && step);
12267 ROSE_ASSERT(isSgBasicBlock(orig_body));
12270 bool needFringe =
true;
12271 SgForStatement* fringe_loop = deepCopy<SgForStatement>(target_loop);
12289 ROSE_ASSERT(scope != NULL);
12293 attachComment(fringe_decl,
"iter_count = (ub-lb+1)%step ==0?(ub-lb+1)/step: (ub-lb+1)/step+1;");
12294 attachComment(fringe_decl,
"fringe = iter_count%unroll_factor==0 ? 0:unroll_factor*step");
12301 ConstantFolding::constantFoldingOptimization(fringe_decl,
false);
12303 ROSE_ASSERT(ivarname != NULL);
12307 if (isSgIntVal(init1->get_operand_i()))
12308 if (isSgIntVal(init1->get_operand_i())->get_value() == 0)
12309 needFringe =
false;
12313 ROSE_ASSERT(ub_bin_op);
12323 ROSE_ASSERT(step_bin_op != NULL);
12326 bool isPlus =
false;
12327 if (isSgPlusAssignOp(step_bin_op))
12329 else if (isSgMinusAssignOp(step_bin_op))
12333 cerr<<
"Error in SageInterface::loopUnrolling(): illegal incremental exp of a canonical loop"<<endl;
12339 for (
size_t i =1; i<unrolling_factor; i++)
12343 std::vector<SgVarRefExp*> refs = querySubTree<SgVarRefExp> (body, V_SgVarRefExp);
12344 for (std::vector<SgVarRefExp*>::iterator iter = refs.begin(); iter !=refs.end(); iter++)
12373 ConstantFolding::constantFoldingOptimization(scope,
false);
12385static size_t myfactorial (
size_t n)
12388 for (
size_t i=2; i<=n; i++)
12399std::vector<size_t> getPermutationOrder(
size_t n,
size_t lexicoOrder)
12401 size_t k = lexicoOrder;
12402 std::vector<size_t> s(n);
12404 for (
size_t i=0; i<n; i++)
12408 size_t factorial = myfactorial(n-1);
12410 if (k/n>=factorial)
12412 printf(
"Error: in getPermutationOrder(), lexicoOrder is larger than n!-1\n");
12428 for (
size_t j=0; j<n-1; j++)
12432 int tempj = (k/factorial) % (n - j);
12435 int temps = s[j+tempj];
12438 for (
size_t i=j+tempj; i>j; i--)
12445 factorial = factorial /(n-(j+1));
12448 for (
size_t i = 0; i<n; i++)
12480 ROSE_ASSERT(loopNest != NULL);
12481 ROSE_ASSERT(targetLevel >0);
12488 std::vector<SgForStatement* > loops= SageInterface::querySubTree<SgForStatement>(loopNest,V_SgForStatement);
12489 ROSE_ASSERT(loops.size()>=targetLevel);
12507 cerr<<
"Error in SageInterface::loopTiling(): target loop is not canonical."<<endl;
12511 ROSE_ASSERT(ivar&& lb && ub && step);
12519 parent = isSgLocatedNode(loopNest ->get_parent());
12521 ROSE_ASSERT(parent!= NULL);
12523 string ivar2_name =
"_lt_var_"+ivar->get_name().getString();
12533 if (isSgBinaryOp(orig_test))
12535 if (isSgLessOrEqualOp(orig_test))
12537 else if (isSgGreaterOrEqualOp(orig_test))
12543 cerr<<
"Error: illegal condition operator for a canonical loop"<<endl;
12550 cerr<<
"Error: illegal condition expression for a canonical loop"<<endl;
12554 ROSE_ASSERT(cond_stmt != NULL);
12559 SgExpression* orig_incr_exp = target_loop->get_increment();
12560 if( isSgPlusAssignOp(orig_incr_exp))
12564 else if (isSgMinusAssignOp(orig_incr_exp))
12570 cerr<<
"Error: illegal increment expression for a canonical loop"<<endl;
12582 ROSE_ASSERT(assign_op);
12586 ROSE_ASSERT(bin_op);
12606 if (lexicoOrder == 0)
12609 ROSE_ASSERT(loop != NULL);
12611 ROSE_ASSERT (depth >1);
12612 ROSE_ASSERT(lexicoOrder<myfactorial(depth));
12615 std::vector<SgForStatement* > loopNest = SageInterface::querySubTree<SgForStatement>(loop,V_SgForStatement);
12616 ROSE_ASSERT(loopNest.size()>=depth);
12617 std::vector<std::vector<SgNode*> > loopHeads;
12618 for (std::vector<SgForStatement* > ::iterator i = loopNest.begin(); i!= loopNest.end(); i++)
12621 std::vector<SgNode*> head;
12623 head.push_back(cur_loop->get_test());
12624 head.push_back(cur_loop->get_increment());
12625 loopHeads.push_back(head);
12629 std::vector<size_t> changedOrder = getPermutationOrder (depth, lexicoOrder);
12632 for (
size_t i=0; i<depth; i++)
12635 if (i != changedOrder[i])
12638 std::vector<SgNode*> newhead = loopHeads[changedOrder[i]];
12646 init->set_parent(cur_loop);
12651 cur_loop->set_test(test);
12659 cur_loop->set_increment(incr);
12673 ROSE_ASSERT(loop != NULL);
12679 SgAssignOp* assign_op = isSgAssignOp (do_loop->get_initialization());
12680 ROSE_ASSERT (assign_op != NULL);
12682 ROSE_ASSERT (var != NULL);
12683 ivarname = var->get_symbol()->get_declaration();
12684 ROSE_ASSERT (ivarname != NULL);
12698 SgStatementPtrList & init = fs->get_init_stmt();
12699 if (init.size() !=1)
12701 cerr<<
"SageInterface::getLoopIndexVariable(), no or more than one initialization statements are encountered. Not supported yet "<<endl;
12712 if (isSgVariableDeclaration(init1))
12716 ROSE_ASSERT(ivarname != NULL);
12723 SgVarRefExp* var = isSgVarRefExp(SkipCasting(ivarast));
12726 ivarname = var->get_symbol()->get_declaration();
12733 if (
SgCommaOpExp* comma_exp = isSgCommaOpExp(exp_stmt->get_expression()))
12740 SgVarRefExp* var = isSgVarRefExp(assign_op->get_lhs_operand());
12743 ivarname = var->get_symbol()->get_declaration();
12751 mlog[Sawyer::Message::Common::WARN] <<
"Warning: SageInterface::getLoopIndexVariable(). Unhandled init_stmt type of SgForStatement"<<endl;
12752 mlog[Sawyer::Message::Common::WARN] <<
"Init statement is :"<<init1->
class_name() <<
" " <<init1->
unparseToString()<<endl;
12770 ROSE_ASSERT (ivar != NULL);
12771 ROSE_ASSERT (subtree_root != NULL);
12772 bool result =
false;
12777 if (i_index == ivar)
12797 ROSE_ASSERT (loop !=NULL);
12798 SgStatementPtrList& stmt_list = loop->get_init_stmt();
12799 if (stmt_list.size() >1)
return true;
12800 if (stmt_list.size() == 0)
return false;
12805 if (decl_stmt != NULL)
12810 ROSE_ASSERT (exp_stmt != NULL);
12811 if (isSgCommaOpExp (exp_stmt->get_expression()) )
12821 ROSE_ASSERT(loop != NULL);
12829 SgAssignOp* init_assign = isSgAssignOp (init);
12834 bool isCase1=
false;
12839 ivarname = var->get_symbol()->get_declaration();
12841 if (ivarname && lbast )
12853 SgBinaryOp* test = isSgBinaryOp(fs->get_test_expr());
12857 case V_SgLessOrEqualOp:
12858 if (isInclusiveUpperBound != NULL)
12859 *isInclusiveUpperBound =
true;
12860 if (hasIncrementalIterationSpace != NULL)
12861 *hasIncrementalIterationSpace =
true;
12863 case V_SgLessThanOp:
12864 if (isInclusiveUpperBound != NULL)
12865 *isInclusiveUpperBound =
false;
12866 if (hasIncrementalIterationSpace != NULL)
12867 *hasIncrementalIterationSpace =
true;
12869 case V_SgGreaterOrEqualOp:
12870 if (isInclusiveUpperBound != NULL)
12871 *isInclusiveUpperBound =
true;
12872 if (hasIncrementalIterationSpace != NULL)
12873 *hasIncrementalIterationSpace =
false;
12875 case V_SgGreaterThanOp:
12876 if (isInclusiveUpperBound != NULL)
12877 *isInclusiveUpperBound =
false;
12878 if (hasIncrementalIterationSpace != NULL)
12879 *hasIncrementalIterationSpace =
false;
12888 if (testvar == NULL)
12894 ubast = loop->get_bound();
12896 if (isInclusiveUpperBound != NULL)
12897 *isInclusiveUpperBound =
true;
12900 ROSE_ASSERT (incr != NULL);
12901 if (isSgNullExpression(incr))
12903 cerr<<
"Error:isCanonicalDoLoop() found NULL increment expression. Please call doLoopNormalization() first!"<<endl;
12904 ROSE_ASSERT (
false);
12906 if (hasIncrementalIterationSpace != NULL)
12908 *hasIncrementalIterationSpace =
true;
12910 if (
SgIntVal* i_v = isSgIntVal(incr))
12912 if (i_v->get_value()<0)
12913 *hasIncrementalIterationSpace =
false;
12919 case V_SgPlusAssignOp:
12920 case V_SgMinusAssignOp:
12921 incr_var = isSgVarRefExp(SkipCasting(isSgBinaryOp(incr)->get_lhs_operand()));
12924 case V_SgPlusPlusOp:
12925 case V_SgMinusMinusOp:
12926 incr_var = isSgVarRefExp(SkipCasting(isSgUnaryOp(incr)->get_operand()));
12932 if (incr_var == NULL)
12946 if (body != NULL) {
12947 *body = fs->get_body();
12984 ROSE_ASSERT (s != NULL);
12987 std::set<SgNode*> bset = SgNodeHelper::loopRelevantBreakStmtNodes (s);
12988 if (bset.size()!=0 )
13002 ROSE_ASSERT(loop != NULL);
13013 SgStatementPtrList & init = fs->get_init_stmt();
13014 if (init.size() !=1)
13017 SgExpression* ivarast=NULL, *lbast=NULL, *ubast=NULL, *stepast=NULL;
13020 bool isCase1=
false, isCase2=
false;
13022 if (isSgVariableDeclaration(init1))
13026 ROSE_ASSERT(ivarname != NULL);
13028 if (isSgAssignInitializer(initor))
13030 lbast = isSgAssignInitializer(initor)->
get_operand();
13036 SgVarRefExp* var = isSgVarRefExp(SkipCasting(ivarast));
13039 ivarname = var->get_symbol()->get_declaration();
13044 ROSE_ASSERT(!(isCase1&&isCase2));
13046 if (!(isCase1||isCase2))
13058 case V_SgLessOrEqualOp:
13059 if (isInclusiveUpperBound != NULL)
13060 *isInclusiveUpperBound =
true;
13061 if (hasIncrementalIterationSpace != NULL)
13062 *hasIncrementalIterationSpace =
true;
13064 case V_SgLessThanOp:
13065 if (isInclusiveUpperBound != NULL)
13066 *isInclusiveUpperBound =
false;
13067 if (hasIncrementalIterationSpace != NULL)
13068 *hasIncrementalIterationSpace =
true;
13070 case V_SgGreaterOrEqualOp:
13071 if (isInclusiveUpperBound != NULL)
13072 *isInclusiveUpperBound =
true;
13073 if (hasIncrementalIterationSpace != NULL)
13074 *hasIncrementalIterationSpace =
false;
13076 case V_SgGreaterThanOp:
13077 if (isInclusiveUpperBound != NULL)
13078 *isInclusiveUpperBound =
false;
13079 if (hasIncrementalIterationSpace != NULL)
13080 *hasIncrementalIterationSpace =
false;
13089 if (testvar == NULL)
13113 case V_SgPlusAssignOp:
13114 case V_SgMinusAssignOp:
13115 incr_var = isSgVarRefExp(SkipCasting(isSgBinaryOp(incr)->get_lhs_operand()));
13118 case V_SgPlusPlusOp:
13119 case V_SgMinusMinusOp:
13120 incr_var = isSgVarRefExp(SkipCasting(isSgUnaryOp(incr)->get_operand()));
13123 case V_SgAssignOp: {
13124 incr_var=isSgVarRefExp(SkipCasting(isSgBinaryOp(incr)->get_lhs_operand()));
13125 if(incr_var == NULL)
13127 SgAddOp* addOp=isSgAddOp(SkipCasting(isSgBinaryOp(incr)->get_rhs_operand()));
13128 SgSubtractOp* subtractOp=isSgSubtractOp(SkipCasting(isSgBinaryOp(incr)->get_rhs_operand()));
13132 else if(subtractOp)
13133 arithOp=subtractOp;
13136 ROSE_ASSERT(arithOp!=0);
13137 if(
SgVarRefExp* varRefExp=isSgVarRefExp(SkipCasting(isSgBinaryOp(arithOp)->get_lhs_operand()))) {
13139 incr_var=varRefExp;
13141 }
else if(
SgVarRefExp* varRefExp=isSgVarRefExp(SkipCasting(isSgBinaryOp(arithOp)->get_rhs_operand()))) {
13142 if(isSgAddOp(arithOp)) {
13144 incr_var=varRefExp;
13154 if (incr_var == NULL)
13175 if (body != NULL) {
13184 ROSE_ASSERT(loop != NULL);
13185 ROSE_ASSERT(lb != NULL);
13190 if (forstmt != NULL)
13195 Rose_STL_Container<SgNode* > testList = NodeQuery::querySubTree( *((forstmt->get_init_stmt()).begin()), V_SgAssignOp);
13196 if (testList.size()>0)
13198 ROSE_ASSERT(testList.size()==1);
13199 SgAssignOp * assignop = isSgAssignOp((*testList.begin()));
13200 ROSE_ASSERT(assignop);
13210 Rose_STL_Container<SgNode* > testList = NodeQuery::querySubTree( *((forstmt->get_init_stmt()).begin()), V_SgAssignInitializer );
13211 ROSE_ASSERT(testList.size()==1);
13213 ROSE_ASSERT(init != NULL);
13214 init->set_operand(lb);
13219 else if (dostmt != NULL)
13222 ROSE_ASSERT (init != NULL);
13224 ROSE_ASSERT (a_op!=NULL);
13231 cerr<<
"Error. SageInterface::setLoopLowerBound(), illegal loop type:"<< loop->
class_name()<<endl;
13232 ROSE_ASSERT (
false);
13239 ROSE_ASSERT(loop != NULL);
13240 ROSE_ASSERT(ub != NULL);
13244 if (forstmt != NULL)
13247 SgBinaryOp * binop= isSgBinaryOp(isSgExprStatement(forstmt->get_test())->get_expression());
13248 ROSE_ASSERT(binop != NULL);
13252 else if (dostmt != NULL)
13254 dostmt->set_bound(ub);
13260 cerr<<
"Error. SageInterface::setLoopUpperBound(), illegal loop type:"<< loop->
class_name()<<endl;
13261 ROSE_ASSERT (
false);
13269 ROSE_ASSERT(loop != NULL);
13270 ROSE_ASSERT(stride != NULL);
13274 if (dostmt != NULL)
13276 dostmt->set_increment(stride);
13280 else if (forstmt != NULL)
13284 Rose_STL_Container<SgNode*> testList = NodeQuery::querySubTree( forstmt->get_increment(), V_SgPlusPlusOp);
13285 if (testList.size()>0)
13287 ROSE_ASSERT(testList.size() == 1);
13289 (isSgPlusPlusOp( *testList.begin())->
get_operand()));
13291 forstmt->set_increment(plusassignop);
13295 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgMinusMinusOp);
13296 if (testList.size()>0)
13298 ROSE_ASSERT(testList.size()==1);
13300 (isSgMinusMinusOp(*testList.begin())->
get_operand()));
13302 forstmt->set_increment(plusassignop);
13306 testList = NodeQuery::querySubTree( forstmt->get_increment(), V_SgPlusAssignOp);
13307 if (testList.size()>0)
13309 ROSE_ASSERT(testList.size()==1);
13310 SgPlusAssignOp * assignop = isSgPlusAssignOp(*(testList.begin()));
13311 ROSE_ASSERT(assignop!=NULL);
13316 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgMinusAssignOp);
13317 if (testList.size()>0)
13319 ROSE_ASSERT(testList.size()==1);
13322 SgExprStatement* exprstmt = isSgExprStatement((*testList.begin())->get_parent());
13323 ROSE_ASSERT(exprstmt !=NULL);
13325 exprstmt->set_expression(plusassignop);
13336 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgAddOp);
13337 if (testList.size()>0)
13339 ROSE_ASSERT(testList.size()==1);
13341 SgAddOp * addop = isSgAddOp(*(testList.begin()));
13342 ROSE_ASSERT(addop!=NULL);
13356 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgSubtractOp);
13357 if (testList.size()>0)
13359 ROSE_ASSERT(testList.size()==1);
13361 SgSubtractOp * subtractop = isSgSubtractOp(*(testList.begin()));
13362 ROSE_ASSERT(subtractop!=NULL);
13365 SgAssignOp *assignop = isSgAssignOp((*testList.begin())->get_parent());
13366 ROSE_ASSERT(assignop !=NULL);
13373 cerr<<
"Error. SageInterface::setLoopStride(), illegal loop type:"<< loop->
class_name()<<endl;
13374 ROSE_ASSERT (
false);
13385 SgExpression *exp = (n != 0)? n->get_expression() : isSgExpression(s);
13388 case V_SgPlusAssignOp:
13389 case V_SgMinusAssignOp:
13390 case V_SgAndAssignOp:
13391 case V_SgIorAssignOp:
13392 case V_SgMultAssignOp:
13393 case V_SgDivAssignOp:
13394 case V_SgModAssignOp:
13395 case V_SgXorAssignOp:
13403 if ( init->variantT() == V_SgAssignInitializer)
13404 init = isSgAssignInitializer(init)->
get_operand();
13408 *readlhs = (exp->
variantT() != V_SgAssignOp);
13422 Rose_STL_Container<SgNode*> gotos = NodeQuery::querySubTree(top,V_SgGotoStatement);
13423 for (
size_t i = 0; i < gotos.size(); ++i)
13428 if (!lsParent)
continue;
13431 size_t j = std::find(bbStatements.begin(), bbStatements.end(), ls) - bbStatements.begin();
13433 ROSE_ASSERT (j != bbStatements.size());
13435 while (j < bbStatements.size() - 1 && isSgLabelStatement(bbStatements[j + 1]))
13439 gs->
set_label(isSgLabelStatement(bbStatements[j]));
13455 ROSE_ASSERT(decl != NULL);
13456 ROSE_ASSERT(assign_stmt != NULL);
13459 SgAssignOp * assign_op = isSgAssignOp (assign_stmt->get_expression());
13460 if (assign_op == NULL)
13463 if (assign_op_var == NULL)
return false;
13467 if (decl_var->get_initptr()!= NULL )
return false;
13474 if (decl_var_symbol!=NULL)
13477 if (assign_op_var->get_symbol() != decl_var_symbol)
return false;
13482 if (assign_op_var->get_symbol()->
get_name() != decl_var ->get_name())
return false;
13496 if (removeAssignStmt)
13500 decl_var->set_initptr(initor);
13511 ROSE_ASSERT(assign_stmt != NULL);
13512 SgAssignOp * assign_op = isSgAssignOp (assign_stmt->get_expression());
13513 if (assign_op == NULL)
13516 if (assign_op_var == NULL)
13520 ROSE_ASSERT(decl != NULL);
13522 if (decl_var->get_initptr()!= NULL)
13529 ROSE_ASSERT(decl_var != NULL);
13531 if (decl_var_symbol != NULL) {
13533 if (assign_op_var->get_symbol() != decl_var_symbol)
13539 if (assign_op_var->get_symbol()->
get_name() != decl_var ->get_name())
13552 decl_var->set_initptr(initor);
13582 ROSE_ASSERT (decl != NULL);
13586 if (initor == NULL)
13593 rhs = ainitor->get_operand();
13599 decl_var->set_initptr(NULL);
13611 cerr<<
"SageInterface::splitVariableDeclaration() topLevelOnly == false is not yet implemented."<<endl;
13612 ROSE_ASSERT (
false);
13615 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(scope, V_SgVariableDeclaration);
13616 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
13621 ROSE_ASSERT(decl != NULL);
13634 ROSE_ASSERT (root != NULL);
13637 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(root, V_SgVarRefExp);
13641 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
13644 ROSE_ASSERT (vRef != NULL);
13645 result.push_back(vRef);
13652 ROSE_ASSERT (root != NULL);
13653 Rose_STL_Container<SgNode*> constructorList= NodeQuery::querySubTree(root, V_SgConstructorInitializer);
13654 for (
size_t i =0; i< constructorList.size(); i++)
13659 Rose_STL_Container<SgNode*> varList = NodeQuery::querySubTree (a_type->get_index(),V_SgVarRefExp);
13660 for (
size_t j =0 ; j< varList.size(); j++)
13662 SgVarRefExp* var_exp = isSgVarRefExp(varList[j]) ;
13663 currentVarRefList.push_back(var_exp);
13687 SgExpression* lhsCopy = isSgExpression(lhs->copy(treeCopy));
13688 ROSE_ASSERT (lhsCopy);
13712 SgExpression* lhsCopy = isSgExpression(lhs->copy(treeCopy));
13713 ROSE_ASSERT (lhsCopy);
13737 SgExpression* lhsCopy = isSgExpression(lhs->copy(treeCopy));
13738 ROSE_ASSERT (lhsCopy);
13755 ROSE_ASSERT(from != NULL);
13757#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
13761 ROSE_ASSERT (
false);
13766 SgStatement* stmt = getStatementOfExpression(from);
13768 if (!isSgForInitStatement(stmt->
get_parent())) {
13777 if (!parent && isSgForInitStatement(stmt->
get_parent()))
13783 SgName varname =
"rose_temp__";
13784 if (newName ==
"") {
13792 vector<SgExpression*> ancestors;
13793 for (
SgExpression *expr = from, *anc = isSgExpression(fromparent); anc != 0;
13794 expr = anc, anc = isSgExpression(anc->get_parent()))
13796 if ((isSgAndOp(anc) && expr != isSgAndOp(anc)->get_lhs_operand()) ||
13799 ancestors.push_back(anc);
13802 for (vector<SgExpression*>::reverse_iterator ai = ancestors.rbegin(); ai != ancestors.rend(); ++ai)
13805 switch ((*ai)->variantT()) {
13810 case V_SgConditionalExp:
13812 default: assert (!
"Should not happen"); abort();
13817 if (ancestors.size() != 0) {
13825 ROSE_ASSERT (initname);
13827 replaceExpressionWithExpression(from, varref);
13831 initname->set_initializer(ai);
13833 myStatementInsert(stmt, vardecl,
true);
13854 SplitStatementGenerator gen;
13860 Rose_STL_Container<SgNode*> gotos = NodeQuery::querySubTree(top,
13861 V_SgGotoStatement);
13862 map<SgLabelStatement*, SgLabelStatement*> labelsToReplace;
for
13863 (
size_t i = 0; i < gotos.size(); ++i) {
13866 if (!gsParent)
continue;
13868 size_t j = std::find(bbStatements.begin(), bbStatements.end(), gs)
13869 - bbStatements.begin();
13870 ROSE_ASSERT (j != bbStatements.size());
13871 if (j == 0)
continue;
13872 if (isSgLabelStatement(bbStatements[j - 1])) {
13873 labelsToReplace[isSgLabelStatement(bbStatements[j - 1])] =
13877 for (
size_t i = 0; i < gotos.size(); ++i) {
13880 while (labelsToReplace.find(oldLabel) != labelsToReplace.end()) {
13881 oldLabel = labelsToReplace[oldLabel];
13891 case V_SgBoolValExp:
return (isSgBoolValExp(e)->get_value() != 0);
13893 case V_SgBoolValExp:
return (isSgBoolValExp(e)->get_value() ==
true);
13895 case V_SgIntVal:
return isSgIntVal(e)->get_value() != 0;
13896 case V_SgCastExp:
return isConstantTrue(isSgCastExp(e)->get_operand());
13898 case V_SgAddressOfOp:
return true;
13899 default:
return false;
13905 case V_SgBoolValExp:
return isSgBoolValExp(e)->get_value() ==
false;
13906 case V_SgIntVal:
return isSgIntVal(e)->get_value() == 0;
13907 case V_SgCastExp:
return
13909 case V_SgNotOp:
return isConstantTrue(isSgNotOp(e)->get_operand());
13910 default:
return false;
13917 if (!fc)
return false;
13919 if (fr == NULL)
return false;
13920 return fr->get_symbol()->get_declaration() == decl;
13926 if (!fc)
return false;
13928 if (fr == NULL)
return false;
13930 fr->get_symbol()->get_declaration()->get_qualified_name().getString();
13931 return (name == qualifiedName &&
13932 fc->get_args()->get_expressions().size() == arity);
13937 ROSE_ASSERT( e != NULL);
13953 ROSE_ASSERT(expList);
13955 expList->append_expression(exp);
13961 for (
size_t i = 0; i < exp.size(); ++i)
13970template <
class actualFunction>
13980 ROSE_ASSERT(paralist);
13985 cerr <<
"Waring! Setting a used SgFunctionParameterList to function: "
13986 << (func->get_name()).getString()<<endl
13987 <<
" Sharing parameter lists can corrupt symbol tables!"<<endl
13988 <<
" Please use deepCopy() to get an exclusive parameter list for each function declaration!"<<endl;
13993 if (func->get_parameterList() != NULL)
13994 if (func->get_parameterList() != paralist)
13995 delete func->get_parameterList();
13997 func->set_parameterList(paralist);
14005 ROSE_ASSERT(paraList != NULL);
14006 ROSE_ASSERT(initName != NULL);
14008 if (isPrepend ==
true)
14009 paraList->prepend_arg(initName);
14011 paraList->append_arg(initName);
14018 ROSE_ASSERT(initName->
get_parent() == paraList);
14028 if (func_decl != NULL)
14034 ROSE_ASSERT(func_def);
14044 initName->set_declptr(func_decl);
14056 initName->set_scope(scope);
14076 return addArg(paraList,initName,
false);
14081 return addArg(paraList,initName,
true);
14087 ROSE_ASSERT(pragma);
14088 if (decl->get_pragma()!=NULL)
delete (decl->get_pragma());
14089 decl->set_pragma(pragma);
14100 void testAstForUniqueNodes (
SgNode* node );
14103 printf (
"In SageInterface::appendStatement(): stmt = %p = %s scope = %p \n",stmt,stmt->
class_name().c_str(),scope);
14112 printf (
" --- scope was not specified as input! \n");
14117 ROSE_ASSERT(stmt != NULL);
14118 ROSE_ASSERT(scope != NULL);
14121 printf (
"In SageInterface::appendStatement(): stmt = %p = %s scope = %p = %s \n",stmt,stmt->
class_name().c_str(),scope,scope->
class_name().c_str());
14128 if (declarationStatement != NULL)
14156 scope->insertStatementInScope(stmt,
false);
14160 bool skipAddingStatement =
false;
14162 if (classDeclaration != NULL)
14168 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());
14174 skipAddingStatement = (classDeclaration->get_isAutonomousDeclaration() ==
false);
14178 skipAddingStatement = (classDeclaration->get_isAutonomousDeclaration() ==
false) || (classDeclaration->
get_parent() != NULL);
14193 if (statementAlreadyExistsInScope ==
true)
14195 if (isSgTemplateInstantiationDecl(classDeclaration) != NULL)
14199#if PRINT_DEVELOPER_WARNINGS
14200 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",
14208 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",
14213 skipAddingStatement =
true;
14220 if (enumDeclaration != NULL)
14223 skipAddingStatement = (enumDeclaration->get_isAutonomousDeclaration() ==
false);
14232 if (skipAddingStatement ==
false && statementAlreadyExistsInScope ==
true)
14235 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",
14239 printf (
"Exiting as a test! \n");
14242 skipAddingStatement =
true;
14247 printf (
" --- skipAddingStatement = %s \n",skipAddingStatement ?
"true" :
"false");
14250 if (skipAddingStatement ==
false)
14262 printf (
" --- calling insertStatementInScope(): scope = %p = %s stmt = %p = %s \n",scope,scope->
class_name().c_str(),stmt,stmt->
class_name().c_str());
14264 scope->insertStatementInScope(stmt,
false);
14291 testAstForUniqueNodes(scope);
14300 ROSE_ASSERT (stmt != NULL);
14301 ROSE_ASSERT (for_init_stmt != NULL);
14304 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());
14313 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());
14321 for_init_stmt->append_init_stmt (stmt);
14327 for (
size_t i = 0; i < stmts.size(); ++i)
14330#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
14331 printf (
"In appendStatementList(): stmts[i = %" PRIuPTR
"] = %p = %s \n",i,stmts[i],stmts[i]->class_name().c_str());
14337 if (stmts[i]->get_parent() != NULL)
14340#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
14341 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());
14348 printf (
" --- WARNING: In appendStatementList(): stmts[i = %" PRIuPTR
"] not added to scope (because stmts[i]->get_parent() == NULL) \n",i);
14357 ROSE_ASSERT (stmt != NULL);
14360 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p \n",stmt,stmt->
class_name().c_str(),scope);
14370 ROSE_ASSERT(scope != NULL);
14380 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: stmt) \n",
14392 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: scope) \n",
14404 printf (
"Calling insertStatementInScope() \n");
14410 scope->insertStatementInScope(stmt,
true);
14430 printf (
"Leaving SageInterface::prependStatement() \n");
14438 ROSE_ASSERT (stmt != NULL);
14439 ROSE_ASSERT (for_init_stmt != NULL);
14442 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());
14451 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());
14459 for_init_stmt->prepend_init_stmt (stmt);
14464 for (
size_t i = stmts.size(); i > 0; --i)
14476 ROSE_ASSERT (scope != NULL);
14479 case V_SgBasicBlock:
14480 case V_SgClassDefinition:
14481 case V_SgFunctionDefinition:
14483 case V_SgNamespaceDefinitionStatement:
14487 case V_SgAssociateStatement :
14488 case V_SgBlockDataStatement :
14489 case V_SgCatchOptionStmt:
14490 case V_SgDoWhileStmt:
14491 case V_SgForAllStatement:
14492 case V_SgForStatement:
14493 case V_SgFortranDo:
14495 case V_SgSwitchStatement:
14496 case V_SgUpcForAllStatement:
14497 case V_SgWhileStmt:
14502 cout<<
"unrecognized or unhandled scope type for SageInterface::hasSimpleChildrenList() "<<endl;
14515 SgDeclarationStatementPtrList & declarationList = globalScope->
get_declarations();
14518 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
14520 while (i != declarationList.end() && (*i)->get_file_info() != NULL && (*i)->get_file_info()->isFrontendSpecific() ==
true)
14523 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");
14525 last_statement = *i;
14530 ROSE_ASSERT(last_statement != NULL);
14532 printf (
"last_statement = %p = %s \n",last_statement,last_statement->
class_name().c_str());
14535 printf (
"Exiting as a test! \n");
14539 return last_statement;
14548 ROSE_ASSERT(targetStmt &&newStmt);
14549 ROSE_ASSERT(targetStmt != newStmt);
14551 if (isSgGlobal(targetStmt) ||
14552 isSgClassDefinition(targetStmt)||
14553 isSgNamespaceDefinitionStatement(targetStmt)||
14554 isSgFunctionParameterList(targetStmt)||
14555 isSgFunctionDefinition(targetStmt)||
14556 isSgCtorInitializerList(targetStmt))
14558 string className = targetStmt->
class_name();
14559 string err_msg =
"targetStmt cannot be a " + className +
". Its parent does not implement insert_child(). Please revise your code to avoid inserting a stmt as a sibling of this type of targetStmt.";
14560 cerr<<err_msg<<endl;
14561 ROSE_ASSERT (
false);
14565 if (isSgCaseOptionStmt(targetStmt))
14567 if (!isSgCaseOptionStmt(newStmt))
14569 cerr<<
"Target statment is a case option stmt. The new stmt should also be the same type to be a sibling. But it is "<< newStmt->
class_name() <<
" instead. This is not semantically correct." <<endl;
14570 ROSE_ASSERT(
false);
14575 if (parent == NULL)
14577 cerr <<
"Empty parent pointer for target statement. May be caused by the wrong order of target and new statements in insertStatement(targetStmt, newStmt)"<<endl;
14578 ROSE_ASSERT(parent);
14604 cerr<<
"Error: you cannot insert a variable declaration stmt inside a case option statement without enclosing brances in between."<<endl;
14605 cerr<<
"parent of target is a case option stmt:"<<parent <<endl;
14606 cerr<<
"new statement is a variable statement:"<<newStmt <<endl;
14607 ASSERT_require(
false);
14611 if (isSgLabelStatement(parent) !=
nullptr)
14615 ROSE_ASSERT(isSgLabelStatement(parent) == NULL);
14618 if (isSgFunctionDefinition(parent) ||
14619 isSgTypedefDeclaration(parent) ||
14620 isSgSwitchStatement(parent) ||
14621 isSgVariableDeclaration(parent))
14624 string err_msg =
"targetStmt's parent cannot be a " + className +
". This parent does not implement insert() function. Please revise your code to avoid inserting a stmt as a child of this type of parent.";
14625 cerr<<err_msg<<endl;
14628 if (switch_stmt->get_item_selector() == targetStmt)
14630 cerr<<
"The target statement is the item selector of a switch statement. You cannot insert any statement before or after it."<<endl;
14634 ROSE_ASSERT (
false);
14638 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());
14656 ROSE_ASSERT(scope);
14659 printf (
"targetStmt = %p = %s \n",targetStmt,targetStmt->
class_name().c_str());
14660 printf (
"scope = %p = %s \n",scope,scope->
class_name().c_str());
14678 ROSE_ASSERT(isSgStatement(parent) != NULL);
14683 ROSE_ASSERT(targetStmt != NULL);
14687 printf (
"In SageInterface::insertStatement(): after checking for associated comments \n");
14688 reportNodesMarkedAsModified(scope);
14694 if (autoMovePreprocessingInfo)
14696 if (comments != NULL && isSgBasicBlock(newStmt) == NULL)
14698 vector<int> captureList;
14700 printf (
"Found attached comments (at %p = %s, inserting %p = %s insertBefore = %s): comments->size() = %" PRIuPTR
" \n",
14701 targetStmt,targetStmt->
class_name().c_str(),newStmt,newStmt->
class_name().c_str(),insertBefore ?
"true" :
"false",comments->size());
14708 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");
14713 int commentIndex = 0;
14714 AttachedPreprocessingInfoType::iterator i;
14715 for (i = comments->begin(); i != comments->end(); i++)
14717 ROSE_ASSERT ( (*i) != NULL );
14719 printf (
" Attached Comment (relativePosition=%s): %s\n",
14720 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
14721 (*i)->getString().c_str());
14722 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
14723 (*i)->get_file_info()->display(
"comment/directive location");
14726 if ((*i)->getRelativePosition() == relativePosition)
14729 captureList.push_back(commentIndex);
14736 if (captureList.empty() ==
false)
14742 ROSE_ASSERT(surroundingStatement != targetStmt);
14743 ROSE_ASSERT(surroundingStatement != NULL);
14745 if (surroundingStatement == NULL)
14748 surroundingStatement = (insertBefore ==
true) ? newStmt : newStmt;
14753 vector<int>::iterator j = captureList.begin();
14754 while (j != captureList.end())
14762 (*comments)[*j] = NULL;
14769 for (
size_t n = 0; n < captureList.size(); n++)
14771 AttachedPreprocessingInfoType::iterator k = comments->begin();
14772 while (k != comments->end())
14777 comments->erase(k);
14790 if (comments != NULL)
14792 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");
14799 printf (
"In SageInterface::insertStatement(): after processing associated comments \n");
14800 reportNodesMarkedAsModified(scope);
14803 if (isSgIfStmt(parent))
14805 if (isSgIfStmt(parent)->get_conditional()==targetStmt)
14811 if (isSgIfStmt(parent)->get_true_body()==targetStmt)
14831 if (isSgIfStmt(parent)->get_false_body()==targetStmt)
14845 if (isSgWhileStmt(parent))
14847 if (isSgWhileStmt(parent)->get_condition()==targetStmt)
14853 if (isSgWhileStmt(parent)->get_body()==targetStmt)
14856 isSgWhileStmt(parent)->
set_body(newparent);
14866 if (isSgDoWhileStmt(parent))
14868 if (isSgDoWhileStmt(parent)->get_condition()==targetStmt)
14874 if (isSgDoWhileStmt(parent)->get_body()==targetStmt)
14877 isSgDoWhileStmt(parent)->
set_body(newparent);
14887 if (isSgForStatement(parent))
14889 if (isSgForStatement(parent)->get_loop_body()==targetStmt)
14900 if (isSgForStatement(parent)->get_test()==targetStmt)
14921 p->set_body(newparent);
14929 ROSE_ASSERT(stmnt != NULL);
14951 printf (
"In SageInterface::insertStatement(): at BASE of function \n");
14952 reportNodesMarkedAsModified(scope);
14961 for (
size_t i = 0; i < newStmts.size(); ++i)
14968 for (
size_t i = newStmts.size(); i > 0; --i)
14977 insertStatement(targetStmt,newStmt,
false, autoMovePreprocessingInfo);
14988 ROSE_ASSERT (stmt != NULL);
14989 ROSE_ASSERT (scope != NULL);
15001 ROSE_ASSERT (scope != NULL);
15002 vector <SgStatement* >::iterator iter;
15004 for (iter= stmt_list.begin(); iter != stmt_list.end(); iter++)
15006 if (iter == stmt_list.begin())
15012 ROSE_ASSERT (prev_stmt != NULL);
15021 ROSE_ASSERT(newStmt!=NULL);
15022 ROSE_ASSERT(scope!=NULL);
15024 if (!isSgDeclarationStatement(targetStmt)) {
15034 ROSE_ASSERT(scope!=NULL);
15036 if (!isSgDeclarationStatement(targetStmt)) {
15059 ROSE_ASSERT(target);
15060 ROSE_ASSERT(operand);
15061 ROSE_ASSERT(target!=operand);
15062 switch (target->variantT())
15064 case V_SgActualArgumentExpression:
15065 isSgActualArgumentExpression(target)->set_expression(operand);
15068 isSgAsmOp(target)->set_expression(operand);
15071 isSgSizeOfOp(target)->set_operand_expr(operand);
15074 isSgTypeIdOp(target)->set_operand_expr(operand);
15077 isSgVarArgOp(target)->set_operand_expr(operand);
15079 case V_SgVarArgStartOneOperandOp:
15080 isSgVarArgStartOneOperandOp(target)->set_operand_expr(operand);
15082 case V_SgAssignInitializer:
15083 isSgAssignInitializer (target)->
set_operand(operand);
15086 if (isSgUnaryOp(target)!=NULL)
15090 cerr<<
"\tSageInterface::setOperand(): unhandled case for target expression of type "
15091 <<target->class_name()<<endl;
15096 markLhsValues(target);
15102 ROSE_ASSERT(target);
15104 ROSE_ASSERT(target!=lhs);
15105 bool hasrhs =
false;
15111 if (varargcopy!=NULL)
15113 varargcopy->set_lhs_operand(lhs);
15114 if( varargcopy->get_rhs_operand()!=NULL) hasrhs=
true;
15116 else if(varargstart!=NULL)
15118 varargstart->set_lhs_operand(lhs);
15119 if( varargstart->get_rhs_operand()!=NULL) hasrhs=
true;
15121 else if(binary!=NULL)
15128 cout<<
"SageInterface::setLhsOperand(): unhandled case for target expression of type "
15129 <<target->class_name()<<endl;
15136 markLhsValues(target);
15141 ROSE_ASSERT(target);
15143 ROSE_ASSERT(target!=rhs);
15144 bool haslhs =
false;
15150 if (varargcopy!=NULL)
15152 varargcopy->set_rhs_operand(rhs);
15153 if( varargcopy->get_lhs_operand()!=NULL) haslhs=
true;
15155 else if(varargstart!=NULL)
15157 varargstart->set_rhs_operand(rhs);
15158 if( varargstart->get_lhs_operand()!=NULL) haslhs=
true;
15160 else if(binary!=NULL)
15167 cout<<
"SageInterface::setRhsOperand(): unhandled case for target expression of type "
15168 <<target->class_name()<<endl;
15174 markLhsValues(target);
15193 ROSE_ASSERT(parentFileList != NULL);
15199 if (parentDirectory != NULL)
15202 parentDirectory->get_directoryList()->get_listOfDirectories().push_back(directory);
15209 project = isSgProject(parentFileList->
get_parent());
15210 ROSE_ASSERT(project != NULL);
15213 project->get_directoryList()->get_listOfDirectories().push_back(directory);
15220 directory->get_fileList()->get_listOfFiles().push_back(file);
15223 parentFileList->get_listOfFiles().erase(find(parentFileList->get_listOfFiles().begin(),parentFileList->get_listOfFiles().end(),file));
15233 ROSE_ASSERT(structDecl != NULL);
15234 ROSE_ASSERT(scope != NULL);
15236 ROSE_ASSERT(nondefdecl != NULL);
15262 SgName name = structDecl->get_name();
15276 if (mysymbol == NULL)
15278 printf (
"Note: SageInterface::fixStructDeclaration(): structDecl = %p nondefdecl = %p (mysymbol == NULL) \n",structDecl,nondefdecl);
15282 ROSE_ASSERT(structDecl->
get_scope() != NULL);
15287 ROSE_ASSERT(mysymbol);
15290 printf (
"############## DANGER:DANGER:DANGER ################\n");
15292 printf (
"In SageInterface::fixStructDeclaration(): Adding class symbol to scope = %p = %s \n",scope,scope->
class_name().c_str());
15300 printf (
"*** WARNING: In SageInterface::fixStructDeclaration(): (mysymbol == NULL) Commented out the setting of the parent to be the same as the scope \n");
15309 printf (
"In SageInterface::fixStructDeclaration(): (mysymbol == NULL) Skipped building an associated symbol! \n");
15314 ROSE_ASSERT(nondefdecl->get_type() != NULL);
15317 ROSE_ASSERT(nondefdecl->get_type()->
variantT() != V_SgNode);
15320 ROSE_ASSERT(isSgClassType(nondefdecl->get_type()) != NULL);
15324 if (nondefdecl->get_type() == NULL)
15328 ROSE_ASSERT (nondefdecl->get_type() != NULL);
15331 if (defdecl != NULL)
15334 ROSE_ASSERT(defdecl->get_type()->
variantT() != V_SgNode);
15337 ROSE_ASSERT(isSgClassType(defdecl->get_type()) != NULL);
15341 if (defdecl != NULL)
15344 ROSE_ASSERT(defdecl->get_type() != NULL);
15345 if (defdecl->get_type() != nondefdecl->get_type())
15347 printf (
"ERROR: defdecl->get_type() != nondefdecl->get_type(): what are these: \n");
15348 printf (
" defdecl->get_type() = %p = %s \n",defdecl ->get_type(),defdecl ->get_type()->class_name().c_str());
15349 SgNamedType* namedType_definingDecl = isSgNamedType(defdecl->get_type());
15350 if (namedType_definingDecl != NULL)
15352 printf (
"namedType_definingDecl->get_declaration() = %p = %s \n",namedType_definingDecl->get_declaration(),namedType_definingDecl->get_declaration()->
class_name().c_str());
15354 printf (
" nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->
class_name().c_str());
15355 SgNamedType* namedType_nondefiningDecl = isSgNamedType(nondefdecl->get_type());
15356 if (namedType_nondefiningDecl != NULL)
15358 printf (
"namedType_nondefiningDecl->get_declaration() = %p = %s \n",namedType_nondefiningDecl->get_declaration(),namedType_nondefiningDecl->get_declaration()->
class_name().c_str());
15374 ROSE_ASSERT(structDecl);
15375 ROSE_ASSERT(scope);
15377 ROSE_ASSERT(nondefdecl);
15396 if (mysymbol==NULL)
15403 ROSE_ASSERT(mysymbol);
15405 printf (
"In SageInterface::fixNamespaceDeclaration(): inserting namespace symbol into scope = %p = %s \n",scope,scope->
class_name().c_str());
15409 ROSE_ASSERT(defdecl);
15419#define DEBUG__SageInterface__fixVariableDeclaration 0
15423 ROSE_ASSERT(varDecl != NULL);
15424 ROSE_ASSERT(scope != NULL);
15426 SgInitializedNamePtrList namelist = varDecl->
get_variables();
15431#if DEBUG__SageInterface__fixVariableDeclaration
15432 printf (
"In SageInterface::fixVariableDeclaration():\n");
15433 printf (
" varDecl = %p scope = %p = %s \n", varDecl);
15434 printf (
" scope = %p : %s \n", scope, scope->
class_name().c_str());
15437 ROSE_ASSERT(namelist.size() > 0);
15439 SgInitializedNamePtrList::iterator i;
15440 for (i = namelist.begin(); i != namelist.end(); i++)
15443 ROSE_ASSERT(initName != NULL);
15444#if DEBUG__SageInterface__fixVariableDeclaration
15445 printf (
" initName = %p\n", initName);
15446 printf (
" initName->get_scope() = %p : %s\n", initName->get_scope(), initName->get_scope() ? initName->get_scope()->
class_name().c_str() :
"");
15449 SgName name = initName->get_name();
15450#if DEBUG__SageInterface__fixVariableDeclaration
15451 printf (
" name = %s\n", name.str());
15456#if DEBUG__SageInterface__fixVariableDeclaration
15457 printf (
" name = %s\n", name.str());
15464 if (preAssociatedScope != NULL) {
15465 requiredScope = preAssociatedScope;
15469 initName->set_scope(requiredScope);
15474 ROSE_ASSERT(requiredScope != NULL);
15475 SgVariableSymbol* varSymbol = requiredScope->lookup_variable_symbol(name);
15476#if DEBUG__SageInterface__fixVariableDeclaration
15477 printf (
" varSymbol = %p (%s)\n", varSymbol, varSymbol ? varSymbol->
class_name().c_str() :
"");
15479 if (varSymbol == NULL) {
15480 if (scope == initName->get_scope()) {
15481 if (isSgTemplateVariableDeclaration(varDecl)) {
15486 ROSE_ASSERT(varSymbol);
15491 ROSE_ASSERT(prev_decl);
15492 if (initName != prev_decl) {
15493 initName->set_prev_decl_item(prev_decl);
15495 ROSE_ASSERT(initName->get_prev_decl_item() != initName);
15497#if DEBUG__SageInterface__fixVariableDeclaration
15498 printf (
" varSymbol = %p (%s)\n", varSymbol, varSymbol ? varSymbol->
class_name().c_str() :
"");
15516 Rose_STL_Container<SgNode*> varList;
15519 Rose_STL_Container<SgNode*> reflist = NodeQuery::querySubTree(root, V_SgVarRefExp);
15520 for (Rose_STL_Container<SgNode*>::iterator i=reflist.begin();i!=reflist.end();i++)
15522 varRef= isSgVarRefExp(*i);
15523 ROSE_ASSERT(varRef->get_symbol());
15526 ROSE_ASSERT (initname != NULL);
15529 SgName varName=initname->get_name();
15540 if (varRef == arrowExp->get_rhs_operand_i())
15544 SgType* lhs_type = arrowExp->get_lhs_operand_i()->get_type() ;
15545 lhs_type = lhs_type->
stripType(SgType::STRIP_MODIFIER_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE | SgType::STRIP_TYPEDEF_TYPE);
15547 ROSE_ASSERT(ptrType);
15548 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));
15549 ROSE_ASSERT(clsType);
15567 if (varRef == dotExp->get_rhs_operand_i())
15572 SgType* lhs_type = dotExp->get_lhs_operand_i()->get_type() ;
15573 lhs_type = lhs_type->
stripType(SgType::STRIP_MODIFIER_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE | SgType::STRIP_TYPEDEF_TYPE);
15575 ROSE_ASSERT(clsType);
15599 if (realSymbol==NULL)
15606 ROSE_ASSERT(realSymbol!=(varRef->get_symbol()));
15613 bool toDelete =
true;
15615 SgSymbol* symbolToDelete = varRef->get_symbol();
15616 varRef->set_symbol(isSgVariableSymbol(realSymbol));
15619 if (varList.empty())
15621 VariantVector vv(V_SgVarRefExp);
15622 varList = NodeQuery::queryMemoryPool(vv);
15625 for (Rose_STL_Container<SgNode*>::iterator i = varList.begin();
15626 i != varList.end(); ++i)
15630 if (var->get_symbol() == symbolToDelete)
15640 delete symbolToDelete;
15649 delete (varRef->get_symbol());
15653 varRef->set_symbol(isSgVariableSymbol(realSymbol));
15660 if (cleanUnusedSymbols)
15667 Rose_STL_Container<SgNode*> symbolList;
15668 VariantVector sym_vv(V_SgVariableSymbol);
15669 symbolList = NodeQuery::queryMemoryPool(sym_vv);
15671 Rose_STL_Container<SgNode*> varList;
15672 VariantVector var_vv(V_SgVarRefExp);
15676 varList = NodeQuery::querySubTree(root, V_SgVarRefExp);
15679 for (Rose_STL_Container<SgNode*>::iterator i = symbolList.begin();
15680 i != symbolList.end(); ++i)
15683 ROSE_ASSERT(symbolToDelete);
15687 bool toDelete =
true;
15691 for (Rose_STL_Container<SgNode*>::iterator j = varList.begin();
15692 j != varList.end(); ++j)
15697 if (var->get_symbol() == symbolToDelete)
15708 std::cout <<
"Symbol " << symbolToDelete->
get_name().str() <<
' ' << symbolToDelete <<
15709 ' ' << symbolToDelete->get_declaration() <<
" is deleted." << std::endl;
15711 delete symbolToDelete->get_declaration();
15712 delete symbolToDelete;
15725 ROSE_ASSERT(label_stmt);
15734 if (isSgFunctionDefinition(scope) !=
nullptr)
15736 ASSERT_not_null(label_scope);
15742 SgLabelSymbol* lsymbol = label_scope->lookup_label_symbol(name);
15744 if (lsymbol ==
nullptr)
15749 ASSERT_not_null(lsymbol);
15761 ROSE_ASSERT (stmt != NULL);
15762 ROSE_ASSERT (label_value >0 && label_value <=99999);
15765 if (label_scope == NULL)
15769 ROSE_ASSERT (label_scope != NULL);
15771 SgLabelSymbol * symbol = label_scope->lookup_label_symbol (label_name);
15772 if (symbol == NULL)
15778 ROSE_ASSERT(symbol != NULL);
15779 symbol->set_fortran_statement(stmt);
15780 symbol->set_numeric_label_value(label_value);
15785 cerr<<
"Error. SageInterface::setFortranNumericLabel() tries to set a duplicated label value!"<<endl;
15786 ROSE_ASSERT (
false);
15795 case SgLabelSymbol::e_start_label_type:
15797 stmt->set_numeric_label(ref_exp);
15800 case SgLabelSymbol::e_end_label_type:
15802 stmt->set_end_numeric_label(ref_exp);
15807 std::cerr <<
"SageInterface::setFortranNumericLabel: unimplemented for label_type " << label_type <<
"\n";
15819 ROSE_ASSERT (func_def != NULL);
15824 std::set<SgNode*>::iterator iter ;
15825 for (iter=symbols.begin(); iter !=symbols.end(); iter++)
15830 int cur_val = l_symbol->get_numeric_label_value();
15831 if (result <=cur_val)
15832 result = cur_val +10;
15836 ROSE_ASSERT (result <= 99999);
15847 ROSE_ASSERT(scope != NULL);
15852 ROSE_ASSERT(fTable != NULL);
15859 printf (
"WARNING: Skip setting the scope of the SgFunctionTypeTable scope = %p = %s \n",scope,scope->
class_name().c_str());
15865 printf (
"In SageInterface::fixStatement(): stmt = %p = %s \n",stmt,stmt->
class_name().c_str());
15878 if (tmfunc != NULL)
15879 assert(tmfunc->
variantT() == V_SgTemplateMemberFunctionDeclaration);
15880 else if (mfunc != NULL)
15881 assert(mfunc->
variantT() == V_SgMemberFunctionDeclaration || mfunc->
variantT() == V_SgTemplateInstantiationMemberFunctionDecl);
15882 else if (tfunc != NULL)
15883 assert(tfunc->
variantT() == V_SgTemplateFunctionDeclaration);
15884 else if (procfunc != NULL)
15885 assert(procfunc->
variantT() == V_SgProcedureHeaderStatement);
15886 else if (progfunc != NULL)
15887 assert(progfunc->
variantT() == V_SgProgramHeaderStatement);
15888 else if (func != NULL)
15889 assert(func->
variantT() == V_SgFunctionDeclaration || func->
variantT() == V_SgTemplateInstantiationFunctionDecl);
15893 printf (
"In SageInterface::fixStatement(): scope = %p = %s \n",scope,scope->
class_name().c_str());
15894 printf (
"In SageInterface::fixStatement(): stmt->get_scope() = %p \n",stmt->
get_scope());
15906 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());
15912 if (tmfunc != NULL)
15914 SgTemplateParameterPtrList & templateParameterList = tmfunc->get_templateParameters();
15917 func_symbol = scope->lookup_template_member_function_symbol (func->get_name(), func->get_type(),&templateParameterList);
15919 else if (mfunc != NULL)
15922 SgTemplateArgumentPtrList* templateArgumentList = (templateInstantiationMemberFunctionDecl != NULL) ? &(templateInstantiationMemberFunctionDecl->
get_templateArguments()) : NULL;
15924 func_symbol = scope->lookup_nontemplate_member_function_symbol (func->get_name(), func->get_type(),templateArgumentList);
15926 else if (tfunc != NULL)
15928 SgTemplateParameterPtrList & templateParameterList = tfunc->get_templateParameters();
15930 printf (
"In SageInterface::fixStatement(): templateParameterList.size() = %" PRIuPTR
" \n",templateParameterList.size());
15934 func_symbol = scope->lookup_template_function_symbol (func->get_name(), func->get_type(),&templateParameterList);
15936 else if (procfunc != NULL)
15939 printf (
"In SageInterface::fixStatement(): procfunc->get_name() = %s calling lookup_function_symbol() \n",procfunc->get_name().str());
15941 func_symbol = scope->lookup_function_symbol (procfunc->get_name(), procfunc->get_type());
15942 assert(func_symbol != NULL);
15944 else if (progfunc != NULL)
15946 func_symbol = scope->lookup_function_symbol (progfunc->get_name(), progfunc->get_type());
15947 assert(func_symbol != NULL);
15949 else if (func != NULL)
15952 printf (
"In SageInterface::fixStatement(): func->get_name() = %s calling lookup_function_symbol() \n",func->get_name().str());
15955 SgTemplateArgumentPtrList* templateArgumentList = (templateInstantiationFunctionDecl != NULL) ? &(templateInstantiationFunctionDecl->
get_templateArguments()) : NULL;
15957 func_symbol = scope->lookup_function_symbol (func->get_name(), func->get_type(),templateArgumentList);
15962 if (func_symbol == NULL)
15974 printf (
"In SageInterface::fixStatement(): func_symbol = %p \n",func_symbol);
15976 assert(func_symbol != NULL);
15987 printf (
"Need to handle SgTemplateDeclaration IR nodes as well...(implement later) \n");
15995 if (isSgVariableDeclaration(stmt))
16002 ROSE_ASSERT(classDeclaration !=
nullptr);
16005 else if (isSgClassDeclaration(stmt))
16009 else if (isSgLabelStatement(stmt))
16013 else if (isSgFunctionDeclaration(stmt))
16021 ROSE_ASSERT(fTable);
16030 printf (
"In SageInterface::fixStatement(): scope = %p = %s \n",scope,scope->
class_name().c_str());
16031 printf (
"In SageInterface::fixStatement(): stmt->get_scope() = %p \n",stmt->
get_scope());
16042 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());
16044 SgFunctionSymbol* func_symbol = scope->lookup_function_symbol (func->get_name(), func->get_type());
16046 printf (
"In SageInterface::fixStatement(): func_symbol = %p \n",func_symbol);
16047 if (func_symbol == NULL)
16059 ROSE_ASSERT (func_symbol != NULL);
16065 printf (
"In SageInterface::fixStatement(): found a valid function so no need to insert new symbol \n");
16073 if (local_symbol == NULL)
16078 if (func != src_func )
16088 else if (isSgTemplateDeclaration(stmt) != NULL)
16103 case V_SgEnumDeclaration:
16104 case V_SgTemplateDeclaration:
16105 case V_SgTypedefDeclaration:
16106 case V_SgFunctionDeclaration:
16107 case V_SgMemberFunctionDeclaration:
16108 case V_SgTemplateInstantiationFunctionDecl:
16123 printf (
"In SageInterface::fixStatement(): switch default case used (likely OK): stmt = %p = %s \n",stmt,stmt->
class_name().c_str());
16126 printf (
"switch case not handled properly: stmt = %p = %s \n",stmt,stmt->
class_name().c_str());
16158 ROSE_ASSERT(func != NULL && scope != NULL);
16160 ROSE_ASSERT(func != NULL);
16161 ROSE_ASSERT(scope != NULL);
16163 SgStatementPtrList stmtList, sameFuncList;
16170 SgDeclarationStatementPtrList::iterator i;
16171 for (i=declList.begin();i!=declList.end();i++)
16172 stmtList.push_back(*i);
16180 if (firstNondefiningFunctionDeclaration != NULL)
16185 printf (
"In SageInterface::updateDefiningNondefiningLinks(): func = %p Found a valid pointer to a firstNondefiningFunctionDeclaration = %p \n",func,firstNondefiningFunctionDeclaration);
16196 printf (
"WARNING: symbol for func->get_firstNondefiningDeclaration() = %p = %s = %s is not present in the scope = %p = %s associated with the firstNondefiningDeclaration \n",
16204 SgSymbol* functionSymbol = scope->lookup_function_symbol(func->get_name(),func->get_type());
16205 if (functionSymbol != NULL)
16207 printf (
"In SageInterface::updateDefiningNondefiningLinks(): func = %p Found a valid symbol = %p \n",func,functionSymbol);
16211 printf (
"In SageInterface::updateDefiningNondefiningLinks(): func = %p functionSymbol == NULL \n",func);
16216 SgStatementPtrList::iterator j;
16217 for (j = stmtList.begin(); j != stmtList.end(); j++)
16220 if (func_decl != NULL)
16227 sameFuncList.push_back(func_decl);
16233 printf (
"func = %p \n",func);
16237 ROSE_ASSERT(func != NULL);
16241 for (j = sameFuncList.begin(); j != sameFuncList.end(); j++)
16246 ROSE_ASSERT(func != NULL);
16249 ROSE_ASSERT(sameFuncList.empty() ==
false);
16251 if (func == isSgFunctionDeclaration(*(sameFuncList.begin())))
16253 for (j = sameFuncList.begin(); j != sameFuncList.end(); j++)
16257 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 1) Testing j = %p set_firstNondefiningDeclaration(%p) \n",*j,func);
16261 if (func_decl != func)
16268 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 1) Calling j = %p set_firstNondefiningDeclaration(%p) \n",*j,func);
16278 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 2) Testing func = %p set_firstNondefiningDeclaration(%p) \n",func,isSgFunctionDeclaration(*(sameFuncList.begin()))->
get_firstNondefiningDeclaration());
16285 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 2) Calling func = %p set_firstNondefiningDeclaration(%p) \n",func,isSgFunctionDeclaration(*(sameFuncList.begin()))->
get_firstNondefiningDeclaration());
16294 assert(source_file != NULL);
16295 assert(position == PreprocessingInfo::before || position == PreprocessingInfo::after);
16297 SgGlobal * global_scope = source_file->get_globalScope();
16300 ROSE_ASSERT(result);
16316 PreprocessingInfo::DirectiveType dtype )
16318 ASSERT_not_null(target);
16321 PreprocessingInfo::DirectiveType mytype=dtype;
16326 if (mytype == PreprocessingInfo::CpreprocessorUnknownDeclaration)
16332 mytype = PreprocessingInfo::C_StyleComment;
16337 mytype = PreprocessingInfo::CplusplusStyleComment;
16342 mytype = PreprocessingInfo::F90StyleComment;
16347 mytype = PreprocessingInfo::AdaStyleComment;
16352 mytype = PreprocessingInfo::JovialStyleComment;
16356 cout <<
"WARNING: SageInterface::attachComment(): Unknown programming language \n";
16362 bool resetPositionInfo =
false;
16365 case PreprocessingInfo::C_StyleComment: comment =
"/* " + content +
" */";
break;
16366 case PreprocessingInfo::CplusplusStyleComment: comment =
"// " + content;
break;
16367 case PreprocessingInfo::FortranStyleComment: comment =
" C " + content;
break;
16368 case PreprocessingInfo::F90StyleComment: comment =
"!" + content;
break;
16369 case PreprocessingInfo::AdaStyleComment: comment =
"-- " + content;
break;
16370 case PreprocessingInfo::JovialStyleComment:
16374 case PreprocessingInfo::CpreprocessorLineDeclaration:
16375 comment =
"#myline " + content;
16376 mytype = PreprocessingInfo::CplusplusStyleComment;
16377 resetPositionInfo =
true;
16379 case PreprocessingInfo::CpreprocessorIfndefDeclaration: comment =
"#ifndef " + content +
"\n";
break;
16380 case PreprocessingInfo::CpreprocessorDefineDeclaration: comment =
"#define " + content +
"\n";
break;
16381 case PreprocessingInfo::CpreprocessorEndifDeclaration: comment =
"#endif" + (content.empty() ?
"\n" : (
" /* " + content +
" */\n"));
break;
16382 case PreprocessingInfo::CpreprocessorEnd_ifDeclaration: comment =
"#end if" + (content.empty() ?
"\n" : (
" /* " + content +
" */\n"));
break;
16386 printf (
"Error: default in switch reached in SageInterface::attachComment() PreprocessingInfo::DirectiveType == %d \n",mytype);
16391 result =
new PreprocessingInfo (mytype,comment,
"transformation-generated", 0, 0, 0, position);
16394 if (resetPositionInfo ==
true)
16397 *(result->get_file_info()) = *(target->get_file_info());
16407 ASSERT_not_null(result);
16408 target->addToAttachedPreprocessingInfo(result);
16414 PreprocessingInfo::CpreprocessorIfDeclaration,
16416 "transformation-generated", 0, 0, 0,
16417 PreprocessingInfo::before
16419 target->addToAttachedPreprocessingInfo(if_macro);
16422 PreprocessingInfo::CpreprocessorEndifDeclaration,
16424 "transformation-generated", 0, 0, 0,
16425 PreprocessingInfo::after
16427 target->addToAttachedPreprocessingInfo(endif_macro);
16440static map<SgSourceFile*, map<string, PreprocessingInfo*> > fileHeaderDict;
16445 if (isSystemHeader)
16446 header_key=
"<"+header_file_name+
">";
16448 header_key=
"\""+header_file_name+
"\"";
16450 if (fileHeaderDict.count(source_file) && fileHeaderDict[source_file].count(header_key))
16451 return fileHeaderDict[source_file][header_key];
16453 vector<SgLocatedNode*> candidates;
16456 SgGlobal* global= source_file -> get_globalScope();
16458 candidates.push_back(global);
16461 SgDeclarationStatementPtrList decl_stmt_list = global->
get_declarations();
16462 for (SgDeclarationStatementPtrList::iterator iter= decl_stmt_list.begin(); iter!=decl_stmt_list.end(); iter++)
16463 candidates.push_back(*iter);
16465 bool found =
false;
16466 for (
size_t ci=0; ci<candidates.size(); ci++)
16471 if (comments == NULL)
continue;
16472 AttachedPreprocessingInfoType::iterator i;
16473 for (i = comments->begin (); i != comments->end (); i++)
16475 if ((*i)->getTypeOfDirective () != PreprocessingInfo::CpreprocessorIncludeDeclaration)
continue;
16476 string content = (*i)->getString ();
16477 if (content.find(header_key) != string::npos)
16479 fileHeaderDict[source_file][header_key] = *i;
16490 return fileHeaderDict[source_file][header_key];
16500 bool supportTokenUnparsing =
false;
16502 assert(source_file != NULL);
16503 assert(position == PreprocessingInfo::before || position == PreprocessingInfo::after);
16505 SgGlobal * global_scope = source_file->get_globalScope();
16508 if (isSystemHeader)
16509 content =
"#include <" + header_file_name +
"> \n";
16511 content =
"#include \"" + header_file_name +
"\" \n";
16514 ROSE_ASSERT(result);
16522 supportTokenUnparsing = source_file->get_unparse_tokens();
16523 bool supportUnparseHeaders = source_file->get_unparseHeaderFiles();
16526 printf (
"supportTokenUnparsing = %s \n",supportTokenUnparsing ?
"true" :
"false");
16527 printf (
"supportUnparseHeaders = %s \n",supportUnparseHeaders ?
"true" :
"false");
16528 printf (
"source_file = %p \n",source_file);
16529 printf (
"global_scope = %p \n",global_scope);
16532 printf (
"Exiting as a test! \n");
16537 if (supportTokenUnparsing ==
false)
16546 if (supportUnparseHeaders ==
true)
16551 printf (
"physical_file_id = %d \n",physical_file_id);
16556 printf (
"Exiting as a test! \n");
16563 global_scope->prepend_statement(emptyDeclaration);
16567 printf (
"Exiting as a test! \n");
16568 ROSE_ASSERT(
false);
16579 bool supportTokenUnparsing =
false;
16585 printf (
"In SageInterface::insertHeader(): filename = %s \n",filename.c_str());
16586 printf (
" --- position = %s \n",PreprocessingInfo::relativePositionName(position).c_str());
16592 ROSE_ASSERT(scope);
16595 ROSE_ASSERT(globalScope != NULL);
16603 if (isSystemHeader)
16604 content =
"#include <" + filename +
"> \n";
16606 content =
"#include \"" + filename +
"\" \n";
16615 ROSE_ASSERT(sourceFile != NULL);
16617 supportTokenUnparsing = sourceFile->get_unparse_tokens();
16619 bool supportUnparseHeaders = sourceFile->get_unparseHeaderFiles();
16621 if (supportUnparseHeaders)
16624 string suffix = Rose::StringUtility ::fileNameSuffix(filename);
16627 if (suffix==
"h" ||suffix==
"hpp"|| suffix==
"hh"||suffix==
"H" ||suffix==
"hxx"||suffix==
"h++" ||suffix==
"tcc")
16632 printf (
"supportTokenUnparsing = %s \n",supportTokenUnparsing ?
"true" :
"false");
16633 printf (
"supportUnparseHeaders = %s \n",supportUnparseHeaders ?
"true" :
"false");
16634 printf (
"sourceFile = %p \n",sourceFile);
16635 printf (
"globalScope = %p \n",globalScope);
16638 printf (
"supportTokenUnparsing = %s \n",supportTokenUnparsing ?
"true" :
"false");
16641 printf (
"Exiting as a test! \n");
16645 SgDeclarationStatementPtrList & stmtList = globalScope->
get_declarations();
16648 printf (
"stmtList.size() = %zu \n",stmtList.size());
16651 if (stmtList.size() > 0)
16653 for (SgDeclarationStatementPtrList::iterator j = stmtList.begin (); j != stmtList.end (); j++)
16657 if ( ((*j)->get_file_info())->isSameFile(srcScope->
get_file_info ()) || ((*j)->get_file_info ())->isTransformation() )
16659 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration, content,
"Transformation generated",0, 0, 0, PreprocessingInfo::before);
16660 ROSE_ASSERT(result != NULL);
16662 printf (
"Building a PreprocessingInfo: result = %p \n",result);
16670 if (supportTokenUnparsing ==
false)
16672 (*j)->addToAttachedPreprocessingInfo(result,position);
16676 (*j)->addToAttachedPreprocessingInfo(result,position);
16678 printf (
"In SageInterface::insertHeader(): Calling set_containsTransformationToSurroundingWhitespace(true) \n");
16682 (*j)->set_containsTransformationToSurroundingWhitespace(
true);
16691 printf (
"In SageInterface::insertHeader(): declarationStatement = %p = %s \n",declarationStatement,declarationStatement->
class_name().c_str());
16692 printf (
"In SageInterface::insertHeader(): declarationStatement->get_containsTransformationToSurroundingWhitespace() = %s \n",
16693 declarationStatement->get_containsTransformationToSurroundingWhitespace() ?
"true" :
"false");
16700 if (supportUnparseHeaders ==
true)
16705 printf (
"physical_file_id = %d \n",physical_file_id);
16707 emptyDeclaration->get_startOfConstruct()->set_physical_file_id(physical_file_id);
16708 emptyDeclaration->get_endOfConstruct()->set_physical_file_id(physical_file_id);
16710 printf (
"Exiting as a test! \n");
16711 ROSE_ASSERT(
false);
16715 emptyDeclaration->addToAttachedPreprocessingInfo(result, position);
16721 printf (
"break out of for loop: result = %p \n",result);
16731 cerr<<
"SageInterface::insertHeader() Empty file is found!"<<endl;
16732 cerr<<
"#include xxx is preprocessing information which has to be attached to some other located node (a statement for example)"<<endl;
16733 cerr<<
"You may have to insert some statement first before inserting a header"<<endl;
16734 ROSE_ASSERT(
false);
16735 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration, content,
"Transformation generated",0, 0, 0, PreprocessingInfo::after);
16736 ROSE_ASSERT(result);
16747 if (result != NULL)
16758 printf (
"Exiting as a test! \n");
16759 ROSE_ASSERT(
false);
16763 printf (
"Leaving SageInterface::insertHeader(): filename = %s \n",filename.c_str());
16767 printf (
"Exiting as a test! \n");
16768 ROSE_ASSERT(
false);
16778 ROSE_ASSERT (stmt != NULL);
16779 ROSE_ASSERT (newheader != NULL);
16782 printf (
"In SageInterface::insertHeader (SgStatement* stmt, PreprocessingInfo* newheader, bool asLastHeader) \n");
16788 position = PreprocessingInfo::after;
16790 position = PreprocessingInfo::before;
16796 if (comments != NULL)
16805 AttachedPreprocessingInfoType::iterator i, firsti, lasti;
16806 for (i = comments->begin (); i != comments->end (); i++)
16813 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration)
16816 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration)
16818 if (firstExistingHeader == NULL)
16820 firstExistingHeader = (*i);
16824 lastExistingHeader = (*i);
16830 if ( (*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration ||
16831 (*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorEndifDeclaration )
16834 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration)
16836 if (firstExistingHeader == NULL)
16838 firstExistingHeader = (*i);
16842 lastExistingHeader = (*i);
16845 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorEndifDeclaration)
16847 if (firstExistingEndif == NULL)
16849 firstExistingEndif = (*i);
16864 if (lastExistingHeader == NULL)
16868 comments->insert (lasti+1, newheader);
16873 if (firstExistingHeader == NULL)
16877 comments->insert (firsti, newheader);
16885 printf (
"Exiting as a test! \n");
16886 ROSE_ASSERT(
false);
16895 ROSE_ASSERT (source_file != NULL);
16896 SgGlobal* globalScope = source_file->get_globalScope();
16897 ROSE_ASSERT (globalScope != NULL);
16901 if (isSystemHeader)
16902 content =
"#include <" + filename +
"> \n";
16904 content =
"#include \"" + filename +
"\" \n";
16911 position = PreprocessingInfo::after;
16913 position = PreprocessingInfo::before;
16916 SgDeclarationStatementPtrList & stmtList = globalScope->
get_declarations ();
16917 if (stmtList.size()>0)
16919 for (SgDeclarationStatementPtrList::iterator j = stmtList.begin (); j != stmtList.end (); j++)
16924 if ( (*j)->get_file_info()->isSameFile(globalScope->
get_file_info()) || (*j)->get_file_info()->isTransformation() )
16927 printf (
"In SageInterface::insertHeader(): Found statement to attached #include: *j = %p = %s \n",*j,(*j)->class_name().c_str());
16928 printf (
" --- unparseToString() = %s \n",(*j)->unparseToString().c_str());
16930 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration, content,
"Transformation generated",0, 0, 0, PreprocessingInfo::before);
16931 ROSE_ASSERT(result);
16935 printf (
"Exiting as a test! \n");
16944 cerr<<
"SageInterface::insertHeader() Empty file is found!"<<endl;
16945 cerr<<
"#include xxx is preprocessing information which has to be attached to some other located node (a statement for example)"<<endl;
16946 cerr<<
"You may have to insert some statement first before inserting a header"<<endl;
16949 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,
16950 content,
"Transformation generated",0, 0, 0, PreprocessingInfo::after);
16951 ROSE_ASSERT(result);
16958 printf (
"In SageInterface::insertHeader(): Marking include file for filename = %s as a transformation \n",filename.c_str());
16968 printf (
"Exiting as a test! \n");
16969 ROSE_ASSERT(
false);
16987 ROSE_ASSERT(target != NULL);
16994 PreprocessingInfo::DirectiveType mytype = PreprocessingInfo::CpreprocessorIfDeclaration;
16997 printf (
"Warning: attachArbitraryText(): attaching arbitrary text to the AST as a #if declaration: text = %s \n",text.c_str());
16999 result =
new PreprocessingInfo (mytype,text,
"transformation-generated", 0, 0, 0, position);
17000 ROSE_ASSERT(result);
17007 target->addToAttachedPreprocessingInfo(result);
17021 ROSE_ASSERT(target != NULL);
17022 AttachedPreprocessingInfoType *info= target->getAttachedPreprocessingInfo ();
17023 if (info == NULL)
return;
17024 AttachedPreprocessingInfoType::iterator j;
17025 for (j = info->begin (); j != info->end (); j++)
17027 if ((*j)->getTypeOfDirective()==PreprocessingInfo::CMacroCall)
17029#ifndef ROSE_SKIP_COMPILATION_OF_WAVE
17031 std::ostringstream os;
17032 token_container tc = (*j)->get_macro_call()->expanded_macro;
17033 token_container::const_iterator iter;
17034 for (iter=tc.begin(); iter!=tc.end(); iter++)
17035 os<<(*iter).get_value();
17038 string pragmaText = target->get_pragma()->get_pragma();
17039 string targetString = (*j)->getString();
17040 string replacement = os.str();
17042 size_t pos1 = pragmaText.find(targetString);
17043 while (pos1 != string::npos)
17045 pragmaText.replace(pos1, targetString.size(), replacement);
17046 pos1 = pragmaText.find(targetString);
17048 delete target->get_pragma();
17062 if (isSgWhileStmt(loopOrSwitch) || isSgDoWhileStmt(loopOrSwitch) ||
17063 isSgForStatement(loopOrSwitch)) {
17065 }
else if (isSgSwitchStatement(loopOrSwitch)) {
17066 body = isSgSwitchStatement(loopOrSwitch)->
get_body();
17068 ROSE_ASSERT (body);
17070 if (!breaks.empty()) {
17071 static int breakLabelCounter = 0;
17076 isSgScopeStatement(loopOrSwitch->
get_parent()));
17078 for (
size_t j = 0; j < breaks.size(); ++j) {
17083 newGoto->
set_parent(breaks[j]->get_parent());
17090 ROSE_ASSERT(node!=NULL);
17100 ROSE_ASSERT(node!=NULL);
17113 ROSE_ASSERT(stmt_src != NULL);
17114 ROSE_ASSERT(stmt_dst != NULL);
17117 if (infoList == NULL)
17120 printf (
"In SageInterface::movePreprocessingInfo(): infoList == NULL: exiting movePreprocessingInfo() \n");
17125 AttachedPreprocessingInfoType* infoToRemoveList =
new AttachedPreprocessingInfoType();
17128 printf (
"In SageInterface::movePreprocessingInfo(): \n");
17129 printf (
" --- stmt_src = %p = %s src_position = %d \n",stmt_src,stmt_src->
class_name().c_str(),src_position);
17131 if (src_declarationStatement != NULL)
17134 printf (
"src_declarationStatement->get_definingDeclaration() = %p \n",src_declarationStatement->
get_definingDeclaration());
17136 printf (
" --- stmt_dst = %p = %s dst_position = %d \n",stmt_dst,stmt_dst->
class_name().c_str(),dst_position);
17138 if (dst_declarationStatement != NULL)
17141 printf (
"dst_declarationStatement->get_definingDeclaration() = %p \n",dst_declarationStatement->
get_definingDeclaration());
17143 printf (
" --- src_position = %s \n",PreprocessingInfo::relativePositionName(src_position).c_str());
17144 printf (
" --- dst_position = %s \n",PreprocessingInfo::relativePositionName(dst_position).c_str());
17145 printf (
" --- usePrepend = %s \n",usePrepend ?
"true" :
"false");
17147 printf (
" --- infoList = %p \n",infoList);
17148 printf (
" --- infoToRemoveList = %p \n",infoToRemoveList);
17151 printf (
" --- dst_infoList = %p \n",dst_infoList);
17154 printf (
"****************************************************************** \n");
17155 printf (
"In SageInterface::movePreprocessingInfo(): Attached comments and CPP directives: stmt_src \n");
17157 printf (
"In SageInterface::movePreprocessingInfo(): Attached comments and CPP directives: stmt_dst \n");
17159 printf (
"****************************************************************** \n");
17169 printf (
" --- infoList->size() = %zu \n",infoList->size());
17170 printf (
" --- infoToRemoveList->size() = %zu \n",infoToRemoveList->size());
17176 for (Rose_STL_Container<PreprocessingInfo*>::iterator i = (*infoList).begin(); i != (*infoList).end(); i++)
17179 ROSE_ASSERT(*i != NULL);
17184 ROSE_ASSERT(info != NULL);
17187 printf (
"counter = %d Processing PreprocessingInfo = %s \n",counter,info->getString().c_str());
17196 for (Rose_STL_Container<PreprocessingInfo*>::iterator i = (*infoList).begin(); i != (*infoList).end(); i++)
17198 ROSE_ASSERT(*i != NULL);
17201 ROSE_ASSERT(info != NULL);
17204 (info->getTypeOfDirective()==PreprocessingInfo::C_StyleComment)||
17205 (info->getTypeOfDirective()==PreprocessingInfo::CplusplusStyleComment)||
17206 (info->getTypeOfDirective()==PreprocessingInfo::FortranStyleComment)||
17207 (info->getTypeOfDirective()==PreprocessingInfo::F90StyleComment)||
17208 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIncludeDeclaration )||
17209 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIncludeNextDeclaration )||
17210 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorDefineDeclaration )||
17211 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorUndefDeclaration)||
17212 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIfdefDeclaration )||
17213 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIfndefDeclaration )||
17214 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIfDeclaration )||
17215 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorDeadIfDeclaration )||
17216 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorElseDeclaration )||
17217 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorElifDeclaration )||
17218 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorEndifDeclaration ) ||
17219 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorEnd_ifDeclaration ) ||
17220 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorLineDeclaration) ||
17221 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorErrorDeclaration) ||
17222 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorWarningDeclaration) ||
17224 (info->getTypeOfDirective()==PreprocessingInfo::ClinkageSpecificationStart) ||
17225 (info->getTypeOfDirective()==PreprocessingInfo::ClinkageSpecificationEnd)
17230 if ( src_position == PreprocessingInfo::undef || info->getRelativePosition() == src_position)
17232 if (usePrepend ==
true)
17235 if (prevItem == NULL)
17253 info->setAsTransformation();
17261 stmt_dst->set_containsTransformationToSurroundingWhitespace(
true);
17262 if (isMarkedAsModified ==
false)
17269 (*infoToRemoveList).push_back(*i);
17273 if (dst_position != PreprocessingInfo::undef)
17275 info->setRelativePosition(dst_position);
17281 AttachedPreprocessingInfoType::iterator j;
17282 for (j = (*infoToRemoveList).begin(); j != (*infoToRemoveList).end(); j++)
17284 infoList->erase( find(infoList->begin(),infoList->end(),*j) );
17320 return info && (info->getRelativePosition () != pos);
17330 return info && !isNotRelPos (info, pos);
17337 ASSERT_not_null(src_node);
17340 AttachedPreprocessingInfoType* info = src_node->get_attachedPreprocessingInfoPtr();
17344 remove_copy_if(info->begin(),
17346 back_inserter(save_buf),
17347 [pos](
auto x) {
return !isRelPos(x, pos); }
17351 AttachedPreprocessingInfoType::iterator
17352 new_end = remove_if(info->begin(),
17354 [pos](
auto x) { return isRelPos(x, pos); }
17356 info->erase(new_end, info->end());
17360static AttachedPreprocessingInfoType *
17364 AttachedPreprocessingInfoType* info_list = s->get_attachedPreprocessingInfoPtr ();
17367 info_list =
new AttachedPreprocessingInfoType;
17368 ROSE_ASSERT (info_list);
17369 s->set_attachedPreprocessingInfoPtr (info_list);
17373 ROSE_ASSERT (info_list);
17380 if (save_buf.size()==0)
return;
17382 AttachedPreprocessingInfoType* info = createInfoList (dst_node);
17383 ROSE_ASSERT (info);
17390 if (pos==PreprocessingInfo::before)
17392 for(AttachedPreprocessingInfoType::reverse_iterator i=save_buf.rbegin();i!=save_buf.rend();i++)
17393 info->insert(info->begin(),*i);
17396 else if (pos==PreprocessingInfo::after)
17397 copy (save_buf.begin (), save_buf.end (), back_inserter (*info));
17398 else if (pos==PreprocessingInfo::inside)
17400 copy (save_buf.begin (), save_buf.end (), back_inserter (*info));
17401 cerr<<
"SageInterface::pastePreprocessingInfo() pos==PreprocessingInfo::inside is not supported."<<endl;
17402 save_buf[0]->display(
"ttt");
17408 ROSE_ASSERT(locatedNode != NULL);
17409 AttachedPreprocessingInfoType *comments =
17412 if (comments != NULL)
17414 printf (
"-----------------------------------------------\n");
17415 printf (
"Found an IR node (at %p of type: %s) in file %s \n",
17416 locatedNode, locatedNode->
class_name ().c_str (),
17417 (locatedNode->
get_file_info ()->get_filenameString ()).c_str ());
17419 AttachedPreprocessingInfoType::iterator i;
17420 for (i = comments->begin (); i != comments->end (); i++)
17423 (
"with attached preprocessingInfo numbering #%d :------------- \nclassification= %s:\nString format:%s\n",
17425 PreprocessingInfo::directiveTypeName ((*i)->getTypeOfDirective ()).
17426 c_str (), (*i)->getString ().c_str ());
17427 if ((*i)->getRelativePosition () == PreprocessingInfo::inside)
17428 printf (
"relative position is: inside\n");
17430 printf (
"relative position is: %s\n", \
17431 ((*i)->getRelativePosition () == PreprocessingInfo::before) ?
"before" :
"after");
17436 printf (
"No attached preprocessing info. (at %p of type: %s): \n", locatedNode,
17452template <
class ParentNode>
17462 if (basicblock == NULL) {
17464 (stmt.*setter)(basicblock);
17468 ROSE_ASSERT (basicblock != NULL);
17475 if (!isSgBasicBlock(b)) {
17483 ROSE_ASSERT (isSgBasicBlock(b));
17484 return isSgBasicBlock(b);
17490 if (!isSgBasicBlock(b)) {
17498 ROSE_ASSERT (isSgBasicBlock(b));
17499 return isSgBasicBlock(b);
17505 if (!isSgBasicBlock(b)) {
17513 ROSE_ASSERT (isSgBasicBlock(b));
17514 return isSgBasicBlock(b);
17519 ROSE_ASSERT (fs != NULL);
17521 return ensureBasicBlock_aux(*fs, &SgUpcForAllStatement::get_loop_body, &SgUpcForAllStatement::set_loop_body);
17526 if (!isSgBasicBlock(b)) {
17534 ROSE_ASSERT (isSgBasicBlock(b));
17535 return isSgBasicBlock(b);
17540 if (!isSgBasicBlock(b)) {
17548 ROSE_ASSERT (isSgBasicBlock(b));
17549 return isSgBasicBlock(b);
17554 if (!isSgBasicBlock(b)) {
17562 ROSE_ASSERT (isSgBasicBlock(b));
17563 return isSgBasicBlock(b);
17568 if (!isSgBasicBlock(b)) {
17576 printf (
"In SageInterface::ensureBasicBlockAsTrueBodyOfIf(): Added SgBasicBlock b = %p to addedBasicBlockNodes.size() = %zu \n",b,addedBasicBlockNodes.size());
17579 ROSE_ASSERT (isSgBasicBlock(b));
17580 return isSgBasicBlock(b);
17590 ROSE_ASSERT(bb != NULL);
17591 addedBasicBlockNodes.push_back(bb);
17593 printf (
"In SageInterface::recordNormalizations(): Added SgBasicBlock = %p to addedBasicBlockNodes.size() = %zu \n",bb,addedBasicBlockNodes.size());
17604 printf (
"In SageInterface::cleanupNontransformedBasicBlockNode(): addedBasicBlockNodes.size() = %zu \n",addedBasicBlockNodes.size());
17607 for (vector<SgBasicBlock*>::iterator i = addedBasicBlockNodes.begin(); i != addedBasicBlockNodes.end(); i++)
17610 ROSE_ASSERT(b != NULL);
17614 printf (
"This SgBasicBlock can be denormalized: b = %p \n",b);
17617 ROSE_ASSERT(parentOfBlock != NULL);
17622 ROSE_ASSERT(s != NULL);
17624 switch (parentOfBlock->
variantT())
17628 SgIfStmt* ifStatement = isSgIfStmt(parentOfBlock);
17632 printf (
"Calling set_true_body on ifStatement = %p = %s \n",ifStatement,ifStatement->
class_name().c_str());
17637 printf (
"Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17642 printf (
"DONE: Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17651 printf (
"Calling set_false_body on ifStatement = %p = %s \n",ifStatement,ifStatement->
class_name().c_str());
17656 printf (
"Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17661 printf (
"DONE: Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17665 printf (
"Mark as NOT modified after calling set_false_body on ifStatement = %p = %n \n",ifStatement,ifStatement->
class_name().c_str());
17668 printf (
"Error: case not handled in case V_SgIfStmt: parentOfBlock = %p = %s \n",parentOfBlock,parentOfBlock->
class_name().c_str());
17676 case V_SgWhileStmt:
17678 SgWhileStmt* whileStatement = isSgWhileStmt(parentOfBlock);
17679 if (b == whileStatement->
get_body())
17688 case V_SgSwitchStatement:
17691 if (b == switchStatement->
get_body())
17700 case V_SgForStatement:
17712 case V_SgCaseOptionStmt:
17714 SgCaseOptionStmt* caseOptionStatement = isSgCaseOptionStmt(parentOfBlock);
17715 if (b == caseOptionStatement->
get_body())
17724 case V_SgDefaultOptionStmt:
17727 if (b == defaultOptionStatement->
get_body())
17729 defaultOptionStatement->
set_body(s);
17736 case V_SgDoWhileStmt:
17738 SgDoWhileStmt* doWhileStatement = isSgDoWhileStmt(parentOfBlock);
17739 if (b == doWhileStatement->
get_body())
17749 printf (
"Error: case not handled in switch: parentOfBlock = %p = %s \n",parentOfBlock,parentOfBlock->
class_name().c_str());
17755 if (wasPreviouslyModified ==
false)
17760 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());
17767 printf (
"Exiting as a test! \n");
17774 printf (
"Leaving SageInterface::cleanupNontransformedBasicBlockNode(): addedBasicBlockNodes.size() = %zu \n",addedBasicBlockNodes.size());
17782 if (!createEmptyBody && (b == NULL || isSgNullStatement(b)))
17784 if (!isSgBasicBlock(b)) {
17792 ROSE_ASSERT (isSgBasicBlock(b));
17793 return isSgBasicBlock(b);
17798 if (!isSgBasicBlock(b)) {
17803 ROSE_ASSERT (isSgBasicBlock(b));
17804 return isSgBasicBlock(b);
17810 if (!isSgBasicBlock(b)) {
17815 ROSE_ASSERT (isSgBasicBlock(b));
17816 return isSgBasicBlock(b);
17828 case V_SgForStatement:
17830 if (isSgForStatement(p)->get_loop_body() == s)
17834 case V_SgUpcForAllStatement:
17837 if (upcforall.get_loop_body() == s)
17841 case V_SgWhileStmt:
17843 if (isSgWhileStmt(p)->get_body() == s)
17847 case V_SgDoWhileStmt:
17849 if (isSgDoWhileStmt(p)->get_body() == s)
17853 case V_SgSwitchStatement:
17855 if (isSgSwitchStatement(p)->get_body() == s)
17859 case V_SgCaseOptionStmt:
17861 if (isSgCaseOptionStmt(p)->get_body() == s)
17865 case V_SgDefaultOptionStmt:
17867 if (isSgDefaultOptionStmt(p)->get_body() == s)
17871 case V_SgCatchOptionStmt:
17873 if (isSgCatchOptionStmt(p)->get_body() == s)
17879 if (isSgIfStmt(p)->get_true_body() == s)
17881 else if (isSgIfStmt(p)->get_false_body() == s)
17887 if (isSgOmpBodyStatement(p))
17899 ROSE_ASSERT (singleStmt != NULL);
17900 ROSE_ASSERT (isSgBasicBlock(singleStmt) == NULL);
17912 case V_SgForStatement:
17914 if (isSgForStatement(p)->get_loop_body() == s)
17918 case V_SgUpcForAllStatement:
17922 if (upcforall.get_loop_body() == s)
17926 case V_SgWhileStmt:
17928 if (isSgWhileStmt(p)->get_body() == s)
17932 case V_SgDoWhileStmt:
17934 if (isSgDoWhileStmt(p)->get_body() == s)
17938 case V_SgSwitchStatement:
17940 if (isSgSwitchStatement(p)->get_body() == s)
17944 case V_SgCaseOptionStmt:
17946 if (isSgCaseOptionStmt(p)->get_body() == s)
17950 case V_SgDefaultOptionStmt:
17952 if (isSgDefaultOptionStmt(p)->get_body() == s)
17956 case V_SgCatchOptionStmt:
17958 if (isSgCatchOptionStmt(p)->get_body() == s)
17964 if (isSgIfStmt(p)->get_true_body() == s)
17966 else if (isSgIfStmt(p)->get_false_body() == s)
17972 if (isSgOmpBodyStatement(p))
17979 ROSE_ASSERT (rt != NULL);
17993 case V_SgBasicBlock:
return isSgBasicBlock(p);
17994 case V_SgForStatement:
17996 if (isSgForStatement(p)->get_loop_body() == s)
17998 else if (isSgForStatement(p)->get_test() == s)
18001 else if (isSgForStatement(p)->get_for_init_stmt() == s)
18007 case V_SgUpcForAllStatement:
18011 if (upcforall.get_loop_body() == s)
18014 ROSE_ASSERT( (s == upcforall.get_for_init_stmt())
18015 || (s == upcforall.get_test())
18019 case V_SgWhileStmt:
18021 if (isSgWhileStmt(p)->get_body() == s)
18023 else if (isSgWhileStmt(p)->get_condition() == s)
18029 case V_SgDoWhileStmt:
18031 if (isSgDoWhileStmt(p)->get_body() == s)
18033 else if (isSgDoWhileStmt(p)->get_condition() == s)
18039 case V_SgSwitchStatement:
18041 if (isSgSwitchStatement(p)->get_body() == s)
18043 else if (isSgSwitchStatement(p)->get_item_selector() == s)
18049 case V_SgCatchOptionStmt:
18051 if (isSgCatchOptionStmt(p)->get_body() == s)
18053 else if (isSgCatchOptionStmt(p)->get_condition() == s)
18061 if (isSgIfStmt(p)->get_true_body() == s)
18063 else if (isSgIfStmt(p)->get_false_body() == s)
18065 else if (isSgIfStmt(p)->get_conditional() == s)
18073 if (isSgOmpBodyStatement(p))
18088 void SageInterface::changeAllLoopBodiesToBlocks(
SgNode* top) {
18089 cerr<<
"Warning: SageInterface::changeAllLoopBodiesToBlocks() is being replaced by SageInterface::changeAllBodiesToBlocks()."<<endl;
18090 cerr<<
"Please use SageInterface::changeAllBodiesToBlocks() if you can."<<endl;
18098 bool allowEmptyBody;
18099 Visitor (
bool flag):allowEmptyBody(flag) {}
18100 virtual void visit(
SgNode* n) {
18105 case V_SgForStatement: {
18109 case V_SgWhileStmt: {
18113 case V_SgDoWhileStmt: {
18117 case V_SgSwitchStatement: {
18126 printf (
"In changeAllBodiesToBlocks(): case SgIfStmt: n->get_isModified() = %s \n",n->
get_isModified() ?
"true" :
"false");
18133 printf (
"In changeAllBodiesToBlocks(): AFTER RESET: case SgIfStmt: n->get_isModified() = %s \n",n->
get_isModified() ?
"true" :
"false");
18138 case V_SgCatchOptionStmt: {
18142 case V_SgUpcForAllStatement: {
18149 if (isSgOmpBodyStatement(n))
18156 if (wasPreviouslyModified ==
false)
18161 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());
18170 Visitor(createEmptyBody).traverse(top, postorder);
18191#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
18192 SgStatement* enclosingStatement = getStatementOfExpression(from);
18193 SgExprStatement* exprStatement = isSgExprStatement(enclosingStatement);
18195 SgForStatement* forStatement = isSgForStatement(enclosingStatement);
18196 SgReturnStmt* returnStatement = isSgReturnStmt(enclosingStatement);
18202 ROSE_ASSERT (exprStatement || forStatement || returnStatement || varDeclarationStatement);
18204 if (varDeclarationStatement)
18211 ROSE_ASSERT (root);
18214 if (forStatement && forStatement->get_increment() == root)
18225 forStatement->get_increment()->
set_parent(incrStmt);
18229 forStatement->set_increment(ne);
18236 assert (enclosingStmtParent);
18237 SgWhileStmt* whileStatement = isSgWhileStmt(enclosingStmtParent);
18238 SgDoWhileStmt* doWhileStatement = isSgDoWhileStmt(enclosingStmtParent);
18239 SgIfStmt* ifStatement = isSgIfStmt(enclosingStmtParent);
18241 SgForStatement* enclosingForStatement = isSgForStatement(enclosingStmtParent);
18242 if (enclosingForStatement && enclosingForStatement->get_test() == exprStatement)
18254 pushTestIntoBody(enclosingForStatement);
18257 else if (whileStatement && whileStatement->
get_condition() == exprStatement)
18270 pushTestIntoBody(whileStatement);
18274 else if (doWhileStatement && doWhileStatement->
get_condition() == exprStatement)
18290 myStatementInsert(doWhileStatement, new_statement,
false);
18292 SgName varname =
"rose__temp1";
18297 varname,
buildBoolType(), assignInitializer, new_statement);
18300 initname->set_scope(new_statement);
18332 else if (ifStatement && ifStatement->
get_conditional() == exprStatement)
18338 myStatementInsert(ifStatement, new_statement,
false);
18340 SgName varname =
"rose__temp2";
18349 initname->set_scope(new_statement);
18374 else if (switchStatement && switchStatement->
get_item_selector() == exprStatement)
18376 SgExpression* switchCond = exprStatement->get_expression();
18377 ROSE_ASSERT (switchCond);
18382 myStatementInsert(switchStatement, new_statement,
false);
18384 SgName varname =
"rose__temp3";
18431#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
18432 SgStatement* stmt = getStatementOfExpression(from);
18434 if (isSgExprStatement(stmt))
18448 if (isSgAssignOp(top) && isSgAssignOp(top)->get_rhs_operand() == from)
18466 convertInitializerIntoAssignment(init);
18469 SgExprStatement* new_stmt = isSgExprStatement(getStatementOfExpression(from));
18470 assert (new_stmt != NULL);
18471 replaceAssignmentStmtWithStatement(new_stmt, to);
18488 ROSE_ASSERT(func&&s);
18490 Rose_STL_Container <SgNode* > stmts = NodeQuery::querySubTree(func, V_SgReturnStmt);
18492 Rose_STL_Container<SgNode*>::iterator i;
18493 for (i=stmts.begin();i!=stmts.end();i++)
18496 ROSE_ASSERT(cur_stmt);
18499 bool needRewrite = (exp != NULL) && !(isSgValueExp(exp));
18510 if (stmts.size()==0 )
18515 cout<<
"In instrumentEndOfFunction(), found an empty function body.! "<<endl;
18527 return ((stmt->get_declarationModifier()).get_storageModifier()).isStatic();
18534 return ((stmt->get_declarationModifier()).get_storageModifier()).setStatic();
18540 return ((stmt->get_declarationModifier()).get_storageModifier()).isExtern();
18548 return ((stmt->get_declarationModifier()).get_storageModifier()).setExtern();
18555 return name->get_storageModifier().isMutable();
18568 std::vector<SgInitializedName*> in_params;
18580 std::vector<SgInitializedName*> out_params;
18590 case V_SgCharVal:
return (
long long)(isSgCharVal(expr)->get_value());
18591 case V_SgSignedCharVal:
return (
long long)(isSgSignedCharVal(expr)->get_value());
18592 case V_SgUnsignedCharVal:
return isSgUnsignedCharVal(expr)->get_value();
18593 case V_SgShortVal:
return (
long long)(isSgShortVal(expr)->get_value());
18594 case V_SgUnsignedShortVal:
return isSgUnsignedShortVal(expr)->get_value();
18595 case V_SgIntVal:
return (
long long)(isSgIntVal(expr)->get_value());
18596 case V_SgUnsignedIntVal:
return isSgUnsignedIntVal(expr)->get_value();
18597 case V_SgLongIntVal:
return (
long long)(isSgLongIntVal(expr)->get_value());
18598 case V_SgUnsignedLongVal:
return isSgUnsignedLongVal(expr)->get_value();
18599 case V_SgLongLongIntVal:
return isSgLongLongIntVal(expr)->get_value();
18600 case V_SgUnsignedLongLongIntVal:
return isSgUnsignedLongLongIntVal(expr)->get_value();
18601 case V_SgBoolValExp:
return (
long long )(isSgBoolValExp(expr)->get_value());
18607 printf (
"ERROR: In SageInterface::getIntegerConstantValue(): default reached: expr = %p = %s \n",expr,expr->
class_name().c_str());
18608 ROSE_ASSERT (
false);
18613 ROSE_ASSERT (!
"Bad kind return in getIntegerConstantValue");
18618#ifdef ROSE_ENABLE_BINARY_ANALYSIS
18627 ROSE_ASSERT(binary!=NULL);
18632 if (1==headers.size()) {
18633 requisite_header = headers[0];
18635 for (SgAsmGenericHeaderPtrList::const_iterator hi=headers.begin(); hi!=headers.end(); ++hi) {
18636 if (isSgAsmPEFileHeader(*hi)) {
18637 requisite_header = isSgAsmPEFileHeader(*hi);
18642 ROSE_ASSERT(requisite_header!=NULL);
18645 const SgAsmInterpretationPtrList &interps = binary->get_interpretations()->
get_interpretations();
18646 for (SgAsmInterpretationPtrList::const_iterator ii=interps.begin(); ii!=interps.end(); ++ii) {
18647 const SgAsmGenericHeaderPtrList &headers = (*ii)->get_headers()->get_headers();
18648 for (SgAsmGenericHeaderPtrList::const_iterator hi=headers.begin(); hi!=headers.end(); ++hi) {
18649 if ((*hi)==requisite_header)
18654 ROSE_ASSERT(!
"no appropriate interpretation");
18667 SgNode* copy = n->copy(*
this);
18671 if (fileInfo != NULL)
18680 } collectDependentDeclarationsCopyType;
18688 vector<PreprocessingInfo*> cppDirectiveList;
18690 void visit(
SgNode *astNode);
18698 if (locatedNode != NULL)
18702 if (comments != NULL)
18705 printf (
"Found attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
sage_class_name());
18707 AttachedPreprocessingInfoType::iterator i;
18708 for (i = comments->begin(); i != comments->end(); i++)
18710 ROSE_ASSERT ( (*i) != NULL );
18712 printf (
" Attached Comment (relativePosition=%s): %s\n",
18713 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
18714 (*i)->getString().c_str());
18715 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
18716 (*i)->get_file_info()->display(
"comment/directive location");
18724 cppDirectiveList.push_back(*i);
18726 printf (
" Attached include directive (relativePosition=%s): %s\n",
18727 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
18728 (*i)->getString().c_str());
18736 printf (
"No attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
sage_class_name());
18747vector<PreprocessingInfo*>
18754 return t.cppDirectiveList;
18758vector<PreprocessingInfo*>
18765 return t.cppDirectiveList;
18770outputPreprocessingInfoList (
const vector<PreprocessingInfo*> & l )
18774 vector<PreprocessingInfo*>::const_iterator i = l.begin();
18775 while ( i != l.end() )
18777 printf (
" Attached include directive (relativePosition=%s): %s\n",
18778 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
18779 (*i)->getString().c_str());
18794 case V_SgNamespaceDefinitionStatement:
18797 declaration = namespaceDefinition->get_namespaceDeclaration();
18801 case V_SgClassDefinition:
18802 case V_SgTemplateInstantiationDefn:
18811 printf (
"Error: default reached in getAssociatedDeclaration(): scope = %p = %s \n",scope,scope->
class_name().c_str());
18817 ROSE_ASSERT(declaration != NULL);
18819 return declaration;
18828 vector<SgDeclarationStatement*> declarationList;
18832 vector<SgSymbol*> symbolList;
18835 set<SgDeclarationStatement*> alreadySavedDeclarations;
18838 void visit(
SgNode *astNode);
18854 ROSE_ASSERT(scope != NULL);
18859 SgGlobal* globalScope = isSgGlobal(scope);
18860 if (globalScope == NULL)
18867 ROSE_ASSERT(parentScope != NULL);
18868 while (globalScope == NULL)
18870 associatedDeclaration = getAssociatedDeclaration(parentScope);
18871 ROSE_ASSERT(associatedDeclaration != NULL);
18873 parentScope = parentScope->
get_scope();
18874 globalScope = isSgGlobal(parentScope);
18880 return returnDeclaration;
18886outputDeclarationList (
const vector<SgDeclarationStatement*> & l )
18891 vector<SgDeclarationStatement*>::const_iterator i = l.begin();
18892 while ( i != l.end() )
18894 printf (
"In outputDeclarationList(): list[%d] = %p = %s = %s \n",counter++,*i,(*i)->class_name().c_str(),
SageInterface::get_name(*i).c_str());
18902 if (declaration != NULL)
18911 if (alreadySavedDeclarations.find(dependentDeclaration) == alreadySavedDeclarations.end())
18914 printf (
"In CollectDependentDeclarationsTraversal::visit(): selected dependentDeclaration = %p = %s = %s \n",
18918 declarationList.push_back(dependentDeclaration);
18921 alreadySavedDeclarations.insert(dependentDeclaration);
18923 printf (
"In CollectDependentDeclarationsTraversal::visit(): astNode = %p = %s = %s \n",astNode,astNode->
class_name().c_str(),
SageInterface::get_name(astNode).c_str());
18924 printf (
"############### ADDING dependentDeclaration = %p = %s to alreadySavedDeclarations set (size = %" PRIuPTR
") \n",
18925 dependentDeclaration,dependentDeclaration->
class_name().c_str(),alreadySavedDeclarations.size());
18933 printf (
"In CollectDependentDeclarationsTraversal::visit(): astNode = %p = %s = %s \n",astNode,astNode->
class_name().c_str(),
SageInterface::get_name(astNode).c_str());
18934 printf (
"############### EXISTING dependentDeclaration = %p = %s found in alreadySavedDeclarations set (size = %" PRIuPTR
") \n",
18935 dependentDeclaration,dependentDeclaration->
class_name().c_str(),alreadySavedDeclarations.size());
18942static std::vector<SgTypedefDeclaration*> collectTypedefDeclarations(
SgType* type)
18944 ROSE_ASSERT(type != NULL);
18945 std::vector<SgTypedefDeclaration*> result;
18946 SgType* currentType = type;
18956 modType = isSgModifierType(currentType);
18959 currentType = modType->get_base_type();
18963 refType = isSgReferenceType(currentType);
18966 currentType = refType->get_base_type();
18970 pointType = isSgPointerType(currentType);
18973 currentType = pointType->get_base_type();
18977 arrayType = isSgArrayType(currentType);
18980 currentType = arrayType->get_base_type();
18984 typedefType = isSgTypedefType(currentType);
18995 result.push_back(decl);
19009 if (result.size()>0)
19011 cout<<
"------------Found a chain of typedef decls: count="<<result.size()<<endl;
19012 for (vector <SgTypedefDeclaration*>::const_iterator iter = result.begin();
19013 iter!=result.end(); iter ++)
19040 if (fileInfo != NULL && fileInfo->isFrontendSpecific() ==
false && (isSgStatement(astNode) != NULL) )
19042 printf (
"\n\nIn CollectDependentDeclarationsTraversal::visit(): astNode = %p = %s = %s \n",astNode,astNode->
class_name().c_str(),
SageInterface::get_name(astNode).c_str());
19045 printf (
"alreadySavedDeclarations.size() = %" PRIuPTR
" \n",alreadySavedDeclarations.size());
19046 for (set<SgDeclarationStatement*>::iterator i = alreadySavedDeclarations.begin(); i != alreadySavedDeclarations.end(); i++)
19048 printf (
"alreadySavedDeclarations %d: %p = %s \n",counter++,*i,(*i)->class_name().c_str());
19059 if (initializedname != NULL)
19061 SgType* type = initializedname->get_type();
19064 std::vector <SgTypedefDeclaration*> typedefVec = collectTypedefDeclarations(type);
19065 for (std::vector <SgTypedefDeclaration*>::const_iterator iter =typedefVec.begin();
19066 iter != typedefVec.end(); iter++)
19069 addDeclaration(typedef_decl);
19093 SgNamedType* namedType = isSgNamedType(strippedType);
19094 if (namedType != NULL)
19102 if (classDeclaration != NULL)
19109 if (declaration != NULL)
19112 addDeclaration(declaration);
19115 addDeclaration (classDeclaration);
19126 ROSE_ASSERT(classSymbol != NULL);
19129 symbolList.push_back(classSymbol);
19134 if (enum_decl != NULL)
19137 ROSE_ASSERT(declaration != NULL);
19138 addDeclaration(declaration);
19143 ROSE_ASSERT(esymbol!= NULL);
19144 symbolList.push_back(esymbol);
19148 printf (
"Found reference to type = %p = %s strippedType = %p = %s \n",type,type->
class_name().c_str(),strippedType,strippedType->
class_name().c_str());
19155 if (functionCallExp != NULL)
19160 if (declaration != NULL)
19161 addDeclaration(declaration);
19168 if (functionSymbol)
19169 symbolList.push_back(functionSymbol);
19174 SgEnumVal * eval = isSgEnumVal(astNode);
19177 declaration = eval->get_declaration();
19178 ROSE_ASSERT(declaration != NULL);
19179 addDeclaration(declaration);
19181 ROSE_ASSERT(symbol != NULL);
19182 symbolList.push_back(symbol);
19187static std::map<const SgStatement*, bool> visitedDeclMap;
19199 printf (
"\n\n********************************************************** \n");
19200 printf (
" Inside of getDependentDeclarations(stmt = %p = %s) \n",stmt,stmt->
class_name().c_str());
19201 printf (
"********************************************************** \n");
19203 visitedDeclMap[stmt]=
true;
19207 declarationList = t.declarationList;
19208 symbolList = t.symbolList;
19211 copy(t.declarationList.begin(),t.declarationList.end(), back_inserter(declarationList));
19212 copy(t.symbolList.begin(),t.symbolList.end(), back_inserter(symbolList));
19214 sort (declarationList.begin(), declarationList.end());
19215 vector<SgDeclarationStatement*>::iterator new_end = unique(declarationList.begin(), declarationList.end());
19216 declarationList.erase(new_end, declarationList.end());
19218 sort (symbolList.begin(), symbolList.end());
19219 vector<SgSymbol*>::iterator end2 = unique(symbolList.begin(), symbolList.end());
19220 symbolList.erase(end2, symbolList.end());
19224 for (vector<SgDeclarationStatement*>::const_iterator iter = t.declarationList.begin();
19225 iter !=t.declarationList.end(); iter++)
19228 SgType* base_type = NULL;
19233 if (isSgClassDeclaration(decl))
19235 base_type = isSgClassDeclaration(decl)->get_type();
19237 if (isSgTypedefDeclaration(decl))
19241 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);
19249 if (isSgClassType(base_type))
19251 SgClassDeclaration* class_decl = isSgClassDeclaration(isSgClassType(base_type)->get_declaration()->get_definingDeclaration());
19252 if (class_decl!=NULL)
19254 body_stmt = class_decl->get_definition();
19258 if ((body_stmt!=NULL) &&(!visitedDeclMap[body_stmt]))
19270vector<SgDeclarationStatement*>
19273 vector<SgDeclarationStatement*> sortedNode;
19275 if (nodevec.size()==0 )
19278 if (nodevec.size() ==1)
19282 Rose_STL_Container<SgNode*> queryResult = NodeQuery::querySubTree(project,V_SgDeclarationStatement);
19283 for (Rose_STL_Container<SgNode*>::const_iterator iter = queryResult.begin();
19284 iter!= queryResult.end(); iter++)
19287 SgNode* cur_node = *iter;
19289 ROSE_ASSERT(cur_stmt!=NULL);
19301 ROSE_ASSERT (cur_stmt != func_decl);
19304 vector<SgDeclarationStatement*>::const_iterator i = find (nodevec.begin(), nodevec.end(), cur_stmt);
19305 if (i!=nodevec.end())
19309 vector<SgDeclarationStatement*>::const_iterator j = find (sortedNode.begin(), sortedNode.end(), *i);
19310 if (j == sortedNode.end())
19311 sortedNode.push_back(*i);
19315 if (nodevec.size() != sortedNode.size())
19317 cerr<<
"Fatal error in sortSgNodeListBasedOnAppearanceOrderInSource(): nodevec.size() != sortedNode.size()"<<endl;
19318 cerr<<
"nodevec() have "<< nodevec.size()<<
" elements. They are:"<<endl;
19319 for (vector<SgDeclarationStatement*>::const_iterator iter = nodevec.begin(); iter != nodevec.end(); iter++)
19321 cerr<<(*iter)<<
" "<<(*iter)->class_name() <<
" "<<(*iter)->unparseToString()<<endl;
19323 cerr<<
"sortedNode() have " << sortedNode.size() <<
" elements. They are:"<<endl;
19324 for (vector<SgDeclarationStatement*>::const_iterator iter = sortedNode.begin(); iter != sortedNode.end(); iter++)
19326 cerr<<(*iter)<<
" "<<(*iter)->class_name() <<
" "<<(*iter)->unparseToString()<<endl;
19329 ROSE_ASSERT(nodevec.size() == sortedNode.size());
19336std::vector<SgDeclarationStatement*>
19342 printf (
"\n\n********************************************************** \n");
19343 printf (
" Inside of getDependentDeclarations(stmt = %p = %s) \n",stmt,stmt->
class_name().c_str());
19344 printf (
"********************************************************** \n");
19349 return t.declarationList;
19352 visitedDeclMap.clear();
19353 vector<SgDeclarationStatement*> declarationList;
19354 vector<SgSymbol*> symbolList;
19358 printf (
"\n\n ********************************************************** \n");
19359 cout<<
"Found dependent decl: count="<<declarationList.size()<<endl;
19360 for ( vector<SgDeclarationStatement*>::const_iterator iter = declarationList.begin();
19361 iter != declarationList.end(); iter++)
19363 cout<<
"\t"<<(*iter)->class_name()<<
" at line "<<(*iter)->get_file_info()->get_line()<<endl;
19364 if ((*iter)->variantT()== V_SgFunctionDeclaration)
19365 cout<<
"func name is:"<<isSgFunctionDeclaration(*iter)->get_name().getString()<<endl;
19368 printf (
"\n ********************************************************** \n");
19371 return declarationList;
19380 bool returnValue =
false;
19383 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());
19386 if (functionName.is_null() ==
false)
19389 if ( functionName ==
"operator++" || functionName ==
"operator--" || functionName ==
"operator&" ||
19390 functionName ==
"operator!" || functionName ==
"operator*" || functionName ==
"operator+" ||
19391 functionName ==
"operator-" || functionName ==
"operator+" || functionName ==
"operator~")
19393 returnValue =
true;
19397 return returnValue;
19409 bool returnValue =
false;
19416 size_t numberOfOperands = 0;
19418 if (memberFunctionRefExp != NULL)
19420 ROSE_ASSERT(functionRefExp == NULL);
19422 if (memberFunctionDeclaration != NULL)
19424 functionName = memberFunctionDeclaration->get_name();
19425 numberOfOperands = memberFunctionDeclaration->get_args().size();
19431 if (functionRefExp != NULL)
19434 if (functionDeclaration != NULL)
19436 functionName = functionDeclaration->get_name();
19437 numberOfOperands = functionDeclaration->get_args().size();
19443 printf (
"In SageInterface::isPrefixOperator(): unknown case of exp = %p = %s \n",exp,exp->
class_name().c_str());
19448 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);
19453 if (memberFunctionRefExp != NULL)
19456 ROSE_ASSERT(functionRefExp == NULL);
19457 if (numberOfOperands == 0)
19460 returnValue =
true;
19465 returnValue =
false;
19471 ROSE_ASSERT(functionRefExp != NULL);
19472 ROSE_ASSERT(memberFunctionRefExp == NULL);
19473 if (numberOfOperands == 1)
19476 returnValue =
true;
19481 ROSE_ASSERT(numberOfOperands == 2);
19482 returnValue =
false;
19488 printf (
"Leaving SageInterface::isPrefixOperator(): returnValue = %s \n",returnValue ?
"true" :
"false");
19491 return returnValue;
19507 bool returnValue =
false;
19509 if (memberFunctionRefExp == NULL)
19513 if (memberFunctionDeclaration != NULL)
19515 SgName functionName = memberFunctionDeclaration->get_name();
19516 if ( (functionName ==
"operator[]") && (isSgType(memberFunctionDeclaration->get_type()) != NULL) )
19518 returnValue =
true;
19522 if ( (functionName ==
"operator()") && (isSgType(memberFunctionDeclaration->get_type()) != NULL) )
19524 returnValue =
true;
19528 returnValue =
false;
19533 return returnValue;
19544 ROSE_ASSERT(scope != NULL);
19547 printf (
"In SageInterface::lastStatementOfScopeWithTokenInfo(): scope = %p = %s \n",scope,scope->
class_name().c_str());
19550 SgIfStmt* ifStatement = isSgIfStmt(scope);
19551 if (ifStatement != NULL)
19554 if (lastStatement == NULL || (tokenStreamSequenceMap.find(lastStatement) == tokenStreamSequenceMap.end() || tokenStreamSequenceMap[lastStatement] == NULL))
19557 if (lastStatement == NULL || (tokenStreamSequenceMap.find(lastStatement) == tokenStreamSequenceMap.end() || tokenStreamSequenceMap[lastStatement] == NULL))
19559 lastStatement = NULL;
19563 printf (
"Note: SgIfStmt scope in SageInterface::lastStatementOfScopeWithTokenInfo(): returning lastStatement = %p \n",lastStatement);
19564 if (lastStatement != NULL)
19566 printf (
" --- lastStatement = %p = %s \n",lastStatement,lastStatement->
class_name().c_str());
19569 return lastStatement;
19573 if (statementList.rbegin() != statementList.rend())
19576 SgStatementPtrList::reverse_iterator i = statementList.rbegin();
19578 while (i != statementList.rend() && (tokenStreamSequenceMap.find(*i) == tokenStreamSequenceMap.end() || tokenStreamSequenceMap[*i] == NULL) )
19583 if (i == statementList.rend())
19585 lastStatement = NULL;
19589 lastStatement = *i;
19593 return lastStatement;
19607 void visit (
SgNode* node)
19617 printf (
"Found declaration = %p = %s name = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
19618 if (decl != definingDeclaration && decl != firstNondefiningDeclaration)
19620 otherDeclaration = decl;
19623 if (definingDeclaration != NULL)
19625 definingDeclaration->get_declarationModifier().get_accessModifier().display(
"definingDeclaration: accessModifier");
19628 if (firstNondefiningDeclaration != NULL)
19630 firstNondefiningDeclaration->get_declarationModifier().get_accessModifier().display(
"firstNondefiningDeclaration: accessModifier");
19633 if (otherDeclaration != NULL)
19635 otherDeclaration->get_declarationModifier().get_accessModifier().display(
"otherDeclaration: accessModifier");
19645 DeclarationTraversal traversal;
19646 traversal.traverse(astNode, preorder);
19658 void visit (
SgNode* node)
19664 if (functionDefinition != NULL)
19667 ROSE_ASSERT(functionDeclaration != NULL);
19669 string functionName = functionDeclaration->get_name();
19671 printf (
"functionName = %s \n",functionName.c_str());
19673 if (functionName ==
"main")
19677 ROSE_ASSERT(functionBody != NULL);
19679 ROSE_ASSERT(symbolTable != NULL);
19682 symbolTable->
print();
19687 if (namespaceDefinition != NULL)
19690 ROSE_ASSERT(namespaceDeclaration != NULL);
19692 string namespaceName = namespaceDeclaration->
get_name();
19694 printf (
"namespaceName = %s \n",namespaceName.c_str());
19696 if (namespaceName ==
"B")
19699 ROSE_ASSERT(symbolTable != NULL);
19702 symbolTable->
print();
19710 ScopeTraversal traversal;
19711 traversal.traverse(astNode, preorder);
19719 if (fileInfo != NULL)
19725 if (locatedNode != NULL)
19734 printf (
"In markNodeToBeUnparsed(): physical_file_id = %d \n",physical_file_id);
19737 locatedNode->
get_file_info()->set_physical_file_id(physical_file_id);
19739 printf (
"Note: calling node markTransformationsForOutput(): node = %p = %s \n",node,node->
class_name().c_str());
19743 markTransformationsForOutput(node);
19748 printf (
"Note: node is not a SgLocatedNode: node = %p = %s \n",node,node->
class_name().c_str());
19755 printf (
"Note: no Sg_File_Info was found: node = %p = %s \n",node,node->
class_name().c_str());
19760 if (locatedNode != NULL)
19769 printf (
"In SageInterface::markNodeToBeUnparsed(): locatedNode = %p = %s calling set_physical_file_id(%d) \n",locatedNode,locatedNode->
class_name().c_str(),physical_file_id);
19771 locatedNode->
get_file_info()->set_physical_file_id(physical_file_id);
19776 printf (
"Note: no Sg_File_Info was found: node = %p = %s \n",node,node->
class_name().c_str());
19809 class InheritedAttribute
19812 int physical_file_id;
19813 bool isCastSubtree;
19814 InheritedAttribute(
int file_id): physical_file_id(file_id), isCastSubtree(
false) {}
19815 InheritedAttribute(
const InheritedAttribute & X)
19817 isCastSubtree = X.isCastSubtree;
19818 physical_file_id = X.physical_file_id;
19829 InheritedAttribute evaluateInheritedAttribute (
SgNode* node, InheritedAttribute inheritedAttribute)
19831 InheritedAttribute returnAttribute(inheritedAttribute);
19833 SgCastExp* castExpression = isSgCastExp(node);
19834 if (castExpression != NULL)
19836 returnAttribute.isCastSubtree =
true;
19839 if (returnAttribute.isCastSubtree ==
true)
19843 printf (
"In markSubtreeToBeUnparsedTreeTraversal(): subtree of a SgCastExp: node = %p = %s physical_file_id = %d \n",
19844 node,node->
class_name().c_str(),inheritedAttribute.physical_file_id);
19850 printf (
"In markSubtreeToBeUnparsedTreeTraversal(): Calling markNodeToBeUnparsed(): node = %p = %s physical_file_id = %d \n",
19851 node,node->
class_name().c_str(),inheritedAttribute.physical_file_id);
19857 return returnAttribute;
19861 InheritedAttribute inheritedAttribute(physical_file_id);
19864 SubtreeTraversal traversal;
19867 printf (
"\nIn markSubtreeToBeUnparsedTreeTraversal(): calling traverse \n");
19870 traversal.traverse(root, inheritedAttribute);
19872 printf (
"This function does not compile with GNU 4.9 or older compilers (part of ROSE used only with more modern compilers) \n");
19881vector<SgDeclarationStatement*>
19882generateCopiesOfDependentDeclarations (
const vector<SgDeclarationStatement*>& dependentDeclarations,
SgScopeStatement* targetScope)
19893 printf (
"\n\n********************************************************** \n");
19894 printf (
" Inside of generateCopiesOfDependentDeclarations(stmt = %p = %s) \n",stmt,stmt->
class_name().c_str());
19895 printf (
"********************************************************** \n");
19898 vector<SgDeclarationStatement*> copiesOfDependentDeclarations;
19903 printf (
"Output the dependentDeclarations: dependentDeclarations.size() = %" PRIuPTR
" \n",dependentDeclarations.size());
19904 outputDeclarationList(dependentDeclarations);
19907 printf (
"************************************************ \n");
19908 printf (
"*** Make all copies of dependentDeclarations *** \n");
19909 printf (
"************************************************ \n");
19913 ROSE_ASSERT(targetScope != NULL);
19916 ROSE_ASSERT(isSgGlobal(targetScope) != NULL);
19918 for (vector<SgDeclarationStatement*>::const_iterator i = dependentDeclarations.begin(); i != dependentDeclarations.end(); i++)
19921 printf (
"Copying declaration = %p = %s = %s \n",*i,(*i)->class_name().c_str(),
SageInterface::get_name(*i).c_str());
19925 SgNode* copy_node = NULL;
19930 if (functionDeclaration != NULL)
19939 printf (
"WARNING: In SageInterface -- generateCopiesOfDependentDeclarations(): I think this is the wrong lookup symbol function that is being used here! \n");
19946 printf (
"In generateCopiesOfDependentDeclarations(): Copy mechanism appied to SgFunctionDeclaration functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->
get_firstNondefiningDeclaration());
19948 printf (
"functionDeclaration = %p \n",functionDeclaration);
19949 printf (
"functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->
get_definingDeclaration());
19951 printf (
"functionDeclaration->get_scope() = %p \n",functionDeclaration->
get_scope());
19952 printf (
"targetScope = %p \n",targetScope);
19955 assert(copy_functionDeclaration != NULL);
19957 copy_functionDeclaration->
set_parent(targetScope);
19967 assert(copy_functionDeclaration->
get_scope() != NULL);
19968 assert(copy_functionDeclaration->
get_scope() == targetScope);
19969 assert(copy_functionDeclaration->
get_scope()->lookup_function_symbol(copy_functionDeclaration->get_name(),
19970 copy_functionDeclaration->get_type()) != NULL);
19971 assert(copy_functionDeclaration->
get_scope()->lookup_function_symbol(copy_functionDeclaration->get_name(),
19974 copy_node = copy_functionDeclaration;
19976 printf (
"In generateCopiesOfDependentDeclarations(): DONE: Copy mechanism appied to SgFunctionDeclaration \n");
19990 cout<<
"Copying a defining typedef declaration:"<<tdecl->
unparseToString()<<endl;
19992 cout<<
"Copying a non-defining typedef declaration:"<<tdecl->
unparseToString()<<endl;
19996 tdecl_copy->set_typedefBaseTypeContainsDefiningDeclaration (
false);
19999 copy_node = (*i)->copy(collectDependentDeclarationsCopyType);
20003 ROSE_ASSERT(copy_declaration != NULL);
20007 copy_declaration->
set_scope(targetScope);
20019 ROSE_ASSERT(copy_node != NULL);
20028 ROSE_ASSERT(copy_definingDeclaration != NULL);
20030 ROSE_ASSERT( *i != NULL );
20031 ROSE_ASSERT(copy_definingDeclaration != NULL);
20034 if (copy_definingDeclaration->
get_parent() == NULL)
20036 copy_definingDeclaration->
set_parent(targetScope);
20038 ROSE_ASSERT(copy_definingDeclaration->
get_parent() != NULL);
20041 printf (
"DONE: Copying declaration: original scope = %p copied to scope = %p \n",(*i)->get_scope(),copy_definingDeclaration->
get_scope());
20051 ROSE_ASSERT(copy_definingDeclaration->
get_parent() == NULL);
20058 printf (
"copy_definingDeclaration = %p \n",copy_definingDeclaration);
20059 printf (
"copy_definingDeclaration->get_firstNondefiningDeclaration() == NULL \n");
20060 printf (
"copy_definingDeclaration->get_definingDeclaration() = %p \n",copy_definingDeclaration->
get_definingDeclaration());
20065 if ((*i)->get_firstNondefiningDeclaration() != NULL)
20073 copiesOfDependentDeclarations.push_back(copy_definingDeclaration);
20077 printf (
"****************************************************** \n");
20078 printf (
"*** DONE: Make all copies of dependentDeclarations *** \n");
20079 printf (
"****************************************************** \n");
20080 printf (
"copiesOfDependentDeclarations.size() = %" PRIuPTR
" \n",copiesOfDependentDeclarations.size());
20086 ROSE_ASSERT(copiesOfDependentDeclarations.size() <= dependentDeclarations.size());
20088 return copiesOfDependentDeclarations;
20093declarationContainsDependentDeclarations(
SgDeclarationStatement* decl, vector<SgDeclarationStatement*> & dependentDeclarationList )
20096 bool returnValue =
false;
20099 printf (
"\n\n********************************************************** \n");
20100 printf (
" Inside of declarationContainsDependentDeclarations(decl = %p = %s) \n",decl,decl->
class_name().c_str());
20101 printf (
"********************************************************** \n");
20109 for (
size_t i = 0; i < locallyDependentDeclarationList.size(); i++)
20115 vector<SgDeclarationStatement*>::iterator j = find(dependentDeclarationList.begin(),dependentDeclarationList.end(),d);
20116 if (j != dependentDeclarationList.end())
20121 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());
20123 returnValue =
true;
20128 printf (
"**************************************************************************** \n");
20129 printf (
" LEAVING: Inside of declarationContainsDependentDeclarations(decl = %p = %s) returnValue = %s \n",decl,decl->
class_name().c_str(),returnValue ?
"true" :
"false");
20130 printf (
"**************************************************************************** \n");
20133 return returnValue;
20138 ROSE_ASSERT (new_exp != NULL);
20139 ROSE_ASSERT (anchor_exp != NULL);
20140 ROSE_ASSERT (new_exp != anchor_exp);
20143 ROSE_ASSERT (parent != NULL);
20147 ROSE_ASSERT (result != NULL);
20159 ROSE_ASSERT (new_exp != NULL);
20160 ROSE_ASSERT (anchor_exp != NULL);
20161 ROSE_ASSERT (new_exp != anchor_exp);
20164 ROSE_ASSERT (parent != NULL);
20168 ROSE_ASSERT (t != NULL);
20170 ROSE_ASSERT (enclosing_stmt != NULL);
20177 ROSE_ASSERT (temp_sym != NULL);
20179 *temp_decl = t_decl;
20184 * temp_ref = first_ref;
20197 string fileName =
"separate-outlined-file";
20217 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl = %p \n",decl);
20218 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_parent() = %p \n",decl->
get_parent());
20219 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_scope() = %p \n",decl->
get_scope());
20220 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): original_statement = %p \n",original_statement);
20221 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): file (decl) = %s \n",TransformationSupport::getSourceFile(decl)->getFileName().c_str());
20222 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_firstNondefiningDeclaration() = %p \n",decl->
get_firstNondefiningDeclaration());
20224 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): file (first non-defining) = %s \n",TransformationSupport::getSourceFile(decl->
get_firstNondefiningDeclaration())->
getFileName().c_str());
20225 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_definingDeclaration() = %p \n",decl->
get_definingDeclaration());
20227 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): file (first non-defining) = %s \n",TransformationSupport::getSourceFile(decl->
get_definingDeclaration())->
getFileName().c_str());
20230#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
20262 vector<SgDeclarationStatement*> dependentDeclarationList_inOriginalFile;
20269 vector<SgDeclarationStatement*> dependentDeclarationList = generateCopiesOfDependentDeclarations(dependentDeclarationList_inOriginalFile,scope);
20270 ROSE_ASSERT(dependentDeclarationList.size() <= dependentDeclarationList_inOriginalFile.size());
20280 std::map<SgNode*, SgNode*> replacementMap;
20285 SgCopyHelp::copiedNodeMapType copyNodeMap = collectDependentDeclarationsCopyType.get_copiedNodeMap();
20286 SgCopyHelp::copiedNodeMapType::iterator copyNodeMapItrator = copyNodeMap.begin();
20287 while (copyNodeMapItrator != copyNodeMap.end())
20292 SgNode* first =
const_cast<SgNode*
>(copyNodeMapItrator->first);
20293 SgNode* second = copyNodeMapItrator->second;
20295 printf (
"copyNodeMapItrator.first = %p = %s second = %p = %s \n",first,first->
class_name().c_str(),second,second->
class_name().c_str());
20298 if (isSgSymbol(first) != NULL)
20303 replacementMap.insert(pair<SgNode*,SgNode*>(first,second));
20306 copyNodeMapItrator++;
20310 printf (
"Exiting after test of new functionality \n");
20316 SgSourceFile* sourceFile = TransformationSupport::getSourceFile(original_statement);
20317 vector<PreprocessingInfo*> requiredDirectivesList = collectCppDirectives(sourceFile);
20320 ROSE_ASSERT(outlinedFunctionDeclaration != NULL);
20321 SgGlobal* originalFileGlobalScope = TransformationSupport::getGlobalScope(original_statement);
20322 ROSE_ASSERT(originalFileGlobalScope != NULL);
20324 printf (
"WARNING: In SageInterface::appendStatementWithDependentDeclaration(): I think this is the wrong lookup symbol function that is being used here! \n");
20328 SgFunctionSymbol* outlinedFunctionSymbolFromOriginalFile = isSgFunctionSymbol(originalFileGlobalScope->lookup_symbol(outlinedFunctionDeclaration->get_name(),NULL,NULL));
20334 printf (
"outlinedFunctionSymbolFromOriginalFile = %p outlinedFunctionSymbolFromOutlinedFile = %p \n",outlinedFunctionSymbolFromOriginalFile,outlinedFunctionSymbolFromOutlinedFile);
20336 printf (
"TransformationSupport::getSourceFile(decl)->getFileName() = %s \n",TransformationSupport::getSourceFile(decl)->getFileName().c_str());
20337 printf (
"TransformationSupport::getSourceFile(decl->get_firstNondefiningDeclaration())->getFileName() = %s \n",TransformationSupport::getSourceFile(decl->
get_firstNondefiningDeclaration())->
getFileName().c_str());
20338 printf (
"TransformationSupport::getSourceFile(original_statement)->getFileName() = %s \n",TransformationSupport::getSourceFile(original_statement)->getFileName().c_str());
20341 ROSE_ASSERT(outlinedFunctionSymbolFromOriginalFile != NULL);
20342 ROSE_ASSERT(outlinedFunctionSymbolFromOutlinedFile != NULL);
20345 ROSE_ASSERT(outlinedFunctionSymbolFromOriginalFile == outlinedFunctionSymbolFromOutlinedFile);
20348 replacementMap.insert(pair<SgNode*,SgNode*>(originalFileGlobalScope,scope));
20351 SgFunctionDeclaration* outlinedNondefiningFunctionDeclarationFromOriginalFile = isSgFunctionDeclaration(outlinedFunctionSymbolFromOriginalFile->get_declaration());
20353 ROSE_ASSERT(outlinedNondefiningFunctionDeclarationFromOriginalFile != NULL);
20354 ROSE_ASSERT(outlinedNondefiningFunctionDeclarationFromOutlinedFile != NULL);
20355 replacementMap.insert(pair<SgNode*,SgNode*>(outlinedNondefiningFunctionDeclarationFromOriginalFile,outlinedNondefiningFunctionDeclarationFromOutlinedFile));
20364 for (
size_t i = 0; i < dependentDeclarationList.size(); i++)
20370 printf (
"originalDeclaration = %p \n",originalDeclaration);
20372 d->
get_file_info()->display(
"SageInterface::appendStatementWithDependentDeclaration()");
20380 ROSE_ASSERT(decl->
get_scope() == scope);
20386 printf (
"Add the required symbol information to the symbol table: scope = %p = %s \n",scope,scope->
class_name().c_str());
20393 case V_SgClassDeclaration:
20395 if ( declarationContainsDependentDeclarations(d,dependentDeclarationList) ==
true )
20396 printf (
"Warning: This class contains dependent declarations (not implemented) \n");
20400 case V_SgMemberFunctionDeclaration:
20401 printf (
"Sorry, support for dependent member function declarations not implemented! \n");
20404 case V_SgTemplateInstantiationDecl:
20405 printf (
"Sorry, not implemented: case SgTemplateInstantiationDecl not handled as dependent declaration \n");
20406 d->
get_file_info()->display(
"Sorry, not implemented: case SgTemplateInstantiationDecl not handled as dependent declaration");
20408 printf (
"Case of SgTemplateInstantiationDecl not implemented. \n");
20411 case V_SgNamespaceDeclarationStatement:
20412 if (declarationContainsDependentDeclarations(d,dependentDeclarationList) ==
true )
20413 printf (
"Warning: This namespace contains dependent declarations (not supported) \n");
20416 case V_SgFunctionDeclaration:
20417 case V_SgTypedefDeclaration:
20418 case V_SgEnumDeclaration:
20422 printf (
"default case in SageInterface::appendStatementWithDependentDeclaration() (handling dependentDeclarationList) d = %p = %s \n",d,d->
class_name().c_str());
20428 vector<PreprocessingInfo*> cppDirectivesAlreadyAttachedToDependentDeclarations = collectCppDirectives(d);
20431 printf (
"directives BEFORE excluding those already present in dependent declarations \n");
20432 outputPreprocessingInfoList(requiredDirectivesList);
20434 printf (
"directives already attached to dependent declarations \n");
20435 outputPreprocessingInfoList(cppDirectivesAlreadyAttachedToDependentDeclarations);
20439 vector<PreprocessingInfo*>::iterator j = cppDirectivesAlreadyAttachedToDependentDeclarations.begin();
20440 while ( j != cppDirectivesAlreadyAttachedToDependentDeclarations.end() )
20443 vector<PreprocessingInfo*>::iterator entry = find(requiredDirectivesList.begin(),requiredDirectivesList.end(),*j);
20444 ROSE_ASSERT(entry != requiredDirectivesList.end());
20446 requiredDirectivesList.erase(entry);
20452 printf (
"directives AFTER excluding those already present in dependent declarations \n");
20453 outputPreprocessingInfoList(requiredDirectivesList);
20462 if (dependentDeclarationList.empty() ==
true)
20464 firstStatmentInFile = decl;
20468 firstStatmentInFile = dependentDeclarationList[0];
20471 ROSE_ASSERT(firstStatmentInFile != NULL);
20479 if (excludeHeaderFiles ==
false)
20482 vector<PreprocessingInfo*>::reverse_iterator j = requiredDirectivesList.rbegin();
20483 while ( j != requiredDirectivesList.rend() )
20502 SgSourceFile* outlinedFile = TransformationSupport::getSourceFile(scope);
20503 ROSE_ASSERT(outlinedFile != NULL);
20509 printf (
"\n\n************************************************************\n");
20510 printf (
"Calling Utils::edgePointerReplacement() \n");
20516 printf (
"Calling Utils::edgePointerReplacement(): DONE \n");
20517 printf (
"************************************************************\n\n");
20519 printf (
"\n\n After replacementMapTraversal(): intermediateDeleteSet: \n");
20520 displaySet(intermediateDeleteSet,
"After Utils::edgePointerReplacement");
20524 ROSE_ASSERT(dependentDeclarationList.size() <= dependentDeclarationList_inOriginalFile.size());
20532 printf (
"replacementMap.size() = %" PRIuPTR
" dependentDeclarationList.size() = %" PRIuPTR
" \n",replacementMap.size(),dependentDeclarationList.size());
20548 int SgVariableSymbol_count;
20549 int SgFunctionSymbol_count;
20550 int SgClassDeclaration_count;
20551 int SgTypedefSymbol_count;
20552 int SgMemFuncSymbol_count;
20553 int SgTemplateSymbol_count;
20554 int SgEnumFieldSymbol_count;
20572 SgVariableSymbol_count = 0;
20573 SgVariableSymbolPtr = symbol;
20574 SgFunctionSymbolPtr =NULL;
20575 SgClassSymbolPtr =NULL;
20576 SgTypedefPtr = NULL;
20577 SgMemFuncSymbolPtr =NULL;
20578 class_defining = NULL;
20580 typedef_defining =NULL;
20581 function_decl = NULL;
20582 SgTemplateSymbolPtr = NULL;
20583 template_defining = NULL;
20584 SgEnumFieldSymbolPtr = NULL;
20585 templateInstantiate_defining =NULL;
20589 SgFunctionSymbol_count = 0;
20590 SgFunctionSymbolPtr = symbol;
20593 SgMemFuncSymbol_count =0;
20595 SgVariableSymbolPtr = NULL;
20596 SgClassSymbolPtr =NULL;
20597 SgTypedefPtr = NULL;
20598 SgMemFuncSymbolPtr =NULL;
20599 class_defining = NULL;
20601 typedef_defining =NULL;
20602 function_decl = NULL;
20603 SgTemplateSymbolPtr = NULL;
20604 template_defining = NULL;
20605 SgEnumFieldSymbolPtr = NULL;
20606 templateInstantiate_defining =NULL;
20610 SgClassDeclaration_count = 0;
20611 SgClassSymbolPtr = symbol;
20612 SgFunctionSymbolPtr = NULL;
20613 SgVariableSymbolPtr = NULL;
20614 SgTypedefPtr = NULL;
20615 SgMemFuncSymbolPtr =NULL;
20616 class_defining = NULL;
20618 typedef_defining =NULL;
20619 function_decl = NULL;
20620 SgTemplateSymbolPtr = NULL;
20621 template_defining = NULL;
20622 SgEnumFieldSymbolPtr = NULL;
20623 templateInstantiate_defining =NULL;
20627 SgTypedefSymbol_count =0;
20628 SgTypedefPtr = symbol;
20629 SgClassSymbolPtr = NULL;
20630 SgFunctionSymbolPtr = NULL;
20631 SgVariableSymbolPtr = NULL;
20632 SgMemFuncSymbolPtr =NULL;
20633 class_defining = NULL;
20635 typedef_defining =NULL;
20636 function_decl = NULL;
20637 SgTemplateSymbolPtr = NULL;
20638 template_defining = NULL;
20639 SgEnumFieldSymbolPtr = NULL;
20640 templateInstantiate_defining =NULL;
20644 SgMemFuncSymbolPtr = symbol;
20645 SgMemFuncSymbol_count =0;
20646 SgTypedefPtr = NULL;
20647 SgClassSymbolPtr = NULL;
20648 SgFunctionSymbolPtr = NULL;
20649 SgVariableSymbolPtr = NULL;
20650 class_defining = NULL;
20652 typedef_defining =NULL;
20653 function_decl = NULL;
20654 SgTemplateSymbolPtr = NULL;
20655 template_defining = NULL;
20656 SgEnumFieldSymbolPtr = NULL;
20657 templateInstantiate_defining =NULL;
20661 SgTemplateSymbolPtr = symbol;
20662 SgTemplateSymbol_count =0;
20663 SgMemFuncSymbolPtr = NULL;
20664 SgTypedefPtr = NULL;
20665 SgClassSymbolPtr = NULL;
20666 SgFunctionSymbolPtr = NULL;
20667 SgVariableSymbolPtr = NULL;
20668 class_defining = NULL;
20670 typedef_defining =NULL;
20671 function_decl = NULL;
20672 template_defining = NULL;
20673 SgEnumFieldSymbolPtr = NULL;
20674 templateInstantiate_defining =NULL;
20678 SgEnumFieldSymbolPtr = symbol;
20679 SgEnumFieldSymbol_count =0;
20680 SgTemplateSymbolPtr = NULL;
20681 SgMemFuncSymbolPtr = NULL;
20682 SgTypedefPtr = NULL;
20683 SgClassSymbolPtr = NULL;
20684 SgFunctionSymbolPtr = NULL;
20685 SgVariableSymbolPtr = NULL;
20686 class_defining = NULL;
20688 typedef_defining =NULL;
20689 function_decl = NULL;
20690 template_defining = NULL;
20691 templateInstantiate_defining =NULL;
20696 class_defining = node;
20697 SgMemFuncSymbolPtr = NULL;
20698 SgTypedefPtr = NULL;
20699 SgClassSymbolPtr = NULL;
20700 SgFunctionSymbolPtr = NULL;
20701 SgVariableSymbolPtr = NULL;
20703 typedef_defining =NULL;
20704 function_decl = NULL;
20705 SgTemplateSymbolPtr = NULL;
20706 template_defining = NULL;
20707 SgEnumFieldSymbolPtr = NULL;
20708 templateInstantiate_defining =NULL;
20712 template_defining = node;
20713 class_defining = NULL;
20714 SgMemFuncSymbolPtr = NULL;
20715 SgTypedefPtr = NULL;
20716 SgClassSymbolPtr = NULL;
20717 SgFunctionSymbolPtr = NULL;
20718 SgVariableSymbolPtr = NULL;
20720 typedef_defining =NULL;
20721 function_decl = NULL;
20722 SgTemplateSymbolPtr = NULL;
20723 SgEnumFieldSymbolPtr = NULL;
20724 templateInstantiate_defining =NULL;
20727 function_decl =node;
20728 class_defining = NULL;
20729 SgMemFuncSymbolPtr = NULL;
20730 SgTypedefPtr = NULL;
20731 SgClassSymbolPtr = NULL;
20732 SgFunctionSymbolPtr = NULL;
20733 SgVariableSymbolPtr = NULL;
20735 typedef_defining =NULL;
20736 SgTemplateSymbolPtr = NULL;
20737 template_defining = NULL;
20738 SgEnumFieldSymbolPtr = NULL;
20739 templateInstantiate_defining =NULL;
20744 function_decl =NULL;
20745 class_defining = NULL;
20746 SgMemFuncSymbolPtr = NULL;
20747 SgTypedefPtr = NULL;
20748 SgClassSymbolPtr = NULL;
20749 SgFunctionSymbolPtr = NULL;
20750 SgVariableSymbolPtr = NULL;
20751 typedef_defining =NULL;
20752 SgTemplateSymbolPtr = NULL;
20753 template_defining = NULL;
20754 SgEnumFieldSymbolPtr = NULL;
20755 templateInstantiate_defining =NULL;
20759 typedef_defining = node;
20761 function_decl =NULL;
20762 class_defining = NULL;
20763 SgMemFuncSymbolPtr = NULL;
20764 SgTypedefPtr = NULL;
20765 SgClassSymbolPtr = NULL;
20766 SgFunctionSymbolPtr = NULL;
20767 SgVariableSymbolPtr = NULL;
20768 SgTemplateSymbolPtr = NULL;
20769 template_defining = NULL;
20770 SgEnumFieldSymbolPtr = NULL;
20771 templateInstantiate_defining =NULL;
20775 templateInstantiate_defining =node;
20776 typedef_defining = NULL;
20778 function_decl =NULL;
20779 class_defining = NULL;
20780 SgMemFuncSymbolPtr = NULL;
20781 SgTypedefPtr = NULL;
20782 SgClassSymbolPtr = NULL;
20783 SgFunctionSymbolPtr = NULL;
20784 SgVariableSymbolPtr = NULL;
20785 SgTemplateSymbolPtr = NULL;
20786 template_defining = NULL;
20787 SgEnumFieldSymbolPtr = NULL;
20794 if(SgVariableSymbolPtr !=NULL)
20796 if(node->get_scope()!=NULL)
20802 if (isSgVariableSymbol(s) == SgVariableSymbolPtr) SgVariableSymbol_count++;
20807 if(SgEnumFieldSymbolPtr !=NULL)
20809 if(node->get_scope()!=NULL)
20815 if (isSgEnumFieldSymbol(s) == SgEnumFieldSymbolPtr) SgEnumFieldSymbol_count++;
20823 if(SgVariableSymbolPtr !=NULL){
20825 if (s == SgVariableSymbolPtr) SgVariableSymbol_count++;
20829 int get_num_variable_pointers(){
return SgVariableSymbol_count;}
20831 int get_num_EnumField_pointers(){
return SgEnumFieldSymbol_count;}
20836 if(SgFunctionSymbolPtr !=NULL){
20842 if ((
SgFunctionSymbol *)s == SgFunctionSymbolPtr) SgFunctionSymbol_count++;
20847 if(function_decl!=NULL){
20851 if(node!=function_decl && (define==function_decl || first_nondefine==function_decl))
delete node;
20860 printf (
"In visit(SgFunctionRefExp* node): SgFunctionSymbolPtr = %p \n",SgFunctionSymbolPtr);
20862 if (SgFunctionSymbolPtr !=NULL)
20865 if (isSgFunctionSymbol(s) == SgFunctionSymbolPtr)
20867 SgFunctionSymbol_count++;
20869 printf (
"Increment SgFunctionSymbol_count = %d \n",SgFunctionSymbol_count);
20879 printf (
"In visit(SgMemberFunctionRefExp* node): SgFunctionSymbolPtr = %p \n",SgFunctionSymbolPtr);
20881 if (SgFunctionSymbolPtr !=NULL)
20884 if (isSgFunctionSymbol(s) == SgFunctionSymbolPtr)
20886 SgFunctionSymbol_count++;
20888 printf (
"Increment SgFunctionSymbol_count = %d \n",SgFunctionSymbol_count);
20896 if (SgFunctionSymbolPtr !=NULL){
20898 if (isSgFunctionSymbol(s) == SgFunctionSymbolPtr) SgFunctionSymbol_count++;
20902 int get_num_Function_pointers(){
return SgFunctionSymbol_count;}
20907 if(SgClassSymbolPtr !=NULL){
20912 if (isSgClassSymbol(s) == SgClassSymbolPtr) SgClassDeclaration_count++;
20917 if(class_defining!=NULL) {
20921 if((class_decl==class_defining||class_decl1==class_defining) && node!=class_defining )
20929 if(SgClassSymbolPtr !=NULL){
20934 if (isSgClassSymbol(s) == SgClassSymbolPtr) SgClassDeclaration_count++;
20939 if(templateInstantiate_defining!=NULL) {
20946 if((template_decl==templateInstantiate_defining||template_decl1==templateInstantiate_defining) && node!=templateInstantiate_defining){
20966 if (SgClassSymbolPtr !=NULL){
20967 SgSymbol* s = node->get_class_symbol();
20968 if (s == SgClassSymbolPtr) SgClassDeclaration_count++;
20974 if (SgClassSymbolPtr !=NULL){
20976 if (isSgClassSymbol(s) == SgClassSymbolPtr) SgClassDeclaration_count++;
20981 int get_num_Class_pointers(){
return SgClassDeclaration_count;}
20987 if(memFunc !=NULL){
20989 if(func == memFunc){
20998 if (SgMemFuncSymbolPtr !=NULL){
21003 if(symbol == SgMemFuncSymbolPtr){
21004 SgMemFuncSymbol_count++;
21013 if (SgMemFuncSymbolPtr !=NULL){
21018 if(symbol == SgMemFuncSymbolPtr){
21019 SgMemFuncSymbol_count++;
21028 int get_num_memFunc_pointers(){
return SgMemFuncSymbol_count;}
21034 if(SgTypedefPtr!=NULL){
21043 if(typedef_defining!=NULL){
21045 if(typedef_define == typedef_defining && node != typedef_defining ) {
21051 int get_num_Typedef_pointers(){
return SgTypedefSymbol_count;}
21057 if (SgTemplateSymbolPtr !=NULL){
21062 if(symbol == SgTemplateSymbolPtr){
21063 SgTemplateSymbol_count++;
21069 if(template_defining !=NULL) {
21076 if((template_decl==template_defining||template_decl1==template_defining) && node!=template_defining) {
21086 int get_num_Template_pointers(){
return SgTemplateSymbol_count;}
21096 void visit (
SgNode* node)
21103 printf (
"In DeleteAST::visit(): node = %p = %s \n",node,node->
class_name().c_str());
21108 if (isSgScopeStatement(node) !=NULL)
21112 printf (
"Deleting the scopes type table: scope->get_type_table() = %p \n",scope->get_type_table());
21114 delete scope->get_type_table();
21120 if (isSgTypeTable(node) !=NULL)
21124 printf (
"Deleting the type table (SgSymbolTable): typeTable->get_type_table() = %p \n",typeTable->get_type_table());
21126 delete typeTable->get_type_table();
21129 if(isSgInitializedName(node) !=NULL){
21133 if(isSgVariableDefinition(var_def) !=NULL){
21140 if(isSgInitializedName(node)->get_scope()!=NULL){
21144 if(isSgVariableSymbol(symbol) !=NULL){
21146 traverseMemoryPoolVisitorPattern(visitor);
21147 if(visitor.get_num_variable_pointers()==1){
21154 if(isSgEnumFieldSymbol(symbol) !=NULL){
21156 traverseMemoryPoolVisitorPattern(visitor);
21157 if(visitor.get_num_EnumField_pointers()==1){
21168 if(isSgVarRefExp(node) !=NULL){
21170 ClassicVisitor visitor(symbol);
21171 traverseMemoryPoolVisitorPattern(visitor);
21172 if(visitor.get_num_variable_pointers()==1){
21184 SgFunctionDeclaration* funcDecl = isSgFunctionDeclaration(node);
21185 if (funcDecl != NULL){
21186 if (isSgMemberFunctionDeclaration(node) == NULL) {
21187 if (funcDecl->get_scope() != NULL) {
21188 if (funcDecl->get_scope()->get_symbol_table() != NULL) {
21189 SgSymbol* symbol = ((SgFunctionDeclaration*)node)->get_symbol_from_symbol_table();
21190 ClassicVisitor visitor((SgFunctionSymbol *)symbol);
21191 traverseMemoryPoolVisitorPattern(visitor);
21192 if (visitor.get_num_Function_pointers()==1) { //only one reference to this FunctionSymbol => safe to delete
21193 ((SgFunctionDeclaration*)node)->get_scope()->get_symbol_table()->remove(symbol);
21195 //printf("A SgFunctionSymbol was deleted\n");
21197 ClassicVisitor visitor1((SgFunctionDeclaration *)node);
21198 traverseMemoryPoolVisitorPattern(visitor1);
21205 if(isSgFunctionRefExp(node) !=NULL)
21208 SgFunctionRefExp* functionRefExp = isSgFunctionRefExp(node);
21209 ROSE_ASSERT(functionRefExp->get_symbol_i() != NULL);
21210 printf ("In DeleteAST::visit(): functionRefExp->get_symbol_i() = %p = %s \n",functionRefExp->get_symbol_i(),functionRefExp->get_symbol_i()->class_name().c_str());
21212 SgFunctionSymbol *symbol = ((SgFunctionRefExp*)node)->get_symbol_i();
21213 ClassicVisitor visitor(symbol);
21214 traverseMemoryPoolVisitorPattern(visitor);
21215 if(visitor.get_num_Function_pointers()==1)
21217 // only one reference to this FunctionSymbol => safe to delete
21218 //((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21220 //printf("A SgFunctionSymbol was deleted\n");
21225 if(isSgUserDefinedBinaryOp(node) !=NULL){
21226 SgFunctionSymbol *symbol = ((SgUserDefinedBinaryOp*)node)->get_symbol();
21227 ClassicVisitor visitor(symbol);
21228 traverseMemoryPoolVisitorPattern(visitor);
21229 if(visitor.get_num_Function_pointers()==1){ //only one reference to this FunctionSymbol => safe to delete
21230 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21232 //printf("A SgFunctionSymbol was deleted\n");
21240 if(isSgTypedefDeclaration(node) !=NULL){
21245 if(isSgTypedefSymbol(symbol)){
21247 traverseMemoryPoolVisitorPattern(visitor);
21248 if(visitor.get_num_Typedef_pointers()==1){
21259 traverseMemoryPoolVisitorPattern(visitor1);
21267 if(isSgNamespaceDeclarationStatement(node) !=NULL){
21268 if(((SgNamespaceDeclarationStatement*)node)->get_scope()!=NULL){
21269 if(((SgNamespaceDeclarationStatement*)node)->get_scope()->get_symbol_table()!=NULL)
21271 SgSymbol* symbol = ((SgNamespaceDeclarationStatement*)node)->get_symbol_from_symbol_table();
21272 if(isSgNamespaceSymbol(symbol)){
21273 ((SgNamespaceDeclarationStatement*)node)->get_scope()->get_symbol_table()->remove(symbol);
21275 //printf("A SgNamespaceSymbol was deleted\n");
21282 if(isSgNamespaceAliasDeclarationStatement(node) !=NULL){
21283 if(((SgNamespaceAliasDeclarationStatement*)node)->get_scope()!=NULL){
21284 if(((SgNamespaceAliasDeclarationStatement*)node)->get_scope()->get_symbol_table()!=NULL)
21286 SgSymbol* symbol = ((SgNamespaceAliasDeclarationStatement*)node)->get_symbol_from_symbol_table();
21287 if(isSgNamespaceSymbol(symbol)){
21288 ((SgNamespaceAliasDeclarationStatement*)node)->get_scope()->get_symbol_table()->remove(symbol);
21290 //printf("A SgNamespaceSymbol was deleted\n");
21301 if(isSgLabelStatement(node) !=NULL){
21306 if(isSgLabelSymbol(symbol)){
21315 if(isSgLabelRefExp(node) !=NULL){
21327 if(isSgEnumDeclaration(node) !=NULL){
21328 if(((SgEnumDeclaration*)node)->get_scope()!=NULL){
21329 if(((SgEnumDeclaration*)node)->get_scope()->get_symbol_table()!=NULL)
21331 SgSymbol* symbol = ((SgEnumDeclaration*)node)->get_symbol_from_symbol_table();
21332 if(isSgEnumSymbol(symbol) !=NULL){
21333 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21335 //printf("A SgEnumSymbol was deleted\n");
21339 SgEnumType* type= ((SgEnumDeclaration*)node)->get_type();
21342 //printf("A SgEnumType was deleted\n");
21351 if(isSgClassDeclaration(node) !=NULL && isSgTemplateInstantiationDecl(node) ==NULL){
21356 if(isSgClassSymbol(symbol) !=NULL){
21358 traverseMemoryPoolVisitorPattern(visitor);
21359 if(visitor.get_num_Class_pointers()==1){
21369 traverseMemoryPoolVisitorPattern(visitor);
21378 if(isSgThisExp(node) !=NULL){
21381 traverseMemoryPoolVisitorPattern(visitor);
21382 if(visitor.get_num_Class_pointers()==1){
21383 ((
SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21390 if(isSgClassNameRefExp(node) !=NULL){
21392 if(isSgClassSymbol(symbol) !=NULL)
21395 traverseMemoryPoolVisitorPattern(visitor);
21396 if(visitor.get_num_Class_pointers()==1){
21397 ((
SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21409 if(isSgMemberFunctionDeclaration(node) !=NULL){
21410 if(((SgMemberFunctionDeclaration*)node)->get_scope()!=NULL){
21411 if(((SgMemberFunctionDeclaration*)node)->get_scope()->get_symbol_table()!=NULL)
21413 SgSymbol* symbol = ((SgMemberFunctionDeclaration*)node)->get_symbol_from_symbol_table();
21414 if(isSgMemberFunctionSymbol(symbol)){
21415 ClassicVisitor visitor((SgMemberFunctionSymbol*)symbol);
21416 traverseMemoryPoolVisitorPattern(visitor);
21417 if(visitor.get_num_memFunc_pointers()==1){
21418 ((SgMemberFunctionDeclaration*)node)->get_scope()->get_symbol_table()->remove(symbol);
21420 //printf("A SgMemberFunctionSymbol was deleted\n");
21425 ClassicVisitor visitor((SgMemberFunctionDeclaration*) node);
21426 traverseMemoryPoolVisitorPattern(visitor);
21429//Tan: I have no idea why the codes below cannot work. Perhaps it conflicts with some prior works
21431 if(isSgMemberFunctionRefExp(node) !=NULL){
21432 SgMemberFunctionSymbol* symbol = ((SgMemberFunctionRefExp*)node)->get_symbol_i();
21433 ClassicVisitor visitor(symbol);
21434 traverseMemoryPoolVisitorPattern(visitor);
21435 if(visitor.get_num_memFunc_pointers()==1){ //only one reference to this symbol => safe to delete
21436 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21438 //printf("A SgClassSymbol was deleted\n");
21443 if(isSgFunctionType(node) !=NULL){
21444 SgSymbol* symbol = ((SgFunctionType*)node)->get_symbol_from_symbol_table();
21445 if(isSgFunctionTypeSymbol(symbol)){
21446 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21448 //printf("A SgFunctionTypeSymbol was deleted\n");
21457 if(isSgInterfaceStatement(node) !=NULL){
21462 if(isSgInterfaceSymbol(symbol)){
21473 if(isSgModuleStatement(node) !=NULL){
21478 if(isSgModuleSymbol(symbol)){
21491 if(isSgTemplateInstantiationMemberFunctionDecl(node) !=NULL){
21496 if(isSgMemberFunctionSymbol(symbol)){
21498 traverseMemoryPoolVisitorPattern(visitor);
21499 if(visitor.get_num_memFunc_pointers()==1){
21508 traverseMemoryPoolVisitorPattern(visitor);
21511 if(isSgTemplateDeclaration(node) !=NULL){
21517 traverseMemoryPoolVisitorPattern(visitor);
21518 if(visitor.get_num_Template_pointers()==1){
21521 printf(
"A SgTemplateSymbol was deleted\n");
21527 traverseMemoryPoolVisitorPattern(visitor1);
21532 if(isSgInterfaceStatement(node) !=NULL){
21537 if(isSgInterfaceSymbol(symbol)){
21548 if(isSgModuleStatement(node) !=NULL){
21553 if(isSgModuleSymbol(symbol)){
21563 if(isSgTemplateInstantiationDecl(node) !=NULL){
21568 if(isSgClassSymbol(symbol)){
21570 traverseMemoryPoolVisitorPattern(visitor);
21571 if(visitor.get_num_Class_pointers()==1){
21590 printf(
"SgTemplateArg in normal traversal\n");
21592 printf(
"SgTemplateInstantiationDecl in normal traversal\n");
21595 traverseMemoryPoolVisitorPattern(visitor);
21605 printf (
"After delete node: node = %p = %s \n",node,node->
class_name().c_str());
21611 DeleteAST deleteTree;
21614 deleteTree.traverse(n,postorder);
21617 printf (
"Leaving SageInterface::deleteAST(): n = %p = %s \n",n,n->
class_name().c_str());
21644 virtual void visit(
SgNode* n)
21647 if (expression != NULL)
21649 Visitor().traverse(expression->get_originalExpressionTree(), postorder);
21656 Visitor().traverse(root, postorder);
21668 SgSymbol* symbol = s_table->find(iname);
21669 ASSERT_not_null(symbol);
21674 ASSERT_not_null(sourceBlock);
21675 ASSERT_not_null(targetBlock);
21690 SgSymbol* symbol = s_table->find(iname);
21691 ASSERT_not_null(symbol);
21698 ASSERT_not_null(symbol);
21709 ASSERT_require(stmt->
get_parent() == targetBlock);
21724 func->set_scope(targetBlock);
21727 SgFunctionDeclaration* nondef_decl= isSgFunctionDeclaration(func->get_firstNondefiningDeclaration());
21728 if (func != nondef_decl)
21730 ASSERT_not_null(nondef_decl);
21737 else if (
auto labelStmt = isSgLabelStatement(stmt))
21739 if (labelStmt->get_scope() == sourceBlock) {
21740 labelStmt->set_scope(targetBlock);
21745 else if (isSgJovialTableStatement(stmt) || isSgTypedefDeclaration(stmt) || isSgEnumDeclaration(stmt))
21753 mlog[Rose::Diagnostics::WARN] <<
"test failing stmt->get_scope() == targetBlock in SageInterface::moveStatementsBetweenBlocks(): class: "
21760 if (declaration !=
nullptr)
21767 case V_SgVariableDeclaration:
21772 for (SgInitializedNamePtrList::iterator ii = l.begin(); ii != l.end(); ii++)
21782 SgType* var_type = init_name->get_type();
21785 var_type = mod_type->get_base_type();
21792 if (isSgEnumType(var_type))
21794 SgEnumType* enum_type = isSgEnumType(var_type);
21809 enumerator->set_scope(targetBlock);
21813 else if (isSgJovialTableType(var_type))
21829 SgVariableSymbol* var_sym = isSgVariableSymbol(init_name -> search_for_symbol_from_symbol_table ()) ;
21830 ASSERT_not_null(var_sym);
21833 if (old_scope != sourceBlock)
21835 old_scope->remove_symbol (var_sym);
21836 sourceBlock ->
insert_symbol(init_name->get_name(), var_sym);
21839 init_name->set_scope(targetBlock);
21840 initname_vec.push_back(init_name);
21844 case V_SgFunctionDeclaration:
21847 ASSERT_not_null(funcDecl);
21854 if (old_scope != sourceBlock)
21856 old_scope->remove_symbol (func_sym);
21864 case V_SgProgramHeaderStatement:
21865 case V_SgProcedureHeaderStatement:
21866 case V_SgClassDeclaration:
21867 case V_SgEnumDeclaration:
21870 ASSERT_not_null(nondef_decl);
21884 if (
auto proc = isSgProcedureHeaderStatement(nondef_decl)) {
21885 for (
auto arg : proc->get_parameterList()->get_args()) {
21886 if (arg->get_scope() != proc->get_scope()) {
21890 arg->set_scope(proc->get_scope());
21902 name->set_scope(targetBlock);
21907 case V_SgJovialTableStatement:
21911 ROSE_ASSERT (table);
21920 case V_SgTypedefDeclaration:
21924 ASSERT_not_null(typedef_decl);
21929 case V_SgAttributeSpecificationStatement:
21930 case V_SgEmptyDeclaration:
21931 case V_SgFortranIncludeLine:
21932 case V_SgImplicitStatement:
21933 case V_SgJovialDefineDeclaration:
21934 case V_SgJovialDirectiveStatement:
21935 case V_SgJovialLabelDeclaration:
21936 case V_SgJovialOverlayDeclaration:
21937 case V_SgPragmaDeclaration:
21938 case V_SgAdaAttributeClause:
21942 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());
21951template <
class T1,
class T2>
21952void moveDeclarationsBetweenScopes( T1* sourceBlock, T2* targetBlock)
21956 ROSE_ASSERT (sourceBlock && targetBlock);
21957 ROSE_ASSERT (sourceBlock->containsOnlyDeclarations() && targetBlock->containsOnlyDeclarations());
21958 if ((
void*)sourceBlock == (
void*)targetBlock)
21960 cerr<<
"warning: SageInterface::moveStatementsBetweenScopes() is skipped, "<<endl;
21961 cerr<<
" since program is trying to move statements from and to the identical scoped block. "<<endl;
21965 SgDeclarationStatementPtrList& srcStmts = sourceBlock->get_declarations ();
21966 std::vector <SgInitializedName*> initname_vec;
21968 for (
auto stmt : srcStmts)
21970 moveOneStatement(sourceBlock, targetBlock, stmt, initname_vec);
21975 ROSE_ASSERT(srcStmts.empty() ==
true);
21976 ROSE_ASSERT(sourceBlock->get_declarations().empty() ==
true);
21979 moveSymbolTableBetweenBlocks(sourceBlock, targetBlock, initname_vec);
21992template <
class T1,
class T2>
21993void moveStatementsBetweenScopes( T1* sourceBlock, T2* targetBlock)
21996 ROSE_ASSERT (sourceBlock && targetBlock);
21997 if ((
void*)sourceBlock == (
void*)targetBlock)
21999 cerr<<
"warning: SageInterface::moveStatementsBetweenScopes() is skipped, "<<endl;
22000 cerr<<
" since program is trying to move statements from and to the identical scoped block. "<<endl;
22004 SgStatementPtrList & srcStmts = sourceBlock->get_statements();
22005 std::vector <SgInitializedName*> initname_vec;
22009 moveOneStatement(sourceBlock, targetBlock, stmt, initname_vec);
22014 ROSE_ASSERT(srcStmts.empty() ==
true);
22015 ROSE_ASSERT(sourceBlock->get_statements().empty() ==
true);
22018 moveSymbolTableBetweenBlocks(sourceBlock, targetBlock, initname_vec);
22032 ASSERT_not_null(decl);
22036 ASSERT_require(local_def && global_def && (local_def!=global_def));
22038 for (
auto symbol : local_def->get_symbol_table()->get_symbols())
22040 SgSymbol *orig_sym = isSgSymbol(symbol);
22041 ASSERT_not_null(orig_sym);
22050 moveDeclarationsBetweenScopes(sourceBlock, targetBlock);
22052 createAliasSymbols(isSgNamespaceDeclarationStatement(targetBlock->
get_parent()));
22057 moveStatementsBetweenScopes(sourceBlock, targetBlock);
22059 createAliasSymbols(isSgNamespaceDeclarationStatement(targetBlock->
get_parent()));
22064 moveDeclarationsBetweenScopes(sourceBlock, targetBlock);
22070 moveStatementsBetweenScopes (sourceBlock, targetBlock);
22078 ROSE_ASSERT (func != NULL);
22080 ROSE_ASSERT (p != NULL);
22082 if (le && le->get_lambda_function() == func)
22095 #pragma message ("WARNING: MSVC does not handle isLambdaCapturedVariable() properly.")
22097 ROSE_ASSERT (varRef!= NULL);
22101 SgThisExp* te = isSgThisExp(p->get_lhs_operand_i());
22105 ROSE_ASSERT (csym!= NULL);
22108 ROSE_ASSERT (xdecl != NULL);
22112 if (le->get_lambda_closure_class() == xdecl )
22128 ROSE_ASSERT(current != NULL);
22130 if (isSgInitializedName(current))
22132 name = isSgInitializedName(current);
22134 else if (isSgPntrArrRefExp(current) != NULL)
22138 ROSE_ASSERT(exp != NULL);
22140 ROSE_ASSERT(suc ==
true);
22144 else if (isSgVarRefExp(current) != NULL)
22150 if (isSgDotExp(parent))
22152 if (isSgDotExp(parent)->get_rhs_operand() == current)
22158 if (isSgArrowExp(parent)->get_rhs_operand() == current)
22162 name = isSgVarRefExp(current)->get_symbol()->get_declaration();
22164 else if (isSgFunctionRefExp(current) != NULL ||
22165 isSgTemplateFunctionRefExp(current) != NULL ||
22166 isSgMemberFunctionRefExp(current) != NULL ||
22167 isSgTemplateMemberFunctionRefExp(current) != NULL)
22172 else if (isSgNonrealRefExp(current) != NULL)
22177 else if (isSgDotExp(current))
22184 ROSE_ASSERT(child);
22188 else if (isSgArrowExp(current))
22209 ROSE_ASSERT(child);
22214 else if (isSgThisExp(current))
22219 else if (isSgPointerDerefExp(current))
22223 else if(isSgUnaryOp(current)) {
22226 else if (isSgCastExp(current))
22232 else if (isSgAddOp(current))
22237 else if (isSgSubtractOp(current))
22248 else if (isSgIntVal(current))
22258 if (!isSgConstructorInitializer(current))
22260 mlog[Sawyer::Message::Common::WARN] <<
22261 "convertRefToInitializedName: " <<
22264 cerr<<
"In SageInterface::convertRefToInitializedName(): unhandled reference type:"<<current->
class_name()<<endl;
22275#ifdef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22276 printf (
"AbstractHandle support is disabled for ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT \n");
22282 size_t pos = input_string.find(
"SourceFile<");
22283 ROSE_ASSERT (pos != string::npos);
22284 string trimed_string = input_string.substr(pos);
22288 if (handle->getNode()!=NULL)
22293#pragma message ("WARNING: covariant return type for get_node() not supported in MSVC.")
22294 printf (
"ERROR: covariant return type for get_node() not supported in MSVC. \n");
22317 ROSE_ASSERT(node != NULL);
22320 cout<<
"///////////// begin of SageInterface::dumpInfo() ///////////////"<<endl;
22321 cout<<
"--------------base info. for SgNode---------------"<<endl;
22327 cout<<
"--------------source location info. for SgNode---------------"<<endl;
22335 cout<<
"--------------preprocessing info. for SgNode---------------"<<endl;
22336 AttachedPreprocessingInfoType::iterator i;
22337 cout<<
"Total attached preprocessingInfo count="<<comments->size()<<endl;
22338 for (i = comments->begin (); i != comments->end (); i++)
22341 pinfo->display(
"");
22344 cout<<
"--------------name info. for SgNode---------------"<<endl;
22348 cout<<
"\tqualified name="<<decl->get_qualified_name().getString()<<endl;
22351 cout<<
"\treferenced variable name= "<<varRef->get_symbol()->
get_name().getString()<<endl;
22358 cout<<
"///////////// end of SageInterface::dumpInfo() ///////////////"<<endl;
22369 bool retVal =
true;
22371 ROSE_ASSERT(stmt !=NULL);
22373#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22380 if (funcDecl != NULL)
22383 if (funcDecl == NULL)
22385 cerr<<
"In collectReadWriteRefs(): cannot proceed without a function body!"<<endl;
22388 stmt = funcDecl->get_definition()->
get_body();
22396 ROSE_ASSERT(funcDef != NULL);
22398 ROSE_ASSERT(funcBody!= NULL);
22401 AstInterfaceImpl faImpl(funcBody);
22402 AstInterface fa(&faImpl);
22403 ArrayAnnotation* annot = ArrayAnnotation::get_inst();
22404 if( useCachedDefUse ){
22405 ArrayInterface* array_interface = ArrayInterface::get_inst(*annot, fa, funcDef, AstNodePtrImpl(funcDef));
22406 LoopTransformInterface::set_arrayInfo(array_interface);
22408 ArrayInterface array_interface(*annot);
22411 array_interface.observe(fa);
22412 LoopTransformInterface::set_arrayInfo(&array_interface);
22414 LoopTransformInterface::set_astInterface(fa);
22416 LoopTransformInterface::set_sideEffectInfo(annot);
22419 DoublyLinkedListWrap<AstNodePtr> rRef1, wRef1;
22420 CollectDoublyLinkedList<AstNodePtr> crRef1(rRef1),cwRef1(wRef1);
22421 AstNodePtr s1 = AstNodePtrImpl(stmt);
22424 if (!AnalyzeStmtRefs(fa, s1, cwRef1, crRef1))
22429 mlog[Sawyer::Message::Common::DEBUG] <<
"Function: " << funcDef->get_declaration()->get_qualified_name() <<
" calls at least one function that has not been annotated." << endl;
22434 for (DoublyLinkedEntryWrap<AstNodePtr>* p = rRef1.First(); p != 0; )
22436 DoublyLinkedEntryWrap<AstNodePtr>* p1 = p;
22438 AstNodePtr cur = p1->GetEntry();
22439 SgNode* sgRef = AstNodePtrImpl(cur).get_ptr();
22440 ROSE_ASSERT(sgRef != NULL);
22441 readRefs.push_back(sgRef);
22446 for (DoublyLinkedEntryWrap<AstNodePtr>* p = wRef1.First(); p != 0; )
22448 DoublyLinkedEntryWrap<AstNodePtr>* p1 = p;
22450 AstNodePtr cur = p1->GetEntry();
22451 SgNode* sgRef = AstNodePtrImpl(cur).get_ptr();
22452 ROSE_ASSERT(sgRef != NULL);
22453 writeRefs.push_back(sgRef);
22466static bool skipSomeRefs(
SgNode* n)
22469 return (isSgThisExp(n)||isSgArrowExp(n)||isSgDotExp(n));
22475 ROSE_ASSERT(stmt != NULL);
22476 vector <SgNode* > readRefs, writeRefs;
22480 vector<SgNode*>::iterator iter = readRefs.begin();
22481 for (; iter!=readRefs.end();iter++)
22483 SgNode* current = *iter;
22486 ROSE_ASSERT (current != NULL);
22489 if (!name)
continue;
22492 readVars.insert(name);
22495 vector<SgNode*>::iterator iterw = writeRefs.begin();
22496 for (; iterw!=writeRefs.end();iterw++)
22498 SgNode* current = *iterw;
22499 ROSE_ASSERT (current != NULL);
22501 if (!name)
continue;
22505 writeVars.insert(name);
22513 ROSE_ASSERT(stmt != NULL);
22514 set<SgInitializedName*> readVars, writeVars;
22519 set_difference(readVars.begin(), readVars.end(),
22520 writeVars.begin(), writeVars.end(),
22521 std::inserter(readOnlyVars, readOnlyVars.begin()));
22531 readOnlyVars.insert (v_ref->get_symbol()->get_declaration());
22541 set<SgInitializedName*> temp;
22544 for (set<SgInitializedName*>::const_iterator iter = temp.begin();
22545 iter!=temp.end(); iter++)
22547 SgSymbol* symbol = (*iter)->get_symbol_from_symbol_table () ;
22548 ROSE_ASSERT(symbol != NULL );
22549 ROSE_ASSERT(isSgVariableSymbol(symbol));
22550 readOnlySymbols.insert(isSgVariableSymbol(symbol));
22558 bool result =
false;
22559 ROSE_ASSERT(ref != NULL);
22571 ROSE_ASSERT(grandparent);
22572 if (isSgFunctionCallExp(grandparent))
22578 size_t param_index = 0;
22580 SgExpressionPtrList expList = isSgExprListExp(ref->
get_parent())->get_expressions();
22581 Rose_STL_Container<SgExpression*>::const_iterator iter= expList.begin();
22582 for (; iter!=expList.end(); iter++)
22590 SgExpression* func_exp = isSgFunctionCallExp(grandparent)->get_function();
22591 ROSE_ASSERT (func_exp);
22596 SgInitializedNamePtrList nameList = funcDecl->get_args();
22601 if (param_index >= nameList.size() ||isSgTypeEllipse(nameList[param_index]->get_type()) )
22603 if (isSgReferenceType(ref))
22607 if (isSgReferenceType(nameList[param_index]->get_type()))
22612 else if (isSgDotExp (func_exp) || isSgArrowExp(func_exp))
22615 ROSE_ASSERT (binOp);
22617 ROSE_ASSERT (mfuncRef);
22619 ROSE_ASSERT (mfuncDecl);
22620 SgInitializedNamePtrList nameList = mfuncDecl->get_args();
22622 if (isSgReferenceType(nameList[param_index]->get_type()))
22637 Rose_STL_Container <SgNode*> var_refs = NodeQuery::querySubTree (
const_cast<SgStatement *
> (s), V_SgVarRefExp);
22639 Rose_STL_Container<SgNode*>::iterator iter = var_refs.begin();
22640 for (; iter!=var_refs.end(); iter++)
22643 ROSE_ASSERT(ref != NULL);
22650 varSetB.insert(ref);
22656 ROSE_ASSERT(grandparent);
22657 if (isSgFunctionCallExp(grandparent))
22660 int param_index =0;
22661 SgExpressionPtrList expList = isSgExprListExp(ref->
get_parent())->get_expressions();
22662 Rose_STL_Container<SgExpression*>::const_iterator iter= expList.begin();
22663 for (; iter!=expList.end(); iter++)
22671 SgFunctionRefExp * funcRef = isSgFunctionRefExp(isSgFunctionCallExp(grandparent)->get_function());
22673 SgInitializedNamePtrList nameList = funcDecl->get_args();
22675 if (isSgReferenceType(nameList[param_index]->get_type()))
22677 varSetB.insert(ref);
22683 varSetB.insert(ref);
22687#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22692 static LivenessAnalysis* liv = NULL;
22696 static DFAnalysis * defuse = NULL;
22700 ROSE_ASSERT(project != NULL);
22701 defuse =
new DefUseAnalysis(project);
22704 ROSE_ASSERT(defuse != NULL);
22705 defuse->run(debug);
22708 defuse->dfaToDOT();
22711 liv =
new LivenessAnalysis(debug,(DefUseAnalysis*)defuse);
22712 ROSE_ASSERT(liv != NULL);
22714 std::vector <FilteredCFGNode < IsDFAFilter > > dfaFunctions;
22715 NodeQuerySynthesizedAttributeType vars =
22716 NodeQuery::querySubTree(project, V_SgFunctionDefinition);
22717 NodeQuerySynthesizedAttributeType::const_iterator i;
22718 bool abortme=
false;
22720 for (i= vars.begin(); i!=vars.end();++i)
22723 ROSE_ASSERT(func != NULL);
22727 string funcName = func->get_declaration()->get_qualified_name().str();
22728 cout<<
" .. running liveness analysis for function: " << funcName << endl;
22730 FilteredCFGNode <IsDFAFilter> rem_source = liv->run(func,abortme);
22732 liv->fixupStatementsINOUT(func);
22733 if (rem_source.getNode()!=NULL)
22734 dfaFunctions.push_back(rem_source);
22740 cout <<
"Writing out liveness analysis results into var.dot... " << endl;
22741 std::ofstream f2(
"var.dot");
22742 dfaToDot(f2,
string(
"var"), dfaFunctions, (DefUseAnalysis*)defuse, liv);
22746 cerr<<
"Error: Liveness analysis is ABORTING ." << endl;
22754#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22758 ROSE_ASSERT(liv != NULL);
22759 ROSE_ASSERT(loop != NULL);
22761 std::vector<SgInitializedName*> liveIns0, liveOuts0;
22771 CFGNode cfgnode(forstmt,2);
22772 FilteredCFGNode<IsDFAFilter> filternode= FilteredCFGNode<IsDFAFilter> (cfgnode);
22776 ROSE_ASSERT(filternode.getNode()==forstmt);
22779 vector<FilteredCFGEdge < IsDFAFilter > > out_edges = filternode.outEdges();
22780 ROSE_ASSERT(out_edges.size()==2);
22781 vector<FilteredCFGEdge < IsDFAFilter > >::iterator iter= out_edges.begin();
22783 for (; iter!=out_edges.end();iter++)
22785 FilteredCFGEdge < IsDFAFilter > edge= *iter;
22789 if (edge.condition()==eckTrue)
22791 SgNode* firstnode= edge.target().getNode();
22792 liveIns0 = liv->getIn(firstnode);
22794 for (std::vector<SgInitializedName*>::iterator iter = liveIns0.begin();
22795 iter!=liveIns0.end(); iter++)
22798 liveIns.insert(*iter);
22803 else if (edge.condition()==eckFalse)
22805 SgNode* firstnode= edge.target().getNode();
22806 liveOuts0 = liv->getIn(firstnode);
22808 for (std::vector<SgInitializedName*>::iterator iter = liveOuts0.begin();
22809 iter!=liveOuts0.end(); iter++)
22813 liveOuts.insert(*iter);
22818 cerr<<
"Unexpected CFG out edge type for SgForStmt!"<<endl;
22827static bool isAssignReduction (
SgVarRefExp* ref_exp1,
SgVarRefExp* ref_exp2, OmpSupport::omp_construct_enum& optype)
22829 bool isReduction =
false;
22831 ROSE_ASSERT (ref_exp1!= NULL);
22832 ROSE_ASSERT (ref_exp2!= NULL);
22833 ROSE_ASSERT (ref_exp1-> get_symbol() == ref_exp2-> get_symbol());
22839 if (stmt != stmt2)
return false;
22846 if (exp_stmt && isSgAssignOp(exp_stmt->get_expression()))
22849 assign_lhs = isSgAssignOp(exp_stmt->get_expression())->
get_lhs_operand();
22850 assign_rhs = isSgAssignOp(exp_stmt->get_expression())->
get_rhs_operand();
22851 ROSE_ASSERT(assign_lhs && assign_rhs);
22859 SgBinaryOp * binop = isSgBinaryOp(assign_rhs);
22865 if( !((op_lhs==ref_exp1)||(op_lhs==ref_exp2))
22866 && !((op_rhs==ref_exp1)||(op_rhs==ref_exp2)))
22869 bool isOnLeft =
false;
22870 if ((op_lhs==ref_exp1)||
22871 (op_lhs==ref_exp2))
22877 optype = OmpSupport::e_reduction_plus;
22878 isReduction =
true;
22881 case V_SgMultiplyOp:
22883 optype = OmpSupport::e_reduction_mul;
22884 isReduction =
true;
22887 case V_SgSubtractOp:
22889 optype = OmpSupport::e_reduction_minus;
22892 isReduction =
true;
22898 optype = OmpSupport::e_reduction_bitand ;
22899 isReduction =
true;
22904 optype = OmpSupport::e_reduction_bitxor;
22905 isReduction =
true;
22910 optype = OmpSupport::e_reduction_bitor;
22911 isReduction =
true;
22916 optype = OmpSupport::e_reduction_logand;
22917 isReduction =
true;
22922 optype = OmpSupport::e_reduction_logor;
22923 isReduction =
true;
22932 return isReduction;
22941 bool matchStmt1 =
false;
22942 bool matchStmt2 =
false;
22949 ROSE_ASSERT (ref1 != NULL);
22950 ROSE_ASSERT (ref2 != NULL);
22951 ROSE_ASSERT (ref1-> get_symbol() == ref2-> get_symbol());
22959 if (stmt1 == stmt2)
return false;
22982 bool matchBody =
false;
22983 bool matchCondition=
false;
22984 if (
SgIfStmt * if_stmt = isSgIfStmt (if_cond_stmt->get_parent()) )
22986 if (
SgStatement* body = if_stmt->get_true_body())
22991 ROSE_ASSERT(stmt2 != NULL);
22992 if ( ((block->get_statements()).size() == 1) && stmt2->
get_scope() == block )
23003 if (
SgExprStatement* cond_exp_stmt = isSgExprStatement (if_stmt->get_conditional()) )
23005 SgExpression* cond_exp = cond_exp_stmt->get_expression();
23006 if (
SgBinaryOp * binop = isSgBinaryOp (cond_exp))
23011 if (isSgLessThanOp (binop))
23013 optype = OmpSupport::e_reduction_max;
23014 matchCondition=
true;
23016 else if (isSgGreaterThanOp(binop))
23018 optype = OmpSupport::e_reduction_min;
23019 matchCondition=
true;
23025 if (isSgLessThanOp (binop))
23027 optype = OmpSupport::e_reduction_min;
23028 matchCondition=
true;
23030 else if (isSgGreaterThanOp(binop))
23032 optype = OmpSupport::e_reduction_max;
23033 matchCondition=
true;
23040 matchStmt1 = matchBody && matchCondition;
23044 return (matchStmt2 && matchStmt1);
23051static bool isSingleAppearanceReduction(
SgVarRefExp* ref1, OmpSupport::omp_construct_enum& optype )
23053 bool isReduction =
false;
23055 ROSE_ASSERT (ref1 != NULL);
23061 if (isSgExprStatement(stmt))
23063 SgExpression* exp = isSgExprStatement(stmt)->get_expression();
23065 if (isSgPlusPlusOp(exp))
23068 optype = OmpSupport::e_reduction_plus;
23069 isReduction =
true;
23071 else if (isSgMinusMinusOp(exp))
23073 optype = OmpSupport::e_reduction_minus;
23074 isReduction =
true;
23085 case V_SgPlusAssignOp:
23087 optype = OmpSupport::e_reduction_plus;
23088 isReduction =
true;
23091 case V_SgMultAssignOp:
23093 optype = OmpSupport::e_reduction_mul;
23094 isReduction =
true;
23097 case V_SgMinusAssignOp:
23099 optype = OmpSupport::e_reduction_minus;
23100 isReduction =
true;
23103 case V_SgAndAssignOp:
23105 optype = OmpSupport::e_reduction_bitand;
23106 isReduction =
true;
23109 case V_SgXorAssignOp:
23111 optype = OmpSupport::e_reduction_bitxor;
23112 isReduction =
true;
23115 case V_SgIorAssignOp:
23117 optype = OmpSupport::e_reduction_bitor;
23118 isReduction =
true;
23127 return isReduction;
23159 std::set<SgInitializedName*> candidateVars;
23161 std::map <SgInitializedName*, vector<SgVarRefExp* > > var_references;
23163 Rose_STL_Container<SgNode*> reflist = NodeQuery::querySubTree(loop, V_SgVarRefExp);
23165 ROSE_ASSERT(lbody != NULL);
23166 Rose_STL_Container<SgNode*>::iterator iter = reflist.begin();
23167 for (; iter!=reflist.end(); iter++)
23176 ROSE_ASSERT(var_scope != NULL);
23177 if ((
isScalarType(initname->get_type())) &&(initname !=loopindex)
23180 candidateVars.insert(initname);
23181 var_references[initname].push_back(ref_exp);
23186 std::set<SgInitializedName*>::iterator niter=candidateVars.begin();
23187 for (; niter!=candidateVars.end(); niter++)
23190 bool isReduction =
false;
23191 OmpSupport::omp_construct_enum optype;
23193 if (var_references[initname].size()==1)
23195 mlog[Sawyer::Message::Common::DEBUG] <<
"Debug: SageInterface::ReductionRecognition() A candidate used once:"<<initname->get_name().getString()<<endl;
23196 SgVarRefExp* ref_exp = *(var_references[initname].begin());
23197 if (isSingleAppearanceReduction (ref_exp, optype))
23198 isReduction =
true;
23201 else if (var_references[initname].size()==2)
23203 mlog[Sawyer::Message::Common::DEBUG] <<
"Debug: A candidate used twice:"<<initname->get_name().getString()<<endl;
23204 SgVarRefExp* ref_exp1 = *(var_references[initname].begin());
23205 SgVarRefExp* ref_exp2 = *(++var_references[initname].begin());
23208 if (isAssignReduction (ref_exp1, ref_exp2, optype) || isIfReduction (ref_exp1, ref_exp2, optype) )
23210 isReduction =
true;
23216 results.insert(make_pair(initname,optype));
23223 ROSE_ASSERT(r!=NULL);
23224#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
23225 ConstantFolding::constantFoldingOptimization(r,
false);
23235 virtual void visit (
SgNode * n)
23242 ROSE_ASSERT (name_attribute != NULL);
23250 exampleTraversal.
traverse(project, preorder);
23282 const SgInitializedNamePtrList& orig_decls = params.
get_args();
23284 std::transform( orig_decls.begin(), orig_decls.end(), sg::sage_inserter(copy), sg::InitNameCloner(copy, fundef) );
23298 sg::swap_child(ll, rr, &SgFunctionDeclaration::get_definition, &SgFunctionDeclaration::set_definition);
23299 sg::swap_child(ll, rr, &SgFunctionDeclaration::get_parameterList, &SgFunctionDeclaration::set_parameterList);
23309 std::pair<SgStatement*, SgInitializedName*>
23323 SgType* result_type = definingDeclaration.get_type()->get_return_type();
23328 SgFunctionDeclaration* wrapperfn = SB::buildDefiningFunctionDeclaration(newName, result_type, ¶m_list, containing_scope);
23331 ROSE_ASSERT(wrapperdef);
23334 wrapperfn->set_exceptionSpecification(definingDeclaration.get_exceptionSpecification());
23338 swapDefiningElements(definingDeclaration, *wrapperfn);
23343 SgInitializedNamePtrList& param_decls = param_list.
get_args();
23345 std::transform( param_decls.begin(), param_decls.end(), sg::sage_inserter(*args), sg::VarRefBuilder(*wrapperdef) );
23347 SgFunctionCallExp* callWrapped = SB::buildFunctionCallExp( newName, result_type, args, body );
23352 if (!isSgTypeVoid(result_type))
23355 SgVariableDeclaration* res = SB::buildVariableDeclaration(
"res", result_type, SB::buildAssignInitializer(callWrapped), body );
23362 callStatement = res;
23369 callStatement = SB::buildExprStatement(callWrapped);
23373 ROSE_ASSERT(callStatement);
23377 SgFunctionDeclaration* wrapperfn_proto = SB::buildNondefiningFunctionDeclaration(wrapperfn, containing_scope, decorator_proto);
23383 return std::make_pair(callStatement, resultName);
23391 struct VarrefBuilder
23410 template <
class AstNode>
23411 struct VarrefCreator : VarrefBuilder
23416 VarrefCreator(AstNode& orig)
23420 SgVarRefExp*
get()
const {
return VarrefBuilder::build(origin); }
23423 template <
class AstNode>
23424 VarrefCreator<AstNode>
23425 varrefCreator(AstNode& n)
23427 return VarrefCreator<AstNode>(n);
23437 return SB::buildMultiplyOp(lhs, SI::deepCopy(rhs));
23440 std::pair<std::vector<SgExpression*>,
SgType*>
23441 get_C_array_dimensions_aux(
const SgArrayType& arr_type)
23447 std::vector<SgExpression*> indices;
23448 SgType* undertype = NULL;
23452 if (arrtype->get_index() == NULL)
23454 indices.push_back(SB::buildNullExpression());
23455 undertype = arrtype->get_base_type();
23456 arrtype = isSgArrayType(undertype);
23462 ROSE_ASSERT(indexexpr);
23464 indices.push_back(SI::deepCopy(indexexpr));
23465 undertype = arrtype->get_base_type();
23466 arrtype = isSgArrayType(undertype);
23469 ROSE_ASSERT((!indices.empty()) && undertype);
23470 return std::make_pair(indices, undertype);
23474 std::vector<SgExpression*>
23475 get_C_array_dimensions_aux(
const SgArrayType& arrtype,
const VarrefBuilder& varrefBuilder)
23479 std::pair<std::vector<SgExpression*>,
SgType*> res = get_C_array_dimensions_aux(arrtype);
23480 const std::vector<SgExpression*>::iterator first = res.first.begin();
23483 if (isSgNullExpression(*first))
23491 const std::vector<SgExpression*>::iterator aa = first+1;
23492 const std::vector<SgExpression*>::iterator zz = res.first.end();
23494 SgExpression* sz_undertype = SB::buildSizeOfOp(res.second);
23495 SgExpression* denominator = std::accumulate(aa, zz, sz_undertype, create_mulop);
23496 SgSizeOfOp* sz_var = SB::buildSizeOfOp(varrefBuilder.get());
23497 SgExpression* sz = SB::buildDivideOp(sz_var, denominator);
23499 std::swap(*first, sz);
23507 std::vector<SgExpression*>
23510 return get_C_array_dimensions_aux(arrtype).first;
23513 std::vector<SgExpression*>
23516 return get_C_array_dimensions_aux(arrtype, varrefCreator(varref));
23519 std::vector<SgExpression*>
23522 return get_C_array_dimensions_aux(arrtype, varrefCreator(initname));
23529 set<unsigned int> sourceSequenceSet;
23531 void visit (
SgNode* astNode );
23539 if (fileInfo != NULL)
23541 unsigned int source_sequence_number = fileInfo->get_source_sequence_number();
23543 printf (
"In CollectSourceSequenceNumbers::visit(): source_sequence_number = %" PRIuPTR
" \n",source_sequence_number);
23545 sourceSequenceSet.insert(source_sequence_number);
23555 traversal.
traverse(astNode,preorder);
23557 return traversal.sourceSequenceSet;
23644#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
23646 if (collapsing_factor <= 1)
23659 ROSE_ASSERT (global_scope != NULL);
23668 bool *isPlus =
new bool[collapsing_factor];
23672 std::vector<SgForStatement* > loops= SageInterface::querySubTree<SgForStatement>(target_loop,V_SgForStatement);
23673 ROSE_ASSERT(loops.size()>=collapsing_factor);
23689 ROSE_ASSERT(
getScope(target_loop)->get_parent()!= NULL);
23693 while(scope == NULL)
23695 parent = isSgStatement(parent->
get_parent());
23696 scope = isSgScopeStatement(parent);
23700 if (insert_target != NULL)
23705 ROSE_ASSERT(scope != NULL);
23708 for(
size_t i = 0; i < collapsing_factor; i ++)
23710 temp_target_loop = loops[i];
23715 if (!
isCanonicalForLoop(temp_target_loop, &ivar[i], &lb[i], &ub[i], &step[i], &orig_body[i], &isPlus[i]))
23717 cerr<<
"Error in SageInterface::loopCollapsing(): target loop is not canonical."<<endl;
23725 delete[] orig_body;
23726 delete[] total_iters;
23733 ROSE_ASSERT(ivar[i]&& lb[i] && ub[i] && step[i]);
23737 if(isPlus[i] ==
true)
23751 string iter_var_name=
"_total_iters";
23772 new_var_list->append_expression(isSgVarRefExp(ub_exp));
23775 for(
unsigned int i = 0; i < collapsing_factor; i++)
23778 for(
unsigned int j = collapsing_factor - 1; j > i; j--)
23787 new_var_list->append_expression(isSgVarRefExp(interval[i]));
23797 ROSE_ASSERT(insert_target != NULL);
23802 new_var_list->append_expression(clps_index_ref);
23808 ROSE_ASSERT(body != NULL);
23811 std::vector<SgStatement*> new_stmt_list;
23822 for(
unsigned int i = 0; i < collapsing_factor - 1; i ++)
23824 if(isPlus[i] ==
true)
23830 new_stmt_list.push_back(assign_stmt);
23833 if(i != collapsing_factor - 2){
23834 string remain_var_name=
"_remainder";
23835 remain_var_name =
"__"+ ivar[i]->get_name().getString() + remain_var_name;
23838 new_stmt_list.push_back(loop_index_decl);
23844 if(isPlus[collapsing_factor - 1] ==
true)
23848 new_stmt_list.push_back(assign_stmt);
23860 ROSE_ASSERT(cond_stmt != NULL);
23867 target_loop = new_loop;
23869 ConstantFolding::constantFoldingOptimization(scope->
get_parent(),
false);
23875 delete [] orig_body;
23876 delete [] total_iters;
23877 delete [] interval;
23882 return new_var_list;
23901 RoseAst ast_of_original(tree2);
23910 while (i_copy != ast_of_copy.
end())
23913 printf (
"*i_copy = %p = %s \n",*i_copy,(*i_copy)->class_name().c_str());
23914 printf (
"*i_original = %p = %s \n",*i_original,(*i_original)->class_name().c_str());
23918 if ((*i_copy)->variantT() != (*i_original)->variantT())
23921 printf (
"ERROR: return from SageInterface::isStructurallyEquivalentAST(): (*i_copy)->variantT() != (*i_original)->variantT() \n");
23924 printf (
"Making this an error! \n");
23934 ROSE_ASSERT(i_original != ast_of_original.
end());
23939 ROSE_ASSERT(i_copy == ast_of_copy.
end() && i_original == ast_of_original.
end());
23959 lower_bound = NULL;
23960 upper_bound = NULL;
23964 const std::vector<SgStatement *> & init_stmts = for_init_stmt->
get_init_stmt();
23965 assert(init_stmts.size() == 1);
23967 assert(init_stmt != NULL);
23970 SgAssignOp * assign_init = isSgAssignOp(init);
23971 assert(assign_init != NULL);
23973 assert(iterator_init_ref != NULL);
23974 iterator = iterator_init_ref->get_symbol();
23975 assert(iterator != NULL);
23978 SgExprStatement * test_stmt = isSgExprStatement(for_loop->get_test());
23979 assert(test_stmt != NULL);
23985 while (isSgCastExp(lhs_exp)) lhs_exp = ((
SgCastExp *)lhs_exp)->get_operand_i();
23986 SgVarRefExp * lhs_var_ref = isSgVarRefExp(lhs_exp);
23987 bool lhs_it = (lhs_var_ref != NULL) && (lhs_var_ref->get_symbol() == iterator);
23990 while (isSgCastExp(rhs_exp)) rhs_exp = ((
SgCastExp *)rhs_exp)->get_operand_i();
23991 SgVarRefExp * rhs_var_ref = isSgVarRefExp(rhs_exp);
23993 bool rhs_it = (rhs_var_ref != NULL) && (rhs_var_ref->get_symbol() == iterator);
24001 assert(lhs_it != rhs_it);
24010 case V_SgGreaterOrEqualOp:
24011 inclusive = lhs_it;
24014 case V_SgGreaterThanOp:
24015 inclusive = !lhs_it;
24018 case V_SgLessOrEqualOp:
24019 inclusive = lhs_it;
24020 reversed = !lhs_it;
24022 case V_SgLessThanOp:
24023 inclusive = !lhs_it;
24024 reversed = !lhs_it;
24026 case V_SgEqualityOp:
24027 case V_SgNotEqualOp:
24033 switch (increment->variantT()) {
24034 case V_SgPlusPlusOp:
24038 case V_SgMinusMinusOp:
24042 case V_SgPlusAssignOp:
24047 assert(var_ref_lhs != NULL && var_ref_lhs->get_symbol() == iterator);
24052 case V_SgMinusAssignOp:
24057 assert(var_ref_lhs != NULL && var_ref_lhs->get_symbol() == iterator);
24067 assert(inc_assign_lhs != NULL && inc_assign_lhs->get_symbol() == iterator);
24070 assert(inc_assign_rhs != NULL);
24072 if (inc_assign_rhs_lhs != NULL && inc_assign_rhs_lhs->get_symbol() == iterator)
24075 if (inc_assign_rhs_rhs != NULL && inc_assign_rhs_rhs->get_symbol() == iterator)
24096#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
24103 jstring temp_directory = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(::currentJavaTraversalClass, Rose::Frontend::Java::Ecj::getTempDirectoryMethod);
24105 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_directory, NULL);
24107 string directory_name = utf8;
24108 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_directory, utf8);
24110 list<string> sourcepath = project -> get_Java_sourcepath();
24111 sourcepath.push_back(directory_name);
24112 project -> set_Java_sourcepath(sourcepath);
24114 return directory_name;
24122 string command = string(
"rm -fr ") + directory_name;
24123 int status = system(command.c_str());
24124 ROSE_ASSERT(status == 0);
24135 project -> get_sourceFileNameList().push_back(filename);
24136 Rose_STL_Container<std::string> arg_list = project -> get_originalCommandLineArgumentList();
24137 arg_list.push_back(filename);
24140 int error_code = 0;
24141 SgFile *file = determineFileType(arg_list, error_code, project);
24143 ROSE_ASSERT(sourcefile);
24144 sourcefile -> set_parent(project);
24149 project -> get_fileList_ptr() -> get_listOfFiles().push_back(sourcefile);
24150 ROSE_ASSERT(sourcefile == isSgSourceFile((*project)[filename]));
24152 sourcefile -> build_Java_AST(arg_list, project -> get_originalCommandLineArgumentList());
24155 project -> get_fileList_ptr() -> get_listOfFiles().pop_back();
24156 ROSE_ASSERT(sourcefile != isSgSourceFile((*project)[filename]));
24160 ROSE_ASSERT(file->get_preprocessorDirectivesAndCommentsList() != NULL);
24171 string command =
"package " + package_name +
";";
24176 jstring temp_file = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
24177 Rose::Frontend::Java::Ecj::createTempFileMethod,
24178 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(command.c_str()));
24180 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_file, NULL);
24182 string filename = (string) utf8;
24183 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_file, utf8);
24187 return package_name;
24196 string command =
"import " + import_string +
";";
24201 jstring temp_file = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
24202 Rose::Frontend::Java::Ecj::createTempFileMethod,
24203 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(command.c_str()));
24205 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_file, NULL);
24207 string filename = (string) utf8;
24208 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_file, utf8);
24212 return import_string;
24224 jstring temp_file = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
24225 Rose::Frontend::Java::Ecj::createTempNamedFileMethod,
24226 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(file_name.c_str()),
24227 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(file_content.c_str()));
24229 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_file, NULL);
24231 string filename = (string) utf8;
24232 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_file, utf8);
24242 ROSE_ASSERT(scope);
24244 for (
int index = 0, length = package_name.size(); index < length; index++) {
24246 for (n = index; n < length; n++) {
24247 if (package_name[n] ==
'.') {
24251 string name = package_name.substr(index, n - index);
24253 SgClassSymbol *package_symbol = scope -> lookup_class_symbol(name);
24254 if (package_symbol == NULL) {
24258 SgJavaPackageDeclaration *package_declaration = isSgJavaPackageDeclaration(package_symbol -> get_declaration() -> get_definingDeclaration());
24259 ROSE_ASSERT(package_declaration);
24260 package_definition = package_declaration -> get_definition();
24261 ROSE_ASSERT(package_definition);
24262 scope = package_definition;
24267 return package_definition;
24275 SgGlobal *global_scope = project -> get_globalScopeAcrossFiles();
24277 if (package_definition == NULL) {
24283 if (create_directory) {
24284 Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
24285 Rose::Frontend::Java::Ecj::createTempNamedDirectoryMethod,
24286 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(package_name.c_str()));
24292 return package_definition;
24299 ROSE_ASSERT(package_definition);
24300 SgClassSymbol *class_symbol = package_definition -> lookup_class_symbol(class_name);
24303 : isSgClassDeclaration(class_symbol -> get_declaration() -> get_definingDeclaration()));
24304 if ((! class_declaration) || (! class_declaration -> attributeExists(
"complete"))) {
24305 string qualified_name = package_definition -> get_qualified_name().getString() +
"." + class_name;
24307 class_symbol = package_definition -> lookup_class_symbol(class_name);
24310 class_declaration = (class_symbol == NULL
24312 : isSgClassDeclaration(class_symbol -> get_declaration() -> get_definingDeclaration()));
24314 return class_declaration;
24330 SgClassDeclaration *class_declaration = isSgClassDeclaration(class_type -> get_declaration() -> get_definingDeclaration());
24331 ROSE_ASSERT(class_declaration);
24332 SgClassDefinition *scope = isSgClassDefinition(class_declaration -> get_scope());
24333 while (scope && (! isSgJavaPackageDeclaration(scope -> get_parent()))) {
24334 class_declaration = isSgClassDeclaration(scope -> get_parent());
24335 ROSE_ASSERT(class_declaration);
24336 scope = isSgClassDefinition(class_declaration -> get_scope());
24343 string class_name = class_declaration ->
get_name().getString();
24352 ROSE_ASSERT(class_definition);
24354 ROSE_ASSERT(type_list);
24356 ROSE_ASSERT(string_array_type);
24357 type_list -> append_argument(string_array_type);
24363 SgFunctionSymbol *method_symbol = class_definition -> lookup_function_symbol(
"main", member_function_type);
24365 return (method_symbol == NULL ? NULL : isSgMemberFunctionDeclaration(method_symbol -> get_declaration()));
24373 SgClassDeclaration *class_declaration = isSgClassDeclaration(class_type -> get_declaration() -> get_definingDeclaration());
24374 ROSE_ASSERT(class_declaration);
24387 ROSE_ASSERT (old_sym != NULL);
24388 ROSE_ASSERT (new_sym != NULL);
24389 ROSE_ASSERT (old_sym != new_sym);
24390 ROSE_ASSERT (scope != NULL);
24392 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(scope, V_SgVarRefExp);
24393 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
24396 if (vRef->get_symbol() == old_sym)
24397 vRef->set_symbol(new_sym);
24410 bool result =
true;
24412 bool includingSelf =
false;
24415 if (sourceFile == NULL)
24417 printf (
"In SageInterface::statementCanBeTransformed(): sourceFile not found \n");
24421 ROSE_ASSERT(sourceFile != NULL);
24423 if (sourceFile != NULL && sourceFile->get_unparse_tokens() ==
true && sourceFile->get_unparseHeaderFiles() ==
true)
24427 string source_filename = stmt->getFilenameString();
24429 printf (
"In SageInterface::statementCanBeTransformed(): source_filename = %s \n",source_filename.c_str());
24430 printf (
" --- Rose::includeFileMapForUnparsing.size() = %zu \n",Rose::includeFileMapForUnparsing.size());
24434 if (EDG_ROSE_Translation::edg_include_file_map.find(source_filename) != EDG_ROSE_Translation::edg_include_file_map.end())
24436 SgIncludeFile* include_file = EDG_ROSE_Translation::edg_include_file_map[source_filename];
24437 ROSE_ASSERT(include_file != NULL);
24439 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");
24441 if (include_file->get_can_be_supported_using_token_based_unparsing() ==
false)
24444 printf (
"NOTE: Transformations of this statement cannot be supported using the header file unparsing with token unparsing options! \n");
24454 printf (
"Not found in Rose::includeFileMapForUnparsing: source_filename = %s \n",source_filename.c_str());
24457 printf (
"Exiting as a test! \n");
24463 printf (
"Error: In statementCanBeTransformed(): this might be an issue! \n");
24476 ROSE_ASSERT (decl!= NULL);
24477 ROSE_ASSERT (target_scope != NULL);
24478 ROSE_ASSERT (target_scope != decl->
get_scope());
24485 if (isSgIfStmt (target_scope))
24488 if (target_scope == )
24498 case V_SgBasicBlock:
24510 case V_SgForStatement:
24514 ROSE_ASSERT(stmt != NULL);
24515 SgStatementPtrList& stmt_list = stmt->get_init_stmt();
24519 if (stmt_list.size() !=1)
24521 cerr<<
"Error in moveVariableDeclaration(): only single init statement is handled for SgForStatement now."<<endl;
24522 ROSE_ASSERT (stmt_list.size() ==1);
24525 ROSE_ASSERT (exp_stmt != NULL);
24526 SgAssignOp* assign_op = isSgAssignOp(exp_stmt->get_expression());
24527 ROSE_ASSERT (assign_op != NULL);
24537 if (init_name->get_initptr() != NULL)
24539 init_name->set_initptr(initor);
24542 stmt_list.insert (stmt_list.begin(), decl );
24548 cerr<<
"Error. Unhandled target scope type:"<<target_scope->
class_name()<<endl;
24549 ROSE_ASSERT (
false);
24555 ROSE_ASSERT(sym != NULL);
24557 if (orig_scope != target_scope)
24562 init_name->set_scope(target_scope);
24564 orig_scope->remove_symbol(sym);
24569 ROSE_ASSERT (target_scope->symbol_exists(sym));
24579 subtreeVal.hasValue_ =
true;
24581 if (isSgIntVal(valExp)) {
24582 subtreeVal.value_ = isSgIntVal(valExp)->get_value();
24583 }
else if (isSgLongIntVal(valExp)) {
24584 subtreeVal.value_ = isSgLongIntVal(valExp)->get_value();
24585 }
else if (isSgLongLongIntVal(valExp)) {
24586 subtreeVal.value_ = isSgLongLongIntVal(valExp)->get_value();
24587 }
else if (isSgShortVal(valExp)) {
24588 subtreeVal.value_ = isSgShortVal(valExp)->get_value();
24589 }
else if (isSgUnsignedIntVal(valExp)) {
24590 subtreeVal.value_ = isSgUnsignedIntVal(valExp)->get_value();
24591 }
else if (isSgUnsignedLongVal(valExp)) {
24592 subtreeVal.value_ = isSgUnsignedLongVal(valExp)->get_value();
24593 }
else if (isSgUnsignedLongLongIntVal(valExp)) {
24594 subtreeVal.value_ = isSgUnsignedLongLongIntVal(valExp)->get_value();
24595 }
else if (isSgUnsignedShortVal(valExp)) {
24596 subtreeVal.value_ = isSgUnsignedShortVal(valExp)->get_value();
24602 if (isSgModifierType(vRef->get_type()) == NULL) {
24605 val.hasValue_ =
false;
24608 if (isSgModifierType(vRef->get_type())->
get_typeModifier().get_constVolatileModifier().isConst()) {
24614 if (isSgAssignInitializer(ini)) {
24619 return variableEval.
traverse(rhs);
24623 val.hasValue_ =
false;
24629 if (isSgExpression(node) != NULL) {
24631 if (valueExp != NULL) {
24632 return this->getValueExpressionValue(valueExp);
24636 if (varRefExp != NULL) {
24638 return evaluateVariableReference(varRefExp);
24641 if (isSgAssignInitializer(node)) {
24642 if(synList.at(0).hasValue_){
24643 return synList.at(0);
24647 val.hasValue_ =
false;
24652 evaluatedValue.hasValue_ =
false;
24653 evaluatedValue.value_ = -1;
24655 if(synList.size() != 2){
24656 for(SynthesizedAttributesList::iterator it = synList.begin(); it != synList.end(); ++it){
24657 std::cout <<
"Node: " << node->unparseToString() <<
"\n" << (*it).value_ << std::endl;
24658 std::cout <<
"Parent: " << node->get_parent()->unparseToString() << std::endl;
24659 std::cout <<
"Parent, Parent: " << node->get_parent()->get_parent()->unparseToString() << std::endl;
24663 for (SynthesizedAttributesList::iterator it = synList.begin(); it != synList.end(); ++it) {
24664 if((*it).hasValue_){
24665 if (isSgAddOp(node)) {
24666 assert(synList.size() == 2);
24667 evaluatedValue.value_ = synList[0].value_ + synList[1].value_ ;
24668 evaluatedValue.hasValue_ =
true;
24669 }
else if (isSgSubtractOp(node)) {
24670 assert(synList.size() == 2);
24671 evaluatedValue.value_ = synList[0].value_ - synList[1].value_ ;
24672 evaluatedValue.hasValue_ =
true;
24673 }
else if (isSgMultiplyOp(node)) {
24674 assert(synList.size() == 2);
24675 evaluatedValue.value_ = synList[0].value_ * synList[1].value_ ;
24676 evaluatedValue.hasValue_ =
true;
24677 }
else if (isSgDivideOp(node)) {
24678 assert(synList.size() == 2);
24679 evaluatedValue.value_ = synList[0].value_ / synList[1].value_ ;
24680 evaluatedValue.hasValue_ =
true;
24681 }
else if (isSgModOp(node)) {
24682 assert(synList.size() == 2);
24683 evaluatedValue.value_ = synList[0].value_ % synList[1].value_ ;
24684 evaluatedValue.hasValue_ =
true;
24687 std::cerr <<
"Expression is not evaluatable" << std::endl;
24688 evaluatedValue.hasValue_ =
false;
24689 evaluatedValue.value_ = -1;
24690 return evaluatedValue;
24693 evaluatedValue.hasValue_ =
true;
24694 return evaluatedValue;
24697 evaluatedValue.hasValue_ =
false;
24698 evaluatedValue.value_ = -1;
24699 return evaluatedValue;
24712 class TypeEquivalenceChecker {
24714 TypeEquivalenceChecker(
bool profile,
bool useSemanticEquivalence)
24715 : profile_(profile), useSemanticEquivalence_(useSemanticEquivalence),
24716 namedType_(0), pointerType_(0), arrayType_(0), functionType_(0)
24722 if (isSgTypedefType(t)) {
24724 node = isSgTypedefType(t)->
stripType(SgType::STRIP_TYPEDEF_TYPE);
24726 if(useSemanticEquivalence_){
24727 if(isSgModifierType(t)){
24729 ROSE_ASSERT(modType != NULL);
24736 std::cout <<
"Hit volatile type, stripping of modifier type" << std::endl;
24737 node = modType->get_base_type();
24741 std::cout <<
"Hit restrict type, stripping of modifier type" << std::endl;
24742 node = modType->get_base_type();
24746 ROSE_ASSERT(node != NULL);
24751 bool equal =
false;
24752 if(t1 == NULL || t2 == NULL){
24753 std::string wasNull;
24759 std::cerr <<
"ERROR: " << wasNull <<
" was NULL" << std::endl;
24772 i != subT1.
end() && j != subT2.
end(); ++i, ++j) {
24777 nodeT1 = getBasetypeIfApplicable(nodeT1);
24778 nodeT2 = getBasetypeIfApplicable(nodeT2);
24782 if(isSgModifierType(nodeT1)){
24786 if(modT1.get_constVolatileModifier().isConst() != modT2.get_constVolatileModifier().isConst()){
24789 if(modT1.get_constVolatileModifier().isVolatile() != modT2.get_constVolatileModifier().isVolatile()){
24792 }
else if (isSgNamedType(nodeT1)) {
24796 i.skipChildrenOnForward();
24797 j.skipChildrenOnForward();
24803 if(!c1->get_autonomous_declaration()){
24806 if (!c2->get_autonomous_declaration()){
24815 }
else if (isSgPointerType(nodeT1)) {
24822 return typesAreEqual(t1->get_base_type(), t2->get_base_type());
24824 }
else if(isSgReferenceType(nodeT1)){
24828 return typesAreEqual(t1->get_base_type(), t2->get_base_type());
24829 }
else if (isSgArrayType(nodeT1)) {
24836 bool arrayBaseIsEqual = typesAreEqual(a1->get_base_type(), a2->get_base_type());
24840 bool arrayIndexExpressionIsEquivalent =
false;
24841 if(t1Index.hasValue_ && t2Index.hasValue_){
24842 if(t1Index.value_ == t2Index.value_){
24843 arrayIndexExpressionIsEquivalent =
true;
24846 bool arraysAreEqual = (arrayBaseIsEqual && arrayIndexExpressionIsEquivalent);
24847 return arraysAreEqual;
24848 }
else if (isSgFunctionType(nodeT1)) {
24856 if(typesAreEqual(funcTypeA->get_return_type(), funcTypeB->get_return_type())) {
24866 for(SgTypePtrList::const_iterator ii = funcTypeA->
get_arguments().begin(),
24873 if(!typesAreEqual((*ii), (*jj))) {
24893 std::cerr <<
"This feature for now is available with autotools only!" << std::endl;
24898int getNamedTypeCount() {
24902int getPointerTypeCount() {
24903 return pointerType_;
24906int getArrayTypeCount() {
24910int getFunctionTypeCount() {
24911 return functionType_;
24915 bool profile_, useSemanticEquivalence_;
24916 int namedType_, pointerType_, arrayType_, functionType_;
24919TypeEquivalenceChecker tec(
false,
false);
24920return tec.typesAreEqual(typeA, typeB);
24924std::set<SgStatement*>
24933 StatementTraversal() : count (0) {}
24934 void visit (
SgNode* node)
24939 returnset.insert(statement);
24945 std::set<SgStatement*> returnset;
24949 StatementTraversal traversal;
24950 traversal.traverse(node, preorder);
24952 return traversal.returnset;
24955std::set<SgStatement*>
24962 printf (
"In collectModifiedStatements(): node = %p = %s \n",node,node->
class_name().c_str());
24968 StatementTraversal() : count (0) {}
24969 void visit (
SgNode* node)
24974 returnset.insert(statement);
24980 std::set<SgStatement*> returnset;
24984 StatementTraversal traversal;
24985 traversal.traverse(node, preorder);
24987 return traversal.returnset;
24997 printf (
"In outputFileIds(): node = %p = %s \n",node,node->
class_name().c_str());
25003 LocatedNodeTraversal() {}
25004 void visit (
SgNode* node)
25007 if (locatedNode != NULL)
25010 printf (
"In outputFileIds(): isModified() == %s: locatedNode = %p = %s \n",locatedNode->
get_isModified() ?
"true" :
"false",locatedNode,locatedNode->
class_name().c_str());
25011 printf (
" --- file id = %d physical_file_id = %d \n",node->
get_file_info()->get_file_id(),node->
get_file_info()->get_physical_file_id());
25017 if (initializedName != NULL)
25019 printf (
"In outputFileIds(): isModified() == %s: initializedName = %p = %s \n",initializedName->
get_isModified() ?
"true" :
"false",initializedName,initializedName->
class_name().c_str());
25020 printf (
" --- file id = %d physical_file_id = %d \n",initializedName->
get_file_info()->get_file_id(),initializedName->
get_file_info()->get_physical_file_id());
25027 LocatedNodeTraversal traversal;
25028 traversal.traverse(node, preorder);
25031 printf (
"Exiting as a test! \n");
25037std::set<SgLocatedNode*>
25044 printf (
"In collectModifiedLocatedNodes(): node = %p = %s \n",node,node->
class_name().c_str());
25050 LocatedNodeTraversal() : count (0) {}
25051 void visit (
SgNode* node)
25054 if (locatedNode != NULL && locatedNode->
get_isModified() ==
true)
25057 printf (
"In collectModifiedLocatedNodes(): isModified() == true: locatedNode = %p = %s \n",locatedNode,locatedNode->
class_name().c_str());
25059 returnset.insert(locatedNode);
25065 std::set<SgLocatedNode*> returnset;
25069 LocatedNodeTraversal traversal;
25070 traversal.traverse(node, preorder);
25072 return traversal.returnset;
25083 printf (
"In resetModifiedLocatedNodes(): modifiedNodeSet.size() = %zu \n",modifiedNodeSet.size());
25086 std::set<SgLocatedNode*>::const_iterator i = modifiedNodeSet.begin();
25087 while (i != modifiedNodeSet.end())
25091 printf (
"Marking node = %p = %s as modified \n",node,node->
class_name().c_str());
25106 printf (
"\n\n##################################################### \n");
25107 printf (
"Report on modified statements: label = %s \n",label.c_str());
25110 if (sourceFile != NULL)
25112 printf (
" --- (SgSourceFile) filename = %s \n",sourceFile->
getFileName().c_str());
25116 SgGlobal* globalScope = isSgGlobal(node);
25117 if (globalScope != NULL)
25119 sourceFile = isSgSourceFile(globalScope->
get_parent());
25120 printf (
" --- (SgGlobal) filename = %s \n",sourceFile->
getFileName().c_str());
25124 ROSE_ASSERT(node != NULL);
25128 printf (
"In reportModifiedStatements(): collection.size() = %zu \n",collection.size());
25131 std::set<SgStatement*>::iterator i = collection.begin();
25132 while (i != collection.end())
25135 string filename = (*i)->get_file_info()->get_filename();
25138 if (filename ==
"transformation")
25141 printf (
" --- filename == transformation: sourceFile = %p using physical filename \n",sourceFile);
25144 SgSourceFile* sourceFile = TransformationSupport::getSourceFile(*i);
25145 if (sourceFile != NULL)
25151 printf (
" --- filename = %s modified statement = %p = %s \n",filename.c_str(),(*i),(*i)->class_name().c_str());
25159 printf (
"########################################################## \n");
25160 printf (
"reportModifiedStatements(): Called using label = %s \n",label.c_str());
25162 printf (
"########################################################## \n\n\n");
25165 printf (
"Exiting as a test! \n");
25166 ROSE_ASSERT(
false);
25178 printf (
"\n\n##################################################### \n");
25179 printf (
"Report on modified locatedNodes: label = %s \n",label.c_str());
25182 if (sourceFile != NULL)
25184 printf (
" --- (SgSourceFile) filename = %s \n",sourceFile->
getFileName().c_str());
25188 SgGlobal* globalScope = isSgGlobal(node);
25189 if (globalScope != NULL)
25191 sourceFile = isSgSourceFile(globalScope->
get_parent());
25192 printf (
" --- (SgGlobal) filename = %s \n",sourceFile->
getFileName().c_str());
25196 ROSE_ASSERT(node != NULL);
25200 printf (
"In reportModifiedLocatedNode(): collection.size() = %zu \n",collection.size());
25203 std::set<SgLocatedNode*>::iterator i = collection.begin();
25204 while (i != collection.end())
25207 string filename = (*i)->get_file_info()->get_filename();
25210 if (filename ==
"transformation")
25213 printf (
" --- filename == transformation: sourceFile = %p using physical filename \n",sourceFile);
25216 SgSourceFile* sourceFile = TransformationSupport::getSourceFile(*i);
25217 if (sourceFile != NULL)
25223 printf (
" --- filename = %s modified locatedNode = %p = %s \n",filename.c_str(),(*i),(*i)->class_name().c_str());
25231 printf (
"########################################################## \n");
25232 printf (
"reportModifiedLocatedNodes(): Called using label = %s \n",label.c_str());
25234 printf (
"########################################################## \n\n\n");
25237 printf (
"Exiting as a test! \n");
25238 ROSE_ASSERT(
false);
25252 ROSE_ASSERT(locatedNode != NULL);
25256 curprint (
"/* Inside of printOutComments() */");
25259 if (comments != NULL)
25262 printf (
"Found attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
class_name().c_str());
25263 curprint (
"/* Inside of printOutComments(): comments != NULL */");
25266 AttachedPreprocessingInfoType::iterator i;
25267 for (i = comments->begin(); i != comments->end(); i++)
25269 ROSE_ASSERT ( (*i) != NULL );
25270 printf (
" Attached Comment (relativePosition=%s): %s \n",
25273 PreprocessingInfo::relativePositionName((*i)->getRelativePosition()).c_str(),
25274 (*i)->getString().c_str());
25275 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
25279 (*i)->get_file_info()->display(
"comment/directive location");
25286 printf (
"In SageInterface::printOutComments(): No attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
class_name().c_str());
25296 bool returnValue =
false;
25298 ROSE_ASSERT(currentPreprocessingInfo != NULL);
25300 PreprocessingInfo::DirectiveType directive = currentPreprocessingInfo->getTypeOfDirective();
25302 if (directive == PreprocessingInfo::C_StyleComment ||
25303 directive == PreprocessingInfo::CplusplusStyleComment ||
25304 directive == PreprocessingInfo::FortranStyleComment ||
25305 directive == PreprocessingInfo::CpreprocessorBlankLine ||
25306 directive == PreprocessingInfo::ClinkageSpecificationStart ||
25307 directive == PreprocessingInfo::ClinkageSpecificationEnd)
25309 returnValue =
true;
25312 return returnValue;
25315std::vector<SgC_PreprocessorDirectiveStatement*>
25318 std::vector<SgC_PreprocessorDirectiveStatement*> directiveList;
25323 if (comments !=
nullptr)
25325 AttachedPreprocessingInfoType::iterator i;
25326 for (i = comments->begin (); i != comments->end(); i++)
25335 ROSE_ASSERT(directive != NULL);
25336 directiveList.push_back(directive);
25339 printf (
"directiveList.size() = %zu \n",directiveList.size());
25343 return directiveList;
25352 printf (
"In translateScopeToUseCppDeclarations(): declarationsOnly = %s scope = %p = %s \n",declarationsOnly ?
"true" :
"false",scope,scope->
class_name().c_str());
25354 std::map<SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> > directiveMap;
25356 if (declarationsOnly ==
true)
25360 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
25361 while (i != declarationList.end())
25364 ROSE_ASSERT(declaration != NULL);
25368 printf (
"attachDirectives.size() = %zu \n",attachDirectives.size());
25370 if (attachDirectives.empty() ==
false)
25372 directiveMap.insert(std::pair<
SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> >(declaration,attachDirectives));
25384 SgStatementPtrList::iterator i = statementList.begin();
25385 while (i != statementList.end())
25388 ROSE_ASSERT(statement != NULL);
25392 printf (
"attachDirectives.size() = %zu \n",attachDirectives.size());
25394 if (attachDirectives.empty() ==
false)
25396 directiveMap.insert(std::pair<
SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> >(statement,attachDirectives));
25403 printf (
"directiveMap.size() = %zu \n",directiveMap.size());
25405 printf (
"Processing the directiveMap: \n");
25406 std::map<SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> >::iterator i = directiveMap.begin();
25407 while (i != directiveMap.end())
25410 std::vector<SgC_PreprocessorDirectiveStatement*> directives = i->second;
25412 printf (
"statement = %p = %s \n",statement,statement->
class_name().c_str());
25413 printf (
"directives.size() = %zu \n",directives.size());
25415 std::vector<SgC_PreprocessorDirectiveStatement*>::iterator j = directives.begin();
25416 while (j != directives.end())
25425 ROSE_ASSERT(comments != NULL);
25427 AttachedPreprocessingInfoType deleteList;
25432 AttachedPreprocessingInfoType::iterator k;
25433 for (k = comments->begin(); k != comments->end(); k++)
25436 ROSE_ASSERT ( (*k) != NULL );
25437 printf (
" Attached Comment (relativePosition=%s): %s\n",
25438 ((*k)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
25439 (*k)->getString().c_str());
25440 printf (
"translateScopeToUseCppDeclarations(): Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*k)->getNumberOfLines(),(*k)->getColumnNumberOfEndOfString());
25447 printf (
"Do NOT delete *k = %p = %s \n",*k,(*k)->getString().c_str());
25451 printf (
"DO delete *k = %p = %s \n",*k,(*k)->getString().c_str());
25453 deleteList.push_back(*k);
25459 printf (
"Iterate over the deleteList: deleteList.size() = %zu comments->size() = %zu \n",deleteList.size(),comments->size());
25460 AttachedPreprocessingInfoType::iterator m = deleteList.begin();
25461 while (m != deleteList.end())
25465 comments->erase(std::remove(comments->begin(), comments->end(), *m), comments->end());
25467 printf (
" --- comments->size() = %zu \n",comments->size());
25479 printf (
"Leaving translateScopeToUseCppDeclarations(): scope = %p = %s \n",scope,scope->
class_name().c_str());
25489 CppTranslationTraversal() {}
25490 void visit (
SgNode* node)
25492 printf (
"In CppTranslationTraversal::visit(): node = %p = %s \n",node,node->
class_name().c_str());
25495 SgGlobal* globalScope = isSgGlobal(scope);
25496 if (globalScope != NULL)
25498 printf (
"In CppTranslationTraversal::visit(): processing scope = %p = %s \n",scope,scope->
class_name().c_str());
25505 printf (
"In SageInterface::translateToUseCppDeclarations(): Currently skipping all but global scope! \n");
25512 CppTranslationTraversal traversal;
25514 printf (
"In translateToUseCppDeclarations(): Calling traversal.traverse() \n");
25518 traversal.traverse(n, postorder);
25520 printf (
"Leaving translateToUseCppDeclarations(): DONE: Calling traversal.traverse() \n");
25527 cout<<
"--------------"<<endl;
25531 cout<<
"file info:\t ";
25532 lnode->get_file_info()->display();
25533 cout<<
"\n unparseToString:\t ";
25534 lnode->unparseToString();
25545static void serialize(SgTemplateArgumentPtrList& plist,
string& prefix,
bool hasRemaining, ostringstream& out,
string& edgeLabel)
25548 out<< (hasRemaining?
"|---":
"|___");
25551 out<<
" "<<edgeLabel<<
" ->";
25553 out<<
"@"<<&plist<<
" "<<
"SgTemplateArgumentPtrList ";
25557 int last_non_null_child_idx =-1;
25558 for (
int i = (
int) (plist.size())-1; i>=0; i--)
25562 last_non_null_child_idx = i;
25567 for (
size_t i=0; i< plist.size(); i++ )
25569 bool n_hasRemaining=
false;
25571 if (i+1 < plist.size())
25572 n_hasRemaining=
true;
25574 if ((
int)i< last_non_null_child_idx) n_hasRemaining =
true;
25576 string suffix= hasRemaining?
"| " :
" ";
25577 string n_prefix = prefix+suffix;
25578 string n_edge_label=
"";
25580 serialize (plist[i], n_prefix, n_hasRemaining, out,n_edge_label);
25593 out<< (hasRemaining?
"|---":
"|___");
25595 out<<
" "<<edgeLabel<<
" ->";
25598 out<<
" NULL "<<endl;
25603 out<<
"@"<<node<<
" "<< node->
class_name()<<
" ";
25609 out<< lnode->get_file_info()->get_filename() <<
" "<<lnode->get_file_info()->get_line()<<
":"<<lnode->get_file_info()->get_col();
25611 AttachedPreprocessingInfoType *comments =
25612 lnode->getAttachedPreprocessingInfo ();
25614 if (comments != NULL)
25617 out<<
" AttachedPreprocessingInfoType@"<<comments;
25619 AttachedPreprocessingInfoType::iterator i;
25621 for (i = comments->begin (); i != comments->end (); i++)
25623 if (i!=comments->begin ())
25626 out<<counter++<<
" ";
25635 out<<*i<<
" classification="<<PreprocessingInfo::directiveTypeName((*i)->getTypeOfDirective ()). c_str ();
25636 out<<
" string="<<(*i)->getString ().c_str ();
25637 out<<
" relative pos=" ;
25639 if ((*i)->getRelativePosition () == PreprocessingInfo::inside)
25641 else if ((*i)->getRelativePosition () == PreprocessingInfo::before)
25655 out<<
" first nondefining decl@"<< v->get_firstNondefiningDeclaration();
25656 out<<
" defining decl@"<< v->get_definingDeclaration();
25660 out<<
" value="<< f->get_value() <<
" declaration="<<f->get_declaration() <<
" name="<< f->get_name().getString();
25667 out<<
" renamed_function "<< f->get_renamed_function();
25670 out<<
" name="<< f->get_name() <<
" renamed decl "<<f->get_renamed() ;
25682 out<<
" enumType="<< f->get_enumType();
25690 out<<
" is_general_access"<< v->get_is_general_access();
25693 out<<
" is_anonymous:"<< v->get_is_anonymous ();
25698 out<<
" is_protected"<< v->get_is_protected();
25704 out<<
" type@"<< v->get_type();
25705 out<<
" initializer@"<< v->get_initializer();
25706 out<<
" scope@"<< v->get_scope();
25712 out<<
" template class decl@"<< f->get_templateDeclaration();
25715 out<<
" assoc. class decl@"<< f->get_associatedClassDeclaration();
25719 out<<
" member function decl@"<< ctor->get_declaration();
25722 if (
SgIntVal* v= isSgIntVal(node))
25723 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25726 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25729 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25732 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25735 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25738 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25741 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25744 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25747 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25750 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25753 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25756 out<<
" init name@"<< var_ref->get_symbol()->get_declaration() <<
" symbol name="<<var_ref->get_symbol()->get_name();
25759 out<<
" member func decl@"<< func_ref->get_symbol_i()->get_declaration();
25762 out<<
" template member func decl@"<< cnode->get_templateDeclaration();
25767 out<<
" func decl@"<< sym->get_declaration() <<
" func sym name="<<sym->
get_name();
25773 out<<
" ada renaming decl@"<< renaming_decl;
25779 out<<
" base_type@"<< v->get_base_type();
25784 out<<
" base_type@"<< v->get_base_type();
25787 out<<
" base_type@"<< v->get_base_type();
25790 out<<
" type@"<< v->get_type();
25793 out<<
" attribute@"<< v->get_attribute();
25796 out<<
" namespaceDeclaration="<< v->get_namespaceDeclaration();
25802 int total_count = children.size();
25803 int current_index=0;
25806 int last_non_null_child_idx =-1;
25807 for (
int i = (
int) (children.size())-1; i>=0; i--)
25811 last_non_null_child_idx = i;
25819 if (isSgTemplateInstantiationDecl (node))
25826 SgTemplateArgumentPtrList& plist = sn->get_templateArguments();
25827 bool n_hasRemaining=
false;
25828 if (last_non_null_child_idx>-1) n_hasRemaining =
true;
25829 string suffix= hasRemaining?
"| " :
" ";
25830 string n_prefix = prefix+suffix;
25831 string n_edge_label=
"";
25832 serialize_list(plist,
"SgTemplateArgumentPtrList", n_prefix, n_hasRemaining, out, n_edge_label);
25836 SgExpressionPtrList& plist = import_stmt->get_import_list();
25837 bool n_hasRemaining=
false;
25838 if (last_non_null_child_idx>-1) n_hasRemaining =
true;
25839 string suffix= hasRemaining?
"| " :
" ";
25840 string n_prefix = prefix+suffix;
25841 string n_edge_label=
"";
25842 serialize_list(plist,
"SgExpressionPtrList", n_prefix, n_hasRemaining, out, n_edge_label);
25848 for (
size_t i =0; i< children.size(); i++)
25850 bool n_hasRemaining=
false;
25852 if (current_index+1<total_count)
25853 n_hasRemaining=
true;
25856 if ((
int)i<last_non_null_child_idx) n_hasRemaining =
true;
25858 string suffix= hasRemaining?
"| " :
" ";
25859 string n_prefix = prefix+suffix;
25861 serialize (children[i], n_prefix, n_hasRemaining, out, successorNames[i]);
25870 serialize(node, prefix,
false, oss, label);
25891 serialize(node, prefix,
false, oss, label);
25893 textfile.open(filename, ios::out);
25894 textfile<<oss.str();
25899 textfile<<
"Types encountered ...."<<endl;
25900 ostringstream oss2;
25901 VariantVector vv(V_SgType);
25902 Rose_STL_Container<SgNode*> tnodes= NodeQuery::queryMemoryPool(vv);
25903 for (Rose_STL_Container<SgNode*>::const_iterator i = tnodes.begin(); i != tnodes.end(); ++i)
25905 serialize (*i, prefix,
false, oss2, label);
25907 textfile<<oss2.str();
25915 saveToPDF(node,
string(
"temp.pdf.json") );
25921 ROSE_ASSERT(node != NULL);
25928 bool rtval =
false;
25929 ROSE_ASSERT (node != NULL);
25933 string fname = finfo->get_filenameString();
25934 string buildtree_str1 = string(
"include-staging/gcc_HEADERS");
25935 string buildtree_str2 = string(
"include-staging/g++_HEADERS");
25936 string installtree_str1 = string(
"include/edg/gcc_HEADERS");
25937 string installtree_str2 = string(
"include/edg/g++_HEADERS");
25938 string system_headers = string(
"/usr/include");
25940 if ((fname.find (buildtree_str1, 0) != string::npos) ||
25941 (fname.find (buildtree_str2, 0) != string::npos) ||
25942 (fname.find (installtree_str1, 0) != string::npos) ||
25943 (fname.find (installtree_str2, 0) != string::npos) ||
25944 (fname.find (system_headers, 0) != string::npos)
25957 bool returnValue =
false;
25960 ROSE_ASSERT(fileInfo != NULL);
25961 string filename = fileInfo->get_filenameString();
25964 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());
25969 if (EDG_ROSE_Translation::edg_include_file_map.find(filename) == EDG_ROSE_Translation::edg_include_file_map.end())
25972 printf (
"This is NOT in the EDG_ROSE_Translation::edg_include_file_map \n");
25978 printf (
"This IS in the EDG_ROSE_Translation::edg_include_file_map \n");
25980 returnValue =
true;
25983 return returnValue;
25990 ROSE_ASSERT(return_type != NULL);
25991 ROSE_ASSERT(typeList != NULL);
25993 ROSE_ASSERT(fTable);
25998 SgFunctionType* funcType = isSgFunctionType(fTable->lookup_function_type(typeName));
26008 ROSE_ASSERT (lhs != NULL);
26009 ROSE_ASSERT (rhs != NULL);
26014 SgType* rt1 = lhs->get_return_type();
26015 SgType* rt2 = rhs->get_return_type();
26022 if (f1_arg_types.size() == f2_arg_types.size())
26026 size_t counter = 0;
26029 for (
size_t i=0; i< f1_arg_types.size(); i++)
26037 if (counter == f1_arg_types.size())
26059 ROSE_ASSERT(lhs != NULL);
26060 ROSE_ASSERT(rhs != NULL);
26062 bool isSame =
false;
26065 static int counter = 0;
26067 const SgType & X = *lhs;
26068 const SgType & Y = *rhs;
26076#define DEBUG_TYPE_EQUIVALENCE 0
26078#if DEBUG_TYPE_EQUIVALENCE
26079 printf (
"In SageInterface::isEquivalentType(): evaluation of type equivalence for lhs and rhs: counter = %d \n",counter);
26084#if DEBUG_TYPE_EQUIVALENCE || 0
26087 printf (
"In SageInterface::isEquivalentType(): evaluation of type equivalence for lhs and rhs: counter = %d \n",counter);
26093#if DEBUG_TYPE_EQUIVALENCE || 0
26099 printf (
"Output of type chain for lhs: \n");
26100 for (
size_t i = 0; i < X_typeChain.size(); i++)
26102 SgType* element_type = X_typeChain[i];
26103 printf (
"X_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
26104 printf (
" --- X_element_type unparseToString: = %s \n",element_type->
unparseToString().c_str());
26106 if (modifierType != NULL)
26110 printf (
" --- type chain modifier: %s \n",s.c_str());
26111 printf (
" --- type chain modifier: unparseToString: %s \n",modifierType->
unparseToString().c_str());
26115 printf (
"Output of type chain for rhs: \n");
26116 for (
size_t i = 0; i < Y_typeChain.size(); i++)
26118 SgType* element_type = Y_typeChain[i];
26119 printf (
"Y_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
26120 printf (
" --- Y_element_type unparseToString: = %s \n",element_type->
unparseToString().c_str());
26122 if (modifierType != NULL)
26126 printf (
" --- type chain modifier: %s \n",s.c_str());
26127 printf (
" --- type chain modifier: unparseToString: %s \n",modifierType->
unparseToString().c_str());
26138 if (counter >= 280)
26141 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);
26153 printf (
"ERROR: In SageInterface::isEquivalentType(): recursive limit exceeded for : counter = %d \n",counter);
26164 SgReferenceType* X_referenceType = isSgReferenceType(X_element_type);
26165 SgReferenceType* Y_referenceType = isSgReferenceType(Y_element_type);
26167 if (X_referenceType != NULL && Y_referenceType != NULL)
26169 X_element_type = X_referenceType->get_base_type();
26170 Y_element_type = Y_referenceType->get_base_type();
26181 SgPointerType* X_pointerType = isSgPointerType(X_element_type);
26182 SgPointerType* Y_pointerType = isSgPointerType(Y_element_type);
26184 if (X_pointerType != NULL && Y_pointerType != NULL)
26186 X_element_type = X_pointerType->get_base_type();
26187 Y_element_type = Y_pointerType->get_base_type();
26198 SgArrayType* X_arrayType = isSgArrayType(X_element_type);
26199 SgArrayType* Y_arrayType = isSgArrayType(Y_element_type);
26202 if (X_arrayType != NULL && Y_arrayType != NULL)
26204 X_element_type = X_arrayType->get_base_type();
26205 Y_element_type = Y_arrayType->get_base_type();
26207 SgExpression* X_array_index_expression = X_arrayType->get_index();
26208 SgExpression* Y_array_index_expression = Y_arrayType->get_index();
26210 if (X_array_index_expression == Y_array_index_expression)
26212#if DEBUG_TYPE_EQUIVALENCE || 0
26213 printf (
"In SageInterface::isEquivalentType(): counter = %d: Need to check the array size for static equivalence \n",counter);
26224#if DEBUG_TYPE_EQUIVALENCE || 0
26225 printf (
"In SageInterface::isEquivalentType(): counter = %d Need more complex test for expression equivalence \n",counter);
26228 printf (
" --- array index expressions: str1 = %s str2 = %s \n",str1.c_str(),str2.c_str());
26240 SgNonrealType* X_templateType = isSgNonrealType(X_element_type);
26241 SgNonrealType* Y_templateType = isSgNonrealType(Y_element_type);
26244 if (X_templateType != NULL && Y_templateType != NULL)
26246 string X_name = X_templateType->
get_name();
26247 string Y_name = Y_templateType->
get_name();
26249 SgNonrealDecl* X_templateDecl = isSgNonrealDecl(X_templateType->get_declaration());
26250 ROSE_ASSERT(X_templateDecl != NULL);
26251 SgNonrealDecl* Y_templateDecl = isSgNonrealDecl(Y_templateType->get_declaration());
26252 ROSE_ASSERT(Y_templateDecl != NULL);
26254 int X_template_parameter_position = X_templateDecl->get_template_parameter_position();
26255 int Y_template_parameter_position = Y_templateDecl->get_template_parameter_position();
26260#if DEBUG_TYPE_EQUIVALENCE
26263 printf (
"In SageInterface::isEquivalentType(): case SgNonrealType:\n");
26264 printf (
" -- X_name = %s Y_name = %s\n", X_name.c_str(),Y_name.c_str());
26265 printf (
" -- X_template_parameter_position = %d Y_template_parameter_position = %d\n", X_template_parameter_position,Y_template_parameter_position);
26266 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() :
"");
26267 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() :
"");
26268 printf (
" -- X_templateDecl->get_mangled_name() = %s\n", X_templateDecl->get_mangled_name().str());
26269 printf (
" -- Y_templateDecl->get_mangled_name() = %s\n", Y_templateDecl->get_mangled_name().str());
26271 bool value = (X_parent == Y_parent);
26273 if (value && X_templateDecl->get_is_template_param() && Y_templateDecl->get_is_template_param()) {
26274 value = (X_template_parameter_position == Y_template_parameter_position);
26275 }
else if (value && X_templateDecl->get_is_class_member() && Y_templateDecl->get_is_class_member()) {
26276 value = (X_name == Y_name);
26288 printf (
"Nothing to do here since we have explored all uniform pairs of intermediate types possible: isSame = %s \n",isSame ?
"true" :
"false");
26294#if DEBUG_TYPE_EQUIVALENCE
26295 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");
26302 SgModifierType* X_modifierType = isSgModifierType(X_element_type);
26303 SgModifierType* Y_modifierType = isSgModifierType(Y_element_type);
26305#if DEBUG_TYPE_EQUIVALENCE
26306 printf (
"In SageInterface::isEquivalentType(): counter = %d: type chain X_element_type = %p = %s Y_element_type = %p = %s \n",
26307 counter,X_element_type,X_element_type->
class_name().c_str(),Y_element_type,Y_element_type->
class_name().c_str());
26310 if (X_modifierType != NULL && Y_modifierType != NULL)
26313#if DEBUG_TYPE_EQUIVALENCE
26314 printf (
"In SageInterface::isEquivalentType(): loop: these are the both SgModifierType nodes: isSame = %s \n",isSame ?
"true" :
"false");
26316 if (X_modifierType == Y_modifierType)
26319#if DEBUG_TYPE_EQUIVALENCE
26320 printf (
"In SageInterface::isEquivalentType(): loop: these are the same modifier type: isSame = %s \n",isSame ?
"true" :
"false");
26327#if DEBUG_TYPE_EQUIVALENCE
26328 printf (
"In SageInterface::isEquivalentType(): loop: these are equivalent modifiers: check the base type: isSame = %s \n",isSame ?
"true" :
"false");
26332 isSame =
isEquivalentType(X_modifierType->get_base_type(),Y_modifierType->get_base_type());
26336#if DEBUG_TYPE_EQUIVALENCE
26337 printf (
"In SageInterface::isEquivalentType(): loop: these are not equivalent modifier types: check for default settings: isSame = %s \n",isSame ?
"true" :
"false");
26340 bool skippingOverIdentityModifier =
false;
26344#if DEBUG_TYPE_EQUIVALENCE
26345 printf (
"In SageInterface::isEquivalentType(): loop: found self-similar setting for lhs: isSame = %s \n",isSame ?
"true" :
"false");
26347 X_element_type = X_modifierType->get_base_type();
26350 skippingOverIdentityModifier =
true;
26355#if DEBUG_TYPE_EQUIVALENCE
26356 printf (
"In SageInterface::isEquivalentType(): loop: found self-similar setting for rhs: isSame = %s \n",isSame ?
"true" :
"false");
26358 Y_element_type = Y_modifierType->get_base_type();
26361 skippingOverIdentityModifier =
true;
26365#if DEBUG_TYPE_EQUIVALENCE
26366 printf (
"In SageInterface::isEquivalentType(): loop: skippingOverIdentityModifier = %s \n",skippingOverIdentityModifier ?
"true" :
"false");
26371 if (skippingOverIdentityModifier ==
true)
26373#if DEBUG_TYPE_EQUIVALENCE
26374 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");
26383#if DEBUG_TYPE_EQUIVALENCE
26384 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");
26388#if DEBUG_TYPE_EQUIVALENCE
26389 printf (
"In SageInterface::isEquivalentType(): loop: these are different modifier types: after recursive call to compare base types: isSame = %s \n",isSame ?
"true" :
"false");
26398 if (X_modifierType != NULL || Y_modifierType != NULL)
26400 bool isReduceable =
false;
26402 if (X_modifierType != NULL && X_modifierType->
get_typeModifier().isIdentity() ==
true)
26404#if DEBUG_TYPE_EQUIVALENCE
26405 printf (
"In SageInterface::isEquivalentType(): loop: found default setting for lhs: isSame = %s \n",isSame ?
"true" :
"false");
26407 X_element_type = X_modifierType->get_base_type();
26408 isReduceable =
true;
26411 if (Y_modifierType != NULL && Y_modifierType->
get_typeModifier().isIdentity() ==
true)
26413#if DEBUG_TYPE_EQUIVALENCE
26414 printf (
"In SageInterface::isEquivalentType(): loop: found default setting for rhs: isSame = %s \n",isSame ?
"true" :
"false");
26416 Y_element_type = Y_modifierType->get_base_type();
26417 isReduceable =
true;
26421#if DEBUG_TYPE_EQUIVALENCE
26422 printf (
"In SageInterface::isEquivalentType(): loop: these are different modifier types: after recursive call to compare base types: isReduceable = %s \n",isReduceable ?
"true" :
"false");
26424 if (isReduceable ==
true)
26436#if DEBUG_TYPE_EQUIVALENCE
26437 printf (
"In SageInterface::isEquivalentType(): loop: these are different modifier types: after recursive call to compare base types: isReduceable = %s isSame = %s \n",
26438 isReduceable ?
"true" :
"false",isSame ?
"true" :
"false");
26447 if (X_element_type == Y_element_type)
26450#if DEBUG_TYPE_EQUIVALENCE || 0
26452 printf (
"In SageInterface::isEquivalentType(): resolved to equal types: isSame = %s lhs = %p = %s rhs = %p = %s \n",
26455#if DEBUG_TYPE_EQUIVALENCE || 0
26458 const SgTypedefType* lhs_typedefType = isSgTypedefType(lhs);
26459 const SgTypedefType* rhs_typedefType = isSgTypedefType(rhs);
26461 if (lhs_typedefType != NULL || rhs_typedefType != NULL)
26464 if (lhs_typedefType != NULL)
26466 printf (
"lhs was a typedef: lhs = %p = %s \n",lhs,lhs->
unparseToString().c_str());
26468 if (rhs_typedefType != NULL)
26470 printf (
"rhs was a typedef: rhs = %p = %s \n",rhs,rhs->
unparseToString().c_str());
26473 printf (
" --- one was a typedef: lhs = %p = %s \n",lhs,lhs->
unparseToString().c_str());
26474 printf (
" --- one was a typedef: rhs = %p = %s \n",rhs,rhs->
unparseToString().c_str());
26485 SgReferenceType* X_referenceType = isSgReferenceType(X_element_type);
26486 SgReferenceType* Y_referenceType = isSgReferenceType(Y_element_type);
26488 if (X_referenceType != NULL || Y_referenceType != NULL)
26491 if (X_referenceType != NULL)
26493 X_element_type = X_referenceType->get_base_type();
26497 isReduceable =
false;
26500 if (Y_referenceType != NULL)
26502 Y_element_type = Y_referenceType->get_base_type();
26506 isReduceable =
false;
26509 if (isReduceable ==
true)
26530#if DEBUG_TYPE_EQUIVALENCE
26531 printf (
"In SageInterface::isEquivalentType(): loop: evaluation of inner types: isSame = %s \n",isSame ?
"true" :
"false");
26535 SgPointerType* X_pointerType = isSgPointerType(X_element_type);
26536 SgPointerType* Y_pointerType = isSgPointerType(Y_element_type);
26538 if (X_pointerType != NULL || Y_pointerType != NULL)
26541 if (X_pointerType != NULL)
26543 X_element_type = X_pointerType->get_base_type();
26547 isReduceable =
false;
26550 if (Y_pointerType != NULL)
26552 Y_element_type = Y_pointerType->get_base_type();
26556 isReduceable =
false;
26559 if (isReduceable ==
true)
26580#if DEBUG_TYPE_EQUIVALENCE
26581 printf (
"In SageInterface::isEquivalentType(): loop: evaluation of inner types: isSame = %s \n",isSame ?
"true" :
"false");
26585 SgArrayType* X_arrayType = isSgArrayType(X_element_type);
26586 SgArrayType* Y_arrayType = isSgArrayType(Y_element_type);
26588 if (X_arrayType != NULL || Y_arrayType != NULL)
26591 if (X_arrayType != NULL)
26593 X_element_type = X_arrayType->get_base_type();
26597 isReduceable =
false;
26600 if (Y_arrayType != NULL)
26602 Y_element_type = Y_arrayType->get_base_type();
26606 isReduceable =
false;
26609 if (isReduceable ==
true)
26630#if DEBUG_TYPE_EQUIVALENCE
26631 printf (
"In SageInterface::isEquivalentType(): loop: evaluation of inner types: isSame = %s \n",isSame ?
"true" :
"false");
26635 SgFunctionType* X_functionType = isSgFunctionType(X_element_type);
26636 SgFunctionType* Y_functionType = isSgFunctionType(Y_element_type);
26638 if (X_functionType != NULL || Y_functionType != NULL)
26640 bool value = ( (X_functionType != NULL && Y_functionType != NULL) && (X_functionType == Y_functionType) );
26643#if DEBUG_TYPE_EQUIVALENCE || 0
26644 printf (
"In SageInterface::isEquivalentType(): loop: Process case of SgFunctionType: value = %s \n",value ?
"true" :
"false");
26662 if (X_memberFunctionType != NULL || Y_memberFunctionType != NULL)
26665 printf (
"This should be unreachable code \n");
26669 bool value = ( (X_memberFunctionType != NULL && Y_memberFunctionType != NULL) && (X_memberFunctionType == Y_memberFunctionType) );
26670#if DEBUG_TYPE_EQUIVALENCE || 0
26671 printf (
"In SageInterface::isEquivalentType(): loop: Process case of SgMemberFunctionType: value = %s \n",value ?
"true" :
"false");
26684 bool X_isReduceable =
true;
26685 if (isSgTypeSignedLong(X_element_type) != NULL ||
26686 isSgTypeUnsignedInt(X_element_type) != NULL ||
26687 isSgTypeBool(X_element_type) != NULL ||
26688 isSgTypeInt(X_element_type) != NULL)
26690 X_isReduceable =
false;
26693 bool Y_isReduceable =
true;
26694 if (isSgTypeSignedLong(Y_element_type) != NULL ||
26695 isSgTypeUnsignedInt(Y_element_type) != NULL ||
26696 isSgTypeBool(Y_element_type) != NULL ||
26697 isSgTypeInt(Y_element_type) != NULL)
26699 Y_isReduceable =
false;
26701#if DEBUG_TYPE_EQUIVALENCE || 0
26702 printf (
"In SageInterface::isEquivalentType(): loop: Process default case: X_isReduceable = %s Y_isReduceable = %s \n",
26703 X_isReduceable ?
"true" :
"false",Y_isReduceable ?
"true" :
"false");
26705 if (X_isReduceable ==
true || Y_isReduceable ==
true)
26719#if DEBUG_TYPE_EQUIVALENCE || 0
26720 printf (
"In SageInterface::isEquivalentType(): loop: Process default case: X_element_type = %p = %s Y_element_type = %p = %s \n",
26721 X_element_type,X_element_type->
class_name().c_str(),Y_element_type,Y_element_type->
class_name().c_str());
26726 isSame = (X_element_type == Y_element_type);
26746#if DEBUG_TYPE_EQUIVALENCE || 0
26747 printf (
"In SageInterface::isEquivalentType(): isSame = %s \n",isSame ?
"true" :
"false");
26750#if DEBUG_TYPE_EQUIVALENCE || 0
26751 if (counter == 1 && isSame ==
true)
26753 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());
26760 printf (
" --- Output of type chain for lhs: \n");
26761 for (
size_t i = 0; i < X_typeChain.size(); i++)
26763 SgType* element_type = X_typeChain[i];
26764 printf (
" --- --- X_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
26766 if (modifierType != NULL)
26770 printf (
" --- type chain modifier: %s \n",s.c_str());
26774 printf (
" --- Output of type chain for rhs: \n");
26775 for (
size_t i = 0; i < Y_typeChain.size(); i++)
26777 SgType* element_type = Y_typeChain[i];
26778 printf (
" --- --- Y_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
26780 if (modifierType != NULL)
26784 printf (
" --- --- type chain modifier: %s \n",s.c_str());
26793 if (isSame ==
true)
26796 printf (
" --- isSame = %s \n",isSame ?
"true" :
"false");
26799 printf (
" --- --- X_element_type = %p = %s = %s \n",X_element_type,X_element_type->
class_name().c_str(),X_element_type->
unparseToString().c_str());
26800 printf (
" --- --- Y_element_type = %p = %s = %s \n",Y_element_type,Y_element_type->
class_name().c_str(),Y_element_type->
unparseToString().c_str());
26805 printf (
" --- isSame = %s \n",isSame ?
"true" :
"false");
26810 printf (
" --- counter = %d \n",counter);
26827 bool retval =
false;
26836 retval = function->get_marked_as_edg_normalization();
26844 if (templateInstantiationFunction != NULL)
26849 if (templateFunctionDeclaration != NULL)
26860 printf (
" --- case of templateInstantiationFunction: retval = %s \n",retval ?
"true" :
"false");
26865 if (templateInstantiationMemberFunction != NULL)
26868 templateInstantiationMemberFunction = isSgTemplateInstantiationMemberFunctionDecl(templateInstantiationMemberFunction->
get_firstNondefiningDeclaration());
26870 if (templateMemberFunctionDeclaration != NULL)
26881 printf (
" --- case of templateInstantiationMemberFunction: retval = %s \n",retval ?
"true" :
"false");
26893 printf(
"In detectCycleInType():\n");
26894 printf(
" -- from = %s\n", from.c_str());
26895 printf(
" -- type = %p (%s)\n", type, type->
class_name().c_str());
26897 std::vector<SgType *> seen_types;
26899 while (type != NULL) {
26902 ROSE_ASSERT(type != NULL);
26904 std::vector<SgType *>::const_iterator it = std::find(seen_types.begin(), seen_types.end(), type);
26905 if (it != seen_types.end()) {
26906 printf(
"ERROR: Cycle found in type = %p (%s):\n", type, type->
class_name().c_str());
26908 for (; it != seen_types.end(); it++) {
26909 printf(
" [%zd] %p (%s)\n", i, *it, (*it)->class_name().c_str());
26912 printf(
"-> detectCycleInType() was called from: %s\n", from.c_str());
26915 seen_types.push_back(type);
26925 if (isSgPointerMemberType(type) != NULL)
26932 type = modType->get_base_type();
26933 }
else if ( refType ) {
26934 type = refType->get_base_type();
26935 }
else if ( pointType ) {
26936 type = pointType->get_base_type();
26939 }
else if ( arrayType ) {
26940 type = arrayType->get_base_type();
26941 }
else if ( typedefType ) {
26946 ROSE_ASSERT(type != NULL);
26967 std::vector<SgFunctionDeclaration*> functionList;
26970 string filenameWithPath;
26973 TransformFunctionDefinitionsTraversal(): sourceFile(NULL), sourceFileId(-99) {}
26975 void visit (
SgNode* node)
26978 printf (
"In convertFunctionDefinitionsToFunctionPrototypes visit(): node = %p = %s \n",node,node->
class_name().c_str());
26981 if (temp_sourceFile != NULL)
26983 sourceFile = temp_sourceFile;
26987 filenameWithPath = sourceFile->get_sourceFileNameWithPath();
26989 printf (
"Found source file: id = %d name = %s \n",sourceFileId,sourceFile->get_sourceFileNameWithPath().c_str());
26994 if (functionDeclaration != NULL)
26997 ROSE_ASSERT(sourceFile != NULL);
27000 if (functionDeclaration == definingFunctionDeclaration)
27003 printf (
"Found a defining function declaration: functionDeclaration = %p = %s name = %s \n",
27004 functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
27006 printf (
" --- recorded source file: id = %d name = %s \n",sourceFileId,sourceFile->get_sourceFileNameWithPath().c_str());
27007 printf (
" --- source file: file_info: id = %d name = %s \n",
27012 bool isInSourceFile = (filenameWithPath == functionDeclaration->
get_file_info()->get_filenameString());
27014 printf (
" --- isInSourceFile = %s \n",isInSourceFile ?
"true" :
"false");
27018 if (isInSourceFile ==
true && functionDeclarationScope != NULL)
27021 printf (
" --- Found a defining function declaration: functionDeclarationScope = %p = %s \n",
27022 functionDeclarationScope,functionDeclarationScope->
class_name().c_str());
27026 functionList.push_back(functionDeclaration);
27034 TransformFunctionDefinitionsTraversal traversal;
27035 traversal.traverse(node, preorder);
27037 std::vector<SgFunctionDeclaration*> & functionList = traversal.functionList;
27040 printf (
"In convertFunctionDefinitionsToFunctionPrototypes(): functionList.size() = %zu \n",functionList.size());
27043 std::vector<SgFunctionDeclaration*>::iterator i = functionList.begin();
27044 while (i != functionList.end())
27047 ROSE_ASSERT(functionDeclaration != NULL);
27050 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27053 printf (
" --- Removing function declaration: functionDeclaration = %p = %s name = %s \n",
27054 functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
27064 printf (
"In convertFunctionDefinitionsToFunctionPrototypes(): exiting as a test! \n");
27075 ROSE_ASSERT(scope != NULL);
27077 printf (
"Output the statements in scope = %p = %s \n",scope,scope->
class_name().c_str());
27081 for (
size_t i = 0; i < statementList.size(); i++)
27088 printf (
"Exiting as a test at the end of evaluation of global scope! \n");
27101 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration = %p = %s name = %s \n",
27102 functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
27106 bool isConstructor =
false;
27108 if (tmp_memberFunctionDeclaration != NULL)
27110 isConstructor = tmp_memberFunctionDeclaration->get_specialFunctionModifier().isConstructor();
27113 if (isConstructor ==
true)
27115 printf (
"Skipping case of constructors (in building prototype from defining function declaration) \n");
27125 SgName name = functionDeclaration->get_name();
27126 SgType* return_type = functionDeclaration->get_type()->get_return_type();
27134 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration = %p \n",functionDeclaration);
27135 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->
get_firstNondefiningDeclaration());
27136 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->
get_definingDeclaration());
27140 for (
size_t i = 0; i < functionDeclaration->get_args().size(); i++)
27144 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration->get_args(): (i = %zu) arg = %p = %s isDefaultArgument = %s \n",
27145 i,arg,arg->get_name().str(),arg->
get_file_info()->isDefaultArgument() ?
"true" :
"false");
27146 printf (
" --- arg->get_initializer() = %p \n",arg->get_initializer());
27150 printf (
"NOTE: default argument (i = %zu) not reproduced in function prototype: arg = %p = %s \n",i,arg,arg->get_name().str());
27163 if (templateInstantiationFunctionDecl == NULL)
27170 if (templateInstantiationMemberFunctionDecl == NULL)
27179 bool isTemplateInstantiationMemberFunctionDecl =
false;
27184 bool buildTemplateInstantiation =
false;
27185 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
27190 ROSE_ASSERT(param_list == NULL || param_list->
get_parent() == NULL);
27192 switch (functionDeclaration->
variantT())
27194 case V_SgTemplateMemberFunctionDeclaration:
27197 printf (
"This function to replace the defining declaration with a non-defining declaration does not yet support template member functions \n");
27200 ROSE_ASSERT(original_templateMemberFunctionDeclaration != NULL);
27204 unsigned int functionConstVolatileFlags = 0;
27206 ROSE_ASSERT(original_templateMemberFunctionDeclaration->get_type() != NULL);
27211 SgMemberFunctionType* memberFunctionType = isSgMemberFunctionType(original_templateMemberFunctionDeclaration->get_type());
27212 ROSE_ASSERT(memberFunctionType != NULL);
27214 functionConstVolatileFlags = memberFunctionType->get_mfunc_specifier();
27220 SgTemplateParameterPtrList templateParameterList = original_templateMemberFunctionDeclaration->get_templateParameters();
27223 templateMemberFunctionDeclaration =
27226 printf (
"ERROR: Template functions are not yet supported! \n");
27229 nondefiningFunctionDeclaration = templateMemberFunctionDeclaration;
27231 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27234 if (isConstructor ==
true)
27236 templateMemberFunctionDeclaration->get_specialFunctionModifier().setConstructor();
27242 case V_SgTemplateFunctionDeclaration:
27245 printf (
"This function to replace the defining declaration with a non-defining declaration does not yet support template functions \n");
27248 ROSE_ASSERT(original_templateFunctionDeclaration != NULL);
27256 SgTemplateParameterPtrList templateParameterList = original_templateFunctionDeclaration->get_templateParameters();
27260 printf (
"ERROR: Template functions are not yet supported! \n");
27263 nondefiningFunctionDeclaration = templateFunctionDeclaration;
27265 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27271 case V_SgTemplateInstantiationMemberFunctionDecl:
27273 buildTemplateInstantiation =
true;
27275 isTemplateInstantiationMemberFunctionDecl =
true;
27278 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
27281 printf (
"name from functionDeclaration->get_name(): name = %s \n",name.str());
27283 printf (
"name from templateInstantiationMemberFunctionDecl->get_templateName(): template_name = %s \n",templateInstantiationMemberFunctionDecl->
get_templateName().str());
27285 if (templateDeclaration != NULL)
27287 printf (
"name from templateInstantiationMemberFunctionDecl->get_template_declaration()->get_name(): template_name = %s \n",templateDeclaration->get_name().str());
27288 printf (
"name from templateInstantiationMemberFunctionDecl->get_template_declaration()->get_template_name(): template_name = %s \n",templateDeclaration->
get_template_name().str());
27295 printf (
"In case V_SgTemplateInstantiationMemberFunctionDecl: using name = %s \n",name.str());
27300 case V_SgMemberFunctionDeclaration:
27303 printf (
"This function to replace the defining declaration with a non-defining declaration does not yet support member functions \n");
27306 ROSE_ASSERT(original_memberFunctionDeclaration != NULL);
27314 unsigned int functionConstVolatileFlags = 0;
27316 ROSE_ASSERT(original_memberFunctionDeclaration->get_type() != NULL);
27325 bool buildPrototype = isTemplateInstantiationMemberFunctionDecl || original_memberFunctionDeclaration->
get_parent() == original_memberFunctionDeclaration->
get_scope();
27327 printf (
"In SageInterface::buildFunctionPrototype(): buildPrototype = %s \n",buildPrototype ?
"true" :
"false");
27329 if (buildPrototype ==
true)
27331 SgMemberFunctionType* memberFunctionType = isSgMemberFunctionType(original_memberFunctionDeclaration->get_type());
27332 ROSE_ASSERT(memberFunctionType != NULL);
27334 printf (
"original_memberFunctionDeclaration->get_parent() == original_memberFunctionDeclaration->get_scope() \n");
27336 functionConstVolatileFlags = memberFunctionType->get_mfunc_specifier();
27338 memberFunctionDeclaration =
27340 ( name, return_type, param_list, scope, python_decoratorList, functionConstVolatileFlags,
27341 buildTemplateInstantiation,templateArgumentsList );
27343 printf (
"ERROR: Member functions are not yet supported! \n");
27347 if (isConstructor ==
true)
27349 memberFunctionDeclaration->get_specialFunctionModifier().setConstructor();
27352 nondefiningFunctionDeclaration = memberFunctionDeclaration;
27354 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27360 printf (
"NOTE: Member functions defined outside of their class can not be output as member function prototypes (not allowed in C++) \n");
27364 nondefiningFunctionDeclaration = NULL;
27366 nondefiningFunctionDeclaration = NULL;
27368 replaceWithEmptyDeclaration =
true;
27370 ROSE_ASSERT(emptyDeclaration != NULL);
27379 printf (
"Exiting as a test! \n");
27389 case V_SgFunctionDeclaration:
27392 nondefiningFunctionDeclaration =
buildNondefiningFunctionDeclaration (name, return_type, param_list, scope, python_decoratorList, buildTemplateInstantiation,templateArgumentsList);
27393 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27398 case V_SgTemplateInstantiationFunctionDecl:
27401 buildTemplateInstantiation =
true;
27403 ROSE_ASSERT(templateInstantiationFunctionDecl != NULL);
27406 printf (
"name from functionDeclaration->get_name(): name = %s \n",name.str());
27408 printf (
"name from templateInstantiationFunctionDecl->get_templateName(): template_name = %s \n",templateInstantiationFunctionDecl->
get_templateName().str());
27410 if (templateDeclaration != NULL)
27412 printf (
"name from templateInstantiationFunctionDecl->get_template_declaration()->get_name(): template_name = %s \n",templateDeclaration->get_name().str());
27413 printf (
"name from templateInstantiationFunctionDecl->get_template_declaration()->get_template_name(): template_name = %s \n",templateDeclaration->
get_template_name().str());
27418 printf (
"In case V_SgTemplateInstantiationFunctionDecl: using name = %s \n",name.str());
27420 nondefiningFunctionDeclaration =
buildNondefiningFunctionDeclaration (name, return_type, param_list, scope, python_decoratorList, buildTemplateInstantiation,templateArgumentsList);
27421 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
27440 ROSE_ASSERT(param_list == NULL || param_list->
get_parent() != NULL);
27446 if (nondefiningFunctionDeclaration != NULL)
27451 printf (
"Setting the firstNondefiningDeclaration \n");
27459 printf (
"Setting the definingDeclaration \n");
27468 if (nondefiningFunctionDeclaration != NULL)
27478 return nondefiningFunctionDeclaration;
27487 ROSE_ASSERT(functionDeclaration != NULL);
27490 printf (
"****************************************************************** \n");
27491 printf (
"Attached comments and CPP directives: defining functionDeclaration \n");
27493 printf (
"****************************************************************** \n");
27501 if (nondefiningFunctionDeclaration != NULL)
27512 if (templateInstantiationFunctionDecl == NULL)
27514 if (nondefiningFunctionDeclaration != NULL)
27517 nondefiningFunctionDeclaration->get_declarationModifier() = functionDeclaration->get_declarationModifier();
27520 nondefiningFunctionDeclaration->get_functionModifier() = functionDeclaration->get_functionModifier();
27521 nondefiningFunctionDeclaration->get_specialFunctionModifier() = functionDeclaration->get_specialFunctionModifier();
27523 nondefiningFunctionDeclaration->set_linkage( functionDeclaration->get_linkage() );
27524 nondefiningFunctionDeclaration->set_externBrace( functionDeclaration->get_externBrace() );
27526 ROSE_ASSERT(nondefiningFunctionDeclaration->get_forward() ==
true);
27529 int file_id = functionDeclaration->
get_file_info()->get_physical_file_id();
27530 nondefiningFunctionDeclaration->
get_file_info()->set_physical_file_id(file_id);
27546 ROSE_ASSERT(nondefiningFunctionDeclaration->
get_parent() != NULL);
27552 nondefiningFunctionDeclaration = NULL;
27556 if (functionDeclaration->get_declarationModifier().get_storageModifier().
isStatic() ==
true)
27558 ROSE_ASSERT(nondefiningFunctionDeclaration->get_declarationModifier().get_storageModifier().
isStatic() ==
true);
27562 return nondefiningFunctionDeclaration;
27566std::vector<SgFunctionDeclaration*>
27578 std::vector<SgFunctionDeclaration*> functionList;
27579 FunctionDefinitionsTraversal() {}
27581 void visit (
SgNode* node)
27584 if (functionDeclaration != NULL)
27590 if (functionDeclaration == definingFunctionDeclaration)
27594 if (functionDeclarationScope != NULL)
27596 functionList.push_back(functionDeclaration);
27604 FunctionDefinitionsTraversal traversal;
27606 traversal.traverseWithinFile(node, preorder);
27608 std::vector<SgFunctionDeclaration*> & functionList = traversal.functionList;
27610 return functionList;
27617 ROSE_ASSERT(node != NULL);
27620 std::vector<SgFunctionDeclaration*>::iterator i = functionList.begin();
27622 while (i != functionList.end())
27625 ROSE_ASSERT(functionDeclaration != NULL);
27643 ROSE_ASSERT(node !=
nullptr);
27649 void visit (
SgNode* node)
27652 if (variableDeclaration != NULL)
27655 SgExpression* initializer = initializedName->get_initializer();
27657 printf (
"variableDeclaration = %p initializedName = %p = %s initializer = %p \n",
27658 variableDeclaration,initializedName,initializedName->get_name().str(),initializer);
27660 if (initializer != NULL)
27662 printf (
" --- initializer = %s \n",initializer->
class_name().c_str());
27669 CheckInitializerTraversal traversal;
27670 traversal.traverse(node, preorder);
27678 void setResult(
SgType*) { }
27680 void handle(
SgNode& n,
SgNode&) { SG_UNEXPECTED_NODE(n); }
27682 template <
class SageDeclarationStatement>
27688 setResult(n.get_type());
27691 template <
class SageNode>
27692 void handle(SageNode& n)
27705 SgGlobal * gsaf = project->get_globalScopeAcrossFiles();
27706 ROSE_ASSERT(gsaf !=
nullptr);
27708 ROSE_ASSERT(st !=
nullptr);
27710 ROSE_ASSERT(hmm !=
nullptr);
27714 ROSE_ASSERT(st !=
nullptr);
27715 hmm = st->get_table();
27716 ROSE_ASSERT(hmm !=
nullptr);
27720 ROSE_ASSERT(st !=
nullptr);
27721 hmm = st->get_table();
27722 ROSE_ASSERT(hmm !=
nullptr);
27742 int match_count = 0;
27743 ROSE_ASSERT (root);
27747 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(root, V_SgArrowExp);
27751 boost::unordered::unordered_map <SgNode*, bool> visited;
27754 for (Rose_STL_Container<SgNode *>::reverse_iterator i = nodeList.rbegin(); i != nodeList.rend(); i++)
27757 if (visited.count(*i)==1)
27766 cerr<<
"SageInterface::normalizeArrowExpWithAddressOfLeftOperand() expects SgArrowExp while encountering "<<(*i)->class_name()<<
"@"<<(*i) <<endl;
27767 ROSE_ASSERT (a_exp);
27770 if (transformationGeneratedOnly)
27778 if (
SgVarRefExp* left = isSgVarRefExp(address_op->get_operand()))
27791 return match_count;
27801 Traversal() : found(
false) {}
27802 void visit (
SgNode* node)
27804 SgCastExp* castExpression = isSgCastExp(node);
27805 if (castExpression != NULL)
27809 if (initializer == NULL)
27814 printf (
" --- Found a SgCastExp marked as a transformation: castExpression = %p \n",castExpression);
27817 printf (
"Exiting as a test! \n");
27818 ROSE_ASSERT(
false);
27824 printf (
" --- SgCastExp (but not marked as a transformation) node = %p = %s \n",node,node->
class_name().c_str());
27832 printf (
" --- SgCastExp (but from an initializer) node = %p = %s \n",node,node->
class_name().c_str());
27839 printf (
" --- node = %p = %s \n",node,node->
class_name().c_str());
27846 printf (
"In findFirstSgCastExpMarkedAsTransformation(): s = %s \n",s.c_str());
27850 Traversal traversal;
27851 traversal.traverse(n, preorder);
27854 printf (
"In findFirstSgCastExpMarkedAsTransformation(): s = %s traversal.found = %s \n",s.c_str(),traversal.found ?
"true" :
"false");
27858 if (traversal.found ==
true)
27860 printf (
"In findFirstSgCastExpMarkedAsTransformation(): returning false \n");
27865 return traversal.found;
27876 ROSE_ASSERT (info != NULL);
27877 PreprocessingInfo::DirectiveType dtype= info->getTypeOfDirective();
27878 if (dtype == PreprocessingInfo::CpreprocessorIfdefDeclaration ||
27879 dtype == PreprocessingInfo::CpreprocessorIfndefDeclaration ||
27880 dtype == PreprocessingInfo::CpreprocessorIfDeclaration )
27884 else if (dtype==PreprocessingInfo::CpreprocessorElseDeclaration||
27885 dtype==PreprocessingInfo::CpreprocessorElifDeclaration)
27889 else if (dtype==PreprocessingInfo::CpreprocessorEndifDeclaration)
27898static void moveInofListToNewPlace(AttachedPreprocessingInfoType* infoList,
int cidx, set <AttachedPreprocessingInfoType*>& relatedInfoList,
SgLocatedNode* lnode,
int &retVal)
27903 relatedInfoList.insert (infoList);
27907 info->setRelativePosition(PreprocessingInfo::after);
27914 (*infoList)[cidx]= NULL;
27921 ROSE_ASSERT(lnode);
27927 vector < pair< AttachedPreprocessingInfoType*, int> > empty_entries;
27928 for(;ast_i!=ast.
end();++ast_i) {
27930 if (current ==NULL )
27934 if (infoList == NULL)
continue;
27936 int commentIndex=0;
27937 for (Rose_STL_Container<PreprocessingInfo*>::iterator ci = (*infoList).begin(); ci != (*infoList).end(); ci++)
27943 empty_entries.push_back( make_pair (infoList, commentIndex) );
27949 for (
auto ki = empty_entries.rbegin(); ki != empty_entries.rend(); ki ++)
27951 AttachedPreprocessingInfoType* infoList = (*ki).first;
27952 int cidx= (*ki).second;
27955 ROSE_ASSERT (info==NULL);
27958 AttachedPreprocessingInfoType::iterator k = infoList->begin();
27959 infoList->erase(k+cidx);
27969static std::unordered_map <PreprocessingInfo*, SageInterface::PreprocessingInfoData> infoMap;
27974 if (current == NULL)
27980 vector<PreprocessingInfo*> afterList;
27983 AttachedPreprocessingInfoType* comments = locatedNode->getAttachedPreprocessingInfo();
27985 if (comments !=
nullptr)
27987 AttachedPreprocessingInfoType::iterator i;
27989 for (i = comments->begin (); i != comments->end (); i++)
27995 data.container=comments;
27997 data.depth = depth;
28000 if (info->getRelativePosition () == PreprocessingInfo::before)
28002 infoList.push_back (info);
28003 infoMap[info] = data;
28008 else if (info->getRelativePosition () == PreprocessingInfo::after
28009 || info->getRelativePosition () == PreprocessingInfo::inside
28012 afterList.push_back (info);
28013 infoMap[info] = data;
28017 mlog[Sawyer::Message::Common::WARN] <<
"Warning: unhandled relative position value:" <<info->getRelativePosition () <<endl;
28028 for (
auto c: children)
28032 for (
auto fi : afterList)
28033 infoList.push_back(fi);
28047 ROSE_ASSERT(lnode);
28063 vector < pair< AttachedPreprocessingInfoType*, int> > keepers;
28067 unordered_map < PreprocessingInfo * , vector< pair<AttachedPreprocessingInfoType*, int>> > associated_directives;
28072 vector< pair<AttachedPreprocessingInfoType*, int>> associated_erase;
28080 vector<PreprocessingInfo*> candidateInfoList;
28085 for (
auto candidate: candidateInfoList)
28092 if (infoMap[info].depth ==0)
28095 int commentIndex = infoMap[info].index;
28096 AttachedPreprocessingInfoType* infoList = infoMap[info].container;
28099 if ( isBeginDirective(info) == 1)
28101 keepers.push_back(make_pair (infoList,commentIndex));
28104 else if (isBeginDirective(info) == 2)
28109 if (keepers.size()==0)
28110 keepers.push_back(make_pair (infoList, commentIndex));
28111 else if (isBeginDirective( (*(keepers.back().first))[keepers.back().second] )!=1 )
28113 keepers.push_back(make_pair (infoList,commentIndex));
28115 else if(isBeginDirective( (*(keepers.back().first))[keepers.back().second] )==1 )
28117 PreprocessingInfo* begin_info = (*(keepers.back().first))[keepers.back().second];
28119 associated_directives[begin_info].push_back(make_pair (infoList,commentIndex));
28123 else if ( isBeginDirective(info) == -1)
28125 bool neutralized =
false;
28127 if (keepers.size()>0)
28129 AttachedPreprocessingInfoType* comments = keepers.back().first;
28130 int idx = keepers.back().second;
28132 if(isBeginDirective( (*comments)[idx] )==1)
28134 keepers.pop_back();
28135 neutralized =
true;
28140 keepers.push_back(make_pair (infoList,commentIndex));
28148 for(;ast_i!=ast.
end();++ast_i) {
28150 if (current ==NULL )
28154 if (infoList == NULL)
continue;
28156 int commentIndex=0;
28157 for (Rose_STL_Container<PreprocessingInfo*>::iterator ci = (*infoList).begin(); ci != (*infoList).end(); ci++)
28159 ROSE_ASSERT(*ci != NULL);
28165 if ( isBeginDirective(info) == 1)
28167 keepers.push_back(make_pair (infoList,commentIndex));
28170 else if (isBeginDirective(info) == 2)
28175 if (keepers.size()==0)
28176 keepers.push_back(make_pair (infoList,commentIndex));
28177 else if (isBeginDirective( (*(keepers.back().first))[keepers.back().second] )!=1 )
28179 keepers.push_back(make_pair (infoList,commentIndex));
28181 else if(isBeginDirective( (*(keepers.back().first))[keepers.back().second] )==1 )
28183 PreprocessingInfo* begin_info = (*(keepers.back().first))[keepers.back().second];
28185 associated_directives[begin_info].push_back(make_pair (infoList,commentIndex));
28189 else if ( isBeginDirective(info) == -1)
28191 bool neutralized =
false;
28193 if (keepers.size()>0)
28195 AttachedPreprocessingInfoType* comments = keepers.back().first;
28196 int idx = keepers.back().second;
28198 if(isBeginDirective( (*comments)[idx] )==1)
28200 keepers.pop_back();
28201 neutralized =
true;
28206 keepers.push_back(make_pair (infoList,commentIndex));
28213 set <AttachedPreprocessingInfoType*> relatedInfoList;
28216 for (
auto ki = keepers.begin(); ki != keepers.end(); ki ++)
28218 AttachedPreprocessingInfoType* infoList = (*ki).first;
28219 int cidx= (*ki).second;
28221 relatedInfoList.insert (infoList);
28225 info->setRelativePosition(PreprocessingInfo::after);
28232 if (associated_directives.count (info)!=0)
28234 vector<pair<AttachedPreprocessingInfoType*,int>> a_list_vec = associated_directives[info];
28235 for (
auto vec_i = a_list_vec.rbegin(); vec_i != a_list_vec.rend(); vec_i ++ )
28237 AttachedPreprocessingInfoType* a_infoList = (*vec_i).first;
28238 int aidx= (*vec_i).second;
28239 moveInofListToNewPlace (a_infoList, aidx, relatedInfoList, lnode, retVal);
28240 associated_erase.push_back(make_pair (a_infoList, aidx));
28246 (*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 &)
Insert data into the digest.
uint64_t toU64()
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() const
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 std::vector< SgNode * > get_traversalSuccessorContainer() const
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
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::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 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.
virtual std::vector< SgNode * > get_traversalSuccessorContainer() const override
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
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)
Converts a 64 bit int to base 62.
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 SgName appendTemplateArgumentsToName(const SgName &name, const SgTemplateArgumentPtrList &templateArgumentsList)
DQ (7/27/2012): changed semantics from removing the template arguments in names to adding the templat...
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 bool normalizeCaseAndDefaultBlocks(SgSwitchStatement *switchStmt)
Normalize the structure of case and default blocks within a switch statement.
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 void moveCommentsToNewStatement(SgStatement *sourceStatement, const std::vector< int > &indexList, SgStatement *destinationStatement, bool destinationStatementPreceedsSourceStatement)
Relocate comments and CPP directives from one statement to another.
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 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: