ROSE  0.9.9.109
checkIsModifiedFlag.C
1 // tps (01/14/2010) : Switching from rose.h to sage3.
2 #include "sage3basic.h"
3 #include "checkIsModifiedFlag.h"
4 using namespace std;
5 
6 #if 0
7 // DQ (4/16/2015): Replaced with better implementation.
8 
11 bool 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
24 bool
25 CheckIsModifiedFlagSupport(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 
49 ROSE_DLL_API void
50 reportNodesMarkedAsModified(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 
71 ROSE_DLL_API void
72 unsetNodesMarkedAsModified(SgNode *node)
73  {
74  // DQ (4/16/2015): This function sets the isModified flag on each node of the AST to false.
75 
76  class NodesMarkedAsModified : public AstSimpleProcessing
77  {
78  public:
79  void visit (SgNode* node)
80  {
81  if (node->get_isModified() == true)
82  {
83 #if 0
84  printf ("unsetNodesMarkedAsModified(): node = %p = %s \n",node,node->class_name().c_str());
85 #endif
86  // Note that the set_isModified() functions is the only set_* access function that will not set the isModified flag.
87  node->set_isModified(false);
88  }
89  }
90  };
91 
92  // Now buid the traveral object and call the traversal (preorder) on the AST subtree.
93  NodesMarkedAsModified traversal;
94  traversal.traverse(node, preorder);
95  }
96 
97 bool
98 checkIsModifiedFlag(SgNode *node)
99  {
100  // DQ (4/16/2015): This function is a reimplementation of the previous version which used to much space on large programs.
101 
102  // This function reproduces the functionality of the original checkIsModifiedFlag() function by both
103  // returning a bool value if any subtree was marked as isModified and also resetting the isModified flags.
104 
105  class NodesMarkedAsModified : public AstSimpleProcessing
106  {
107  public:
108  bool isSubtreeModifiedFlag;
109 
110  NodesMarkedAsModified () : isSubtreeModifiedFlag(false) {}
111 
112  void visit (SgNode* node)
113  {
114  if (node->get_isModified() == true)
115  {
116  isSubtreeModifiedFlag = true;
117 
118  // Note that the set_isModified() functions is the only set_* access function that will not set the isModified flag.
119  node->set_isModified(false);
120  }
121  }
122  };
123 
124  // Now buid the traveral object and call the traversal (preorder) on the AST subtree.
125  NodesMarkedAsModified traversal;
126  traversal.traverse(node, preorder);
127 
128  return traversal.isSubtreeModifiedFlag;
129  }
Class for traversing the AST.
STL namespace.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8322
virtual std::string class_name() const
returns a string representing the class name
virtual std::vector< SgNode * > get_traversalSuccessorContainer()
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
bool get_isModified() const
Acess function for isModified flag.
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.