ROSE  0.9.9.139
defsAndUsesTraversal.h
1 #pragma once
2 
3 // DQ (10/5/2014): This is more strict now that we include rose_config.h in the sage3basic.h.
4 // #include "rose.h"
5 // rose.h and sage3basic.h should not be included in librose header files. [Robb P. Matzke 2014-10-15]
6 // #include "sage3basic.h"
7 
8 #include "staticSingleAssignment.h"
9 
10 namespace ssa_private
11 {
12 
14  class ChildUses
15  {
16  private:
18  SgVarRefExp* currentVar;
19 
21  std::vector<SgNode*> uses;
22 
23  public:
24 
26  ChildUses() : currentVar(NULL)
27  {
28  }
29 
30  ChildUses(SgNode* useNode, SgVarRefExp* var)
31  {
32  uses.push_back(useNode);
33  currentVar = var;
34  }
35 
40  ChildUses(const std::vector<SgNode*>& useTree, SgVarRefExp* var = NULL)
41  {
42  if (useTree.size() > 0)
43  uses.assign(useTree.begin(), useTree.end());
44  currentVar = var;
45  }
46 
51  std::vector<SgNode*>& getUses()
52  {
53  return uses;
54  }
55 
60  void setUses(const std::vector<SgNode*>& newUses)
61  {
62  uses.assign(newUses.begin(), newUses.end());
63  }
64 
65  SgVarRefExp* getCurrentVar() const
66  {
67  return currentVar;
68  }
69  };
70 
74  class DefsAndUsesTraversal : public AstBottomUpProcessing<ChildUses>
75  {
77 
80  const bool treatPointersAsStructs;
81 
82  public:
83 
86  DefsAndUsesTraversal(StaticSingleAssignment* ssa, bool treatPointersAsStructs = true) : ssa(ssa),
87  treatPointersAsStructs(treatPointersAsStructs)
88  {
89  }
90 
99  virtual ChildUses evaluateSynthesizedAttribute(SgNode* node, SynthesizedAttributesList attrs);
100 
101  private:
102 
104  void addUsesToNode(SgNode* node, std::vector<SgNode*> uses);
105 
107  void addDefForVarAtNode(SgVarRefExp* currentVar, SgNode* defNode);
108  };
109 
110 } //namespace ssa_private
111 
Attribute that describes the variables used by a given expression.
Attribute Evaluator for synthesized attributes.
void setUses(const std::vector< SgNode * > &newUses)
Set the uses for this node and below.
ChildUses(const std::vector< SgNode * > &useTree, SgVarRefExp *var=NULL)
Create the attribute with the def and list of uses.
DefsAndUsesTraversal(StaticSingleAssignment *ssa, bool treatPointersAsStructs=true)
Static single assignment analysis.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8322
This class represents the variable refernece in expressions.
ChildUses()
Create the attribute with no refs.
virtual ChildUses evaluateSynthesizedAttribute(SgNode *node, SynthesizedAttributesList attrs)
Called to evaluate the synthesized attribute on every node.
std::vector< SgNode * > & getUses()
Get the uses for this node and below.
This class collects all the defs and uses associated with each node in the traversed CFG...