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