ROSE 0.11.145.317
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
49template <typename T>
50static std::string toStringForRTI(const std::vector<std::pair<T,T> >& x) {
51 std::ostringstream ss;
52 ss << "[";
53 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;}
54 ss << "]";
55 return ss.str();
56}
57
58template <typename F, typename S> // First and Second
59static 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#ifdef ROSE_ENABLE_BINARY_ANALYSIS
69template <typename T>
70static std::string toStringForRTI(const SgSharedVector<T>& /*x*/)
71 {
72 std::ostringstream ss;
73 ss << "[";
74 printf ("Warning: SgSharedVector iterator support is not finished! \n");
75 ss << "]";
76 return ss.str();
77 }
78#endif
79
80static std::string toStringForRTI(const std::vector<bool>& x) {
81 std::ostringstream ss;
82 ss << "[";
83 for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
84 ss << "]";
85 return ss.str();
86}
87
88template <typename T>
89static std::string toStringForRTI(const std::list<T>& x) {
90 std::ostringstream ss;
91 ss << "[";
92 for (typename std::list<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
93 ss << "]";
94 return ss.str();
95}
96
97template <typename T>
98static std::string toStringForRTI(const std::set<T>& x) {
99 std::ostringstream ss;
100 ss << "[";
101 for (typename std::set<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
102 ss << "]";
103 return ss.str();
104}
105
106template <typename T>
107static std::string toStringForRTI(const std::unordered_set<T>& x) {
108 std::ostringstream ss;
109 ss << "[";
110 for (auto i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
111 ss << "]";
112 return ss.str();
113}
114
115
116template <typename K, typename V>
117static std::string toStringForRTI(const std::map<K, V>& x) {
118 std::ostringstream ss;
119 ss << "[";
120 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);}
121 ss << "]";
122 return ss.str();
123}
124
125template <typename K, typename V>
126static std::string toStringForRTI(const std::unordered_map<K, V>& x) {
127 std::ostringstream ss;
128 ss << "[";
129 for (auto i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << toStringForRTI(i->second);}
130 ss << "]";
131 return ss.str();
132}
133
134
135template <typename K>
136static std::string toStringForRTI(const std::map<K, std::set<PreprocessingInfo*> >& x) {
137 std::ostringstream ss;
138 ss << "[";
139 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);}
140 ss << "]";
141 return ss.str();
142}
143
144template <typename K, typename V>
145static 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#ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
154static std::string toStringForRTI(const rose_graph_node_edge_hash_multimap & /*x*/)
155{
156 std::ostringstream ss;
157 ss << "[";
158 ss << "]";
159 return ss.str();
160}
161#endif
162
163static std::string toStringForRTI(const rose_graph_integer_node_hash_map & /*x*/)
164{
165 std::ostringstream ss;
166 ss << "[";
167 ss << "]";
168 return ss.str();
169}
170
171static std::string toStringForRTI(const rose_graph_integer_edge_hash_map & /*x*/)
172{
173 std::ostringstream ss;
174 ss << "[";
175 ss << "]";
176 return ss.str();
177}
178
179static std::string toStringForRTI(const rose_graph_integer_edge_hash_multimap & /*x*/)
180{
181 std::ostringstream ss;
182 ss << "[";
183 ss << "]";
184 return ss.str();
185}
186
187static std::string toStringForRTI(const rose_graph_string_integer_hash_multimap & /*x*/)
188{
189 std::ostringstream ss;
190 ss << "[";
191 ss << "]";
192 return ss.str();
193}
194
195static std::string toStringForRTI(const rose_graph_integerpair_edge_hash_multimap & /*x*/)
196{
197 std::ostringstream ss;
198 ss << "[";
199 ss << "]";
200 return ss.str();
201}
202
203#ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
204static std::string toStringForRTI(const rose_graph_hash_multimap & /*x*/)
205{
206 std::ostringstream ss;
207 ss << "[";
208 ss << "]";
209 return ss.str();
210}
211#endif
212
213static std::string toStringForRTI(const SgAccessModifier& m) {
214 return m.displayString();
215}
216
217static std::string toStringForRTI(const SgUPC_AccessModifier& m) {
218 return m.displayString();
219}
220
221static std::string toStringForRTI(const SgConstVolatileModifier& m) {
222 return m.displayString();
223}
224
225static std::string toStringForRTI(const SgElaboratedTypeModifier& m) {
226 return m.displayString();
227}
228
229static std::string toStringForRTI(const SgTypeModifier& m) {
230 return m.displayString();
231}
232
233static std::string toStringForRTI(const SgStorageModifier& m) {
234 return m.displayString();
235}
236
237static std::string toStringForRTI(const SgDeclarationModifier& m) {
238 return m.displayString();
239}
240
241static std::string toStringForRTI(const SgFunctionModifier& m) {
242 return m.displayString();
243}
244
245static std::string toStringForRTI(const SgSpecialFunctionModifier& m) {
246 return m.displayString();
247}
248
249static std::string toStringForRTI(const SgName& n) {
250 return n.getString();
251}
252
253static std::string toStringForRTI(const SgFunctionModifier::opencl_work_group_size_t & x) {
254 std::ostringstream os;
255 os << " ( " << x.x << ", " << x.y << ", " << x.z << " ) ";
256 return os.str();
257}
258
259// For scoped enumerations from ROSETTA
260static std::string toStringForRTI(SgJovialTableStatement::WordsPerEntry &e) {
261 return std::to_string(static_cast<int>(e));
262}
263static std::string toStringForRTI(SgJovialTableType::StructureSpecifier &e) {
264 return std::to_string(static_cast<int>(e));
265}
266#ifdef ROSE_ENABLE_BINARY_ANALYSIS
267static std::string toStringForRTI(Rose::BinaryAnalysis::JvmInstructionKind &e) {
268 std::ostringstream os;
269 Rose::BinaryAnalysis::JvmInstructionKind kind = Rose::BinaryAnalysis::JvmInstructionKind::nop;
270 int intKind = static_cast<int>(kind);
271 os << intKind;
272 return std::to_string(static_cast<int>(e));
273}
274#endif
275
276void 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);
277
278#endif // ROSE_RTIHELPERS_H
Access to C++ Run Time Information (RTI)
Definition sageRti.h:16
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.