ROSE  0.11.145.0
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 #include <Sawyer/BitVector.h>
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 inline 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 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
83 // DQ (8/29/2008): Added the support for the Robb's SgSharedVector class.
84 template <typename T>
85 static std::string toStringForRTI(const SgSharedVector<T>& x)
86  {
87  std::ostringstream ss;
88  ss << "[";
89 
90  printf ("Warning: SgSharedVector iterator support is not finished! \n");
91  // ROSE_ASSERT(false);
92 
93  // for (typename std::vector<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
94 
95  ss << "]";
96  return ss.str();
97  }
98 #endif
99 
100 static std::string toStringForRTI(const std::vector<bool>& x) {
101  std::ostringstream ss;
102  ss << "[";
103  for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
104  ss << "]";
105  return ss.str();
106 }
107 
108 template <typename T>
109 static std::string toStringForRTI(const std::list<T>& x) {
110  std::ostringstream ss;
111  ss << "[";
112  for (typename std::list<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
113  ss << "]";
114  return ss.str();
115 }
116 
117 template <typename T>
118 static std::string toStringForRTI(const std::set<T>& x) {
119  std::ostringstream ss;
120  ss << "[";
121  for (typename std::set<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
122  ss << "]";
123  return ss.str();
124 }
125 
126 template <typename K, typename V>
127 static std::string toStringForRTI(const std::map<K, V>& x) {
128  std::ostringstream ss;
129  ss << "[";
130  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);}
131  ss << "]";
132  return ss.str();
133 }
134 
135 // negara1 (06/27/2011): Added support for the map of including files (field p_preprocessorDirectivesAndCommentsList)
136 template <typename K>
137 static std::string toStringForRTI(const std::map<K, std::set<PreprocessingInfo*> >& x) {
138  std::ostringstream ss;
139  ss << "[";
140  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);}
141  ss << "]";
142  return ss.str();
143 }
144 
145 // DQ (4/30/2009): Added new support for std::multimap.
146 template <typename K, typename V>
147 static std::string toStringForRTI(const std::multimap<K, V>& x) {
148  std::ostringstream ss;
149  ss << "[";
150  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;}
151  ss << "]";
152  return ss.str();
153 }
154 
155 #if 0
156 static std::string toStringForRTI(const std::map<std::pair<int,std::pair<int,int> >, uint64_t > & x) {
157  std::ostringstream ss;
158  ss << "[";
159 // for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
160  ss << "]";
161  return ss.str();
162 }
163 #endif
164 
165 #if 0
166 static std::string toStringForRTI(const std::map<uint64_t ,std::pair<int,std::pair<int,int> > > & x) {
167  std::ostringstream ss;
168  ss << "[";
169 // for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
170  ss << "]";
171  return ss.str();
172 }
173 #endif
174 
175 #if 1
176 // #if !OLD_GRAPH_NODES
177 //#ifdef ROSE_USE_NEW_GRAPH_NODES
178 // DQ (8/18/2008): Added support for new Graph IR node.
179 
180 #ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
181 // static std::string toStringForRTI(const SgGraphNodeDirectedGraphEdgeMultimapPtrList & x)
182 static std::string toStringForRTI(const rose_graph_node_edge_hash_multimap & x)
183 {
184  std::ostringstream ss;
185  ss << "[";
186 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
187  ss << "]";
188  return ss.str();
189 }
190 #endif
191 
192 static std::string toStringForRTI(const rose_graph_integer_node_hash_map & x)
193 {
194  std::ostringstream ss;
195  ss << "[";
196 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
197  ss << "]";
198  return ss.str();
199 }
200 
201 static std::string toStringForRTI(const rose_graph_integer_edge_hash_map & x)
202 {
203  std::ostringstream ss;
204  ss << "[";
205 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
206  ss << "]";
207  return ss.str();
208 }
209 
210 static std::string toStringForRTI(const rose_graph_integer_edge_hash_multimap & x)
211 {
212  std::ostringstream ss;
213  ss << "[";
214 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
215  ss << "]";
216  return ss.str();
217 }
218 
219 static std::string toStringForRTI(const rose_graph_string_integer_hash_multimap & x)
220 {
221  std::ostringstream ss;
222  ss << "[";
223 // 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;}
224  ss << "]";
225  return ss.str();
226 }
227 
228 static std::string toStringForRTI(const rose_graph_integerpair_edge_hash_multimap & x)
229 {
230  std::ostringstream ss;
231  ss << "[";
232 // 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;}
233  ss << "]";
234  return ss.str();
235 }
236 
237 #if 0
238 // DQ (4/30/2009): Removed these in favor of the hash_multimap using the SgGraphEdge class.
239 static std::string toStringForRTI(const rose_undirected_graph_hash_multimap & x)
240 {
241  std::ostringstream ss;
242  ss << "[";
243 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
244  ss << "]";
245  return ss.str();
246 }
247 #endif
248 
249 #if 0
250 // DQ (4/30/2009): Removed these in favor of the hash_multimap using the SgGraphEdge class.
251 static std::string toStringForRTI(const rose_directed_graph_hash_multimap & x)
252 {
253  std::ostringstream ss;
254  ss << "[";
255 // for (SgGraphNodeDirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
256  ss << "]";
257  return ss.str();
258 }
259 #endif
260 
261 #ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
262 // DQ (8/18/2008): Added support for new Graph IR node.
263 // static std::string toStringForRTI(const SgStringGraphNodeMapPtrList & x)
264 static std::string toStringForRTI(const rose_graph_hash_multimap & x)
265 {
266  std::ostringstream ss;
267  ss << "[";
268 // for (SgStringGraphNodeMapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
269  ss << "]";
270  return ss.str();
271 }
272 #endif
273 
274 #if 0
275 // DQ (5/1/2009): This is no longer used and is replaced by an implementation using a hash_map.
276 // DQ (8/18/2008): Added support for new Graph IR node.
277 // static std::string toStringForRTI(const SgIntegerGraphNodeMapPtrList & x)
278 static std::string toStringForRTI(const std::map<int, SgGraphNode*> & x)
279 {
280  std::ostringstream ss;
281  ss << "[";
282 // for (SgIntegerGraphNodeMapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
283  for (std::map<int, SgGraphNode*>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
284  ss << "]";
285  return ss.str();
286 }
287 #endif
288 
289 #if 0
290 // DQ (4/25/2009): This is now redundant...
291 // DQ (8/18/2008): Added support for new Graph IR node.
292 // static std::string toStringForRTI(const SgGraphNodeUndirectedGraphEdgeMultimapPtrList & x)
293 static std::string toStringForRTI(const rose_undirected_graph_hash_multimap & x)
294 {
295  std::ostringstream ss;
296  ss << "[";
297 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
298  ss << "]";
299  return ss.str();
300 }
301 #endif
302 #endif
303 //#endif
304 // end condition new_graph
305 
306 static std::string toStringForRTI(const SgAccessModifier& m) {
307  return m.displayString();
308 }
309 
310 static std::string toStringForRTI(const SgUPC_AccessModifier& m) {
311  return m.displayString();
312 }
313 
314 static std::string toStringForRTI(const SgConstVolatileModifier& m) {
315  return m.displayString();
316 }
317 
318 static std::string toStringForRTI(const SgElaboratedTypeModifier& m) {
319  return m.displayString();
320 }
321 
322 static std::string toStringForRTI(const SgTypeModifier& m) {
323  return m.displayString();
324 }
325 
326 static std::string toStringForRTI(const SgStorageModifier& m) {
327  return m.displayString();
328 }
329 
330 static std::string toStringForRTI(const SgDeclarationModifier& m) {
331  return m.displayString();
332 }
333 
334 static std::string toStringForRTI(const SgFunctionModifier& m) {
335  return m.displayString();
336 }
337 
338 static std::string toStringForRTI(const SgSpecialFunctionModifier& m) {
339  return m.displayString();
340 }
341 
342 static std::string toStringForRTI(const SgName& n) {
343  return n.getString();
344 }
345 
346 static std::string toStringForRTI(const SgFunctionModifier::opencl_work_group_size_t & x) {
347  std::ostringstream os;
348  os << " ( " << x.x << ", " << x.y << ", " << x.z << " ) ";
349  return os.str();
350 }
351 
352 // Rasmussen (6/4/2021): scoped enumerations from ROSETTA
353 static std::string toStringForRTI(SgJovialTableStatement::WordsPerEntry &e) {
354  return std::to_string(static_cast<int>(e));
355 }
356 static std::string toStringForRTI(SgJovialTableType::StructureSpecifier &e) {
357  return std::to_string(static_cast<int>(e));
358 }
359 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
360 static std::string toStringForRTI(Rose::BinaryAnalysis::JvmInstructionKind &e) {
361  std::ostringstream os;
363  int intKind = static_cast<int>(kind);
364  os << intKind;
365  return std::to_string(static_cast<int>(e));
366 }
367 #endif
368 
369 #if 0
370 // None of these seem to be used
371 
372 template <typename Sym>
373 static std::string toStringForRTISymbol(Sym* sym) {
374  std::ostringstream ss;
375  ss << sym;
376  if (sym) {
377  ss << ": varsym " << sym->get_name().str() << " declared at 0x" << std::hex << (sym->get_declaration());
378  }
379  return ss.str();
380 }
381 
382 static std::string toStringForRTI(SgVariableSymbol* sym) {return toStringForRTISymbol(sym);}
383 static std::string toStringForRTI(SgFunctionSymbol* sym) {return toStringForRTISymbol(sym);}
384 static std::string toStringForRTI(SgMemberFunctionSymbol* sym) {return toStringForRTISymbol(sym);}
385 
386 static std::string toStringForRTI(const SgSymbolTable&) {return "<no output operator defined for this type>";}
387 static std::string toStringForRTI(const SgSymbolHashBase::iterator&) {return "<no output operator defined for this type>";}
388 #endif
389 
390 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);
391 
392 #endif // ROSE_RTIHELPERS_H
This class represents modifiers for SgDeclaration (declaration statements).
JvmInstructionKind
The Java Virtual Machine (JVM) instruction set.
This class represents strings within the IR nodes.
StructureSpecifier
Enum for Jovial structure specifiers.
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:9607
iterator begin()
First-item iterator.
Definition: rangemap.h:901
iterator end()
End-item iterator.
Definition: rangemap.h:913
This class represents modifiers specific to storage.
This class represents the symbol tables used in both SgScopeStatement and the SgFunctionTypeSymbolTab...
WordsPerEntry
Enum for words-per-entry in a Jovial table.
std::string toHex(const BitRange &range) const
Convert to a hexadecimal string.
Definition: BitVector.h:1249