ROSE  0.9.9.139
rtiHelpers.h
1 #ifndef ROSE_RTIHELPERS_H
2 #define ROSE_RTIHELPERS_H
3 
4 #include <string>
5 #include <vector>
6 #include <list>
7 #include <set>
8 #include <sstream>
9 #include <iomanip>
10 #include <boost/lexical_cast.hpp>
11 
12 
13 // Helpful functions for Cxx_GrammarRTI.C
14 // Probably should not be included anywhere else
15 
16 #if ROSE_USE_VALGRIND
17 #include <valgrind/valgrind.h>
18 #include <valgrind/memcheck.h>
19 #include <stdio.h>
20 static void doUninitializedFieldCheck(const char* fieldName, void* fieldPointer, size_t fieldSize, void* wholeObject, const char* className) {
21  if (VALGRIND_CHECK_READABLE(fieldPointer, fieldSize)) {
22  fprintf(stderr, "Warning: uninitialized field p_%s of object %p of class %s\n", fieldName, wholeObject, className);
23  }
24 }
25 #endif
26 
27 template <typename T>
28 static std::string toStringForRTI(const T& x) {
29  std::ostringstream ss;
30  ss << x;
31  return ss.str();
32 }
33 
34 static std::string toStringForRTI(const Sawyer::Container::BitVector &x) {
35  return "0x" + x.toHex();
36 }
37 
38 template <typename T>
39 static std::string toStringForRTI(const std::vector<T>& x) {
40  std::ostringstream ss;
41  ss << "[";
42  for (typename std::vector<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
43  ss << "]";
44  return ss.str();
45 }
46 
47 // DQ (8/8/2008): Added support for type used in binary file format support.
48 template <typename T>
49 static std::string toStringForRTI(const std::vector<std::pair<T,T> >& x) {
50  std::ostringstream ss;
51  ss << "[";
52  for (typename std::vector<std::pair<T,T> >::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
53  ss << "]";
54  return ss.str();
55 }
56 
57 // std::vector < std::pair <SgOmpClause::omp_map_dist_data_enum, SgExpression*> >
58 template <typename F, typename S> // First and Second
59 static std::string toStringForRTI(const std::vector<std::pair<F,S> >& x) {
60  std::ostringstream ss;
61  ss << "[";
62  for (typename std::vector<std::pair<F,S> >::const_iterator i = x.begin(); i != x.end(); ++i)
63  {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
64  ss << "]";
65  return ss.str();
66 }
67 
68 #if 0 // not used
69 static std::string toStringForRTI(const ExtentMap &x)
70 {
71  std::ostringstream ss;
72  ss << "[";
73  for (ExtentMap::const_iterator i=x.begin(); i!=x.end(); ++i) {
74  if (i!=x.begin())
75  ss << ", ";
76  ss << i->first << "->" << i->second;
77  }
78  ss <<"]";
79  return ss.str();
80 }
81 #endif
82 // DQ (8/29/2008): Added the support for the Robb's SgSharedVector class.
83 template <typename T>
84 static std::string toStringForRTI(const SgSharedVector<T>& x)
85  {
86  std::ostringstream ss;
87  ss << "[";
88 
89  printf ("Warning: SgSharedVector iterator support is not finished! \n");
90  // ROSE_ASSERT(false);
91 
92  // for (typename std::vector<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
93 
94  ss << "]";
95  return ss.str();
96  }
97 
98 static std::string toStringForRTI(const std::vector<bool>& x) {
99  std::ostringstream ss;
100  ss << "[";
101  for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
102  ss << "]";
103  return ss.str();
104 }
105 
106 template <typename T>
107 static std::string toStringForRTI(const std::list<T>& x) {
108  std::ostringstream ss;
109  ss << "[";
110  for (typename std::list<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
111  ss << "]";
112  return ss.str();
113 }
114 
115 template <typename T>
116 static std::string toStringForRTI(const std::set<T>& x) {
117  std::ostringstream ss;
118  ss << "[";
119  for (typename std::set<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
120  ss << "]";
121  return ss.str();
122 }
123 
124 template <typename K, typename V>
125 static std::string toStringForRTI(const std::map<K, V>& x) {
126  std::ostringstream ss;
127  ss << "[";
128  for (typename std::map<K, V>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << toStringForRTI(i->second);}
129  ss << "]";
130  return ss.str();
131 }
132 
133 // negara1 (06/27/2011): Added support for the map of including files (field p_preprocessorDirectivesAndCommentsList)
134 template <typename K>
135 static std::string toStringForRTI(const std::map<K, std::set<PreprocessingInfo*> >& x) {
136  std::ostringstream ss;
137  ss << "[";
138  for (typename std::map<K, std::set<PreprocessingInfo*> >::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << toStringForRTI(i->second);}
139  ss << "]";
140  return ss.str();
141 }
142 
143 // DQ (4/30/2009): Added new support for std::multimap.
144 template <typename K, typename V>
145 static std::string toStringForRTI(const std::multimap<K, V>& x) {
146  std::ostringstream ss;
147  ss << "[";
148  for (typename std::multimap<K, V>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
149  ss << "]";
150  return ss.str();
151 }
152 
153 #if 0
154 static std::string toStringForRTI(const std::map<std::pair<int,std::pair<int,int> >, uint64_t > & x) {
155  std::ostringstream ss;
156  ss << "[";
157 // for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
158  ss << "]";
159  return ss.str();
160 }
161 #endif
162 
163 #if 0
164 static std::string toStringForRTI(const std::map<uint64_t ,std::pair<int,std::pair<int,int> > > & x) {
165  std::ostringstream ss;
166  ss << "[";
167 // for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
168  ss << "]";
169  return ss.str();
170 }
171 #endif
172 
173 #if 1
174 // #if !OLD_GRAPH_NODES
175 //#ifdef ROSE_USE_NEW_GRAPH_NODES
176 // DQ (8/18/2008): Added support for new Graph IR node.
177 
178 #ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
179 // static std::string toStringForRTI(const SgGraphNodeDirectedGraphEdgeMultimapPtrList & x)
180 static std::string toStringForRTI(const rose_graph_node_edge_hash_multimap & x)
181 {
182  std::ostringstream ss;
183  ss << "[";
184 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
185  ss << "]";
186  return ss.str();
187 }
188 #endif
189 
190 static std::string toStringForRTI(const rose_graph_integer_node_hash_map & x)
191 {
192  std::ostringstream ss;
193  ss << "[";
194 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
195  ss << "]";
196  return ss.str();
197 }
198 
199 static std::string toStringForRTI(const rose_graph_integer_edge_hash_map & x)
200 {
201  std::ostringstream ss;
202  ss << "[";
203 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
204  ss << "]";
205  return ss.str();
206 }
207 
208 static std::string toStringForRTI(const rose_graph_integer_edge_hash_multimap & x)
209 {
210  std::ostringstream ss;
211  ss << "[";
212 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
213  ss << "]";
214  return ss.str();
215 }
216 
217 static std::string toStringForRTI(const rose_graph_string_integer_hash_multimap & x)
218 {
219  std::ostringstream ss;
220  ss << "[";
221 // for (rose_graph_string_integer_hash_multimap::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
222  ss << "]";
223  return ss.str();
224 }
225 
226 static std::string toStringForRTI(const rose_graph_integerpair_edge_hash_multimap & x)
227 {
228  std::ostringstream ss;
229  ss << "[";
230 // for (rose_graph_string_integer_hash_multimap::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
231  ss << "]";
232  return ss.str();
233 }
234 
235 #if 0
236 // DQ (4/30/2009): Removed these in favor of the hash_multimap using the SgGraphEdge class.
237 static std::string toStringForRTI(const rose_undirected_graph_hash_multimap & x)
238 {
239  std::ostringstream ss;
240  ss << "[";
241 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
242  ss << "]";
243  return ss.str();
244 }
245 #endif
246 
247 #if 0
248 // DQ (4/30/2009): Removed these in favor of the hash_multimap using the SgGraphEdge class.
249 static std::string toStringForRTI(const rose_directed_graph_hash_multimap & x)
250 {
251  std::ostringstream ss;
252  ss << "[";
253 // for (SgGraphNodeDirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
254  ss << "]";
255  return ss.str();
256 }
257 #endif
258 
259 #ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
260 // DQ (8/18/2008): Added support for new Graph IR node.
261 // static std::string toStringForRTI(const SgStringGraphNodeMapPtrList & x)
262 static std::string toStringForRTI(const rose_graph_hash_multimap & x)
263 {
264  std::ostringstream ss;
265  ss << "[";
266 // for (SgStringGraphNodeMapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
267  ss << "]";
268  return ss.str();
269 }
270 #endif
271 
272 #if 0
273 // DQ (5/1/2009): This is no longer used and is replaced by an implementation using a hash_map.
274 // DQ (8/18/2008): Added support for new Graph IR node.
275 // static std::string toStringForRTI(const SgIntegerGraphNodeMapPtrList & x)
276 static std::string toStringForRTI(const std::map<int, SgGraphNode*> & x)
277 {
278  std::ostringstream ss;
279  ss << "[";
280 // for (SgIntegerGraphNodeMapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
281  for (std::map<int, SgGraphNode*>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
282  ss << "]";
283  return ss.str();
284 }
285 #endif
286 
287 #if 0
288 // DQ (4/25/2009): This is now redundant...
289 // DQ (8/18/2008): Added support for new Graph IR node.
290 // static std::string toStringForRTI(const SgGraphNodeUndirectedGraphEdgeMultimapPtrList & x)
291 static std::string toStringForRTI(const rose_undirected_graph_hash_multimap & x)
292 {
293  std::ostringstream ss;
294  ss << "[";
295 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
296  ss << "]";
297  return ss.str();
298 }
299 #endif
300 #endif
301 //#endif
302 // end condition new_graph
303 
304 static std::string toStringForRTI(const SgAccessModifier& m) {
305  return m.displayString();
306 }
307 
308 static std::string toStringForRTI(const SgUPC_AccessModifier& m) {
309  return m.displayString();
310 }
311 
312 static std::string toStringForRTI(const SgConstVolatileModifier& m) {
313  return m.displayString();
314 }
315 
316 static std::string toStringForRTI(const SgElaboratedTypeModifier& m) {
317  return m.displayString();
318 }
319 
320 static std::string toStringForRTI(const SgTypeModifier& m) {
321  return m.displayString();
322 }
323 
324 static std::string toStringForRTI(const SgStorageModifier& m) {
325  return m.displayString();
326 }
327 
328 static std::string toStringForRTI(const SgDeclarationModifier& m) {
329  return m.displayString();
330 }
331 
332 static std::string toStringForRTI(const SgFunctionModifier& m) {
333  return m.displayString();
334 }
335 
336 static std::string toStringForRTI(const SgSpecialFunctionModifier& m) {
337  return m.displayString();
338 }
339 
340 static std::string toStringForRTI(const SgName& n) {
341  return n.getString();
342 }
343 
344 static std::string toStringForRTI(const SgFunctionModifier::opencl_work_group_size_t & x) {
345  std::ostringstream os;
346  os << " ( " << x.x << ", " << x.y << ", " << x.z << " ) ";
347  return os.str();
348 }
349 
350 #if 0
351 // None of these seem to be used
352 
353 template <typename Sym>
354 static std::string toStringForRTISymbol(Sym* sym) {
355  std::ostringstream ss;
356  ss << sym;
357  if (sym) {
358  ss << ": varsym " << sym->get_name().str() << " declared at 0x" << std::hex << (sym->get_declaration());
359  }
360  return ss.str();
361 }
362 
363 static std::string toStringForRTI(SgVariableSymbol* sym) {return toStringForRTISymbol(sym);}
364 static std::string toStringForRTI(SgFunctionSymbol* sym) {return toStringForRTISymbol(sym);}
365 static std::string toStringForRTI(SgMemberFunctionSymbol* sym) {return toStringForRTISymbol(sym);}
366 
367 static std::string toStringForRTI(const SgSymbolTable&) {return "<no output operator defined for this type>";}
368 static std::string toStringForRTI(const SgSymbolHashBase::iterator&) {return "<no output operator defined for this type>";}
369 #endif
370 
371 void doRTI(const char* fieldNameBase, void* fieldPtr, size_t fieldSize, void* thisPtr, const char* className, const char* typeString, const char* fieldName, const std::string& fieldContents, RTIMemberData& memberData);
372 
373 #endif // ROSE_RTIHELPERS_H
This class represents modifiers for SgDeclaration (declaration statements).
This class represents strings within the IR nodes.
This class represents the concept of a variable name within the compiler (a shared container for the ...
Access to C++ Run Time Information (RTI)
Definition: Cxx_Grammar.h:8025
iterator begin()
First-item iterator.
Definition: rangemap.h:906
iterator end()
End-item iterator.
Definition: rangemap.h:918
This class represents modifiers specific to storage.
This class represents the symbol tables used in both SgScopeStatement and the SgFunctionTypeSymbolTab...
std::string toHex(const BitRange &range) const
Convert to a hexadecimal string.
Definition: BitVector.h:1123