ROSE 0.11.145.147
checkIsModifiedFlag.C
1// tps (01/14/2010) : Switching from rose.h to sage3.
2#include "sage3basic.h"
3#include "checkIsModifiedFlag.h"
4using namespace std;
5
6#if 0
7// DQ (4/16/2015): Replaced with better implementation.
8
11bool checkIsModifiedFlag( SgNode *node)
12 {
13 // DQ (7/7/2005): Introduce tracking of performance of ROSE.
14 TimingPerformance timer ("Check the isModifiedFlag in each IR node:");
15
16 return CheckIsModifiedFlagSupport(node);
17 }
18#endif
19
20#if 0
21// DQ (4/16/2015): Replaced with better implementation.
22
23// QY
24bool
25CheckIsModifiedFlagSupport(SgNode *node)
26{
27 bool retval=false;
28
29 // DQ (7/21/2010): This appears to be consuming 8-9 Gig of memory for the case of ROSE compiling a large source file.
30 // RPM (8/2/2010): However, binary unparsing depends on being able to see when the AST has been modified.
31#if 1
32 if (node->get_isModified()) {
33 node->set_isModified(false);
34 retval = true;
35 }
36
37 vector <SgNode*> children = node->get_traversalSuccessorContainer();
38 for (vector<SgNode*>::const_iterator p = children.begin(); p != children.end(); ++p) {
39 SgNode *cur = *p;
40 if (cur && node==cur->get_parent() && CheckIsModifiedFlagSupport(cur))
41 retval = true;
42 }
43#endif
44
45 return retval;
46}
47#endif
48
49ROSE_DLL_API void
50reportNodesMarkedAsModified(SgNode *node)
51 {
52 // DQ (4/15/2015): This function reports using an output message and nodes marked as isModified (useful for debugging).
53
54 class NodesMarkedAsModified : public AstSimpleProcessing
55 {
56 public:
57 void visit (SgNode* node)
58 {
59 if (node->get_isModified() == true)
60 {
61 printf ("reportNodesMarkedAsModified(): node = %p = %s \n",node,node->class_name().c_str());
62 }
63 }
64 };
65
66 // Now buid the traveral object and call the traversal (preorder) on the AST subtree.
67 NodesMarkedAsModified traversal;
68 traversal.traverse(node, preorder);
69 }
70
71ROSE_DLL_API void
72unsetNodesMarkedAsModified(SgNode *node)
73 {
74 // DQ (4/16/2015): This function sets the isModified flag on each node of the AST to false.
75
76#if 0
77 // DQ (6/4/2019): Debuggin the outlining to a seperate file (friend function inserted as
78 // part of transformation is marked as modified (but is reset, unclear how this is done).
79 printf ("In unsetNodesMarkedAsModified(): node = %p = %s \n",node,node->class_name().c_str());
80#endif
81
82 class NodesMarkedAsModified : public AstSimpleProcessing
83 {
84 public:
85 void visit (SgNode* node)
86 {
87 if (node->get_isModified() == true)
88 {
89#if 0
90 printf ("unsetNodesMarkedAsModified(): node = %p = %s \n",node,node->class_name().c_str());
91#endif
92 // Note that the set_isModified() functions is the only set_* access function that will not set the isModified flag.
93 node->set_isModified(false);
94 }
95 }
96 };
97
98 // Now buid the traveral object and call the traversal (preorder) on the AST subtree.
99 NodesMarkedAsModified traversal;
100 traversal.traverse(node, preorder);
101 }
102
103bool
104checkIsModifiedFlag(SgNode *node)
105 {
106 // DQ (4/16/2015): This function is a reimplementation of the previous version which used to much space on large programs.
107
108#if 0
109 // DQ (6/4/2019): Debugging the outlining to a seperate file (friend function inserted as
110 // part of transformation is marked as modified (but is reset, unclear how this is done).
111 printf ("In checkIsModifiedFlag(): node = %p = %s \n",node,node->class_name().c_str());
112#endif
113
114 // This function reproduces the functionality of the original checkIsModifiedFlag() function by both
115 // returning a bool value if any subtree was marked as isModified and also resetting the isModified flags.
116
117 class NodesMarkedAsModified : public AstSimpleProcessing
118 {
119 public:
120 bool isSubtreeModifiedFlag;
121
122 NodesMarkedAsModified () : isSubtreeModifiedFlag(false) {}
123
124 void visit (SgNode* node)
125 {
126 if (node->get_isModified() == true)
127 {
128 isSubtreeModifiedFlag = true;
129
130 // Note that the set_isModified() functions is the only set_* access function that will not set the isModified flag.
131 node->set_isModified(false);
132 }
133 }
134 };
135
136 // Now buid the traveral object and call the traversal (preorder) on the AST subtree.
137 NodesMarkedAsModified traversal;
138 traversal.traverse(node, preorder);
139
140 return traversal.isSubtreeModifiedFlag;
141 }
Class for traversing the AST.
virtual void visit(SgNode *astNode)=0
this method is called at every traversed node.
This class represents the base class for all IR nodes within Sage III.
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()
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
virtual std::string class_name() const
returns a string representing the class name
bool get_isModified() const
Acess function for isModified flag.