ROSE 0.11.145.147
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
10namespace ssa_private
11{
12
17{
18private:
19
23 std::vector<SgInitializedName*> key;
24
25 bool usesThis;
26
27public:
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
134public:
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
154class 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
171public:
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
Base class for all IR node attribute values.
Attribute Evaluator for synthesized attributes.
This class represents the notion of a declared variable.
This class represents the base class for all IR nodes within Sage III.
Class to traverse the AST and assign unique names to every varRef.
static std::string varKeyTag
Tag to use to retrieve unique naming key from node.
UniqueNameTraversal(const std::vector< SgInitializedName * > &allNames, bool treatPointersAsStructs=true, bool propagateNamesThroughComma=true)
std::vector< SgInitializedName * > VarName
A compound variable name as used by the variable renaming.
virtual VariableReferenceSet evaluateSynthesizedAttribute(SgNode *node, SynthesizedAttributesList attrs)
Called to evaluate the synthesized attribute on every node.
Class holding a unique name for a variable.
std::string getNameString()
Get the string representing this uniqueName.
const std::vector< SgInitializedName * > & getKey()
Get a constant reference to the name.
VarUniqueName(const VarUniqueName &other)
Copy the attribute.
VarUniqueName * copy() const
Virtual copy constructor.
VarUniqueName()
Constructs the attribute with an empty key.
VarUniqueName(const std::vector< SgInitializedName * > &prefix, SgInitializedName *thisNode)
Constructs the attribute using the prefix vector and thisNode.
void setKey(const std::vector< SgInitializedName * > &newKey)
Set the value of the name.
VarUniqueName(SgInitializedName *thisNode)
Constructs the attribute with value thisNode.
Attribute that describes the variables modified by a given expression.