1 #ifndef ROSE_SAGE_INTERFACE
2 #define ROSE_SAGE_INTERFACE
4 #include "sage3basic.hhh"
8 #if 0 // FMZ(07/07/2010): the argument "nextErrorCode" should be call-by-reference
14 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
19 #include "astUnparseAttribute.h"
22 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
24 #include "abstract_handle.h"
52 #define TRANS_FILE Sg_File_Info::generateDefaultFileInfoForTransformationNode()
84 namespace SageInterface
98 std::map<SgDeclarationStatement*,std::set<SgDeclarationStatement*>* >
declarationMap;
104 std::map<SgDeclarationStatement*,std::set<SgDeclarationStatement*>* > &
getDeclarationMap();
152 inline size_t hash_value(
SgNode* t) {
return (
size_t)t;}
168 return (
size_t) hash_value(node);
170 return (
size_t) node;
377 * memberFunctionDeclaration);
401 memberFunctionDeclaration);
452 std::string
generateUniqueName (
const SgNode * node,
bool ignoreDifferenceBetweenDefiningAndNondefiningDeclarations);
518 template <
typename NodeType>
699 const std::string & text,
814 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
908 std::vector<SgExpression*>
931 std::vector<SgExpression*>
937 std::vector<SgExpression*>
1090 template <
typename NodeType>
1095 std::vector<NodeType*> result(nodes.size(), NULL);
1097 for (Rose_STL_Container<SgNode*>::const_iterator i = nodes.begin();
1098 i != nodes.end(); ++i, ++count) {
1099 NodeType* node =
dynamic_cast<NodeType*
>(*i);
1101 result[count] = node;
1115 template <
typename NodeType>
1122 std::vector<NodeType*> resultlist;
1123 void visit (
SgNode* node)
1125 NodeType* result =
dynamic_cast<NodeType*
> (node);
1126 ROSE_ASSERT(result!= NULL);
1129 resultlist.push_back(result);
1132 virtual ~MyTraversal() {}
1135 MyTraversal my_traversal;
1136 NodeType::visitRepresentativeNode(my_traversal);
1137 return my_traversal.resultlist;
1171 template <
typename T>
1175 if (!root)
return 0;
1176 T* decl =
dynamic_cast<T*
>(root);
1181 if ((decl->get_scope() == scope)&&
1182 (decl->search_for_symbol_from_symbol_table()->get_name()==
name))
1189 if(decl->search_for_symbol_from_symbol_table()->get_name()==
name)
1200 ROSE_ASSERT (decl->get_definingDeclaration() != NULL);
1201 return dynamic_cast<T*
> (decl->get_definingDeclaration());
1208 for (std::vector<SgNode*>::const_iterator i = children.begin();
1209 i != children.end(); ++i)
1211 T* target= findDeclarationStatement<T> (*i,
name, scope, isDefining);
1253 template <
typename NodeType>
1261 if (NULL == astNode)
1266 if ( (includingSelf ) && (dynamic_cast<const NodeType*>(astNode)) )
1268 return const_cast<NodeType*
>(
dynamic_cast<const NodeType*
> (astNode));
1272 ROSE_ASSERT(astNode->
get_parent() != astNode);
1277 SgNode* previouslySeenParent = parent;
1278 bool foundCycle =
false;
1279 while ( (foundCycle ==
false) && (parent != NULL) && (!dynamic_cast<const NodeType*>(parent)) )
1281 ROSE_ASSERT(parent->get_parent() != parent);
1283 printf (
"In getEnclosingNode(): parent = %p = %s \n",parent,parent->class_name().c_str());
1289 if (parent == previouslySeenParent)
1296 printf (
"previouslySeenParent = %p = %s \n",previouslySeenParent,previouslySeenParent->
class_name().c_str());
1299 parent = previouslySeenParent;
1302 if (declarationStatement != NULL)
1305 printf (
"Found a SgDeclarationStatement \n");
1311 printf (
" --- declarationStatement = %p \n",declarationStatement);
1312 printf (
" --- definingDeclaration = %p \n",definingDeclaration);
1313 if (definingDeclaration != NULL && definingDeclaration->
get_parent() != NULL)
1314 printf (
" --- definingDeclaration ->get_parent() = %p = %s \n",definingDeclaration->
get_parent(),definingDeclaration->
get_parent()->
class_name().c_str());
1315 printf (
" --- firstNondefiningDeclaration = %p \n",firstNondefiningDeclaration);
1316 if (firstNondefiningDeclaration != NULL && firstNondefiningDeclaration->
get_parent() != NULL)
1317 printf (
" --- firstNondefiningDeclaration ->get_parent() = %p = %s \n",firstNondefiningDeclaration->
get_parent(),firstNondefiningDeclaration->
get_parent()->
class_name().c_str());
1319 if (definingDeclaration != NULL && declarationStatement != firstNondefiningDeclaration)
1322 printf (
"Found a nondefining declaration so use the non-defining declaration instead \n");
1326 parent = definingDeclaration;
1331 printf (
"reset: previouslySeenParent = %p = %s \n",previouslySeenParent,previouslySeenParent->
class_name().c_str());
1345 if (foundCycle ==
false)
1349 while ( (parent != NULL) && (!
dynamic_cast<const NodeType*
>(parent)) )
1351 ROSE_ASSERT(parent->get_parent() != parent);
1353 printf (
"In getEnclosingNode() (2nd try): parent = %p = %s \n",parent,parent->class_name().c_str());
1354 if (parent->get_file_info() != NULL)
1358 if (declarationStatement != NULL)
1361 printf (
"Found a SgDeclarationStatement \n");
1366 printf (
" --- declarationStatement = %p = %s \n",declarationStatement,(declarationStatement != NULL) ? declarationStatement->
class_name().c_str() :
"null");
1368 printf (
" --- definingDeclaration = %p \n",definingDeclaration);
1369 if (definingDeclaration != NULL && definingDeclaration->
get_parent() != NULL)
1370 printf (
" --- definingDeclaration ->get_parent() = %p = %s \n",definingDeclaration->
get_parent(),definingDeclaration->
get_parent()->
class_name().c_str());
1372 printf (
" --- firstNondefiningDeclaration = %p \n",firstNondefiningDeclaration);
1373 if (firstNondefiningDeclaration != NULL && firstNondefiningDeclaration->
get_parent() != NULL)
1374 printf (
" --- firstNondefiningDeclaration ->get_parent() = %p = %s \n",firstNondefiningDeclaration->
get_parent(),firstNondefiningDeclaration->
get_parent()->
class_name().c_str());
1376 if (definingDeclaration != NULL && declarationStatement != firstNondefiningDeclaration)
1379 printf (
"Found a nondefining declaration so use the firstNondefining declaration instead \n");
1383 parent = definingDeclaration;
1391 ROSE_ASSERT(parent != previouslySeenParent);
1393 printf (
"WARNING::WARNING::WARNING commented out assertion for parent != previouslySeenParent \n");
1394 if (parent == previouslySeenParent)
1400 return const_cast<NodeType*
>(
dynamic_cast<const NodeType*
> (parent));
1407 std::set<const SgNode*> seen;
1409 if (NodeType *found = dynamic_cast<NodeType*>(node))
1413 ROSE_ASSERT(seen.insert(node).second);
1419 if (definingDeclaration && firstNondefiningDeclaration && declarationStatement != firstNondefiningDeclaration) {
1422 node = definingDeclaration;
1673 template <
class actualFunction>
1681 template <
class actualFunction>
1690 ROSE_ASSERT(func != NULL);
1691 ROSE_ASSERT(paralist != NULL);
1698 cerr <<
"Waring! Setting a used SgFunctionParameterList to function: "
1699 << (func->get_name()).getString()<<endl
1700 <<
" Sharing parameter lists can corrupt symbol tables!"<<endl
1701 <<
" Please use deepCopy() to get an exclusive parameter list for each function declaration!"<<endl;
1707 if (func->get_parameterList() != NULL)
1709 if (func->get_parameterList() != paralist)
1711 delete func->get_parameterList();
1715 func->set_parameterList(paralist);
1722 for (SgInitializedNamePtrList::iterator i = args.begin(); i != args.end(); i++)
1724 (*i)->set_declptr(func);
1851 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
1997 std::pair<SgStatement*, SgInitializedName*>
2005 template <
class NameGen>
2006 std::pair<SgStatement*, SgInitializedName*>
2027 std::string buildOperatorString (
SgNode* astNode );
2030 std::string dump_node(
const SgNode* astNode);
2031 std::string dump_tree(
const SgNode* astNode);
2052 verifySgNode(
SgNode* node,
bool subTree=
true);
2069 void insertAst(
SgNode* targetPosition,
SgNode* newNode,
bool insertBefore=
true);
2081 void removeSgNode(
SgNode* targetNode);
2082 void removeSgNodeTree(
SgNode* subtree);
2105 void flattenBlocks(
SgNode* n);
2108 void renameVariables(
SgNode* n);
2111 void simpleCopyAndConstantPropagation(
SgNode* top);
2112 void changeAllMembersToPublic(
SgNode* n);
2123 void pushTestIntoBody(LoopStatement* loopStmt);
2127 void moveForDeclaredVariables(
SgNode* root);
2153 bool isConst(
SgNode* node);
2176 bool isPotentiallyModifiedDuringLifeOf(
SgBasicBlock* sc,
2180 bool anyOfListPotentiallyModifiedIn(
const std::vector<SgVariableSymbol*>& syms,
SgNode* n);
2199 void replaceAssignmentStmtWithStatement(
SgExprStatement* from, StatementGenerator* to);
2202 StatementGenerator* to);
2231 from transformationSupport.h, not sure
if they should be included here
2233 operatorCodeType classifyOverloadedOperator();
2240 std::string stringifyOperator (std::string
name);
2244 std::string buildMacro ( std::string s );
2249 *
get/set a direct child/grandchild node or fields
2250 *
get/set a
property flag value
2251 *
get a descendent child node
using preorder searching
2252 *
get an
ancestor node
using bottomup/reverse searching