ROSE  0.11.96.11
uniqueNameTraversal.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 <vector>
9 
10 namespace ssa_private
11 {
12 
17 {
18 private:
19 
23  std::vector<SgInitializedName*> key;
24 
25  bool usesThis;
26 
27 public:
28 
31  VarUniqueName() : key(), usesThis(false)
32  {
33  }
34 
41  VarUniqueName(SgInitializedName* thisNode) : usesThis(false)
42  {
43  key.push_back(thisNode);
44  }
45 
54  VarUniqueName(const std::vector<SgInitializedName*>& prefix, SgInitializedName* thisNode) : usesThis(false)
55  {
56  key.assign(prefix.begin(), prefix.end());
57  key.push_back(thisNode);
58  }
59 
64  VarUniqueName(const VarUniqueName& other) : AstAttribute(other), usesThis(false)
65  {
66  key.assign(other.key.begin(), other.key.end());
67  }
68 
70  {
71  VarUniqueName* newName = new VarUniqueName(*this);
72  return newName;
73  }
74 
79  const std::vector<SgInitializedName*>& getKey()
80  {
81  return key;
82  }
83 
88  void setKey(const std::vector<SgInitializedName*>& newKey)
89  {
90  key.assign(newKey.begin(), newKey.end());
91  }
92 
93  bool getUsesThis()
94  {
95  return usesThis;
96  }
97 
98  void setUsesThis(bool uses)
99  {
100  usesThis = uses;
101  }
102 
107  std::string getNameString()
108  {
109  std::string name = "";
110  std::vector<SgInitializedName*>::iterator iter;
111  if (usesThis)
112  name += "this->";
113  for (iter = key.begin(); iter != key.end(); ++iter)
114  {
115  if (iter != key.begin())
116  {
117  name += ":";
118  }
119  name += (*iter)->get_name().getString();
120  }
121 
122  return name;
123  }
124 };
125 
128 {
132  SgNode* currentVar;
133 
134 public:
135 
137 
138  VariableReferenceSet() : currentVar(NULL)
139  {
140  }
141 
143  {
144  currentVar = var;
145  }
146 
147  SgNode* getCurrentVar()
148  {
149  return currentVar;
150  }
151 };
152 
154 class UniqueNameTraversal : public AstBottomUpProcessing<VariableReferenceSet>
155 {
157  std::vector<SgInitializedName*> allInitNames;
158 
161  SgInitializedName* resolveTemporaryInitNames(SgInitializedName* name);
162 
165  const bool treatPointersAsStructs;
166 
169  const bool propagateNamesThroughComma;
170 
171 public:
172 
174  static std::string varKeyTag;
175 
177  typedef std::vector<SgInitializedName*> VarName;
178 
181 
182  UniqueNameTraversal(const std::vector<SgInitializedName*>& allNames,
183  bool treatPointersAsStructs = true, bool propagateNamesThroughComma = true) : allInitNames(allNames),
184  treatPointersAsStructs(treatPointersAsStructs), propagateNamesThroughComma(propagateNamesThroughComma)
185  {
186  }
187 
196  virtual VariableReferenceSet evaluateSynthesizedAttribute(SgNode* node, SynthesizedAttributesList attrs);
197 };
198 
199 } //namespace ssa_private
ssa_private::VarUniqueName::getKey
const std::vector< SgInitializedName * > & getKey()
Get a constant reference to the name.
Definition: uniqueNameTraversal.h:79
ssa_private::UniqueNameTraversal::VarName
std::vector< SgInitializedName * > VarName
A compound variable name as used by the variable renaming.
Definition: uniqueNameTraversal.h:177
ssa_private::UniqueNameTraversal
Class to traverse the AST and assign unique names to every varRef.
Definition: uniqueNameTraversal.h:154
AstAttribute
Base class for all IR node attribute values.
Definition: AstAttributeMechanism.h:35
ssa_private::VarUniqueName::VarUniqueName
VarUniqueName(const VarUniqueName &other)
Copy the attribute.
Definition: uniqueNameTraversal.h:64
ssa_private::VarUniqueName::VarUniqueName
VarUniqueName()
Constructs the attribute with an empty key.
Definition: uniqueNameTraversal.h:31
AstBottomUpProcessing
Attribute Evaluator for synthesized attributes.
Definition: AstProcessing.h:289
ssa_private::UniqueNameTraversal::varKeyTag
static std::string varKeyTag
Tag to use to retrieve unique naming key from node.
Definition: uniqueNameTraversal.h:174
ssa_private::VarUniqueName::VarUniqueName
VarUniqueName(SgInitializedName *thisNode)
Constructs the attribute with value thisNode.
Definition: uniqueNameTraversal.h:41
ssa_private::VarUniqueName::copy
VarUniqueName * copy() const
Virtual copy constructor.
Definition: uniqueNameTraversal.h:69
ssa_private::UniqueNameTraversal::evaluateSynthesizedAttribute
virtual VariableReferenceSet evaluateSynthesizedAttribute(SgNode *node, SynthesizedAttributesList attrs)
Called to evaluate the synthesized attribute on every node.
SgNode
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:6739
ssa_private::VarUniqueName::getNameString
std::string getNameString()
Get the string representing this uniqueName.
Definition: uniqueNameTraversal.h:107
ssa_private::VariableReferenceSet
Attribute that describes the variables modified by a given expression.
Definition: uniqueNameTraversal.h:127
SgInitializedName
This class represents the notion of a declared variable.
Definition: Cxx_Grammar.h:76851
ssa_private::VariableReferenceSet::VariableReferenceSet
VariableReferenceSet()
Default constructor.
Definition: uniqueNameTraversal.h:138
ssa_private::VarUniqueName::setKey
void setKey(const std::vector< SgInitializedName * > &newKey)
Set the value of the name.
Definition: uniqueNameTraversal.h:88
ssa_private::VarUniqueName::VarUniqueName
VarUniqueName(const std::vector< SgInitializedName * > &prefix, SgInitializedName *thisNode)
Constructs the attribute using the prefix vector and thisNode.
Definition: uniqueNameTraversal.h:54
ssa_private::VarUniqueName
Class holding a unique name for a variable.
Definition: uniqueNameTraversal.h:16
ssa_private::UniqueNameTraversal::UniqueNameTraversal
UniqueNameTraversal(const std::vector< SgInitializedName * > &allNames, bool treatPointersAsStructs=true, bool propagateNamesThroughComma=true)
Definition: uniqueNameTraversal.h:182