2#include "markLhsValues.h"
4#include "FileUtility.h"
5#include <Sawyer/Message.h>
7#include "AstJSONGeneration.h"
8#include "SgNodeHelper.h"
10#include "Rose/AST/Utility.h"
11#include "sageInterface.h"
12#include "Combinatorics.h"
14#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
15#include "replaceExpressionWithStatement.h"
17#include "constantFolding.h"
20#include "sageBuilder.h"
23#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
25#include "AstInterface_ROSE.h"
26#include "LoopTransformInterface.h"
28#include "DepInfoAnal.h"
29#include "ArrayAnnot.h"
30#include "ArrayInterface.h"
32#include "LoopUnroll.h"
33#include "abstract_handle.h"
34#include "roseAdapter.h"
37#include <boost/lexical_cast.hpp>
38#include <boost/foreach.hpp>
44#include <unordered_map>
46#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
54 extern jclass currentJavaTraversalClass;
55 extern JNIEnv *currentEnvironment;
56 extern jmethodID mainMethod;
57 extern jmethodID hasConflictsMethod;
58 extern jmethodID getTempDirectoryMethod;
59 extern jmethodID createTempFileMethod;
60 extern jmethodID createTempNamedFileMethod;
61 extern jmethodID createTempNamedDirectoryMethod;
68using namespace Rose::Frontend::Java::Ecj;
73#include "rose_config.h"
76namespace EDG_ROSE_Translation
79#if defined(ROSE_BUILD_CXX_LANGUAGE_SUPPORT) && !defined(ROSE_USE_CLANG_FRONTEND)
81 extern std::map<std::string, SgIncludeFile*> edg_include_file_map;
84 std::map<std::string, SgIncludeFile*> edg_include_file_map;
88#include "detectMacroOrIncludeFileExpansions.h"
91 template<
class T>
void setSourcePositionToDefault( T* node );
95#ifdef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
96 #include "transformationSupport.h"
100#include "AST_FILE_IO.h"
104#define OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS 1
113typedef std::set<SgLabelStatement*> SgLabelStatementPtrSet;
127 vector<SgBasicBlock*> addedBasicBlockNodes;
140 std::vector<SgNode*> resultlist;
141 void visit (
SgNode* node)
144 ROSE_ASSERT(result != NULL);
148 resultlist.push_back(result);
151 resultlist.push_back(result);
155 virtual ~MyTraversal() {}
159 size_t numberOfNodes_before{numberOfNodes()};
160 MyTraversal my_traversal;
161 my_traversal.traverseMemoryPool();
163 vector<SgNode*>& nodeList = my_traversal.resultlist;
164 printf (
"In SageInterface::deleteAllNodes(): get list of SgNode: nodeList.size() = %zu \n",nodeList.size());
166 vector<SgNode*>::iterator i = nodeList.begin();
169 while (i != nodeList.end())
179 AST_FILE_IO::clearAllMemoryPools();
181 size_t numberOfNodes_after = numberOfNodes();
182 printf (
"Leaving SageInterface::deleteAllNodes(): numberOfNodes_before = %zu numberOfNodes_after = %zu \n",numberOfNodes_before,numberOfNodes_after);
210 void visit (
SgNode* node)
217 resultlist.push_back(result);
220 virtual ~MyTraversal() {}
224 size_t numberOfNodes_before = numberOfNodes();
226 MyTraversal my_traversal;
230 my_traversal.traverseMemoryPool();
239 ASSERT_not_null(decl);
243 if (firstNondefiningDeclaration ==
nullptr)
248 ASSERT_not_null(firstNondefiningDeclaration);
250 if (decl == firstNondefiningDeclaration)
252 if (declarationMap.find(firstNondefiningDeclaration) == declarationMap.end())
255 declarationMap[decl] =
new set<SgDeclarationStatement*>();
257 ROSE_ASSERT (declarationMap.find(firstNondefiningDeclaration) != declarationMap.end());
258 ROSE_ASSERT(declarationMap[decl] !=
nullptr);
261 declarationMap[firstNondefiningDeclaration]->insert(decl);
265 if (declarationMap[firstNondefiningDeclaration]->find(decl) == declarationMap[firstNondefiningDeclaration]->end())
268 declarationMap[firstNondefiningDeclaration]->insert(decl);
274 bool ignore_error = (isSgFunctionParameterList(decl) !=
nullptr);
285 bool isInTemplateFunctionDeclaration = enclosingFunction !=
nullptr && (isSgTemplateMemberFunctionDeclaration(enclosingFunction) || isSgTemplateFunctionDeclaration(enclosingFunction));
289 bool isInTemplateClassDefinition = enclosingClassDefinition !=
nullptr && isSgTemplateClassDefinition(enclosingClassDefinition);
291 bool isInTemplateDeclaration = isInTemplateFunctionDeclaration || isInTemplateClassDefinition;
293 ignore_error = ignore_error || (isSgTypedefDeclaration(decl) !=
nullptr) || (isSgTemplateInstantiationDecl(decl) !=
nullptr) || (isInTemplateDeclaration ==
true);
298 if (isSgClassDeclaration(decl) !=
nullptr)
300 ignore_error = ignore_error || (isSgClassDeclaration(decl)->get_isUnNamed() ==
true);
308 if (declarationMap.find(firstNondefiningDeclaration) != declarationMap.end())
311 ROSE_ASSERT (declarationMap[firstNondefiningDeclaration] !=
nullptr);
312 if (declarationMap[firstNondefiningDeclaration]->find(decl) == declarationMap[firstNondefiningDeclaration]->end())
315 declarationMap[firstNondefiningDeclaration]->insert(decl);
326 declarationMap[firstNondefiningDeclaration] =
new set<SgDeclarationStatement*>();
327 ASSERT_require(declarationMap.find(firstNondefiningDeclaration) != declarationMap.end());
331 declarationMap[firstNondefiningDeclaration]->insert(decl);
334 ROSE_ASSERT(declarationMap[firstNondefiningDeclaration]->find(decl) != declarationMap[firstNondefiningDeclaration]->end());
336 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());
343const std::set<SgDeclarationStatement*>*
349 ROSE_ASSERT(declarationMap.find(firstNondefiningDeclaration) != declarationMap.end());
351 const set<SgDeclarationStatement*>* declarationSet = declarationMap[firstNondefiningDeclaration];
354 return declarationSet;
357std::map<SgDeclarationStatement*,std::set<SgDeclarationStatement*>* > &
358SageInterface::DeclarationSets::getDeclarationMap()
360 return declarationMap;
376#define DEBUG_LOCATED_IN_DEFINING_SCOPE 0
379 ROSE_ASSERT(firstNondefiningDeclaration !=
nullptr);
381 set<SgDeclarationStatement*>* declarationSet = declarationMap[firstNondefiningDeclaration];
382 ROSE_ASSERT(declarationSet !=
nullptr);
384 set<SgDeclarationStatement*>::iterator i = declarationSet->begin();
386 bool isDefinedInNamedScope =
false;
388#if DEBUG_LOCATED_IN_DEFINING_SCOPE
389 printf (
"In DeclarationSets::isLocatedInDefiningScope(): decl = %p = %s \n",decl,decl->
class_name().c_str());
390 printf (
" --- declarationSet->size() = %" PRIuPTR
" \n",declarationSet->size());
393 while (isDefinedInNamedScope ==
false && i != declarationSet->end())
395 ROSE_ASSERT(*i !=
nullptr);
396#if DEBUG_LOCATED_IN_DEFINING_SCOPE
397 printf (
" --- *i = %p = %s \n",*i,(*i)->class_name().c_str());
401 SgScopeStatement* structural_scope = isSgScopeStatement((*i)->get_parent());
403#if DEBUG_LOCATED_IN_DEFINING_SCOPE
404 printf (
" --- semantic_scope = %p = %s \n",semantic_scope,semantic_scope->
class_name().c_str());
405 printf (
" --- structural_scope = %p = %s \n",structural_scope,structural_scope->
class_name().c_str());
408 SgScopeStatement* scope = isSgClassDefinition(semantic_scope) !=
nullptr ? semantic_scope : structural_scope;
409 ASSERT_not_null(scope);
411#if DEBUG_LOCATED_IN_DEFINING_SCOPE
412 printf (
" --- scope = %p = %s \n",scope,scope->
class_name().c_str());
413 printf (
" --- scope->isNamedScope() = %s \n",scope->
isNamedScope() ?
"true" :
"false");
415 SgGlobal* globalScope = isSgGlobal(scope);
418 if (globalScope !=
nullptr || (scope->
isNamedScope() ==
true && isSgClassDefinition(structural_scope) ==
nullptr) )
421 bool willBeOutput = ((*i)->get_file_info()->isCompilerGenerated() ==
false ||
422 ((*i)->get_file_info()->isCompilerGenerated() &&
423 (*i)->get_file_info()->isOutputInCodeGeneration()) );
424#if DEBUG_LOCATED_IN_DEFINING_SCOPE
425 printf (
" --- before: willBeOutput = %s \n",willBeOutput ?
"true" :
"false");
428 willBeOutput = willBeOutput && scope == structural_scope;
430#if DEBUG_LOCATED_IN_DEFINING_SCOPE
431 printf (
" --- after: willBeOutput = %s \n",willBeOutput ?
"true" :
"false");
437 isDefinedInNamedScope = willBeOutput;
443#if DEBUG_LOCATED_IN_DEFINING_SCOPE
444 if (associatedDeclaration !=
nullptr)
446 printf (
"Leaving DeclarationSets::isLocatedInDefiningScope(): associatedDeclaration = %p = %s \n",associatedDeclaration,
associatedDeclaration->
class_name().c_str());
450 printf (
"Leaving DeclarationSets::isLocatedInDefiningScope(): associatedDeclaration = %p \n",associatedDeclaration);
454 return isDefinedInNamedScope;
458SageInterface::buildDeclarationSets(
SgNode* n)
460 DeclarationSets* declarationSet =
new DeclarationSets();
465 DeclarationSets* declarationSet;
468 DeclarationSetTraversal(DeclarationSets* ds) : declarationSet(ds) {}
474 declarationSet->addDeclaration(decl);
480 DeclarationSetTraversal traversal(declarationSet);
481 traversal.traverse(n, preorder);
483 return declarationSet;
490string getVariantName ( VariantT v )
492 ROSE_ASSERT(
int(v) <
int(V_SgNumVariants));
496 extern const char* roseGlobalVariantNameList[];
497 return string(roseGlobalVariantNameList[v]);
504 bool usingTemplateSyntax =
false;
505 string nameString = name.getString();
508 usingTemplateSyntax = (nameString.find(
'<') != string::npos) && (nameString.find(
'>') != string::npos);
512 if (nameString ==
"<unnamed>")
514 printf (
"In SageInterface::hasTemplateSyntax(): Identified case of name == <unnamed> \n");
516 usingTemplateSyntax =
false;
519 return usingTemplateSyntax;
531 ROSE_ASSERT(node != NULL);
535 ROSE_ASSERT(isSgFile(node) == NULL);
536 ROSE_ASSERT(isSgFileList(node) == NULL);
537 ROSE_ASSERT(isSgProject(node) == NULL);
542 while (parent !=
nullptr && isSgFileList(parent) ==
nullptr)
546 printf (
"--- parent = %p = %s \n",parent,parent->
class_name().c_str());
549 parent->
get_file_info()->display(
"In SageInterface::whereAmI() diagnostics support");
576 ifstmt->setCaseInsensitive(
true);
579 if (conditional) conditional->
set_parent(ifstmt);
581 if (false_body) false_body->
set_parent(ifstmt);
588 ROSE_ASSERT(switchStatement != NULL);
592 switchStatement->setCaseInsensitive(
true);
597 if (switchStatement->
get_body() ==
nullptr)
601 if (item_selector !=
nullptr)
611 ROSE_ASSERT(whileStatement);
615 whileStatement->setCaseInsensitive(
true);
619 if (whileStatement->
get_body() ==
nullptr)
623 if (whileStatement->get_else_body() ==
nullptr)
624 whileStatement->set_else_body(else_body);
627 if (condition) condition->
set_parent(whileStatement);
631 if (else_body !=
nullptr)
633 whileStatement->set_else_body(else_body);
654 ASSERT_not_null(declaration);
658 while ( isSgNamespaceDefinitionStatement(tempScope) ==
nullptr && isSgGlobal(tempScope) ==
nullptr )
661 ASSERT_not_null(tempScope);
665 return namespaceScope;
679 ASSERT_not_null(defn);
683 ASSERT_not_null(templateDeclaration);
689 if (templateInstatiationClassDefinition !=
nullptr)
693 ASSERT_not_null(parentTemplateInstantiationDefinition);
695 ASSERT_not_null(parentTemplateInstantiationDeclaration);
698 ASSERT_not_null(parentDeclaration);
700 else if (cdefn !=
nullptr)
704 ASSERT_not_null(parentDeclaration);
706 else if (nrscope !=
nullptr)
708 parentDeclaration = isSgDeclarationStatement(nrscope->
get_parent());
709 ASSERT_not_null(parentDeclaration);
716 return parentDeclaration;
725 ASSERT_not_null(var_decl);
726 ASSERT_not_null(base_decl);
740 if (find(stmt_list.begin(), stmt_list.end(), base_decl) != stmt_list.end())
745 var_decl->set_baseTypeDefiningDeclaration(base_decl);
751 t1.traverseMemoryPool();
760 bool foundExistingPrototype =
false;
762 ROSE_ASSERT(scope != NULL);
763 ROSE_ASSERT(functionDeclaration != NULL);
764 ROSE_ASSERT(startingAtDeclaration != NULL);
767 if (isSgDeclarationScope(scope)) {
768 printf(
"TODO: SgDeclarationScope handling in SageInterface::isPrototypeInScope see ROSE-1378\n");
779 SgDeclarationStatementPtrList::iterator startingLocation = find(declarationList.begin(),declarationList.end(),startingAtDeclaration);
781 if (startingLocation != declarationList.end())
784 printf (
"startingLocation = %p = %s = %s \n",*startingLocation,(*startingLocation)->class_name().c_str(),
SageInterface::get_name(*startingLocation).c_str());
787 SgDeclarationStatementPtrList::iterator i = startingLocation;
789 SgName targetName = functionDeclaration->get_name();
791 while (i != declarationList.end())
797 if (templateMemberFunction !=
nullptr)
800 if (targetScope == templateMemberFunction->
get_scope())
802 if (targetName == templateMemberFunction->get_name())
805 if (templateMemberFunction->
isForward() ==
true)
807 foundExistingPrototype =
true;
820 return foundExistingPrototype;
826 ROSE_ASSERT(node1 && node2);
836 }
while( (curnode!=
nullptr) && (curnode!=node1));
853#define DEBUG_HAS_SAME_SCOPE 0
855#if DEBUG_HAS_SAME_SCOPE
856 printf (
"In SageInterface::hasSameGlobalScope(): \n");
857 printf (
" --- statement_1 = %p = %s \n",statement_1,statement_1->
class_name().c_str());
858 printf (
" --- statement_2 = %p = %s \n",statement_2,statement_2->
class_name().c_str());
861 bool includingSelf =
true;
862 SgGlobal* global_scope_1 = getEnclosingNode<SgGlobal>(statement_1,includingSelf);
863 SgGlobal* global_scope_2 = getEnclosingNode<SgGlobal>(statement_2,includingSelf);
865#if DEBUG_HAS_SAME_SCOPE
866 printf (
" --- global_scope_1 = %p = %s \n",global_scope_1,global_scope_1->
class_name().c_str());
868 printf (
" --- --- sourcefile_1 = %p filename = %s \n",sourcefile_1,sourcefile_1->
getFileName().c_str());
870 printf (
" --- global_scope_2 = %p = %s \n",global_scope_2,global_scope_2->
class_name().c_str());
872 printf (
" --- --- sourcefile_2 = %p filename = %s \n",sourcefile_2,sourcefile_2->
getFileName().c_str());
875 bool returnResult = (global_scope_1 == global_scope_2);
877#if DEBUG_HAS_SAME_SCOPE
878 printf (
"Leaving SageInterface::hasSameGlobalScope(): returning: %s \n",returnResult ?
"true" :
"false");
888 std::vector<SgNode*> intersectionSet;
891 std::vector<SgNode*> AST_original = NodeQuery::querySubTree (original,V_SgNode);
892 std::vector<SgNode*> AST_copy = NodeQuery::querySubTree (copy,V_SgNode);
894 int AST_original_size = AST_original.size();
895 int AST_copy_size = AST_copy.size();
899 printf (
"Original AST size = %d \n",AST_original_size);
900 printf (
"Copy of original AST size = %d \n",AST_copy_size);
903 int differenceInSizes = AST_original_size - AST_copy_size;
904 if (differenceInSizes == 0)
907 printf (
"Copied AST is the SAME size as the original (size = %d) \n",AST_original_size);
911 printf (
"Warning: Copied AST and the original are DIFFERENT sizes (original size = %d copyied size = %d) \n",AST_original_size,AST_copy_size);
916 std::set<SgNode*> AST_set_original;
917 for (
int i = 0; i < AST_original_size; i++)
919 AST_set_original.insert(AST_original[i]);
922 std::set<SgNode*> AST_set_copy;
923 for (
int i = 0; i < AST_copy_size; i++)
925 AST_set_copy.insert(AST_copy[i]);
928 int size = AST_original_size;
929 std::vector<SgNode*> intersectionList(size);
932 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());
935 std::vector<SgNode*> meaningIntersectionList = std::vector<SgNode*>(intersectionList.begin(),end);
936 std::vector<SgNode*> deleteList;
937 for (
int i = 0; i < (int)meaningIntersectionList.size(); i++)
939 if (meaningIntersectionList[i] !=
nullptr && isSgType(meaningIntersectionList[i]) !=
nullptr)
941 deleteList.push_back(meaningIntersectionList[i]);
947 printf (
"Remove the types that are allowed to be shared: deleteList.size() = %ld \n",(
long)deleteList.size());
949 for (std::vector<SgNode*>::iterator i = deleteList.begin(); i != deleteList.end(); i++)
951 meaningIntersectionList.erase(find(meaningIntersectionList.begin(),meaningIntersectionList.end(),*i));
955 printf (
"After removing the types there are meaningIntersectionList.size() = %ld \n",(
long)meaningIntersectionList.size());
957 for (
int i = 0; i < (int)meaningIntersectionList.size(); i++)
959 printf (
" meaningIntersectionList[%d] = %p = %s = %s \n",i,meaningIntersectionList[i],meaningIntersectionList[i]->class_name().c_str(),
get_name(meaningIntersectionList[i]).c_str());
962 int unmatchedIRnodes = 0;
965 std::vector<SgNode*> tmp_AST_original;
966 std::vector<SgNode*> tmp_AST_copy;
968 int AST_original_size = AST_original.size();
969 for (
int j = 0; j < AST_original_size; j++)
971 if (AST_original[j] != NULL && isSgType(AST_original[j]) == NULL)
973 tmp_AST_original.push_back(AST_original[j]);
977 int AST_copy_size = AST_copy.size();
978 for (
int j = 0; j < AST_copy_size; j++)
980 if (AST_copy[j] != NULL && isSgType(AST_copy[j]) == NULL)
982 tmp_AST_copy.push_back(AST_copy[j]);
986 std::vector<SgNode*> deleteList_original;
987 std::vector<SgNode*> deleteList_copy;
988 for (
int j = 0; j < (int)tmp_AST_original.size(); j++)
991 SgCopyHelp::copiedNodeMapTypeIterator i = help->get_copiedNodeMap().find(tmp_AST_original[j]);
993 if (i != help->get_copiedNodeMap().end())
996 SgNode* associated_node_copy = i->second;
997 ROSE_ASSERT(associated_node_copy != NULL);
998 deleteList_original.push_back(tmp_AST_original[j]);
999 deleteList_copy.push_back(associated_node_copy);
1004 if (templateMemberFunction != NULL)
1006 printf (
"In SageInterface::astIntersection(): Found a SgTemplateInstantiationMemberFunctionDecl = %p copy = %p \n",templateMemberFunction,associated_node_copy);
1014 int deleteList_original_size = deleteList_original.size();
1015 for (
int j = 0; j < deleteList_original_size; j++)
1018 std::vector<SgNode*>::iterator k = find(tmp_AST_original.begin(),tmp_AST_original.end(),deleteList_original[j]);
1019 if (k != tmp_AST_original.end())
1021 tmp_AST_original.erase(k);
1026 printf (
"IR nodes different between the original AST and the copy of the AST = %" PRIuPTR
" \n",tmp_AST_original.size());
1028 for (
int j = 0; j < (int)tmp_AST_original.size(); j++)
1030 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());
1034 unmatchedIRnodes = (int)tmp_AST_original.size();
1038 if (differenceInSizes != 0)
1040 SgProject* originalProject = isSgProject(original);
1041 if (originalProject != NULL)
1043 printf (
"In %s Copied AST and the original are DIFFERENT sizes (original size = %d copyied size = %d) IR nodes different = %d \n",
1044 (*originalProject)[0]->get_sourceFileNameWithoutPath().c_str(),AST_original_size,AST_copy_size,unmatchedIRnodes);
1047 if (unmatchedIRnodes > 0)
1049 printf (
"Make this an error under stricter testing \n");
1054 return intersectionSet;
1064 ROSE_ASSERT(initializedNameNode != NULL);
1066#define DEBUG_SET_NAME 0
1070 printf (
"In SageInterface::set_name(): initializedNameNode = %p name = %s new_name = %s \n",initializedNameNode,initializedNameNode->get_name().str(),new_name.str());
1077 while((node!=NULL) && ( isSgScopeStatement(node)==NULL))
1080 ROSE_ASSERT(node!=NULL);
1088 if (isSgEnumDeclaration(initializedNameNode->
get_parent()) != NULL)
1090 ROSE_ASSERT(scope_stmt != NULL);
1091 printf (
"scope_stmt = %p = %s \n",scope_stmt,scope_stmt->
class_name().c_str());
1093 printf (
"Detected isSgEnumDeclaration as parent: exiting as a test in SageInterface::set_name() \n");
1098 ROSE_ASSERT(scope_stmt != NULL);
1104 ROSE_ASSERT(parent_declaration != NULL);
1107 std::pair<SgSymbolTable::hash_iterator,SgSymbolTable::hash_iterator> pair_it = scope_stmt->
get_symbol_table()->get_table()->equal_range(initializedNameNode->get_name());
1109 SgSymbolTable::hash_iterator found_it = scope_stmt->
get_symbol_table()->get_table()->end();
1111 for (SgSymbolTable::hash_iterator it = pair_it.first; it != pair_it.second; ++it)
1114 printf (
"Looking for symbol in scope = %p = %s \n",scope_stmt,scope_stmt->
class_name().c_str());
1115 printf (
" --- *it = %p = %s \n",(*it).second,(*it).second->class_name().c_str());
1117 switch(parent_declaration->
variantT())
1119 case V_SgFunctionParameterList:
1120 case V_SgVariableDeclaration:
1122 if (isSgVariableSymbol((*it).second) != NULL)
1127 case V_SgClassDeclaration:
1129 if (isSgClassSymbol((*it).second) != NULL)
1134 case V_SgFunctionDeclaration:
1136 if (isSgFunctionSymbol((*it).second) != NULL)
1142 case V_SgEnumDeclaration:
1144 if (isSgEnumFieldSymbol((*it).second) != NULL)
1151 printf (
"Default reached in switch in SageInterface::set_name() \n");
1159 printf (
"Warning: There is no Variable, Class, Function, or EnumValue symbol associated with p_name \n");
1166 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");
1172 printf (
"In SageInterface::set_name(): This statement can be transformed! parent_declaration = %p = %s \n",parent_declaration,
get_name(parent_declaration).c_str());
1177 printf (
"Exiting as a test! \n");
1182 SgSymbol * associated_symbol = (*found_it).second;
1197 found_it = scope_stmt->
get_symbol_table()->get_table()->insert(pair<SgName,SgSymbol*> ( new_name,associated_symbol));
1199 found_it = scope_stmt->
get_symbol_table()->get_table()->insert(pair<SgName,SgSymbol*> ( new_name,associated_symbol));
1204 printf (
"Warning: insertion of new symbol failed \n");
1210 printf (
"Reset initializedNameNode->get_name() = %s to new_name = %s \n",initializedNameNode->get_name().str(),new_name.str());
1214 initializedNameNode->set_name(new_name);
1219 ROSE_ASSERT(enclosingStatement != NULL);
1235 void visit (
SgNode* node)
1240 ROSE_ASSERT(varRefExp != NULL);
1241 ROSE_ASSERT(variableSymbol != NULL);
1243 if (varRefExp->get_symbol() == variableSymbol)
1246 printf (
"In SageInterface::set_name(): Found associated SgVarRefExp varRefExp = %p to symbol associated_symbol = %p \n",varRefExp,variableSymbol);
1249 printf (
"Exiting as a test! \n");
1260 printf (
"In SageInterface::set_name(): When unparsing header files, we need to set the physical file id to the correct file \n");
1265 ROSE_ASSERT(associatedStatement != NULL);
1271 ROSE_ASSERT(associatedStatement != NULL);
1279 RoseVisitor(
SgSymbol* symbol_parmeter) : counter(0), symbol(symbol_parmeter)
1282 printf (
"roseVisitor::visit: counter %4d node = %s \n",counter,symbol_parmeter->
class_name().c_str());
1290 RoseVisitor t1(associated_symbol);
1295 printf (
"Leaving SageInterface::set_name(): initializedNameNode = %p name = %s new_name = %s (return 1) \n",initializedNameNode,initializedNameNode->get_name().str(),new_name.str());
1307 printf (
"In SageInterface::listHeaderFiles(): includeFile filename = %s \n",includeFile->get_filename().str());
1313 void visit (
SgNode* node)
1315 printf (
"In listHeaderFiles visit(): node = %p = %s \n",node,node->
class_name().c_str());
1317 if (includeFile != NULL)
1319 printf (
"include file: filename = %s \n",includeFile->get_filename().str());
1325 PrefixTraversal traversal;
1326 traversal.traverse(includeFile, preorder);
1345 ROSE_ASSERT(scope != NULL);
1346 int scope_file_id = scope->
get_file_info()->get_physical_file_id();
1348 bool return_value =
false;
1352 SgDeclarationStatementPtrList & declarationStatementList = scope->
getDeclarationList();
1354 printf (
"In scopeHasStatementsFromSameFile(): DeclarationStatementList not implemented \n");
1357 printf (
"declarationStatementList.size() = %zu \n",declarationStatementList.size());
1359 SgDeclarationStatementPtrList::iterator i = declarationStatementList.begin();
1361 while (i != declarationStatementList.end() && return_value ==
false)
1364 int statement_file_id = statement->
get_file_info()->get_physical_file_id();
1366 if (statement_file_id == scope_file_id)
1368 return_value =
true;
1374 printf (
"Exiting as a test! \n");
1382 printf (
"In scopeHasStatementsFromSameFile(): StatementList not implemented \n");
1384 SgStatementPtrList::iterator i = statementList.begin();
1386 while (i != statementList.end() && return_value ==
false)
1389 int statement_file_id = statement->
get_file_info()->get_physical_file_id();
1391 if (statement_file_id == scope_file_id)
1393 return_value =
true;
1400 return return_value;
1406 template <
class SageDecl>
1407 std::string genericGetName(SageDecl* dcl)
1410 return dcl->get_name();
1420 string name =
"undefined_name";
1422 ROSE_ASSERT(directive != NULL);
1431 case V_SgIncludeDirectiveStatement:
1432 case V_SgDefineDirectiveStatement:
1433 case V_SgUndefDirectiveStatement:
1434 case V_SgIfdefDirectiveStatement:
1435 case V_SgIfndefDirectiveStatement:
1436 case V_SgDeadIfDirectiveStatement:
1437 case V_SgIfDirectiveStatement:
1438 case V_SgElseDirectiveStatement:
1439 case V_SgElseifDirectiveStatement:
1440 case V_SgLineDirectiveStatement:
1441 case V_SgWarningDirectiveStatement:
1442 case V_SgErrorDirectiveStatement:
1443 case V_SgEmptyDirectiveStatement:
1450 case V_SgClinkageStartStatement:
1451 case V_SgClinkageEndStatement:
1457 case V_SgFortranIncludeLine:
1465 printf (
"Warning: default case reached in SageInterface::get_name ( const SgC_PreprocessorDirectiveStatement* directive ), directive = %p = %s \n",
1469 name =
"directive_default_name_case_reached_not_handled";
1481 string name =
"undefined_name";
1483 ROSE_ASSERT(declaration != NULL);
1487 if (directive != NULL)
1494 case V_SgTemplateMemberFunctionDeclaration:
1495 name = isSgTemplateMemberFunctionDeclaration(declaration)->get_name().str();
1498 case V_SgTemplateFunctionDeclaration:
1499 name = isSgTemplateFunctionDeclaration(declaration)->get_name().str();
1502 case V_SgTemplateClassDeclaration:
1503 name = isSgTemplateClassDeclaration(declaration)->get_name().str();
1506 case V_SgTemplateDeclaration:
1507 name = isSgTemplateDeclaration(declaration)->
get_name().str();
1510 case V_SgTemplateInstantiationDecl:
1511 name = isSgTemplateInstantiationDecl(declaration)->
get_templateName().str();
1514 case V_SgClassDeclaration:
1515 case V_SgDerivedTypeStatement:
1516 case V_SgJovialTableStatement:
1517 name = isSgClassDeclaration(declaration)->get_name().str();
1522 case V_SgJovialDefineDeclaration:
1523 case V_SgJovialDirectiveStatement:
1524 case V_SgJovialCompoolStatement:
1525 name =
"__" + declaration->
class_name() +
"_";
1529 case V_SgJovialLabelDeclaration:
1530 name = isSgJovialLabelDeclaration(declaration)->get_label();
1533 case V_SgEnumDeclaration:
1534 name = isSgEnumDeclaration(declaration)->
get_name().str();
1538 case V_SgTemplateInstantiationTypedefDeclaration:
1540 case V_SgTemplateTypedefDeclaration:
1541 case V_SgTypedefDeclaration:
1542 name = isSgTypedefDeclaration(declaration)->get_name().str();
1545 case V_SgFunctionDeclaration:
1546 case V_SgProgramHeaderStatement:
1547 case V_SgProcedureHeaderStatement:
1548 case V_SgMemberFunctionDeclaration:
1549 case V_SgTemplateInstantiationFunctionDecl:
1550 case V_SgTemplateInstantiationMemberFunctionDecl:
1551 case V_SgAdaFunctionRenamingDecl:
1552 case V_SgAdaEntryDecl:
1553 name = isSgFunctionDeclaration(declaration)->get_name().str();
1556 case V_SgNamespaceDeclarationStatement:
1557 name = isSgNamespaceDeclarationStatement(declaration)->
get_name().str();
1561 case V_SgFunctionParameterList:
1564 ROSE_ASSERT(declaration->
get_parent() != NULL);
1568 name =
get_name(functionDeclaration);
1576 name +=
"_parameter_list_";
1581 case V_SgTemplateVariableDeclaration:
1582 case V_SgTemplateVariableInstantiation:
1585 case V_SgVariableDeclaration:
1589 name =
"_variable_declaration_";
1591 ROSE_ASSERT(variableDeclaration != NULL);
1592 SgInitializedNamePtrList::const_iterator i = variableDeclaration->
get_variables().begin();
1595 ROSE_ASSERT(i != variableDeclaration->
get_variables().end());
1598 name += string((*i)->get_name().str());
1607 case V_SgVariableDefinition:
1611 name =
"_variable_definition_";
1613 ROSE_ASSERT(variableDefinition != NULL);
1616 ROSE_ASSERT(variableDefinition->
get_vardefn() != NULL);
1622 case V_SgPragmaDeclaration:
1624 name =
"_pragma_declaration_";
1626 ROSE_ASSERT(pragmaDeclaration != NULL);
1627 ROSE_ASSERT(pragmaDeclaration->get_pragma() != NULL);
1628 name +=
get_name(pragmaDeclaration->get_pragma());
1633 case V_SgUsingDirectiveStatement:
1635 name =
"_using_directive_statement_";
1637 ROSE_ASSERT(usingDeclaration != NULL);
1644 case V_SgNamespaceAliasDeclarationStatement:
1646 name =
"_namespace_alias_directive_statement_";
1648 ROSE_ASSERT(namespaceAliasDeclaration != NULL);
1649 ROSE_ASSERT(namespaceAliasDeclaration->
get_name().is_null() ==
false);
1650 name += namespaceAliasDeclaration->
get_name();
1655 case V_SgUsingDeclarationStatement:
1657 name =
"_using_declaration_statement_";
1659 ROSE_ASSERT(usingDeclaration != NULL);
1673 case V_SgTemplateInstantiationDirectiveStatement:
1675 name =
"_template_instantiation_directive_statement_";
1676 ROSE_ASSERT(declaration != NULL);
1678 ROSE_ASSERT(templateInstantiationDirective != NULL);
1679 ROSE_ASSERT(templateInstantiationDirective->
get_declaration() != NULL);
1687 case V_SgCtorInitializerList:
1689 name =
"_ctor_list_";
1691 ROSE_ASSERT(ctorDeclaration != NULL);
1692 ROSE_ASSERT(ctorDeclaration->
get_parent() != NULL);
1700 name =
"_asm_stmt_";
1701 const SgAsmStmt* asmStatement = isSgAsmStmt(declaration);
1702 ROSE_ASSERT(asmStatement != NULL);
1703 ROSE_ASSERT(asmStatement->
get_parent() != NULL);
1709 case V_SgImplicitStatement:
1711 name =
"_fortran_implicit_";
1713 ROSE_ASSERT(implicitStatement != NULL);
1714 ROSE_ASSERT(implicitStatement->
get_parent() != NULL);
1720 case V_SgNamelistStatement:
1722 name =
"_fortran_namelist_";
1724 ROSE_ASSERT(namelistStatement != NULL);
1725 ROSE_ASSERT(namelistStatement->
get_parent() != NULL);
1731 case V_SgEquivalenceStatement:
1733 name =
"_fortran_equivalence_";
1735 ROSE_ASSERT(equivalenceStatement != NULL);
1736 ROSE_ASSERT(equivalenceStatement->
get_parent() != NULL);
1743 case V_SgCommonBlock:
1745 name =
"_fortran_common_block_";
1746 const SgCommonBlock* commonBlockStatement = isSgCommonBlock(declaration);
1747 ROSE_ASSERT(commonBlockStatement != NULL);
1748 ROSE_ASSERT(commonBlockStatement->
get_parent() != NULL);
1754 case V_SgImportStatement:
1756 name =
"_fortran_import_stmt_";
1758 ROSE_ASSERT(importStatement != NULL);
1759 ROSE_ASSERT(importStatement->
get_parent() != NULL);
1765 case V_SgFormatStatement:
1767 name =
"_fortran_format_stmt_";
1769 ROSE_ASSERT(formatStatement != NULL);
1770 ROSE_ASSERT(formatStatement->
get_parent() != NULL);
1776 case V_SgModuleStatement:
1778 name =
"_fortran_module_stmt_";
1780 ROSE_ASSERT(moduleStatement != NULL);
1781 ROSE_ASSERT(moduleStatement->
get_parent() != NULL);
1787 case V_SgUseStatement:
1789 name =
"_fortran_use_stmt_";
1790 const SgUseStatement* useStatement = isSgUseStatement(declaration);
1791 ROSE_ASSERT(useStatement != NULL);
1792 ROSE_ASSERT(useStatement->
get_parent() != NULL);
1798 case V_SgContainsStatement:
1800 name =
"_fortran_contains_stmt_";
1802 ROSE_ASSERT(containsStatement != NULL);
1803 ROSE_ASSERT(containsStatement->
get_parent() != NULL);
1809 case V_SgEntryStatement:
1811 name =
"_fortran_entry_stmt_";
1813 ROSE_ASSERT(entryStatement != NULL);
1814 ROSE_ASSERT(entryStatement->
get_parent() != NULL);
1820 case V_SgAttributeSpecificationStatement:
1822 name =
"_fortran_attribute_specification_stmt_";
1824 ROSE_ASSERT(statement != NULL);
1825 ROSE_ASSERT(statement->
get_parent() != NULL);
1830 case V_SgInterfaceStatement:
1832 name =
"_fortran_interface_stmt_";
1834 ROSE_ASSERT(statement != NULL);
1835 ROSE_ASSERT(statement->
get_parent() != NULL);
1840 case V_SgFortranIncludeLine:
1842 name =
"_fortran_include_line_stmt_";
1844 ROSE_ASSERT(statement != NULL);
1845 ROSE_ASSERT(statement->
get_parent() != NULL);
1851 case V_SgJavaImportStatement:
1853 name =
"_java_import_stmt_";
1855 ROSE_ASSERT(statement != NULL);
1856 ROSE_ASSERT(statement->
get_parent() != NULL);
1861 case V_SgJavaPackageDeclaration:
1863 name =
"_java_package_declaration_";
1865 ROSE_ASSERT(package_declaration != NULL);
1866 ROSE_ASSERT(package_declaration->
get_parent() != NULL);
1871 case V_SgJavaPackageStatement:
1873 name =
"_java_package_stmt_";
1875 ROSE_ASSERT(statement != NULL);
1876 ROSE_ASSERT(statement->
get_parent() != NULL);
1882 case V_SgStaticAssertionDeclaration:
1884 name =
"_static_assertion_declaration_stmt_";
1886 ROSE_ASSERT(statement != NULL);
1887 ROSE_ASSERT(statement->
get_parent() != NULL);
1892 case V_SgNonrealDecl:
1894 const SgNonrealDecl * nrdecl = isSgNonrealDecl(declaration);
1895 ROSE_ASSERT(nrdecl != NULL);
1896 name = nrdecl->get_name();
1901 case V_SgEmptyDeclaration:
1904 ROSE_ASSERT(emptyDeclaration != NULL);
1909 case V_SgAdaPackageSpecDecl:
1911 name = genericGetName(isSgAdaPackageSpecDecl(declaration));
1915 case V_SgAdaPackageBodyDecl:
1917 name = genericGetName(isSgAdaPackageBodyDecl(declaration));
1921 case V_SgAdaFormalTypeDecl:
1923 name = genericGetName(isSgAdaFormalTypeDecl(declaration));
1927 case V_SgAdaGenericDecl:
1931 name =
get_name(gendcl->get_declaration());
1934 if (isSgFunctionDeclaration(dcl->get_declaration())) {
1935 name =
"_ada_generic_decl_" + genericGetName(isSgFunctionDeclaration(dcl->get_declaration()));
1938 if (isSgAdaPackageSpecDecl(dcl->get_declaration())) {
1939 name =
"_ada_generic_decl_" + genericGetName(isSgAdaPackageSpecDecl(dcl->get_declaration()));
1949 case V_SgAdaDiscriminatedTypeDecl:
1960 name =
"_incomplete_Ada_discriminated_type_";
1966 case V_SgAdaVariantDecl:
1968 name =
"_ada_variant_decl_";
1972 case V_SgAdaAttributeClause:
1974 name =
"_ada_attribute_clause_";
1978 case V_SgAdaRepresentationClause:
1980 name =
"_ada_representation_clause_";
1984 case V_SgAdaEnumRepresentationClause:
1986 name =
"_ada_enum_representation_clause_";
1990 case V_SgAdaComponentClause:
1992 name =
"_ada_component_clause_";
1996 case V_SgAdaTaskTypeDecl:
1998 name = genericGetName(isSgAdaTaskTypeDecl(declaration));
2002 case V_SgAdaProtectedTypeDecl:
2004 name = genericGetName(isSgAdaProtectedTypeDecl(declaration));
2008 case V_SgAdaTaskBodyDecl:
2010 name = genericGetName(isSgAdaTaskBodyDecl(declaration));
2014 case V_SgAdaProtectedBodyDecl:
2016 name = genericGetName(isSgAdaProtectedBodyDecl(declaration));
2020 case V_SgAdaRenamingDecl:
2022 name = genericGetName(isSgAdaRenamingDecl(declaration));
2026 case V_SgAdaTaskSpecDecl:
2028 name = genericGetName(isSgAdaTaskSpecDecl(declaration));
2032 case V_SgAdaProtectedSpecDecl:
2034 name = genericGetName(isSgAdaProtectedSpecDecl(declaration));
2038 case V_SgAdaGenericInstanceDecl:
2040 name = genericGetName(isSgAdaGenericInstanceDecl(declaration));
2044 case V_SgAdaFormalPackageDecl:
2046 name = genericGetName(isSgAdaFormalPackageDecl(declaration));
2050 case V_SgAdaParameterList:
2055 name = std::accumulate( plst->get_parameters().begin(), plst->get_parameters().end(),
2056 std::string{
"_ada_parameter_list_"},
2059 n += SageInterface::get_name(rhs);
2068 printf (
"Warning: default case reached in SageInterface::get_name ( const SgDeclarationStatement* declaration ), declaration = %p = %s \n",
2069 declaration,declaration->
class_name().c_str());
2079 string name =
"undefined_name";
2081 ROSE_ASSERT(scope != NULL);
2086 case V_SgTemplateClassDefinition:
2087 name =
get_name(isSgTemplateClassDefinition(scope)->get_declaration());
2090 case V_SgClassDefinition:
2091 case V_SgTemplateInstantiationDefn:
2092 name =
get_name(isSgClassDefinition(scope)->get_declaration());
2096 case V_SgTemplateFunctionDefinition:
2097 case V_SgFunctionDefinition:
2098 name =
get_name(isSgFunctionDefinition(scope)->get_declaration());
2101 case V_SgNamespaceDefinitionStatement:
2102 name =
get_name(isSgNamespaceDefinitionStatement(scope)->get_namespaceDeclaration());
2104 case V_SgJavaLabelStatement:
2105 name = (isSgJavaLabelStatement(scope)->get_label()).getString();
2109 case V_SgDeclarationScope:
2112 case V_SgAssociateStatement:
2113 case V_SgJavaForEachStatement:
2115 case V_SgFunctionParameterScope:
2116 case V_SgAdaPackageSpec:
2117 case V_SgAdaPackageBody:
2118 case V_SgAdaTaskSpec:
2119 case V_SgAdaTaskBody:
2120 case V_SgAdaProtectedSpec:
2121 case V_SgAdaProtectedBody:
2122 case V_SgAdaGenericDefn:
2123 case V_SgAdaAcceptStmt:
2124 case V_SgJovialForThenStatement:
2125 case V_SgMatlabForStatement:
2126 case V_SgBasicBlock:
2127 case V_SgCatchOptionStmt:
2128 case V_SgDoWhileStmt:
2129 case V_SgForStatement:
2132 case V_SgSwitchStatement:
2135 case V_SgForAllStatement:
2136 case V_SgRangeBasedForStatement:
2141 printf (
"Error: undefined case (SgScopeStatement) in SageInterface::get_name(): node = %s \n",scope->
class_name().c_str());
2151 string name =
"undefined_name";
2153 ROSE_ASSERT(stmt != NULL);
2156 if (declaration != NULL)
2174 case V_SgCaseOptionStmt:
2175 case V_SgCatchStatementSeq:
2176 case V_SgClinkageStartStatement:
2177 case V_SgContinueStmt:
2178 case V_SgDefaultOptionStmt:
2180 case V_SgForInitStmt:
2181 case V_SgFunctionTypeTable:
2182 case V_SgGotoStatement:
2183 case V_SgReturnStmt:
2189 case V_SgLabelStatement:
2192 name = labelStatement->
get_label().str();
2215 ROSE_ASSERT(node != NULL);
2217 string name =
"undefined_name";
2219 ROSE_ASSERT(node != NULL);
2223 case V_SgInitializedName:
2226 if (initializedName != NULL)
2228 name = initializedName->get_name().str();
2236 name =
"_pragma_string_";
2237 const SgPragma* pragma = isSgPragma(node);
2238 ROSE_ASSERT(pragma != NULL);
2239 name += pragma->get_pragma();
2253 case V_SgSourceFile:
2254#ifdef ROSE_ENABLE_BINARY_ANALYSIS
2255 case V_SgBinaryComposite:
2261 const SgFile* file = isSgFile(node);
2262 ROSE_ASSERT(file != NULL);
2269 case V_SgSymbolTable:
2271 name =
"_symbol_table_";
2276 case V_SgStorageModifier:
2278 name =
"_storage_modifier_";
2284 case V_Sg_File_Info:
2286 name =
"_file_info_";
2291 case V_SgTemplateArgument:
2293 name =
"_template_argument_";
2295 ROSE_ASSERT(templateArgument != NULL);
2301 ROSE_ASSERT(t != NULL);
2315 ROSE_ASSERT(templateArgument->get_initializedName() == NULL);
2320 ROSE_ASSERT(t == NULL);
2322 ROSE_ASSERT(initializedName != NULL);
2333 ROSE_ASSERT(t != NULL);
2340 printf (
"Error: default case reached in switch on templateArgument->get_argumentType() \n");
2349 case V_SgTypeModifier:
2352 ROSE_ASSERT(typeModifier != NULL);
2353 name =
"_type_modifier_" + typeModifier->displayString();
2360 const SgNameGroup* nameGroup = isSgNameGroup(node);
2361 ROSE_ASSERT(nameGroup != NULL);
2362 name =
"_name_group_" + nameGroup->get_group_name();
2367 case V_SgDataStatementGroup:
2370 ROSE_ASSERT(dataGroup != NULL);
2371 name =
"_data_statement_group_";
2376 case V_SgDataStatementObject:
2379 ROSE_ASSERT(dataObject != NULL);
2380 name =
"_data_statement_object_";
2385 case V_SgDataStatementValue:
2388 ROSE_ASSERT(dataValue != NULL);
2389 name =
"_data_statement_value_";
2394 case V_SgCommonBlockObject:
2397 ROSE_ASSERT(commonBlockObject != NULL);
2398 name =
"_common_block_object_" + commonBlockObject->get_block_name();
2403 case V_SgFormatItem:
2406 ROSE_ASSERT(formatItem != NULL);
2407 name =
"_format_item_";
2412 case V_SgFormatItemList:
2415 ROSE_ASSERT(formatItemList != NULL);
2416 name =
"_format_item_list_";
2421 case V_SgRenamePair:
2424 ROSE_ASSERT(renamePair != NULL);
2425 name = renamePair->get_local_name() +
"__" + renamePair->get_use_name() +
"_rename_pair_";
2432 const SgName* name_node = isSgName(node);
2433 ROSE_ASSERT(name_node != NULL);
2434 name =
"_name_" + name_node->getString();
2439 case V_SgTemplateParameter:
2442 ROSE_ASSERT(template_parameter_node != NULL);
2443 name =
"_template_parameter_";
2445 switch(template_parameter_node->get_parameterType())
2449 name +=
"type_parameter_";
2455 name +=
"nontype_parameter_";
2459 if (template_parameter_node->get_expression() != NULL)
2465 ROSE_ASSERT(template_parameter_node->get_initializedName() != NULL);
2471 name += template_parameter_node->get_initializedName()->
unparseToString();
2479 name +=
"template_parameter_";
2485 printf (
"Error: default reached \n");
2495 const SgBaseClass* base_class_node = isSgBaseClass(node);
2496 ROSE_ASSERT(base_class_node != NULL);
2497 ROSE_ASSERT(base_class_node->get_base_class() != NULL);
2502 ROSE_ASSERT(baseClassModifier != NULL);
2503 access = baseClassModifier->displayString();
2505 name =
"_base_class_" + access +
"_" +
get_name(base_class_node->get_base_class());
2511 printf (
"Default reached in switch for SgSupport IR node = %s \n",node->
class_name().c_str());
2512 name =
"default name";
2527 ROSE_ASSERT(symbol != NULL);
2529 string aliasSymbolPrefix =
"";
2530 if (isSgAliasSymbol(symbol) != NULL)
2532 aliasSymbolPrefix =
"_ALIAS";
2539 return symbol->
get_name() + aliasSymbolPrefix +
"_symbol_";
2547 ROSE_ASSERT(type != NULL);
2551 const SgNamedType* namedType = isSgNamedType(type);
2552 if (namedType != NULL)
2554 returnName =
"named_type_";
2555 returnName = namedType->
get_name().getString();
2561 case V_SgPointerType:
2564 returnName =
"pointer_to_";
2565 returnName +=
get_name(pointerType->get_base_type());
2569 case V_SgReferenceType:
2572 returnName =
"reference_to_";
2573 returnName +=
get_name(referenceType->get_base_type());
2579 const SgArrayType* arrayType = isSgArrayType(type);
2580 returnName =
"array_of_";
2581 returnName +=
get_name(arrayType->get_base_type());
2585 case V_SgModifierType:
2589 returnName +=
get_name(modifierType->get_base_type());
2594 case V_SgTemplateType:
2597 returnName =
"templateType_";
2598 returnName += templateType->get_name();
2615 string name =
"undefined_name";
2623 name =
"var_ref_of_";
2624 ROSE_ASSERT(varRef != NULL);
2625 ROSE_ASSERT(varRef->get_symbol() != NULL);
2626 name += varRef->get_symbol()->
get_name();
2631 case V_SgLabelRefExp:
2634 name =
"label_ref_of_";
2635 ROSE_ASSERT(labelRef != NULL);
2636 ROSE_ASSERT(labelRef->get_symbol() != NULL);
2637 name += labelRef->get_symbol()->
get_name();
2641 case V_SgPntrArrRefExp:
2644 name =
"array_ref_of_";
2651 case V_SgFunctionCallExp:
2654 name =
"function_call_";
2655 name +=
get_name(functionCall->get_function());
2659 case V_SgFunctionRefExp:
2662 name =
"function_ref_";
2663 name += functionRefExp->get_symbol()->
get_name();
2668 case V_SgMemberFunctionRefExp:
2671 name =
"member_function_ref_";
2672 name += memberFunctionRefExp->get_symbol()->
get_name();
2678 const SgIntVal* valueExp = isSgIntVal(expr);
2679 name =
"integer_value_exp_";
2686 const SgStringVal* valueExp = isSgStringVal(expr);
2687 name =
"string_value_exp_";
2688 name += valueExp->get_value();
2692 case V_SgSubscriptExpression:
2695 name =
"subscript_exp_";
2697 name +=
get_name(subscriptExpression->get_lowerBound());
2700 name +=
get_name(subscriptExpression->get_upperBound());
2703 name +=
get_name(subscriptExpression->get_stride());
2707 case V_SgNullExpression:
2709 name =
"null_expression";
2714 case V_SgExprListExp:
2717 name =
"expr_list_exp_";
2718 for (
size_t i = 0; i < exprListExp->get_expressions().size(); i++)
2720 name +=
get_name(exprListExp->get_expressions()[i]);
2726 case V_SgActualArgumentExpression:
2729 name =
"actual_arg_exp_name_";
2730 name += actualArgExp->get_argument_name();
2732 name +=
get_name(actualArgExp->get_expression());
2737 case V_SgTemplateParameterVal:
2740 name =
"template_parameter_value_expression_number_";
2750 const SgDotExp* dotExp = isSgDotExp(expr);
2751 ROSE_ASSERT(dotExp != NULL);
2753 name =
"_dot_exp_lhs_";
2755 name +=
"_dot_exp_rhs_";
2764 const SgLambdaExp* lambdaExp = isSgLambdaExp(expr);
2765 ROSE_ASSERT (lambdaExp != NULL);
2766 name =
"lambda_expression_";
2773 const SgThisExp* thisExp = isSgThisExp(expr);
2774 ROSE_ASSERT(thisExp != NULL);
2776 name =
"_this_exp_for_";
2779 ROSE_ASSERT(classSymbol != NULL);
2792 printf (
"Note: default reached in get_name() expr = %p = %s \n",expr,expr->
class_name().c_str());
2811 ROSE_ASSERT(node != NULL);
2817 case V_SgRenamePair:
2820 returnName =
"rename_pair_";
2821 returnName += n->get_local_name().str();
2822 returnName +=
"_from_";
2823 returnName += n->get_use_name().str();
2827 case V_SgInitializedName:
2830 ROSE_ASSERT (n != NULL);
2831 returnName =
"initialized_name_";
2832 returnName += n->get_name().str();
2837 case V_SgLambdaCapture:
2840 ROSE_ASSERT (n != NULL);
2841 returnName =
"lambda_capture_";
2847 case V_SgInterfaceBody:
2850 returnName =
"interface_body";
2870 string name =
"undefined_name";
2872 ROSE_ASSERT(node != NULL);
2875 if (locatedNode != NULL)
2877 const SgStatement* statement = isSgStatement(node);
2878 if (statement != NULL)
2885 if (expression != NULL)
2892 if (locatedNodeSupport != NULL)
2894 name =
get_name(locatedNodeSupport);
2898 const SgToken* token = isSgToken(node);
2905 printf (
"Unknown SgLocatedNode = %p = %s \n",node,node->
class_name().c_str());
2914 const SgSupport* supportNode = isSgSupport(node);
2915 if (supportNode != NULL)
2922 const SgSymbol* symbol = isSgSymbol(node);
2930 const SgType* type = isSgType(node);
2951 string name =
"undefined_name";
2953 ROSE_ASSERT(token != NULL);
2954 name = token->get_lexeme_string();
2959 else if (name ==
"\n")
2961 else if (name ==
"\t")
3003 case V_SgClassDeclaration:
3004 case V_SgTemplateClassDeclaration:
3008 ROSE_ASSERT(classDeclaration != NULL);
3010 string type_name = classDeclaration->get_name();
3012 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case class or template type: type_name = %s \n",type_name.c_str());
3014 string className = string(
"scope_") + scope +
"_type_name_" + type_name;
3016 printf (
"classDeclaration->get_scope() = %p = %s scope = %s \n",classDeclaration->
get_scope(),classDeclaration->
get_scope()->
class_name().c_str(),scope.c_str());
3023 case V_SgTemplateInstantiationDecl:
3026 ROSE_ASSERT(templateInstantiationDeclaration != NULL);
3032 string type_name = templateInstantiationDeclaration->get_name();
3034 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgTemplateInstantiationDecl: type_name = %s \n",type_name.c_str());
3036 string className = string(
"scope_") + scope +
"_type_name_" + type_name;
3051 printf (
"className = %s compressedClassName = %s \n",className.c_str(),compressedClassName.c_str());
3054 printf (
"templateInstantiationDeclaration->get_scope() = %p = %s scope = %s \n",
3058 s = compressedClassName;
3060 printf (
"Exiting as a test! \n");
3066 case V_SgFunctionDeclaration:
3067 case V_SgTemplateFunctionDeclaration:
3068 case V_SgTemplateInstantiationFunctionDecl:
3071 ROSE_ASSERT(functionDeclaration != NULL);
3073 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgFunctionDeclaration: not implemented \n");
3076 string original_name = functionDeclaration->get_name();
3078 string function_name_part = mangleFunctionName(original_name,
"return_type");
3079 string function_name = string(
"scope_") + scope +
"_function_name_" + function_name_part;
3093 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): Collision count = %d \n",count);
3100 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): case SgFunctionDeclaration: Exiting as a test! \n");
3106 case V_SgMemberFunctionDeclaration:
3107 case V_SgTemplateMemberFunctionDeclaration:
3108 case V_SgTemplateInstantiationMemberFunctionDecl:
3111 ROSE_ASSERT(memberFunctionDeclaration != NULL);
3113 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier_support(): case SgMemberFunctionDeclaration: not implemented \n");
3116 string original_name = memberFunctionDeclaration->get_name();
3122 string member_function_name_part = mangleFunctionName(original_name,
"return_type");
3124 string member_function_name = string(
"scope_") + scope +
"_member_function_name_" + member_function_name_part;
3138 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): Collision count = %d \n",count);
3143 s = member_function_name;
3145 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): case SgMemberFunctionDeclaration: Exiting as a test! \n");
3153 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): Unsupported declaration = %p = %s \n",declaration,declaration->
class_name().c_str());
3159 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): s = %s \n",s.c_str());
3164 printf (
"In SageInterface::generateUniqueNameForUseAsIdentifier(): s = %s \n",s.c_str());
3169 printf (
"Exiting as a test! \n");
3188 printf (
"In generateUniqueNameForUseAsIdentifier(): evaluating declaration = %p = %s \n",declaration,declaration->
class_name().c_str());
3201 if (definingDeclaration != NULL)
3204 printf (
"In generateUniqueName(): Using the defining declaration = %p since %p was not in the map \n",definingDeclaration,declaration);
3212 printf (
"Warning: defining declaration not in SageInterface::local_node_to_name_map: declaration = %p = %s using name = %s \n",
3219 ROSE_ASSERT(nondefiningDeclaration != NULL);
3225 printf (
"Exiting as a test! \n");
3236 ROSE_ASSERT(astNode != NULL);
3246 void visit (
SgNode* node)
3253 if (classDeclaration != NULL || functionDeclaration != NULL)
3264 UniqueNameTraversal traversal;
3265 traversal.traverse(astNode, preorder);
3275 ROSE_ASSERT(classDeclaration != NULL);
3277 ROSE_ASSERT(definingDeclaration != NULL);
3278 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(definingDeclaration);
3282 if (definingClassDeclaration != NULL)
3284 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3285 ROSE_ASSERT(classDefinition != NULL);
3287 SgDeclarationStatementPtrList::iterator i = classDefinition->
get_members().begin();
3288 while ( i != classDefinition->
get_members().end() )
3291 ROSE_ASSERT( (*i)->get_parent() != NULL);
3292 ROSE_ASSERT( (*i)->get_parent() == classDefinition);
3295 if (memberFunction != NULL)
3298 if ( memberFunction->get_specialFunctionModifier().isConstructor() ==
true )
3299 defaultConstructor = memberFunction;
3310 return defaultConstructor;
3318 ROSE_ASSERT(classDeclaration != NULL);
3320 if (definingDeclaration != NULL)
3322 ROSE_ASSERT(definingDeclaration != NULL);
3323 SgClassDeclaration* definingClassDeclaration = isSgClassDeclaration(definingDeclaration);
3327 if (definingClassDeclaration != NULL)
3329 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3330 ROSE_ASSERT(classDefinition != NULL);
3332 SgDeclarationStatementPtrList::iterator i = classDefinition->
get_members().begin();
3333 while ( i != classDefinition->
get_members().end() )
3337 ROSE_ASSERT(i_parent != NULL);
3342 if ( i_parent != classDefinition )
3344 printf (
"Error: (*i)->get_parent() = %p = %s \n",i_parent,i_parent->
class_name().c_str());
3345 printf (
"(*i) = %p = %s = %s \n",*i,(*i)->class_name().c_str(),(*i)->unparseToString().c_str());
3346 (*i)->get_file_info()->display(
"Called from SageInterface::getDefaultDestructor: debug");
3348 ROSE_ASSERT( i_parent == classDefinition);
3351 if (memberFunction != NULL)
3353 if ( memberFunction->get_specialFunctionModifier().isDestructor() ==
true )
3354 defaultDestructor = memberFunction;
3363 return defaultDestructor;
3375#define DEBUG_ADD_DEFAULT_CONSTRUCTOR 0
3379 ASSERT_not_null(classType);
3381 bool returnValue =
false;
3384 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
3385 ROSE_ASSERT(classDeclaration != NULL);
3387 ROSE_ASSERT(definingClassDeclaration != NULL);
3388 SgClassDefinition* classDefinition = definingClassDeclaration->get_definition();
3389 ROSE_ASSERT(classDefinition != NULL);
3391 SgDeclarationStatementPtrList & declarationList = classDefinition->
get_members();
3393 bool foundConstructor =
false;
3394 bool foundDefaultConstructor =
false;
3396#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3397 printf (
"In addDefaultConstructorIfRequired(): class name = %s \n",classDeclaration->get_name().str());
3400 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
3401 while (i != declarationList.end())
3404 if (memberFunctionDeclaration != NULL)
3406 bool isConstructor = memberFunctionDeclaration->get_specialFunctionModifier().isConstructor();
3407 if (isConstructor ==
true)
3409 foundConstructor =
true;
3411#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3412 printf (
"Found a constructor! \n");
3415 ROSE_ASSERT(functionParameterList != NULL);
3419 foundDefaultConstructor = ((foundDefaultConstructor ==
true) || (functionParameterList->
get_args().size() == 0));
3421#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3422 if (foundDefaultConstructor ==
true)
3424 printf (
"Found a default constructor! \n");
3428 printf (
"This is not a default constructor: functionParameterList->get_args().size() = %zu \n",functionParameterList->
get_args().size());
3434#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3435 printf (
"This is not a constructor \n");
3443#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3444 printf (
"foundConstructor = %s \n",foundConstructor ?
"true" :
"false");
3445 printf (
"foundDefaultConstructor = %s \n",foundDefaultConstructor ?
"true" :
"false");
3448 if (foundConstructor ==
true)
3451#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3452 printf (
"Since there is at least one constructor, we can't rely on compiler generated constructors \n");
3454 if (foundDefaultConstructor ==
true)
3457#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3458 printf (
"We can use the existing default constructor (no need to build one) \n");
3465#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3466 printf (
"########################################################### \n");
3467 printf (
"Need to build a default constructor in the associated class \n");
3470 ROSE_ASSERT(constructorDeclaration != NULL);
3472#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3473 printf (
" --- constructorDeclaration = %p = %s name = %s \n",constructorDeclaration,constructorDeclaration->
class_name().c_str(),constructorDeclaration->get_name().str());
3475 ROSE_ASSERT (constructorDeclaration->get_declarationModifier().get_accessModifier().isPublic() ==
true);
3477 classDefinition->prepend_statement(constructorDeclaration);
3480 ROSE_ASSERT(constructorDeclaration->
get_parent() != NULL);
3488 constructorDeclaration->
get_endOfConstruct ()->set_physical_file_id(physical_file_id);
3492 ROSE_ASSERT(constructorDeclaration->get_definition() != NULL);
3495 constructorDeclaration->get_definition()->
get_startOfConstruct()->set_physical_file_id(physical_file_id);
3496 constructorDeclaration->get_definition()->
get_endOfConstruct ()->set_physical_file_id(physical_file_id);
3499#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3500 printf (
"DONE: Need to build a default constructor in the associated class \n");
3501 printf (
"################################################################# \n");
3504 printf (
"Exiting as a test! \n");
3513#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3514 printf (
"No constructors found, so we don't need to add an explicit default constructor \n");
3518#if DEBUG_ADD_DEFAULT_CONSTRUCTOR
3519 printf (
"Leaving addDefaultConstructorIfRequired(): returnValue = %s \n",returnValue ?
"true" :
"false");
3551 astTraversal.
traverse(node,preorder);
3561 printf (
"Exiting as a test! \n");
3571 printf (
"Symbol Table from %p = %s at: \n",scope,scope->
sage_class_name());
3572 scope->
get_file_info()->display(
"Symbol Table Location (Called from SageInterface::OutputLocalSymbolTables::visit())");
3574 scope->print_symboltable(
"Called from SageInterface::OutputLocalSymbolTables::visit()");
3589 bool result =
false;
3604 bool result =
false;
3608 if (isTemplateMemberFunction(memberFunctionDeclaration) ==
true)
3611 printf (
"templateDeclaration = %p parent of templateDeclaration = %p \n",templateDeclaration,templateDeclaration->
get_parent());
3614 SgClassDeclaration* classDeclaration = memberFunctionDeclaration->get_class_scope()->get_declaration();
3615 ROSE_ASSERT(classDeclaration != NULL);
3618 if (classTemplateInstantiation != NULL)
3621 if (classTemplateDeclaration != NULL && classTemplateDeclaration != templateDeclaration)
3635 if (templateDeclaration != NULL && templateDeclaration->
get_parent() != NULL)
3638 if (isSgClassDefinition(parentScope) != NULL)
3651 printf (
"Error: This is no longer used. \n");
3664 if (firstNondefiningDeclaration != NULL)
3665 keyDeclaration = firstNondefiningDeclaration;
3667 keyDeclaration = definingDeclaration;
3668 ROSE_ASSERT(keyDeclaration != NULL);
3670 return keyDeclaration;
3676 string pragmaString = pragmaDeclaration->get_pragma()->get_pragma();
3677 istringstream istr(pragmaString);
3687 ROSE_ASSERT (n != NULL);
3688 bool result =
false;
3689 if (isSgOmpBarrierStatement(n)||
3690 isSgOmpBodyStatement(n)||
3691 isSgOmpDeclareSimdStatement(n) ||
3692 isSgOmpFlushStatement(n)||
3693 isSgOmpThreadprivateStatement(n)||
3694 isSgOmpTaskwaitStatement(n) )
3722 if (memberFunctionDeclaration != NULL)
3732 ROSE_ASSERT(scope != NULL);
3735 if (isSgDeclarationScope(scope)) {
3736 printf(
"TODO SageInterface::isOverloaded case when scope is SgDeclarationScope. See ROSE-1378.\n");
3742 isSgClassDefinition(memberFunctionDeclaration->
get_scope());
3743 ROSE_ASSERT(classDefinition != NULL);
3747 ROSE_ASSERT(classDeclaration != NULL);
3750 SgDeclarationStatementPtrList & memberList = classDefinition->
get_members();
3753 printf (
" memberList.size() = %" PRIuPTR
" \n",memberList.size());
3755 for (SgDeclarationStatementPtrList::iterator i = memberList.begin(); i != memberList.end(); i++)
3758 printf (
" counter = %d declaration = %p = %s \n",counter,*i,(*i)->class_name().c_str());
3764 if (tempMemberFunction != NULL)
3769 if ( keyDeclaration == generateUniqueDeclaration(tempMemberFunction) )
3772 printf (
"Skipping the case of keyDeclaration == generateUniqueDeclaration(tempMemberFunction) = %p \n",keyDeclaration);
3777 ROSE_ASSERT(tempMemberFunction->get_name() !=
"");
3779 printf (
" tempMemberFunction = (name) %s = (qualified) %s \n",
3780 tempMemberFunction->get_name().str(),
3781 tempMemberFunction->get_qualified_name().str());
3783 if (tempMemberFunction->get_name() == memberFunctionDeclaration->get_name())
3786 printf (
" Found a matching overloaded member function! \n");
3795 if (tempTemplateDeclaration != NULL)
3801 printf (
"tempTemplateDeclaration->get_name() = %s \n",tempTemplateDeclaration->
get_name().str());
3803 if (memberFunctionDeclaration->get_name() == tempTemplateDeclaration->
get_name())
3806 printf (
" Found a matching overloaded member function! \n");
3815 if (functionDeclaration->
variantT() == V_SgFunctionDeclaration)
3817 printf (
"In SageInterface::isOverloaded(): could friend functions be overloaded in a class? \n");
3830 printf (
"In SageInterface::isOverloaded(): case of non-member function not yet implemented! \n");
3837 return (counter > 1);
3852 ROSE_ASSERT(memberFunctionInstantiation != NULL);
3855 printf (
"buildForwardFunctionDeclaration: Member function = %p = %s = definition = %p \n",
3856 memberFunctionInstantiation,
3857 memberFunctionInstantiation->get_name().str(),
3858 memberFunctionInstantiation->get_definition());
3859 memberFunctionInstantiation->
get_file_info()->display(
"memberFunctionInstantiation: debug");
3865 class NondefiningFunctionDeclarationCopyType :
public SgCopyHelp
3875 SgNode* returnValue = NULL;
3883 case V_SgFunctionDeclaration:
3884 case V_SgMemberFunctionDeclaration:
3885 case V_SgTemplateInstantiationFunctionDecl:
3886 case V_SgTemplateInstantiationMemberFunctionDecl:
3890 ROSE_ASSERT(functionDeclaration != NULL);
3896 returnValue =
const_cast<SgNode *
>(n);
3908 case V_SgFunctionDefinition:
3910 printf (
"Skip copying the function definition if it is present \n");
3912 returnValue =
const_cast<SgNode *
>(n);
3926 if (returnValue == NULL)
3927 returnValue = n->copy(*
this);
3929 ROSE_ASSERT(returnValue != NULL);
3932 } nondefiningFunctionDeclarationCopy;
3937 if (memberFunctionInstantiation->get_definition() != NULL)
3939 printf (
"\n\nNEED TO REMOVE POINTERS IN THE NON-DEFINING DECLARATION TO THE SgClassDefinition objects. \n");
3944 memberFunctionInstantiation->set_definition(NULL);
3946 SgNode* copyOfMemberFunctionNode = memberFunctionInstantiation->copy(nondefiningFunctionDeclarationCopy);
3965 printf (
"copyOfMemberFunction->isForward() = %s \n",copyOfMemberFunction->
isForward() ?
"true" :
"false");
3966 printf (
"memberFunctionInstantiation->isForward() = %s \n",memberFunctionInstantiation->
isForward() ?
"true" :
"false");
3969 printf (
"memberFunctionInstantiation->isSpecialization() = %s \n",memberFunctionInstantiation->isSpecialization() ?
"true" :
"false");
3970 printf (
"copyOfMemberFunctionNode = %p = %s = %s memberFunctionInstantiation->isSpecialization() = %s \n",
3971 copyOfMemberFunction,copyOfMemberFunction->
class_name().c_str(),
SageInterface::get_name(copyOfMemberFunction).c_str(),copyOfMemberFunction->isSpecialization() ?
"true" :
"false");
3972 copyOfMemberFunction->
get_file_info()->display(
"copyOfMemberFunction: debug");
3976 ROSE_ASSERT(memberFunctionInstantiation->get_args().size() == copyOfMemberFunction->get_args().size());
3982 ROSE_ASSERT(copyOfMemberFunction != NULL);
3983 return copyOfMemberFunction;
3992 ROSE_ASSERT(declarationForType != NULL);
3995 switch(declarationForType->
variantT())
3998 case V_SgTemplateInstantiationDecl:
3999 case V_SgTemplateClassDeclaration:
4001 case V_SgClassDeclaration:
4006 if (isSgTemplateClassDeclaration(declarationForType) != NULL)
4015 ROSE_ASSERT(symbol != NULL);
4016 SgName name = classDeclaration->get_name();
4017 symbolTable->insert(name,symbol);
4021 case V_SgEnumDeclaration:
4025 ROSE_ASSERT(symbol != NULL);
4027 symbolTable->insert(name,symbol);
4031 case V_SgFunctionDeclaration:
4035 ROSE_ASSERT(symbol != NULL);
4036 SgName name = functionDeclaration->get_name();
4037 symbolTable->insert(name,symbol);
4041 case V_SgMemberFunctionDeclaration:
4045 ROSE_ASSERT(symbol != NULL);
4049 SgName name = functionDeclaration->get_name();
4050 symbolTable->insert(name,symbol);
4056 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());
4067 SgInitializedNamePtrList::iterator i = variableList.begin();
4068 while (i != variableList.end())
4072 if (
variable->get_scope() == scope)
4080 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());
4085 ROSE_ASSERT(symbol != NULL);
4087 symbolTable->insert(name,symbol);
4095SageInterface::supportForInitializedNameLists (
SgScopeStatement* scope, SgInitializedNamePtrList & variableList )
4098 ROSE_ASSERT(symbolTable != NULL);
4100 supportForVariableLists(scope,symbolTable,variableList);
4108 SgInitializedNamePtrList & variableList = variableDeclaration->
get_variables();
4109 supportForVariableLists(scope,symbolTable,variableList);
4117 ROSE_ASSERT(symbolTable != NULL);
4128 std::vector<SgNode*> labelList = NodeQuery::querySubTree (scope,V_SgLabelStatement);
4130 int numberOfLabels = labelList.size();
4131 for (
int i=0; i < numberOfLabels; i++)
4135 ROSE_ASSERT(labelStatement != NULL);
4136 ROSE_ASSERT(labelStatement->
get_scope() == scope);
4139 ROSE_ASSERT(symbol != NULL);
4143 SgName name = labelStatement->get_name();
4144 symbolTable->insert(name,symbol);
4154 ROSE_ASSERT(scope != NULL);
4156 printf (
"In SageInterface::rebuildSymbolTable(): Symbol Table from %p = %s \n",scope,scope->
class_name().c_str());
4159 printf (
"Exiting as a test \n");
4165 if (symbolTable != NULL)
4168 if (symbolTable->
size() != 0)
4170 printf (
"symbolTable->size() = %d \n",symbolTable->
size());
4172 ROSE_ASSERT(symbolTable->
size() == 0);
4174 printf (
"Symbol Table from %p = %s of size = %" PRIuPTR
" \n",scope,scope->
class_name().c_str(),symbolTable->
size());
4175 symbolTable->
print(
"Called from SageInterface::rebuildSymbolTable()");
4181 printf (
"In SageInterface::rebuildSymbolTable(): No symbol table found \n");
4183 ROSE_ASSERT(symbolTable == NULL);
4188 ROSE_ASSERT(symbolTable != NULL);
4189 ROSE_ASSERT(symbolTable->get_table() != NULL);
4193 ROSE_ASSERT(symbolTable->
get_parent() != NULL);
4206 case V_SgForStatement:
4213 SgStatementPtrList::iterator i = forStatement->get_init_stmt().begin();
4217 while (i != forStatement->get_init_stmt().end())
4221 if (variableDeclarationInitializer != NULL)
4226 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationInitializer );
4232 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(forStatement->get_test());
4233 if (variableDeclarationCondition != NULL)
4238 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4245 case V_SgJovialForThenStatement:
4246 case V_SgMatlabForStatement:
4254 case V_SgTemplateFunctionDefinition:
4256 case V_SgFunctionDefinition:
4263 if (functionDefinition != NULL)
4269 if (functionDeclaration != NULL)
4272 if (functionDeclaration->
isForward() ==
true)
4274 printf (
"ERROR: functionDeclaration = %p = %s = %s \n",functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
4275 printf (
" --- functionDeclaration (get_name()) = %s \n",
get_name(functionDeclaration).c_str());
4276 printf (
" --- functionDeclaration (mangled name) = %s \n",functionDeclaration->get_mangled_name().str());
4278 if (memberFunctionDeclaration != NULL)
4280 printf (
"memberFunctionDeclaration != NULL \n");
4283 ROSE_ASSERT(functionDeclaration->
isForward() ==
false);
4284 SgInitializedNamePtrList & argumentList = functionDeclaration->get_args();
4285 supportForVariableLists(scope,symbolTable,argumentList);
4298 supportForLabelStatements(scope,symbolTable);
4309 SgIfStmt* ifStatement = isSgIfStmt(scope);
4311 if (variableDeclarationCondition != NULL)
4316 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4322 case V_SgSwitchStatement:
4329 if (variableDeclarationSelector != NULL)
4334 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationSelector );
4346 SgWhileStmt* whileStatement = isSgWhileStmt(scope);
4348 if (variableDeclarationCondition != NULL)
4354 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4360 case V_SgCatchOptionStmt:
4361 case V_SgDoWhileStmt:
4370 case V_SgTemplateClassDefinition:
4372 case V_SgBasicBlock:
4373 case V_SgClassDefinition:
4374 case V_SgTemplateInstantiationDefn:
4376 case V_SgNamespaceDefinitionStatement:
4384 case V_SgJavaForEachStatement:
4387 SgVariableDeclaration* variableDeclarationCondition = isSgVariableDeclaration(javaForEachStatement->get_element());
4388 if (variableDeclarationCondition != NULL)
4394 supportForVariableDeclarations ( scope, symbolTable, variableDeclarationCondition );
4402 printf (
"Default reached in SageInterface::rebuildSymbolTable() scope = %p = %s \n",scope,scope->
class_name().c_str());
4408 printf (
"In SageInterface::rebuildSymbolTable(): fixup declarations in Symbol Table from %p = %s \n",scope,scope->
class_name().c_str());
4416 for (SgStatementPtrList::iterator i = statementList.begin(); i != statementList.end(); i++)
4423 if (declaration != NULL)
4429 list<SgSymbol*> symbolList;
4432 case V_SgTemplateInstantiationMemberFunctionDecl:
4436 if (scope == derivedDeclaration->
get_scope())
4439 ROSE_ASSERT(symbol != NULL);
4445 SgName name = derivedDeclaration->get_name();
4446 symbolTable->insert(name,symbol);
4457 ROSE_ASSERT(derivedDeclarationScope != NULL);
4464 ROSE_ASSERT(templateDeclaration != NULL);
4472 SgType* functionType = templateDeclaration->get_type();
4473 SgTemplateParameterPtrList & templateParameterList = templateDeclaration->get_templateParameters();
4476 if (templateSymbol != NULL)
4480 printf (
"Building a symbol for derivedDeclaration = %p = %s to an alternative symbol table in derivedDeclarationScope = %p \n",
4481 derivedDeclaration,
get_name(derivedDeclaration).c_str(),derivedDeclarationScope);
4484 ROSE_ASSERT(symbol != NULL);
4485 SgName name = derivedDeclaration->get_name();
4497 case V_SgTemplateMemberFunctionDeclaration:
4499 case V_SgMemberFunctionDeclaration:
4504 if (scope == derivedDeclaration->
get_scope())
4508 if (isSgTemplateFunctionDeclaration(declaration) != NULL)
4513 ROSE_ASSERT(symbol != NULL);
4517 SgName name = derivedDeclaration->get_name();
4518 symbolTable->insert(name,symbol);
4529 case V_SgTemplateInstantiationFunctionDecl:
4533 if (scope == derivedDeclaration->
get_scope())
4536 ROSE_ASSERT(symbol != NULL);
4537 SgName name = derivedDeclaration->get_name();
4538 symbolTable->insert(name,symbol);
4542 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4544#if PRINT_DEVELOPER_WARNINGS
4545 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4554 case V_SgTemplateFunctionDeclaration:
4556 case V_SgFunctionDeclaration:
4562 if (useThisDeclaration ==
true)
4564 if (scope == derivedDeclaration->
get_scope())
4569 if (isSgTemplateFunctionDeclaration(declaration) != NULL)
4574 ROSE_ASSERT(symbol != NULL);
4575 SgName name = derivedDeclaration->get_name();
4576 symbolTable->insert(name,symbol);
4580 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4582#if PRINT_DEVELOPER_WARNINGS
4583 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4592 case V_SgTemplateVariableDeclaration:
4594 case V_SgVariableDeclaration:
4597 SgInitializedNamePtrList & variableList = derivedDeclaration->
get_variables();
4598 SgInitializedNamePtrList::iterator i = variableList.begin();
4599 while ( i != variableList.end() )
4605 if (
variable->get_scope() == scope)
4608 ROSE_ASSERT(symbol != NULL);
4613 symbolTable->insert(name,symbol);
4630 ROSE_ASSERT(symbolTable != NULL);
4639 case V_SgTemplateInstantiationDecl:
4646 if (scope == derivedDeclaration->
get_scope())
4650 ROSE_ASSERT(symbol != NULL);
4651 SgName name = derivedDeclaration->get_name();
4654 if (scope != derivedDeclaration->
get_scope())
4656 printf (
"Error: scopes don't match for derivedDeclaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4658 ROSE_ASSERT(scope == derivedDeclaration->
get_scope());
4660 symbolTable->insert(name,symbol);
4666 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4668#if PRINT_DEVELOPER_WARNINGS
4669 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4675 ROSE_ASSERT(symbol != NULL);
4676 SgName name = derivedDeclaration->get_name();
4677 symbolTable->insert(name,symbol);
4684 case V_SgTemplateClassDeclaration:
4686 case V_SgClassDeclaration:
4690 if (scope == derivedDeclaration->
get_scope())
4693 if (isSgTemplateClassDeclaration(declaration) != NULL)
4698 ROSE_ASSERT(symbol != NULL);
4699 SgName name = derivedDeclaration->get_name();
4700 symbolTable->insert(name,symbol);
4704 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4706#if PRINT_DEVELOPER_WARNINGS
4707 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4713 ROSE_ASSERT(symbol != NULL);
4714 SgName name = derivedDeclaration->get_name();
4715 symbolTable->insert(name,symbol);
4720 case V_SgEnumDeclaration:
4723 ROSE_ASSERT(derivedDeclaration != NULL);
4725 ROSE_ASSERT(symbol != NULL);
4727 symbolTable->insert(name,symbol);
4730 SgInitializedNamePtrList & enumFieldList = derivedDeclaration->
get_enumerators();
4731 SgInitializedNamePtrList::iterator i = enumFieldList.begin();
4734 while (i != enumFieldList.end())
4737 ROSE_ASSERT(enum_field_symbol != NULL);
4738 SgName enum_field_name = (*i)->get_name();
4739 symbolTable->insert(enum_field_name,enum_field_symbol);
4749 case V_SgTemplateTypedefDeclaration:
4751 case V_SgTypedefDeclaration:
4755 ROSE_ASSERT(symbol != NULL);
4756 SgName name = derivedDeclaration->get_name();
4757 symbolTable->insert(name,symbol);
4759 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration \n");
4764 if (derivedDeclaration->get_typedefBaseTypeContainsDefiningDeclaration() ==
true)
4767 ROSE_ASSERT(symbolTable != NULL);
4770 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == true calling supportForBaseTypeDefiningDeclaration() \n");
4778 if (declaration != NULL)
4781 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == false calling supportForBaseTypeDefiningDeclaration() \n");
4786 printf (
"In SageInterface::rebuildSymbolTable(): case of SgTypedefDeclaration: typedefBaseTypeContainsDefiningDeclaration == false: skipping call to supportForBaseTypeDefiningDeclaration() \n");
4790 printf (
"In SageInterface::rebuildSymbolTable(): Leaving case of SgTypedefDeclaration \n");
4795 case V_SgTemplateDeclaration:
4801 printf (
"case V_SgTemplateDeclaration: derivedDeclaration = %p \n",derivedDeclaration);
4802 printf (
"case V_SgTemplateDeclaration: derivedDeclaration->get_declarationModifier().isFriend() = %s \n",derivedDeclaration->get_declarationModifier().
isFriend() ?
"true" :
"false");
4803 printf (
"case V_SgTemplateDeclaration: derivedDeclaration->get_name() = %s \n",derivedDeclaration->
get_name().str());
4804 printf (
"case V_SgTemplateDeclaration: derivedDeclaration->get_string() = %s \n",derivedDeclaration->
get_string().str());
4806 if (scope == derivedDeclaration->
get_scope())
4809 ROSE_ASSERT(symbol != NULL);
4811 symbolTable->insert(name,symbol);
4815 if (derivedDeclaration->get_declarationModifier().
isFriend() ==
false)
4817#if PRINT_DEVELOPER_WARNINGS
4818 printf (
"Shouldn't this be a friend declaration = %p = %s \n",derivedDeclaration,derivedDeclaration->
class_name().c_str());
4825 ROSE_ASSERT(symbol != NULL);
4827 symbolTable->insert(name,symbol);
4834 case V_SgNamespaceAliasDeclarationStatement:
4837 ROSE_ASSERT(aliasDeclaration != NULL);
4841 ROSE_ASSERT(derivedDeclaration != NULL);
4845 ROSE_ASSERT(symbol != NULL);
4847 symbolTable->insert(name,symbol);
4855 case V_SgNamespaceDeclarationStatement:
4858 ROSE_ASSERT(derivedDeclaration != NULL);
4862 ROSE_ASSERT(symbol != NULL);
4864 symbolTable->insert(name,symbol);
4870 case V_SgUsingDirectiveStatement:
4871 case V_SgPragmaDeclaration:
4872 case V_SgTemplateInstantiationDirectiveStatement:
4873 case V_SgUsingDeclarationStatement:
4877 printf (
"This declaration is ignored in rebuilding symbol table %p = %s = %s \n",*i,(*i)->class_name().c_str(),
get_name(*i).c_str());
4886 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());
4892 case V_SgVariableDefinition:
4893 case V_SgFunctionParameterList:
4894 case V_SgCtorInitializerList:
4897 printf (
"Special cases not handled %p = %s = %s \n",*i,(*i)->class_name().c_str(),
get_name(*i).c_str());
4901 case V_SgStaticAssertionDeclaration:
4905 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());
4912 printf (
"Error: Default reached in rebuildSymbolTable declaration = %p = %s \n",declaration,declaration->
class_name().c_str());
4917 ROSE_ASSERT(symbolTable != NULL);
4918 ROSE_ASSERT(symbolTable->get_table() != NULL);
4924 ROSE_ASSERT(symbolTable != NULL);
4925 ROSE_ASSERT(symbolTable->get_table() != NULL);
4928 printf (
"Leaving SageInterface::rebuildSymbolTable(): fixup declarations in Symbol Table from %p = %s \n",scope,scope->
class_name().c_str());
4932 printf (
"Symbol Table from %p = %s at: \n",scope,scope->
class_name().c_str());
4934 symbolTable->
print(
"Called from SageInterface::rebuildSymbolTable()");
4949#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
4950 ROSE_ASSERT(this_scope != NULL);
4951 ROSE_ASSERT(copy_scope != NULL);
4954 printf (
"In fixupReferencesToSymbols(this_scope = %p = %s = %s, copy_scope = %p = %s = %s) \n",
4962 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());
4963 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());
4969 if (this_symbolTable->get_table()->size() != copy_symbolTable->get_table()->size())
4973 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());
4974 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());
4975 printf (
"Warning the symbols tables in these different scopes are different sizes \n");
4980 SgSymbolTable::hash_iterator i = this_symbolTable->get_table()->begin();
4983 std::map<SgNode*, SgNode*> replacementMap;
4985 while (i != this_symbolTable->get_table()->end())
4987 ROSE_ASSERT ( isSgSymbol( (*i).second ) != NULL );
4989 SgName name = (*i).first;
4992 ROSE_ASSERT ( symbol != NULL );
4994 SgSymbol* associated_symbol = NULL;
4996 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());
4999 SgSymbolTable::hash_iterator associated_symbol_iterator = copy_symbolTable->get_table()->find(name);
5004 while (associated_symbol_iterator != copy_symbolTable->get_table()->end() && associated_symbol_iterator->first == name)
5006 if ( associated_symbol_iterator->second->variantT() == symbol->
variantT() )
5008 associated_symbol = associated_symbol_iterator->second;
5011 associated_symbol_iterator++;
5014 if (associated_symbol != NULL)
5016 ROSE_ASSERT ( associated_symbol != NULL );
5019 ROSE_ASSERT(copy_scope->symbol_exists(associated_symbol) ==
true);
5024 replacementMap.insert(pair<SgNode*,SgNode*>(symbol,associated_symbol));
5031 help.get_copiedNodeMap().insert(pair<const SgNode*,SgNode*>(symbol,associated_symbol));
5038 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());
5039 printf (
"Warning: associated_symbol == NULL, need to investigate this (ignoring for now) \n");
5049 printf (
"\n\n************************************************************\n");
5050 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());
5056 printf (
"fixupReferencesToSymbols(): calling Utils::edgePointerReplacement(): DONE \n");
5057 printf (
"************************************************************\n\n");
5059 printf (
"\n\n After replacementMapTraversal(): intermediateDeleteSet: \n");
5060 displaySet(intermediateDeleteSet,
"After Utils::edgePointerReplacement");
5062 printf (
"After fixup: this_symbolTable->get_table()->size() = %" PRIuPTR
" \n",this_symbolTable->get_table()->size());
5063 printf (
"After fixup: copy_symbolTable->get_table()->size() = %" PRIuPTR
" \n",copy_symbolTable->get_table()->size());
5072 printf (
"Exiting as a test in fixupReferencesToSymbols() \n");
5088 vector<SgFile*> fileList;
5089 void visit (
SgNode* node)
5091 SgFile* file = isSgFile(node);
5092 ROSE_ASSERT(file != NULL);
5095 fileList.push_back(file);
5099 virtual ~FileTraversal() {}
5102 FileTraversal fileTraversal;
5107#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5118 return fileTraversal.fileList;
5136 void visit (
SgNode* node)
5138 project = isSgProject(node);
5139 ROSE_ASSERT(project!= NULL);
5141 virtual ~ProjectTraversal() {}
5144 ProjectTraversal projectTraversal;
5146 return projectTraversal.project;
5148 std::vector<SgProject* > resultlist = getSgNodeListFromMemoryPool<SgProject>();
5149 if (resultlist.empty())
5151 ROSE_ASSERT(resultlist.size()==1);
5152 return resultlist[0];
5157 return getEnclosingNode<SgProject>(node,
true );
5162 if (isSgFunctionRefExp(func))
5164 return isSgFunctionRefExp(func)->get_symbol()->get_declaration();
5166 else if (isSgDotExp(func) || isSgArrowExp(func))
5169 if (isSgMemberFunctionRefExp(func2))
5170 return isSgMemberFunctionRefExp(func2)->get_symbol()->get_declaration();
5173 cerr<<
"Warning in SageInterface::getDeclarationOfNamedFunction(): rhs operand of dot or arrow operations is not a member function, but a "<<func2->
class_name()<<endl;
5182 const SgExpressionPtrList& ls = el->get_expressions();
5183 if (ls.empty())
return 0;
5184 if (isSgAssignOp(ls.back()))
return 0;
5191 ASSERT_not_null(astNode);
5192 Rose_STL_Container<SgNode*> arr_exp_list = NodeQuery::querySubTree(astNode,V_SgPntrArrRefExp);
5193 for (
SgNode* expr : arr_exp_list)
5196 ASSERT_not_null(arr_exp);
5197 Rose_STL_Container<SgNode*> refList = NodeQuery::querySubTree(arr_exp->
get_lhs_operand(),V_SgVarRefExp);
5198 for (
SgNode* ref : refList)
5201 ASSERT_not_null(cur_ref);
5203 ASSERT_not_null(sym);
5205 ASSERT_not_null(iname);
5206 SgArrayType * a_type = isSgArrayType(iname->get_typeptr());
5207 if (a_type && a_type->get_dim_info())
5209 Rose_STL_Container<SgNode*> dim_ref_list = NodeQuery::querySubTree(a_type->get_dim_info(),V_SgVarRefExp);
5210 for (Rose_STL_Container<SgNode*>::iterator iter2 = dim_ref_list.begin(); iter2 != dim_ref_list.end(); iter2++)
5213 NodeList_t.push_back(dim_ref);
5223#if (INLINE_OPTIMIZED_IS_LANGUAGE_KIND_FUNCTIONS == 0)
5227#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5229 return Rose::is_Ada_language;
5231 bool returnValue =
false;
5235 int size = (int)fileList.size();
5236 for (
int i = 0; i < size; i++)
5238 if (fileList[i]->get_Ada_only() ==
true)
5249#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5251 return Rose::is_C_language;
5253 bool returnValue =
false;
5257 int size = (int)fileList.size();
5258 for (
int i = 0; i < size; i++)
5260 if (fileList[i]->get_C_only() ==
true)
5271#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5273 return Rose::is_OpenMP_language;
5275 bool returnValue =
false;
5279 int size = (int)fileList.size();
5280 for (
int i = 0; i < size; i++)
5282 if (fileList[i]->get_openmp() ==
true)
5293#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5295 return Rose::is_UPC_language;
5297 bool returnValue =
false;
5301 int size = (int)fileList.size();
5302 for (
int i = 0; i < size; i++)
5304 if (fileList[i]->get_UPC_only() ==
true)
5316#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5318 return Rose::is_CAF_language;
5320 bool returnValue =
false;
5324 int size = (int)fileList.size();
5325 for (
int i = 0; i < size; i++)
5327 if (fileList[i]->get_CoArrayFortran_only()==
true)
5340#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5342 return Rose::is_UPC_dynamic_threads;
5344 bool returnValue =
false;
5348 int size = (int)fileList.size();
5349 for (
int i = 0; i < size; i++)
5351 if (fileList[i]->get_upc_threads() > 0)
5364#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5366 return Rose::is_C99_language;
5368 bool returnValue =
false;
5372 int size = (int)fileList.size();
5373 for (
int i = 0; i < size; i++)
5375 if (fileList[i]->get_C99_only() ==
true)
5386#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5388 return Rose::is_Cxx_language;
5390 bool returnValue =
false;
5394 int size = (int)fileList.size();
5395 for (
int i = 0; i < size; i++)
5398 if (fileList[i]->get_Cxx_only() ==
true)
5400 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);
5413#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5415 return Rose::is_Java_language;
5417 bool returnValue =
false;
5421 int size = (int)fileList.size();
5422 for (
int i = 0; i < size; i++)
5424 if (fileList[i]->get_Java_only() ==
true)
5435#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5437 return Rose::is_Jvm_language;
5439 bool returnValue =
false;
5443 int size = (int)fileList.size();
5444 for (
int i = 0; i < size; i++)
5446 if (fileList[i]->get_Jvm_only() ==
true)
5458#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5460 return Rose::is_Jovial_language;
5462 bool returnValue =
false;
5466 int size = (int)fileList.size();
5467 for (
int i = 0; i < size; i++)
5469 if (fileList[i]->get_Jovial_only() ==
true)
5481#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5483 return Rose::is_Fortran_language;
5485 bool returnValue =
false;
5489 int size = (int)fileList.size();
5490 for (
int i = 0; i < size; i++)
5492 if (fileList[i]->get_Fortran_only() ==
true)
5504#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5506 return Rose::is_binary_executable;
5508 bool returnValue =
false;
5512 int size = (int)fileList.size();
5513 for (
int i = 0; i < size; i++)
5515 if (fileList[i]->get_binary_only() ==
true)
5526#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5528 return Rose::is_PHP_language;
5530 bool returnValue =
false;
5534 int size = (int)fileList.size();
5535 for (
int i = 0; i < size; i++)
5537 if (fileList[i]->get_PHP_only() ==
true)
5548#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5550 return Rose::is_Python_language;
5552 bool returnValue =
false;
5556 int size = (int)fileList.size();
5557 for (
int i = 0; i < size; i++)
5559 if (fileList[i]->get_Python_only() ==
true)
5570#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5572 return Rose::is_Cuda_language;
5574 bool returnValue =
false;
5578 int size = (int)fileList.size();
5579 for (
int i = 0; i < size; i++)
5581 if (fileList[i]->get_Cuda_only() ==
true)
5592#if OPTIMIZE_IS_LANGUAGE_KIND_FUNCTIONS
5594 return Rose::is_OpenCL_language;
5596 bool returnValue =
false;
5600 int size = (int)fileList.size();
5601 for (
int i = 0; i < size; i++)
5603 if (fileList[i]->get_OpenCL_only() ==
true)
5651 ASSERT_not_null(functionDefinition);
5652 std::map<SgNode*,int> & scopeMap = functionDefinition->get_scope_number_list();
5655 scopeMap.erase(scopeMap.begin(),scopeMap.end());
5657 ASSERT_require(scopeMap.empty() ==
true);
5658 ASSERT_require(functionDefinition->get_scope_number_list().empty() ==
true);
5668 ROSE_ASSERT(functionDefinition != NULL);
5671 ROSE_ASSERT(functionDefinition->get_scope_number_list().empty() ==
true);
5677 ScopeNumberingTraversal() : count (0), storedFunctionDefinition(NULL) {}
5678 void visit (
SgNode* node)
5685 if (testFunctionDefinition != NULL && storedFunctionDefinition == NULL)
5687 ROSE_ASSERT(storedFunctionDefinition == NULL);
5688 storedFunctionDefinition = testFunctionDefinition;
5692 ROSE_ASSERT(storedFunctionDefinition != NULL);
5696 std::map<SgNode*,int> & scopeMap = storedFunctionDefinition->get_scope_number_list();
5697 scopeMap.insert(pair<SgNode*,int>(scope,count));
5699 string functionName = storedFunctionDefinition->get_declaration()->get_name().str();
5700 printf (
"In function = %s insert scope = %p = %s with count = %d into local map (size = %d) \n",
5701 functionName.c_str(),scope,scope->
class_name().c_str(),count,scopeMap.size());
5712 ScopeNumberingTraversal traversal;
5713 traversal.traverse(functionDefinition, preorder);
5727 ROSE_ASSERT(globalScope != NULL);
5728 std::map<SgNode*,std::string> & mangledNameCache = globalScope->get_mangledNameCache();
5731 mangledNameCache.erase(mangledNameCache.begin(),mangledNameCache.end());
5733 ROSE_ASSERT(mangledNameCache.empty() ==
true);
5734 ROSE_ASSERT(globalScope->get_mangledNameCache().empty() ==
true);
5742 ROSE_ASSERT(globalScope != NULL);
5743 ROSE_ASSERT(globalScope->get_mangledNameCache().empty() ==
true);
5749 MangledNameTraversal() : storedGlobalScope(NULL) {}
5750 void visit (
SgNode* node)
5753 if ( (mangleableNode != NULL) || (isSgGlobal(node) != NULL) )
5756 SgGlobal* testGlobalScope = isSgGlobal(mangleableNode);
5757 if (testGlobalScope != NULL && storedGlobalScope == NULL)
5759 ROSE_ASSERT(storedGlobalScope == NULL);
5760 storedGlobalScope = testGlobalScope;
5764 ROSE_ASSERT(storedGlobalScope != NULL);
5766 string mangledName = mangleableNode->get_mangled_name();
5769 std::map<SgNode*,std::string> & mangledNameCache = storedGlobalScope->get_mangledNameCache();
5770 mangledNameCache.insert(pair<SgNode*,std::string>(mangleableNode,mangledName));
5772 string nodeName =
get_name(mangleableNode);
5773 printf (
"At node = %p = %s = %s in local map (size = %d) \n",
5774 mangleableNode,mangleableNode->
class_name().c_str(),nodeName.c_str(),mangledNameCache.size());
5784 MangledNameTraversal traversal;
5785 traversal.traverse(globalScope, preorder);
5797 SgGlobal* globalScope = isSgGlobal(astNode);
5799 if (globalScope == NULL && isSgFile(astNode) != NULL)
5801 globalScope = isSgFile(astNode)->get_globalScope();
5802 ROSE_ASSERT(globalScope != NULL);
5805 if (globalScope == NULL && isSgProject(astNode) != NULL)
5808 ROSE_ASSERT( isSgProject(astNode)->get_fileList()->size() == 1 );
5809 globalScope = isSgProject(astNode)->get_fileList()->operator[](0)->get_globalScope();
5810 ROSE_ASSERT(globalScope != NULL);
5814 while (temp->
get_parent() != NULL && globalScope == NULL)
5817 globalScope = isSgGlobal(temp);
5819 ROSE_ASSERT(globalScope != NULL);
5826 std::map<SgNode*,std::string>::iterator i = mangledNameCache.find(astNode);
5829 if (i != mangledNameCache.end())
5833 mangledName = i->second;
5844#define DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE 0
5845#define DEBUG_MANGLED_SHORTNAME 1
5854#if DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE
5855 printf (
"In SageInterface::addMangledNameToCache(): TOP: astNode = %p = %s oldMangledName = %s \n",astNode,astNode->
class_name().c_str(),oldMangledName.c_str());
5859#ifdef DEBUG_MANGLED_SHORTNAME
5860 static std::unordered_map<uint64_t, std::string> mangledNameHashCollisionCheckMap;
5865 SgGlobal* globalScope = isSgGlobal(astNode);
5867 if (globalScope == NULL && isSgFile(astNode) != NULL)
5869 globalScope = isSgFile(astNode)->get_globalScope();
5870 ROSE_ASSERT(globalScope != NULL);
5873 if (globalScope == NULL && isSgProject(astNode) != NULL)
5876 ROSE_ASSERT( isSgProject(astNode)->get_fileList()->size() == 1 );
5877 globalScope = isSgProject(astNode)->get_fileList()->operator[](0)->get_globalScope();
5878 ROSE_ASSERT(globalScope != NULL);
5882 while (temp->
get_parent() != NULL && globalScope == NULL)
5885 globalScope = isSgGlobal(temp);
5887 ROSE_ASSERT(globalScope != NULL);
5892 std::string mangledName;
5894 if (SgProject::get_mangled_noshortname() ==
false) {
5897 if (oldMangledName.size() > 40) {
5898 std::map<std::string, uint64_t>::const_iterator shortMNIter = shortMangledNameCache.find(oldMangledName);
5899 uint64_t idNumber = 0;
5900 if (shortMNIter != shortMangledNameCache.end())
5902 idNumber = shortMNIter->second;
5904#ifdef DEBUG_MANGLED_SHORTNAME
5906 auto collisionIt = mangledNameHashCollisionCheckMap.find(idNumber);
5907 if(collisionIt != mangledNameHashCollisionCheckMap.end() &&
5908 oldMangledName != shortMNIter->first)
5910 mlog[Sawyer::Message::Common::ERROR] <<
" Got a short mangled name collision. \n "<<
5911 oldMangledName <<
" and \n " << shortMNIter->first <<
" \n" <<
5915 mangledNameHashCollisionCheckMap[idNumber] = oldMangledName;
5923 hasher.
insert(oldMangledName);
5925 idNumber = hasher.
toU64();
5926 shortMangledNameCache.insert(std::pair<std::string, uint64_t>(oldMangledName, idNumber));
5929 std::ostringstream mn;
5931 mangledName = mn.str();
5933 mangledName = oldMangledName;
5944 static unsigned long counter = 0;
5948 if (counter++ % 500 == 0)
5950 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");
5952 mangledName = oldMangledName;
5959 printf (
"Updating mangled name cache for node = %p = %s with mangledName = %s \n",astNode,astNode->
class_name().c_str(),mangledName.c_str());
5962#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
5968 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",
5969 statement,statement->
class_name().c_str(),oldMangledName.c_str());
5974 mangledNameCache.insert(pair<SgNode*,string>(astNode,mangledName));
5976#if DEBUG_SAGE_INTERFACE_ADD_MANGLED_TO_CACHE
5977 printf (
"In SageInterface::addMangledNameToCache(): returning mangledName = %s \n",mangledName.c_str());
6001 : storedNondefiningDeclaration(nonDefiningDeclaration),
6002 storedDefiningDeclaration(definingDeclaration)
6004 storedDeclarationFound =
false;
6005 nonDefiningDeclarationPreceedsDefiningDeclaration =
false;
6008 void visit (
SgNode* node)
6010 ROSE_ASSERT(storedNondefiningDeclaration != NULL);
6011 ROSE_ASSERT(storedDefiningDeclaration != NULL);
6012 ROSE_ASSERT(storedNondefiningDeclaration != storedDefiningDeclaration);
6020 if ( declaration != NULL )
6022 if (storedDeclarationFound ==
false)
6024 if (declaration == storedDefiningDeclaration)
6026 storedDeclarationFound =
true;
6027 nonDefiningDeclarationPreceedsDefiningDeclaration =
false;
6029 if (declaration == storedNondefiningDeclaration)
6031 storedDeclarationFound =
true;
6032 nonDefiningDeclarationPreceedsDefiningDeclaration =
true;
6039 bool storedDeclarationFound;
6040 bool nonDefiningDeclarationPreceedsDefiningDeclaration;
6047 ROSE_ASSERT(nonDefiningDeclaration != NULL);
6049 printf (
"In SageInterface::declarationPreceedsDefinition(): \n");
6050 printf (
" nondefiningDeclaration = %p = %s \n",nonDefiningDeclaration,nonDefiningDeclaration->
class_name().c_str());
6051 nonDefiningDeclaration->
get_file_info()->display(
"nonDefiningDeclaration");
6052 printf (
" nondefiningDeclaration->get_definingDeclaration() = %p \n",nonDefiningDeclaration->
get_definingDeclaration());
6053 printf (
" definingDeclaration = %p = %s \n",definingDeclaration,definingDeclaration->
class_name().c_str());
6054 definingDeclaration->
get_file_info()->display(
"definingDeclaration");
6055 printf (
"************************************************************* \n");
6062 printf (
"In SageInterface::declarationPreceedsDefinition() (warning): \n");
6063 printf (
" nondefiningDeclaration = %p \n",nonDefiningDeclaration);
6064 printf (
" nondefiningDeclaration->get_definingDeclaration() = %p \n",nonDefiningDeclaration->
get_definingDeclaration());
6065 printf (
" definingDeclaration = %p \n",definingDeclaration);
6070 bool returnResult =
false;
6071 if (nonDefiningDeclaration != definingDeclaration)
6074 SgGlobal* globalScope = TransformationSupport::getGlobalScope(definingDeclaration);
6075 ROSE_ASSERT(globalScope != NULL);
6078 DeclarationOrderTraversal traversal (nonDefiningDeclaration,definingDeclaration);
6081 traversal.traverse(globalScope, preorder);
6084 printf (
"Skipping traversal within SageInterface::declarationPreceedsDefinition() \n");
6085 traversal.storedDeclarationFound =
true;
6086 traversal.nonDefiningDeclarationPreceedsDefiningDeclaration =
false;
6093 if (traversal.storedDeclarationFound ==
false)
6096 printf (
"In SageInterface::declarationPreceedsDefinition(): warning, nonDefiningDeclaration not found in the AST \n");
6097 nonDefiningDeclaration->
get_file_info()->display(
"nonDefiningDeclaration");
6098 definingDeclaration->
get_file_info()->display(
"definingDeclaration");
6099 printf (
"---------------------------------------------------- \n\n");
6103 returnResult =
true;
6107 returnResult = traversal.nonDefiningDeclarationPreceedsDefiningDeclaration;
6113 printf (
"returnResult = %s \n",returnResult ?
"true" :
"false");
6114 printf (
"************************************************************* \n\n");
6116 return returnResult;
6133 : storedFunctionCall(functionCall)
6135 ROSE_ASSERT(functionCall != NULL);
6136 ROSE_ASSERT(functionCall->get_function() != NULL);
6137 SgExpression* functionExpression = functionCall->get_function();
6139 switch (functionExpression->
variantT())
6145 case V_SgArrowStarOp:
6146 case V_SgPointerDerefExp:
6149 printf (
"These are the acceptable cases, but not handled yet... \n");
6153 case V_SgFunctionRefExp:
6156 ROSE_ASSERT(functionRefExp != NULL);
6158 ROSE_ASSERT(functionSymbol != NULL);
6161 ROSE_ASSERT(functionSymbol->get_declaration() != NULL);
6162 storedFunctionDeclaration = functionSymbol->get_declaration();
6166 case V_SgMemberFunctionRefExp:
6169 ROSE_ASSERT(memberFunctionRefExp != NULL);
6171 ROSE_ASSERT(memberFunctionSymbol != NULL);
6173 storedFunctionDeclaration = memberFunctionSymbol->get_declaration();
6175 printf (
"V_SgMemberFunctionRefExp case not handled yet... \n");
6181 printf (
"default reached in SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope() functionExpression = %s \n",
6189 ROSE_ASSERT(storedFunctionDeclaration != NULL);
6191 storedFunctionCallFound =
false;
6195 void visit (
SgNode* node)
6197 ROSE_ASSERT(storedFunctionCall != NULL);
6198 ROSE_ASSERT(storedFunctionDeclaration != NULL);
6201 if (storedFunctionCallFound ==
false)
6204 if ( functionCall != NULL )
6206 if (functionCall == storedFunctionCall)
6208 storedFunctionCallFound =
true;
6218 ROSE_ASSERT(storedFunctionDeclaration != NULL);
6231 storedFunctionCallFound =
true;
6237 printf (
"Found a declaration which preceeds the function \n");
6238 declaration->
get_file_info()->display(
"Found a declaration which preceeds the function: declaration");
6239 storedFunctionCall->get_file_info()->display(
"Found a declaration which preceeds the function: storedFunctionCall");
6240 storedFunctionDeclaration->get_file_info()->display(
"Found a declaration which preceeds the function: storedFunctionDeclaration");
6246 if (parentScopeOfDeclaration == NULL)
6249 printf (
"Strange case of parentScopeOfDeclaration == NULL in SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope() \n");
6251 if (parent != NULL) {
6252 printf (
"declaration->get_parent() = %s \n",parent->
class_name().c_str());
6255 printf (
"declaration->get_parent() = NULL \n");
6257 declaration->
get_file_info()->display(
"case of parentScopeOfDeclaration == NULL");
6266 bool storedFunctionCallFound;
6274 ROSE_ASSERT(functionCall != NULL);
6276 printf (
"In SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope(): \n");
6277 printf (
" storedFunctionCall = %p = %s \n",functionCall,functionCall->
class_name().c_str());
6278 functionCall->
get_file_info()->display(
"storedFunctionCall");
6279 printf (
" storedFunctionCall->get_function() = %p = %s \n",functionCall->get_function(),functionCall->get_function()->
class_name().c_str());
6280 printf (
"************************************************************* \n");
6284 bool returnResult =
false;
6287 SgGlobal* globalScope = TransformationSupport::getGlobalScope(functionCall);
6288 ROSE_ASSERT(globalScope != NULL);
6291 DeclarationOrderTraversal traversal (functionCall);
6294 traversal.traverse(globalScope, preorder);
6297 printf (
"Skipping traversal within SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope() \n");
6298 traversal.storedFunctionCallFound =
true;
6299 traversal.functionCallExpressionPreceedsDeclarationWhichAssociatesScope =
false;
6306 if (traversal.storedFunctionCallFound ==
false)
6309 printf (
"In SageInterface::functionCallExpressionPreceedsDeclarationWhichAssociatesScope(): warning, storedFunctionCall not found in the AST \n");
6311 printf (
"---------------------------------------------------- \n\n");
6316 returnResult =
true;
6320 returnResult = traversal.functionCallExpressionPreceedsDeclarationWhichAssociatesScope;
6324 ROSE_ASSERT(traversal.storedFunctionCallFound ==
true);
6326 printf (
"returnResult = %s \n",returnResult ?
"true" :
"false");
6327 printf (
"************************************************************* \n\n");
6329 return returnResult;
6350 ROSE_ASSERT(project != NULL);
6357 Rose_STL_Container<string>::iterator i = fileList.begin();
6360 if ( fileList.empty() ==
true )
6362 return "empty_file_list";
6366 string filename = *i;
6372 if (i != fileList.begin())
6373 projectName +=
"--";
6377 string filenameWithoutSuffix;
6378 if ( i != fileList.end() || supressSuffix ==
true )
6381 filenameWithoutSuffix = filename;
6388 filename = filenameWithoutPathOrSuffix;
6390 unsigned long int n = 0;
6391 while (n < filename.size())
6393 if (filename[n] ==
'/')
6400 projectName += filename;
6404 while (i != fileList.end());
6423 if (currentScope == NULL)
6425 ROSE_ASSERT(currentScope != NULL);
6428 while ((functionSymbol == NULL) && (tempScope != NULL))
6430 functionSymbol = tempScope->lookup_function_symbol(functionName);
6432 printf (
"In lookupFunctionSymbolInParentScopes(): Searching scope = %p = %s functionName = %s functionSymbol = %p \n",tempScope,tempScope->
class_name().c_str(),functionName.str(),functionSymbol);
6435 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6439 return functionSymbol;
6450 if (currentScope == NULL)
6452 ROSE_ASSERT(currentScope != NULL);
6455 while ((functionSymbol == NULL) && (tempScope != NULL))
6457 functionSymbol = tempScope->lookup_template_function_symbol(functionName, ftype, tplparams);
6459 printf (
"In lookupTemplateFunctionSymbolInParentScopes(): Searching scope = %p = %s functionName = %s functionSymbol = %p \n",tempScope,tempScope->
class_name().c_str(),functionName.str(),functionSymbol);
6462 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6466 return functionSymbol;
6477 if (currentScope == NULL)
6479 ROSE_ASSERT(currentScope != NULL);
6482 while ((functionSymbol == NULL) && (tempScope != NULL))
6484 functionSymbol = tempScope->lookup_template_member_function_symbol(functionName, ftype, tplparams);
6486 printf (
"In lookupTemplateMemberFunctionSymbolInParentScopes(): Searching scope = %p = %s functionName = %s functionSymbol = %p \n",tempScope,tempScope->
class_name().c_str(),functionName.str(),functionSymbol);
6489 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6493 return functionSymbol;
6501 if (isSgType(astNode) != NULL)
6503 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");
6507 if (astNode->
attributeExists(AstUnparseAttribute::markerName) ==
true)
6509 AstUnparseAttribute* code =
dynamic_cast<AstUnparseAttribute*
>(astNode->
getAttribute(AstUnparseAttribute::markerName));
6510 ROSE_ASSERT(code != NULL);
6514 code->addString(s,inputlocation);
6523 AstUnparseAttribute* code =
new AstUnparseAttribute(s,inputlocation);
6524 ROSE_ASSERT(code != NULL);
6541 ROSE_ASSERT(cscope != NULL);
6543 while ((cscope != NULL) && (symbol == NULL))
6546 symbol = cscope->lookup_class_symbol(name,NULL);
6549 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6580 if (currentScope == NULL)
6582 ROSE_ASSERT(currentScope != NULL);
6584 while (functionSymbol == NULL && tempScope != NULL)
6586 functionSymbol = tempScope->lookup_function_symbol(functionName,t);
6588 tempScope = isSgGlobal(tempScope) ? NULL : tempScope->
get_scope();
6589 else tempScope = NULL;
6591 return functionSymbol;
6598 if (cscope ==
nullptr) {
6601 ASSERT_not_null(cscope);
6603 while ((cscope !=
nullptr) && (symbol ==
nullptr))
6605 symbol = cscope->lookup_symbol(name,templateParameterList,templateArgumentList);
6607 cscope = isSgGlobal(cscope) ? nullptr : cscope->
get_scope();
6626#define USING_PERFORMANCE_TRACING 0
6630#if USING_PERFORMANCE_TRACING
6632 TimingPerformance timer1 (
"SageInterface::lookupSymbolInParentScopesIgnoringAliasSymbols: whole function:");
6635 if (currentScope == NULL)
6640 ROSE_ASSERT(currentScope != NULL);
6642#define DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS 0
6644#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6645 printf (
"In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): currentScope = %p = %s (templateParameterList = %p templateArgumentList = %p) \n",
6646 currentScope,currentScope->
class_name().c_str(),templateParameterList,templateArgumentList);
6649 while ((currentScope != NULL) && (symbol == NULL))
6651#if USING_PERFORMANCE_TRACING
6653 TimingPerformance timer1 (
"SageInterface::lookupSymbolInParentScopesIgnoringAliasSymbols: in loop:");
6656#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6657 printf(
" --- In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): name = %s currentScope = %p = %s \n",
6658 name.str(),currentScope,currentScope->
class_name().c_str());
6663 symbol = currentScope->lookup_symbol(name,templateParameterList,templateArgumentList);
6665 if (isSgAliasSymbol(symbol) != NULL)
6667#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6668 printf (
"Found a SgAliasSymbol: reset to NULL: symbol = %p = %s \n",symbol,symbol->
class_name().c_str());
6673#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS && 1
6675 printf(
" --- In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): symbol = %p \n",symbol);
6676 currentScope->print_symboltable(
"In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): debug");
6679 currentScope = isSgGlobal(currentScope) ? NULL : currentScope->
get_scope();
6681 currentScope = NULL;
6683#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6684 printf (
" --- In SageInterface:: (base of loop) lookupSymbolInParentScopesIgnoringAliasSymbols(): cscope = %p symbol = %p \n\n",currentScope,symbol);
6690#if DEBUG_SYMBOL_LOOKUP_IN_PARENT_SCOPES_IGNORING_ALIAS_SYMBOLS
6691 printf (
"Warning: In SageInterface:: lookupSymbolInParentScopesIgnoringAliasSymbols(): could not locate the specified name %s in any outer symbol table (templateParameterList = %p templateArgumentList = %p) \n",
6692 name.str(),templateParameterList,templateArgumentList);
6698 printf (
"Support for lookupSymbolInParentScopesIgnoringAliasSymbols() is not yet implemented \n");
6720 ROSE_ASSERT(cscope);
6722 while ((cscope!=NULL)&&(symbol==NULL))
6724 symbol = cscope->lookup_symbol(name);
6728 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6754 printf (
"WARNING: SageInterface::lookupVariableSymbolInParentScopes() should be implemented similar to SageInterface::lookupClassSymbolInParentScopes() \n");
6760 if (isSgAliasSymbol(symbol) != NULL)
6762 printf (
"Error: This SageInterface::lookupVariableSymbolInParentScopes() function does not handle SgAliasSymbols \n");
6765 result = isSgVariableSymbol(symbol);
6773 ROSE_ASSERT(cscope != NULL);
6775 while ((cscope != NULL) && (symbol == NULL))
6778 symbol = cscope->lookup_variable_symbol(name);
6781 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6790#define DEBUG_LOOKUP_TEMPLATE_VARIABLE 0
6795#if DEBUG_LOOKUP_TEMPLATE_VARIABLE
6796 printf (
"In SageInterface::lookupTemplateVariableSymbolInParentScopes():\n");
6797 printf (
" -- name = %s\n", name.str());
6798 printf (
" -- tplparams = %p [%zd]\n", tplparams, tplparams ? tplparams->size() : 0);
6799 printf (
" -- tplargs = %p [%zd]\n", tplargs, tplargs ? tplargs->size() : 0);
6800 printf (
" -- cscope = %p (%s)\n", cscope, cscope ? cscope->
class_name().c_str() :
"");
6806 ROSE_ASSERT(cscope != NULL);
6808 while ((cscope != NULL) && (symbol == NULL))
6811 symbol = cscope->lookup_template_variable_symbol(name, tplparams, tplargs);
6814 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6830 ROSE_ASSERT(cscope != NULL);
6832 while ((cscope != NULL) && (symbol == NULL))
6836 symbol = cscope->lookup_class_symbol(name,templateArgumentList);
6839 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6853 ROSE_ASSERT(cscope != NULL);
6855 while ((cscope != NULL) && (symbol == NULL))
6857 symbol = cscope->lookup_nonreal_symbol(name,templateParameterList,templateArgumentList);
6860 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6875 ROSE_ASSERT(cscope != NULL);
6878 printf (
"In lookupTypedefSymbolInParentScopes(): name = %s starting with cscope = %p = %s \n",name.str(),cscope,cscope->
class_name().c_str());
6882 while ((cscope != NULL) && (symbol == NULL))
6885 symbol = cscope->lookup_typedef_symbol(name);
6888 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6893 printf (
"In lookupTypedefSymbolInParentScopes(): symbol = %p next cscope = %p = %s \n",symbol,cscope,(cscope != NULL) ? cscope->
class_name().c_str() :
"null");
6898 printf (
"Leaving lookupTypedefSymbolInParentScopes(): symbol = %p \n",symbol);
6916 ROSE_ASSERT(cscope != NULL);
6918 while ((cscope != NULL) && (symbol == NULL))
6924 symbol = cscope->lookup_template_symbol(name,NULL,NULL);
6926 printf (
"In lookupTemplateSymbolInParentScopes(): Searching scope = %p = %s name = %s symbol = %p \n",cscope,cscope->
class_name().c_str(),name.str(),symbol);
6929 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6946 ROSE_ASSERT(cscope != NULL);
6948 while ((cscope != NULL) && (symbol == NULL))
6954 symbol = cscope->lookup_template_class_symbol(name,templateParameterList,templateArgumentList);
6956 printf (
"In lookupTemplateSymbolInParentScopes(): Searching scope = %p = %s name = %s symbol = %p \n",cscope,cscope->
class_name().c_str(),name.str(),symbol);
6959 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6976 ROSE_ASSERT(cscope != NULL);
6978 while ((cscope != NULL) && (symbol == NULL))
6981 symbol = cscope->lookup_enum_symbol(name);
6984 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
6999 ROSE_ASSERT(cscope != NULL);
7001 while ((cscope != NULL) && (symbol == NULL))
7004 symbol = cscope->lookup_namespace_symbol(name);
7007 cscope = isSgGlobal(cscope) ? NULL : cscope->
get_scope();
7017SageInterface::setSourcePositionToDefault( T* node )
7035 ROSE_ASSERT(node != NULL);
7038 if (node->get_endOfConstruct() == NULL && node->get_startOfConstruct() == NULL)
7041 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());
7044 ROSE_ASSERT(node->get_endOfConstruct() == NULL);
7045 ROSE_ASSERT(node->get_startOfConstruct() == NULL);
7052 printf (
"In SageInterface::setSourcePositionToDefault(): Calling setSourcePositionUnavailableInFrontend() \n");
7054 start_fileInfo->setSourcePositionUnavailableInFrontend();
7055 end_fileInfo->setSourcePositionUnavailableInFrontend();
7059 printf (
"In SageInterface::setSourcePositionToDefault(): Calling setOutputInCodeGeneration() \n");
7065 node->set_startOfConstruct(start_fileInfo);
7066 node->set_endOfConstruct (end_fileInfo);
7068 node->get_startOfConstruct()->set_parent(node);
7069 node->get_endOfConstruct ()->set_parent(node);
7076 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());
7078 if (node->get_startOfConstruct() == NULL)
7080 printf (
"ERROR: startOfConstruct not set for locatedNode = %p = %s \n",node,node->class_name().c_str());
7082 if (node->get_endOfConstruct() == NULL)
7084 printf (
"ERROR: endOfConstruct not set for locatedNode = %p = %s \n",node,node->class_name().c_str());
7087 ROSE_ASSERT(node->get_startOfConstruct() != NULL);
7088 ROSE_ASSERT(node->get_endOfConstruct() != NULL);
7089 ROSE_ASSERT(node->get_endOfConstruct() != NULL && node->get_startOfConstruct() != NULL);
7110 if (expression != NULL)
7113 SgBinaryOp* binaryOp = isSgBinaryOp(expression);
7114 if (binaryOp != NULL)
7116 if (binaryOp->get_operatorPosition() == NULL)
7119 operator_fileInfo->setSourcePositionUnavailableInFrontend();
7121 binaryOp->set_operatorPosition(operator_fileInfo);
7124 binaryOp->get_operatorPosition()->
set_parent(binaryOp);
7129 if (expression->get_operatorPosition() == NULL)
7132 operator_fileInfo->setSourcePositionUnavailableInFrontend();
7134 expression->set_operatorPosition(operator_fileInfo);
7139 ROSE_ASSERT(expression->get_operatorPosition()->
get_parent() == expression);
7150#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
7151 printf (
"+++++ Depricated function (use setSourcePositionAsTransformation() instead) (no using internal source position mode) \n");
7170 ROSE_ASSERT(node != NULL);
7179 SgPragma* pragma = isSgPragma(node);
7180 SgGlobal* global = isSgGlobal(node);
7185 printf (
"Debug, Found a variable definition: %p\n", v_d);
7188 if (locatedNode != NULL)
7200 if (expression!=NULL)
7203 expression->get_operatorPosition()->
set_parent(expression);
7222 printf (
"+++++ Depricated name setOneSourcePositionNull() (use setSourcePositionPointersToNull() instead) (no using internal source position mode) \n");
7240 ROSE_ASSERT(node != NULL);
7244 SgPragma* pragma = isSgPragma(node);
7245 SgGlobal* global = isSgGlobal(node);
7251 if (locatedNode != NULL)
7254 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of startOfConstruct Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7262 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of endOfConstruct Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7268 if (expression != NULL)
7270 if (expression->get_operatorPosition() != NULL)
7271 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of operatorPosition Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7273 expression->set_operatorPosition(NULL);
7280 printf (
"WARNING: In SageInterface::setSourcePositionPointersToNull(): Memory leak of Sg_File_Info object (setting Sg_File_Info pointers to NULL) \n");
7282 pragma->set_startOfConstruct(NULL);
7293 printf (
"+++++ Depricated name setSourcePositionForTransformation() (use setSourcePositionAtRootAndAllChildrenAsTransformation() instead) \n");
7306 Rose_STL_Container <SgNode*> nodeList = NodeQuery::querySubTree(root,V_SgNode);
7307 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i!=nodeList.end(); i++ )
7318SageInterface::setSourcePositionAtRootAndAllChildrenAsTransformation(
SgNode *root)
7320 Rose_STL_Container <SgNode*> nodeList= NodeQuery::querySubTree(root,V_SgNode);
7321 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i!=nodeList.end(); i++ )
7330SageInterface::setSourcePositionAtRootAndAllChildrenAsDefault(
SgNode *root)
7332 Rose_STL_Container <SgNode*> nodeList= NodeQuery::querySubTree(root,V_SgNode);
7333 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i!=nodeList.end(); i++ )
7335 setSourcePositionAsDefault(*i);
7345 Rose_STL_Container <SgNode*> nodeList = NodeQuery::querySubTree(root,V_SgNode);
7348 printf (
"In setSourcePositionAtRootAndAllChildren(): nodeList.size() = %" PRIuPTR
" \n",nodeList.size());
7351 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
7354 printf (
"In setSourcePositionAtRootAndAllChildren(): *i = %p = %s \n",*i,(*i)->class_name().c_str());
7373 printf (
"In SageInterface::setSourcePosition(): SourcePositionClassification scp = %s \n",
display(scp).c_str());
7378 case e_sourcePositionError:
7380 printf (
"Error: error value e_sourcePositionError in SageInterface::setSourcePosition() \n");
7387 printf (
"e_sourcePositionDefault in SageInterface::setSourcePosition() \n");
7390 if (locatedNode != NULL)
7392 setSourcePositionToDefault(locatedNode);
7397 printf (
"Error: can't call setSourcePosition() in mode e_sourcePositionDefault with non SgLocatedNode (node = %p = %s) \n",node,node->
class_name().c_str());
7406 printf (
"e_sourcePositionTransformation in SageInterface::setSourcePosition() \n");
7415 printf (
"e_sourcePositionCompilerGenerated in SageInterface::setSourcePosition() \n");
7417 printf (
"Sorry, not implemented \n");
7426 printf (
"e_sourcePositionNullPointers in SageInterface::setSourcePosition() \n");
7443 printf (
"e_sourcePositionFrontendConstruction in SageInterface::setSourcePosition() \n");
7446 if (locatedNode != NULL)
7449 setSourcePositionToDefault(locatedNode);
7454 SgPragma* pragma = isSgPragma(node);
7457 setSourcePositionToDefault(pragma);
7463 SgType* type = isSgType(node);
7471 if (functionParameterTypeList != NULL)
7477 printf (
"Error: can't call setSourcePosition() in mode e_sourcePositionFrontendConstruction with non SgLocatedNode (node = %p = %s) \n",node,node->
class_name().c_str());
7490 printf (
"Error: error value e_sourcePositionError in SageInterface::setSourcePosition() \n");
7496 printf (
"Error: default reached in SageInterface::setSourcePosition() \n");
7504 node->
get_file_info()->display(
"Leaving SageInterface::setSourcePosition()");
7511SageInterface::setSourcePositionForTransformation_memoryPool()
7516 printf (
"ERROR: In setSourcePositionForTransformation_memoryPool(): This seems like a very dangerous function to have, is it required? \n");
7519 VariantVector vv(V_SgNode);
7520 Rose_STL_Container<SgNode*> nodeList = NodeQuery::queryMemoryPool(vv);
7521 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++ )
7532 ROSE_ASSERT(project != NULL);
7535 ROSE_ASSERT(project->get_fileList().empty() ==
false);
7538 SgSourceFile* file = isSgSourceFile(project->get_fileList()[0]);
7539 SgGlobal* global = file->get_globalScope();
7542 SgFilePtrListPtr fileList = project->get_fileList();
7543 SgFilePtrList::const_iterator i= fileList->begin();
7545 SgGlobal* global = (*i)->get_globalScope();
7547 ROSE_ASSERT(global != NULL);
7568 if (declList.empty() ==
false)
7570 stmt = isSgStatement(declList.back());
7579 if (stmtList.empty() ==
false)
7581 stmt = stmtList.back();
7603 if (includingCompilerGenerated)
7607 if (declList.empty() ==
false)
7609 stmt = isSgStatement(declList.front());
7615 SgDeclarationStatementPtrList::iterator i=declList.begin();
7616 while (i != declList.end())
7643 if (includingCompilerGenerated)
7647 if (stmtList.empty() ==
false)
7649 stmt = stmtList.front();
7655 SgStatementPtrList::iterator i = stmtList.begin();
7656 while (i!=stmtList.end())
7691 SgDeclarationStatementPtrList::iterator i=declList.begin();
7692 while (i!=declList.end())
7716 SgStatementPtrList::iterator i=stmtList.begin();
7717 while (i!=stmtList.end())
7744 bool result =
false;
7747 if (isSgProgramHeaderStatement(n)) {
7752 if (isSgFunctionDeclaration(n) !=
nullptr) {
7753 bool either =
false;
7759 ROSE_ASSERT(stmnt !=
nullptr);
7766 ROSE_ASSERT(funcDefn !=
nullptr);
7767 if (funcDefn->get_name() ==
"main") {
7791 return isSgFunctionDeclaration(n);
7794 for (vector<SgNode*>::const_iterator i = children.begin();
7795 i != children.end(); ++i) {
7813 ROSE_ASSERT (scope != NULL);
7817 for (
size_t i = 0; i<stmt_list.size(); i++)
7821 if (isSgDeclarationStatement(cur_stmt))
7823 if (isSgPragmaDeclaration (cur_stmt))
7843 rt = n->copy (g_treeCopy);
7853 bool isC = TransformationSupport::getSourceFile(n)->get_outputLanguage() ==
SgFile::e_C_language;
7865#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
7867 for (std::vector<SgContinueStmt*>::iterator i = continues.begin(); i != continues.end(); ++i)
7872 LowLevelRewrite::replace(*i, make_unit_list( gotoStatement ) );
7878 printf (
"Not supported in mode: ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT (LowLevelRewrite::replace() is unavailable)");
7883#define DEBUG_TEMPLATE_ARG_EQUIVALENCE 0
7889#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7890 printf (
"In templateArgumentEquivalence(): same pointer to template argument: returning true \n");
7897#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7898 printf (
"In templateArgumentEquivalence(): different argumentType(): returning false \n");
7907 ROSE_ASSERT(arg1->
get_type() != NULL);
7908 ROSE_ASSERT(arg2->
get_type() != NULL);
7910#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7911 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::type_argument: checking for the same type: arg1->get_type() = %p = %s arg2->get_type() = %p = %s \n",
7919#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7920 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::type_argument: checking for the same type: returning true \n");
7933#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7934 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::type_argument: checking for the same type: pointers are different: returning typesAreEqual = %s \n",typesAreEqual ?
"true" :
"false");
7936 return typesAreEqual;
7944 if (expr1 == expr2) {
7945#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7946 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: checking for the same expression: returning true \n");
7950#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7951 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: same variant of expression: %s\n", expr1->
class_name().c_str());
7954 case V_SgLongIntVal: {
7958 case V_SgUnsignedLongVal:
7963 case V_SgBoolValExp:
7968 mlog[Sawyer::Message::Common::FATAL]
7969 <<
"FATAL: In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: expression have the same variant "
7971 <<
" but comparison is not NIY!"
7977#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7978 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::nontype_argument: different variant of expression: returning false \n");
7986 if (arg1->get_templateDeclaration() == arg2->get_templateDeclaration())
7988#if DEBUG_TEMPLATE_ARG_EQUIVALENCE
7989 printf (
"In templateArgumentEquivalence(): case SgTemplateArgument::template_template_argument: checking for the same templateDeclaration: returning true \n");
7995 ROSE_ASSERT(!
"NIY: template template argument comparaison.");
8001 ROSE_ASSERT(!
"Try to compare template arguments of unknown type...");
8010 ROSE_ASSERT(!
"Try to compare template arguments of unknown type start_of_pack_expansion_argument");
8016 printf (
"Error: default case not handled! \n");
8024#define DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE 0
8028 if (list1.size() != list2.size())
8030#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8031 printf (
"In templateArgumentListEquivalence(): different list sizes: returning false \n");
8032 printf (
" --- list1.size() = %zu \n",list1.size());
8033 printf (
" --- list2.size() = %zu \n",list2.size());
8040#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8041 printf (
"In templateArgumentListEquivalence(): same list using STL equality operator: returning true \n");
8047 for (
size_t i = 0; i < list1.size(); i++)
8049#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8050 printf (
"In templateArgumentListEquivalence(): calling templateArgumentEquivalence() for i = %zu \n",i);
8055#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8056 printf (
"In templateArgumentListEquivalence(): calling templateArgumentEquivalence() for i = %zu --- returned false: returning false \n",i);
8062#if DEBUG_TEMPLATE_ARG_LIST_EQUIVALENCE
8063 printf (
"In templateArgumentListEquivalence(): reached base of function: returning true \n");
8083 SgName labelname =
"rose_label__";
8096 if (isSgNullExpression(f->get_increment()))
return;
8101 f->set_increment(ne);
8111 ROSE_ASSERT(condstmt);
8113 if (isSgNullStatement(condstmt))
return true;
8117 return isSgNullExpression(exprStmt->get_expression());
8126 bbStmts = initStmts;
8127 for (
size_t i = 0; i < bbStmts.size(); ++i) {
8128 bbStmts[i]->set_parent(bb);
8131 const bool testIsNull = hasEmptyCondition(f);
8141 Rose_STL_Container<SgNode*> fors = NodeQuery::querySubTree(top,
8143 for (
size_t i = 0; i < fors.size(); ++i) {
8151 Rose_STL_Container<SgNode*> allGotos = NodeQuery::querySubTree(scope, V_SgGotoStatement);
8153 vector<SgGotoStatement*> result;
8154 for (Rose_STL_Container<SgNode*>::const_iterator i = allGotos.begin(); i != allGotos.end(); ++i) {
8155 if (isSgGotoStatement(*i)->
get_label() == l) {
8156 result.push_back(isSgGotoStatement(*i));
8164 vector<SgReturnStmt*> SageInterface::findReturnStmts(
SgStatement* scope) {
8167 Rose_STL_Container<SgNode*> returns = NodeQuery::querySubTree(scope, V_SgReturnStmt);
8169 vector<SgReturnStmt*> result;
8170 for (Rose_STL_Container<SgNode*>::const_iterator i = returns.begin(); i != returns.end(); ++i) {
8171 result.push_back(isSgReturnStmt(*i));
8177static void getSwitchCasesHelper(
SgStatement* top, vector<SgStatement*>& result) {
8179 if (isSgSwitchStatement(top))
return;
8180 if (isSgCaseOptionStmt(top) || isSgDefaultOptionStmt(top)) {
8181 result.push_back(top);
8184 for (
unsigned int i = 0; i < children.size(); ++i) {
8185 if (isSgStatement(children[i])) {
8186 getSwitchCasesHelper(isSgStatement(children[i]), result);
8192 vector<SgStatement*> result;
8193 getSwitchCasesHelper(sw->
get_body(), result);
8223 if (
const SgSymbol* symbol = isSgSymbol(astNode))
8224 return symbol->get_scope();
8229 else if (
const SgQualifiedName* qualifiedName = isSgQualifiedName(astNode))
8233 const SgNode* parentNode = astNode;
8234 while (!isSgScopeStatement(parentNode))
8239 if (isSgFunctionParameterList(parentNode) || isSgCtorInitializerList(parentNode))
8242 ROSE_ASSERT(funcDeclaration != NULL);
8244 if (funcDeclaration != NULL)
8246 return funcDeclaration->get_definition();
8251 if (parentNode == NULL)
8259 if ( isSgScopeStatement(parentNode) == NULL &&
8260 dynamic_cast<const SgType*
>(parentNode) == NULL &&
8261 dynamic_cast<const SgSymbol*
>(parentNode) == NULL )
8263 printf (
"Error: In SageInterface::getScope(): could not trace back to SgScopeStatement node \n");
8268 if (
dynamic_cast<const SgType*
>(parentNode) != NULL ||
dynamic_cast<const SgSymbol*
>(parentNode) != NULL )
8270 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());
8278 ROSE_ASSERT (scopeStatement != NULL);
8281 if (isSgScopeStatement(astNode))
8282 if (isSgScopeStatement(parentNode))
8284 ROSE_ASSERT (astNode == parentNode);
8311 printf (
"In getVarSymFromName(): name->get_name() = %s \n",name->get_name().str());
8314 ROSE_ASSERT (scope != NULL);
8316 printf (
"In getVarSymFromName(): name->get_name() = %s scope = %p = %s \n",name->get_name().str(),scope,scope->
class_name().c_str());
8318 v_sym = scope->lookup_var_symbol (name->get_name());
8327 if (decl_scope != NULL)
8328 v_sym = decl_scope->lookup_var_symbol (name->get_name());
8331 cerr <<
"\t\t*** WARNING: Can't seem to find a symbol for '"
8332 << name->get_name ().str ()
8362getVarSym_const (
const SgNode* n)
8368 v_sym = isSgVarRefExp (n)->get_symbol ();
8370 case V_SgInitializedName:
8371 v_sym = getVarSymFromName_const (isSgInitializedName (n));
8397 if (!decl)
return 0;
8398 const SgInitializedNamePtrList& names = decl->
get_variables ();
8399 if (names.begin () != names.end ())
8402 return getVarSym_const (name);
8421 if (names.begin () != names.end ())
8422 return *(names.begin ());
8428static void findBreakStmtsHelper(
SgStatement* code,
const std::string& fortranLabel,
bool inOutermostBody, vector<SgBreakStmt*>& breakStmts) {
8429 if (isSgWhileStmt(code) || isSgDoWhileStmt(code) || isSgForStatement(code) || isSgSwitchStatement(code)) {
8430 if (fortranLabel ==
"") {
8435 inOutermostBody =
false;
8438 if (isSgBreakStmt(code)) {
8440 bool breakMatchesThisConstruct =
false;
8441 if (bs->get_do_string_label() ==
"") {
8443 breakMatchesThisConstruct = inOutermostBody;
8445 breakMatchesThisConstruct = (fortranLabel == bs->get_do_string_label());
8447 if (breakMatchesThisConstruct) {
8448 breakStmts.push_back(bs);
8453 for (
unsigned int i = 0; i < children.size(); ++i) {
8454 if (isSgStatement(children[i])) {
8455 findBreakStmtsHelper(isSgStatement(children[i]), fortranLabel, inOutermostBody, breakStmts);
8463 vector<SgBreakStmt*> result;
8464 findBreakStmtsHelper(code, fortranLabel,
true, result);
8469static void findContinueStmtsHelper(
SgStatement* code,
const std::string& fortranLabel,
bool inOutermostBody, vector<SgContinueStmt*>& continueStmts) {
8470 if (isSgWhileStmt(code) || isSgDoWhileStmt(code) || isSgForStatement(code)) {
8471 if (fortranLabel ==
"") {
8476 inOutermostBody =
false;
8479 if (isSgContinueStmt(code)) {
8481 bool continueMatchesThisConstruct =
false;
8482 if (cs->get_do_string_label() ==
"") {
8484 continueMatchesThisConstruct = inOutermostBody;
8486 continueMatchesThisConstruct = (fortranLabel == cs->get_do_string_label());
8488 if (continueMatchesThisConstruct) {
8489 continueStmts.push_back(cs);
8494 for (
unsigned int i = 0; i < children.size(); ++i) {
8496 if (stmnt != NULL) {
8497 findContinueStmtsHelper(stmnt, fortranLabel, inOutermostBody, continueStmts);
8505 vector<SgContinueStmt*> result;
8506 findContinueStmtsHelper(code, fortranLabel,
true, result);
8517 std::cout <<
"Starting getInitializerOfExpression on 0x" << std::hex << (int)n <<
", which has type " << n->
sage_class_name() << std::endl;
8519 while (!isSgInitializer(n)) {
8522 std::cout <<
"Continuing getInitializerOfExpression on 0x" << std::hex << (int)n;
8524 std::cout << std::endl;
8528 return isSgInitializer(n);
8536 std::vector<SgVariableSymbol*> symbols;
8538 virtual void visit(
SgNode* n) {
8539 if (isSgVarRefExp(n))
8540 symbols.push_back(isSgVarRefExp(n)->get_symbol());
8544 GetSymbolsUsedInExpressionVisitor vis;
8545 vis.traverse(expr, preorder);
8552 return getEnclosingNode<SgSourceFile>(n, includingSelf);
8558 return findDeclarationStatement<SgFunctionDeclaration> (root, name, scope, isDefining);
8569 return getEnclosingNode<SgFunctionDefinition>(n, includingSelf);
8575 return getEnclosingNode<SgFunctionDeclaration>(astNode, includingSelf);
8585 return getEnclosingNode<SgGlobal>(astNode,
true );
8590 return getEnclosingNode<SgClassDefinition>(astNode, includingSelf);
8598 return getEnclosingNode<SgClassDeclaration>(astNode,
true);
8603 return getEnclosingNode<SgExprListExp>(astNode, includingSelf);
8609 bool returnValue =
false;
8615 virtual void visit(
SgNode* n)
8617 if (n == expression_target)
8623 Visitor(
SgExpression* expr) : expression_target(expr), in_subtree(
false) {}
8626 Visitor traversal(exp);
8628 traversal.traverse(subtree, preorder);
8630 returnValue = traversal.in_subtree;
8644 ROSE_ASSERT (functionCallExp != NULL);
8646 SgExpression* expression = functionCallExp->get_function();
8647 ROSE_ASSERT (expression != NULL);
8651 SgDotExp* dotExp = isSgDotExp(expression);
8654 ROSE_ASSERT (dotExp != NULL);
8657 ROSE_ASSERT (rhsOperand != NULL);
8662 if (memberFunctionRefExp != NULL)
8669 if (functionReferenceExp != NULL)
8674 SgArrowExp* arrowExp = isSgArrowExp(expression);
8675 if ( arrowExp != NULL)
8677 ROSE_ASSERT (arrowExp != NULL);
8680 ROSE_ASSERT (rhsOperand != NULL);
8685 if (memberFunctionRefExp != NULL)
8691 return returnDeclaration;
8696std::list<SgClassType*>
8701#define DEBUG_DATA_MEMBER_TYPE_CHAIN 0
8707 ROSE_ASSERT(varRefExp != NULL || memberFunctionRefExp != NULL);
8709 std::list<SgClassType*> returnTypeChain;
8712 std::list<SgClassType*> classChain;
8717 if (varRefExp != NULL)
8723 ROSE_ASSERT(memberFunctionRefExp != NULL);
8728 ROSE_ASSERT(parent != NULL);
8730#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8731 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): parent = %p = %s \n",parent,parent->
class_name().c_str());
8735 SgDotExp* dotExp = isSgDotExp(parent);
8739 if (arrowExp != NULL)
8741#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8742 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): Found an arrow expression \n");
8744 binaryOperator = arrowExp;
8749#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8750 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): Found an dot expression \n");
8752 binaryOperator = dotExp;
8756 if (binaryOperator != NULL)
8759 ROSE_ASSERT(lhs != NULL);
8761#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8762 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs = %p = %s \n",lhs,lhs->
class_name().c_str());
8768 while (isSgCastExp(temp_lhs) != NULL)
8770 cast = isSgCastExp(temp_lhs);
8771 ROSE_ASSERT(cast != NULL);
8774#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8775 printf (
"Top of loop: processing cast = %p temp_lhs = %p = %s \n",cast,temp_lhs,temp_lhs->
class_name().c_str());
8777 ROSE_ASSERT(cast->
get_type() != NULL);
8779 if (classType == NULL)
8781#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8782 printf (
" --- looking for base type: In SageInterface::getClassTypeChainForDataMemberReference(): classType == NULL: cast->get_type() = %p = %s \n",
8785 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);
8786 ROSE_ASSERT(baseType != NULL);
8788#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8789 printf (
" --- baseType = %p = %s name = %s \n",baseType,baseType->
class_name().c_str(),
get_name(baseType).c_str());
8791 classType = isSgClassType(baseType);
8795 ROSE_ASSERT(temp_lhs != NULL);
8797#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8798 printf (
" --- temp_lhs = %p = %s name = %s \n",temp_lhs,temp_lhs->
class_name().c_str(),
get_name(temp_lhs).c_str());
8804 if (classType != NULL)
8806 classChain.push_front(classType);
8810 if (classType != NULL)
8821 ROSE_ASSERT(target_type != NULL);
8822 SgClassType* target_classType = isSgClassType(target_type);
8824 if (target_classType != NULL)
8827 ROSE_ASSERT(target_declaration != NULL);
8828 SgClassDeclaration* target_classDeclaration = isSgClassDeclaration(target_declaration);
8829 ROSE_ASSERT(target_classDeclaration != NULL);
8831 ROSE_ASSERT(target_definingClassDeclaration != NULL);
8832 SgScopeStatement* target_scope = target_definingClassDeclaration->get_definition();
8833 ROSE_ASSERT(target_scope != NULL);
8835#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8836 printf (
"target_classDeclaration = %p = %s name = %s target_scope = %p = %s \n",
8837 target_classDeclaration,target_classDeclaration->
class_name().c_str(),target_classDeclaration->get_name().str(),target_scope,target_scope->
class_name().c_str());
8840 ROSE_ASSERT(source_classType != NULL);
8842 ROSE_ASSERT(source_declaration != NULL);
8843 SgClassDeclaration* source_classDeclaration = isSgClassDeclaration(source_declaration);
8844 ROSE_ASSERT(source_classDeclaration != NULL);
8846 ROSE_ASSERT(source_definingClassDeclaration != NULL);
8847 SgScopeStatement* source_scope = source_definingClassDeclaration->get_definition();
8848 ROSE_ASSERT(source_scope != NULL);
8850#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8851 printf (
"source_classDeclaration = %p = %s name = %s source_scope = %p = %s \n",
8852 source_classDeclaration,source_classDeclaration->
class_name().c_str(),source_classDeclaration->get_name().str(),source_scope,source_scope->
class_name().c_str());
8855 while (tmp_scope != NULL && tmp_scope != target_scope)
8857#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8858 printf (
"tmp_scope = %p = %s \n",tmp_scope,tmp_scope->
class_name().c_str());
8861 ROSE_ASSERT(tmp_classDefinition != NULL);
8863 ROSE_ASSERT(tmp_classDeclaration != NULL);
8865#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8866 SgName scope_name = tmp_classDeclaration->get_name();
8867 printf (
"scope_name = %s \n",scope_name.str());
8869 SgClassType* tmp_classType = tmp_classDeclaration->get_type();
8870 ROSE_ASSERT(tmp_classType != NULL);
8873 classChain.push_front(tmp_classType);
8877 if (isSgGlobal(tmp_scope) != NULL)
8886 printf (
"In loop processing cast: target_type = %p = %s \n",target_type,target_type->
class_name().c_str());
8892#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8893 printf (
"Bottom of loop: processing cast = %p temp_lhs = %p = %s \n",cast,temp_lhs,temp_lhs->
class_name().c_str());
8899 ROSE_ASSERT(temp_lhs != NULL);
8901#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8902 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): temp_lhs = %p = %s \n",temp_lhs,temp_lhs->
class_name().c_str());
8905 SgVarRefExp* derivedClassVarRefExp = isSgVarRefExp(temp_lhs);
8906 if (derivedClassVarRefExp != NULL)
8908 SgVariableSymbol* derivedClassVariableSymbol = derivedClassVarRefExp->get_symbol();
8909 ROSE_ASSERT(derivedClassVariableSymbol != NULL);
8911 SgName derivedClassVariableName = derivedClassVariableSymbol->
get_name();
8913#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8914 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): derivedClassVariableName = %s \n",derivedClassVariableName.str());
8918 ROSE_ASSERT(type != NULL);
8920#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8921 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs type = %p = %s \n",type,type->
class_name().c_str());
8925 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);
8927#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8928 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs stripped_type = %p = %s \n",stripped_type,stripped_type->
class_name().c_str());
8932 SgClassType* classType = isSgClassType(stripped_type);
8935 if (classType != NULL)
8937#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8938 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs classType = %p = %s \n",classType,classType->
class_name().c_str());
8939 SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
8940 ROSE_ASSERT(classDeclaration != NULL);
8941 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs classDeclaration = %p = %s name = %s \n",
8942 classDeclaration,classDeclaration->
class_name().c_str(),classDeclaration->get_name().str());
8947 classChain.push_front(classType);
8951#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8952 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs stripped_type is not a SgClassType \n");
8958#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8959 printf (
"Need to support alternative to SgVarRefExp: temp_lhs = %p = %s \n",temp_lhs,temp_lhs->
class_name().c_str());
8962 ROSE_ASSERT(type != NULL);
8964#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8965 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): lhs type = %p = %s name = %s \n",type,type->
class_name().c_str(),
get_name(type).c_str());
8969 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);
8971#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8972 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());
8975 SgClassType* classType = isSgClassType(stripped_type);
8977 if (classType != NULL)
8979 classChain.push_front(classType);
8983#if DEBUG_DATA_MEMBER_TYPE_CHAIN
8984 printf (
"classChain.size() = %zu \n",classChain.size());
8985 std::list<SgClassType*>::iterator iter = classChain.begin();
8986 while(iter != classChain.end())
8988 printf (
" --- *iter = %p = %s name = %s \n",*iter,(*iter)->class_name().c_str(),(*iter)->get_name().str());
9001 if (varRefExp != NULL)
9003 ROSE_ASSERT(varRefExp != NULL);
9004 ROSE_ASSERT(memberFunctionRefExp == NULL);
9006 referenceSymbol = varRefExp->get_symbol();
9010 ROSE_ASSERT(varRefExp == NULL);
9011 ROSE_ASSERT(memberFunctionRefExp != NULL);
9013 referenceSymbol = memberFunctionRefExp->get_symbol();
9015 ROSE_ASSERT(referenceSymbol != NULL);
9018#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9019 printf (
"referenceSymbol = %p = %s \n",referenceSymbol,referenceSymbol->
class_name().c_str());
9020 printf (
"symbolName = %s \n",symbolName.str());
9025 if (functionSymbol != NULL)
9030 if (templateInstantiationMemberFunctionDeclaration != NULL)
9032#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9033 printf (
"This is a template name, we want the name without template arguments \n");
9034 printf (
"templateInstantiationMemberFunctionDeclaration = %p \n",templateInstantiationMemberFunctionDeclaration);
9035 printf (
"templateInstantiationMemberFunctionDeclaration->get_name() = %s \n",templateInstantiationMemberFunctionDeclaration->get_name().str());
9042 isSgTemplateMemberFunctionDeclaration(templateInstantiationMemberFunctionDeclaration->
get_templateDeclaration());
9043 if (templateMemberFunctionDeclaration != NULL)
9045#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9046 printf (
"templateMemberFunctionDeclaration = %p \n",templateMemberFunctionDeclaration);
9047 printf (
"templateMemberFunctionDeclaration->get_name() = %s \n",templateMemberFunctionDeclaration->get_name().str());
9050 symbolName = templateMemberFunctionDeclaration->get_name();
9054#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9055 printf (
"templateMemberFunctionDeclaration == NULL: template declaration not available from template instantiation (rare, I think) \n");
9059 printf (
"Exiting as a test! \n");
9067 ROSE_ASSERT(declarationStatement != NULL);
9068#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9069 printf (
"functionSymbol != NULL: but declaration is not a member function: declarationStatement = %p = %s \n",declarationStatement,declarationStatement->
class_name().c_str());
9076 if (variableSymbol != NULL)
9082#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9083 printf (
"In SageInterface::getClassTypeChainForDataMemberReference(): NOTE: referenceSymbol is not a SgFunctionSymbol or SgVariableSymbol \n");
9086 printf (
"Exiting as a test! \n");
9093#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9094 printf (
"symbolName = %s \n",symbolName.str());
9103 std::list<SgClassType*> saveList;
9105#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9106 printf (
"classChain.size() = %zu \n",classChain.size());
9109 std::list<SgClassType*>::iterator i = classChain.begin();
9110 std::list<SgClassType*>::iterator save_iter = i;
9116 bool ambiguityDetectedSoSaveWholeChain =
false;
9118 while(i != classChain.end())
9120#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9121 printf (
"******** TOP OF WHILE LOOP ******** \n");
9122 printf (
" --- *i = %p = %s name = %s \n",*i,(*i)->class_name().c_str(),(*i)->get_name().str());
9123 printf (
" --- --- referenceSymbol = %p = %s \n",referenceSymbol,referenceSymbol->
class_name().c_str());
9125 bool ambiguityDetected =
false;
9128 ROSE_ASSERT(declarationStatement != NULL);
9130 if (definingDeclarationStatement != NULL)
9132 SgClassDeclaration* classDeclaration = isSgClassDeclaration(definingDeclarationStatement);
9133 ROSE_ASSERT(classDeclaration != NULL);
9136#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9137 printf (
" --- classDeclaration = %p = %s name = %s \n",classDeclaration,classDeclaration->
class_name().c_str(),classDeclaration->get_name().str());
9138 printf (
" --- classDefinition = %p = %s \n",classDefinition,classDefinition->
class_name().c_str());
9141 ambiguityDetected = classDefinition->hasAmbiguity(symbolName,referenceSymbol);
9143#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9144 printf (
" --- ambiguityDetected = %s \n",ambiguityDetected ?
"true" :
"false");
9149 if (ambiguityDetected ==
true || ambiguityDetectedSoSaveWholeChain ==
true)
9151 ambiguityDetectedSoSaveWholeChain =
true;
9153 if (save_iter != classChain.end())
9155#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9156 printf (
" --- add to saveList: *save_iter = %p \n",*save_iter);
9158 saveList.push_back(*save_iter);
9162#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9163 printf (
" --- save_iter == classChain.end() \n");
9168#if DEBUG_DATA_MEMBER_TYPE_CHAIN || 0
9169 printf (
"******** BOTTOM OF WHILE LOOP ******** \n");
9179#if DEBUG_DATA_MEMBER_TYPE_CHAIN
9180 printf (
"saveList.size() = %zu \n",saveList.size());
9181 std::list<SgClassType*>::iterator saveList_iterator = saveList.begin();
9182 while (saveList_iterator != saveList.end())
9184 printf (
" --- *saveList_iterator = %p = %s name = %s \n",*saveList_iterator,(*saveList_iterator)->class_name().c_str(),(*saveList_iterator)->get_name().str());
9186 saveList_iterator++;
9190 returnTypeChain = saveList;
9195 return returnTypeChain;
9205#define DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE 0
9207 ROSE_ASSERT(memberFunctionRefExp != NULL);
9209 bool returnValue =
false;
9215 SgDotExp* dotExp = isSgDotExp(parent);
9222 if (arrowExp != NULL || dotExp != NULL || addressOfOp != NULL)
9226 ROSE_ASSERT(symbol != NULL);
9229 ROSE_ASSERT(functionDeclaration != NULL);
9232 if (functionDeclaration != NULL)
9234 bool isStatic = functionDeclaration->get_declarationModifier().get_storageModifier().
isStatic();
9235#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9236 printf (
"isStatic = %s \n",
isStatic ?
"true" :
"false");
9241 ROSE_ASSERT(scope != NULL);
9244 if (classDefinition != NULL)
9252#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9253 printf (
"In SageInterface::isMemberFunctionMemberReference(): memberFunctionRefExp is not associated with variableDeclaration (could not compute if it is static data member) \n");
9259#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9260 printf (
"In SageInterface::isMemberFunctionMemberReference(): memberFunctionRefExp parent is not a is not SgArrowExp or SgDotExp expression \n");
9264#if DEBUG_IS_MEMBER_FUNCTION_MEMBER_REFERENCE
9265 printf (
"Leaving SageInterface::isMemberFunctionMemberReference(): returnValue = %s \n",returnValue ?
"true" :
"false");
9284#define DEBUG_IS_DATA_MEMBER_REFERENCE 0
9286 ROSE_ASSERT(varRefExp != NULL);
9288 bool returnValue =
false;
9294 SgDotExp* dotExp = isSgDotExp(parent);
9298 if (arrowExp != NULL || dotExp != NULL || addressOfOp != NULL)
9300 if (arrowExp != NULL)
9304 ROSE_ASSERT(parentOfArrowExp != NULL);
9305 SgSizeOfOp* sizeOfOp = isSgSizeOfOp(parentOfArrowExp);
9306 if (sizeOfOp != NULL && sizeOfOp->get_is_objectless_nonstatic_data_member_reference() ==
true)
9309#if DEBUG_IS_DATA_MEMBER_REFERENCE
9310 printf (
"In SageInterface::isDataMemberReference(): Found case of expression used in sizeof with objectless_nonstatic_data_member_reference \n");
9317 ROSE_ASSERT(symbol != NULL);
9320 ROSE_ASSERT(initializedName != NULL);
9324 if (variableDeclaration != NULL)
9326 bool isStatic = variableDeclaration->get_declarationModifier().get_storageModifier().
isStatic();
9330 ROSE_ASSERT(scope != NULL);
9333 if (classDefinition != NULL)
9341#if DEBUG_IS_DATA_MEMBER_REFERENCE
9342 printf (
"In SageInterface::isDataMemberReference(): varRefExp is not associated with variableDeclaration (could not compute if it is static data member) \n");
9348#if DEBUG_IS_DATA_MEMBER_REFERENCE
9349 printf (
"In SageInterface::isDataMemberReference(): varRefExp parent is not a is not SgArrowExp or SgDotExp expression \n");
9353#if DEBUG_IS_DATA_MEMBER_REFERENCE
9354 printf (
"Leaving SageInterface::isDataMemberReference(): returnValue = %s \n",returnValue ?
"true" :
"false");
9366 ROSE_ASSERT(varRefExp != NULL);
9368 bool returnValue =
false;
9372 if (addressOfOp != NULL)
9390 ROSE_ASSERT(varRefExp != NULL || memberFunctionRefExp != NULL);
9394 ROSE_ASSERT(refExp != NULL);
9396 bool returnValue =
false;
9401 if (addressOfOp != NULL)
9419 ROSE_ASSERT (astNode != NULL);
9423 ROSE_ASSERT (isSgProject(astNode) == NULL);
9425 SgNode* previous_parent = NULL;
9426 SgNode* previous_previous_parent = NULL;
9428 SgNode* parent = astNode;
9430 while ( (parent != NULL) && (isSgFile(parent) == NULL) && isSgJavaPackageDeclaration(parent) == NULL)
9433 printf (
"In getEnclosingFileNode(): parent = %p = %s \n",parent,parent->
class_name().c_str());
9435 previous_previous_parent = previous_parent;
9436 previous_parent = parent;
9441 if (previous_previous_parent != NULL && previous_parent != NULL && isSgJavaPackageDeclaration(parent) != NULL)
9445 printf (
"parent = %p = %s \n",parent,parent->
class_name().c_str());
9446 printf (
"previous_parent = %p = %s \n",previous_parent,previous_parent->
class_name().c_str());
9447 printf (
"previous_previous_parent = %p = %s \n",previous_previous_parent,previous_previous_parent->
class_name().c_str());
9449 SgClassDeclaration* classDeclaration = isSgClassDeclaration(previous_previous_parent);
9450 if (classDeclaration != NULL)
9453 printf (
"Class name = %p = %s = %s \n",classDeclaration,classDeclaration->
class_name().c_str(),classDeclaration->get_name().str());
9458 SgProject* project = TransformationSupport::getProject(parent);
9459 ROSE_ASSERT(project != NULL);
9460 SgFileList* fileList = project->get_fileList_ptr();
9461 ROSE_ASSERT(fileList != NULL);
9462 SgFilePtrList & vectorFile = fileList->get_listOfFiles();
9464 printf (
"Output list of files: \n");
9466 SgFilePtrList::iterator i = vectorFile.begin();
9467 while (i != vectorFile.end())
9470 ROSE_ASSERT(file != NULL);
9472 printf (
" --- filename = %s \n",file->
getFileName().c_str());
9475 string filenameWithoutPath = file->get_sourceFileNameWithoutPath();
9476 string classname = classDeclaration->get_name();
9477 string matchingfilename = classname +
".java";
9479 printf (
" --- --- filename = %s \n",filename.c_str());
9480 printf (
" --- --- filenameWithoutPath = %s \n",filenameWithoutPath.c_str());
9481 printf (
" --- --- classname = %s \n",classname.c_str());
9482 printf (
" --- --- matchingfilename = %s \n",matchingfilename.c_str());
9484 if (filenameWithoutPath == matchingfilename)
9487 printf (
" return file = %p \n",file);
9503 SgSourceFile *sourcefile = isSgSourceFile(attribute->getNode());
9504 ROSE_ASSERT(sourcefile != NULL);
9513 if (previous_parent == NULL && isSgJavaPackageDeclaration(parent) != NULL)
9516 ROSE_ASSERT(isSgJavaPackageDeclaration(astNode) != NULL);
9521 if (previous_previous_parent == NULL && isSgJavaPackageDeclaration(parent) != NULL)
9524 ROSE_ASSERT(isSgClassDefinition(astNode) != NULL);
9535 if (parent ==
nullptr)
9541 return isSgFile(parent);
9547 std::set<SgNode*> specific;
9548 std::set<SgNode*> non_specific;
9550 static void recursive_collect(
SgNode* node , std::set<SgNode *> & collection ) {
9552 if (node == NULL || !collection.insert(node).second)
return;
9555 for (std::vector<std::pair<SgNode*, std::string> >::iterator i = data_members.begin(); i != data_members.end(); ++i) {
9556 recursive_collect(i->first, collection);
9563 if (fileInfo != NULL) {
9564 if (fileInfo->isFrontendSpecific()) {
9566 recursive_collect(n, specific);
9568 non_specific.insert(n);
9569 recursive_collect(n, non_specific);
9572 fileInfo = isSg_File_Info(n);
9573 if (fileInfo != NULL) {
9574 if (fileInfo->isFrontendSpecific()) {
9577 non_specific.insert(n);
9583 std::set<SgNode*> apply() {
9584 traverseMemoryPool();
9586 std::set<SgNode*> result;
9588 std::set_difference(
9589 specific.begin(), specific.end(),
9590 non_specific.begin(), non_specific.end(),
9591 std::insert_iterator<set<SgNode*> >(result, result.begin())
9598 FrontendSpecificTraversal fst;
9611 void visit(
SgNode *astNode)
9613 ROSE_ASSERT(astNode != NULL);
9615 if (file_info != NULL)
9619 printf (
"Found shared node: astNode = %p = %s \n",astNode,astNode->
class_name().c_str());
9625 OutputSharedNodesTraversal tt;
9626 tt.traverse(node,preorder);
9634 while (n && !isSgStatement(n)) n = n->
get_parent();
9635 return isSgStatement(n);
9644SageInterface::DeferredTransformation::DeferredTransformation()
9645 : deferredTransformationKind(e_default),
9646 statementToRemove(NULL),
9647 statementToAdd(NULL),
9648 class_definition(NULL),
9649 target_class_member(NULL),
9650 new_function_prototype(NULL),
9652 locationToOverwriteWithTransformation(NULL),
9653 transformationToOverwriteFirstStatementInInterval(NULL),
9654 blockOfStatementsToOutline(NULL)
9658 printf (
"In SageInterface::DeferredTransformation default constructor called \n");
9666SageInterface::DeferredTransformation::DeferredTransformation(
9670 : deferredTransformationKind(e_outliner),
9671 statementToRemove(NULL),
9672 statementToAdd(NULL),
9673 class_definition(input_class_definition),
9674 target_class_member(input_target_class_member),
9675 new_function_prototype(input_new_function_prototype),
9677 locationToOverwriteWithTransformation(NULL),
9678 transformationToOverwriteFirstStatementInInterval(NULL),
9679 blockOfStatementsToOutline(NULL)
9683 printf (
"In SageInterface::DeferredTransformation constructor for outliner called \n");
9691 printf (
"In SageInterface::DeferredTransformation constructor for replaceDefiningFunctionDeclarationWithFunctionPrototype called \n");
9697 X.deferredTransformationKind = e_replaceDefiningFunctionDeclarationWithFunctionPrototype;
9698 X.statementToRemove = functionDeclaration;
9699 X.statementToAdd = NULL;
9700 X.class_definition = NULL;
9701 X.target_class_member = NULL;
9702 X.new_function_prototype = NULL;
9705 X.locationToOverwriteWithTransformation = NULL;
9706 X.transformationToOverwriteFirstStatementInInterval = NULL;
9707 X.blockOfStatementsToOutline = NULL;
9713SageInterface::DeferredTransformation::replaceStatement(
SgStatement* oldStmt,
SgStatement* newStmt,
bool )
9716 printf (
"In SageInterface::DeferredTransformation constructor for replaceStatement called \n");
9722 X.deferredTransformationKind = e_replaceStatement;
9723 X.statementToRemove = oldStmt;
9724 X.statementToAdd = newStmt;
9725 X.class_definition = NULL;
9726 X.target_class_member = NULL;
9727 X.new_function_prototype = NULL;
9730 X.locationToOverwriteWithTransformation = NULL;
9731 X.transformationToOverwriteFirstStatementInInterval = NULL;
9732 X.blockOfStatementsToOutline = NULL;
9737SageInterface::DeferredTransformation::DeferredTransformation (
const DeferredTransformation& X)
9739 : deferredTransformationKind(X.deferredTransformationKind),
9740 statementToRemove(X.statementToRemove),
9741 statementToAdd(X.StatementToAdd),
9742 class_definition(X.class_definition),
9743 target_class_member(X.target_class_member),
9744 new_function_prototype(X.new_function_prototype),
9745 targetClasses(X.targetClasses),
9746 targetFriends(X.targetFriends)
9752 printf (
"In SageInterface::DeferredTransformation copy constructor called \n");
9762 printf (
"Inside of SageInterface::DeferredTransformation::operator= (const DeferredTransformation& X) \n");
9767 targetFriends = X.targetFriends;
9768 targetClasses = X.targetClasses;
9774 transformationLabel = X.transformationLabel;
9777 deferredTransformationKind = X.deferredTransformationKind;
9778 statementToRemove = X.statementToRemove;
9779 statementToAdd = X.statementToAdd;
9781 class_definition = X.class_definition;
9782 target_class_member = X.target_class_member;
9783 new_function_prototype = X.new_function_prototype;
9784 targetClasses = X.targetClasses;
9785 targetFriends = X.targetFriends;
9788 statementInterval = X.statementInterval;
9789 locationToOverwriteWithTransformation = X.locationToOverwriteWithTransformation;
9790 transformationToOverwriteFirstStatementInInterval = X.transformationToOverwriteFirstStatementInInterval;
9793 blockOfStatementsToOutline = X.blockOfStatementsToOutline;
9804std::string SageInterface::DeferredTransformation::outputDeferredTransformationKind(
const TransformationKind & kind)
9806 string returnValue =
"uninitialized";
9809 case e_error: returnValue =
"e_error";
break;
9810 case e_default: returnValue =
"e_default";
break;
9811 case e_outliner: returnValue =
"e_outliner";
break;
9812 case e_replaceStatement: returnValue =
"e_replaceStatement";
break;
9813 case e_removeStatement: returnValue =
"e_removeStatement";
break;
9814 case e_replaceDefiningFunctionDeclarationWithFunctionPrototype: returnValue =
"e_replaceDefiningFunctionDeclarationWithFunctionPrototype";
break;
9815 case e_last: returnValue =
"e_last";
break;
9818 printf (
"Error: SageInterface::DeferredTransformation::get_deferredTransformationKind_string(): default reached \n");
9826void SageInterface::DeferredTransformation::display ( std::string label )
const
9828 printf (
"SageInterface::DeferredTransformation::display(): label = %s \n",label.c_str());
9833 printf (
" --- transformationLabel = %s \n",transformationLabel.c_str());
9835 printf (
" --- deferredTransformationKind = %s \n",outputDeferredTransformationKind(deferredTransformationKind).c_str());
9836 if (statementToRemove != NULL)
9838 printf (
" --- statementToRemove = %p = %s name = %s \n",statementToRemove,statementToRemove->class_name().c_str(),
get_name(statementToRemove).c_str());
9842 printf (
" --- statementToRemove == NULL \n");
9845 if (statementToAdd != NULL)
9847 printf (
" --- statementToAdd = %p = %s name = %s \n",statementToAdd,statementToAdd->class_name().c_str(),
get_name(statementToAdd).c_str());
9851 printf (
" --- statementToAdd == NULL \n");
9854 if (class_definition != NULL)
9857 printf (
" --- class_definition = %p \n",class_definition);
9860 if (target_class_member != NULL)
9862 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());
9865 if (new_function_prototype != NULL)
9867 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());
9871 if (locationToOverwriteWithTransformation != NULL)
9875 printf (
" --- locationToOverwriteWithTransformation = %p \n",locationToOverwriteWithTransformation);
9879 if (transformationToOverwriteFirstStatementInInterval != NULL)
9883 printf (
" --- transformationToOverwriteFirstStatementInInterval = %p \n",transformationToOverwriteFirstStatementInInterval);
9887 if (blockOfStatementsToOutline != NULL)
9889 printf (
" --- blockOfStatementsToOutline = %p \n",blockOfStatementsToOutline);
9892 printf (
"targetClasses.size() = %zu \n",targetClasses.size());
9893 printf (
"targetFriends.size() = %zu \n",targetFriends.size());
9896 printf (
"statementInterval.size() = %zu \n",statementInterval.size());
9906#define REMOVE_STATEMENT_DEBUG 0
9911#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
9922 ASSERT_not_null(targetStmt);
9930 bool isRemovable = (parentStatement != NULL) ? LowLevelRewrite::isRemovableStatement(targetStmt) :
false;
9932#if REMOVE_STATEMENT_DEBUG || 0
9933 printf (
"In SageInterface::removeStatement(): parentStatement = %p = %s remove targetStatement = %p = %s (isRemovable = %s) \n",
9934 parentStatement,parentStatement->
class_name().c_str(),targetStmt,targetStmt->
class_name().c_str(),isRemovable ?
"true" :
"false");
9937 if (isRemovable ==
true)
9944 if (autoRelocatePreprocessingInfo ==
true)
9954 if (comments !=
nullptr && isSgBasicBlock(targetStmt) ==
nullptr )
9956 vector<int> captureList;
9957#if REMOVE_STATEMENT_DEBUG
9958 printf (
"Found attached comments (removing %p = %s): comments->size() = %" PRIuPTR
" \n",targetStmt,targetStmt->
class_name().c_str(),comments->size());
9964 int commentIndex = 0;
9965 AttachedPreprocessingInfoType::iterator i;
9966 for (i = comments->begin(); i != comments->end(); i++)
9968 ROSE_ASSERT ( (*i) != NULL );
9969#if REMOVE_STATEMENT_DEBUG
9970 printf (
" Attached Comment (relativePosition=%s): %s\n",
9971 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
9972 (*i)->getString().c_str());
9973 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
9974 (*i)->get_file_info()->display(
"comment/directive location debug");
9976 captureList.push_back(commentIndex);
9980#if REMOVE_STATEMENT_DEBUG
9981 printf (
"captureList.size() = %" PRIuPTR
" \n",captureList.size());
9984 if (captureList.empty() ==
false)
9989 bool surroundingStatementPreceedsTargetStatement =
false;
9992 if (surroundingStatement !=
nullptr)
9995#if REMOVE_STATEMENT_DEBUG
9996 printf (
"In removeStatement(): surroundingStatementPreceedsTargetStatement = %s \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false");
9997 printf (
" --- moving comments from targetStmt = %p = %s name = %s \n",targetStmt,targetStmt->
class_name().c_str(),
get_name(targetStmt).c_str());
9998 printf (
" --- moving comments to surroundingStatement = %p = %s name = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str(),
get_name(surroundingStatement).c_str());
10013 printf (
"Error: This is not supported within Microsoft Windows (I forget why). \n");
10035 printf (
"In SageInterface::resetInternalMapsForTargetStatement(SgStatement*): sourceStatement = %p = %s \n",sourceStatement,sourceStatement->
class_name().c_str());
10044 printf (
"In SageInterface::resetInternalMapsForTargetStatement(SgStatement*): sourceFile = %p \n",sourceFile);
10047 if (sourceFile != NULL)
10049 std::map<SgStatement*,MacroExpansion*> & macroExpansionMap = sourceFile->get_macroExpansionMap();
10051 if (macroExpansionMap.find(sourceStatement) != macroExpansionMap.end())
10053 MacroExpansion* macroExpansion = macroExpansionMap[sourceStatement];
10054 ROSE_ASSERT(macroExpansion != NULL);
10056 printf (
"In resetInternalMapsForTargetStatement(): macroExpansion = %p = %s \n",macroExpansion,macroExpansion->macro_name.c_str());
10058 if (macroExpansion->isTransformed ==
false)
10061 std::vector<SgStatement*> & associatedStatementVector = macroExpansion->associatedStatementVector;
10063 for (
size_t i = 0; i < associatedStatementVector.size(); i++)
10066 SgStatement* statement = associatedStatementVector[i];
10068 printf (
"Mark as transformation to be output: statement = %p = %s \n",statement,statement->
class_name().c_str());
10092 macroExpansion->isTransformed =
true;
10109#if REMOVE_STATEMENT_DEBUG || 0
10110 printf (
"In moveCommentsToNewStatement(): destinationStatementProceedsSourceStatement = %s \n",destinationStatementProceedsSourceStatement ?
"true" :
"false");
10111 printf (
" --- sourceStatement = %p = %s name = %s \n",sourceStatement,sourceStatement->
class_name().c_str(),
get_name(sourceStatement).c_str());
10112 printf (
" --- destinationStatement = %p = %s name = %s \n",destinationStatement,destinationStatement->
class_name().c_str(),
get_name(destinationStatement).c_str());
10120#if REMOVE_STATEMENT_DEBUG
10121 printf (
"Output the comments attached to sourceStatement: \n");
10123 printf (
"Output the comments attached to destinationStatement: \n");
10128 vector<int>::const_iterator j = indexList.begin();
10130 while (j != indexList.end())
10133 ROSE_ASSERT(destinationStatement->
get_file_info() != NULL);
10134#if REMOVE_STATEMENT_DEBUG || 0
10135 printf (
"Attaching comments to destinationStatement = %p = %s on file = %s line %d \n",
10136 destinationStatement,destinationStatement->
class_name().c_str(),
10137 destinationStatement->
get_file_info()->get_filenameString().c_str(),
10140 printf (
"(*comments)[*j]->getRelativePosition() = %s \n",PreprocessingInfo::relativePositionName((*comments)[*j]->getRelativePosition()).c_str());
10152 if (destinationStatementProceedsSourceStatement ==
true || isSgGlobal(destinationStatement) != NULL )
10158 auto commentPosition = (*comments)[*j]->getRelativePosition();
10159 if (commentPosition == PreprocessingInfo::before)
10162 (*comments)[*j]->setRelativePosition(PreprocessingInfo::after);
10164 else if (commentPosition == PreprocessingInfo::after ||
10165 commentPosition == PreprocessingInfo::end_of)
10171 ROSE_ASSERT(
false &&
"Comment relative position neither, before, after, nor end_of");
10183 (*comments)[*j]->setRelativePosition(PreprocessingInfo::inside);
10194 if ((*comments)[*j]->getRelativePosition() == PreprocessingInfo::before)
10202 ASSERT_require((*comments)[*j]->getRelativePosition() == PreprocessingInfo::after||
10203 (*comments)[*j]->getRelativePosition() == PreprocessingInfo::end_of);
10204 (*comments)[*j]->setRelativePosition(PreprocessingInfo::before);
10213 if (targetInfoList==NULL)
10222 if( prevTargetAnchorComment==NULL)
10235 prevTargetAnchorComment = (*comments)[*j];
10240#if REMOVE_STATEMENT_DEBUG
10241 printf (
"Marking entry from comments list as NULL on sourceStatement = %p = %s \n",sourceStatement,sourceStatement->
class_name().c_str());
10243 (*comments)[*j] =
nullptr;
10250 for (
size_t n = 0; n < indexList.size(); n++)
10252#if REMOVE_STATEMENT_DEBUG || 0
10253 printf (
"Erase entry from comments list on comments->size() %" PRIuPTR
" \n",comments->size());
10255 bool modifiedList =
false;
10256 AttachedPreprocessingInfoType::iterator k = comments->begin();
10257 while (k != comments->end() && modifiedList ==
false)
10262 k = comments->erase(k);
10263 modifiedList =
true;
10285 ROSE_ASSERT(targetStmt != NULL);
10290#if REMOVE_STATEMENT_DEBUG || 0
10291 printf (
"TOP of findSurroundingStatementFromSameFile(): surroundingStatementPreceedsTargetStatement = %s \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false");
10294 std::set<SgStatement*> previousVisitedStatementSet;
10299 surroundingStatementPreceedsTargetStatement =
true;
10301#if REMOVE_STATEMENT_DEBUG
10302 printf (
" targetStmt->get_file_info()->get_file_id() = %d \n",targetStmt->
get_file_info()->get_file_id());
10304#if REMOVE_STATEMENT_DEBUG
10305 printf (
"Before loop: surroundingStatement = %p = %s name = %s surroundingStatement_fileId = %d \n",surroundingStatement,
10308 bool returningNullSurroundingStatement =
false;
10320#if REMOVE_STATEMENT_DEBUG
10321 printf (
"In loop: after getPreviousStatement(): surroundingStatement = %p = %s name = %s \n",surroundingStatement,
10325 if (surroundingStatement == NULL)
10328#if REMOVE_STATEMENT_DEBUG
10329 printf (
" surroundingStatement_fileId set to Sg_File_Info::BAD_FILE_ID \n");
10334 surroundingStatement_fileId = surroundingStatement->
get_file_info()->get_file_id();
10335#if REMOVE_STATEMENT_DEBUG
10336 printf (
" surroundingStatement = %p = %s surroundingStatement->get_file_info()->get_file_id() = %d \n",
10337 surroundingStatement,surroundingStatement->
class_name().c_str(),surroundingStatement->
get_file_info()->get_file_id());
10341#if REMOVE_STATEMENT_DEBUG
10342 if (surroundingStatement != NULL)
10344 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",
10345 surroundingStatement,surroundingStatement->
class_name().c_str(),
10346 surroundingStatement->
get_file_info()->get_filenameString().c_str(),
10352 printf (
"surroundingStatement == NULL \n");
10357 if (previousVisitedStatementSet.find(surroundingStatement) != previousVisitedStatementSet.end())
10359 printf (
"This statement has been previously visited: surroundingStatement = %p = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str());
10361 printf (
"ERROR: SageInterface::findSurroundingStatementFromSameFile(): cannot located surrounding statement from same file (return NULL) \n");
10363 surroundingStatement = NULL;
10369 previousVisitedStatementSet.insert(surroundingStatement);
10373 if (surroundingStatement == NULL || isSgGlobal(surroundingStatement) != NULL)
10376#if REMOVE_STATEMENT_DEBUG
10377 printf (
"We just ran off the start (top) of the file... targetStmt = %p = %s \n",targetStmt,targetStmt->
class_name().c_str());
10383 surroundingStatementPreceedsTargetStatement =
false;
10386 surroundingStatement = targetStmt;
10387 SgStatement* previousStatement = surroundingStatement;
10391 std::set<SgStatement*> forwardVisitedStatementSet;
10394 while ( (surroundingStatement != NULL) && (surroundingStatement_fileId != targetStmt->
get_file_info()->get_file_id()) )
10397 if (forwardVisitedStatementSet.find(surroundingStatement) != forwardVisitedStatementSet.end())
10399 printf (
"This statement has been previously visited: surroundingStatement = %p = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str());
10401 printf (
"ERROR: SageInterface::findSurroundingStatementFromSameFile(): cannot located surrounding statement from same file (return NULL) \n");
10403 surroundingStatement = NULL;
10409 forwardVisitedStatementSet.insert(surroundingStatement);
10412 previousStatement = surroundingStatement;
10415 if (surroundingStatement == NULL)
10418#if REMOVE_STATEMENT_DEBUG
10419 printf (
"We just ran off the end (bottom) of the file... \n");
10424 returningNullSurroundingStatement =
true;
10428 surroundingStatement_fileId = surroundingStatement->
get_file_info()->get_file_id();
10429#if REMOVE_STATEMENT_DEBUG
10430 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",
10431 surroundingStatement,surroundingStatement->
class_name().c_str(),
10432 surroundingStatement->
get_file_info()->get_filenameString().c_str(),
10439 if (surroundingStatement == NULL)
10441#if REMOVE_STATEMENT_DEBUG
10442 printf (
"Resetting the surroundingStatement to the previousStatement = %p = %s \n",previousStatement,previousStatement->
class_name().c_str());
10444 surroundingStatement = previousStatement;
10447 if (surroundingStatement == targetStmt)
10451#if REMOVE_STATEMENT_DEBUG
10452 printf (
"Setting the surroundingStatement to be global scope \n");
10454 surroundingStatement = TransformationSupport::getGlobalScope(targetStmt);
10460 ROSE_ASSERT(surroundingStatement != NULL);
10464 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());
10465 surroundingStatement = NULL;
10468#if REMOVE_STATEMENT_DEBUG
10469 printf (
"BOTTOM of findSurroundingStatementFromSameFile(): surroundingStatementPreceedsTargetStatement = %s surroundingStatement = %p \n",surroundingStatementPreceedsTargetStatement ?
"true" :
"false",surroundingStatement);
10470 if (surroundingStatement != NULL)
10472 printf (
"surroundingStatement = %p = %s \n",surroundingStatement,surroundingStatement->
class_name().c_str());
10478 return surroundingStatement;
10488 virtual void visit(
SgNode* n) {
10492 Visitor().
traverse(root, postorder);
10502 ROSE_ASSERT(oldStmt);
10503 ROSE_ASSERT(newStmt);
10505 if (oldStmt == newStmt)
return;
10516 ROSE_ASSERT (f_do->get_body() == oldStmt);
10517 if (!isSgBasicBlock(newStmt))
10519 f_do->set_body(isSgBasicBlock(newStmt));
10536 printf (
"In SageInterface::replaceStatement(): physical_file_id = %d \n",physical_file_id);
10547 if (movePreprocessingInfoValue)
10555 printf (
"In SageInterface::replaceStatement(): calling moveUpPreprocessingInfo() changed to movePreprocessingInfo() \n");
10567 bool usePrepend =
true;
10569 movePreprocessingInfo ( oldStmt, newStmt, PreprocessingInfo::undef, PreprocessingInfo::undef, usePrepend );
10590 printf (
"In SageInterface::moveDeclarationToAssociatedNamespace(): declarationStatement = %p = %s \n",declarationStatement,declarationStatement->
class_name().c_str());
10591 printf (
" --- previousDeclarationStatement = %p = %s \n",previousDeclarationStatement,previousDeclarationStatement != NULL ? previousDeclarationStatement->
class_name().c_str() :
"null");
10592 printf (
" --- nextDeclarationStatement = %p \n",nextDeclarationStatement);
10593 printf (
" --- nextDeclarationStatement = %p = %s \n",nextDeclarationStatement, nextDeclarationStatement != NULL ? nextDeclarationStatement->
class_name().c_str() :
"null");
10597 if (previousDeclarationStatement != NULL)
10603 printf (
"There is no previous statement so there is no namespace to close off! \n");
10606 printf (
"Exiting as a test! \n");
10611 if (nextDeclarationStatement != NULL)
10618 printf (
"There is no next statement so there is no namespace to reopen! \n");
10622 printf (
"Exiting as a test! \n");
10627 if (previousDeclarationStatement != NULL && nextDeclarationStatement != NULL)
10631 printf (
"Identified the most common case... \n");
10636 printf (
"declarationScope = %p = %s \n",declarationScope,declarationScope->
class_name().c_str());
10640 printf (
"Exiting as a test! \n");
10646 if (previousDeclarationStatement != NULL && nextDeclarationStatement == NULL)
10650 printf (
"Found 2nd most common case: previousDeclarationStatement != NULL && nextDeclarationStatement == NULL \n");
10654 printf (
"Exiting as a test! \n");
10660 if (previousDeclarationStatement == NULL && nextDeclarationStatement == NULL)
10662 printf (
"This case should require no special handling, unless we are still in the wrong namespace \n");
10665 printf (
"Exiting as a test! \n");
10670 printf (
"This case should have been caught above! \n");
10673 printf (
"Exiting as a test! \n");
10680 if (declarationParent == NULL)
10683 printf (
"declarationStatement->get_parent() = %p = %s \n",declarationStatement->
get_parent(), (declarationStatement->
get_parent() != NULL) ? declarationStatement->
get_parent()->
class_name().c_str() :
"null");
10689 if (declarationParent != NULL)
10692 ROSE_ASSERT(declarationScope != NULL);
10695 if (namespaceDefinition != NULL)
10698 ROSE_ASSERT(namespaceDeclaration != NULL);
10700 printf (
"The declaration has been identified to be associuated with a valid namespace = %p = %s \n",namespaceDeclaration,namespaceDeclaration->
get_name().str());
10701 printf (
" --- declarationParent = %p = %s \n",declarationParent,declarationParent->
class_name().c_str());
10702 printf (
" --- Move declaration from scope = %p = %s to namespace = %p = %s \n",declarationParent,declarationParent->
class_name().c_str(),namespaceDeclaration,namespaceDeclaration->
get_name().str());
10705 printf (
"Exiting as a test! \n");
10712 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());
10719 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");
10731 if (isSgTemplateInstantiationDefn(node) != NULL)
10734 printf (
"Note: In SageInterface::isTemplateInstantiationNode(): skipping SgTemplateInstantiationDefn \n");
10738 return isSgTemplateInstantiationDecl(node)
10741 || isSgTemplateInstantiationDefn(node)
10742 || isSgTemplateInstantiationFunctionDecl(node)
10743 || isSgTemplateInstantiationMemberFunctionDecl(node)
10744 || isSgTemplateInstantiationTypedefDeclaration(node)
10745 || isSgTemplateInstantiationDirectiveStatement(node)
10754SageInterface::isTemplateDeclarationNode(
SgNode* node)
10757 if (isSgTemplateDefinition(node) != NULL)
10760 printf (
"Note: In SageInterface::isTemplateDeclarationNode(): skipping SgTemplateDefinition \n");
10764 return isSgTemplateInstantiationDecl(node)
10767 || isSgTemplateInstantiationDefn(node)
10768 || isSgTemplateInstantiationFunctionDecl(node)
10769 || isSgTemplateInstantiationMemberFunctionDecl(node)
10770 || isSgTemplateInstantiationTypedefDeclaration(node)
10771 || isSgTemplateInstantiationDirectiveStatement(node)
10784 std::vector<SgDeclarationStatement*> templateInstantiationVector;
10796 if (declaration != NULL)
10798 templateInstantiationVector.push_back(declaration);
10807 std::cerr <<
"This feature for now is available with autotools only!" << std::endl;
10811 std::vector<SgDeclarationStatement*>::iterator j = templateInstantiationVector.begin();
10812 while (j != templateInstantiationVector.end())
10826 SgExpression * pattern_exp = isSgExpression(new_pattern);
10827 ROSE_ASSERT (anchor_exp != NULL);
10828 ROSE_ASSERT (pattern_exp != NULL);
10831 Rose_STL_Container<SgNode*> opaque_exp_list = NodeQuery::querySubTree(pattern_exp,V_SgExpression);
10832 for (
size_t i = 0; i<opaque_exp_list.size(); i++)
10834 SgExpression* opaque_exp = isSgExpression(opaque_exp_list[i]);
10835 ROSE_ASSERT (opaque_exp != NULL);
10836 if (opaque_exp->
variantT() == V_SgVariantExpression)
10845 return new_pattern;
10852 static int counter = 0;
10855 bool collision =
false;
10858 name =
"__" + baseName + boost::lexical_cast<string > (counter++) +
"__";
10864 collision = (nameSymbol != NULL);
10867 Rose_STL_Container<SgNode*> childScopes = NodeQuery::querySubTree(scope, V_SgScopeStatement);
10869 BOOST_FOREACH(
SgNode* childScope, childScopes)
10875 nameSymbol = childScopeStatement->lookup_symbol(
SgName(name),NULL,NULL);
10877 collision = collision || (nameSymbol != NULL);
10879 }
while (collision);
10889 SgType* variableType = expressionType;
10896 SgType* expressionBaseType = expressionType->
stripType(SgType::STRIP_TYPEDEF_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE);
10901 if (
SgArrayType* arrayType=isSgArrayType(expressionType)) {
10902 if(
SgArrayType* strippedArrayType = isSgArrayType(arrayType->stripType(SgType::STRIP_TYPEDEF_TYPE))) {
10903 SgType* strippedArrayBaseType = strippedArrayType->get_base_type();
10909 if (isSgPointerDerefExp(expression))
10917 ROSE_ASSERT(tempVarInitExpression != NULL);
10928 if (initializeInDeclaration)
10935 ROSE_ASSERT(tempVarDeclaration != NULL);
10938 if (reEvaluate != NULL)
10952 return std::make_pair(tempVarDeclaration, varRefExpression);
10965 SgType* variableType = expressionType;
10968 if (
SgArrayType* arrayType=isSgArrayType(expressionType))
10970 if(
SgArrayType* strippedArrayType = isSgArrayType(arrayType->stripType(SgType::STRIP_TYPEDEF_TYPE))) {
10971 SgType* strippedArrayBaseType = strippedArrayType->get_base_type();
10985 ROSE_ASSERT(tempVarDeclaration != NULL);
10989 return std::make_pair(tempVarDeclaration, varRefExpression);
10996 replaceExpressionInSgExpressionPtrList(
SgExpression* oldExp,
SgExpression* newExp, SgExpressionPtrList& lst,
bool replAll =
false)
10998 SgExpressionPtrList::iterator lim = lst.end();
10999 SgExpressionPtrList::iterator pos = lst.begin();
11004 pos = std::find(pos, lim, oldExp);
11006 if (pos != lim) { *pos = newExp; ++pos; chg =
true; }
11007 }
while (replAll && (pos != lim));
11021 ROSE_ASSERT(oldExp);
11022 ROSE_ASSERT(newExp);
11023 if (oldExp==newExp)
return;
11025 if (isSgVarRefExp(newExp))
11029 ROSE_ASSERT(parent!=NULL);
11035 if (isSgExprStatement(parent)) {
11036 isSgExprStatement(parent)->set_expression(newExp);
11037 }
else if (isSgForStatement(parent)) {
11038 ROSE_ASSERT (isSgForStatement(parent)->get_increment() == oldExp);
11039 isSgForStatement(parent)->set_increment(newExp);
11042 if(matlabFor->get_index() == oldExp)
11043 matlabFor->set_index(newExp);
11044 else if(matlabFor->get_range() == oldExp)
11045 matlabFor->set_range(newExp);
11047 ROSE_ASSERT(!
"sub-expression not found");
11049 if(jovFor->get_initialization() == oldExp)
11050 jovFor->set_initialization(newExp);
11051 else if(jovFor->get_while_expression() == oldExp)
11052 jovFor->set_while_expression(newExp);
11053 else if(jovFor->get_by_or_then_expression() == oldExp)
11054 jovFor->set_by_or_then_expression(newExp);
11056 ROSE_ASSERT(!
"sub-expression not found");
11057 }
else if (
SgRangeExp* rngexp = isSgRangeExp(parent)) {
11058 if (rngexp->get_start() == oldExp)
11059 rngexp->set_start(newExp);
11060 else if (rngexp->get_end() == oldExp)
11061 rngexp->set_end(newExp);
11062 else if (rngexp->get_stride() == oldExp)
11063 rngexp->set_stride(newExp);
11065 ROSE_ASSERT(!
"sub-expression not found");
11066 }
else if (isSgReturnStmt(parent)) {
11067 isSgReturnStmt(parent)->set_expression(newExp);
11068 }
else if (isSgBinaryOp(parent)!=NULL) {
11069 if (oldExp==isSgBinaryOp(parent)->get_lhs_operand()) {
11071 }
else if (oldExp==isSgBinaryOp(parent)->get_rhs_operand()) {
11076 }
else if (isSgUnaryOp(parent)!=NULL){
11077 if (oldExp==isSgUnaryOp(parent)->get_operand_i())
11081 }
else if (isSgConditionalExp(parent) != NULL) {
11091 }
else if (isSgExprListExp(parent) != NULL) {
11092 SgExpressionPtrList& explist = isSgExprListExp(parent)->get_expressions();
11093 for (Rose_STL_Container<SgExpression*>::iterator i=explist.begin();i!=explist.end();i++) {
11094 if (isSgExpression(*i)==oldExp) {
11100 }
else if (isSgValueExp(parent)) {
11105 ROSE_ASSERT(oldExp == actexp->get_expression());
11106 actexp->set_expression(newExp);
11108 if (oldExp == attrexp->get_object()) {
11109 attrexp->set_object(newExp);
11110 }
else if (oldExp == attrexp->get_args()) {
11112 ASSERT_not_null(newLst);
11114 attrexp->set_args(newLst);
11119 }
else if ((parentExp=isSgExpression(parent)) != NULL) {
11122 ROSE_ASSERT (worked);
11123 }
else if (isSgInitializedName(parent)) {
11125 if (oldExp == initializedNameParent->get_initializer()) {
11127 ROSE_ASSERT(isSgInitializer(newExp));
11128 initializedNameParent->set_initializer(isSgInitializer(newExp));
11133 }
else if (isSgCaseOptionStmt(parent)) {
11135 if (oldExp == case_stmt->
get_key()) {
11137 }
else if(oldExp == case_stmt->get_key_range_end()) {
11138 case_stmt->set_key_range_end(newExp);
11142 }
else if (isSgProcessControlStatement(parent)) {
11144 if (oldExp == ctrl_stmt->get_quiet()) {
11145 ctrl_stmt->set_quiet(newExp);
11146 }
else if (oldExp == ctrl_stmt->get_code()) {
11147 ctrl_stmt->set_code(newExp);
11151 }
else if (isSgFortranDo(parent)) {
11153 if (oldExp == fortranDo->get_initialization()) {
11154 fortranDo->set_initialization(newExp);
11155 }
else if(oldExp == fortranDo->get_bound()) {
11156 fortranDo->set_bound(newExp);
11157 }
else if (oldExp == fortranDo->get_increment()) {
11158 fortranDo->set_increment(newExp);
11164 ROSE_ASSERT(oldExp == stm->get_condition());
11165 stm->set_condition(newExp);
11168 ROSE_ASSERT(oldExp == ptype->get_modexpr());
11169 ptype->set_modexpr(newExp);
11172 ROSE_ASSERT(oldExp == stm->get_time());
11173 stm->set_time(newExp);
11175 ROSE_ASSERT(oldExp == clause->get_size());
11176 clause->set_size(newExp);
11178 ROSE_ASSERT(oldExp == dcl->get_renamed());
11179 dcl->set_renamed(newExp);
11181 ROSE_ASSERT(oldExp == dcl->get_entryBarrier());
11182 dcl->set_entryBarrier(newExp);
11184 ROSE_ASSERT(oldExp == stm->get_guard());
11185 stm->set_guard(newExp);
11187 ROSE_ASSERT(oldExp == delc->get_delta());
11188 delc->set_delta(newExp);
11190 ROSE_ASSERT(oldExp == digc->get_digits());
11191 digc->set_digits(newExp);
11193 replaceExpressionInSgExpressionPtrList(oldExp, newExp, disc->get_discriminants());
11195 ROSE_ASSERT(oldExp == rngc->get_range());
11196 rngc->set_range(newExp);
11198 replaceExpressionInSgExpressionPtrList(oldExp, newExp, idxc->get_indexRanges());
11200 ROSE_ASSERT(oldExp == vtdcl->get_discriminant());
11201 vtdcl->set_discriminant(newExp);
11203 ROSE_ASSERT(oldExp == clause->get_alignment());
11204 clause->set_alignment(newExp);
11207 if (newLst && (oldExp == vtwhen->get_choices()))
11208 vtwhen->set_choices(newLst);
11212 if (oldExp == clause->get_offset())
11213 clause->set_offset(newExp);
11214 else if (oldExp == clause->get_range() && isSgRangeExp(newExp))
11215 clause->set_range(isSgRangeExp(newExp));
11216 else if (oldExp == clause->get_component() && isSgVarRefExp(newExp))
11217 clause->set_component(isSgVarRefExp(newExp));
11221 if (oldExp == rendcl->get_renamed_function())
11222 rendcl->set_renamed_function(newExp);
11226 cerr<<
"SageInterface::replaceExpression(). Unhandled parent expression type of SageIII enum value: " <<parent->
class_name()<<endl;
11241 return Rose::getNextStatement(currentStmt);
11250 return isSgIntVal(e) && isSgIntVal(e)->get_value() == value;
11255 ROSE_ASSERT(func1&& func2);
11256 bool result =
false;
11257 if (func1 == func2)
11263 if (func1->get_name() == func2->get_name())
11268 if (func1->get_qualified_name().getString() +
11269 func1->get_mangled_name().getString() ==
11270 func2->get_qualified_name().getString() +
11271 func2->get_mangled_name().getString()
11280 if (func1->get_name() == func2->get_name())
11285 cout<<
"Error: SageInterface::isSameFunction(): unhandled language"<<endl;
11296 bool result =
false;
11297 ROSE_ASSERT(stmt != NULL);
11299 ROSE_ASSERT(p_scope != NULL);
11304 if (stmtlist[stmtlist.size()-1] == stmt)
11310 if (stmtlist[stmtlist.size()-1] == stmt)
11315 if (stmtlist[stmtlist.size()-1] == stmt)
11327 virtual void visit(
SgNode* n) {
11329 if (valueExp != NULL) {
11330 valueExp->set_originalExpressionTree(NULL);
11334 if (cast_exp != NULL) {
11335 cast_exp->set_originalExpressionTree(NULL);
11340 Visitor().traverse(top, preorder);
11345 while (s && !isSgSwitchStatement(s)) {
11349 return isSgSwitchStatement(s);
11354 while (s && !isSgOmpClauseBodyStatement(s)) {
11360 return isSgOmpClauseBodyStatement(s);
11366 for (; s; s = isSgStatement(s->
get_parent())) {
11371 case V_SgDoWhileStmt: {
11372 if (label.empty()) {
11377 case V_SgForStatement: {
11378 if (label.empty()) {
11383 case V_SgFortranDo:
11384 case V_SgFortranNonblockedDo: {
11385 if (label.empty() ||
11386 label == isSgFortranDo(sc)->get_string_label()) {
11391 case V_SgWhileStmt: {
11392 if (label.empty() ||
11393 label == isSgWhileStmt(sc)->get_string_label()) {
11398 case V_SgSwitchStatement: {
11399 if (stopOnSwitches)
return sc;
11402 case V_SgJavaForEachStatement: {
11403 if (label.empty()) {
11408 case V_SgJavaLabelStatement: {
11409 if (label.empty() ||
11410 label == isSgJavaLabelStatement(sc)->get_label().getString()) {
11426 virtual void visit(
SgNode* n) {
11427 if (isSgBasicBlock(n)) {
11429 bool changes =
true;
11432 for (SgStatementPtrList::iterator i = bb->
get_statements().begin();
11434 if (isSgGotoStatement(*i)) {
11436 SgStatementPtrList::iterator inext = i;
11440 if (!isSgLabelStatement(*inext))
11455 RemoveJumpsToNextStatementVisitor().traverse(top, postorder);
11464 ROSE_ASSERT (parent);
11468 ROSE_ASSERT (bb || fis);
11469 SgStatementPtrList& siblings =
11471 SgStatementPtrList::iterator j =
11472 std::find(siblings.begin(), siblings.end(), stmt);
11473 ROSE_ASSERT (j != siblings.end());
11486 SgLabelStatementPtrSet& used;
11487 SgLabelStatementPtrSet& all;
11490 FindUsedAndAllLabelsVisitor(SgLabelStatementPtrSet& used,
11491 SgLabelStatementPtrSet& all):
11492 used(used), all(all) {}
11494 virtual void visit(
SgNode* n) {
11495 if (isSgGotoStatement(n)) {
11496 used.insert(isSgGotoStatement(n)->get_label());
11498 if (isSgLabelStatement(n)) {
11499 all.insert(isSgLabelStatement(n));
11504 SgLabelStatementPtrSet used;
11505 SgLabelStatementPtrSet unused;
11506 FindUsedAndAllLabelsVisitor(used, unused).traverse(top, preorder);
11508 for (SgLabelStatementPtrSet::iterator i = used.begin();
11509 i != used.end(); ++i) {
11510 assert (unused.find(*i) != unused.end());
11523 for (SgLabelStatementPtrSet::iterator i = unused.begin();
11524 i != unused.end(); ++i) {
11532 l_stmt->set_statement(NULL);
11542 if (isSgWhileStmt(loopStmt))
return isSgWhileStmt(loopStmt)->
get_body();
11543 if (isSgForStatement(loopStmt))
return isSgForStatement(loopStmt)->
get_loop_body();
11544 if (isSgDoWhileStmt(loopStmt))
return isSgDoWhileStmt(loopStmt)->
get_body();
11546 ROSE_ASSERT (!
"Bad loop kind");
11551 if (isSgWhileStmt(loopStmt)) {
11552 isSgWhileStmt(loopStmt)->
set_body(body);
11553 }
else if (isSgForStatement(loopStmt)) {
11555 }
else if (isSgDoWhileStmt(loopStmt)) {
11556 isSgDoWhileStmt(loopStmt)->
set_body(body);
11558 ROSE_ASSERT (!
"Bad loop kind");
11564 if (isSgWhileStmt(loopStmt))
return isSgWhileStmt(loopStmt)->
get_condition();
11565 if (isSgForStatement(loopStmt))
return isSgForStatement(loopStmt)->get_test();
11566 if (isSgDoWhileStmt(loopStmt))
return isSgDoWhileStmt(loopStmt)->
get_condition();
11568 ROSE_ASSERT (!
"Bad loop kind");
11573 if (isSgWhileStmt(loopStmt)) {
11575 }
else if (isSgForStatement(loopStmt)) {
11576 isSgForStatement(loopStmt)->set_test(cond);
11577 }
else if (isSgDoWhileStmt(loopStmt)) {
11580 ROSE_ASSERT (!
"Bad loop kind");
11589 SgCastExp* cast_exp = isSgCastExp(exp);
11590 if (cast_exp != NULL)
11593 assert(operand != 0);
11594 return SkipCasting(operand);
11603 ROSE_ASSERT(loop!=NULL);
11605 SgStatementPtrList &init = loop ->get_init_stmt();
11606 if (init.size() !=1)
11617 ROSE_ASSERT(ivarname != NULL);
11619 if (isSgAssignInitializer(initor))
11621 lbast = isSgAssignInitializer(initor)->
get_operand();
11636 ROSE_ASSERT(funcDef!=NULL);
11638 ROSE_ASSERT(funcBody!=NULL);
11640 std::ostringstream os;
11641 os<<ivarname->get_name().getString();
11646 if (visibleSym != NULL)
11657 Rose_STL_Container<SgNode*> varRefs = NodeQuery::querySubTree(loop,V_SgVarRefExp);
11658 for (Rose_STL_Container<SgNode *>::iterator i = varRefs.begin(); i != varRefs.end(); i++)
11661 if (vRef->get_symbol()==osymbol)
11662 vRef->set_symbol(nsymbol);
11667 init.push_back(ninit);
11674 trans_records.forLoopInitNormalizationTable[loop] =
true;
11675 trans_records.forLoopInitNormalizationRecord[loop] = make_pair (decl, ndecl) ;
11688 ROSE_ASSERT (loop != NULL);
11690 if (!trans_records.forLoopInitNormalizationTable[loop])
11695 ROSE_ASSERT (decl!= NULL);
11696 ROSE_ASSERT (ndecl!= NULL);
11700 SgStatementPtrList &init = loop ->get_init_stmt();
11701 ROSE_ASSERT(init.size() ==1);
11706 ROSE_ASSERT (exp_stmt != NULL);
11707 SgAssignOp* assign_op = isSgAssignOp(exp_stmt->get_expression());
11708 ROSE_ASSERT (assign_op != NULL);
11715 init.push_back(decl);
11726 Rose_STL_Container<SgNode*> varRefs = NodeQuery::querySubTree(loop,V_SgVarRefExp);
11727 for (Rose_STL_Container<SgNode *>::iterator i = varRefs.begin(); i != varRefs.end(); i++)
11730 if (vRef->get_symbol()==osymbol)
11731 vRef->set_symbol(nsymbol);
11735 trans_records.forLoopInitNormalizationTable[loop] =
false;
11741 ROSE_ASSERT(loop != NULL);
11748 if (test_stmt!=NULL)
11750 if (isSgNullStatement(test_stmt))
11756 if (isSgBinaryOp(test))
11760 ROSE_ASSERT(testlhs && testrhs);
11765 SgVarRefExp* testlhs_var = isSgVarRefExp(SkipCasting(testlhs));
11766 if (testlhs_var == NULL )
11769 if (var_symbol==NULL)
11773 case V_SgLessThanOp:
11778 case V_SgGreaterThanOp:
11782 case V_SgLessOrEqualOp:
11783 case V_SgGreaterOrEqualOp:
11784 case V_SgNotEqualOp:
11793 ROSE_ASSERT(loop != NULL);
11797 if (isSgBinaryOp(test))
11801 ROSE_ASSERT(testlhs && testrhs);
11806 SgVarRefExp* testlhs_var = isSgVarRefExp(SkipCasting(testlhs));
11807 if (testlhs_var == NULL )
11810 if (var_symbol==NULL)
11816 ROSE_ASSERT(incr != NULL);
11818 case V_SgPlusPlusOp:
11821 SgVarRefExp* incr_var = isSgVarRefExp(SkipCasting(isSgPlusPlusOp(incr)->get_operand()));
11822 if (incr_var == NULL)
return false;
11823 if ( incr_var->get_symbol() != var_symbol)
11829 case V_SgMinusMinusOp:
11832 SgVarRefExp* incr_var = isSgVarRefExp(SkipCasting(isSgMinusMinusOp(incr)->get_operand()));
11833 if (incr_var == NULL)
return false;
11834 if ( incr_var->get_symbol() != var_symbol)
11840 case V_SgMinusAssignOp:
11842 SgVarRefExp* incr_var = isSgVarRefExp(SkipCasting(isSgMinusAssignOp(incr)->get_lhs_operand()));
11844 ROSE_ASSERT (rhs != NULL);
11845 if (incr_var == NULL)
return false;
11846 if ( incr_var->get_symbol() != var_symbol)
11853 case V_SgPlusAssignOp:
11908 bool changed =
false;
11910 if (!switchStmt)
return changed;
11914 if (!bodyBlock)
return changed;
11918 std::vector<SgStatement*> stmts(stmtList.begin(), stmtList.end());
11919 int n =
static_cast<int>(stmts.size());
11923 for (
int i = 0; i < n; ) {
11928 auto processLabel = [&](
SgStatement* labelStmt) {
11932 std::vector<SgStatement*> toWrap;
11934 while (j < n && !isSgCaseOptionStmt(stmts[j]) && !isSgDefaultOptionStmt(stmts[j])) {
11935 toWrap.push_back(stmts[j]);
11942 if (toWrap.size() == 1
11943 && isSgBasicBlock(toWrap[0])
11944 && ((isSgCaseOptionStmt(labelStmt) && !isSgBasicBlock(isSgCaseOptionStmt(labelStmt)->get_body()))
11945 || (isSgDefaultOptionStmt(labelStmt) && !isSgBasicBlock(isSgDefaultOptionStmt(labelStmt)->get_body()))))
11951 if (
auto c = isSgCaseOptionStmt(labelStmt)) {
11952 c->set_body(moved);
11953 }
else if (
auto d = isSgDefaultOptionStmt(labelStmt)) {
11954 d->set_body(moved);
11960 else if (!toWrap.empty()) {
11975 if (
auto caseLabel = isSgCaseOptionStmt(labelStmt)) {
11976 caseLabel->set_body(newBlock);
11977 }
else if (
auto defaultLabel = isSgDefaultOptionStmt(labelStmt)) {
11978 defaultLabel->set_body(newBlock);
11982 for (
auto* w: toWrap) {
11995 if (
auto caseLabel = isSgCaseOptionStmt(curr)) {
11996 i = processLabel(caseLabel);
11997 }
else if (
auto defaultLabel = isSgDefaultOptionStmt(curr)) {
11998 i = processLabel(defaultLabel);
12012 ROSE_ASSERT(loop != NULL);
12030 ROSE_ASSERT(body!=NULL);
12048 ROSE_ASSERT (loop != NULL);
12050 if (isSgNullExpression(e_3))
12053 loop->set_increment(iv);
12068 ROSE_ASSERT(func!=NULL);
12069 AstInterfaceImpl faImpl(func->get_definition()->
get_body());
12070 AstInterface fa(&faImpl);
12071 ArrayAnnotation* annot = ArrayAnnotation::get_inst();
12072 ArrayInterface array_interface (*annot);
12073 array_interface.initialize(fa, AstNodePtrImpl(func->get_definition()));
12074 array_interface.observe(fa);
12075 LoopTransformInterface :: set_astInterface(fa);
12076 LoopTransformInterface :: set_arrayInterface(&array_interface);
12080 AstNodePtr result = AstNodePtrImpl(loop->
get_parent()) ;
12082 LoopUnrolling lu(unrolling_factor);
12085 result = lu(lpTrans, result);
12129#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
12131 if (unrolling_factor <= 1)
12152 cerr<<
"Error in SageInterface::loopUnrolling(): target loop is not canonical."<<endl;
12156 ROSE_ASSERT(ivar&& lb && ub && step);
12157 ROSE_ASSERT(isSgBasicBlock(orig_body));
12160 bool needFringe =
true;
12161 SgForStatement* fringe_loop = deepCopy<SgForStatement>(target_loop);
12179 ROSE_ASSERT(scope != NULL);
12183 attachComment(fringe_decl,
"iter_count = (ub-lb+1)%step ==0?(ub-lb+1)/step: (ub-lb+1)/step+1;");
12184 attachComment(fringe_decl,
"fringe = iter_count%unroll_factor==0 ? 0:unroll_factor*step");
12191 ConstantFolding::constantFoldingOptimization(fringe_decl,
false);
12193 ROSE_ASSERT(ivarname != NULL);
12197 if (isSgIntVal(init1->get_operand_i()))
12198 if (isSgIntVal(init1->get_operand_i())->get_value() == 0)
12199 needFringe =
false;
12203 ROSE_ASSERT(ub_bin_op);
12213 ROSE_ASSERT(step_bin_op != NULL);
12216 bool isPlus =
false;
12217 if (isSgPlusAssignOp(step_bin_op))
12219 else if (isSgMinusAssignOp(step_bin_op))
12223 cerr<<
"Error in SageInterface::loopUnrolling(): illegal incremental exp of a canonical loop"<<endl;
12229 for (
size_t i =1; i<unrolling_factor; i++)
12233 std::vector<SgVarRefExp*> refs = querySubTree<SgVarRefExp> (body, V_SgVarRefExp);
12234 for (std::vector<SgVarRefExp*>::iterator iter = refs.begin(); iter !=refs.end(); iter++)
12263 ConstantFolding::constantFoldingOptimization(scope,
false);
12275static size_t myfactorial (
size_t n)
12278 for (
size_t i=2; i<=n; i++)
12289std::vector<size_t> getPermutationOrder(
size_t n,
size_t lexicoOrder)
12291 size_t k = lexicoOrder;
12292 std::vector<size_t> s(n);
12294 for (
size_t i=0; i<n; i++)
12298 size_t factorial = myfactorial(n-1);
12300 if (k/n>=factorial)
12302 printf(
"Error: in getPermutationOrder(), lexicoOrder is larger than n!-1\n");
12318 for (
size_t j=0; j<n-1; j++)
12322 int tempj = (k/factorial) % (n - j);
12325 int temps = s[j+tempj];
12328 for (
size_t i=j+tempj; i>j; i--)
12335 factorial = factorial /(n-(j+1));
12338 for (
size_t i = 0; i<n; i++)
12370 ROSE_ASSERT(loopNest != NULL);
12371 ROSE_ASSERT(targetLevel >0);
12378 std::vector<SgForStatement* > loops= SageInterface::querySubTree<SgForStatement>(loopNest,V_SgForStatement);
12379 ROSE_ASSERT(loops.size()>=targetLevel);
12397 cerr<<
"Error in SageInterface::loopTiling(): target loop is not canonical."<<endl;
12401 ROSE_ASSERT(ivar&& lb && ub && step);
12409 parent = isSgLocatedNode(loopNest ->get_parent());
12411 ROSE_ASSERT(parent!= NULL);
12413 string ivar2_name =
"_lt_var_"+ivar->get_name().getString();
12423 if (isSgBinaryOp(orig_test))
12425 if (isSgLessOrEqualOp(orig_test))
12427 else if (isSgGreaterOrEqualOp(orig_test))
12433 cerr<<
"Error: illegal condition operator for a canonical loop"<<endl;
12440 cerr<<
"Error: illegal condition expression for a canonical loop"<<endl;
12444 ROSE_ASSERT(cond_stmt != NULL);
12449 SgExpression* orig_incr_exp = target_loop->get_increment();
12450 if( isSgPlusAssignOp(orig_incr_exp))
12454 else if (isSgMinusAssignOp(orig_incr_exp))
12460 cerr<<
"Error: illegal increment expression for a canonical loop"<<endl;
12472 ROSE_ASSERT(assign_op);
12476 ROSE_ASSERT(bin_op);
12496 if (lexicoOrder == 0)
12499 ROSE_ASSERT(loop != NULL);
12501 ROSE_ASSERT (depth >1);
12502 ROSE_ASSERT(lexicoOrder<myfactorial(depth));
12505 std::vector<SgForStatement* > loopNest = SageInterface::querySubTree<SgForStatement>(loop,V_SgForStatement);
12506 ROSE_ASSERT(loopNest.size()>=depth);
12507 std::vector<std::vector<SgNode*> > loopHeads;
12508 for (std::vector<SgForStatement* > ::iterator i = loopNest.begin(); i!= loopNest.end(); i++)
12511 std::vector<SgNode*> head;
12513 head.push_back(cur_loop->get_test());
12514 head.push_back(cur_loop->get_increment());
12515 loopHeads.push_back(head);
12519 std::vector<size_t> changedOrder = getPermutationOrder (depth, lexicoOrder);
12522 for (
size_t i=0; i<depth; i++)
12525 if (i != changedOrder[i])
12528 std::vector<SgNode*> newhead = loopHeads[changedOrder[i]];
12536 init->set_parent(cur_loop);
12541 cur_loop->set_test(test);
12549 cur_loop->set_increment(incr);
12563 ROSE_ASSERT(loop != NULL);
12569 SgAssignOp* assign_op = isSgAssignOp (do_loop->get_initialization());
12570 ROSE_ASSERT (assign_op != NULL);
12572 ROSE_ASSERT (var != NULL);
12573 ivarname = var->get_symbol()->get_declaration();
12574 ROSE_ASSERT (ivarname != NULL);
12588 SgStatementPtrList & init = fs->get_init_stmt();
12589 if (init.size() !=1)
12591 cerr<<
"SageInterface::getLoopIndexVariable(), no or more than one initialization statements are encountered. Not supported yet "<<endl;
12602 if (isSgVariableDeclaration(init1))
12606 ROSE_ASSERT(ivarname != NULL);
12613 SgVarRefExp* var = isSgVarRefExp(SkipCasting(ivarast));
12616 ivarname = var->get_symbol()->get_declaration();
12623 if (
SgCommaOpExp* comma_exp = isSgCommaOpExp(exp_stmt->get_expression()))
12630 SgVarRefExp* var = isSgVarRefExp(assign_op->get_lhs_operand());
12633 ivarname = var->get_symbol()->get_declaration();
12641 mlog[Sawyer::Message::Common::WARN] <<
"Warning: SageInterface::getLoopIndexVariable(). Unhandled init_stmt type of SgForStatement"<<endl;
12642 mlog[Sawyer::Message::Common::WARN] <<
"Init statement is :"<<init1->
class_name() <<
" " <<init1->
unparseToString()<<endl;
12660 ROSE_ASSERT (ivar != NULL);
12661 ROSE_ASSERT (subtree_root != NULL);
12662 bool result =
false;
12667 if (i_index == ivar)
12687 ROSE_ASSERT (loop !=NULL);
12688 SgStatementPtrList& stmt_list = loop->get_init_stmt();
12689 if (stmt_list.size() >1)
return true;
12690 if (stmt_list.size() == 0)
return false;
12695 if (decl_stmt != NULL)
12700 ROSE_ASSERT (exp_stmt != NULL);
12701 if (isSgCommaOpExp (exp_stmt->get_expression()) )
12711 ROSE_ASSERT(loop != NULL);
12719 SgAssignOp* init_assign = isSgAssignOp (init);
12724 bool isCase1=
false;
12729 ivarname = var->get_symbol()->get_declaration();
12731 if (ivarname && lbast )
12743 SgBinaryOp* test = isSgBinaryOp(fs->get_test_expr());
12747 case V_SgLessOrEqualOp:
12748 if (isInclusiveUpperBound != NULL)
12749 *isInclusiveUpperBound =
true;
12750 if (hasIncrementalIterationSpace != NULL)
12751 *hasIncrementalIterationSpace =
true;
12753 case V_SgLessThanOp:
12754 if (isInclusiveUpperBound != NULL)
12755 *isInclusiveUpperBound =
false;
12756 if (hasIncrementalIterationSpace != NULL)
12757 *hasIncrementalIterationSpace =
true;
12759 case V_SgGreaterOrEqualOp:
12760 if (isInclusiveUpperBound != NULL)
12761 *isInclusiveUpperBound =
true;
12762 if (hasIncrementalIterationSpace != NULL)
12763 *hasIncrementalIterationSpace =
false;
12765 case V_SgGreaterThanOp:
12766 if (isInclusiveUpperBound != NULL)
12767 *isInclusiveUpperBound =
false;
12768 if (hasIncrementalIterationSpace != NULL)
12769 *hasIncrementalIterationSpace =
false;
12778 if (testvar == NULL)
12784 ubast = loop->get_bound();
12786 if (isInclusiveUpperBound != NULL)
12787 *isInclusiveUpperBound =
true;
12790 ROSE_ASSERT (incr != NULL);
12791 if (isSgNullExpression(incr))
12793 cerr<<
"Error:isCanonicalDoLoop() found NULL increment expression. Please call doLoopNormalization() first!"<<endl;
12794 ROSE_ASSERT (
false);
12796 if (hasIncrementalIterationSpace != NULL)
12798 *hasIncrementalIterationSpace =
true;
12800 if (
SgIntVal* i_v = isSgIntVal(incr))
12802 if (i_v->get_value()<0)
12803 *hasIncrementalIterationSpace =
false;
12809 case V_SgPlusAssignOp:
12810 case V_SgMinusAssignOp:
12811 incr_var = isSgVarRefExp(SkipCasting(isSgBinaryOp(incr)->get_lhs_operand()));
12814 case V_SgPlusPlusOp:
12815 case V_SgMinusMinusOp:
12816 incr_var = isSgVarRefExp(SkipCasting(isSgUnaryOp(incr)->get_operand()));
12822 if (incr_var == NULL)
12836 if (body != NULL) {
12837 *body = fs->get_body();
12874 ROSE_ASSERT (s != NULL);
12877 std::set<SgNode*> bset = SgNodeHelper::loopRelevantBreakStmtNodes (s);
12878 if (bset.size()!=0 )
12892 ROSE_ASSERT(loop != NULL);
12903 SgStatementPtrList & init = fs->get_init_stmt();
12904 if (init.size() !=1)
12907 SgExpression* ivarast=NULL, *lbast=NULL, *ubast=NULL, *stepast=NULL;
12910 bool isCase1=
false, isCase2=
false;
12912 if (isSgVariableDeclaration(init1))
12916 ROSE_ASSERT(ivarname != NULL);
12918 if (isSgAssignInitializer(initor))
12920 lbast = isSgAssignInitializer(initor)->
get_operand();
12926 SgVarRefExp* var = isSgVarRefExp(SkipCasting(ivarast));
12929 ivarname = var->get_symbol()->get_declaration();
12934 ROSE_ASSERT(!(isCase1&&isCase2));
12936 if (!(isCase1||isCase2))
12948 case V_SgLessOrEqualOp:
12949 if (isInclusiveUpperBound != NULL)
12950 *isInclusiveUpperBound =
true;
12951 if (hasIncrementalIterationSpace != NULL)
12952 *hasIncrementalIterationSpace =
true;
12954 case V_SgLessThanOp:
12955 if (isInclusiveUpperBound != NULL)
12956 *isInclusiveUpperBound =
false;
12957 if (hasIncrementalIterationSpace != NULL)
12958 *hasIncrementalIterationSpace =
true;
12960 case V_SgGreaterOrEqualOp:
12961 if (isInclusiveUpperBound != NULL)
12962 *isInclusiveUpperBound =
true;
12963 if (hasIncrementalIterationSpace != NULL)
12964 *hasIncrementalIterationSpace =
false;
12966 case V_SgGreaterThanOp:
12967 if (isInclusiveUpperBound != NULL)
12968 *isInclusiveUpperBound =
false;
12969 if (hasIncrementalIterationSpace != NULL)
12970 *hasIncrementalIterationSpace =
false;
12979 if (testvar == NULL)
13003 case V_SgPlusAssignOp:
13004 case V_SgMinusAssignOp:
13005 incr_var = isSgVarRefExp(SkipCasting(isSgBinaryOp(incr)->get_lhs_operand()));
13008 case V_SgPlusPlusOp:
13009 case V_SgMinusMinusOp:
13010 incr_var = isSgVarRefExp(SkipCasting(isSgUnaryOp(incr)->get_operand()));
13013 case V_SgAssignOp: {
13014 incr_var=isSgVarRefExp(SkipCasting(isSgBinaryOp(incr)->get_lhs_operand()));
13015 if(incr_var == NULL)
13017 SgAddOp* addOp=isSgAddOp(SkipCasting(isSgBinaryOp(incr)->get_rhs_operand()));
13018 SgSubtractOp* subtractOp=isSgSubtractOp(SkipCasting(isSgBinaryOp(incr)->get_rhs_operand()));
13022 else if(subtractOp)
13023 arithOp=subtractOp;
13026 ROSE_ASSERT(arithOp!=0);
13027 if(
SgVarRefExp* varRefExp=isSgVarRefExp(SkipCasting(isSgBinaryOp(arithOp)->get_lhs_operand()))) {
13029 incr_var=varRefExp;
13031 }
else if(
SgVarRefExp* varRefExp=isSgVarRefExp(SkipCasting(isSgBinaryOp(arithOp)->get_rhs_operand()))) {
13032 if(isSgAddOp(arithOp)) {
13034 incr_var=varRefExp;
13044 if (incr_var == NULL)
13065 if (body != NULL) {
13074 ROSE_ASSERT(loop != NULL);
13075 ROSE_ASSERT(lb != NULL);
13080 if (forstmt != NULL)
13085 Rose_STL_Container<SgNode* > testList = NodeQuery::querySubTree( *((forstmt->get_init_stmt()).begin()), V_SgAssignOp);
13086 if (testList.size()>0)
13088 ROSE_ASSERT(testList.size()==1);
13089 SgAssignOp * assignop = isSgAssignOp((*testList.begin()));
13090 ROSE_ASSERT(assignop);
13100 Rose_STL_Container<SgNode* > testList = NodeQuery::querySubTree( *((forstmt->get_init_stmt()).begin()), V_SgAssignInitializer );
13101 ROSE_ASSERT(testList.size()==1);
13103 ROSE_ASSERT(init != NULL);
13104 init->set_operand(lb);
13109 else if (dostmt != NULL)
13112 ROSE_ASSERT (init != NULL);
13114 ROSE_ASSERT (a_op!=NULL);
13121 cerr<<
"Error. SageInterface::setLoopLowerBound(), illegal loop type:"<< loop->
class_name()<<endl;
13122 ROSE_ASSERT (
false);
13129 ROSE_ASSERT(loop != NULL);
13130 ROSE_ASSERT(ub != NULL);
13134 if (forstmt != NULL)
13137 SgBinaryOp * binop= isSgBinaryOp(isSgExprStatement(forstmt->get_test())->get_expression());
13138 ROSE_ASSERT(binop != NULL);
13142 else if (dostmt != NULL)
13144 dostmt->set_bound(ub);
13150 cerr<<
"Error. SageInterface::setLoopUpperBound(), illegal loop type:"<< loop->
class_name()<<endl;
13151 ROSE_ASSERT (
false);
13159 ROSE_ASSERT(loop != NULL);
13160 ROSE_ASSERT(stride != NULL);
13164 if (dostmt != NULL)
13166 dostmt->set_increment(stride);
13170 else if (forstmt != NULL)
13174 Rose_STL_Container<SgNode*> testList = NodeQuery::querySubTree( forstmt->get_increment(), V_SgPlusPlusOp);
13175 if (testList.size()>0)
13177 ROSE_ASSERT(testList.size() == 1);
13179 (isSgPlusPlusOp( *testList.begin())->
get_operand()));
13181 forstmt->set_increment(plusassignop);
13185 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgMinusMinusOp);
13186 if (testList.size()>0)
13188 ROSE_ASSERT(testList.size()==1);
13190 (isSgMinusMinusOp(*testList.begin())->
get_operand()));
13192 forstmt->set_increment(plusassignop);
13196 testList = NodeQuery::querySubTree( forstmt->get_increment(), V_SgPlusAssignOp);
13197 if (testList.size()>0)
13199 ROSE_ASSERT(testList.size()==1);
13200 SgPlusAssignOp * assignop = isSgPlusAssignOp(*(testList.begin()));
13201 ROSE_ASSERT(assignop!=NULL);
13206 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgMinusAssignOp);
13207 if (testList.size()>0)
13209 ROSE_ASSERT(testList.size()==1);
13212 SgExprStatement* exprstmt = isSgExprStatement((*testList.begin())->get_parent());
13213 ROSE_ASSERT(exprstmt !=NULL);
13215 exprstmt->set_expression(plusassignop);
13226 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgAddOp);
13227 if (testList.size()>0)
13229 ROSE_ASSERT(testList.size()==1);
13231 SgAddOp * addop = isSgAddOp(*(testList.begin()));
13232 ROSE_ASSERT(addop!=NULL);
13246 testList = NodeQuery::querySubTree(forstmt->get_increment(), V_SgSubtractOp);
13247 if (testList.size()>0)
13249 ROSE_ASSERT(testList.size()==1);
13251 SgSubtractOp * subtractop = isSgSubtractOp(*(testList.begin()));
13252 ROSE_ASSERT(subtractop!=NULL);
13255 SgAssignOp *assignop = isSgAssignOp((*testList.begin())->get_parent());
13256 ROSE_ASSERT(assignop !=NULL);
13263 cerr<<
"Error. SageInterface::setLoopStride(), illegal loop type:"<< loop->
class_name()<<endl;
13264 ROSE_ASSERT (
false);
13275 SgExpression *exp = (n != 0)? n->get_expression() : isSgExpression(s);
13278 case V_SgPlusAssignOp:
13279 case V_SgMinusAssignOp:
13280 case V_SgAndAssignOp:
13281 case V_SgIorAssignOp:
13282 case V_SgMultAssignOp:
13283 case V_SgDivAssignOp:
13284 case V_SgModAssignOp:
13285 case V_SgXorAssignOp:
13293 if ( init->variantT() == V_SgAssignInitializer)
13294 init = isSgAssignInitializer(init)->
get_operand();
13298 *readlhs = (exp->
variantT() != V_SgAssignOp);
13312 Rose_STL_Container<SgNode*> gotos = NodeQuery::querySubTree(top,V_SgGotoStatement);
13313 for (
size_t i = 0; i < gotos.size(); ++i)
13318 if (!lsParent)
continue;
13321 size_t j = std::find(bbStatements.begin(), bbStatements.end(), ls) - bbStatements.begin();
13323 ROSE_ASSERT (j != bbStatements.size());
13325 while (j < bbStatements.size() - 1 && isSgLabelStatement(bbStatements[j + 1]))
13329 gs->
set_label(isSgLabelStatement(bbStatements[j]));
13345 ROSE_ASSERT(decl != NULL);
13346 ROSE_ASSERT(assign_stmt != NULL);
13349 SgAssignOp * assign_op = isSgAssignOp (assign_stmt->get_expression());
13350 if (assign_op == NULL)
13353 if (assign_op_var == NULL)
return false;
13357 if (decl_var->get_initptr()!= NULL )
return false;
13364 if (decl_var_symbol!=NULL)
13367 if (assign_op_var->get_symbol() != decl_var_symbol)
return false;
13372 if (assign_op_var->get_symbol()->
get_name() != decl_var ->get_name())
return false;
13386 if (removeAssignStmt)
13390 decl_var->set_initptr(initor);
13401 ROSE_ASSERT(assign_stmt != NULL);
13402 SgAssignOp * assign_op = isSgAssignOp (assign_stmt->get_expression());
13403 if (assign_op == NULL)
13406 if (assign_op_var == NULL)
13410 ROSE_ASSERT(decl != NULL);
13412 if (decl_var->get_initptr()!= NULL)
13419 ROSE_ASSERT(decl_var != NULL);
13421 if (decl_var_symbol != NULL) {
13423 if (assign_op_var->get_symbol() != decl_var_symbol)
13429 if (assign_op_var->get_symbol()->
get_name() != decl_var ->get_name())
13442 decl_var->set_initptr(initor);
13472 ROSE_ASSERT (decl != NULL);
13476 if (initor == NULL)
13483 rhs = ainitor->get_operand();
13489 decl_var->set_initptr(NULL);
13501 cerr<<
"SageInterface::splitVariableDeclaration() topLevelOnly == false is not yet implemented."<<endl;
13502 ROSE_ASSERT (
false);
13505 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(scope, V_SgVariableDeclaration);
13506 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
13511 ROSE_ASSERT(decl != NULL);
13524 ROSE_ASSERT (root != NULL);
13527 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(root, V_SgVarRefExp);
13531 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
13534 ROSE_ASSERT (vRef != NULL);
13535 result.push_back(vRef);
13542 ROSE_ASSERT (root != NULL);
13543 Rose_STL_Container<SgNode*> constructorList= NodeQuery::querySubTree(root, V_SgConstructorInitializer);
13544 for (
size_t i =0; i< constructorList.size(); i++)
13549 Rose_STL_Container<SgNode*> varList = NodeQuery::querySubTree (a_type->get_index(),V_SgVarRefExp);
13550 for (
size_t j =0 ; j< varList.size(); j++)
13552 SgVarRefExp* var_exp = isSgVarRefExp(varList[j]) ;
13553 currentVarRefList.push_back(var_exp);
13577 SgExpression* lhsCopy = isSgExpression(lhs->copy(treeCopy));
13578 ROSE_ASSERT (lhsCopy);
13602 SgExpression* lhsCopy = isSgExpression(lhs->copy(treeCopy));
13603 ROSE_ASSERT (lhsCopy);
13627 SgExpression* lhsCopy = isSgExpression(lhs->copy(treeCopy));
13628 ROSE_ASSERT (lhsCopy);
13645 ROSE_ASSERT(from != NULL);
13647#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
13651 ROSE_ASSERT (
false);
13656 SgStatement* stmt = getStatementOfExpression(from);
13658 if (!isSgForInitStatement(stmt->
get_parent())) {
13667 if (!parent && isSgForInitStatement(stmt->
get_parent()))
13673 SgName varname =
"rose_temp__";
13674 if (newName ==
"") {
13682 vector<SgExpression*> ancestors;
13683 for (
SgExpression *expr = from, *anc = isSgExpression(fromparent); anc != 0;
13684 expr = anc, anc = isSgExpression(anc->get_parent()))
13686 if ((isSgAndOp(anc) && expr != isSgAndOp(anc)->get_lhs_operand()) ||
13689 ancestors.push_back(anc);
13692 for (vector<SgExpression*>::reverse_iterator ai = ancestors.rbegin(); ai != ancestors.rend(); ++ai)
13695 switch ((*ai)->variantT()) {
13700 case V_SgConditionalExp:
13702 default: assert (!
"Should not happen"); abort();
13707 if (ancestors.size() != 0) {
13715 ROSE_ASSERT (initname);
13717 replaceExpressionWithExpression(from, varref);
13721 initname->set_initializer(ai);
13723 myStatementInsert(stmt, vardecl,
true);
13744 SplitStatementGenerator gen;
13750 Rose_STL_Container<SgNode*> gotos = NodeQuery::querySubTree(top,
13751 V_SgGotoStatement);
13752 map<SgLabelStatement*, SgLabelStatement*> labelsToReplace;
for
13753 (
size_t i = 0; i < gotos.size(); ++i) {
13756 if (!gsParent)
continue;
13758 size_t j = std::find(bbStatements.begin(), bbStatements.end(), gs)
13759 - bbStatements.begin();
13760 ROSE_ASSERT (j != bbStatements.size());
13761 if (j == 0)
continue;
13762 if (isSgLabelStatement(bbStatements[j - 1])) {
13763 labelsToReplace[isSgLabelStatement(bbStatements[j - 1])] =
13767 for (
size_t i = 0; i < gotos.size(); ++i) {
13770 while (labelsToReplace.find(oldLabel) != labelsToReplace.end()) {
13771 oldLabel = labelsToReplace[oldLabel];
13781 case V_SgBoolValExp:
return (isSgBoolValExp(e)->get_value() != 0);
13783 case V_SgBoolValExp:
return (isSgBoolValExp(e)->get_value() ==
true);
13785 case V_SgIntVal:
return isSgIntVal(e)->get_value() != 0;
13786 case V_SgCastExp:
return isConstantTrue(isSgCastExp(e)->get_operand());
13788 case V_SgAddressOfOp:
return true;
13789 default:
return false;
13795 case V_SgBoolValExp:
return isSgBoolValExp(e)->get_value() ==
false;
13796 case V_SgIntVal:
return isSgIntVal(e)->get_value() == 0;
13797 case V_SgCastExp:
return
13799 case V_SgNotOp:
return isConstantTrue(isSgNotOp(e)->get_operand());
13800 default:
return false;
13807 if (!fc)
return false;
13809 if (fr == NULL)
return false;
13810 return fr->get_symbol()->get_declaration() == decl;
13816 if (!fc)
return false;
13818 if (fr == NULL)
return false;
13820 fr->get_symbol()->get_declaration()->get_qualified_name().getString();
13821 return (name == qualifiedName &&
13822 fc->get_args()->get_expressions().size() == arity);
13827 ROSE_ASSERT( e != NULL);
13843 ROSE_ASSERT(expList);
13845 expList->append_expression(exp);
13851 for (
size_t i = 0; i < exp.size(); ++i)
13860template <
class actualFunction>
13870 ROSE_ASSERT(paralist);
13875 cerr <<
"Waring! Setting a used SgFunctionParameterList to function: "
13876 << (func->get_name()).getString()<<endl
13877 <<
" Sharing parameter lists can corrupt symbol tables!"<<endl
13878 <<
" Please use deepCopy() to get an exclusive parameter list for each function declaration!"<<endl;
13883 if (func->get_parameterList() != NULL)
13884 if (func->get_parameterList() != paralist)
13885 delete func->get_parameterList();
13887 func->set_parameterList(paralist);
13895 ROSE_ASSERT(paraList != NULL);
13896 ROSE_ASSERT(initName != NULL);
13898 if (isPrepend ==
true)
13899 paraList->prepend_arg(initName);
13901 paraList->append_arg(initName);
13908 ROSE_ASSERT(initName->
get_parent() == paraList);
13918 if (func_decl != NULL)
13924 ROSE_ASSERT(func_def);
13934 initName->set_declptr(func_decl);
13946 initName->set_scope(scope);
13966 return addArg(paraList,initName,
false);
13971 return addArg(paraList,initName,
true);
13977 ROSE_ASSERT(pragma);
13978 if (decl->get_pragma()!=NULL)
delete (decl->get_pragma());
13979 decl->set_pragma(pragma);
13990 void testAstForUniqueNodes (
SgNode* node );
13993 printf (
"In SageInterface::appendStatement(): stmt = %p = %s scope = %p \n",stmt,stmt->
class_name().c_str(),scope);
14002 printf (
" --- scope was not specified as input! \n");
14007 ROSE_ASSERT(stmt != NULL);
14008 ROSE_ASSERT(scope != NULL);
14011 printf (
"In SageInterface::appendStatement(): stmt = %p = %s scope = %p = %s \n",stmt,stmt->
class_name().c_str(),scope,scope->
class_name().c_str());
14018 if (declarationStatement != NULL)
14046 scope->insertStatementInScope(stmt,
false);
14050 bool skipAddingStatement =
false;
14052 if (classDeclaration != NULL)
14058 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());
14064 skipAddingStatement = (classDeclaration->get_isAutonomousDeclaration() ==
false);
14068 skipAddingStatement = (classDeclaration->get_isAutonomousDeclaration() ==
false) || (classDeclaration->
get_parent() != NULL);
14083 if (statementAlreadyExistsInScope ==
true)
14085 if (isSgTemplateInstantiationDecl(classDeclaration) != NULL)
14089#if PRINT_DEVELOPER_WARNINGS
14090 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",
14098 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",
14103 skipAddingStatement =
true;
14110 if (enumDeclaration != NULL)
14113 skipAddingStatement = (enumDeclaration->get_isAutonomousDeclaration() ==
false);
14122 if (skipAddingStatement ==
false && statementAlreadyExistsInScope ==
true)
14125 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",
14129 printf (
"Exiting as a test! \n");
14132 skipAddingStatement =
true;
14137 printf (
" --- skipAddingStatement = %s \n",skipAddingStatement ?
"true" :
"false");
14140 if (skipAddingStatement ==
false)
14152 printf (
" --- calling insertStatementInScope(): scope = %p = %s stmt = %p = %s \n",scope,scope->
class_name().c_str(),stmt,stmt->
class_name().c_str());
14154 scope->insertStatementInScope(stmt,
false);
14181 testAstForUniqueNodes(scope);
14190 ROSE_ASSERT (stmt != NULL);
14191 ROSE_ASSERT (for_init_stmt != NULL);
14194 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());
14203 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());
14211 for_init_stmt->append_init_stmt (stmt);
14217 for (
size_t i = 0; i < stmts.size(); ++i)
14220#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
14221 printf (
"In appendStatementList(): stmts[i = %" PRIuPTR
"] = %p = %s \n",i,stmts[i],stmts[i]->class_name().c_str());
14227 if (stmts[i]->get_parent() != NULL)
14230#ifdef ROSE_DEBUG_NEW_EDG_ROSE_CONNECTION
14231 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());
14238 printf (
" --- WARNING: In appendStatementList(): stmts[i = %" PRIuPTR
"] not added to scope (because stmts[i]->get_parent() == NULL) \n",i);
14247 ROSE_ASSERT (stmt != NULL);
14250 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p \n",stmt,stmt->
class_name().c_str(),scope);
14260 ROSE_ASSERT(scope != NULL);
14270 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: stmt) \n",
14282 printf (
"In SageInterface::prependStatement(): stmt = %p = %s scope = %p = %s (resetInternalMapsForTargetStatement: scope) \n",
14294 printf (
"Calling insertStatementInScope() \n");
14300 scope->insertStatementInScope(stmt,
true);
14320 printf (
"Leaving SageInterface::prependStatement() \n");
14328 ROSE_ASSERT (stmt != NULL);
14329 ROSE_ASSERT (for_init_stmt != NULL);
14332 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());
14341 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());
14349 for_init_stmt->prepend_init_stmt (stmt);
14354 for (
size_t i = stmts.size(); i > 0; --i)
14366 ROSE_ASSERT (scope != NULL);
14369 case V_SgBasicBlock:
14370 case V_SgClassDefinition:
14371 case V_SgFunctionDefinition:
14373 case V_SgNamespaceDefinitionStatement:
14377 case V_SgAssociateStatement :
14378 case V_SgBlockDataStatement :
14379 case V_SgCatchOptionStmt:
14380 case V_SgDoWhileStmt:
14381 case V_SgForAllStatement:
14382 case V_SgForStatement:
14383 case V_SgFortranDo:
14385 case V_SgSwitchStatement:
14386 case V_SgUpcForAllStatement:
14387 case V_SgWhileStmt:
14392 cout<<
"unrecognized or unhandled scope type for SageInterface::hasSimpleChildrenList() "<<endl;
14405 SgDeclarationStatementPtrList & declarationList = globalScope->
get_declarations();
14408 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
14410 while (i != declarationList.end() && (*i)->get_file_info() != NULL && (*i)->get_file_info()->isFrontendSpecific() ==
true)
14413 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");
14415 last_statement = *i;
14420 ROSE_ASSERT(last_statement != NULL);
14422 printf (
"last_statement = %p = %s \n",last_statement,last_statement->
class_name().c_str());
14425 printf (
"Exiting as a test! \n");
14429 return last_statement;
14438 ROSE_ASSERT(targetStmt &&newStmt);
14439 ROSE_ASSERT(targetStmt != newStmt);
14441 if (isSgGlobal(targetStmt) ||
14442 isSgClassDefinition(targetStmt)||
14443 isSgNamespaceDefinitionStatement(targetStmt)||
14444 isSgFunctionParameterList(targetStmt)||
14445 isSgFunctionDefinition(targetStmt)||
14446 isSgCtorInitializerList(targetStmt))
14448 string className = targetStmt->
class_name();
14449 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.";
14450 cerr<<err_msg<<endl;
14451 ROSE_ASSERT (
false);
14455 if (isSgCaseOptionStmt(targetStmt))
14457 if (!isSgCaseOptionStmt(newStmt))
14459 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;
14460 ROSE_ASSERT(
false);
14465 if (parent == NULL)
14467 cerr <<
"Empty parent pointer for target statement. May be caused by the wrong order of target and new statements in insertStatement(targetStmt, newStmt)"<<endl;
14468 ROSE_ASSERT(parent);
14490 if ( isSgCaseOptionStmt(parent))
14492 if ( isSgVariableDeclaration(newStmt))
14494 cerr<<
"Error: you cannot insert a variable declaration stmt inside a case option statement without enclosing brances in between."<<endl;
14495 cerr<<
"parent of target is a case option stmt:"<<parent <<endl;
14496 cerr<<
"new statement is a variable statement:"<<newStmt <<endl;
14497 ASSERT_require(
false);
14501 if (isSgLabelStatement(parent) !=
nullptr)
14505 ROSE_ASSERT(isSgLabelStatement(parent) == NULL);
14508 if (isSgFunctionDefinition(parent) ||
14509 isSgTypedefDeclaration(parent) ||
14510 isSgSwitchStatement(parent) ||
14511 isSgVariableDeclaration(parent))
14514 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.";
14515 cerr<<err_msg<<endl;
14518 if (switch_stmt->get_item_selector() == targetStmt)
14520 cerr<<
"The target statement is the item selector of a switch statement. You cannot insert any statement before or after it."<<endl;
14524 ROSE_ASSERT (
false);
14528 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());
14546 ROSE_ASSERT(scope);
14549 printf (
"targetStmt = %p = %s \n",targetStmt,targetStmt->
class_name().c_str());
14550 printf (
"scope = %p = %s \n",scope,scope->
class_name().c_str());
14568 ROSE_ASSERT(isSgStatement(parent) != NULL);
14573 ROSE_ASSERT(targetStmt != NULL);
14577 printf (
"In SageInterface::insertStatement(): after checking for associated comments \n");
14578 reportNodesMarkedAsModified(scope);
14584 if (autoMovePreprocessingInfo)
14586 if (comments != NULL && isSgBasicBlock(newStmt) == NULL)
14588 vector<int> captureList;
14590 printf (
"Found attached comments (at %p = %s, inserting %p = %s insertBefore = %s): comments->size() = %" PRIuPTR
" \n",
14591 targetStmt,targetStmt->
class_name().c_str(),newStmt,newStmt->
class_name().c_str(),insertBefore ?
"true" :
"false",comments->size());
14598 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");
14603 int commentIndex = 0;
14604 AttachedPreprocessingInfoType::iterator i;
14605 for (i = comments->begin(); i != comments->end(); i++)
14607 ROSE_ASSERT ( (*i) != NULL );
14609 printf (
" Attached Comment (relativePosition=%s): %s\n",
14610 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
14611 (*i)->getString().c_str());
14612 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
14613 (*i)->get_file_info()->display(
"comment/directive location");
14616 if ((*i)->getRelativePosition() == relativePosition)
14619 captureList.push_back(commentIndex);
14626 if (captureList.empty() ==
false)
14632 ROSE_ASSERT(surroundingStatement != targetStmt);
14633 ROSE_ASSERT(surroundingStatement != NULL);
14635 if (surroundingStatement == NULL)
14638 surroundingStatement = (insertBefore ==
true) ? newStmt : newStmt;
14643 vector<int>::iterator j = captureList.begin();
14644 while (j != captureList.end())
14652 (*comments)[*j] = NULL;
14659 for (
size_t n = 0; n < captureList.size(); n++)
14661 AttachedPreprocessingInfoType::iterator k = comments->begin();
14662 while (k != comments->end())
14667 comments->erase(k);
14680 if (comments != NULL)
14682 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");
14689 printf (
"In SageInterface::insertStatement(): after processing associated comments \n");
14690 reportNodesMarkedAsModified(scope);
14693 if (isSgIfStmt(parent))
14695 if (isSgIfStmt(parent)->get_conditional()==targetStmt)
14701 if (isSgIfStmt(parent)->get_true_body()==targetStmt)
14721 if (isSgIfStmt(parent)->get_false_body()==targetStmt)
14735 if (isSgWhileStmt(parent))
14737 if (isSgWhileStmt(parent)->get_condition()==targetStmt)
14743 if (isSgWhileStmt(parent)->get_body()==targetStmt)
14746 isSgWhileStmt(parent)->
set_body(newparent);
14756 if (isSgDoWhileStmt(parent))
14758 if (isSgDoWhileStmt(parent)->get_condition()==targetStmt)
14764 if (isSgDoWhileStmt(parent)->get_body()==targetStmt)
14767 isSgDoWhileStmt(parent)->
set_body(newparent);
14777 if (isSgForStatement(parent))
14779 if (isSgForStatement(parent)->get_loop_body()==targetStmt)
14790 if (isSgForStatement(parent)->get_test()==targetStmt)
14811 p->set_body(newparent);
14819 ROSE_ASSERT(stmnt != NULL);
14841 printf (
"In SageInterface::insertStatement(): at BASE of function \n");
14842 reportNodesMarkedAsModified(scope);
14851 for (
size_t i = 0; i < newStmts.size(); ++i)
14858 for (
size_t i = newStmts.size(); i > 0; --i)
14867 insertStatement(targetStmt,newStmt,
false, autoMovePreprocessingInfo);
14878 ROSE_ASSERT (stmt != NULL);
14879 ROSE_ASSERT (scope != NULL);
14891 ROSE_ASSERT (scope != NULL);
14892 vector <SgStatement* >::iterator iter;
14894 for (iter= stmt_list.begin(); iter != stmt_list.end(); iter++)
14896 if (iter == stmt_list.begin())
14902 ROSE_ASSERT (prev_stmt != NULL);
14911 ROSE_ASSERT(newStmt!=NULL);
14912 ROSE_ASSERT(scope!=NULL);
14914 if (!isSgDeclarationStatement(targetStmt)) {
14924 ROSE_ASSERT(scope!=NULL);
14926 if (!isSgDeclarationStatement(targetStmt)) {
14949 ROSE_ASSERT(target);
14950 ROSE_ASSERT(operand);
14951 ROSE_ASSERT(target!=operand);
14952 switch (target->variantT())
14954 case V_SgActualArgumentExpression:
14955 isSgActualArgumentExpression(target)->set_expression(operand);
14958 isSgAsmOp(target)->set_expression(operand);
14961 isSgSizeOfOp(target)->set_operand_expr(operand);
14964 isSgTypeIdOp(target)->set_operand_expr(operand);
14967 isSgVarArgOp(target)->set_operand_expr(operand);
14969 case V_SgVarArgStartOneOperandOp:
14970 isSgVarArgStartOneOperandOp(target)->set_operand_expr(operand);
14972 case V_SgAssignInitializer:
14973 isSgAssignInitializer (target)->
set_operand(operand);
14976 if (isSgUnaryOp(target)!=NULL)
14980 cerr<<
"\tSageInterface::setOperand(): unhandled case for target expression of type "
14981 <<target->class_name()<<endl;
14986 markLhsValues(target);
14992 ROSE_ASSERT(target);
14994 ROSE_ASSERT(target!=lhs);
14995 bool hasrhs =
false;
15001 if (varargcopy!=NULL)
15003 varargcopy->set_lhs_operand(lhs);
15004 if( varargcopy->get_rhs_operand()!=NULL) hasrhs=
true;
15006 else if(varargstart!=NULL)
15008 varargstart->set_lhs_operand(lhs);
15009 if( varargstart->get_rhs_operand()!=NULL) hasrhs=
true;
15011 else if(binary!=NULL)
15018 cout<<
"SageInterface::setLhsOperand(): unhandled case for target expression of type "
15019 <<target->class_name()<<endl;
15026 markLhsValues(target);
15031 ROSE_ASSERT(target);
15033 ROSE_ASSERT(target!=rhs);
15034 bool haslhs =
false;
15040 if (varargcopy!=NULL)
15042 varargcopy->set_rhs_operand(rhs);
15043 if( varargcopy->get_lhs_operand()!=NULL) haslhs=
true;
15045 else if(varargstart!=NULL)
15047 varargstart->set_rhs_operand(rhs);
15048 if( varargstart->get_lhs_operand()!=NULL) haslhs=
true;
15050 else if(binary!=NULL)
15057 cout<<
"SageInterface::setRhsOperand(): unhandled case for target expression of type "
15058 <<target->class_name()<<endl;
15064 markLhsValues(target);
15083 ROSE_ASSERT(parentFileList != NULL);
15089 if (parentDirectory != NULL)
15092 parentDirectory->get_directoryList()->get_listOfDirectories().push_back(directory);
15099 project = isSgProject(parentFileList->
get_parent());
15100 ROSE_ASSERT(project != NULL);
15103 project->get_directoryList()->get_listOfDirectories().push_back(directory);
15110 directory->get_fileList()->get_listOfFiles().push_back(file);
15113 parentFileList->get_listOfFiles().erase(find(parentFileList->get_listOfFiles().begin(),parentFileList->get_listOfFiles().end(),file));
15123 ROSE_ASSERT(structDecl != NULL);
15124 ROSE_ASSERT(scope != NULL);
15126 ROSE_ASSERT(nondefdecl != NULL);
15152 SgName name = structDecl->get_name();
15166 if (mysymbol == NULL)
15168 printf (
"Note: SageInterface::fixStructDeclaration(): structDecl = %p nondefdecl = %p (mysymbol == NULL) \n",structDecl,nondefdecl);
15172 ROSE_ASSERT(structDecl->
get_scope() != NULL);
15177 ROSE_ASSERT(mysymbol);
15180 printf (
"############## DANGER:DANGER:DANGER ################\n");
15182 printf (
"In SageInterface::fixStructDeclaration(): Adding class symbol to scope = %p = %s \n",scope,scope->
class_name().c_str());
15190 printf (
"*** WARNING: In SageInterface::fixStructDeclaration(): (mysymbol == NULL) Commented out the setting of the parent to be the same as the scope \n");
15199 printf (
"In SageInterface::fixStructDeclaration(): (mysymbol == NULL) Skipped building an associated symbol! \n");
15204 ROSE_ASSERT(nondefdecl->get_type() != NULL);
15207 ROSE_ASSERT(nondefdecl->get_type()->
variantT() != V_SgNode);
15210 ROSE_ASSERT(isSgClassType(nondefdecl->get_type()) != NULL);
15214 if (nondefdecl->get_type() == NULL)
15218 ROSE_ASSERT (nondefdecl->get_type() != NULL);
15221 if (defdecl != NULL)
15224 ROSE_ASSERT(defdecl->get_type()->
variantT() != V_SgNode);
15227 ROSE_ASSERT(isSgClassType(defdecl->get_type()) != NULL);
15231 if (defdecl != NULL)
15234 ROSE_ASSERT(defdecl->get_type() != NULL);
15235 if (defdecl->get_type() != nondefdecl->get_type())
15237 printf (
"ERROR: defdecl->get_type() != nondefdecl->get_type(): what are these: \n");
15238 printf (
" defdecl->get_type() = %p = %s \n",defdecl ->get_type(),defdecl ->get_type()->class_name().c_str());
15239 SgNamedType* namedType_definingDecl = isSgNamedType(defdecl->get_type());
15240 if (namedType_definingDecl != NULL)
15242 printf (
"namedType_definingDecl->get_declaration() = %p = %s \n",namedType_definingDecl->get_declaration(),namedType_definingDecl->get_declaration()->
class_name().c_str());
15244 printf (
" nondefdecl->get_type() = %p = %s \n",nondefdecl->get_type(),nondefdecl->get_type()->
class_name().c_str());
15245 SgNamedType* namedType_nondefiningDecl = isSgNamedType(nondefdecl->get_type());
15246 if (namedType_nondefiningDecl != NULL)
15248 printf (
"namedType_nondefiningDecl->get_declaration() = %p = %s \n",namedType_nondefiningDecl->get_declaration(),namedType_nondefiningDecl->get_declaration()->
class_name().c_str());
15264 ROSE_ASSERT(structDecl);
15265 ROSE_ASSERT(scope);
15267 ROSE_ASSERT(nondefdecl);
15286 if (mysymbol==NULL)
15293 ROSE_ASSERT(mysymbol);
15295 printf (
"In SageInterface::fixNamespaceDeclaration(): inserting namespace symbol into scope = %p = %s \n",scope,scope->
class_name().c_str());
15299 ROSE_ASSERT(defdecl);
15309#define DEBUG__SageInterface__fixVariableDeclaration 0
15313 ROSE_ASSERT(varDecl != NULL);
15314 ROSE_ASSERT(scope != NULL);
15316 SgInitializedNamePtrList namelist = varDecl->
get_variables();
15321#if DEBUG__SageInterface__fixVariableDeclaration
15322 printf (
"In SageInterface::fixVariableDeclaration():\n");
15323 printf (
" varDecl = %p scope = %p = %s \n", varDecl);
15324 printf (
" scope = %p : %s \n", scope, scope->
class_name().c_str());
15327 ROSE_ASSERT(namelist.size() > 0);
15329 SgInitializedNamePtrList::iterator i;
15330 for (i = namelist.begin(); i != namelist.end(); i++)
15333 ROSE_ASSERT(initName != NULL);
15334#if DEBUG__SageInterface__fixVariableDeclaration
15335 printf (
" initName = %p\n", initName);
15336 printf (
" initName->get_scope() = %p : %s\n", initName->get_scope(), initName->get_scope() ? initName->get_scope()->
class_name().c_str() :
"");
15339 SgName name = initName->get_name();
15340#if DEBUG__SageInterface__fixVariableDeclaration
15341 printf (
" name = %s\n", name.str());
15346#if DEBUG__SageInterface__fixVariableDeclaration
15347 printf (
" name = %s\n", name.str());
15354 if (preAssociatedScope != NULL) {
15355 requiredScope = preAssociatedScope;
15359 initName->set_scope(requiredScope);
15364 ROSE_ASSERT(requiredScope != NULL);
15365 SgVariableSymbol* varSymbol = requiredScope->lookup_variable_symbol(name);
15366#if DEBUG__SageInterface__fixVariableDeclaration
15367 printf (
" varSymbol = %p (%s)\n", varSymbol, varSymbol ? varSymbol->
class_name().c_str() :
"");
15369 if (varSymbol == NULL) {
15370 if (scope == initName->get_scope()) {
15371 if (isSgTemplateVariableDeclaration(varDecl)) {
15376 ROSE_ASSERT(varSymbol);
15381 ROSE_ASSERT(prev_decl);
15382 if (initName != prev_decl) {
15383 initName->set_prev_decl_item(prev_decl);
15385 ROSE_ASSERT(initName->get_prev_decl_item() != initName);
15387#if DEBUG__SageInterface__fixVariableDeclaration
15388 printf (
" varSymbol = %p (%s)\n", varSymbol, varSymbol ? varSymbol->
class_name().c_str() :
"");
15406 Rose_STL_Container<SgNode*> varList;
15409 Rose_STL_Container<SgNode*> reflist = NodeQuery::querySubTree(root, V_SgVarRefExp);
15410 for (Rose_STL_Container<SgNode*>::iterator i=reflist.begin();i!=reflist.end();i++)
15412 varRef= isSgVarRefExp(*i);
15413 ROSE_ASSERT(varRef->get_symbol());
15416 ROSE_ASSERT (initname != NULL);
15419 SgName varName=initname->get_name();
15430 if (varRef == arrowExp->get_rhs_operand_i())
15434 SgType* lhs_type = arrowExp->get_lhs_operand_i()->get_type() ;
15435 lhs_type = lhs_type->
stripType(SgType::STRIP_MODIFIER_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE | SgType::STRIP_TYPEDEF_TYPE);
15437 ROSE_ASSERT(ptrType);
15438 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));
15439 ROSE_ASSERT(clsType);
15457 if (varRef == dotExp->get_rhs_operand_i())
15462 SgType* lhs_type = dotExp->get_lhs_operand_i()->get_type() ;
15463 lhs_type = lhs_type->
stripType(SgType::STRIP_MODIFIER_TYPE | SgType::STRIP_REFERENCE_TYPE | SgType::STRIP_RVALUE_REFERENCE_TYPE | SgType::STRIP_TYPEDEF_TYPE);
15465 ROSE_ASSERT(clsType);
15489 if (realSymbol==NULL)
15496 ROSE_ASSERT(realSymbol!=(varRef->get_symbol()));
15503 bool toDelete =
true;
15505 SgSymbol* symbolToDelete = varRef->get_symbol();
15506 varRef->set_symbol(isSgVariableSymbol(realSymbol));
15509 if (varList.empty())
15511 VariantVector vv(V_SgVarRefExp);
15512 varList = NodeQuery::queryMemoryPool(vv);
15515 for (Rose_STL_Container<SgNode*>::iterator i = varList.begin();
15516 i != varList.end(); ++i)
15520 if (var->get_symbol() == symbolToDelete)
15530 delete symbolToDelete;
15539 delete (varRef->get_symbol());
15543 varRef->set_symbol(isSgVariableSymbol(realSymbol));
15550 if (cleanUnusedSymbols)
15557 Rose_STL_Container<SgNode*> symbolList;
15558 VariantVector sym_vv(V_SgVariableSymbol);
15559 symbolList = NodeQuery::queryMemoryPool(sym_vv);
15561 Rose_STL_Container<SgNode*> varList;
15562 VariantVector var_vv(V_SgVarRefExp);
15566 varList = NodeQuery::querySubTree(root, V_SgVarRefExp);
15569 for (Rose_STL_Container<SgNode*>::iterator i = symbolList.begin();
15570 i != symbolList.end(); ++i)
15573 ROSE_ASSERT(symbolToDelete);
15577 bool toDelete =
true;
15581 for (Rose_STL_Container<SgNode*>::iterator j = varList.begin();
15582 j != varList.end(); ++j)
15587 if (var->get_symbol() == symbolToDelete)
15598 std::cout <<
"Symbol " << symbolToDelete->
get_name().str() <<
' ' << symbolToDelete <<
15599 ' ' << symbolToDelete->get_declaration() <<
" is deleted." << std::endl;
15601 delete symbolToDelete->get_declaration();
15602 delete symbolToDelete;
15615 ROSE_ASSERT(label_stmt);
15624 if (isSgFunctionDefinition(scope) !=
nullptr)
15626 ASSERT_not_null(label_scope);
15632 SgLabelSymbol* lsymbol = label_scope->lookup_label_symbol(name);
15634 if (lsymbol ==
nullptr)
15639 ASSERT_not_null(lsymbol);
15651 ROSE_ASSERT (stmt != NULL);
15652 ROSE_ASSERT (label_value >0 && label_value <=99999);
15655 if (label_scope == NULL)
15659 ROSE_ASSERT (label_scope != NULL);
15661 SgLabelSymbol * symbol = label_scope->lookup_label_symbol (label_name);
15662 if (symbol == NULL)
15668 ROSE_ASSERT(symbol != NULL);
15669 symbol->set_fortran_statement(stmt);
15670 symbol->set_numeric_label_value(label_value);
15675 cerr<<
"Error. SageInterface::setFortranNumericLabel() tries to set a duplicated label value!"<<endl;
15676 ROSE_ASSERT (
false);
15685 case SgLabelSymbol::e_start_label_type:
15687 stmt->set_numeric_label(ref_exp);
15690 case SgLabelSymbol::e_end_label_type:
15692 stmt->set_end_numeric_label(ref_exp);
15697 std::cerr <<
"SageInterface::setFortranNumericLabel: unimplemented for label_type " << label_type <<
"\n";
15709 ROSE_ASSERT (func_def != NULL);
15714 std::set<SgNode*>::iterator iter ;
15715 for (iter=symbols.begin(); iter !=symbols.end(); iter++)
15720 int cur_val = l_symbol->get_numeric_label_value();
15721 if (result <=cur_val)
15722 result = cur_val +10;
15726 ROSE_ASSERT (result <= 99999);
15737 ROSE_ASSERT(scope != NULL);
15742 ROSE_ASSERT(fTable != NULL);
15749 printf (
"WARNING: Skip setting the scope of the SgFunctionTypeTable scope = %p = %s \n",scope,scope->
class_name().c_str());
15755 printf (
"In SageInterface::fixStatement(): stmt = %p = %s \n",stmt,stmt->
class_name().c_str());
15768 if (tmfunc != NULL)
15769 assert(tmfunc->
variantT() == V_SgTemplateMemberFunctionDeclaration);
15770 else if (mfunc != NULL)
15771 assert(mfunc->
variantT() == V_SgMemberFunctionDeclaration || mfunc->
variantT() == V_SgTemplateInstantiationMemberFunctionDecl);
15772 else if (tfunc != NULL)
15773 assert(tfunc->
variantT() == V_SgTemplateFunctionDeclaration);
15774 else if (procfunc != NULL)
15775 assert(procfunc->
variantT() == V_SgProcedureHeaderStatement);
15776 else if (progfunc != NULL)
15777 assert(progfunc->
variantT() == V_SgProgramHeaderStatement);
15778 else if (func != NULL)
15779 assert(func->
variantT() == V_SgFunctionDeclaration || func->
variantT() == V_SgTemplateInstantiationFunctionDecl);
15783 printf (
"In SageInterface::fixStatement(): scope = %p = %s \n",scope,scope->
class_name().c_str());
15784 printf (
"In SageInterface::fixStatement(): stmt->get_scope() = %p \n",stmt->
get_scope());
15796 printf (
"Looking up the function symbol using name = %s and type = %p = %s \n",func->get_name().str(),func->get_type(),func->get_type()->
class_name().c_str());
15802 if (tmfunc != NULL)
15804 SgTemplateParameterPtrList & templateParameterList = tmfunc->get_templateParameters();
15807 func_symbol = scope->lookup_template_member_function_symbol (func->get_name(), func->get_type(),&templateParameterList);
15809 else if (mfunc != NULL)
15812 SgTemplateArgumentPtrList* templateArgumentList = (templateInstantiationMemberFunctionDecl != NULL) ? &(templateInstantiationMemberFunctionDecl->
get_templateArguments()) : NULL;
15814 func_symbol = scope->lookup_nontemplate_member_function_symbol (func->get_name(), func->get_type(),templateArgumentList);
15816 else if (tfunc != NULL)
15818 SgTemplateParameterPtrList & templateParameterList = tfunc->get_templateParameters();
15820 printf (
"In SageInterface::fixStatement(): templateParameterList.size() = %" PRIuPTR
" \n",templateParameterList.size());
15824 func_symbol = scope->lookup_template_function_symbol (func->get_name(), func->get_type(),&templateParameterList);
15826 else if (procfunc != NULL)
15829 printf (
"In SageInterface::fixStatement(): procfunc->get_name() = %s calling lookup_function_symbol() \n",procfunc->get_name().str());
15831 func_symbol = scope->lookup_function_symbol (procfunc->get_name(), procfunc->get_type());
15832 assert(func_symbol != NULL);
15834 else if (progfunc != NULL)
15836 func_symbol = scope->lookup_function_symbol (progfunc->get_name(), progfunc->get_type());
15837 assert(func_symbol != NULL);
15839 else if (func != NULL)
15842 printf (
"In SageInterface::fixStatement(): func->get_name() = %s calling lookup_function_symbol() \n",func->get_name().str());
15845 SgTemplateArgumentPtrList* templateArgumentList = (templateInstantiationFunctionDecl != NULL) ? &(templateInstantiationFunctionDecl->
get_templateArguments()) : NULL;
15847 func_symbol = scope->lookup_function_symbol (func->get_name(), func->get_type(),templateArgumentList);
15852 if (func_symbol == NULL)
15864 printf (
"In SageInterface::fixStatement(): func_symbol = %p \n",func_symbol);
15866 assert(func_symbol != NULL);
15877 printf (
"Need to handle SgTemplateDeclaration IR nodes as well...(implement later) \n");
15885 if (isSgVariableDeclaration(stmt))
15892 ROSE_ASSERT(classDeclaration !=
nullptr);
15895 else if (isSgClassDeclaration(stmt))
15899 else if (isSgLabelStatement(stmt))
15903 else if (isSgFunctionDeclaration(stmt))
15911 ROSE_ASSERT(fTable);
15920 printf (
"In SageInterface::fixStatement(): scope = %p = %s \n",scope,scope->
class_name().c_str());
15921 printf (
"In SageInterface::fixStatement(): stmt->get_scope() = %p \n",stmt->
get_scope());
15932 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());
15934 SgFunctionSymbol* func_symbol = scope->lookup_function_symbol (func->get_name(), func->get_type());
15936 printf (
"In SageInterface::fixStatement(): func_symbol = %p \n",func_symbol);
15937 if (func_symbol == NULL)
15949 ROSE_ASSERT (func_symbol != NULL);
15955 printf (
"In SageInterface::fixStatement(): found a valid function so no need to insert new symbol \n");
15963 if (local_symbol == NULL)
15968 if (func != src_func )
15978 else if (isSgTemplateDeclaration(stmt) != NULL)
15993 case V_SgEnumDeclaration:
15994 case V_SgTemplateDeclaration:
15995 case V_SgTypedefDeclaration:
15996 case V_SgFunctionDeclaration:
15997 case V_SgMemberFunctionDeclaration:
15998 case V_SgTemplateInstantiationFunctionDecl:
16013 printf (
"In SageInterface::fixStatement(): switch default case used (likely OK): stmt = %p = %s \n",stmt,stmt->
class_name().c_str());
16016 printf (
"switch case not handled properly: stmt = %p = %s \n",stmt,stmt->
class_name().c_str());
16048 ROSE_ASSERT(func != NULL && scope != NULL);
16050 ROSE_ASSERT(func != NULL);
16051 ROSE_ASSERT(scope != NULL);
16053 SgStatementPtrList stmtList, sameFuncList;
16060 SgDeclarationStatementPtrList::iterator i;
16061 for (i=declList.begin();i!=declList.end();i++)
16062 stmtList.push_back(*i);
16070 if (firstNondefiningFunctionDeclaration != NULL)
16075 printf (
"In SageInterface::updateDefiningNondefiningLinks(): func = %p Found a valid pointer to a firstNondefiningFunctionDeclaration = %p \n",func,firstNondefiningFunctionDeclaration);
16086 printf (
"WARNING: symbol for func->get_firstNondefiningDeclaration() = %p = %s = %s is not present in the scope = %p = %s associated with the firstNondefiningDeclaration \n",
16094 SgSymbol* functionSymbol = scope->lookup_function_symbol(func->get_name(),func->get_type());
16095 if (functionSymbol != NULL)
16097 printf (
"In SageInterface::updateDefiningNondefiningLinks(): func = %p Found a valid symbol = %p \n",func,functionSymbol);
16101 printf (
"In SageInterface::updateDefiningNondefiningLinks(): func = %p functionSymbol == NULL \n",func);
16106 SgStatementPtrList::iterator j;
16107 for (j = stmtList.begin(); j != stmtList.end(); j++)
16110 if (func_decl != NULL)
16117 sameFuncList.push_back(func_decl);
16123 printf (
"func = %p \n",func);
16127 ROSE_ASSERT(func != NULL);
16131 for (j = sameFuncList.begin(); j != sameFuncList.end(); j++)
16136 ROSE_ASSERT(func != NULL);
16139 ROSE_ASSERT(sameFuncList.empty() ==
false);
16141 if (func == isSgFunctionDeclaration(*(sameFuncList.begin())))
16143 for (j = sameFuncList.begin(); j != sameFuncList.end(); j++)
16147 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 1) Testing j = %p set_firstNondefiningDeclaration(%p) \n",*j,func);
16151 if (func_decl != func)
16158 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 1) Calling j = %p set_firstNondefiningDeclaration(%p) \n",*j,func);
16168 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 2) Testing func = %p set_firstNondefiningDeclaration(%p) \n",func,isSgFunctionDeclaration(*(sameFuncList.begin()))->
get_firstNondefiningDeclaration());
16175 printf (
"In SageInterface::updateDefiningNondefiningLinks(): (case 2) Calling func = %p set_firstNondefiningDeclaration(%p) \n",func,isSgFunctionDeclaration(*(sameFuncList.begin()))->
get_firstNondefiningDeclaration());
16184 assert(source_file != NULL);
16185 assert(position == PreprocessingInfo::before || position == PreprocessingInfo::after);
16187 SgGlobal * global_scope = source_file->get_globalScope();
16190 ROSE_ASSERT(result);
16206 PreprocessingInfo::DirectiveType dtype )
16208 ASSERT_not_null(target);
16211 PreprocessingInfo::DirectiveType mytype=dtype;
16216 if (mytype == PreprocessingInfo::CpreprocessorUnknownDeclaration)
16222 mytype = PreprocessingInfo::C_StyleComment;
16227 mytype = PreprocessingInfo::CplusplusStyleComment;
16232 mytype = PreprocessingInfo::F90StyleComment;
16237 mytype = PreprocessingInfo::AdaStyleComment;
16242 mytype = PreprocessingInfo::JovialStyleComment;
16246 cout <<
"WARNING: SageInterface::attachComment(): Unknown programming language \n";
16252 bool resetPositionInfo =
false;
16255 case PreprocessingInfo::C_StyleComment: comment =
"/* " + content +
" */";
break;
16256 case PreprocessingInfo::CplusplusStyleComment: comment =
"// " + content;
break;
16257 case PreprocessingInfo::FortranStyleComment: comment =
" C " + content;
break;
16258 case PreprocessingInfo::F90StyleComment: comment =
"!" + content;
break;
16259 case PreprocessingInfo::AdaStyleComment: comment =
"-- " + content;
break;
16260 case PreprocessingInfo::JovialStyleComment:
16264 case PreprocessingInfo::CpreprocessorLineDeclaration:
16265 comment =
"#myline " + content;
16266 mytype = PreprocessingInfo::CplusplusStyleComment;
16267 resetPositionInfo =
true;
16269 case PreprocessingInfo::CpreprocessorIfndefDeclaration: comment =
"#ifndef " + content +
"\n";
break;
16270 case PreprocessingInfo::CpreprocessorDefineDeclaration: comment =
"#define " + content +
"\n";
break;
16271 case PreprocessingInfo::CpreprocessorEndifDeclaration: comment =
"#endif" + (content.empty() ?
"\n" : (
" /* " + content +
" */\n"));
break;
16272 case PreprocessingInfo::CpreprocessorEnd_ifDeclaration: comment =
"#end if" + (content.empty() ?
"\n" : (
" /* " + content +
" */\n"));
break;
16276 printf (
"Error: default in switch reached in SageInterface::attachComment() PreprocessingInfo::DirectiveType == %d \n",mytype);
16281 result =
new PreprocessingInfo (mytype,comment,
"transformation-generated", 0, 0, 0, position);
16284 if (resetPositionInfo ==
true)
16287 *(result->get_file_info()) = *(target->get_file_info());
16297 ASSERT_not_null(result);
16298 target->addToAttachedPreprocessingInfo(result);
16304 PreprocessingInfo::CpreprocessorIfDeclaration,
16306 "transformation-generated", 0, 0, 0,
16307 PreprocessingInfo::before
16309 target->addToAttachedPreprocessingInfo(if_macro);
16312 PreprocessingInfo::CpreprocessorEndifDeclaration,
16314 "transformation-generated", 0, 0, 0,
16315 PreprocessingInfo::after
16317 target->addToAttachedPreprocessingInfo(endif_macro);
16330static map<SgSourceFile*, map<string, PreprocessingInfo*> > fileHeaderDict;
16335 if (isSystemHeader)
16336 header_key=
"<"+header_file_name+
">";
16338 header_key=
"\""+header_file_name+
"\"";
16340 if (fileHeaderDict.count(source_file) && fileHeaderDict[source_file].count(header_key))
16341 return fileHeaderDict[source_file][header_key];
16343 vector<SgLocatedNode*> candidates;
16346 SgGlobal* global= source_file -> get_globalScope();
16348 candidates.push_back(global);
16351 SgDeclarationStatementPtrList decl_stmt_list = global->
get_declarations();
16352 for (SgDeclarationStatementPtrList::iterator iter= decl_stmt_list.begin(); iter!=decl_stmt_list.end(); iter++)
16353 candidates.push_back(*iter);
16355 bool found =
false;
16356 for (
size_t ci=0; ci<candidates.size(); ci++)
16361 if (comments == NULL)
continue;
16362 AttachedPreprocessingInfoType::iterator i;
16363 for (i = comments->begin (); i != comments->end (); i++)
16365 if ((*i)->getTypeOfDirective () != PreprocessingInfo::CpreprocessorIncludeDeclaration)
continue;
16366 string content = (*i)->getString ();
16367 if (content.find(header_key) != string::npos)
16369 fileHeaderDict[source_file][header_key] = *i;
16380 return fileHeaderDict[source_file][header_key];
16390 bool supportTokenUnparsing =
false;
16392 assert(source_file != NULL);
16393 assert(position == PreprocessingInfo::before || position == PreprocessingInfo::after);
16395 SgGlobal * global_scope = source_file->get_globalScope();
16398 if (isSystemHeader)
16399 content =
"#include <" + header_file_name +
"> \n";
16401 content =
"#include \"" + header_file_name +
"\" \n";
16404 ROSE_ASSERT(result);
16412 supportTokenUnparsing = source_file->get_unparse_tokens();
16413 bool supportUnparseHeaders = source_file->get_unparseHeaderFiles();
16416 printf (
"supportTokenUnparsing = %s \n",supportTokenUnparsing ?
"true" :
"false");
16417 printf (
"supportUnparseHeaders = %s \n",supportUnparseHeaders ?
"true" :
"false");
16418 printf (
"source_file = %p \n",source_file);
16419 printf (
"global_scope = %p \n",global_scope);
16422 printf (
"Exiting as a test! \n");
16427 if (supportTokenUnparsing ==
false)
16436 if (supportUnparseHeaders ==
true)
16441 printf (
"physical_file_id = %d \n",physical_file_id);
16446 printf (
"Exiting as a test! \n");
16453 global_scope->prepend_statement(emptyDeclaration);
16457 printf (
"Exiting as a test! \n");
16458 ROSE_ASSERT(
false);
16469 bool supportTokenUnparsing =
false;
16475 printf (
"In SageInterface::insertHeader(): filename = %s \n",filename.c_str());
16476 printf (
" --- position = %s \n",PreprocessingInfo::relativePositionName(position).c_str());
16482 ROSE_ASSERT(scope);
16485 ROSE_ASSERT(globalScope != NULL);
16493 if (isSystemHeader)
16494 content =
"#include <" + filename +
"> \n";
16496 content =
"#include \"" + filename +
"\" \n";
16505 ROSE_ASSERT(sourceFile != NULL);
16507 supportTokenUnparsing = sourceFile->get_unparse_tokens();
16509 bool supportUnparseHeaders = sourceFile->get_unparseHeaderFiles();
16511 if (supportUnparseHeaders)
16514 string suffix = Rose::StringUtility ::fileNameSuffix(filename);
16517 if (suffix==
"h" ||suffix==
"hpp"|| suffix==
"hh"||suffix==
"H" ||suffix==
"hxx"||suffix==
"h++" ||suffix==
"tcc")
16522 printf (
"supportTokenUnparsing = %s \n",supportTokenUnparsing ?
"true" :
"false");
16523 printf (
"supportUnparseHeaders = %s \n",supportUnparseHeaders ?
"true" :
"false");
16524 printf (
"sourceFile = %p \n",sourceFile);
16525 printf (
"globalScope = %p \n",globalScope);
16528 printf (
"supportTokenUnparsing = %s \n",supportTokenUnparsing ?
"true" :
"false");
16531 printf (
"Exiting as a test! \n");
16535 SgDeclarationStatementPtrList & stmtList = globalScope->
get_declarations();
16538 printf (
"stmtList.size() = %zu \n",stmtList.size());
16541 if (stmtList.size() > 0)
16543 for (SgDeclarationStatementPtrList::iterator j = stmtList.begin (); j != stmtList.end (); j++)
16547 if ( ((*j)->get_file_info())->isSameFile(srcScope->
get_file_info ()) || ((*j)->get_file_info ())->isTransformation() )
16549 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration, content,
"Transformation generated",0, 0, 0, PreprocessingInfo::before);
16550 ROSE_ASSERT(result != NULL);
16552 printf (
"Building a PreprocessingInfo: result = %p \n",result);
16560 if (supportTokenUnparsing ==
false)
16562 (*j)->addToAttachedPreprocessingInfo(result,position);
16566 (*j)->addToAttachedPreprocessingInfo(result,position);
16568 printf (
"In SageInterface::insertHeader(): Calling set_containsTransformationToSurroundingWhitespace(true) \n");
16572 (*j)->set_containsTransformationToSurroundingWhitespace(
true);
16581 printf (
"In SageInterface::insertHeader(): declarationStatement = %p = %s \n",declarationStatement,declarationStatement->
class_name().c_str());
16582 printf (
"In SageInterface::insertHeader(): declarationStatement->get_containsTransformationToSurroundingWhitespace() = %s \n",
16583 declarationStatement->get_containsTransformationToSurroundingWhitespace() ?
"true" :
"false");
16590 if (supportUnparseHeaders ==
true)
16595 printf (
"physical_file_id = %d \n",physical_file_id);
16597 emptyDeclaration->get_startOfConstruct()->set_physical_file_id(physical_file_id);
16598 emptyDeclaration->get_endOfConstruct()->set_physical_file_id(physical_file_id);
16600 printf (
"Exiting as a test! \n");
16601 ROSE_ASSERT(
false);
16605 emptyDeclaration->addToAttachedPreprocessingInfo(result, position);
16611 printf (
"break out of for loop: result = %p \n",result);
16621 cerr<<
"SageInterface::insertHeader() Empty file is found!"<<endl;
16622 cerr<<
"#include xxx is preprocessing information which has to be attached to some other located node (a statement for example)"<<endl;
16623 cerr<<
"You may have to insert some statement first before inserting a header"<<endl;
16624 ROSE_ASSERT(
false);
16625 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration, content,
"Transformation generated",0, 0, 0, PreprocessingInfo::after);
16626 ROSE_ASSERT(result);
16637 if (result != NULL)
16648 printf (
"Exiting as a test! \n");
16649 ROSE_ASSERT(
false);
16653 printf (
"Leaving SageInterface::insertHeader(): filename = %s \n",filename.c_str());
16657 printf (
"Exiting as a test! \n");
16658 ROSE_ASSERT(
false);
16668 ROSE_ASSERT (stmt != NULL);
16669 ROSE_ASSERT (newheader != NULL);
16672 printf (
"In SageInterface::insertHeader (SgStatement* stmt, PreprocessingInfo* newheader, bool asLastHeader) \n");
16678 position = PreprocessingInfo::after;
16680 position = PreprocessingInfo::before;
16686 if (comments != NULL)
16695 AttachedPreprocessingInfoType::iterator i, firsti, lasti;
16696 for (i = comments->begin (); i != comments->end (); i++)
16703 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration)
16706 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration)
16708 if (firstExistingHeader == NULL)
16710 firstExistingHeader = (*i);
16714 lastExistingHeader = (*i);
16720 if ( (*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration ||
16721 (*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorEndifDeclaration )
16724 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorIncludeDeclaration)
16726 if (firstExistingHeader == NULL)
16728 firstExistingHeader = (*i);
16732 lastExistingHeader = (*i);
16735 if ((*i)->getTypeOfDirective () == PreprocessingInfo::CpreprocessorEndifDeclaration)
16737 if (firstExistingEndif == NULL)
16739 firstExistingEndif = (*i);
16754 if (lastExistingHeader == NULL)
16758 comments->insert (lasti+1, newheader);
16763 if (firstExistingHeader == NULL)
16767 comments->insert (firsti, newheader);
16775 printf (
"Exiting as a test! \n");
16776 ROSE_ASSERT(
false);
16785 ROSE_ASSERT (source_file != NULL);
16786 SgGlobal* globalScope = source_file->get_globalScope();
16787 ROSE_ASSERT (globalScope != NULL);
16791 if (isSystemHeader)
16792 content =
"#include <" + filename +
"> \n";
16794 content =
"#include \"" + filename +
"\" \n";
16801 position = PreprocessingInfo::after;
16803 position = PreprocessingInfo::before;
16806 SgDeclarationStatementPtrList & stmtList = globalScope->
get_declarations ();
16807 if (stmtList.size()>0)
16809 for (SgDeclarationStatementPtrList::iterator j = stmtList.begin (); j != stmtList.end (); j++)
16814 if ( (*j)->get_file_info()->isSameFile(globalScope->
get_file_info()) || (*j)->get_file_info()->isTransformation() )
16817 printf (
"In SageInterface::insertHeader(): Found statement to attached #include: *j = %p = %s \n",*j,(*j)->class_name().c_str());
16818 printf (
" --- unparseToString() = %s \n",(*j)->unparseToString().c_str());
16820 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration, content,
"Transformation generated",0, 0, 0, PreprocessingInfo::before);
16821 ROSE_ASSERT(result);
16825 printf (
"Exiting as a test! \n");
16834 cerr<<
"SageInterface::insertHeader() Empty file is found!"<<endl;
16835 cerr<<
"#include xxx is preprocessing information which has to be attached to some other located node (a statement for example)"<<endl;
16836 cerr<<
"You may have to insert some statement first before inserting a header"<<endl;
16839 result =
new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,
16840 content,
"Transformation generated",0, 0, 0, PreprocessingInfo::after);
16841 ROSE_ASSERT(result);
16848 printf (
"In SageInterface::insertHeader(): Marking include file for filename = %s as a transformation \n",filename.c_str());
16858 printf (
"Exiting as a test! \n");
16859 ROSE_ASSERT(
false);
16877 ROSE_ASSERT(target != NULL);
16884 PreprocessingInfo::DirectiveType mytype = PreprocessingInfo::CpreprocessorIfDeclaration;
16887 printf (
"Warning: attachArbitraryText(): attaching arbitrary text to the AST as a #if declaration: text = %s \n",text.c_str());
16889 result =
new PreprocessingInfo (mytype,text,
"transformation-generated", 0, 0, 0, position);
16890 ROSE_ASSERT(result);
16897 target->addToAttachedPreprocessingInfo(result);
16911 ROSE_ASSERT(target != NULL);
16912 AttachedPreprocessingInfoType *info= target->getAttachedPreprocessingInfo ();
16913 if (info == NULL)
return;
16914 AttachedPreprocessingInfoType::iterator j;
16915 for (j = info->begin (); j != info->end (); j++)
16917 if ((*j)->getTypeOfDirective()==PreprocessingInfo::CMacroCall)
16919#ifndef ROSE_SKIP_COMPILATION_OF_WAVE
16921 std::ostringstream os;
16922 token_container tc = (*j)->get_macro_call()->expanded_macro;
16923 token_container::const_iterator iter;
16924 for (iter=tc.begin(); iter!=tc.end(); iter++)
16925 os<<(*iter).get_value();
16928 string pragmaText = target->get_pragma()->get_pragma();
16929 string targetString = (*j)->getString();
16930 string replacement = os.str();
16932 size_t pos1 = pragmaText.find(targetString);
16933 while (pos1 != string::npos)
16935 pragmaText.replace(pos1, targetString.size(), replacement);
16936 pos1 = pragmaText.find(targetString);
16938 delete target->get_pragma();
16952 if (isSgWhileStmt(loopOrSwitch) || isSgDoWhileStmt(loopOrSwitch) ||
16953 isSgForStatement(loopOrSwitch)) {
16955 }
else if (isSgSwitchStatement(loopOrSwitch)) {
16956 body = isSgSwitchStatement(loopOrSwitch)->
get_body();
16958 ROSE_ASSERT (body);
16960 if (!breaks.empty()) {
16961 static int breakLabelCounter = 0;
16966 isSgScopeStatement(loopOrSwitch->
get_parent()));
16968 for (
size_t j = 0; j < breaks.size(); ++j) {
16973 newGoto->
set_parent(breaks[j]->get_parent());
16980 ROSE_ASSERT(node!=NULL);
16990 ROSE_ASSERT(node!=NULL);
17003 ROSE_ASSERT(stmt_src != NULL);
17004 ROSE_ASSERT(stmt_dst != NULL);
17007 if (infoList == NULL)
17010 printf (
"In SageInterface::movePreprocessingInfo(): infoList == NULL: exiting movePreprocessingInfo() \n");
17015 AttachedPreprocessingInfoType* infoToRemoveList =
new AttachedPreprocessingInfoType();
17018 printf (
"In SageInterface::movePreprocessingInfo(): \n");
17019 printf (
" --- stmt_src = %p = %s src_position = %d \n",stmt_src,stmt_src->
class_name().c_str(),src_position);
17021 if (src_declarationStatement != NULL)
17024 printf (
"src_declarationStatement->get_definingDeclaration() = %p \n",src_declarationStatement->
get_definingDeclaration());
17026 printf (
" --- stmt_dst = %p = %s dst_position = %d \n",stmt_dst,stmt_dst->
class_name().c_str(),dst_position);
17028 if (dst_declarationStatement != NULL)
17031 printf (
"dst_declarationStatement->get_definingDeclaration() = %p \n",dst_declarationStatement->
get_definingDeclaration());
17033 printf (
" --- src_position = %s \n",PreprocessingInfo::relativePositionName(src_position).c_str());
17034 printf (
" --- dst_position = %s \n",PreprocessingInfo::relativePositionName(dst_position).c_str());
17035 printf (
" --- usePrepend = %s \n",usePrepend ?
"true" :
"false");
17037 printf (
" --- infoList = %p \n",infoList);
17038 printf (
" --- infoToRemoveList = %p \n",infoToRemoveList);
17041 printf (
" --- dst_infoList = %p \n",dst_infoList);
17044 printf (
"****************************************************************** \n");
17045 printf (
"In SageInterface::movePreprocessingInfo(): Attached comments and CPP directives: stmt_src \n");
17047 printf (
"In SageInterface::movePreprocessingInfo(): Attached comments and CPP directives: stmt_dst \n");
17049 printf (
"****************************************************************** \n");
17059 printf (
" --- infoList->size() = %zu \n",infoList->size());
17060 printf (
" --- infoToRemoveList->size() = %zu \n",infoToRemoveList->size());
17066 for (Rose_STL_Container<PreprocessingInfo*>::iterator i = (*infoList).begin(); i != (*infoList).end(); i++)
17069 ROSE_ASSERT(*i != NULL);
17074 ROSE_ASSERT(info != NULL);
17077 printf (
"counter = %d Processing PreprocessingInfo = %s \n",counter,info->getString().c_str());
17086 for (Rose_STL_Container<PreprocessingInfo*>::iterator i = (*infoList).begin(); i != (*infoList).end(); i++)
17088 ROSE_ASSERT(*i != NULL);
17091 ROSE_ASSERT(info != NULL);
17094 (info->getTypeOfDirective()==PreprocessingInfo::C_StyleComment)||
17095 (info->getTypeOfDirective()==PreprocessingInfo::CplusplusStyleComment)||
17096 (info->getTypeOfDirective()==PreprocessingInfo::FortranStyleComment)||
17097 (info->getTypeOfDirective()==PreprocessingInfo::F90StyleComment)||
17098 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIncludeDeclaration )||
17099 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIncludeNextDeclaration )||
17100 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorDefineDeclaration )||
17101 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorUndefDeclaration)||
17102 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIfdefDeclaration )||
17103 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIfndefDeclaration )||
17104 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorIfDeclaration )||
17105 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorDeadIfDeclaration )||
17106 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorElseDeclaration )||
17107 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorElifDeclaration )||
17108 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorEndifDeclaration ) ||
17109 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorEnd_ifDeclaration ) ||
17110 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorLineDeclaration) ||
17111 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorErrorDeclaration) ||
17112 (info->getTypeOfDirective()==PreprocessingInfo::CpreprocessorWarningDeclaration) ||
17114 (info->getTypeOfDirective()==PreprocessingInfo::ClinkageSpecificationStart) ||
17115 (info->getTypeOfDirective()==PreprocessingInfo::ClinkageSpecificationEnd)
17120 if ( src_position == PreprocessingInfo::undef || info->getRelativePosition() == src_position)
17122 if (usePrepend ==
true)
17125 if (prevItem == NULL)
17143 info->setAsTransformation();
17151 stmt_dst->set_containsTransformationToSurroundingWhitespace(
true);
17152 if (isMarkedAsModified ==
false)
17159 (*infoToRemoveList).push_back(*i);
17163 if (dst_position != PreprocessingInfo::undef)
17165 info->setRelativePosition(dst_position);
17171 AttachedPreprocessingInfoType::iterator j;
17172 for (j = (*infoToRemoveList).begin(); j != (*infoToRemoveList).end(); j++)
17174 infoList->erase( find(infoList->begin(),infoList->end(),*j) );
17210 return info && (info->getRelativePosition () != pos);
17220 return info && !isNotRelPos (info, pos);
17227 ASSERT_not_null(src_node);
17230 AttachedPreprocessingInfoType* info = src_node->get_attachedPreprocessingInfoPtr();
17234 remove_copy_if(info->begin(),
17236 back_inserter(save_buf),
17237 [pos](
auto x) {
return !isRelPos(x, pos); }
17241 AttachedPreprocessingInfoType::iterator
17242 new_end = remove_if(info->begin(),
17244 [pos](
auto x) { return isRelPos(x, pos); }
17246 info->erase(new_end, info->end());
17250static AttachedPreprocessingInfoType *
17254 AttachedPreprocessingInfoType* info_list = s->get_attachedPreprocessingInfoPtr ();
17257 info_list =
new AttachedPreprocessingInfoType;
17258 ROSE_ASSERT (info_list);
17259 s->set_attachedPreprocessingInfoPtr (info_list);
17263 ROSE_ASSERT (info_list);
17270 if (save_buf.size()==0)
return;
17272 AttachedPreprocessingInfoType* info = createInfoList (dst_node);
17273 ROSE_ASSERT (info);
17280 if (pos==PreprocessingInfo::before)
17282 for(AttachedPreprocessingInfoType::reverse_iterator i=save_buf.rbegin();i!=save_buf.rend();i++)
17283 info->insert(info->begin(),*i);
17286 else if (pos==PreprocessingInfo::after)
17287 copy (save_buf.begin (), save_buf.end (), back_inserter (*info));
17288 else if (pos==PreprocessingInfo::inside)
17290 copy (save_buf.begin (), save_buf.end (), back_inserter (*info));
17291 cerr<<
"SageInterface::pastePreprocessingInfo() pos==PreprocessingInfo::inside is not supported."<<endl;
17292 save_buf[0]->display(
"ttt");
17298 ROSE_ASSERT(locatedNode != NULL);
17299 AttachedPreprocessingInfoType *comments =
17302 if (comments != NULL)
17304 printf (
"-----------------------------------------------\n");
17305 printf (
"Found an IR node (at %p of type: %s) in file %s \n",
17306 locatedNode, locatedNode->
class_name ().c_str (),
17307 (locatedNode->
get_file_info ()->get_filenameString ()).c_str ());
17309 AttachedPreprocessingInfoType::iterator i;
17310 for (i = comments->begin (); i != comments->end (); i++)
17313 (
"with attached preprocessingInfo numbering #%d :------------- \nclassification= %s:\nString format:%s\n",
17315 PreprocessingInfo::directiveTypeName ((*i)->getTypeOfDirective ()).
17316 c_str (), (*i)->getString ().c_str ());
17317 if ((*i)->getRelativePosition () == PreprocessingInfo::inside)
17318 printf (
"relative position is: inside\n");
17320 printf (
"relative position is: %s\n", \
17321 ((*i)->getRelativePosition () == PreprocessingInfo::before) ?
"before" :
"after");
17326 printf (
"No attached preprocessing info. (at %p of type: %s): \n", locatedNode,
17342template <
class ParentNode>
17352 if (basicblock == NULL) {
17354 (stmt.*setter)(basicblock);
17358 ROSE_ASSERT (basicblock != NULL);
17365 if (!isSgBasicBlock(b)) {
17373 ROSE_ASSERT (isSgBasicBlock(b));
17374 return isSgBasicBlock(b);
17380 if (!isSgBasicBlock(b)) {
17388 ROSE_ASSERT (isSgBasicBlock(b));
17389 return isSgBasicBlock(b);
17395 if (!isSgBasicBlock(b)) {
17403 ROSE_ASSERT (isSgBasicBlock(b));
17404 return isSgBasicBlock(b);
17409 ROSE_ASSERT (fs != NULL);
17411 return ensureBasicBlock_aux(*fs, &SgUpcForAllStatement::get_loop_body, &SgUpcForAllStatement::set_loop_body);
17416 if (!isSgBasicBlock(b)) {
17424 ROSE_ASSERT (isSgBasicBlock(b));
17425 return isSgBasicBlock(b);
17430 if (!isSgBasicBlock(b)) {
17438 ROSE_ASSERT (isSgBasicBlock(b));
17439 return isSgBasicBlock(b);
17444 if (!isSgBasicBlock(b)) {
17452 ROSE_ASSERT (isSgBasicBlock(b));
17453 return isSgBasicBlock(b);
17458 if (!isSgBasicBlock(b)) {
17466 printf (
"In SageInterface::ensureBasicBlockAsTrueBodyOfIf(): Added SgBasicBlock b = %p to addedBasicBlockNodes.size() = %zu \n",b,addedBasicBlockNodes.size());
17469 ROSE_ASSERT (isSgBasicBlock(b));
17470 return isSgBasicBlock(b);
17480 ROSE_ASSERT(bb != NULL);
17481 addedBasicBlockNodes.push_back(bb);
17483 printf (
"In SageInterface::recordNormalizations(): Added SgBasicBlock = %p to addedBasicBlockNodes.size() = %zu \n",bb,addedBasicBlockNodes.size());
17494 printf (
"In SageInterface::cleanupNontransformedBasicBlockNode(): addedBasicBlockNodes.size() = %zu \n",addedBasicBlockNodes.size());
17497 for (vector<SgBasicBlock*>::iterator i = addedBasicBlockNodes.begin(); i != addedBasicBlockNodes.end(); i++)
17500 ROSE_ASSERT(b != NULL);
17504 printf (
"This SgBasicBlock can be denormalized: b = %p \n",b);
17507 ROSE_ASSERT(parentOfBlock != NULL);
17512 ROSE_ASSERT(s != NULL);
17514 switch (parentOfBlock->
variantT())
17518 SgIfStmt* ifStatement = isSgIfStmt(parentOfBlock);
17522 printf (
"Calling set_true_body on ifStatement = %p = %s \n",ifStatement,ifStatement->
class_name().c_str());
17527 printf (
"Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17532 printf (
"DONE: Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17541 printf (
"Calling set_false_body on ifStatement = %p = %s \n",ifStatement,ifStatement->
class_name().c_str());
17546 printf (
"Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17551 printf (
"DONE: Calling set_parent on s = %p = %n \n",s,s->
class_name().c_str());
17555 printf (
"Mark as NOT modified after calling set_false_body on ifStatement = %p = %n \n",ifStatement,ifStatement->
class_name().c_str());
17558 printf (
"Error: case not handled in case V_SgIfStmt: parentOfBlock = %p = %s \n",parentOfBlock,parentOfBlock->
class_name().c_str());
17566 case V_SgWhileStmt:
17568 SgWhileStmt* whileStatement = isSgWhileStmt(parentOfBlock);
17569 if (b == whileStatement->
get_body())
17578 case V_SgSwitchStatement:
17581 if (b == switchStatement->
get_body())
17590 case V_SgForStatement:
17602 case V_SgCaseOptionStmt:
17604 SgCaseOptionStmt* caseOptionStatement = isSgCaseOptionStmt(parentOfBlock);
17605 if (b == caseOptionStatement->
get_body())
17614 case V_SgDefaultOptionStmt:
17617 if (b == defaultOptionStatement->
get_body())
17619 defaultOptionStatement->
set_body(s);
17626 case V_SgDoWhileStmt:
17628 SgDoWhileStmt* doWhileStatement = isSgDoWhileStmt(parentOfBlock);
17629 if (b == doWhileStatement->
get_body())
17639 printf (
"Error: case not handled in switch: parentOfBlock = %p = %s \n",parentOfBlock,parentOfBlock->
class_name().c_str());
17645 if (wasPreviouslyModified ==
false)
17650 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());
17657 printf (
"Exiting as a test! \n");
17664 printf (
"Leaving SageInterface::cleanupNontransformedBasicBlockNode(): addedBasicBlockNodes.size() = %zu \n",addedBasicBlockNodes.size());
17672 if (!createEmptyBody && (b == NULL || isSgNullStatement(b)))
17674 if (!isSgBasicBlock(b)) {
17682 ROSE_ASSERT (isSgBasicBlock(b));
17683 return isSgBasicBlock(b);
17688 if (!isSgBasicBlock(b)) {
17693 ROSE_ASSERT (isSgBasicBlock(b));
17694 return isSgBasicBlock(b);
17700 if (!isSgBasicBlock(b)) {
17705 ROSE_ASSERT (isSgBasicBlock(b));
17706 return isSgBasicBlock(b);
17718 case V_SgForStatement:
17720 if (isSgForStatement(p)->get_loop_body() == s)
17724 case V_SgUpcForAllStatement:
17727 if (upcforall.get_loop_body() == s)
17731 case V_SgWhileStmt:
17733 if (isSgWhileStmt(p)->get_body() == s)
17737 case V_SgDoWhileStmt:
17739 if (isSgDoWhileStmt(p)->get_body() == s)
17743 case V_SgSwitchStatement:
17745 if (isSgSwitchStatement(p)->get_body() == s)
17749 case V_SgCaseOptionStmt:
17751 if (isSgCaseOptionStmt(p)->get_body() == s)
17755 case V_SgDefaultOptionStmt:
17757 if (isSgDefaultOptionStmt(p)->get_body() == s)
17761 case V_SgCatchOptionStmt:
17763 if (isSgCatchOptionStmt(p)->get_body() == s)
17769 if (isSgIfStmt(p)->get_true_body() == s)
17771 else if (isSgIfStmt(p)->get_false_body() == s)
17777 if (isSgOmpBodyStatement(p))
17789 ROSE_ASSERT (singleStmt != NULL);
17790 ROSE_ASSERT (isSgBasicBlock(singleStmt) == NULL);
17802 case V_SgForStatement:
17804 if (isSgForStatement(p)->get_loop_body() == s)
17808 case V_SgUpcForAllStatement:
17812 if (upcforall.get_loop_body() == s)
17816 case V_SgWhileStmt:
17818 if (isSgWhileStmt(p)->get_body() == s)
17822 case V_SgDoWhileStmt:
17824 if (isSgDoWhileStmt(p)->get_body() == s)
17828 case V_SgSwitchStatement:
17830 if (isSgSwitchStatement(p)->get_body() == s)
17834 case V_SgCaseOptionStmt:
17836 if (isSgCaseOptionStmt(p)->get_body() == s)
17840 case V_SgDefaultOptionStmt:
17842 if (isSgDefaultOptionStmt(p)->get_body() == s)
17846 case V_SgCatchOptionStmt:
17848 if (isSgCatchOptionStmt(p)->get_body() == s)
17854 if (isSgIfStmt(p)->get_true_body() == s)
17856 else if (isSgIfStmt(p)->get_false_body() == s)
17862 if (isSgOmpBodyStatement(p))
17869 ROSE_ASSERT (rt != NULL);
17883 case V_SgBasicBlock:
return isSgBasicBlock(p);
17884 case V_SgForStatement:
17886 if (isSgForStatement(p)->get_loop_body() == s)
17888 else if (isSgForStatement(p)->get_test() == s)
17891 else if (isSgForStatement(p)->get_for_init_stmt() == s)
17897 case V_SgUpcForAllStatement:
17901 if (upcforall.get_loop_body() == s)
17904 ROSE_ASSERT( (s == upcforall.get_for_init_stmt())
17905 || (s == upcforall.get_test())
17909 case V_SgWhileStmt:
17911 if (isSgWhileStmt(p)->get_body() == s)
17913 else if (isSgWhileStmt(p)->get_condition() == s)
17919 case V_SgDoWhileStmt:
17921 if (isSgDoWhileStmt(p)->get_body() == s)
17923 else if (isSgDoWhileStmt(p)->get_condition() == s)
17929 case V_SgSwitchStatement:
17931 if (isSgSwitchStatement(p)->get_body() == s)
17933 else if (isSgSwitchStatement(p)->get_item_selector() == s)
17939 case V_SgCatchOptionStmt:
17941 if (isSgCatchOptionStmt(p)->get_body() == s)
17943 else if (isSgCatchOptionStmt(p)->get_condition() == s)
17951 if (isSgIfStmt(p)->get_true_body() == s)
17953 else if (isSgIfStmt(p)->get_false_body() == s)
17955 else if (isSgIfStmt(p)->get_conditional() == s)
17963 if (isSgOmpBodyStatement(p))
17978 void SageInterface::changeAllLoopBodiesToBlocks(
SgNode* top) {
17979 cerr<<
"Warning: SageInterface::changeAllLoopBodiesToBlocks() is being replaced by SageInterface::changeAllBodiesToBlocks()."<<endl;
17980 cerr<<
"Please use SageInterface::changeAllBodiesToBlocks() if you can."<<endl;
17988 bool allowEmptyBody;
17989 Visitor (
bool flag):allowEmptyBody(flag) {}
17990 virtual void visit(
SgNode* n) {
17995 case V_SgForStatement: {
17999 case V_SgWhileStmt: {
18003 case V_SgDoWhileStmt: {
18007 case V_SgSwitchStatement: {
18016 printf (
"In changeAllBodiesToBlocks(): case SgIfStmt: n->get_isModified() = %s \n",n->
get_isModified() ?
"true" :
"false");
18023 printf (
"In changeAllBodiesToBlocks(): AFTER RESET: case SgIfStmt: n->get_isModified() = %s \n",n->
get_isModified() ?
"true" :
"false");
18028 case V_SgCatchOptionStmt: {
18032 case V_SgUpcForAllStatement: {
18039 if (isSgOmpBodyStatement(n))
18046 if (wasPreviouslyModified ==
false)
18051 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());
18060 Visitor(createEmptyBody).traverse(top, postorder);
18081#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
18082 SgStatement* enclosingStatement = getStatementOfExpression(from);
18083 SgExprStatement* exprStatement = isSgExprStatement(enclosingStatement);
18085 SgForStatement* forStatement = isSgForStatement(enclosingStatement);
18086 SgReturnStmt* returnStatement = isSgReturnStmt(enclosingStatement);
18092 ROSE_ASSERT (exprStatement || forStatement || returnStatement || varDeclarationStatement);
18094 if (varDeclarationStatement)
18101 ROSE_ASSERT (root);
18104 if (forStatement && forStatement->get_increment() == root)
18115 forStatement->get_increment()->
set_parent(incrStmt);
18119 forStatement->set_increment(ne);
18126 assert (enclosingStmtParent);
18127 SgWhileStmt* whileStatement = isSgWhileStmt(enclosingStmtParent);
18128 SgDoWhileStmt* doWhileStatement = isSgDoWhileStmt(enclosingStmtParent);
18129 SgIfStmt* ifStatement = isSgIfStmt(enclosingStmtParent);
18131 SgForStatement* enclosingForStatement = isSgForStatement(enclosingStmtParent);
18132 if (enclosingForStatement && enclosingForStatement->get_test() == exprStatement)
18144 pushTestIntoBody(enclosingForStatement);
18147 else if (whileStatement && whileStatement->
get_condition() == exprStatement)
18160 pushTestIntoBody(whileStatement);
18164 else if (doWhileStatement && doWhileStatement->
get_condition() == exprStatement)
18180 myStatementInsert(doWhileStatement, new_statement,
false);
18182 SgName varname =
"rose__temp1";
18187 varname,
buildBoolType(), assignInitializer, new_statement);
18190 initname->set_scope(new_statement);
18222 else if (ifStatement && ifStatement->
get_conditional() == exprStatement)
18228 myStatementInsert(ifStatement, new_statement,
false);
18230 SgName varname =
"rose__temp2";
18239 initname->set_scope(new_statement);
18264 else if (switchStatement && switchStatement->
get_item_selector() == exprStatement)
18266 SgExpression* switchCond = exprStatement->get_expression();
18267 ROSE_ASSERT (switchCond);
18272 myStatementInsert(switchStatement, new_statement,
false);
18274 SgName varname =
"rose__temp3";
18321#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
18322 SgStatement* stmt = getStatementOfExpression(from);
18324 if (isSgExprStatement(stmt))
18338 if (isSgAssignOp(top) && isSgAssignOp(top)->get_rhs_operand() == from)
18356 convertInitializerIntoAssignment(init);
18359 SgExprStatement* new_stmt = isSgExprStatement(getStatementOfExpression(from));
18360 assert (new_stmt != NULL);
18361 replaceAssignmentStmtWithStatement(new_stmt, to);
18378 ROSE_ASSERT(func&&s);
18380 Rose_STL_Container <SgNode* > stmts = NodeQuery::querySubTree(func, V_SgReturnStmt);
18382 Rose_STL_Container<SgNode*>::iterator i;
18383 for (i=stmts.begin();i!=stmts.end();i++)
18386 ROSE_ASSERT(cur_stmt);
18389 bool needRewrite = (exp != NULL) && !(isSgValueExp(exp));
18400 if (stmts.size()==0 )
18405 cout<<
"In instrumentEndOfFunction(), found an empty function body.! "<<endl;
18417 return ((stmt->get_declarationModifier()).get_storageModifier()).isStatic();
18424 return ((stmt->get_declarationModifier()).get_storageModifier()).setStatic();
18430 return ((stmt->get_declarationModifier()).get_storageModifier()).isExtern();
18438 return ((stmt->get_declarationModifier()).get_storageModifier()).setExtern();
18445 return name->get_storageModifier().isMutable();
18458 std::vector<SgInitializedName*> in_params;
18470 std::vector<SgInitializedName*> out_params;
18480 case V_SgCharVal:
return (
long long)(isSgCharVal(expr)->get_value());
18481 case V_SgSignedCharVal:
return (
long long)(isSgSignedCharVal(expr)->get_value());
18482 case V_SgUnsignedCharVal:
return isSgUnsignedCharVal(expr)->get_value();
18483 case V_SgShortVal:
return (
long long)(isSgShortVal(expr)->get_value());
18484 case V_SgUnsignedShortVal:
return isSgUnsignedShortVal(expr)->get_value();
18485 case V_SgIntVal:
return (
long long)(isSgIntVal(expr)->get_value());
18486 case V_SgUnsignedIntVal:
return isSgUnsignedIntVal(expr)->get_value();
18487 case V_SgLongIntVal:
return (
long long)(isSgLongIntVal(expr)->get_value());
18488 case V_SgUnsignedLongVal:
return isSgUnsignedLongVal(expr)->get_value();
18489 case V_SgLongLongIntVal:
return isSgLongLongIntVal(expr)->get_value();
18490 case V_SgUnsignedLongLongIntVal:
return isSgUnsignedLongLongIntVal(expr)->get_value();
18491 case V_SgBoolValExp:
return (
long long )(isSgBoolValExp(expr)->get_value());
18497 printf (
"ERROR: In SageInterface::getIntegerConstantValue(): default reached: expr = %p = %s \n",expr,expr->
class_name().c_str());
18498 ROSE_ASSERT (
false);
18503 ROSE_ASSERT (!
"Bad kind return in getIntegerConstantValue");
18508#ifdef ROSE_ENABLE_BINARY_ANALYSIS
18517 ROSE_ASSERT(binary!=NULL);
18522 if (1==headers.size()) {
18523 requisite_header = headers[0];
18525 for (SgAsmGenericHeaderPtrList::const_iterator hi=headers.begin(); hi!=headers.end(); ++hi) {
18526 if (isSgAsmPEFileHeader(*hi)) {
18527 requisite_header = isSgAsmPEFileHeader(*hi);
18532 ROSE_ASSERT(requisite_header!=NULL);
18535 const SgAsmInterpretationPtrList &interps = binary->get_interpretations()->
get_interpretations();
18536 for (SgAsmInterpretationPtrList::const_iterator ii=interps.begin(); ii!=interps.end(); ++ii) {
18537 const SgAsmGenericHeaderPtrList &headers = (*ii)->get_headers()->get_headers();
18538 for (SgAsmGenericHeaderPtrList::const_iterator hi=headers.begin(); hi!=headers.end(); ++hi) {
18539 if ((*hi)==requisite_header)
18544 ROSE_ASSERT(!
"no appropriate interpretation");
18557 SgNode* copy = n->copy(*
this);
18561 if (fileInfo != NULL)
18570 } collectDependentDeclarationsCopyType;
18578 vector<PreprocessingInfo*> cppDirectiveList;
18580 void visit(
SgNode *astNode);
18588 if (locatedNode != NULL)
18592 if (comments != NULL)
18595 printf (
"Found attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
sage_class_name());
18597 AttachedPreprocessingInfoType::iterator i;
18598 for (i = comments->begin(); i != comments->end(); i++)
18600 ROSE_ASSERT ( (*i) != NULL );
18602 printf (
" Attached Comment (relativePosition=%s): %s\n",
18603 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
18604 (*i)->getString().c_str());
18605 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
18606 (*i)->get_file_info()->display(
"comment/directive location");
18614 cppDirectiveList.push_back(*i);
18616 printf (
" Attached include directive (relativePosition=%s): %s\n",
18617 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
18618 (*i)->getString().c_str());
18626 printf (
"No attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
sage_class_name());
18637vector<PreprocessingInfo*>
18644 return t.cppDirectiveList;
18648vector<PreprocessingInfo*>
18655 return t.cppDirectiveList;
18660outputPreprocessingInfoList (
const vector<PreprocessingInfo*> & l )
18664 vector<PreprocessingInfo*>::const_iterator i = l.begin();
18665 while ( i != l.end() )
18667 printf (
" Attached include directive (relativePosition=%s): %s\n",
18668 ((*i)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
18669 (*i)->getString().c_str());
18684 case V_SgNamespaceDefinitionStatement:
18687 declaration = namespaceDefinition->get_namespaceDeclaration();
18691 case V_SgClassDefinition:
18692 case V_SgTemplateInstantiationDefn:
18701 printf (
"Error: default reached in getAssociatedDeclaration(): scope = %p = %s \n",scope,scope->
class_name().c_str());
18707 ROSE_ASSERT(declaration != NULL);
18709 return declaration;
18718 vector<SgDeclarationStatement*> declarationList;
18722 vector<SgSymbol*> symbolList;
18725 set<SgDeclarationStatement*> alreadySavedDeclarations;
18728 void visit(
SgNode *astNode);
18744 ROSE_ASSERT(scope != NULL);
18749 SgGlobal* globalScope = isSgGlobal(scope);
18750 if (globalScope == NULL)
18757 ROSE_ASSERT(parentScope != NULL);
18758 while (globalScope == NULL)
18760 associatedDeclaration = getAssociatedDeclaration(parentScope);
18761 ROSE_ASSERT(associatedDeclaration != NULL);
18763 parentScope = parentScope->
get_scope();
18764 globalScope = isSgGlobal(parentScope);
18770 return returnDeclaration;
18776outputDeclarationList (
const vector<SgDeclarationStatement*> & l )
18781 vector<SgDeclarationStatement*>::const_iterator i = l.begin();
18782 while ( i != l.end() )
18784 printf (
"In outputDeclarationList(): list[%d] = %p = %s = %s \n",counter++,*i,(*i)->class_name().c_str(),
SageInterface::get_name(*i).c_str());
18792 if (declaration != NULL)
18801 if (alreadySavedDeclarations.find(dependentDeclaration) == alreadySavedDeclarations.end())
18804 printf (
"In CollectDependentDeclarationsTraversal::visit(): selected dependentDeclaration = %p = %s = %s \n",
18808 declarationList.push_back(dependentDeclaration);
18811 alreadySavedDeclarations.insert(dependentDeclaration);
18813 printf (
"In CollectDependentDeclarationsTraversal::visit(): astNode = %p = %s = %s \n",astNode,astNode->
class_name().c_str(),
SageInterface::get_name(astNode).c_str());
18814 printf (
"############### ADDING dependentDeclaration = %p = %s to alreadySavedDeclarations set (size = %" PRIuPTR
") \n",
18815 dependentDeclaration,dependentDeclaration->
class_name().c_str(),alreadySavedDeclarations.size());
18823 printf (
"In CollectDependentDeclarationsTraversal::visit(): astNode = %p = %s = %s \n",astNode,astNode->
class_name().c_str(),
SageInterface::get_name(astNode).c_str());
18824 printf (
"############### EXISTING dependentDeclaration = %p = %s found in alreadySavedDeclarations set (size = %" PRIuPTR
") \n",
18825 dependentDeclaration,dependentDeclaration->
class_name().c_str(),alreadySavedDeclarations.size());
18832static std::vector<SgTypedefDeclaration*> collectTypedefDeclarations(
SgType* type)
18834 ROSE_ASSERT(type != NULL);
18835 std::vector<SgTypedefDeclaration*> result;
18836 SgType* currentType = type;
18846 modType = isSgModifierType(currentType);
18849 currentType = modType->get_base_type();
18853 refType = isSgReferenceType(currentType);
18856 currentType = refType->get_base_type();
18860 pointType = isSgPointerType(currentType);
18863 currentType = pointType->get_base_type();
18867 arrayType = isSgArrayType(currentType);
18870 currentType = arrayType->get_base_type();
18874 typedefType = isSgTypedefType(currentType);
18885 result.push_back(decl);
18899 if (result.size()>0)
18901 cout<<
"------------Found a chain of typedef decls: count="<<result.size()<<endl;
18902 for (vector <SgTypedefDeclaration*>::const_iterator iter = result.begin();
18903 iter!=result.end(); iter ++)
18930 if (fileInfo != NULL && fileInfo->isFrontendSpecific() ==
false && (isSgStatement(astNode) != NULL) )
18932 printf (
"\n\nIn CollectDependentDeclarationsTraversal::visit(): astNode = %p = %s = %s \n",astNode,astNode->
class_name().c_str(),
SageInterface::get_name(astNode).c_str());
18935 printf (
"alreadySavedDeclarations.size() = %" PRIuPTR
" \n",alreadySavedDeclarations.size());
18936 for (set<SgDeclarationStatement*>::iterator i = alreadySavedDeclarations.begin(); i != alreadySavedDeclarations.end(); i++)
18938 printf (
"alreadySavedDeclarations %d: %p = %s \n",counter++,*i,(*i)->class_name().c_str());
18949 if (initializedname != NULL)
18951 SgType* type = initializedname->get_type();
18954 std::vector <SgTypedefDeclaration*> typedefVec = collectTypedefDeclarations(type);
18955 for (std::vector <SgTypedefDeclaration*>::const_iterator iter =typedefVec.begin();
18956 iter != typedefVec.end(); iter++)
18959 addDeclaration(typedef_decl);
18983 SgNamedType* namedType = isSgNamedType(strippedType);
18984 if (namedType != NULL)
18992 if (classDeclaration != NULL)
18999 if (declaration != NULL)
19002 addDeclaration(declaration);
19005 addDeclaration (classDeclaration);
19016 ROSE_ASSERT(classSymbol != NULL);
19019 symbolList.push_back(classSymbol);
19024 if (enum_decl != NULL)
19027 ROSE_ASSERT(declaration != NULL);
19028 addDeclaration(declaration);
19033 ROSE_ASSERT(esymbol!= NULL);
19034 symbolList.push_back(esymbol);
19038 printf (
"Found reference to type = %p = %s strippedType = %p = %s \n",type,type->
class_name().c_str(),strippedType,strippedType->
class_name().c_str());
19045 if (functionCallExp != NULL)
19050 if (declaration != NULL)
19051 addDeclaration(declaration);
19058 if (functionSymbol)
19059 symbolList.push_back(functionSymbol);
19064 SgEnumVal * eval = isSgEnumVal(astNode);
19067 declaration = eval->get_declaration();
19068 ROSE_ASSERT(declaration != NULL);
19069 addDeclaration(declaration);
19071 ROSE_ASSERT(symbol != NULL);
19072 symbolList.push_back(symbol);
19077static std::map<const SgStatement*, bool> visitedDeclMap;
19089 printf (
"\n\n********************************************************** \n");
19090 printf (
" Inside of getDependentDeclarations(stmt = %p = %s) \n",stmt,stmt->
class_name().c_str());
19091 printf (
"********************************************************** \n");
19093 visitedDeclMap[stmt]=
true;
19097 declarationList = t.declarationList;
19098 symbolList = t.symbolList;
19101 copy(t.declarationList.begin(),t.declarationList.end(), back_inserter(declarationList));
19102 copy(t.symbolList.begin(),t.symbolList.end(), back_inserter(symbolList));
19104 sort (declarationList.begin(), declarationList.end());
19105 vector<SgDeclarationStatement*>::iterator new_end = unique(declarationList.begin(), declarationList.end());
19106 declarationList.erase(new_end, declarationList.end());
19108 sort (symbolList.begin(), symbolList.end());
19109 vector<SgSymbol*>::iterator end2 = unique(symbolList.begin(), symbolList.end());
19110 symbolList.erase(end2, symbolList.end());
19114 for (vector<SgDeclarationStatement*>::const_iterator iter = t.declarationList.begin();
19115 iter !=t.declarationList.end(); iter++)
19118 SgType* base_type = NULL;
19123 if (isSgClassDeclaration(decl))
19125 base_type = isSgClassDeclaration(decl)->get_type();
19127 if (isSgTypedefDeclaration(decl))
19131 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);
19139 if (isSgClassType(base_type))
19141 SgClassDeclaration* class_decl = isSgClassDeclaration(isSgClassType(base_type)->get_declaration()->get_definingDeclaration());
19142 if (class_decl!=NULL)
19144 body_stmt = class_decl->get_definition();
19148 if ((body_stmt!=NULL) &&(!visitedDeclMap[body_stmt]))
19160vector<SgDeclarationStatement*>
19163 vector<SgDeclarationStatement*> sortedNode;
19165 if (nodevec.size()==0 )
19168 if (nodevec.size() ==1)
19172 Rose_STL_Container<SgNode*> queryResult = NodeQuery::querySubTree(project,V_SgDeclarationStatement);
19173 for (Rose_STL_Container<SgNode*>::const_iterator iter = queryResult.begin();
19174 iter!= queryResult.end(); iter++)
19177 SgNode* cur_node = *iter;
19179 ROSE_ASSERT(cur_stmt!=NULL);
19191 ROSE_ASSERT (cur_stmt != func_decl);
19194 vector<SgDeclarationStatement*>::const_iterator i = find (nodevec.begin(), nodevec.end(), cur_stmt);
19195 if (i!=nodevec.end())
19199 vector<SgDeclarationStatement*>::const_iterator j = find (sortedNode.begin(), sortedNode.end(), *i);
19200 if (j == sortedNode.end())
19201 sortedNode.push_back(*i);
19205 if (nodevec.size() != sortedNode.size())
19207 cerr<<
"Fatal error in sortSgNodeListBasedOnAppearanceOrderInSource(): nodevec.size() != sortedNode.size()"<<endl;
19208 cerr<<
"nodevec() have "<< nodevec.size()<<
" elements. They are:"<<endl;
19209 for (vector<SgDeclarationStatement*>::const_iterator iter = nodevec.begin(); iter != nodevec.end(); iter++)
19211 cerr<<(*iter)<<
" "<<(*iter)->class_name() <<
" "<<(*iter)->unparseToString()<<endl;
19213 cerr<<
"sortedNode() have " << sortedNode.size() <<
" elements. They are:"<<endl;
19214 for (vector<SgDeclarationStatement*>::const_iterator iter = sortedNode.begin(); iter != sortedNode.end(); iter++)
19216 cerr<<(*iter)<<
" "<<(*iter)->class_name() <<
" "<<(*iter)->unparseToString()<<endl;
19219 ROSE_ASSERT(nodevec.size() == sortedNode.size());
19226std::vector<SgDeclarationStatement*>
19232 printf (
"\n\n********************************************************** \n");
19233 printf (
" Inside of getDependentDeclarations(stmt = %p = %s) \n",stmt,stmt->
class_name().c_str());
19234 printf (
"********************************************************** \n");
19239 return t.declarationList;
19242 visitedDeclMap.clear();
19243 vector<SgDeclarationStatement*> declarationList;
19244 vector<SgSymbol*> symbolList;
19248 printf (
"\n\n ********************************************************** \n");
19249 cout<<
"Found dependent decl: count="<<declarationList.size()<<endl;
19250 for ( vector<SgDeclarationStatement*>::const_iterator iter = declarationList.begin();
19251 iter != declarationList.end(); iter++)
19253 cout<<
"\t"<<(*iter)->class_name()<<
" at line "<<(*iter)->get_file_info()->get_line()<<endl;
19254 if ((*iter)->variantT()== V_SgFunctionDeclaration)
19255 cout<<
"func name is:"<<isSgFunctionDeclaration(*iter)->get_name().getString()<<endl;
19258 printf (
"\n ********************************************************** \n");
19261 return declarationList;
19270 bool returnValue =
false;
19273 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());
19276 if (functionName.is_null() ==
false)
19279 if ( functionName ==
"operator++" || functionName ==
"operator--" || functionName ==
"operator&" ||
19280 functionName ==
"operator!" || functionName ==
"operator*" || functionName ==
"operator+" ||
19281 functionName ==
"operator-" || functionName ==
"operator+" || functionName ==
"operator~")
19283 returnValue =
true;
19287 return returnValue;
19299 bool returnValue =
false;
19306 size_t numberOfOperands = 0;
19308 if (memberFunctionRefExp != NULL)
19310 ROSE_ASSERT(functionRefExp == NULL);
19312 if (memberFunctionDeclaration != NULL)
19314 functionName = memberFunctionDeclaration->get_name();
19315 numberOfOperands = memberFunctionDeclaration->get_args().size();
19321 if (functionRefExp != NULL)
19324 if (functionDeclaration != NULL)
19326 functionName = functionDeclaration->get_name();
19327 numberOfOperands = functionDeclaration->get_args().size();
19333 printf (
"In SageInterface::isPrefixOperator(): unknown case of exp = %p = %s \n",exp,exp->
class_name().c_str());
19338 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);
19343 if (memberFunctionRefExp != NULL)
19346 ROSE_ASSERT(functionRefExp == NULL);
19347 if (numberOfOperands == 0)
19350 returnValue =
true;
19355 returnValue =
false;
19361 ROSE_ASSERT(functionRefExp != NULL);
19362 ROSE_ASSERT(memberFunctionRefExp == NULL);
19363 if (numberOfOperands == 1)
19366 returnValue =
true;
19371 ROSE_ASSERT(numberOfOperands == 2);
19372 returnValue =
false;
19378 printf (
"Leaving SageInterface::isPrefixOperator(): returnValue = %s \n",returnValue ?
"true" :
"false");
19381 return returnValue;
19397 bool returnValue =
false;
19399 if (memberFunctionRefExp == NULL)
19403 if (memberFunctionDeclaration != NULL)
19405 SgName functionName = memberFunctionDeclaration->get_name();
19406 if ( (functionName ==
"operator[]") && (isSgType(memberFunctionDeclaration->get_type()) != NULL) )
19408 returnValue =
true;
19412 if ( (functionName ==
"operator()") && (isSgType(memberFunctionDeclaration->get_type()) != NULL) )
19414 returnValue =
true;
19418 returnValue =
false;
19423 return returnValue;
19434 ROSE_ASSERT(scope != NULL);
19437 printf (
"In SageInterface::lastStatementOfScopeWithTokenInfo(): scope = %p = %s \n",scope,scope->
class_name().c_str());
19440 SgIfStmt* ifStatement = isSgIfStmt(scope);
19441 if (ifStatement != NULL)
19444 if (lastStatement == NULL || (tokenStreamSequenceMap.find(lastStatement) == tokenStreamSequenceMap.end() || tokenStreamSequenceMap[lastStatement] == NULL))
19447 if (lastStatement == NULL || (tokenStreamSequenceMap.find(lastStatement) == tokenStreamSequenceMap.end() || tokenStreamSequenceMap[lastStatement] == NULL))
19449 lastStatement = NULL;
19453 printf (
"Note: SgIfStmt scope in SageInterface::lastStatementOfScopeWithTokenInfo(): returning lastStatement = %p \n",lastStatement);
19454 if (lastStatement != NULL)
19456 printf (
" --- lastStatement = %p = %s \n",lastStatement,lastStatement->
class_name().c_str());
19459 return lastStatement;
19463 if (statementList.rbegin() != statementList.rend())
19466 SgStatementPtrList::reverse_iterator i = statementList.rbegin();
19468 while (i != statementList.rend() && (tokenStreamSequenceMap.find(*i) == tokenStreamSequenceMap.end() || tokenStreamSequenceMap[*i] == NULL) )
19473 if (i == statementList.rend())
19475 lastStatement = NULL;
19479 lastStatement = *i;
19483 return lastStatement;
19497 void visit (
SgNode* node)
19507 printf (
"Found declaration = %p = %s name = %s \n",decl,decl->
class_name().c_str(),
get_name(decl).c_str());
19508 if (decl != definingDeclaration && decl != firstNondefiningDeclaration)
19510 otherDeclaration = decl;
19513 if (definingDeclaration != NULL)
19515 definingDeclaration->get_declarationModifier().get_accessModifier().display(
"definingDeclaration: accessModifier");
19518 if (firstNondefiningDeclaration != NULL)
19520 firstNondefiningDeclaration->get_declarationModifier().get_accessModifier().display(
"firstNondefiningDeclaration: accessModifier");
19523 if (otherDeclaration != NULL)
19525 otherDeclaration->get_declarationModifier().get_accessModifier().display(
"otherDeclaration: accessModifier");
19535 DeclarationTraversal traversal;
19536 traversal.traverse(astNode, preorder);
19548 void visit (
SgNode* node)
19554 if (functionDefinition != NULL)
19557 ROSE_ASSERT(functionDeclaration != NULL);
19559 string functionName = functionDeclaration->get_name();
19561 printf (
"functionName = %s \n",functionName.c_str());
19563 if (functionName ==
"main")
19567 ROSE_ASSERT(functionBody != NULL);
19569 ROSE_ASSERT(symbolTable != NULL);
19572 symbolTable->
print();
19577 if (namespaceDefinition != NULL)
19580 ROSE_ASSERT(namespaceDeclaration != NULL);
19582 string namespaceName = namespaceDeclaration->
get_name();
19584 printf (
"namespaceName = %s \n",namespaceName.c_str());
19586 if (namespaceName ==
"B")
19589 ROSE_ASSERT(symbolTable != NULL);
19592 symbolTable->
print();
19600 ScopeTraversal traversal;
19601 traversal.traverse(astNode, preorder);
19609 if (fileInfo != NULL)
19615 if (locatedNode != NULL)
19624 printf (
"In markNodeToBeUnparsed(): physical_file_id = %d \n",physical_file_id);
19627 locatedNode->
get_file_info()->set_physical_file_id(physical_file_id);
19629 printf (
"Note: calling node markTransformationsForOutput(): node = %p = %s \n",node,node->
class_name().c_str());
19633 markTransformationsForOutput(node);
19638 printf (
"Note: node is not a SgLocatedNode: node = %p = %s \n",node,node->
class_name().c_str());
19645 printf (
"Note: no Sg_File_Info was found: node = %p = %s \n",node,node->
class_name().c_str());
19650 if (locatedNode != NULL)
19659 printf (
"In SageInterface::markNodeToBeUnparsed(): locatedNode = %p = %s calling set_physical_file_id(%d) \n",locatedNode,locatedNode->
class_name().c_str(),physical_file_id);
19661 locatedNode->
get_file_info()->set_physical_file_id(physical_file_id);
19666 printf (
"Note: no Sg_File_Info was found: node = %p = %s \n",node,node->
class_name().c_str());
19698 (void) root; (void) physical_file_id;
19700 class InheritedAttribute
19703 int physical_file_id;
19704 bool isCastSubtree;
19705 InheritedAttribute(
int file_id): physical_file_id(file_id), isCastSubtree(
false) {}
19706 InheritedAttribute(
const InheritedAttribute & X)
19708 isCastSubtree = X.isCastSubtree;
19709 physical_file_id = X.physical_file_id;
19720 InheritedAttribute evaluateInheritedAttribute (
SgNode* node, InheritedAttribute inheritedAttribute)
19722 InheritedAttribute returnAttribute(inheritedAttribute);
19724 SgCastExp* castExpression = isSgCastExp(node);
19725 if (castExpression != NULL)
19727 returnAttribute.isCastSubtree =
true;
19730 if (returnAttribute.isCastSubtree ==
true)
19734 printf (
"In markSubtreeToBeUnparsedTreeTraversal(): subtree of a SgCastExp: node = %p = %s physical_file_id = %d \n",
19735 node,node->
class_name().c_str(),inheritedAttribute.physical_file_id);
19741 printf (
"In markSubtreeToBeUnparsedTreeTraversal(): Calling markNodeToBeUnparsed(): node = %p = %s physical_file_id = %d \n",
19742 node,node->
class_name().c_str(),inheritedAttribute.physical_file_id);
19748 return returnAttribute;
19752 InheritedAttribute inheritedAttribute(physical_file_id);
19755 SubtreeTraversal traversal;
19758 printf (
"\nIn markSubtreeToBeUnparsedTreeTraversal(): calling traverse \n");
19761 traversal.traverse(root, inheritedAttribute);
19763 printf (
"This function does not compile with GNU 4.9 or older compilers (part of ROSE used only with more modern compilers) \n");
19772vector<SgDeclarationStatement*>
19773generateCopiesOfDependentDeclarations (
const vector<SgDeclarationStatement*>& dependentDeclarations,
SgScopeStatement* targetScope)
19784 printf (
"\n\n********************************************************** \n");
19785 printf (
" Inside of generateCopiesOfDependentDeclarations(stmt = %p = %s) \n",stmt,stmt->
class_name().c_str());
19786 printf (
"********************************************************** \n");
19789 vector<SgDeclarationStatement*> copiesOfDependentDeclarations;
19794 printf (
"Output the dependentDeclarations: dependentDeclarations.size() = %" PRIuPTR
" \n",dependentDeclarations.size());
19795 outputDeclarationList(dependentDeclarations);
19798 printf (
"************************************************ \n");
19799 printf (
"*** Make all copies of dependentDeclarations *** \n");
19800 printf (
"************************************************ \n");
19804 ROSE_ASSERT(targetScope != NULL);
19807 ROSE_ASSERT(isSgGlobal(targetScope) != NULL);
19809 for (vector<SgDeclarationStatement*>::const_iterator i = dependentDeclarations.begin(); i != dependentDeclarations.end(); i++)
19812 printf (
"Copying declaration = %p = %s = %s \n",*i,(*i)->class_name().c_str(),
SageInterface::get_name(*i).c_str());
19816 SgNode* copy_node = NULL;
19821 if (functionDeclaration != NULL)
19830 printf (
"WARNING: In SageInterface -- generateCopiesOfDependentDeclarations(): I think this is the wrong lookup symbol function that is being used here! \n");
19837 printf (
"In generateCopiesOfDependentDeclarations(): Copy mechanism appied to SgFunctionDeclaration functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->
get_firstNondefiningDeclaration());
19839 printf (
"functionDeclaration = %p \n",functionDeclaration);
19840 printf (
"functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->
get_definingDeclaration());
19842 printf (
"functionDeclaration->get_scope() = %p \n",functionDeclaration->
get_scope());
19843 printf (
"targetScope = %p \n",targetScope);
19846 assert(copy_functionDeclaration != NULL);
19848 copy_functionDeclaration->
set_parent(targetScope);
19858 assert(copy_functionDeclaration->
get_scope() != NULL);
19859 assert(copy_functionDeclaration->
get_scope() == targetScope);
19860 assert(copy_functionDeclaration->
get_scope()->lookup_function_symbol(copy_functionDeclaration->get_name(),
19861 copy_functionDeclaration->get_type()) != NULL);
19862 assert(copy_functionDeclaration->
get_scope()->lookup_function_symbol(copy_functionDeclaration->get_name(),
19865 copy_node = copy_functionDeclaration;
19867 printf (
"In generateCopiesOfDependentDeclarations(): DONE: Copy mechanism appied to SgFunctionDeclaration \n");
19881 cout<<
"Copying a defining typedef declaration:"<<tdecl->
unparseToString()<<endl;
19883 cout<<
"Copying a non-defining typedef declaration:"<<tdecl->
unparseToString()<<endl;
19887 tdecl_copy->set_typedefBaseTypeContainsDefiningDeclaration (
false);
19890 copy_node = (*i)->copy(collectDependentDeclarationsCopyType);
19894 ROSE_ASSERT(copy_declaration != NULL);
19898 copy_declaration->
set_scope(targetScope);
19910 ROSE_ASSERT(copy_node != NULL);
19919 ROSE_ASSERT(copy_definingDeclaration != NULL);
19921 ROSE_ASSERT( *i != NULL );
19922 ROSE_ASSERT(copy_definingDeclaration != NULL);
19925 if (copy_definingDeclaration->
get_parent() == NULL)
19927 copy_definingDeclaration->
set_parent(targetScope);
19929 ROSE_ASSERT(copy_definingDeclaration->
get_parent() != NULL);
19932 printf (
"DONE: Copying declaration: original scope = %p copied to scope = %p \n",(*i)->get_scope(),copy_definingDeclaration->
get_scope());
19942 ROSE_ASSERT(copy_definingDeclaration->
get_parent() == NULL);
19949 printf (
"copy_definingDeclaration = %p \n",copy_definingDeclaration);
19950 printf (
"copy_definingDeclaration->get_firstNondefiningDeclaration() == NULL \n");
19951 printf (
"copy_definingDeclaration->get_definingDeclaration() = %p \n",copy_definingDeclaration->
get_definingDeclaration());
19956 if ((*i)->get_firstNondefiningDeclaration() != NULL)
19964 copiesOfDependentDeclarations.push_back(copy_definingDeclaration);
19968 printf (
"****************************************************** \n");
19969 printf (
"*** DONE: Make all copies of dependentDeclarations *** \n");
19970 printf (
"****************************************************** \n");
19971 printf (
"copiesOfDependentDeclarations.size() = %" PRIuPTR
" \n",copiesOfDependentDeclarations.size());
19977 ROSE_ASSERT(copiesOfDependentDeclarations.size() <= dependentDeclarations.size());
19979 return copiesOfDependentDeclarations;
19984declarationContainsDependentDeclarations(
SgDeclarationStatement* decl, vector<SgDeclarationStatement*> & dependentDeclarationList )
19987 bool returnValue =
false;
19990 printf (
"\n\n********************************************************** \n");
19991 printf (
" Inside of declarationContainsDependentDeclarations(decl = %p = %s) \n",decl,decl->
class_name().c_str());
19992 printf (
"********************************************************** \n");
20000 for (
size_t i = 0; i < locallyDependentDeclarationList.size(); i++)
20006 vector<SgDeclarationStatement*>::iterator j = find(dependentDeclarationList.begin(),dependentDeclarationList.end(),d);
20007 if (j != dependentDeclarationList.end())
20012 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());
20014 returnValue =
true;
20019 printf (
"**************************************************************************** \n");
20020 printf (
" LEAVING: Inside of declarationContainsDependentDeclarations(decl = %p = %s) returnValue = %s \n",decl,decl->
class_name().c_str(),returnValue ?
"true" :
"false");
20021 printf (
"**************************************************************************** \n");
20024 return returnValue;
20029 ROSE_ASSERT (new_exp != NULL);
20030 ROSE_ASSERT (anchor_exp != NULL);
20031 ROSE_ASSERT (new_exp != anchor_exp);
20034 ROSE_ASSERT (parent != NULL);
20038 ROSE_ASSERT (result != NULL);
20050 ROSE_ASSERT (new_exp != NULL);
20051 ROSE_ASSERT (anchor_exp != NULL);
20052 ROSE_ASSERT (new_exp != anchor_exp);
20055 ROSE_ASSERT (parent != NULL);
20059 ROSE_ASSERT (t != NULL);
20061 ROSE_ASSERT (enclosing_stmt != NULL);
20068 ROSE_ASSERT (temp_sym != NULL);
20070 *temp_decl = t_decl;
20075 * temp_ref = first_ref;
20088 string fileName =
"separate-outlined-file";
20108 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl = %p \n",decl);
20109 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_parent() = %p \n",decl->
get_parent());
20110 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_scope() = %p \n",decl->
get_scope());
20111 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): original_statement = %p \n",original_statement);
20112 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): file (decl) = %s \n",TransformationSupport::getSourceFile(decl)->getFileName().c_str());
20113 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_firstNondefiningDeclaration() = %p \n",decl->
get_firstNondefiningDeclaration());
20115 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): file (first non-defining) = %s \n",TransformationSupport::getSourceFile(decl->
get_firstNondefiningDeclaration())->
getFileName().c_str());
20116 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): decl->get_definingDeclaration() = %p \n",decl->
get_definingDeclaration());
20118 printf (
"***** In SageInterface::appendStatementWithDependentDeclaration(): file (first non-defining) = %s \n",TransformationSupport::getSourceFile(decl->
get_definingDeclaration())->
getFileName().c_str());
20121#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
20153 vector<SgDeclarationStatement*> dependentDeclarationList_inOriginalFile;
20160 vector<SgDeclarationStatement*> dependentDeclarationList = generateCopiesOfDependentDeclarations(dependentDeclarationList_inOriginalFile,scope);
20161 ROSE_ASSERT(dependentDeclarationList.size() <= dependentDeclarationList_inOriginalFile.size());
20171 std::map<SgNode*, SgNode*> replacementMap;
20176 SgCopyHelp::copiedNodeMapType copyNodeMap = collectDependentDeclarationsCopyType.get_copiedNodeMap();
20177 SgCopyHelp::copiedNodeMapType::iterator copyNodeMapItrator = copyNodeMap.begin();
20178 while (copyNodeMapItrator != copyNodeMap.end())
20183 SgNode* first =
const_cast<SgNode*
>(copyNodeMapItrator->first);
20184 SgNode* second = copyNodeMapItrator->second;
20186 printf (
"copyNodeMapItrator.first = %p = %s second = %p = %s \n",first,first->
class_name().c_str(),second,second->
class_name().c_str());
20189 if (isSgSymbol(first) != NULL)
20194 replacementMap.insert(pair<SgNode*,SgNode*>(first,second));
20197 copyNodeMapItrator++;
20201 printf (
"Exiting after test of new functionality \n");
20207 SgSourceFile* sourceFile = TransformationSupport::getSourceFile(original_statement);
20208 vector<PreprocessingInfo*> requiredDirectivesList = collectCppDirectives(sourceFile);
20211 ROSE_ASSERT(outlinedFunctionDeclaration != NULL);
20212 SgGlobal* originalFileGlobalScope = TransformationSupport::getGlobalScope(original_statement);
20213 ROSE_ASSERT(originalFileGlobalScope != NULL);
20215 printf (
"WARNING: In SageInterface::appendStatementWithDependentDeclaration(): I think this is the wrong lookup symbol function that is being used here! \n");
20219 SgFunctionSymbol* outlinedFunctionSymbolFromOriginalFile = isSgFunctionSymbol(originalFileGlobalScope->lookup_symbol(outlinedFunctionDeclaration->get_name(),NULL,NULL));
20225 printf (
"outlinedFunctionSymbolFromOriginalFile = %p outlinedFunctionSymbolFromOutlinedFile = %p \n",outlinedFunctionSymbolFromOriginalFile,outlinedFunctionSymbolFromOutlinedFile);
20227 printf (
"TransformationSupport::getSourceFile(decl)->getFileName() = %s \n",TransformationSupport::getSourceFile(decl)->getFileName().c_str());
20228 printf (
"TransformationSupport::getSourceFile(decl->get_firstNondefiningDeclaration())->getFileName() = %s \n",TransformationSupport::getSourceFile(decl->
get_firstNondefiningDeclaration())->
getFileName().c_str());
20229 printf (
"TransformationSupport::getSourceFile(original_statement)->getFileName() = %s \n",TransformationSupport::getSourceFile(original_statement)->getFileName().c_str());
20232 ROSE_ASSERT(outlinedFunctionSymbolFromOriginalFile != NULL);
20233 ROSE_ASSERT(outlinedFunctionSymbolFromOutlinedFile != NULL);
20236 ROSE_ASSERT(outlinedFunctionSymbolFromOriginalFile == outlinedFunctionSymbolFromOutlinedFile);
20239 replacementMap.insert(pair<SgNode*,SgNode*>(originalFileGlobalScope,scope));
20242 SgFunctionDeclaration* outlinedNondefiningFunctionDeclarationFromOriginalFile = isSgFunctionDeclaration(outlinedFunctionSymbolFromOriginalFile->get_declaration());
20244 ROSE_ASSERT(outlinedNondefiningFunctionDeclarationFromOriginalFile != NULL);
20245 ROSE_ASSERT(outlinedNondefiningFunctionDeclarationFromOutlinedFile != NULL);
20246 replacementMap.insert(pair<SgNode*,SgNode*>(outlinedNondefiningFunctionDeclarationFromOriginalFile,outlinedNondefiningFunctionDeclarationFromOutlinedFile));
20255 for (
size_t i = 0; i < dependentDeclarationList.size(); i++)
20261 printf (
"originalDeclaration = %p \n",originalDeclaration);
20263 d->
get_file_info()->display(
"SageInterface::appendStatementWithDependentDeclaration()");
20271 ROSE_ASSERT(decl->
get_scope() == scope);
20277 printf (
"Add the required symbol information to the symbol table: scope = %p = %s \n",scope,scope->
class_name().c_str());
20284 case V_SgClassDeclaration:
20286 if ( declarationContainsDependentDeclarations(d,dependentDeclarationList) ==
true )
20287 printf (
"Warning: This class contains dependent declarations (not implemented) \n");
20291 case V_SgMemberFunctionDeclaration:
20292 printf (
"Sorry, support for dependent member function declarations not implemented! \n");
20295 case V_SgTemplateInstantiationDecl:
20296 printf (
"Sorry, not implemented: case SgTemplateInstantiationDecl not handled as dependent declaration \n");
20297 d->
get_file_info()->display(
"Sorry, not implemented: case SgTemplateInstantiationDecl not handled as dependent declaration");
20299 printf (
"Case of SgTemplateInstantiationDecl not implemented. \n");
20302 case V_SgNamespaceDeclarationStatement:
20303 if (declarationContainsDependentDeclarations(d,dependentDeclarationList) ==
true )
20304 printf (
"Warning: This namespace contains dependent declarations (not supported) \n");
20307 case V_SgFunctionDeclaration:
20308 case V_SgTypedefDeclaration:
20309 case V_SgEnumDeclaration:
20313 printf (
"default case in SageInterface::appendStatementWithDependentDeclaration() (handling dependentDeclarationList) d = %p = %s \n",d,d->
class_name().c_str());
20319 vector<PreprocessingInfo*> cppDirectivesAlreadyAttachedToDependentDeclarations = collectCppDirectives(d);
20322 printf (
"directives BEFORE excluding those already present in dependent declarations \n");
20323 outputPreprocessingInfoList(requiredDirectivesList);
20325 printf (
"directives already attached to dependent declarations \n");
20326 outputPreprocessingInfoList(cppDirectivesAlreadyAttachedToDependentDeclarations);
20330 vector<PreprocessingInfo*>::iterator j = cppDirectivesAlreadyAttachedToDependentDeclarations.begin();
20331 while ( j != cppDirectivesAlreadyAttachedToDependentDeclarations.end() )
20334 vector<PreprocessingInfo*>::iterator entry = find(requiredDirectivesList.begin(),requiredDirectivesList.end(),*j);
20335 ROSE_ASSERT(entry != requiredDirectivesList.end());
20337 requiredDirectivesList.erase(entry);
20343 printf (
"directives AFTER excluding those already present in dependent declarations \n");
20344 outputPreprocessingInfoList(requiredDirectivesList);
20353 if (dependentDeclarationList.empty() ==
true)
20355 firstStatmentInFile = decl;
20359 firstStatmentInFile = dependentDeclarationList[0];
20362 ROSE_ASSERT(firstStatmentInFile != NULL);
20370 if (excludeHeaderFiles ==
false)
20373 vector<PreprocessingInfo*>::reverse_iterator j = requiredDirectivesList.rbegin();
20374 while ( j != requiredDirectivesList.rend() )
20393 SgSourceFile* outlinedFile = TransformationSupport::getSourceFile(scope);
20394 ROSE_ASSERT(outlinedFile != NULL);
20400 printf (
"\n\n************************************************************\n");
20401 printf (
"Calling Utils::edgePointerReplacement() \n");
20407 printf (
"Calling Utils::edgePointerReplacement(): DONE \n");
20408 printf (
"************************************************************\n\n");
20410 printf (
"\n\n After replacementMapTraversal(): intermediateDeleteSet: \n");
20411 displaySet(intermediateDeleteSet,
"After Utils::edgePointerReplacement");
20415 ROSE_ASSERT(dependentDeclarationList.size() <= dependentDeclarationList_inOriginalFile.size());
20423 printf (
"replacementMap.size() = %" PRIuPTR
" dependentDeclarationList.size() = %" PRIuPTR
" \n",replacementMap.size(),dependentDeclarationList.size());
20431 using DeletedStatementContainer = std::unordered_set<SgStatement*>;
20439 int SgVariableSymbol_count = 0;
20440 int SgFunctionSymbol_count = 0;
20441 int SgClassDeclaration_count = 0;
20442 int SgTypedefSymbol_count = 0;
20443 int SgMemFuncSymbol_count = 0;
20444 int SgTemplateSymbol_count = 0;
20445 int SgEnumFieldSymbol_count = 0;
20460 DeletedStatementContainer& deletedStatements;
20462 void markForDeletion(
SgStatement* n) { deletedStatements.insert(n); }
20466 ClassicVisitor(
SgVariableSymbol* symbol, DeletedStatementContainer& deletedStmt)
20467 : SgVariableSymbolPtr(symbol), deletedStatements(deletedStmt)
20470 ClassicVisitor(
SgFunctionSymbol* symbol, DeletedStatementContainer& deletedStmt)
20471 : SgFunctionSymbolPtr(symbol), deletedStatements(deletedStmt)
20474 ClassicVisitor(
SgClassSymbol* symbol, DeletedStatementContainer& deletedStmt)
20475 : SgClassSymbolPtr(symbol), deletedStatements(deletedStmt)
20478 ClassicVisitor(
SgTypedefSymbol* symbol, DeletedStatementContainer& deletedStmt)
20479 : SgTypedefPtr(symbol), deletedStatements(deletedStmt)
20483 : SgMemFuncSymbolPtr(symbol), deletedStatements(deletedStmt)
20486 ClassicVisitor(
SgTemplateSymbol* symbol, DeletedStatementContainer& deletedStmt)
20487 : SgTemplateSymbolPtr(symbol), deletedStatements(deletedStmt)
20490 ClassicVisitor(
SgEnumFieldSymbol* symbol, DeletedStatementContainer& deletedStmt)
20491 : SgEnumFieldSymbolPtr(symbol), deletedStatements(deletedStmt)
20495 : class_defining(decl), deletedStatements(deletedStmt)
20499 : template_defining(decl), deletedStatements(deletedStmt)
20503 : function_decl(decl), deletedStatements(deletedStmt)
20507 : memFunc(decl), deletedStatements(deletedStmt)
20511 : typedef_defining(decl), deletedStatements(deletedStmt)
20515 : templateInstantiate_defining(decl), deletedStatements(deletedStmt)
20522 if(SgVariableSymbolPtr !=NULL)
20524 if(node->get_scope()!=NULL)
20530 if (isSgVariableSymbol(s) == SgVariableSymbolPtr) SgVariableSymbol_count++;
20535 if(SgEnumFieldSymbolPtr !=NULL)
20537 if(node->get_scope()!=NULL)
20543 if (isSgEnumFieldSymbol(s) == SgEnumFieldSymbolPtr) SgEnumFieldSymbol_count++;
20551 if(SgVariableSymbolPtr !=NULL){
20553 if (s == SgVariableSymbolPtr) SgVariableSymbol_count++;
20557 int get_num_variable_pointers(){
return SgVariableSymbol_count;}
20558 int get_num_EnumField_pointers(){
return SgEnumFieldSymbol_count;}
20561 if(SgFunctionSymbolPtr !=NULL) {
20567 if ((
SgFunctionSymbol *)s == SgFunctionSymbolPtr) SgFunctionSymbol_count++;
20575 if (SgFunctionSymbolPtr !=NULL)
20578 if (isSgFunctionSymbol(s) == SgFunctionSymbolPtr)
20580 SgFunctionSymbol_count++;
20587 if (SgFunctionSymbolPtr !=NULL)
20590 if (isSgFunctionSymbol(s) == SgFunctionSymbolPtr)
20592 SgFunctionSymbol_count++;
20599 if (SgFunctionSymbolPtr !=NULL){
20601 if (isSgFunctionSymbol(s) == SgFunctionSymbolPtr) SgFunctionSymbol_count++;
20605 int get_num_Function_pointers(){
return SgFunctionSymbol_count;}
20609 if(SgClassSymbolPtr !=NULL){
20614 if (isSgClassSymbol(s) == SgClassSymbolPtr) SgClassDeclaration_count++;
20619 if(class_defining!=NULL) {
20623 if((class_decl==class_defining||class_decl1==class_defining) && node!=class_defining )
20624 markForDeletion(node);
20631 if(SgClassSymbolPtr !=NULL){
20636 if (isSgClassSymbol(s) == SgClassSymbolPtr) SgClassDeclaration_count++;
20641 if(templateInstantiate_defining!=NULL) {
20648 if((template_decl==templateInstantiate_defining||template_decl1==templateInstantiate_defining) && node!=templateInstantiate_defining){
20657 markForDeletion(node);
20668 if (SgClassSymbolPtr !=NULL){
20669 SgSymbol* s = node->get_class_symbol();
20670 if (s == SgClassSymbolPtr) SgClassDeclaration_count++;
20676 if (SgClassSymbolPtr !=NULL){
20678 if (isSgClassSymbol(s) == SgClassSymbolPtr) SgClassDeclaration_count++;
20683 int get_num_Class_pointers(){
return SgClassDeclaration_count;}
20689 if(memFunc !=NULL){
20691 if(func == memFunc){
20692 markForDeletion(node);
20700 if (SgMemFuncSymbolPtr !=NULL){
20705 if(symbol == SgMemFuncSymbolPtr){
20706 SgMemFuncSymbol_count++;
20715 if (SgMemFuncSymbolPtr !=NULL){
20720 if(symbol == SgMemFuncSymbolPtr){
20721 SgMemFuncSymbol_count++;
20730 int get_num_memFunc_pointers(){
return SgMemFuncSymbol_count;}
20736 if(SgTypedefPtr!=NULL){
20745 if(typedef_defining!=NULL){
20747 if(typedef_define == typedef_defining && node != typedef_defining ) {
20748 markForDeletion(node);
20753 int get_num_Typedef_pointers(){
return SgTypedefSymbol_count;}
20759 if (SgTemplateSymbolPtr !=NULL){
20764 if(symbol == SgTemplateSymbolPtr){
20765 SgTemplateSymbol_count++;
20771 if(template_defining !=NULL) {
20778 if((template_decl==template_defining||template_decl1==template_defining) && node!=template_defining) {
20779 markForDeletion(node);
20788 int get_num_Template_pointers(){
return SgTemplateSymbol_count;}
20797 void visit (
SgNode* node)
20803 if(isSgInitializedName(node) !=NULL){
20807 if(isSgVariableDefinition(var_def) !=NULL){
20808 markForDeletion(var_def);
20814 if(isSgInitializedName(node)->get_scope()!=NULL){
20815 if(isSgInitializedName(node)->get_scope()->get_symbol_table()!=NULL)
20818 if(isSgVariableSymbol(symbol) !=NULL){
20820 traverseMemoryPoolVisitorPattern(visitor);
20821 if(visitor.get_num_variable_pointers()==1){
20828 if(isSgEnumFieldSymbol(symbol) !=NULL){
20830 traverseMemoryPoolVisitorPattern(visitor);
20831 if(visitor.get_num_EnumField_pointers()==1){
20842 if(isSgVarRefExp(node) !=NULL){
20844 ClassicVisitor visitor(symbol, deletedStatements);
20845 traverseMemoryPoolVisitorPattern(visitor);
20846 if(visitor.get_num_variable_pointers()==1){
20858 SgFunctionDeclaration* funcDecl = isSgFunctionDeclaration(node);
20859 if (funcDecl != NULL){
20860 if (isSgMemberFunctionDeclaration(node) == NULL) {
20861 if (funcDecl->get_scope() != NULL) {
20862 if (funcDecl->get_scope()->get_symbol_table() != NULL) {
20863 SgSymbol* symbol = ((SgFunctionDeclaration*)node)->get_symbol_from_symbol_table();
20864 ClassicVisitor visitor((SgFunctionSymbol *)symbol, deletedStatements);
20865 traverseMemoryPoolVisitorPattern(visitor);
20866 if (visitor.get_num_Function_pointers()==1) { //only one reference to this FunctionSymbol => safe to delete
20867 ((SgFunctionDeclaration*)node)->get_scope()->get_symbol_table()->remove(symbol);
20869 //printf("A SgFunctionSymbol was deleted\n");
20871 ClassicVisitor visitor1((SgFunctionDeclaration *)node, deletedStatements);
20872 traverseMemoryPoolVisitorPattern(visitor1);
20879 if(isSgFunctionRefExp(node) !=NULL)
20881 SgFunctionSymbol *symbol = ((SgFunctionRefExp*)node)->get_symbol_i();
20882 ClassicVisitor visitor(symbol, deletedStatements);
20883 traverseMemoryPoolVisitorPattern(visitor);
20884 if(visitor.get_num_Function_pointers()==1)
20886 // only one reference to this FunctionSymbol => safe to delete
20892 if(isSgUserDefinedBinaryOp(node) !=NULL){
20893 SgFunctionSymbol *symbol = ((SgUserDefinedBinaryOp*)node)->get_symbol();
20894 ClassicVisitor visitor(symbol, deletedStatements);
20895 traverseMemoryPoolVisitorPattern(visitor);
20896 if(visitor.get_num_Function_pointers()==1){ //only one reference to this FunctionSymbol => safe to delete
20897 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
20899 //printf("A SgFunctionSymbol was deleted\n");
20907 if(isSgTypedefDeclaration(node) !=NULL){
20912 if(isSgTypedefSymbol(symbol)){
20913 ClassicVisitor visitor((
SgTypedefSymbol*) symbol, deletedStatements);
20914 traverseMemoryPoolVisitorPattern(visitor);
20915 if(visitor.get_num_Typedef_pointers()==1){
20926 traverseMemoryPoolVisitorPattern(visitor1);
20934 if(isSgNamespaceDeclarationStatement(node) !=NULL){
20935 if(((SgNamespaceDeclarationStatement*)node)->get_scope()!=NULL){
20936 if(((SgNamespaceDeclarationStatement*)node)->get_scope()->get_symbol_table()!=NULL)
20938 SgSymbol* symbol = ((SgNamespaceDeclarationStatement*)node)->get_symbol_from_symbol_table();
20939 if(isSgNamespaceSymbol(symbol)){
20940 ((SgNamespaceDeclarationStatement*)node)->get_scope()->get_symbol_table()->remove(symbol);
20942 //printf("A SgNamespaceSymbol was deleted\n");
20949 if(isSgNamespaceAliasDeclarationStatement(node) !=NULL){
20950 if(((SgNamespaceAliasDeclarationStatement*)node)->get_scope()!=NULL){
20951 if(((SgNamespaceAliasDeclarationStatement*)node)->get_scope()->get_symbol_table()!=NULL)
20953 SgSymbol* symbol = ((SgNamespaceAliasDeclarationStatement*)node)->get_symbol_from_symbol_table();
20954 if(isSgNamespaceSymbol(symbol)){
20955 ((SgNamespaceAliasDeclarationStatement*)node)->get_scope()->get_symbol_table()->remove(symbol);
20957 //printf("A SgNamespaceSymbol was deleted\n");
20968 if(isSgLabelStatement(node) !=NULL){
20973 if(isSgLabelSymbol(symbol)){
20982 if(isSgLabelRefExp(node) !=NULL){
20994 if(isSgEnumDeclaration(node) !=NULL){
20995 if(((SgEnumDeclaration*)node)->get_scope()!=NULL){
20996 if(((SgEnumDeclaration*)node)->get_scope()->get_symbol_table()!=NULL)
20998 SgSymbol* symbol = ((SgEnumDeclaration*)node)->get_symbol_from_symbol_table();
20999 if(isSgEnumSymbol(symbol) !=NULL){
21000 ((SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21002 //printf("A SgEnumSymbol was deleted\n");
21006 SgEnumType* type= ((SgEnumDeclaration*)node)->get_type();
21009 //printf("A SgEnumType was deleted\n");
21018 if(isSgClassDeclaration(node) !=NULL && isSgTemplateInstantiationDecl(node) ==NULL){
21023 if(isSgClassSymbol(symbol) !=NULL){
21024 ClassicVisitor visitor((
SgClassSymbol*)symbol, deletedStatements);
21025 traverseMemoryPoolVisitorPattern(visitor);
21026 if(visitor.get_num_Class_pointers()==1){
21036 traverseMemoryPoolVisitorPattern(visitor);
21045 if(isSgThisExp(node) !=NULL){
21047 ClassicVisitor visitor((
SgClassSymbol*)symbol, deletedStatements);
21048 traverseMemoryPoolVisitorPattern(visitor);
21049 if(visitor.get_num_Class_pointers()==1){
21050 ((
SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21057 if(isSgClassNameRefExp(node) !=NULL){
21059 if(isSgClassSymbol(symbol) !=NULL)
21061 ClassicVisitor visitor((
SgClassSymbol*)symbol, deletedStatements);
21062 traverseMemoryPoolVisitorPattern(visitor);
21063 if(visitor.get_num_Class_pointers()==1){
21064 ((
SgSymbol*)symbol)->get_scope()->get_symbol_table()->remove(symbol);
21076 if(isSgMemberFunctionDeclaration(node) !=NULL){
21077 if(((SgMemberFunctionDeclaration*)node)->get_scope()!=NULL){
21078 if(((SgMemberFunctionDeclaration*)node)->get_scope()->get_symbol_table()!=NULL)
21080 SgSymbol* symbol = ((SgMemberFunctionDeclaration*)node)->get_symbol_from_symbol_table();
21081 if(isSgMemberFunctionSymbol(symbol)){
21082 ClassicVisitor visitor((SgMemberFunctionSymbol*)symbol, deletedStatements);
21083 traverseMemoryPoolVisitorPattern(visitor);
21084 if(visitor.get_num_memFunc_pointers()==1){
21085 ((SgMemberFunctionDeclaration*)node)->get_scope()->get_symbol_table()->remove(symbol);
21087 //printf("A SgMemberFunctionSymbol was deleted\n");
21092 ClassicVisitor visitor((SgMemberFunctionDeclaration*) node, deletedStatements);
21093 traverseMemoryPoolVisitorPattern(visitor);
21101 if(isSgInterfaceStatement(node) !=NULL){
21106 if(isSgInterfaceSymbol(symbol)){
21117 if(isSgModuleStatement(node) !=NULL){
21122 if(isSgModuleSymbol(symbol)){
21134 markForDeletion(stmt);
21139 void cleanUpMacrosThenDeleteStatements(
SgSourceFile* file)
21143 std::map<SgStatement*,MacroExpansion*>& macroMap = file->get_macroExpansionMap();
21145 for (
SgStatement* deletedStmt : deletedStatements)
21147 auto pos = macroMap.find(deletedStmt);
21148 if (pos == macroMap.end())
continue;
21150 ASSERT_not_null(pos->second);
21151 std::vector<SgStatement*>& vec = pos->second->associatedStatementVector;
21152 auto const vecLim = vec.end();
21154 vec.erase(std::remove(vec.begin(), vecLim, deletedStmt), vecLim);
21156 macroMap.erase(pos);
21160 for (
SgStatement* deletedStmt : deletedStatements)
21161 delete deletedStmt;
21164 void markForDeletion(
SgStatement* n) { deletedStatements.insert(n); }
21168 DeletedStatementContainer deletedStatements;
21174 DeleteAST deleteTree;
21177 deleteTree.traverse(n,postorder);
21178 deleteTree.cleanUpMacrosThenDeleteStatements(sourceFile);
21202 virtual void visit(
SgNode* n)
21205 if (expression != NULL)
21207 Visitor().traverse(expression->get_originalExpressionTree(), postorder);
21214 Visitor().traverse(root, postorder);
21226 SgSymbol* symbol = s_table->find(iname);
21227 ASSERT_not_null(symbol);
21232 ASSERT_not_null(sourceBlock);
21233 ASSERT_not_null(targetBlock);
21248 SgSymbol* symbol = s_table->find(iname);
21249 ASSERT_not_null(symbol);
21256 ASSERT_not_null(symbol);
21267 ASSERT_require(stmt->
get_parent() == targetBlock);
21282 func->set_scope(targetBlock);
21285 SgFunctionDeclaration* nondef_decl= isSgFunctionDeclaration(func->get_firstNondefiningDeclaration());
21286 if (func != nondef_decl)
21288 ASSERT_not_null(nondef_decl);
21295 else if (
auto labelStmt = isSgLabelStatement(stmt))
21297 if (labelStmt->get_scope() == sourceBlock) {
21298 labelStmt->set_scope(targetBlock);
21303 else if (isSgJovialTableStatement(stmt) || isSgTypedefDeclaration(stmt) || isSgEnumDeclaration(stmt))
21311 mlog[Rose::Diagnostics::WARN] <<
"test failing stmt->get_scope() == targetBlock in SageInterface::moveStatementsBetweenBlocks(): class: "
21318 if (declaration !=
nullptr)
21325 case V_SgVariableDeclaration:
21330 for (SgInitializedNamePtrList::iterator ii = l.begin(); ii != l.end(); ii++)
21340 SgType* var_type = init_name->get_type();
21343 var_type = mod_type->get_base_type();
21350 if (isSgEnumType(var_type))
21352 SgEnumType* enum_type = isSgEnumType(var_type);
21367 enumerator->set_scope(targetBlock);
21371 else if (isSgJovialTableType(var_type))
21387 SgVariableSymbol* var_sym = isSgVariableSymbol(init_name -> search_for_symbol_from_symbol_table ()) ;
21388 ASSERT_not_null(var_sym);
21391 if (old_scope != sourceBlock)
21393 old_scope->remove_symbol (var_sym);
21394 sourceBlock ->
insert_symbol(init_name->get_name(), var_sym);
21397 init_name->set_scope(targetBlock);
21398 initname_vec.push_back(init_name);
21402 case V_SgFunctionDeclaration:
21405 ASSERT_not_null(funcDecl);
21412 if (old_scope != sourceBlock)
21414 old_scope->remove_symbol (func_sym);
21422 case V_SgProgramHeaderStatement:
21423 case V_SgProcedureHeaderStatement:
21424 case V_SgClassDeclaration:
21425 case V_SgEnumDeclaration:
21428 ASSERT_not_null(nondef_decl);
21442 if (
auto proc = isSgProcedureHeaderStatement(nondef_decl)) {
21443 for (
auto arg : proc->get_parameterList()->get_args()) {
21444 if (arg->get_scope() != proc->get_scope()) {
21448 arg->set_scope(proc->get_scope());
21460 name->set_scope(targetBlock);
21465 case V_SgJovialTableStatement:
21469 ROSE_ASSERT (table);
21478 case V_SgTypedefDeclaration:
21482 ASSERT_not_null(typedef_decl);
21487 case V_SgAttributeSpecificationStatement:
21488 case V_SgEmptyDeclaration:
21489 case V_SgFortranIncludeLine:
21490 case V_SgImplicitStatement:
21491 case V_SgJovialDefineDeclaration:
21492 case V_SgJovialDirectiveStatement:
21493 case V_SgJovialLabelDeclaration:
21494 case V_SgJovialOverlayDeclaration:
21495 case V_SgPragmaDeclaration:
21496 case V_SgAdaAttributeClause:
21500 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());
21509template <
class T1,
class T2>
21510void moveDeclarationsBetweenScopes( T1* sourceBlock, T2* targetBlock)
21514 ROSE_ASSERT (sourceBlock && targetBlock);
21515 ROSE_ASSERT (sourceBlock->containsOnlyDeclarations() && targetBlock->containsOnlyDeclarations());
21516 if ((
void*)sourceBlock == (
void*)targetBlock)
21518 cerr<<
"warning: SageInterface::moveStatementsBetweenScopes() is skipped, "<<endl;
21519 cerr<<
" since program is trying to move statements from and to the identical scoped block. "<<endl;
21523 SgDeclarationStatementPtrList& srcStmts = sourceBlock->get_declarations ();
21524 std::vector <SgInitializedName*> initname_vec;
21526 for (
auto stmt : srcStmts)
21528 moveOneStatement(sourceBlock, targetBlock, stmt, initname_vec);
21533 ROSE_ASSERT(srcStmts.empty() ==
true);
21534 ROSE_ASSERT(sourceBlock->get_declarations().empty() ==
true);
21537 moveSymbolTableBetweenBlocks(sourceBlock, targetBlock, initname_vec);
21550template <
class T1,
class T2>
21551void moveStatementsBetweenScopes( T1* sourceBlock, T2* targetBlock)
21554 ROSE_ASSERT (sourceBlock && targetBlock);
21555 if ((
void*)sourceBlock == (
void*)targetBlock)
21557 cerr<<
"warning: SageInterface::moveStatementsBetweenScopes() is skipped, "<<endl;
21558 cerr<<
" since program is trying to move statements from and to the identical scoped block. "<<endl;
21562 SgStatementPtrList & srcStmts = sourceBlock->get_statements();
21563 std::vector <SgInitializedName*> initname_vec;
21567 moveOneStatement(sourceBlock, targetBlock, stmt, initname_vec);
21572 ROSE_ASSERT(srcStmts.empty() ==
true);
21573 ROSE_ASSERT(sourceBlock->get_statements().empty() ==
true);
21576 moveSymbolTableBetweenBlocks(sourceBlock, targetBlock, initname_vec);
21590 ASSERT_not_null(decl);
21594 ASSERT_require(local_def && global_def && (local_def!=global_def));
21596 for (
auto symbol : local_def->get_symbol_table()->get_symbols())
21598 SgSymbol *orig_sym = isSgSymbol(symbol);
21599 ASSERT_not_null(orig_sym);
21608 moveDeclarationsBetweenScopes(sourceBlock, targetBlock);
21610 createAliasSymbols(isSgNamespaceDeclarationStatement(targetBlock->
get_parent()));
21615 moveStatementsBetweenScopes(sourceBlock, targetBlock);
21617 createAliasSymbols(isSgNamespaceDeclarationStatement(targetBlock->
get_parent()));
21622 moveDeclarationsBetweenScopes(sourceBlock, targetBlock);
21628 moveStatementsBetweenScopes (sourceBlock, targetBlock);
21636 ROSE_ASSERT (func != NULL);
21638 ROSE_ASSERT (p != NULL);
21640 if (le && le->get_lambda_function() == func)
21653 #pragma message ("WARNING: MSVC does not handle isLambdaCapturedVariable() properly.")
21655 ROSE_ASSERT (varRef!= NULL);
21659 SgThisExp* te = isSgThisExp(p->get_lhs_operand_i());
21663 ROSE_ASSERT (csym!= NULL);
21666 ROSE_ASSERT (xdecl != NULL);
21670 if (le->get_lambda_closure_class() == xdecl )
21686 ROSE_ASSERT(current != NULL);
21688 if (isSgInitializedName(current))
21690 name = isSgInitializedName(current);
21692 else if (isSgPntrArrRefExp(current) != NULL)
21696 ROSE_ASSERT(exp != NULL);
21698 ROSE_ASSERT(suc ==
true);
21702 else if (isSgVarRefExp(current) != NULL)
21708 if (isSgDotExp(parent))
21710 if (isSgDotExp(parent)->get_rhs_operand() == current)
21716 if (isSgArrowExp(parent)->get_rhs_operand() == current)
21720 name = isSgVarRefExp(current)->get_symbol()->get_declaration();
21722 else if (isSgFunctionRefExp(current) != NULL ||
21723 isSgTemplateFunctionRefExp(current) != NULL ||
21724 isSgMemberFunctionRefExp(current) != NULL ||
21725 isSgTemplateMemberFunctionRefExp(current) != NULL)
21730 else if (isSgNonrealRefExp(current) != NULL)
21735 else if (isSgDotExp(current))
21742 ROSE_ASSERT(child);
21746 else if (isSgArrowExp(current))
21767 ROSE_ASSERT(child);
21772 else if (isSgThisExp(current))
21777 else if (isSgPointerDerefExp(current))
21781 else if(isSgUnaryOp(current)) {
21784 else if (isSgCastExp(current))
21790 else if (isSgAddOp(current))
21795 else if (isSgSubtractOp(current))
21806 else if (isSgIntVal(current))
21816 if (!isSgConstructorInitializer(current))
21818 mlog[Sawyer::Message::Common::WARN] <<
21819 "convertRefToInitializedName: " <<
21822 cerr<<
"In SageInterface::convertRefToInitializedName(): unhandled reference type:"<<current->
class_name()<<endl;
21833#ifdef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
21834 printf (
"AbstractHandle support is disabled for ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT \n");
21840 size_t pos = input_string.find(
"SourceFile<");
21841 ROSE_ASSERT (pos != string::npos);
21842 string trimed_string = input_string.substr(pos);
21846 if (handle->getNode()!=NULL)
21851#pragma message ("WARNING: covariant return type for get_node() not supported in MSVC.")
21852 printf (
"ERROR: covariant return type for get_node() not supported in MSVC. \n");
21875 ROSE_ASSERT(node != NULL);
21878 cout<<
"///////////// begin of SageInterface::dumpInfo() ///////////////"<<endl;
21879 cout<<
"--------------base info. for SgNode---------------"<<endl;
21885 cout<<
"--------------source location info. for SgNode---------------"<<endl;
21893 cout<<
"--------------preprocessing info. for SgNode---------------"<<endl;
21894 AttachedPreprocessingInfoType::iterator i;
21895 cout<<
"Total attached preprocessingInfo count="<<comments->size()<<endl;
21896 for (i = comments->begin (); i != comments->end (); i++)
21899 pinfo->display(
"");
21902 cout<<
"--------------name info. for SgNode---------------"<<endl;
21906 cout<<
"\tqualified name="<<decl->get_qualified_name().getString()<<endl;
21909 cout<<
"\treferenced variable name= "<<varRef->get_symbol()->
get_name().getString()<<endl;
21916 cout<<
"///////////// end of SageInterface::dumpInfo() ///////////////"<<endl;
21927 bool retVal =
true;
21929 ROSE_ASSERT(stmt !=NULL);
21931#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
21938 if (funcDecl != NULL)
21941 if (funcDecl == NULL)
21943 cerr<<
"In collectReadWriteRefs(): cannot proceed without a function body!"<<endl;
21946 stmt = funcDecl->get_definition()->
get_body();
21954 ROSE_ASSERT(funcDef != NULL);
21956 ROSE_ASSERT(funcBody!= NULL);
21959 AstInterfaceImpl faImpl(funcBody);
21960 AstInterface fa(&faImpl);
21961 ArrayAnnotation* annot = ArrayAnnotation::get_inst();
21962 if( useCachedDefUse ){
21963 ArrayInterface* array_interface = ArrayInterface::get_inst(*annot, fa, funcDef, AstNodePtrImpl(funcDef));
21964 LoopTransformInterface::set_arrayInfo(array_interface);
21966 ArrayInterface array_interface(*annot);
21969 array_interface.observe(fa);
21970 LoopTransformInterface::set_arrayInfo(&array_interface);
21972 LoopTransformInterface::set_astInterface(fa);
21974 LoopTransformInterface::set_sideEffectInfo(annot);
21977 DoublyLinkedListWrap<AstNodePtr> rRef1, wRef1;
21978 CollectDoublyLinkedList<AstNodePtr> crRef1(rRef1),cwRef1(wRef1);
21979 AstNodePtr s1 = AstNodePtrImpl(stmt);
21982 if (!AnalyzeStmtRefs(fa, s1, cwRef1, crRef1))
21987 mlog[Sawyer::Message::Common::DEBUG] <<
"Function: " << funcDef->get_declaration()->get_qualified_name() <<
" calls at least one function that has not been annotated." << endl;
21992 for (DoublyLinkedEntryWrap<AstNodePtr>* p = rRef1.First(); p != 0; )
21994 DoublyLinkedEntryWrap<AstNodePtr>* p1 = p;
21996 AstNodePtr cur = p1->GetEntry();
21997 SgNode* sgRef = AstNodePtrImpl(cur).get_ptr();
21998 ROSE_ASSERT(sgRef != NULL);
21999 readRefs.push_back(sgRef);
22004 for (DoublyLinkedEntryWrap<AstNodePtr>* p = wRef1.First(); p != 0; )
22006 DoublyLinkedEntryWrap<AstNodePtr>* p1 = p;
22008 AstNodePtr cur = p1->GetEntry();
22009 SgNode* sgRef = AstNodePtrImpl(cur).get_ptr();
22010 ROSE_ASSERT(sgRef != NULL);
22011 writeRefs.push_back(sgRef);
22024static bool skipSomeRefs(
SgNode* n)
22027 return (isSgThisExp(n)||isSgArrowExp(n)||isSgDotExp(n));
22033 ROSE_ASSERT(stmt != NULL);
22034 vector <SgNode* > readRefs, writeRefs;
22038 vector<SgNode*>::iterator iter = readRefs.begin();
22039 for (; iter!=readRefs.end();iter++)
22041 SgNode* current = *iter;
22044 ROSE_ASSERT (current != NULL);
22047 if (!name)
continue;
22050 readVars.insert(name);
22053 vector<SgNode*>::iterator iterw = writeRefs.begin();
22054 for (; iterw!=writeRefs.end();iterw++)
22056 SgNode* current = *iterw;
22057 ROSE_ASSERT (current != NULL);
22059 if (!name)
continue;
22063 writeVars.insert(name);
22071 ROSE_ASSERT(stmt != NULL);
22072 set<SgInitializedName*> readVars, writeVars;
22077 set_difference(readVars.begin(), readVars.end(),
22078 writeVars.begin(), writeVars.end(),
22079 std::inserter(readOnlyVars, readOnlyVars.begin()));
22089 readOnlyVars.insert (v_ref->get_symbol()->get_declaration());
22099 set<SgInitializedName*> temp;
22102 for (set<SgInitializedName*>::const_iterator iter = temp.begin();
22103 iter!=temp.end(); iter++)
22105 SgSymbol* symbol = (*iter)->get_symbol_from_symbol_table () ;
22106 ROSE_ASSERT(symbol != NULL );
22107 ROSE_ASSERT(isSgVariableSymbol(symbol));
22108 readOnlySymbols.insert(isSgVariableSymbol(symbol));
22116 bool result =
false;
22117 ROSE_ASSERT(ref != NULL);
22129 ROSE_ASSERT(grandparent);
22130 if (isSgFunctionCallExp(grandparent))
22136 size_t param_index = 0;
22138 SgExpressionPtrList expList = isSgExprListExp(ref->
get_parent())->get_expressions();
22139 Rose_STL_Container<SgExpression*>::const_iterator iter= expList.begin();
22140 for (; iter!=expList.end(); iter++)
22148 SgExpression* func_exp = isSgFunctionCallExp(grandparent)->get_function();
22149 ROSE_ASSERT (func_exp);
22154 SgInitializedNamePtrList nameList = funcDecl->get_args();
22159 if (param_index >= nameList.size() ||isSgTypeEllipse(nameList[param_index]->get_type()) )
22161 if (isSgReferenceType(ref))
22165 if (isSgReferenceType(nameList[param_index]->get_type()))
22170 else if (isSgDotExp (func_exp) || isSgArrowExp(func_exp))
22173 ROSE_ASSERT (binOp);
22175 ROSE_ASSERT (mfuncRef);
22177 ROSE_ASSERT (mfuncDecl);
22178 SgInitializedNamePtrList nameList = mfuncDecl->get_args();
22180 if (isSgReferenceType(nameList[param_index]->get_type()))
22195 Rose_STL_Container <SgNode*> var_refs = NodeQuery::querySubTree (
const_cast<SgStatement *
> (s), V_SgVarRefExp);
22197 Rose_STL_Container<SgNode*>::iterator iter = var_refs.begin();
22198 for (; iter!=var_refs.end(); iter++)
22201 ROSE_ASSERT(ref != NULL);
22208 varSetB.insert(ref);
22214 ROSE_ASSERT(grandparent);
22215 if (isSgFunctionCallExp(grandparent))
22218 int param_index =0;
22219 SgExpressionPtrList expList = isSgExprListExp(ref->
get_parent())->get_expressions();
22220 Rose_STL_Container<SgExpression*>::const_iterator iter= expList.begin();
22221 for (; iter!=expList.end(); iter++)
22229 SgFunctionRefExp * funcRef = isSgFunctionRefExp(isSgFunctionCallExp(grandparent)->get_function());
22231 SgInitializedNamePtrList nameList = funcDecl->get_args();
22233 if (isSgReferenceType(nameList[param_index]->get_type()))
22235 varSetB.insert(ref);
22241 varSetB.insert(ref);
22245#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22250 static LivenessAnalysis* liv = NULL;
22254 static DFAnalysis * defuse = NULL;
22258 ROSE_ASSERT(project != NULL);
22259 defuse =
new DefUseAnalysis(project);
22262 ROSE_ASSERT(defuse != NULL);
22263 defuse->run(debug);
22266 defuse->dfaToDOT();
22269 liv =
new LivenessAnalysis(debug,(DefUseAnalysis*)defuse);
22270 ROSE_ASSERT(liv != NULL);
22272 std::vector <FilteredCFGNode < IsDFAFilter > > dfaFunctions;
22273 NodeQuerySynthesizedAttributeType vars =
22274 NodeQuery::querySubTree(project, V_SgFunctionDefinition);
22275 NodeQuerySynthesizedAttributeType::const_iterator i;
22276 bool abortme=
false;
22278 for (i= vars.begin(); i!=vars.end();++i)
22281 ROSE_ASSERT(func != NULL);
22285 string funcName = func->get_declaration()->get_qualified_name().str();
22286 cout<<
" .. running liveness analysis for function: " << funcName << endl;
22288 FilteredCFGNode <IsDFAFilter> rem_source = liv->run(func,abortme);
22290 liv->fixupStatementsINOUT(func);
22291 if (rem_source.getNode()!=NULL)
22292 dfaFunctions.push_back(rem_source);
22298 cout <<
"Writing out liveness analysis results into var.dot... " << endl;
22299 std::ofstream f2(
"var.dot");
22300 dfaToDot(f2,
string(
"var"), dfaFunctions, (DefUseAnalysis*)defuse, liv);
22304 cerr<<
"Error: Liveness analysis is ABORTING ." << endl;
22312#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22316 ROSE_ASSERT(liv != NULL);
22317 ROSE_ASSERT(loop != NULL);
22319 std::vector<SgInitializedName*> liveIns0, liveOuts0;
22329 CFGNode cfgnode(forstmt,2);
22330 FilteredCFGNode<IsDFAFilter> filternode= FilteredCFGNode<IsDFAFilter> (cfgnode);
22334 ROSE_ASSERT(filternode.getNode()==forstmt);
22337 vector<FilteredCFGEdge < IsDFAFilter > > out_edges = filternode.outEdges();
22338 ROSE_ASSERT(out_edges.size()==2);
22339 vector<FilteredCFGEdge < IsDFAFilter > >::iterator iter= out_edges.begin();
22341 for (; iter!=out_edges.end();iter++)
22343 FilteredCFGEdge < IsDFAFilter > edge= *iter;
22347 if (edge.condition()==eckTrue)
22349 SgNode* firstnode= edge.target().getNode();
22350 liveIns0 = liv->getIn(firstnode);
22352 for (std::vector<SgInitializedName*>::iterator iter = liveIns0.begin();
22353 iter!=liveIns0.end(); iter++)
22356 liveIns.insert(*iter);
22361 else if (edge.condition()==eckFalse)
22363 SgNode* firstnode= edge.target().getNode();
22364 liveOuts0 = liv->getIn(firstnode);
22366 for (std::vector<SgInitializedName*>::iterator iter = liveOuts0.begin();
22367 iter!=liveOuts0.end(); iter++)
22371 liveOuts.insert(*iter);
22376 cerr<<
"Unexpected CFG out edge type for SgForStmt!"<<endl;
22385static bool isAssignReduction (
SgVarRefExp* ref_exp1,
SgVarRefExp* ref_exp2, OmpSupport::omp_construct_enum& optype)
22387 bool isReduction =
false;
22389 ROSE_ASSERT (ref_exp1!= NULL);
22390 ROSE_ASSERT (ref_exp2!= NULL);
22391 ROSE_ASSERT (ref_exp1-> get_symbol() == ref_exp2-> get_symbol());
22397 if (stmt != stmt2)
return false;
22404 if (exp_stmt && isSgAssignOp(exp_stmt->get_expression()))
22407 assign_lhs = isSgAssignOp(exp_stmt->get_expression())->
get_lhs_operand();
22408 assign_rhs = isSgAssignOp(exp_stmt->get_expression())->
get_rhs_operand();
22409 ROSE_ASSERT(assign_lhs && assign_rhs);
22417 SgBinaryOp * binop = isSgBinaryOp(assign_rhs);
22423 if( !((op_lhs==ref_exp1)||(op_lhs==ref_exp2))
22424 && !((op_rhs==ref_exp1)||(op_rhs==ref_exp2)))
22427 bool isOnLeft =
false;
22428 if ((op_lhs==ref_exp1)||
22429 (op_lhs==ref_exp2))
22435 optype = OmpSupport::e_reduction_plus;
22436 isReduction =
true;
22439 case V_SgMultiplyOp:
22441 optype = OmpSupport::e_reduction_mul;
22442 isReduction =
true;
22445 case V_SgSubtractOp:
22447 optype = OmpSupport::e_reduction_minus;
22450 isReduction =
true;
22456 optype = OmpSupport::e_reduction_bitand ;
22457 isReduction =
true;
22462 optype = OmpSupport::e_reduction_bitxor;
22463 isReduction =
true;
22468 optype = OmpSupport::e_reduction_bitor;
22469 isReduction =
true;
22474 optype = OmpSupport::e_reduction_logand;
22475 isReduction =
true;
22480 optype = OmpSupport::e_reduction_logor;
22481 isReduction =
true;
22490 return isReduction;
22499 bool matchStmt1 =
false;
22500 bool matchStmt2 =
false;
22507 ROSE_ASSERT (ref1 != NULL);
22508 ROSE_ASSERT (ref2 != NULL);
22509 ROSE_ASSERT (ref1-> get_symbol() == ref2-> get_symbol());
22517 if (stmt1 == stmt2)
return false;
22540 bool matchBody =
false;
22541 bool matchCondition=
false;
22542 if (
SgIfStmt * if_stmt = isSgIfStmt (if_cond_stmt->get_parent()) )
22544 if (
SgStatement* body = if_stmt->get_true_body())
22549 ROSE_ASSERT(stmt2 != NULL);
22550 if ( ((block->get_statements()).size() == 1) && stmt2->
get_scope() == block )
22561 if (
SgExprStatement* cond_exp_stmt = isSgExprStatement (if_stmt->get_conditional()) )
22563 SgExpression* cond_exp = cond_exp_stmt->get_expression();
22564 if (
SgBinaryOp * binop = isSgBinaryOp (cond_exp))
22569 if (isSgLessThanOp (binop))
22571 optype = OmpSupport::e_reduction_max;
22572 matchCondition=
true;
22574 else if (isSgGreaterThanOp(binop))
22576 optype = OmpSupport::e_reduction_min;
22577 matchCondition=
true;
22583 if (isSgLessThanOp (binop))
22585 optype = OmpSupport::e_reduction_min;
22586 matchCondition=
true;
22588 else if (isSgGreaterThanOp(binop))
22590 optype = OmpSupport::e_reduction_max;
22591 matchCondition=
true;
22598 matchStmt1 = matchBody && matchCondition;
22602 return (matchStmt2 && matchStmt1);
22609static bool isSingleAppearanceReduction(
SgVarRefExp* ref1, OmpSupport::omp_construct_enum& optype )
22611 bool isReduction =
false;
22613 ROSE_ASSERT (ref1 != NULL);
22619 if (isSgExprStatement(stmt))
22621 SgExpression* exp = isSgExprStatement(stmt)->get_expression();
22623 if (isSgPlusPlusOp(exp))
22626 optype = OmpSupport::e_reduction_plus;
22627 isReduction =
true;
22629 else if (isSgMinusMinusOp(exp))
22631 optype = OmpSupport::e_reduction_minus;
22632 isReduction =
true;
22643 case V_SgPlusAssignOp:
22645 optype = OmpSupport::e_reduction_plus;
22646 isReduction =
true;
22649 case V_SgMultAssignOp:
22651 optype = OmpSupport::e_reduction_mul;
22652 isReduction =
true;
22655 case V_SgMinusAssignOp:
22657 optype = OmpSupport::e_reduction_minus;
22658 isReduction =
true;
22661 case V_SgAndAssignOp:
22663 optype = OmpSupport::e_reduction_bitand;
22664 isReduction =
true;
22667 case V_SgXorAssignOp:
22669 optype = OmpSupport::e_reduction_bitxor;
22670 isReduction =
true;
22673 case V_SgIorAssignOp:
22675 optype = OmpSupport::e_reduction_bitor;
22676 isReduction =
true;
22685 return isReduction;
22717 std::set<SgInitializedName*> candidateVars;
22719 std::map <SgInitializedName*, vector<SgVarRefExp* > > var_references;
22721 Rose_STL_Container<SgNode*> reflist = NodeQuery::querySubTree(loop, V_SgVarRefExp);
22723 ROSE_ASSERT(lbody != NULL);
22724 Rose_STL_Container<SgNode*>::iterator iter = reflist.begin();
22725 for (; iter!=reflist.end(); iter++)
22734 ROSE_ASSERT(var_scope != NULL);
22735 if ((
isScalarType(initname->get_type())) &&(initname !=loopindex)
22738 candidateVars.insert(initname);
22739 var_references[initname].push_back(ref_exp);
22744 std::set<SgInitializedName*>::iterator niter=candidateVars.begin();
22745 for (; niter!=candidateVars.end(); niter++)
22748 bool isReduction =
false;
22749 OmpSupport::omp_construct_enum optype;
22751 if (var_references[initname].size()==1)
22753 mlog[Sawyer::Message::Common::DEBUG] <<
"Debug: SageInterface::ReductionRecognition() A candidate used once:"<<initname->get_name().getString()<<endl;
22754 SgVarRefExp* ref_exp = *(var_references[initname].begin());
22755 if (isSingleAppearanceReduction (ref_exp, optype))
22756 isReduction =
true;
22759 else if (var_references[initname].size()==2)
22761 mlog[Sawyer::Message::Common::DEBUG] <<
"Debug: A candidate used twice:"<<initname->get_name().getString()<<endl;
22762 SgVarRefExp* ref_exp1 = *(var_references[initname].begin());
22763 SgVarRefExp* ref_exp2 = *(++var_references[initname].begin());
22766 if (isAssignReduction (ref_exp1, ref_exp2, optype) || isIfReduction (ref_exp1, ref_exp2, optype) )
22768 isReduction =
true;
22774 results.insert(make_pair(initname,optype));
22781 ROSE_ASSERT(r!=NULL);
22782#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22783 ConstantFolding::constantFoldingOptimization(r,
false);
22793 virtual void visit (
SgNode * n)
22800 ROSE_ASSERT (name_attribute != NULL);
22808 exampleTraversal.
traverse(project, preorder);
22840 const SgInitializedNamePtrList& orig_decls = params.
get_args();
22842 std::transform( orig_decls.begin(), orig_decls.end(), sg::sage_inserter(copy), sg::InitNameCloner(copy, fundef) );
22856 sg::swap_child(ll, rr, &SgFunctionDeclaration::get_definition, &SgFunctionDeclaration::set_definition);
22857 sg::swap_child(ll, rr, &SgFunctionDeclaration::get_parameterList, &SgFunctionDeclaration::set_parameterList);
22867 std::pair<SgStatement*, SgInitializedName*>
22881 SgType* result_type = definingDeclaration.get_type()->get_return_type();
22886 SgFunctionDeclaration* wrapperfn = SB::buildDefiningFunctionDeclaration(newName, result_type, ¶m_list, containing_scope);
22889 ROSE_ASSERT(wrapperdef);
22892 wrapperfn->set_exceptionSpecification(definingDeclaration.get_exceptionSpecification());
22896 swapDefiningElements(definingDeclaration, *wrapperfn);
22901 SgInitializedNamePtrList& param_decls = param_list.
get_args();
22903 std::transform( param_decls.begin(), param_decls.end(), sg::sage_inserter(*args), sg::VarRefBuilder(*wrapperdef) );
22905 SgFunctionCallExp* callWrapped = SB::buildFunctionCallExp( newName, result_type, args, body );
22910 if (!isSgTypeVoid(result_type))
22913 SgVariableDeclaration* res = SB::buildVariableDeclaration(
"res", result_type, SB::buildAssignInitializer(callWrapped), body );
22920 callStatement = res;
22927 callStatement = SB::buildExprStatement(callWrapped);
22931 ROSE_ASSERT(callStatement);
22935 SgFunctionDeclaration* wrapperfn_proto = SB::buildNondefiningFunctionDeclaration(wrapperfn, containing_scope, decorator_proto);
22941 return std::make_pair(callStatement, resultName);
22949 struct VarrefBuilder
22968 template <
class AstNode>
22969 struct VarrefCreator : VarrefBuilder
22974 VarrefCreator(AstNode& orig)
22978 SgVarRefExp*
get()
const {
return VarrefBuilder::build(origin); }
22981 template <
class AstNode>
22982 VarrefCreator<AstNode>
22983 varrefCreator(AstNode& n)
22985 return VarrefCreator<AstNode>(n);
22995 return SB::buildMultiplyOp(lhs, SI::deepCopy(rhs));
22998 std::pair<std::vector<SgExpression*>,
SgType*>
22999 get_C_array_dimensions_aux(
const SgArrayType& arr_type)
23005 std::vector<SgExpression*> indices;
23006 SgType* undertype = NULL;
23010 if (arrtype->get_index() == NULL)
23012 indices.push_back(SB::buildNullExpression());
23013 undertype = arrtype->get_base_type();
23014 arrtype = isSgArrayType(undertype);
23020 ROSE_ASSERT(indexexpr);
23022 indices.push_back(SI::deepCopy(indexexpr));
23023 undertype = arrtype->get_base_type();
23024 arrtype = isSgArrayType(undertype);
23027 ROSE_ASSERT((!indices.empty()) && undertype);
23028 return std::make_pair(indices, undertype);
23032 std::vector<SgExpression*>
23033 get_C_array_dimensions_aux(
const SgArrayType& arrtype,
const VarrefBuilder& varrefBuilder)
23037 std::pair<std::vector<SgExpression*>,
SgType*> res = get_C_array_dimensions_aux(arrtype);
23038 const std::vector<SgExpression*>::iterator first = res.first.begin();
23041 if (isSgNullExpression(*first))
23049 const std::vector<SgExpression*>::iterator aa = first+1;
23050 const std::vector<SgExpression*>::iterator zz = res.first.end();
23052 SgExpression* sz_undertype = SB::buildSizeOfOp(res.second);
23053 SgExpression* denominator = std::accumulate(aa, zz, sz_undertype, create_mulop);
23054 SgSizeOfOp* sz_var = SB::buildSizeOfOp(varrefBuilder.get());
23055 SgExpression* sz = SB::buildDivideOp(sz_var, denominator);
23057 std::swap(*first, sz);
23065 std::vector<SgExpression*>
23068 return get_C_array_dimensions_aux(arrtype).first;
23071 std::vector<SgExpression*>
23074 return get_C_array_dimensions_aux(arrtype, varrefCreator(varref));
23077 std::vector<SgExpression*>
23080 return get_C_array_dimensions_aux(arrtype, varrefCreator(initname));
23087 set<unsigned int> sourceSequenceSet;
23089 void visit (
SgNode* astNode );
23097 if (fileInfo != NULL)
23099 unsigned int source_sequence_number = fileInfo->get_source_sequence_number();
23101 printf (
"In CollectSourceSequenceNumbers::visit(): source_sequence_number = %" PRIuPTR
" \n",source_sequence_number);
23103 sourceSequenceSet.insert(source_sequence_number);
23113 traversal.
traverse(astNode,preorder);
23115 return traversal.sourceSequenceSet;
23202#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
23204 if (collapsing_factor <= 1)
23217 ROSE_ASSERT (global_scope != NULL);
23226 bool *isPlus =
new bool[collapsing_factor];
23230 std::vector<SgForStatement* > loops= SageInterface::querySubTree<SgForStatement>(target_loop,V_SgForStatement);
23231 ROSE_ASSERT(loops.size()>=collapsing_factor);
23247 ROSE_ASSERT(
getScope(target_loop)->get_parent()!= NULL);
23251 while(scope == NULL)
23253 parent = isSgStatement(parent->
get_parent());
23254 scope = isSgScopeStatement(parent);
23258 if (insert_target != NULL)
23263 ROSE_ASSERT(scope != NULL);
23266 for(
size_t i = 0; i < collapsing_factor; i ++)
23268 temp_target_loop = loops[i];
23273 if (!
isCanonicalForLoop(temp_target_loop, &ivar[i], &lb[i], &ub[i], &step[i], &orig_body[i], &isPlus[i]))
23275 cerr<<
"Error in SageInterface::loopCollapsing(): target loop is not canonical."<<endl;
23283 delete[] orig_body;
23284 delete[] total_iters;
23291 ROSE_ASSERT(ivar[i]&& lb[i] && ub[i] && step[i]);
23295 if(isPlus[i] ==
true)
23309 string iter_var_name=
"_total_iters";
23330 new_var_list->append_expression(isSgVarRefExp(ub_exp));
23333 for(
unsigned int i = 0; i < collapsing_factor; i++)
23336 for(
unsigned int j = collapsing_factor - 1; j > i; j--)
23345 new_var_list->append_expression(isSgVarRefExp(interval[i]));
23355 ROSE_ASSERT(insert_target != NULL);
23360 new_var_list->append_expression(clps_index_ref);
23366 ROSE_ASSERT(body != NULL);
23369 std::vector<SgStatement*> new_stmt_list;
23380 for(
unsigned int i = 0; i < collapsing_factor - 1; i ++)
23382 if(isPlus[i] ==
true)
23388 new_stmt_list.push_back(assign_stmt);
23391 if(i != collapsing_factor - 2){
23392 string remain_var_name=
"_remainder";
23393 remain_var_name =
"__"+ ivar[i]->get_name().getString() + remain_var_name;
23396 new_stmt_list.push_back(loop_index_decl);
23402 if(isPlus[collapsing_factor - 1] ==
true)
23406 new_stmt_list.push_back(assign_stmt);
23418 ROSE_ASSERT(cond_stmt != NULL);
23425 target_loop = new_loop;
23427 ConstantFolding::constantFoldingOptimization(scope->
get_parent(),
false);
23433 delete [] orig_body;
23434 delete [] total_iters;
23435 delete [] interval;
23440 return new_var_list;
23459 RoseAst ast_of_original(tree2);
23468 while (i_copy != ast_of_copy.
end())
23471 printf (
"*i_copy = %p = %s \n",*i_copy,(*i_copy)->class_name().c_str());
23472 printf (
"*i_original = %p = %s \n",*i_original,(*i_original)->class_name().c_str());
23476 if ((*i_copy)->variantT() != (*i_original)->variantT())
23479 printf (
"ERROR: return from SageInterface::isStructurallyEquivalentAST(): (*i_copy)->variantT() != (*i_original)->variantT() \n");
23482 printf (
"Making this an error! \n");
23492 ROSE_ASSERT(i_original != ast_of_original.
end());
23497 ROSE_ASSERT(i_copy == ast_of_copy.
end() && i_original == ast_of_original.
end());
23517 lower_bound = NULL;
23518 upper_bound = NULL;
23522 const std::vector<SgStatement *> & init_stmts = for_init_stmt->
get_init_stmt();
23523 assert(init_stmts.size() == 1);
23525 assert(init_stmt != NULL);
23528 SgAssignOp * assign_init = isSgAssignOp(init);
23529 assert(assign_init != NULL);
23531 assert(iterator_init_ref != NULL);
23532 iterator = iterator_init_ref->get_symbol();
23533 assert(iterator != NULL);
23536 SgExprStatement * test_stmt = isSgExprStatement(for_loop->get_test());
23537 assert(test_stmt != NULL);
23543 while (isSgCastExp(lhs_exp)) lhs_exp = ((
SgCastExp *)lhs_exp)->get_operand_i();
23544 SgVarRefExp * lhs_var_ref = isSgVarRefExp(lhs_exp);
23545 bool lhs_it = (lhs_var_ref != NULL) && (lhs_var_ref->get_symbol() == iterator);
23548 while (isSgCastExp(rhs_exp)) rhs_exp = ((
SgCastExp *)rhs_exp)->get_operand_i();
23549 SgVarRefExp * rhs_var_ref = isSgVarRefExp(rhs_exp);
23551 bool rhs_it = (rhs_var_ref != NULL) && (rhs_var_ref->get_symbol() == iterator);
23559 assert(lhs_it != rhs_it);
23568 case V_SgGreaterOrEqualOp:
23569 inclusive = lhs_it;
23572 case V_SgGreaterThanOp:
23573 inclusive = !lhs_it;
23576 case V_SgLessOrEqualOp:
23577 inclusive = lhs_it;
23578 reversed = !lhs_it;
23580 case V_SgLessThanOp:
23581 inclusive = !lhs_it;
23582 reversed = !lhs_it;
23584 case V_SgEqualityOp:
23585 case V_SgNotEqualOp:
23591 switch (increment->variantT()) {
23592 case V_SgPlusPlusOp:
23596 case V_SgMinusMinusOp:
23600 case V_SgPlusAssignOp:
23605 assert(var_ref_lhs != NULL && var_ref_lhs->get_symbol() == iterator);
23610 case V_SgMinusAssignOp:
23615 assert(var_ref_lhs != NULL && var_ref_lhs->get_symbol() == iterator);
23625 assert(inc_assign_lhs != NULL && inc_assign_lhs->get_symbol() == iterator);
23628 assert(inc_assign_rhs != NULL);
23630 if (inc_assign_rhs_lhs != NULL && inc_assign_rhs_lhs->get_symbol() == iterator)
23633 if (inc_assign_rhs_rhs != NULL && inc_assign_rhs_rhs->get_symbol() == iterator)
23654#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
23661 jstring temp_directory = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(::currentJavaTraversalClass, Rose::Frontend::Java::Ecj::getTempDirectoryMethod);
23663 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_directory, NULL);
23665 string directory_name = utf8;
23666 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_directory, utf8);
23668 list<string> sourcepath = project -> get_Java_sourcepath();
23669 sourcepath.push_back(directory_name);
23670 project -> set_Java_sourcepath(sourcepath);
23672 return directory_name;
23680 string command = string(
"rm -fr ") + directory_name;
23681 int status = system(command.c_str());
23682 ROSE_ASSERT(status == 0);
23693 project -> get_sourceFileNameList().push_back(filename);
23694 Rose_STL_Container<std::string> arg_list = project -> get_originalCommandLineArgumentList();
23695 arg_list.push_back(filename);
23698 int error_code = 0;
23699 SgFile *file = determineFileType(arg_list, error_code, project);
23701 ROSE_ASSERT(sourcefile);
23702 sourcefile -> set_parent(project);
23707 project -> get_fileList_ptr() -> get_listOfFiles().push_back(sourcefile);
23708 ROSE_ASSERT(sourcefile == isSgSourceFile((*project)[filename]));
23710 sourcefile -> build_Java_AST(arg_list, project -> get_originalCommandLineArgumentList());
23713 project -> get_fileList_ptr() -> get_listOfFiles().pop_back();
23714 ROSE_ASSERT(sourcefile != isSgSourceFile((*project)[filename]));
23718 ROSE_ASSERT(file->get_preprocessorDirectivesAndCommentsList() != NULL);
23729 string command =
"package " + package_name +
";";
23734 jstring temp_file = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
23735 Rose::Frontend::Java::Ecj::createTempFileMethod,
23736 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(command.c_str()));
23738 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_file, NULL);
23740 string filename = (string) utf8;
23741 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_file, utf8);
23745 return package_name;
23754 string command =
"import " + import_string +
";";
23759 jstring temp_file = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
23760 Rose::Frontend::Java::Ecj::createTempFileMethod,
23761 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(command.c_str()));
23763 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_file, NULL);
23765 string filename = (string) utf8;
23766 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_file, utf8);
23770 return import_string;
23782 jstring temp_file = (jstring) Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
23783 Rose::Frontend::Java::Ecj::createTempNamedFileMethod,
23784 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(file_name.c_str()),
23785 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(file_content.c_str()));
23787 const char *utf8 = Rose::Frontend::Java::Ecj::currentEnvironment -> GetStringUTFChars(temp_file, NULL);
23789 string filename = (string) utf8;
23790 Rose::Frontend::Java::Ecj::currentEnvironment -> ReleaseStringUTFChars(temp_file, utf8);
23800 ROSE_ASSERT(scope);
23802 for (
int index = 0, length = package_name.size(); index < length; index++) {
23804 for (n = index; n < length; n++) {
23805 if (package_name[n] ==
'.') {
23809 string name = package_name.substr(index, n - index);
23811 SgClassSymbol *package_symbol = scope -> lookup_class_symbol(name);
23812 if (package_symbol == NULL) {
23816 SgJavaPackageDeclaration *package_declaration = isSgJavaPackageDeclaration(package_symbol -> get_declaration() -> get_definingDeclaration());
23817 ROSE_ASSERT(package_declaration);
23818 package_definition = package_declaration -> get_definition();
23819 ROSE_ASSERT(package_definition);
23820 scope = package_definition;
23825 return package_definition;
23833 SgGlobal *global_scope = project -> get_globalScopeAcrossFiles();
23835 if (package_definition == NULL) {
23841 if (create_directory) {
23842 Rose::Frontend::Java::Ecj::currentEnvironment -> CallObjectMethod(Rose::Frontend::Java::Ecj::currentJavaTraversalClass,
23843 Rose::Frontend::Java::Ecj::createTempNamedDirectoryMethod,
23844 Rose::Frontend::Java::Ecj::currentEnvironment -> NewStringUTF(package_name.c_str()));
23850 return package_definition;
23857 ROSE_ASSERT(package_definition);
23858 SgClassSymbol *class_symbol = package_definition -> lookup_class_symbol(class_name);
23861 : isSgClassDeclaration(class_symbol -> get_declaration() -> get_definingDeclaration()));
23862 if ((! class_declaration) || (! class_declaration -> attributeExists(
"complete"))) {
23863 string qualified_name = package_definition -> get_qualified_name().getString() +
"." + class_name;
23865 class_symbol = package_definition -> lookup_class_symbol(class_name);
23868 class_declaration = (class_symbol == NULL
23870 : isSgClassDeclaration(class_symbol -> get_declaration() -> get_definingDeclaration()));
23872 return class_declaration;
23888 SgClassDeclaration *class_declaration = isSgClassDeclaration(class_type -> get_declaration() -> get_definingDeclaration());
23889 ROSE_ASSERT(class_declaration);
23890 SgClassDefinition *scope = isSgClassDefinition(class_declaration -> get_scope());
23891 while (scope && (! isSgJavaPackageDeclaration(scope -> get_parent()))) {
23892 class_declaration = isSgClassDeclaration(scope -> get_parent());
23893 ROSE_ASSERT(class_declaration);
23894 scope = isSgClassDefinition(class_declaration -> get_scope());
23901 string class_name = class_declaration ->
get_name().getString();
23910 ROSE_ASSERT(class_definition);
23912 ROSE_ASSERT(type_list);
23914 ROSE_ASSERT(string_array_type);
23915 type_list -> append_argument(string_array_type);
23921 SgFunctionSymbol *method_symbol = class_definition -> lookup_function_symbol(
"main", member_function_type);
23923 return (method_symbol == NULL ? NULL : isSgMemberFunctionDeclaration(method_symbol -> get_declaration()));
23931 SgClassDeclaration *class_declaration = isSgClassDeclaration(class_type -> get_declaration() -> get_definingDeclaration());
23932 ROSE_ASSERT(class_declaration);
23945 ROSE_ASSERT (old_sym != NULL);
23946 ROSE_ASSERT (new_sym != NULL);
23947 ROSE_ASSERT (old_sym != new_sym);
23948 ROSE_ASSERT (scope != NULL);
23950 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(scope, V_SgVarRefExp);
23951 for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
23954 if (vRef->get_symbol() == old_sym)
23955 vRef->set_symbol(new_sym);
23968 bool result =
true;
23970 bool includingSelf =
false;
23973 if (sourceFile == NULL)
23975 printf (
"In SageInterface::statementCanBeTransformed(): sourceFile not found \n");
23979 ROSE_ASSERT(sourceFile != NULL);
23981 if (sourceFile != NULL && sourceFile->get_unparse_tokens() ==
true && sourceFile->get_unparseHeaderFiles() ==
true)
23985 string source_filename = stmt->getFilenameString();
23987 printf (
"In SageInterface::statementCanBeTransformed(): source_filename = %s \n",source_filename.c_str());
23988 printf (
" --- Rose::includeFileMapForUnparsing.size() = %zu \n",Rose::includeFileMapForUnparsing.size());
23992 if (EDG_ROSE_Translation::edg_include_file_map.find(source_filename) != EDG_ROSE_Translation::edg_include_file_map.end())
23994 SgIncludeFile* include_file = EDG_ROSE_Translation::edg_include_file_map[source_filename];
23995 ROSE_ASSERT(include_file != NULL);
23997 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");
23999 if (include_file->get_can_be_supported_using_token_based_unparsing() ==
false)
24002 printf (
"NOTE: Transformations of this statement cannot be supported using the header file unparsing with token unparsing options! \n");
24012 printf (
"Not found in Rose::includeFileMapForUnparsing: source_filename = %s \n",source_filename.c_str());
24015 printf (
"Exiting as a test! \n");
24021 printf (
"Error: In statementCanBeTransformed(): this might be an issue! \n");
24034 ROSE_ASSERT (decl!= NULL);
24035 ROSE_ASSERT (target_scope != NULL);
24036 ROSE_ASSERT (target_scope != decl->
get_scope());
24043 if (isSgIfStmt (target_scope))
24046 if (target_scope == )
24056 case V_SgBasicBlock:
24068 case V_SgForStatement:
24072 ROSE_ASSERT(stmt != NULL);
24073 SgStatementPtrList& stmt_list = stmt->get_init_stmt();
24077 if (stmt_list.size() !=1)
24079 cerr<<
"Error in moveVariableDeclaration(): only single init statement is handled for SgForStatement now."<<endl;
24080 ROSE_ASSERT (stmt_list.size() ==1);
24083 ROSE_ASSERT (exp_stmt != NULL);
24084 SgAssignOp* assign_op = isSgAssignOp(exp_stmt->get_expression());
24085 ROSE_ASSERT (assign_op != NULL);
24095 if (init_name->get_initptr() != NULL)
24097 init_name->set_initptr(initor);
24100 stmt_list.insert (stmt_list.begin(), decl );
24106 cerr<<
"Error. Unhandled target scope type:"<<target_scope->
class_name()<<endl;
24107 ROSE_ASSERT (
false);
24113 ROSE_ASSERT(sym != NULL);
24115 if (orig_scope != target_scope)
24120 init_name->set_scope(target_scope);
24122 orig_scope->remove_symbol(sym);
24127 ROSE_ASSERT (target_scope->symbol_exists(sym));
24137 subtreeVal.hasValue_ =
true;
24139 if (isSgIntVal(valExp)) {
24140 subtreeVal.value_ = isSgIntVal(valExp)->get_value();
24141 }
else if (isSgLongIntVal(valExp)) {
24142 subtreeVal.value_ = isSgLongIntVal(valExp)->get_value();
24143 }
else if (isSgLongLongIntVal(valExp)) {
24144 subtreeVal.value_ = isSgLongLongIntVal(valExp)->get_value();
24145 }
else if (isSgShortVal(valExp)) {
24146 subtreeVal.value_ = isSgShortVal(valExp)->get_value();
24147 }
else if (isSgUnsignedIntVal(valExp)) {
24148 subtreeVal.value_ = isSgUnsignedIntVal(valExp)->get_value();
24149 }
else if (isSgUnsignedLongVal(valExp)) {
24150 subtreeVal.value_ = isSgUnsignedLongVal(valExp)->get_value();
24151 }
else if (isSgUnsignedLongLongIntVal(valExp)) {
24152 subtreeVal.value_ = isSgUnsignedLongLongIntVal(valExp)->get_value();
24153 }
else if (isSgUnsignedShortVal(valExp)) {
24154 subtreeVal.value_ = isSgUnsignedShortVal(valExp)->get_value();
24160 if (isSgModifierType(vRef->get_type()) == NULL) {
24163 val.hasValue_ =
false;
24166 if (isSgModifierType(vRef->get_type())->
get_typeModifier().get_constVolatileModifier().isConst()) {
24172 if (isSgAssignInitializer(ini)) {
24177 return variableEval.
traverse(rhs);
24181 val.hasValue_ =
false;
24187 if (isSgExpression(node) != NULL) {
24189 if (valueExp != NULL) {
24190 return this->getValueExpressionValue(valueExp);
24194 if (varRefExp != NULL) {
24196 return evaluateVariableReference(varRefExp);
24199 if (isSgAssignInitializer(node)) {
24200 if(synList.at(0).hasValue_){
24201 return synList.at(0);
24205 val.hasValue_ =
false;
24210 evaluatedValue.hasValue_ =
false;
24211 evaluatedValue.value_ = -1;
24213 if(synList.size() != 2){
24214 for(SynthesizedAttributesList::iterator it = synList.begin(); it != synList.end(); ++it){
24215 std::cout <<
"Node: " << node->unparseToString() <<
"\n" << (*it).value_ << std::endl;
24216 std::cout <<
"Parent: " << node->get_parent()->unparseToString() << std::endl;
24217 std::cout <<
"Parent, Parent: " << node->get_parent()->get_parent()->unparseToString() << std::endl;
24221 for (SynthesizedAttributesList::iterator it = synList.begin(); it != synList.end(); ++it) {
24222 if((*it).hasValue_){
24223 if (isSgAddOp(node)) {
24224 assert(synList.size() == 2);
24225 evaluatedValue.value_ = synList[0].value_ + synList[1].value_ ;
24226 evaluatedValue.hasValue_ =
true;
24227 }
else if (isSgSubtractOp(node)) {
24228 assert(synList.size() == 2);
24229 evaluatedValue.value_ = synList[0].value_ - synList[1].value_ ;
24230 evaluatedValue.hasValue_ =
true;
24231 }
else if (isSgMultiplyOp(node)) {
24232 assert(synList.size() == 2);
24233 evaluatedValue.value_ = synList[0].value_ * synList[1].value_ ;
24234 evaluatedValue.hasValue_ =
true;
24235 }
else if (isSgDivideOp(node)) {
24236 assert(synList.size() == 2);
24237 evaluatedValue.value_ = synList[0].value_ / synList[1].value_ ;
24238 evaluatedValue.hasValue_ =
true;
24239 }
else if (isSgModOp(node)) {
24240 assert(synList.size() == 2);
24241 evaluatedValue.value_ = synList[0].value_ % synList[1].value_ ;
24242 evaluatedValue.hasValue_ =
true;
24245 std::cerr <<
"Expression is not evaluatable" << std::endl;
24246 evaluatedValue.hasValue_ =
false;
24247 evaluatedValue.value_ = -1;
24248 return evaluatedValue;
24251 evaluatedValue.hasValue_ =
true;
24252 return evaluatedValue;
24255 evaluatedValue.hasValue_ =
false;
24256 evaluatedValue.value_ = -1;
24257 return evaluatedValue;
24270 class TypeEquivalenceChecker {
24272 TypeEquivalenceChecker(
bool profile,
bool useSemanticEquivalence)
24273 : profile_(profile), useSemanticEquivalence_(useSemanticEquivalence),
24274 namedType_(0), pointerType_(0), arrayType_(0), functionType_(0)
24280 if (isSgTypedefType(t)) {
24282 node = isSgTypedefType(t)->
stripType(SgType::STRIP_TYPEDEF_TYPE);
24284 if(useSemanticEquivalence_){
24285 if(isSgModifierType(t)){
24287 ROSE_ASSERT(modType != NULL);
24294 std::cout <<
"Hit volatile type, stripping of modifier type" << std::endl;
24295 node = modType->get_base_type();
24299 std::cout <<
"Hit restrict type, stripping of modifier type" << std::endl;
24300 node = modType->get_base_type();
24304 ROSE_ASSERT(node != NULL);
24309 bool equal =
false;
24310 if(t1 == NULL || t2 == NULL){
24311 std::string wasNull;
24317 std::cerr <<
"ERROR: " << wasNull <<
" was NULL" << std::endl;
24330 i != subT1.
end() && j != subT2.
end(); ++i, ++j) {
24335 nodeT1 = getBasetypeIfApplicable(nodeT1);
24336 nodeT2 = getBasetypeIfApplicable(nodeT2);
24340 if(isSgModifierType(nodeT1)){
24344 if(modT1.get_constVolatileModifier().isConst() != modT2.get_constVolatileModifier().isConst()){
24347 if(modT1.get_constVolatileModifier().isVolatile() != modT2.get_constVolatileModifier().isVolatile()){
24350 }
else if (isSgNamedType(nodeT1)) {
24354 i.skipChildrenOnForward();
24355 j.skipChildrenOnForward();
24361 if(!c1->get_autonomous_declaration()){
24364 if (!c2->get_autonomous_declaration()){
24373 }
else if (isSgPointerType(nodeT1)) {
24380 return typesAreEqual(t1->get_base_type(), t2->get_base_type());
24382 }
else if(isSgReferenceType(nodeT1)){
24386 return typesAreEqual(t1->get_base_type(), t2->get_base_type());
24387 }
else if (isSgArrayType(nodeT1)) {
24394 bool arrayBaseIsEqual = typesAreEqual(a1->get_base_type(), a2->get_base_type());
24398 bool arrayIndexExpressionIsEquivalent =
false;
24399 if(t1Index.hasValue_ && t2Index.hasValue_){
24400 if(t1Index.value_ == t2Index.value_){
24401 arrayIndexExpressionIsEquivalent =
true;
24404 bool arraysAreEqual = (arrayBaseIsEqual && arrayIndexExpressionIsEquivalent);
24405 return arraysAreEqual;
24406 }
else if (isSgFunctionType(nodeT1)) {
24414 if(typesAreEqual(funcTypeA->get_return_type(), funcTypeB->get_return_type())) {
24424 for(SgTypePtrList::const_iterator ii = funcTypeA->
get_arguments().begin(),
24431 if(!typesAreEqual((*ii), (*jj))) {
24451 std::cerr <<
"This feature for now is available with autotools only!" << std::endl;
24456int getNamedTypeCount() {
24460int getPointerTypeCount() {
24461 return pointerType_;
24464int getArrayTypeCount() {
24468int getFunctionTypeCount() {
24469 return functionType_;
24473 bool profile_, useSemanticEquivalence_;
24474 int namedType_, pointerType_, arrayType_, functionType_;
24477TypeEquivalenceChecker tec(
false,
false);
24478return tec.typesAreEqual(typeA, typeB);
24482std::set<SgStatement*>
24491 StatementTraversal() : count (0) {}
24492 void visit (
SgNode* node)
24497 returnset.insert(statement);
24503 std::set<SgStatement*> returnset;
24507 StatementTraversal traversal;
24508 traversal.traverse(node, preorder);
24510 return traversal.returnset;
24513std::set<SgStatement*>
24520 printf (
"In collectModifiedStatements(): node = %p = %s \n",node,node->
class_name().c_str());
24526 StatementTraversal() : count (0) {}
24527 void visit (
SgNode* node)
24532 returnset.insert(statement);
24538 std::set<SgStatement*> returnset;
24542 StatementTraversal traversal;
24543 traversal.traverse(node, preorder);
24545 return traversal.returnset;
24555 printf (
"In outputFileIds(): node = %p = %s \n",node,node->
class_name().c_str());
24561 LocatedNodeTraversal() {}
24562 void visit (
SgNode* node)
24565 if (locatedNode != NULL)
24568 printf (
"In outputFileIds(): isModified() == %s: locatedNode = %p = %s \n",locatedNode->
get_isModified() ?
"true" :
"false",locatedNode,locatedNode->
class_name().c_str());
24569 printf (
" --- file id = %d physical_file_id = %d \n",node->
get_file_info()->get_file_id(),node->
get_file_info()->get_physical_file_id());
24575 if (initializedName != NULL)
24577 printf (
"In outputFileIds(): isModified() == %s: initializedName = %p = %s \n",initializedName->
get_isModified() ?
"true" :
"false",initializedName,initializedName->
class_name().c_str());
24578 printf (
" --- file id = %d physical_file_id = %d \n",initializedName->
get_file_info()->get_file_id(),initializedName->
get_file_info()->get_physical_file_id());
24585 LocatedNodeTraversal traversal;
24586 traversal.traverse(node, preorder);
24589 printf (
"Exiting as a test! \n");
24595std::set<SgLocatedNode*>
24602 printf (
"In collectModifiedLocatedNodes(): node = %p = %s \n",node,node->
class_name().c_str());
24608 LocatedNodeTraversal() : count (0) {}
24609 void visit (
SgNode* node)
24612 if (locatedNode != NULL && locatedNode->
get_isModified() ==
true)
24615 printf (
"In collectModifiedLocatedNodes(): isModified() == true: locatedNode = %p = %s \n",locatedNode,locatedNode->
class_name().c_str());
24617 returnset.insert(locatedNode);
24623 std::set<SgLocatedNode*> returnset;
24627 LocatedNodeTraversal traversal;
24628 traversal.traverse(node, preorder);
24630 return traversal.returnset;
24641 printf (
"In resetModifiedLocatedNodes(): modifiedNodeSet.size() = %zu \n",modifiedNodeSet.size());
24644 std::set<SgLocatedNode*>::const_iterator i = modifiedNodeSet.begin();
24645 while (i != modifiedNodeSet.end())
24649 printf (
"Marking node = %p = %s as modified \n",node,node->
class_name().c_str());
24664 printf (
"\n\n##################################################### \n");
24665 printf (
"Report on modified statements: label = %s \n",label.c_str());
24668 if (sourceFile != NULL)
24670 printf (
" --- (SgSourceFile) filename = %s \n",sourceFile->
getFileName().c_str());
24674 SgGlobal* globalScope = isSgGlobal(node);
24675 if (globalScope != NULL)
24677 sourceFile = isSgSourceFile(globalScope->
get_parent());
24678 printf (
" --- (SgGlobal) filename = %s \n",sourceFile->
getFileName().c_str());
24682 ROSE_ASSERT(node != NULL);
24686 printf (
"In reportModifiedStatements(): collection.size() = %zu \n",collection.size());
24689 std::set<SgStatement*>::iterator i = collection.begin();
24690 while (i != collection.end())
24693 string filename = (*i)->get_file_info()->get_filename();
24696 if (filename ==
"transformation")
24699 printf (
" --- filename == transformation: sourceFile = %p using physical filename \n",sourceFile);
24702 SgSourceFile* sourceFile = TransformationSupport::getSourceFile(*i);
24703 if (sourceFile != NULL)
24709 printf (
" --- filename = %s modified statement = %p = %s \n",filename.c_str(),(*i),(*i)->class_name().c_str());
24717 printf (
"########################################################## \n");
24718 printf (
"reportModifiedStatements(): Called using label = %s \n",label.c_str());
24720 printf (
"########################################################## \n\n\n");
24723 printf (
"Exiting as a test! \n");
24724 ROSE_ASSERT(
false);
24736 printf (
"\n\n##################################################### \n");
24737 printf (
"Report on modified locatedNodes: label = %s \n",label.c_str());
24740 if (sourceFile != NULL)
24742 printf (
" --- (SgSourceFile) filename = %s \n",sourceFile->
getFileName().c_str());
24746 SgGlobal* globalScope = isSgGlobal(node);
24747 if (globalScope != NULL)
24749 sourceFile = isSgSourceFile(globalScope->
get_parent());
24750 printf (
" --- (SgGlobal) filename = %s \n",sourceFile->
getFileName().c_str());
24754 ROSE_ASSERT(node != NULL);
24758 printf (
"In reportModifiedLocatedNode(): collection.size() = %zu \n",collection.size());
24761 std::set<SgLocatedNode*>::iterator i = collection.begin();
24762 while (i != collection.end())
24765 string filename = (*i)->get_file_info()->get_filename();
24768 if (filename ==
"transformation")
24771 printf (
" --- filename == transformation: sourceFile = %p using physical filename \n",sourceFile);
24774 SgSourceFile* sourceFile = TransformationSupport::getSourceFile(*i);
24775 if (sourceFile != NULL)
24781 printf (
" --- filename = %s modified locatedNode = %p = %s \n",filename.c_str(),(*i),(*i)->class_name().c_str());
24789 printf (
"########################################################## \n");
24790 printf (
"reportModifiedLocatedNodes(): Called using label = %s \n",label.c_str());
24792 printf (
"########################################################## \n\n\n");
24795 printf (
"Exiting as a test! \n");
24796 ROSE_ASSERT(
false);
24810 ROSE_ASSERT(locatedNode != NULL);
24814 curprint (
"/* Inside of printOutComments() */");
24817 if (comments != NULL)
24820 printf (
"Found attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
class_name().c_str());
24821 curprint (
"/* Inside of printOutComments(): comments != NULL */");
24824 AttachedPreprocessingInfoType::iterator i;
24825 for (i = comments->begin(); i != comments->end(); i++)
24827 ROSE_ASSERT ( (*i) != NULL );
24828 printf (
" Attached Comment (relativePosition=%s): %s \n",
24831 PreprocessingInfo::relativePositionName((*i)->getRelativePosition()).c_str(),
24832 (*i)->getString().c_str());
24833 printf (
"Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
24837 (*i)->get_file_info()->display(
"comment/directive location");
24844 printf (
"In SageInterface::printOutComments(): No attached comments (at %p of type: %s): \n",locatedNode,locatedNode->
class_name().c_str());
24854 bool returnValue =
false;
24856 ROSE_ASSERT(currentPreprocessingInfo != NULL);
24858 PreprocessingInfo::DirectiveType directive = currentPreprocessingInfo->getTypeOfDirective();
24860 if (directive == PreprocessingInfo::C_StyleComment ||
24861 directive == PreprocessingInfo::CplusplusStyleComment ||
24862 directive == PreprocessingInfo::FortranStyleComment ||
24863 directive == PreprocessingInfo::CpreprocessorBlankLine ||
24864 directive == PreprocessingInfo::ClinkageSpecificationStart ||
24865 directive == PreprocessingInfo::ClinkageSpecificationEnd)
24867 returnValue =
true;
24870 return returnValue;
24873std::vector<SgC_PreprocessorDirectiveStatement*>
24876 std::vector<SgC_PreprocessorDirectiveStatement*> directiveList;
24881 if (comments !=
nullptr)
24883 AttachedPreprocessingInfoType::iterator i;
24884 for (i = comments->begin (); i != comments->end(); i++)
24893 ROSE_ASSERT(directive != NULL);
24894 directiveList.push_back(directive);
24897 printf (
"directiveList.size() = %zu \n",directiveList.size());
24901 return directiveList;
24910 printf (
"In translateScopeToUseCppDeclarations(): declarationsOnly = %s scope = %p = %s \n",declarationsOnly ?
"true" :
"false",scope,scope->
class_name().c_str());
24912 std::map<SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> > directiveMap;
24914 if (declarationsOnly ==
true)
24918 SgDeclarationStatementPtrList::iterator i = declarationList.begin();
24919 while (i != declarationList.end())
24922 ROSE_ASSERT(declaration != NULL);
24926 printf (
"attachDirectives.size() = %zu \n",attachDirectives.size());
24928 if (attachDirectives.empty() ==
false)
24930 directiveMap.insert(std::pair<
SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> >(declaration,attachDirectives));
24942 SgStatementPtrList::iterator i = statementList.begin();
24943 while (i != statementList.end())
24946 ROSE_ASSERT(statement != NULL);
24950 printf (
"attachDirectives.size() = %zu \n",attachDirectives.size());
24952 if (attachDirectives.empty() ==
false)
24954 directiveMap.insert(std::pair<
SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> >(statement,attachDirectives));
24961 printf (
"directiveMap.size() = %zu \n",directiveMap.size());
24963 printf (
"Processing the directiveMap: \n");
24964 std::map<SgStatement*,std::vector<SgC_PreprocessorDirectiveStatement*> >::iterator i = directiveMap.begin();
24965 while (i != directiveMap.end())
24968 std::vector<SgC_PreprocessorDirectiveStatement*> directives = i->second;
24970 printf (
"statement = %p = %s \n",statement,statement->
class_name().c_str());
24971 printf (
"directives.size() = %zu \n",directives.size());
24973 std::vector<SgC_PreprocessorDirectiveStatement*>::iterator j = directives.begin();
24974 while (j != directives.end())
24983 ROSE_ASSERT(comments != NULL);
24985 AttachedPreprocessingInfoType deleteList;
24990 AttachedPreprocessingInfoType::iterator k;
24991 for (k = comments->begin(); k != comments->end(); k++)
24994 ROSE_ASSERT ( (*k) != NULL );
24995 printf (
" Attached Comment (relativePosition=%s): %s\n",
24996 ((*k)->getRelativePosition() == PreprocessingInfo::before) ?
"before" :
"after",
24997 (*k)->getString().c_str());
24998 printf (
"translateScopeToUseCppDeclarations(): Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*k)->getNumberOfLines(),(*k)->getColumnNumberOfEndOfString());
25005 printf (
"Do NOT delete *k = %p = %s \n",*k,(*k)->getString().c_str());
25009 printf (
"DO delete *k = %p = %s \n",*k,(*k)->getString().c_str());
25011 deleteList.push_back(*k);
25017 printf (
"Iterate over the deleteList: deleteList.size() = %zu comments->size() = %zu \n",deleteList.size(),comments->size());
25018 AttachedPreprocessingInfoType::iterator m = deleteList.begin();
25019 while (m != deleteList.end())
25023 comments->erase(std::remove(comments->begin(), comments->end(), *m), comments->end());
25025 printf (
" --- comments->size() = %zu \n",comments->size());
25037 printf (
"Leaving translateScopeToUseCppDeclarations(): scope = %p = %s \n",scope,scope->
class_name().c_str());
25047 CppTranslationTraversal() {}
25048 void visit (
SgNode* node)
25050 printf (
"In CppTranslationTraversal::visit(): node = %p = %s \n",node,node->
class_name().c_str());
25053 SgGlobal* globalScope = isSgGlobal(scope);
25054 if (globalScope != NULL)
25056 printf (
"In CppTranslationTraversal::visit(): processing scope = %p = %s \n",scope,scope->
class_name().c_str());
25063 printf (
"In SageInterface::translateToUseCppDeclarations(): Currently skipping all but global scope! \n");
25070 CppTranslationTraversal traversal;
25072 printf (
"In translateToUseCppDeclarations(): Calling traversal.traverse() \n");
25076 traversal.traverse(n, postorder);
25078 printf (
"Leaving translateToUseCppDeclarations(): DONE: Calling traversal.traverse() \n");
25085 cout<<
"--------------"<<endl;
25089 cout<<
"file info:\t ";
25090 lnode->get_file_info()->display();
25091 cout<<
"\n unparseToString:\t ";
25092 lnode->unparseToString();
25103static void serialize(SgTemplateArgumentPtrList& plist,
string& prefix,
bool hasRemaining, ostringstream& out,
string& edgeLabel)
25106 out<< (hasRemaining?
"|---":
"|___");
25109 out<<
" "<<edgeLabel<<
" ->";
25111 out<<
"@"<<&plist<<
" "<<
"SgTemplateArgumentPtrList ";
25115 int last_non_null_child_idx =-1;
25116 for (
int i = (
int) (plist.size())-1; i>=0; i--)
25120 last_non_null_child_idx = i;
25125 for (
size_t i=0; i< plist.size(); i++ )
25127 bool n_hasRemaining=
false;
25129 if (i+1 < plist.size())
25130 n_hasRemaining=
true;
25132 if ((
int)i< last_non_null_child_idx) n_hasRemaining =
true;
25134 string suffix= hasRemaining?
"| " :
" ";
25135 string n_prefix = prefix+suffix;
25136 string n_edge_label=
"";
25138 serialize (plist[i], n_prefix, n_hasRemaining, out,n_edge_label);
25151 out<< (hasRemaining?
"|---":
"|___");
25153 out<<
" "<<edgeLabel<<
" ->";
25156 out<<
" NULL "<<endl;
25161 out<<
"@"<<node<<
" "<< node->
class_name()<<
" ";
25167 out<< lnode->get_file_info()->get_filename() <<
" "<<lnode->get_file_info()->get_line()<<
":"<<lnode->get_file_info()->get_col();
25169 AttachedPreprocessingInfoType *comments =
25170 lnode->getAttachedPreprocessingInfo ();
25172 if (comments != NULL)
25175 out<<
" AttachedPreprocessingInfoType@"<<comments;
25177 AttachedPreprocessingInfoType::iterator i;
25179 for (i = comments->begin (); i != comments->end (); i++)
25181 if (i!=comments->begin ())
25184 out<<counter++<<
" ";
25193 out<<*i<<
" classification="<<PreprocessingInfo::directiveTypeName((*i)->getTypeOfDirective ()). c_str ();
25194 out<<
" string="<<(*i)->getString ().c_str ();
25195 out<<
" relative pos=" ;
25197 if ((*i)->getRelativePosition () == PreprocessingInfo::inside)
25199 else if ((*i)->getRelativePosition () == PreprocessingInfo::before)
25213 out<<
" first nondefining decl@"<< v->get_firstNondefiningDeclaration();
25214 out<<
" defining decl@"<< v->get_definingDeclaration();
25218 out<<
" value="<< f->get_value() <<
" declaration="<<f->get_declaration() <<
" name="<< f->get_name().getString();
25225 out<<
" renamed_function "<< f->get_renamed_function();
25228 out<<
" name="<< f->get_name() <<
" renamed decl "<<f->get_renamed() ;
25240 out<<
" enumType="<< f->get_enumType();
25248 out<<
" is_general_access"<< v->get_is_general_access();
25251 out<<
" is_anonymous:"<< v->get_is_anonymous ();
25256 out<<
" is_protected"<< v->get_is_protected();
25262 out<<
" type@"<< v->get_type();
25263 out<<
" initializer@"<< v->get_initializer();
25264 out<<
" scope@"<< v->get_scope();
25270 out<<
" template class decl@"<< f->get_templateDeclaration();
25273 out<<
" assoc. class decl@"<< f->get_associatedClassDeclaration();
25277 out<<
" member function decl@"<< ctor->get_declaration();
25280 if (
SgIntVal* v= isSgIntVal(node))
25281 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25284 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25287 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25290 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25293 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25296 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25299 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25302 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25305 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25308 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25311 out<<
" value="<< v->get_value() <<
" valueString="<< v->get_valueString();
25314 out<<
" init name@"<< var_ref->get_symbol()->get_declaration() <<
" symbol name="<<var_ref->get_symbol()->get_name();
25317 out<<
" member func decl@"<< func_ref->get_symbol_i()->get_declaration();
25320 out<<
" template member func decl@"<< cnode->get_templateDeclaration();
25325 out<<
" func decl@"<< sym->get_declaration() <<
" func sym name="<<sym->
get_name();
25331 out<<
" ada renaming decl@"<< renaming_decl;
25337 out<<
" base_type@"<< v->get_base_type();
25342 out<<
" base_type@"<< v->get_base_type();
25345 out<<
" base_type@"<< v->get_base_type();
25348 out<<
" type@"<< v->get_type();
25351 out<<
" attribute@"<< v->get_attribute();
25354 out<<
" namespaceDeclaration="<< v->get_namespaceDeclaration();
25360 int total_count = children.size();
25361 int current_index=0;
25364 int last_non_null_child_idx =-1;
25365 for (
int i = (
int) (children.size())-1; i>=0; i--)
25369 last_non_null_child_idx = i;
25377 if (isSgTemplateInstantiationDecl (node))
25384 SgTemplateArgumentPtrList& plist = sn->get_templateArguments();
25385 bool n_hasRemaining=
false;
25386 if (last_non_null_child_idx>-1) n_hasRemaining =
true;
25387 string suffix= hasRemaining?
"| " :
" ";
25388 string n_prefix = prefix+suffix;
25389 string n_edge_label=
"";
25390 serialize_list(plist,
"SgTemplateArgumentPtrList", n_prefix, n_hasRemaining, out, n_edge_label);
25394 SgExpressionPtrList& plist = import_stmt->get_import_list();
25395 bool n_hasRemaining=
false;
25396 if (last_non_null_child_idx>-1) n_hasRemaining =
true;
25397 string suffix= hasRemaining?
"| " :
" ";
25398 string n_prefix = prefix+suffix;
25399 string n_edge_label=
"";
25400 serialize_list(plist,
"SgExpressionPtrList", n_prefix, n_hasRemaining, out, n_edge_label);
25406 for (
size_t i =0; i< children.size(); i++)
25408 bool n_hasRemaining=
false;
25410 if (current_index+1<total_count)
25411 n_hasRemaining=
true;
25414 if ((
int)i<last_non_null_child_idx) n_hasRemaining =
true;
25416 string suffix= hasRemaining?
"| " :
" ";
25417 string n_prefix = prefix+suffix;
25419 serialize (children[i], n_prefix, n_hasRemaining, out, successorNames[i]);
25428 serialize(node, prefix,
false, oss, label);
25449 serialize(node, prefix,
false, oss, label);
25451 textfile.open(filename, ios::out);
25452 textfile<<oss.str();
25457 textfile<<
"Types encountered ...."<<endl;
25458 ostringstream oss2;
25459 VariantVector vv(V_SgType);
25460 Rose_STL_Container<SgNode*> tnodes= NodeQuery::queryMemoryPool(vv);
25461 for (Rose_STL_Container<SgNode*>::const_iterator i = tnodes.begin(); i != tnodes.end(); ++i)
25463 serialize (*i, prefix,
false, oss2, label);
25465 textfile<<oss2.str();
25473 saveToPDF(node,
string(
"temp.pdf.json") );
25479 ROSE_ASSERT(node != NULL);
25486 bool rtval =
false;
25487 ROSE_ASSERT (node != NULL);
25491 string fname = finfo->get_filenameString();
25492 string buildtree_str1 = string(
"include-staging/gcc_HEADERS");
25493 string buildtree_str2 = string(
"include-staging/g++_HEADERS");
25494 string installtree_str1 = string(
"include/edg/gcc_HEADERS");
25495 string installtree_str2 = string(
"include/edg/g++_HEADERS");
25496 string system_headers = string(
"/usr/include");
25498 if ((fname.find (buildtree_str1, 0) != string::npos) ||
25499 (fname.find (buildtree_str2, 0) != string::npos) ||
25500 (fname.find (installtree_str1, 0) != string::npos) ||
25501 (fname.find (installtree_str2, 0) != string::npos) ||
25502 (fname.find (system_headers, 0) != string::npos)
25515 bool returnValue =
false;
25518 ROSE_ASSERT(fileInfo != NULL);
25519 string filename = fileInfo->get_filenameString();
25522 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());
25527 if (EDG_ROSE_Translation::edg_include_file_map.find(filename) == EDG_ROSE_Translation::edg_include_file_map.end())
25530 printf (
"This is NOT in the EDG_ROSE_Translation::edg_include_file_map \n");
25536 printf (
"This IS in the EDG_ROSE_Translation::edg_include_file_map \n");
25538 returnValue =
true;
25541 return returnValue;
25548 ROSE_ASSERT(return_type != NULL);
25549 ROSE_ASSERT(typeList != NULL);
25551 ROSE_ASSERT(fTable);
25556 SgFunctionType* funcType = isSgFunctionType(fTable->lookup_function_type(typeName));
25566 ROSE_ASSERT (lhs != NULL);
25567 ROSE_ASSERT (rhs != NULL);
25572 SgType* rt1 = lhs->get_return_type();
25573 SgType* rt2 = rhs->get_return_type();
25580 if (f1_arg_types.size() == f2_arg_types.size())
25584 size_t counter = 0;
25587 for (
size_t i=0; i< f1_arg_types.size(); i++)
25595 if (counter == f1_arg_types.size())
25617 ROSE_ASSERT(lhs != NULL);
25618 ROSE_ASSERT(rhs != NULL);
25620 bool isSame =
false;
25623 static int counter = 0;
25625 const SgType & X = *lhs;
25626 const SgType & Y = *rhs;
25634#define DEBUG_TYPE_EQUIVALENCE 0
25636#if DEBUG_TYPE_EQUIVALENCE
25637 printf (
"In SageInterface::isEquivalentType(): evaluation of type equivalence for lhs and rhs: counter = %d \n",counter);
25642#if DEBUG_TYPE_EQUIVALENCE || 0
25645 printf (
"In SageInterface::isEquivalentType(): evaluation of type equivalence for lhs and rhs: counter = %d \n",counter);
25651#if DEBUG_TYPE_EQUIVALENCE || 0
25657 printf (
"Output of type chain for lhs: \n");
25658 for (
size_t i = 0; i < X_typeChain.size(); i++)
25660 SgType* element_type = X_typeChain[i];
25661 printf (
"X_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
25662 printf (
" --- X_element_type unparseToString: = %s \n",element_type->
unparseToString().c_str());
25664 if (modifierType != NULL)
25668 printf (
" --- type chain modifier: %s \n",s.c_str());
25669 printf (
" --- type chain modifier: unparseToString: %s \n",modifierType->
unparseToString().c_str());
25673 printf (
"Output of type chain for rhs: \n");
25674 for (
size_t i = 0; i < Y_typeChain.size(); i++)
25676 SgType* element_type = Y_typeChain[i];
25677 printf (
"Y_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
25678 printf (
" --- Y_element_type unparseToString: = %s \n",element_type->
unparseToString().c_str());
25680 if (modifierType != NULL)
25684 printf (
" --- type chain modifier: %s \n",s.c_str());
25685 printf (
" --- type chain modifier: unparseToString: %s \n",modifierType->
unparseToString().c_str());
25696 if (counter >= 280)
25699 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);
25711 printf (
"ERROR: In SageInterface::isEquivalentType(): recursive limit exceeded for : counter = %d \n",counter);
25722 SgReferenceType* X_referenceType = isSgReferenceType(X_element_type);
25723 SgReferenceType* Y_referenceType = isSgReferenceType(Y_element_type);
25725 if (X_referenceType != NULL && Y_referenceType != NULL)
25727 X_element_type = X_referenceType->get_base_type();
25728 Y_element_type = Y_referenceType->get_base_type();
25739 SgPointerType* X_pointerType = isSgPointerType(X_element_type);
25740 SgPointerType* Y_pointerType = isSgPointerType(Y_element_type);
25742 if (X_pointerType != NULL && Y_pointerType != NULL)
25744 X_element_type = X_pointerType->get_base_type();
25745 Y_element_type = Y_pointerType->get_base_type();
25756 SgArrayType* X_arrayType = isSgArrayType(X_element_type);
25757 SgArrayType* Y_arrayType = isSgArrayType(Y_element_type);
25760 if (X_arrayType != NULL && Y_arrayType != NULL)
25762 X_element_type = X_arrayType->get_base_type();
25763 Y_element_type = Y_arrayType->get_base_type();
25765 SgExpression* X_array_index_expression = X_arrayType->get_index();
25766 SgExpression* Y_array_index_expression = Y_arrayType->get_index();
25768 if (X_array_index_expression == Y_array_index_expression)
25770#if DEBUG_TYPE_EQUIVALENCE || 0
25771 printf (
"In SageInterface::isEquivalentType(): counter = %d: Need to check the array size for static equivalence \n",counter);
25782#if DEBUG_TYPE_EQUIVALENCE || 0
25783 printf (
"In SageInterface::isEquivalentType(): counter = %d Need more complex test for expression equivalence \n",counter);
25786 printf (
" --- array index expressions: str1 = %s str2 = %s \n",str1.c_str(),str2.c_str());
25798 SgNonrealType* X_templateType = isSgNonrealType(X_element_type);
25799 SgNonrealType* Y_templateType = isSgNonrealType(Y_element_type);
25802 if (X_templateType != NULL && Y_templateType != NULL)
25804 string X_name = X_templateType->
get_name();
25805 string Y_name = Y_templateType->
get_name();
25807 SgNonrealDecl* X_templateDecl = isSgNonrealDecl(X_templateType->get_declaration());
25808 ROSE_ASSERT(X_templateDecl != NULL);
25809 SgNonrealDecl* Y_templateDecl = isSgNonrealDecl(Y_templateType->get_declaration());
25810 ROSE_ASSERT(Y_templateDecl != NULL);
25812 int X_template_parameter_position = X_templateDecl->get_template_parameter_position();
25813 int Y_template_parameter_position = Y_templateDecl->get_template_parameter_position();
25818#if DEBUG_TYPE_EQUIVALENCE
25821 printf (
"In SageInterface::isEquivalentType(): case SgNonrealType:\n");
25822 printf (
" -- X_name = %s Y_name = %s\n", X_name.c_str(),Y_name.c_str());
25823 printf (
" -- X_template_parameter_position = %d Y_template_parameter_position = %d\n", X_template_parameter_position,Y_template_parameter_position);
25824 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() :
"");
25825 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() :
"");
25826 printf (
" -- X_templateDecl->get_mangled_name() = %s\n", X_templateDecl->get_mangled_name().str());
25827 printf (
" -- Y_templateDecl->get_mangled_name() = %s\n", Y_templateDecl->get_mangled_name().str());
25829 bool value = (X_parent == Y_parent);
25831 if (value && X_templateDecl->get_is_template_param() && Y_templateDecl->get_is_template_param()) {
25832 value = (X_template_parameter_position == Y_template_parameter_position);
25833 }
else if (value && X_templateDecl->get_is_class_member() && Y_templateDecl->get_is_class_member()) {
25834 value = (X_name == Y_name);
25846 printf (
"Nothing to do here since we have explored all uniform pairs of intermediate types possible: isSame = %s \n",isSame ?
"true" :
"false");
25852#if DEBUG_TYPE_EQUIVALENCE
25853 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");
25860 SgModifierType* X_modifierType = isSgModifierType(X_element_type);
25861 SgModifierType* Y_modifierType = isSgModifierType(Y_element_type);
25863#if DEBUG_TYPE_EQUIVALENCE
25864 printf (
"In SageInterface::isEquivalentType(): counter = %d: type chain X_element_type = %p = %s Y_element_type = %p = %s \n",
25865 counter,X_element_type,X_element_type->
class_name().c_str(),Y_element_type,Y_element_type->
class_name().c_str());
25868 if (X_modifierType != NULL && Y_modifierType != NULL)
25871#if DEBUG_TYPE_EQUIVALENCE
25872 printf (
"In SageInterface::isEquivalentType(): loop: these are the both SgModifierType nodes: isSame = %s \n",isSame ?
"true" :
"false");
25874 if (X_modifierType == Y_modifierType)
25877#if DEBUG_TYPE_EQUIVALENCE
25878 printf (
"In SageInterface::isEquivalentType(): loop: these are the same modifier type: isSame = %s \n",isSame ?
"true" :
"false");
25885#if DEBUG_TYPE_EQUIVALENCE
25886 printf (
"In SageInterface::isEquivalentType(): loop: these are equivalent modifiers: check the base type: isSame = %s \n",isSame ?
"true" :
"false");
25890 isSame =
isEquivalentType(X_modifierType->get_base_type(),Y_modifierType->get_base_type());
25894#if DEBUG_TYPE_EQUIVALENCE
25895 printf (
"In SageInterface::isEquivalentType(): loop: these are not equivalent modifier types: check for default settings: isSame = %s \n",isSame ?
"true" :
"false");
25898 bool skippingOverIdentityModifier =
false;
25902#if DEBUG_TYPE_EQUIVALENCE
25903 printf (
"In SageInterface::isEquivalentType(): loop: found self-similar setting for lhs: isSame = %s \n",isSame ?
"true" :
"false");
25905 X_element_type = X_modifierType->get_base_type();
25908 skippingOverIdentityModifier =
true;
25913#if DEBUG_TYPE_EQUIVALENCE
25914 printf (
"In SageInterface::isEquivalentType(): loop: found self-similar setting for rhs: isSame = %s \n",isSame ?
"true" :
"false");
25916 Y_element_type = Y_modifierType->get_base_type();
25919 skippingOverIdentityModifier =
true;
25923#if DEBUG_TYPE_EQUIVALENCE
25924 printf (
"In SageInterface::isEquivalentType(): loop: skippingOverIdentityModifier = %s \n",skippingOverIdentityModifier ?
"true" :
"false");
25929 if (skippingOverIdentityModifier ==
true)
25931#if DEBUG_TYPE_EQUIVALENCE
25932 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");
25941#if DEBUG_TYPE_EQUIVALENCE
25942 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");
25946#if DEBUG_TYPE_EQUIVALENCE
25947 printf (
"In SageInterface::isEquivalentType(): loop: these are different modifier types: after recursive call to compare base types: isSame = %s \n",isSame ?
"true" :
"false");
25956 if (X_modifierType != NULL || Y_modifierType != NULL)
25958 bool isReduceable =
false;
25960 if (X_modifierType != NULL && X_modifierType->
get_typeModifier().isIdentity() ==
true)
25962#if DEBUG_TYPE_EQUIVALENCE
25963 printf (
"In SageInterface::isEquivalentType(): loop: found default setting for lhs: isSame = %s \n",isSame ?
"true" :
"false");
25965 X_element_type = X_modifierType->get_base_type();
25966 isReduceable =
true;
25969 if (Y_modifierType != NULL && Y_modifierType->
get_typeModifier().isIdentity() ==
true)
25971#if DEBUG_TYPE_EQUIVALENCE
25972 printf (
"In SageInterface::isEquivalentType(): loop: found default setting for rhs: isSame = %s \n",isSame ?
"true" :
"false");
25974 Y_element_type = Y_modifierType->get_base_type();
25975 isReduceable =
true;
25979#if DEBUG_TYPE_EQUIVALENCE
25980 printf (
"In SageInterface::isEquivalentType(): loop: these are different modifier types: after recursive call to compare base types: isReduceable = %s \n",isReduceable ?
"true" :
"false");
25982 if (isReduceable ==
true)
25994#if DEBUG_TYPE_EQUIVALENCE
25995 printf (
"In SageInterface::isEquivalentType(): loop: these are different modifier types: after recursive call to compare base types: isReduceable = %s isSame = %s \n",
25996 isReduceable ?
"true" :
"false",isSame ?
"true" :
"false");
26005 if (X_element_type == Y_element_type)
26008#if DEBUG_TYPE_EQUIVALENCE || 0
26010 printf (
"In SageInterface::isEquivalentType(): resolved to equal types: isSame = %s lhs = %p = %s rhs = %p = %s \n",
26013#if DEBUG_TYPE_EQUIVALENCE || 0
26016 const SgTypedefType* lhs_typedefType = isSgTypedefType(lhs);
26017 const SgTypedefType* rhs_typedefType = isSgTypedefType(rhs);
26019 if (lhs_typedefType != NULL || rhs_typedefType != NULL)
26022 if (lhs_typedefType != NULL)
26024 printf (
"lhs was a typedef: lhs = %p = %s \n",lhs,lhs->
unparseToString().c_str());
26026 if (rhs_typedefType != NULL)
26028 printf (
"rhs was a typedef: rhs = %p = %s \n",rhs,rhs->
unparseToString().c_str());
26031 printf (
" --- one was a typedef: lhs = %p = %s \n",lhs,lhs->
unparseToString().c_str());
26032 printf (
" --- one was a typedef: rhs = %p = %s \n",rhs,rhs->
unparseToString().c_str());
26043 SgReferenceType* X_referenceType = isSgReferenceType(X_element_type);
26044 SgReferenceType* Y_referenceType = isSgReferenceType(Y_element_type);
26046 if (X_referenceType != NULL || Y_referenceType != NULL)
26049 if (X_referenceType != NULL)
26051 X_element_type = X_referenceType->get_base_type();
26055 isReduceable =
false;
26058 if (Y_referenceType != NULL)
26060 Y_element_type = Y_referenceType->get_base_type();
26064 isReduceable =
false;
26067 if (isReduceable ==
true)
26088#if DEBUG_TYPE_EQUIVALENCE
26089 printf (
"In SageInterface::isEquivalentType(): loop: evaluation of inner types: isSame = %s \n",isSame ?
"true" :
"false");
26093 SgPointerType* X_pointerType = isSgPointerType(X_element_type);
26094 SgPointerType* Y_pointerType = isSgPointerType(Y_element_type);
26096 if (X_pointerType != NULL || Y_pointerType != NULL)
26099 if (X_pointerType != NULL)
26101 X_element_type = X_pointerType->get_base_type();
26105 isReduceable =
false;
26108 if (Y_pointerType != NULL)
26110 Y_element_type = Y_pointerType->get_base_type();
26114 isReduceable =
false;
26117 if (isReduceable ==
true)
26138#if DEBUG_TYPE_EQUIVALENCE
26139 printf (
"In SageInterface::isEquivalentType(): loop: evaluation of inner types: isSame = %s \n",isSame ?
"true" :
"false");
26143 SgArrayType* X_arrayType = isSgArrayType(X_element_type);
26144 SgArrayType* Y_arrayType = isSgArrayType(Y_element_type);
26146 if (X_arrayType != NULL || Y_arrayType != NULL)
26149 if (X_arrayType != NULL)
26151 X_element_type = X_arrayType->get_base_type();
26155 isReduceable =
false;
26158 if (Y_arrayType != NULL)
26160 Y_element_type = Y_arrayType->get_base_type();
26164 isReduceable =
false;
26167 if (isReduceable ==
true)
26188#if DEBUG_TYPE_EQUIVALENCE
26189 printf (
"In SageInterface::isEquivalentType(): loop: evaluation of inner types: isSame = %s \n",isSame ?
"true" :
"false");
26193 SgFunctionType* X_functionType = isSgFunctionType(X_element_type);
26194 SgFunctionType* Y_functionType = isSgFunctionType(Y_element_type);
26196 if (X_functionType != NULL || Y_functionType != NULL)
26198 bool value = ( (X_functionType != NULL && Y_functionType != NULL) && (X_functionType == Y_functionType) );
26201#if DEBUG_TYPE_EQUIVALENCE || 0
26202 printf (
"In SageInterface::isEquivalentType(): loop: Process case of SgFunctionType: value = %s \n",value ?
"true" :
"false");
26220 if (X_memberFunctionType != NULL || Y_memberFunctionType != NULL)
26223 printf (
"This should be unreachable code \n");
26227 bool value = ( (X_memberFunctionType != NULL && Y_memberFunctionType != NULL) && (X_memberFunctionType == Y_memberFunctionType) );
26228#if DEBUG_TYPE_EQUIVALENCE || 0
26229 printf (
"In SageInterface::isEquivalentType(): loop: Process case of SgMemberFunctionType: value = %s \n",value ?
"true" :
"false");
26242 bool X_isReduceable =
true;
26243 if (isSgTypeSignedLong(X_element_type) != NULL ||
26244 isSgTypeUnsignedInt(X_element_type) != NULL ||
26245 isSgTypeBool(X_element_type) != NULL ||
26246 isSgTypeInt(X_element_type) != NULL)
26248 X_isReduceable =
false;
26251 bool Y_isReduceable =
true;
26252 if (isSgTypeSignedLong(Y_element_type) != NULL ||
26253 isSgTypeUnsignedInt(Y_element_type) != NULL ||
26254 isSgTypeBool(Y_element_type) != NULL ||
26255 isSgTypeInt(Y_element_type) != NULL)
26257 Y_isReduceable =
false;
26259#if DEBUG_TYPE_EQUIVALENCE || 0
26260 printf (
"In SageInterface::isEquivalentType(): loop: Process default case: X_isReduceable = %s Y_isReduceable = %s \n",
26261 X_isReduceable ?
"true" :
"false",Y_isReduceable ?
"true" :
"false");
26263 if (X_isReduceable ==
true || Y_isReduceable ==
true)
26277#if DEBUG_TYPE_EQUIVALENCE || 0
26278 printf (
"In SageInterface::isEquivalentType(): loop: Process default case: X_element_type = %p = %s Y_element_type = %p = %s \n",
26279 X_element_type,X_element_type->
class_name().c_str(),Y_element_type,Y_element_type->
class_name().c_str());
26284 isSame = (X_element_type == Y_element_type);
26304#if DEBUG_TYPE_EQUIVALENCE || 0
26305 printf (
"In SageInterface::isEquivalentType(): isSame = %s \n",isSame ?
"true" :
"false");
26308#if DEBUG_TYPE_EQUIVALENCE || 0
26309 if (counter == 1 && isSame ==
true)
26311 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());
26318 printf (
" --- Output of type chain for lhs: \n");
26319 for (
size_t i = 0; i < X_typeChain.size(); i++)
26321 SgType* element_type = X_typeChain[i];
26322 printf (
" --- --- X_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
26324 if (modifierType != NULL)
26328 printf (
" --- type chain modifier: %s \n",s.c_str());
26332 printf (
" --- Output of type chain for rhs: \n");
26333 for (
size_t i = 0; i < Y_typeChain.size(); i++)
26335 SgType* element_type = Y_typeChain[i];
26336 printf (
" --- --- Y_element_type = %p = %s \n",element_type,element_type->
class_name().c_str());
26338 if (modifierType != NULL)
26342 printf (
" --- --- type chain modifier: %s \n",s.c_str());
26351 if (isSame ==
true)
26354 printf (
" --- isSame = %s \n",isSame ?
"true" :
"false");
26357 printf (
" --- --- X_element_type = %p = %s = %s \n",X_element_type,X_element_type->
class_name().c_str(),X_element_type->
unparseToString().c_str());
26358 printf (
" --- --- Y_element_type = %p = %s = %s \n",Y_element_type,Y_element_type->
class_name().c_str(),Y_element_type->
unparseToString().c_str());
26363 printf (
" --- isSame = %s \n",isSame ?
"true" :
"false");
26368 printf (
" --- counter = %d \n",counter);
26385 bool retval =
false;
26394 retval = function->get_marked_as_edg_normalization();
26402 if (templateInstantiationFunction != NULL)
26407 if (templateFunctionDeclaration != NULL)
26418 printf (
" --- case of templateInstantiationFunction: retval = %s \n",retval ?
"true" :
"false");
26423 if (templateInstantiationMemberFunction != NULL)
26426 templateInstantiationMemberFunction = isSgTemplateInstantiationMemberFunctionDecl(templateInstantiationMemberFunction->
get_firstNondefiningDeclaration());
26428 if (templateMemberFunctionDeclaration != NULL)
26439 printf (
" --- case of templateInstantiationMemberFunction: retval = %s \n",retval ?
"true" :
"false");
26451 printf(
"In detectCycleInType():\n");
26452 printf(
" -- from = %s\n", from.c_str());
26453 printf(
" -- type = %p (%s)\n", type, type->
class_name().c_str());
26455 std::vector<SgType *> seen_types;
26457 while (type != NULL) {
26460 ROSE_ASSERT(type != NULL);
26462 std::vector<SgType *>::const_iterator it = std::find(seen_types.begin(), seen_types.end(), type);
26463 if (it != seen_types.end()) {
26464 printf(
"ERROR: Cycle found in type = %p (%s):\n", type, type->
class_name().c_str());
26466 for (; it != seen_types.end(); it++) {
26467 printf(
" [%zd] %p (%s)\n", i, *it, (*it)->class_name().c_str());
26470 printf(
"-> detectCycleInType() was called from: %s\n", from.c_str());
26473 seen_types.push_back(type);
26483 if (isSgPointerMemberType(type) != NULL)
26490 type = modType->get_base_type();
26491 }
else if ( refType ) {
26492 type = refType->get_base_type();
26493 }
else if ( pointType ) {
26494 type = pointType->get_base_type();
26497 }
else if ( arrayType ) {
26498 type = arrayType->get_base_type();
26499 }
else if ( typedefType ) {
26504 ROSE_ASSERT(type != NULL);
26525 std::vector<SgFunctionDeclaration*> functionList;
26528 string filenameWithPath;
26531 TransformFunctionDefinitionsTraversal(): sourceFile(NULL), sourceFileId(-99) {}
26533 void visit (
SgNode* node)
26536 printf (
"In convertFunctionDefinitionsToFunctionPrototypes visit(): node = %p = %s \n",node,node->
class_name().c_str());
26539 if (temp_sourceFile != NULL)
26541 sourceFile = temp_sourceFile;
26545 filenameWithPath = sourceFile->get_sourceFileNameWithPath();
26547 printf (
"Found source file: id = %d name = %s \n",sourceFileId,sourceFile->get_sourceFileNameWithPath().c_str());
26552 if (functionDeclaration != NULL)
26555 ROSE_ASSERT(sourceFile != NULL);
26558 if (functionDeclaration == definingFunctionDeclaration)
26561 printf (
"Found a defining function declaration: functionDeclaration = %p = %s name = %s \n",
26562 functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
26564 printf (
" --- recorded source file: id = %d name = %s \n",sourceFileId,sourceFile->get_sourceFileNameWithPath().c_str());
26565 printf (
" --- source file: file_info: id = %d name = %s \n",
26570 bool isInSourceFile = (filenameWithPath == functionDeclaration->
get_file_info()->get_filenameString());
26572 printf (
" --- isInSourceFile = %s \n",isInSourceFile ?
"true" :
"false");
26576 if (isInSourceFile ==
true && functionDeclarationScope != NULL)
26579 printf (
" --- Found a defining function declaration: functionDeclarationScope = %p = %s \n",
26580 functionDeclarationScope,functionDeclarationScope->
class_name().c_str());
26584 functionList.push_back(functionDeclaration);
26592 TransformFunctionDefinitionsTraversal traversal;
26593 traversal.traverse(node, preorder);
26595 std::vector<SgFunctionDeclaration*> & functionList = traversal.functionList;
26598 printf (
"In convertFunctionDefinitionsToFunctionPrototypes(): functionList.size() = %zu \n",functionList.size());
26601 std::vector<SgFunctionDeclaration*>::iterator i = functionList.begin();
26602 while (i != functionList.end())
26605 ROSE_ASSERT(functionDeclaration != NULL);
26608 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
26611 printf (
" --- Removing function declaration: functionDeclaration = %p = %s name = %s \n",
26612 functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
26622 printf (
"In convertFunctionDefinitionsToFunctionPrototypes(): exiting as a test! \n");
26633 ROSE_ASSERT(scope != NULL);
26635 printf (
"Output the statements in scope = %p = %s \n",scope,scope->
class_name().c_str());
26639 for (
size_t i = 0; i < statementList.size(); i++)
26646 printf (
"Exiting as a test at the end of evaluation of global scope! \n");
26659 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration = %p = %s name = %s \n",
26660 functionDeclaration,functionDeclaration->
class_name().c_str(),functionDeclaration->get_name().str());
26664 bool isConstructor =
false;
26666 if (tmp_memberFunctionDeclaration != NULL)
26668 isConstructor = tmp_memberFunctionDeclaration->get_specialFunctionModifier().isConstructor();
26671 if (isConstructor ==
true)
26673 printf (
"Skipping case of constructors (in building prototype from defining function declaration) \n");
26683 SgName name = functionDeclaration->get_name();
26684 SgType* return_type = functionDeclaration->get_type()->get_return_type();
26692 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration = %p \n",functionDeclaration);
26693 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->
get_firstNondefiningDeclaration());
26694 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->
get_definingDeclaration());
26698 for (
size_t i = 0; i < functionDeclaration->get_args().size(); i++)
26702 printf (
"In SageInterface::buildFunctionPrototype(): functionDeclaration->get_args(): (i = %zu) arg = %p = %s isDefaultArgument = %s \n",
26703 i,arg,arg->get_name().str(),arg->
get_file_info()->isDefaultArgument() ?
"true" :
"false");
26704 printf (
" --- arg->get_initializer() = %p \n",arg->get_initializer());
26708 printf (
"NOTE: default argument (i = %zu) not reproduced in function prototype: arg = %p = %s \n",i,arg,arg->get_name().str());
26721 if (templateInstantiationFunctionDecl == NULL)
26728 if (templateInstantiationMemberFunctionDecl == NULL)
26737 bool isTemplateInstantiationMemberFunctionDecl =
false;
26742 bool buildTemplateInstantiation =
false;
26743 SgTemplateArgumentPtrList* templateArgumentsList = NULL;
26748 ROSE_ASSERT(param_list == NULL || param_list->
get_parent() == NULL);
26750 switch (functionDeclaration->
variantT())
26752 case V_SgTemplateMemberFunctionDeclaration:
26755 printf (
"This function to replace the defining declaration with a non-defining declaration does not yet support template member functions \n");
26758 ROSE_ASSERT(original_templateMemberFunctionDeclaration != NULL);
26762 unsigned int functionConstVolatileFlags = 0;
26764 ROSE_ASSERT(original_templateMemberFunctionDeclaration->get_type() != NULL);
26769 SgMemberFunctionType* memberFunctionType = isSgMemberFunctionType(original_templateMemberFunctionDeclaration->get_type());
26770 ROSE_ASSERT(memberFunctionType != NULL);
26772 functionConstVolatileFlags = memberFunctionType->get_mfunc_specifier();
26778 SgTemplateParameterPtrList templateParameterList = original_templateMemberFunctionDeclaration->get_templateParameters();
26781 templateMemberFunctionDeclaration =
26784 printf (
"ERROR: Template functions are not yet supported! \n");
26787 nondefiningFunctionDeclaration = templateMemberFunctionDeclaration;
26789 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
26792 if (isConstructor ==
true)
26794 templateMemberFunctionDeclaration->get_specialFunctionModifier().setConstructor();
26800 case V_SgTemplateFunctionDeclaration:
26803 printf (
"This function to replace the defining declaration with a non-defining declaration does not yet support template functions \n");
26806 ROSE_ASSERT(original_templateFunctionDeclaration != NULL);
26814 SgTemplateParameterPtrList templateParameterList = original_templateFunctionDeclaration->get_templateParameters();
26818 printf (
"ERROR: Template functions are not yet supported! \n");
26821 nondefiningFunctionDeclaration = templateFunctionDeclaration;
26823 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
26829 case V_SgTemplateInstantiationMemberFunctionDecl:
26831 buildTemplateInstantiation =
true;
26833 isTemplateInstantiationMemberFunctionDecl =
true;
26836 ROSE_ASSERT(templateInstantiationMemberFunctionDecl != NULL);
26839 printf (
"name from functionDeclaration->get_name(): name = %s \n",name.str());
26841 printf (
"name from templateInstantiationMemberFunctionDecl->get_templateName(): template_name = %s \n",templateInstantiationMemberFunctionDecl->
get_templateName().str());
26843 if (templateDeclaration != NULL)
26845 printf (
"name from templateInstantiationMemberFunctionDecl->get_template_declaration()->get_name(): template_name = %s \n",templateDeclaration->get_name().str());
26846 printf (
"name from templateInstantiationMemberFunctionDecl->get_template_declaration()->get_template_name(): template_name = %s \n",templateDeclaration->
get_template_name().str());
26853 printf (
"In case V_SgTemplateInstantiationMemberFunctionDecl: using name = %s \n",name.str());
26858 case V_SgMemberFunctionDeclaration:
26861 printf (
"This function to replace the defining declaration with a non-defining declaration does not yet support member functions \n");
26864 ROSE_ASSERT(original_memberFunctionDeclaration != NULL);
26872 unsigned int functionConstVolatileFlags = 0;
26874 ROSE_ASSERT(original_memberFunctionDeclaration->get_type() != NULL);
26883 bool buildPrototype = isTemplateInstantiationMemberFunctionDecl || original_memberFunctionDeclaration->
get_parent() == original_memberFunctionDeclaration->
get_scope();
26885 printf (
"In SageInterface::buildFunctionPrototype(): buildPrototype = %s \n",buildPrototype ?
"true" :
"false");
26887 if (buildPrototype ==
true)
26889 SgMemberFunctionType* memberFunctionType = isSgMemberFunctionType(original_memberFunctionDeclaration->get_type());
26890 ROSE_ASSERT(memberFunctionType != NULL);
26892 printf (
"original_memberFunctionDeclaration->get_parent() == original_memberFunctionDeclaration->get_scope() \n");
26894 functionConstVolatileFlags = memberFunctionType->get_mfunc_specifier();
26896 memberFunctionDeclaration =
26898 ( name, return_type, param_list, scope, python_decoratorList, functionConstVolatileFlags,
26899 buildTemplateInstantiation,templateArgumentsList );
26901 printf (
"ERROR: Member functions are not yet supported! \n");
26905 if (isConstructor ==
true)
26907 memberFunctionDeclaration->get_specialFunctionModifier().setConstructor();
26910 nondefiningFunctionDeclaration = memberFunctionDeclaration;
26912 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
26918 printf (
"NOTE: Member functions defined outside of their class can not be output as member function prototypes (not allowed in C++) \n");
26922 nondefiningFunctionDeclaration = NULL;
26924 nondefiningFunctionDeclaration = NULL;
26926 replaceWithEmptyDeclaration =
true;
26928 ROSE_ASSERT(emptyDeclaration != NULL);
26937 printf (
"Exiting as a test! \n");
26947 case V_SgFunctionDeclaration:
26950 nondefiningFunctionDeclaration =
buildNondefiningFunctionDeclaration (name, return_type, param_list, scope, python_decoratorList, buildTemplateInstantiation,templateArgumentsList);
26951 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
26956 case V_SgTemplateInstantiationFunctionDecl:
26959 buildTemplateInstantiation =
true;
26961 ROSE_ASSERT(templateInstantiationFunctionDecl != NULL);
26964 printf (
"name from functionDeclaration->get_name(): name = %s \n",name.str());
26966 printf (
"name from templateInstantiationFunctionDecl->get_templateName(): template_name = %s \n",templateInstantiationFunctionDecl->
get_templateName().str());
26968 if (templateDeclaration != NULL)
26970 printf (
"name from templateInstantiationFunctionDecl->get_template_declaration()->get_name(): template_name = %s \n",templateDeclaration->get_name().str());
26971 printf (
"name from templateInstantiationFunctionDecl->get_template_declaration()->get_template_name(): template_name = %s \n",templateDeclaration->
get_template_name().str());
26976 printf (
"In case V_SgTemplateInstantiationFunctionDecl: using name = %s \n",name.str());
26978 nondefiningFunctionDeclaration =
buildNondefiningFunctionDeclaration (name, return_type, param_list, scope, python_decoratorList, buildTemplateInstantiation,templateArgumentsList);
26979 ROSE_ASSERT(nondefiningFunctionDeclaration != NULL);
26998 ROSE_ASSERT(param_list == NULL || param_list->
get_parent() != NULL);
27004 if (nondefiningFunctionDeclaration != NULL)
27009 printf (
"Setting the firstNondefiningDeclaration \n");
27017 printf (
"Setting the definingDeclaration \n");
27026 if (nondefiningFunctionDeclaration != NULL)
27036 return nondefiningFunctionDeclaration;
27045 ROSE_ASSERT(functionDeclaration != NULL);
27048 printf (
"****************************************************************** \n");
27049 printf (
"Attached comments and CPP directives: defining functionDeclaration \n");
27051 printf (
"****************************************************************** \n");
27059 if (nondefiningFunctionDeclaration != NULL)
27070 if (templateInstantiationFunctionDecl == NULL)
27072 if (nondefiningFunctionDeclaration != NULL)
27075 nondefiningFunctionDeclaration->get_declarationModifier() = functionDeclaration->get_declarationModifier();
27078 nondefiningFunctionDeclaration->get_functionModifier() = functionDeclaration->get_functionModifier();
27079 nondefiningFunctionDeclaration->get_specialFunctionModifier() = functionDeclaration->get_specialFunctionModifier();
27081 nondefiningFunctionDeclaration->set_linkage( functionDeclaration->get_linkage() );
27082 nondefiningFunctionDeclaration->set_externBrace( functionDeclaration->get_externBrace() );
27084 ROSE_ASSERT(nondefiningFunctionDeclaration->get_forward() ==
true);
27087 int file_id = functionDeclaration->
get_file_info()->get_physical_file_id();
27088 nondefiningFunctionDeclaration->
get_file_info()->set_physical_file_id(file_id);
27104 ROSE_ASSERT(nondefiningFunctionDeclaration->
get_parent() != NULL);
27110 nondefiningFunctionDeclaration = NULL;
27114 if (functionDeclaration->get_declarationModifier().get_storageModifier().
isStatic() ==
true)
27116 ROSE_ASSERT(nondefiningFunctionDeclaration->get_declarationModifier().get_storageModifier().
isStatic() ==
true);
27120 return nondefiningFunctionDeclaration;
27124std::vector<SgFunctionDeclaration*>
27136 std::vector<SgFunctionDeclaration*> functionList;
27137 FunctionDefinitionsTraversal() {}
27139 void visit (
SgNode* node)
27142 if (functionDeclaration != NULL)
27148 if (functionDeclaration == definingFunctionDeclaration)
27152 if (functionDeclarationScope != NULL)
27154 functionList.push_back(functionDeclaration);
27162 FunctionDefinitionsTraversal traversal;
27164 traversal.traverseWithinFile(node, preorder);
27166 std::vector<SgFunctionDeclaration*> & functionList = traversal.functionList;
27168 return functionList;
27175 ROSE_ASSERT(node != NULL);
27178 std::vector<SgFunctionDeclaration*>::iterator i = functionList.begin();
27180 while (i != functionList.end())
27183 ROSE_ASSERT(functionDeclaration != NULL);
27201 ROSE_ASSERT(node !=
nullptr);
27207 void visit (
SgNode* node)
27210 if (variableDeclaration != NULL)
27213 SgExpression* initializer = initializedName->get_initializer();
27215 printf (
"variableDeclaration = %p initializedName = %p = %s initializer = %p \n",
27216 variableDeclaration,initializedName,initializedName->get_name().str(),initializer);
27218 if (initializer != NULL)
27220 printf (
" --- initializer = %s \n",initializer->
class_name().c_str());
27227 CheckInitializerTraversal traversal;
27228 traversal.traverse(node, preorder);
27236 void setResult(
SgType*) { }
27238 void handle(
SgNode& n,
SgNode&) { SG_UNEXPECTED_NODE(n); }
27240 template <
class SageDeclarationStatement>
27246 setResult(n.get_type());
27249 template <
class SageNode>
27250 void handle(SageNode& n)
27263 SgGlobal * gsaf = project->get_globalScopeAcrossFiles();
27264 ROSE_ASSERT(gsaf !=
nullptr);
27266 ROSE_ASSERT(st !=
nullptr);
27268 ROSE_ASSERT(hmm !=
nullptr);
27272 ROSE_ASSERT(st !=
nullptr);
27273 hmm = st->get_table();
27274 ROSE_ASSERT(hmm !=
nullptr);
27278 ROSE_ASSERT(st !=
nullptr);
27279 hmm = st->get_table();
27280 ROSE_ASSERT(hmm !=
nullptr);
27300 int match_count = 0;
27301 ROSE_ASSERT (root);
27305 Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(root, V_SgArrowExp);
27309 boost::unordered::unordered_map <SgNode*, bool> visited;
27312 for (Rose_STL_Container<SgNode *>::reverse_iterator i = nodeList.rbegin(); i != nodeList.rend(); i++)
27315 if (visited.count(*i)==1)
27324 cerr<<
"SageInterface::normalizeArrowExpWithAddressOfLeftOperand() expects SgArrowExp while encountering "<<(*i)->class_name()<<
"@"<<(*i) <<endl;
27325 ROSE_ASSERT (a_exp);
27328 if (transformationGeneratedOnly)
27336 if (
SgVarRefExp* left = isSgVarRefExp(address_op->get_operand()))
27349 return match_count;
27359 Traversal() : found(
false) {}
27360 void visit (
SgNode* node)
27362 SgCastExp* castExpression = isSgCastExp(node);
27363 if (castExpression != NULL)
27367 if (initializer == NULL)
27372 printf (
" --- Found a SgCastExp marked as a transformation: castExpression = %p \n",castExpression);
27375 printf (
"Exiting as a test! \n");
27376 ROSE_ASSERT(
false);
27382 printf (
" --- SgCastExp (but not marked as a transformation) node = %p = %s \n",node,node->
class_name().c_str());
27390 printf (
" --- SgCastExp (but from an initializer) node = %p = %s \n",node,node->
class_name().c_str());
27397 printf (
" --- node = %p = %s \n",node,node->
class_name().c_str());
27404 printf (
"In findFirstSgCastExpMarkedAsTransformation(): s = %s \n",s.c_str());
27408 Traversal traversal;
27409 traversal.traverse(n, preorder);
27412 printf (
"In findFirstSgCastExpMarkedAsTransformation(): s = %s traversal.found = %s \n",s.c_str(),traversal.found ?
"true" :
"false");
27416 if (traversal.found ==
true)
27418 printf (
"In findFirstSgCastExpMarkedAsTransformation(): returning false \n");
27423 return traversal.found;
27434 ROSE_ASSERT (info != NULL);
27435 PreprocessingInfo::DirectiveType dtype= info->getTypeOfDirective();
27436 if (dtype == PreprocessingInfo::CpreprocessorIfdefDeclaration ||
27437 dtype == PreprocessingInfo::CpreprocessorIfndefDeclaration ||
27438 dtype == PreprocessingInfo::CpreprocessorIfDeclaration )
27442 else if (dtype==PreprocessingInfo::CpreprocessorElseDeclaration||
27443 dtype==PreprocessingInfo::CpreprocessorElifDeclaration)
27447 else if (dtype==PreprocessingInfo::CpreprocessorEndifDeclaration)
27456static void moveInofListToNewPlace(AttachedPreprocessingInfoType* infoList,
int cidx, set <AttachedPreprocessingInfoType*>& relatedInfoList,
SgLocatedNode* lnode,
int &retVal)
27461 relatedInfoList.insert (infoList);
27465 info->setRelativePosition(PreprocessingInfo::after);
27472 (*infoList)[cidx]= NULL;
27479 ROSE_ASSERT(lnode);
27485 vector < pair< AttachedPreprocessingInfoType*, int> > empty_entries;
27486 for(;ast_i!=ast.
end();++ast_i) {
27488 if (current ==NULL )
27492 if (infoList == NULL)
continue;
27494 int commentIndex=0;
27495 for (Rose_STL_Container<PreprocessingInfo*>::iterator ci = (*infoList).begin(); ci != (*infoList).end(); ci++)
27501 empty_entries.push_back( make_pair (infoList, commentIndex) );
27507 for (
auto ki = empty_entries.rbegin(); ki != empty_entries.rend(); ki ++)
27509 AttachedPreprocessingInfoType* infoList = (*ki).first;
27510 int cidx= (*ki).second;
27513 ROSE_ASSERT (info==NULL);
27516 AttachedPreprocessingInfoType::iterator k = infoList->begin();
27517 infoList->erase(k+cidx);
27527static std::unordered_map <PreprocessingInfo*, SageInterface::PreprocessingInfoData> infoMap;
27532 if (current == NULL)
27538 vector<PreprocessingInfo*> afterList;
27541 AttachedPreprocessingInfoType* comments = locatedNode->getAttachedPreprocessingInfo();
27543 if (comments !=
nullptr)
27545 AttachedPreprocessingInfoType::iterator i;
27547 for (i = comments->begin (); i != comments->end (); i++)
27553 data.container=comments;
27555 data.depth = depth;
27558 if (info->getRelativePosition () == PreprocessingInfo::before)
27560 infoList.push_back (info);
27561 infoMap[info] = data;
27566 else if (info->getRelativePosition () == PreprocessingInfo::after
27567 || info->getRelativePosition () == PreprocessingInfo::inside
27570 afterList.push_back (info);
27571 infoMap[info] = data;
27575 mlog[Sawyer::Message::Common::WARN] <<
"Warning: unhandled relative position value:" <<info->getRelativePosition () <<endl;
27586 for (
auto c: children)
27590 for (
auto fi : afterList)
27591 infoList.push_back(fi);
27605 ROSE_ASSERT(lnode);
27621 vector < pair< AttachedPreprocessingInfoType*, int> > keepers;
27625 unordered_map < PreprocessingInfo * , vector< pair<AttachedPreprocessingInfoType*, int>> > associated_directives;
27630 vector< pair<AttachedPreprocessingInfoType*, int>> associated_erase;
27638 vector<PreprocessingInfo*> candidateInfoList;
27643 for (
auto candidate: candidateInfoList)
27650 if (infoMap[info].depth ==0)
27653 int commentIndex = infoMap[info].index;
27654 AttachedPreprocessingInfoType* infoList = infoMap[info].container;
27657 if ( isBeginDirective(info) == 1)
27659 keepers.push_back(make_pair (infoList,commentIndex));
27662 else if (isBeginDirective(info) == 2)
27667 if (keepers.size()==0)
27668 keepers.push_back(make_pair (infoList, commentIndex));
27669 else if (isBeginDirective( (*(keepers.back().first))[keepers.back().second] )!=1 )
27671 keepers.push_back(make_pair (infoList,commentIndex));
27673 else if(isBeginDirective( (*(keepers.back().first))[keepers.back().second] )==1 )
27675 PreprocessingInfo* begin_info = (*(keepers.back().first))[keepers.back().second];
27677 associated_directives[begin_info].push_back(make_pair (infoList,commentIndex));
27681 else if ( isBeginDirective(info) == -1)
27683 bool neutralized =
false;
27685 if (keepers.size()>0)
27687 AttachedPreprocessingInfoType* comments = keepers.back().first;
27688 int idx = keepers.back().second;
27690 if(isBeginDirective( (*comments)[idx] )==1)
27692 keepers.pop_back();
27693 neutralized =
true;
27698 keepers.push_back(make_pair (infoList,commentIndex));
27706 for(;ast_i!=ast.
end();++ast_i) {
27708 if (current ==NULL )
27712 if (infoList == NULL)
continue;
27714 int commentIndex=0;
27715 for (Rose_STL_Container<PreprocessingInfo*>::iterator ci = (*infoList).begin(); ci != (*infoList).end(); ci++)
27717 ROSE_ASSERT(*ci != NULL);
27723 if ( isBeginDirective(info) == 1)
27725 keepers.push_back(make_pair (infoList,commentIndex));
27728 else if (isBeginDirective(info) == 2)
27733 if (keepers.size()==0)
27734 keepers.push_back(make_pair (infoList,commentIndex));
27735 else if (isBeginDirective( (*(keepers.back().first))[keepers.back().second] )!=1 )
27737 keepers.push_back(make_pair (infoList,commentIndex));
27739 else if(isBeginDirective( (*(keepers.back().first))[keepers.back().second] )==1 )
27741 PreprocessingInfo* begin_info = (*(keepers.back().first))[keepers.back().second];
27743 associated_directives[begin_info].push_back(make_pair (infoList,commentIndex));
27747 else if ( isBeginDirective(info) == -1)
27749 bool neutralized =
false;
27751 if (keepers.size()>0)
27753 AttachedPreprocessingInfoType* comments = keepers.back().first;
27754 int idx = keepers.back().second;
27756 if(isBeginDirective( (*comments)[idx] )==1)
27758 keepers.pop_back();
27759 neutralized =
true;
27764 keepers.push_back(make_pair (infoList,commentIndex));
27771 set <AttachedPreprocessingInfoType*> relatedInfoList;
27774 for (
auto ki = keepers.begin(); ki != keepers.end(); ki ++)
27776 AttachedPreprocessingInfoType* infoList = (*ki).first;
27777 int cidx= (*ki).second;
27779 relatedInfoList.insert (infoList);
27783 info->setRelativePosition(PreprocessingInfo::after);
27790 if (associated_directives.count (info)!=0)
27792 vector<pair<AttachedPreprocessingInfoType*,int>> a_list_vec = associated_directives[info];
27793 for (
auto vec_i = a_list_vec.rbegin(); vec_i != a_list_vec.rend(); vec_i ++ )
27795 AttachedPreprocessingInfoType* a_infoList = (*vec_i).first;
27796 int aidx= (*vec_i).second;
27797 moveInofListToNewPlace (a_infoList, aidx, relatedInfoList, lnode, retVal);
27798 associated_erase.push_back(make_pair (a_infoList, aidx));
27804 (*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()
This function gets the adds comment or CPP directives to the current IR node.
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: