ROSE 0.11.145.247
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 K, typename V>
107static std::string toStringForRTI(const std::map<K, V>& x) {
108 std::ostringstream ss;
109 ss << "[";
110 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);}
111 ss << "]";
112 return ss.str();
113}
114
115template <typename K>
116static std::string toStringForRTI(const std::map<K, std::set<PreprocessingInfo*> >& x) {
117 std::ostringstream ss;
118 ss << "[";
119 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);}
120 ss << "]";
121 return ss.str();
122}
123
124template <typename K, typename V>
125static std::string toStringForRTI(const std::multimap<K, V>& x) {
126 std::ostringstream ss;
127 ss << "[";
128 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;}
129 ss << "]";
130 return ss.str();
131}
132
133#ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
134static std::string toStringForRTI(const rose_graph_node_edge_hash_multimap & /*x*/)
135{
136 std::ostringstream ss;
137 ss << "[";
138 ss << "]";
139 return ss.str();
140}
141#endif
142
143static std::string toStringForRTI(const rose_graph_integer_node_hash_map & /*x*/)
144{
145 std::ostringstream ss;
146 ss << "[";
147 ss << "]";
148 return ss.str();
149}
150
151static std::string toStringForRTI(const rose_graph_integer_edge_hash_map & /*x*/)
152{
153 std::ostringstream ss;
154 ss << "[";
155 ss << "]";
156 return ss.str();
157}
158
159static std::string toStringForRTI(const rose_graph_integer_edge_hash_multimap & /*x*/)
160{
161 std::ostringstream ss;
162 ss << "[";
163 ss << "]";
164 return ss.str();
165}
166
167static std::string toStringForRTI(const rose_graph_string_integer_hash_multimap & /*x*/)
168{
169 std::ostringstream ss;
170 ss << "[";
171 ss << "]";
172 return ss.str();
173}
174
175static std::string toStringForRTI(const rose_graph_integerpair_edge_hash_multimap & /*x*/)
176{
177 std::ostringstream ss;
178 ss << "[";
179 ss << "]";
180 return ss.str();
181}
182
183#ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
184static std::string toStringForRTI(const rose_graph_hash_multimap & /*x*/)
185{
186 std::ostringstream ss;
187 ss << "[";
188 ss << "]";
189 return ss.str();
190}
191#endif
192
193static std::string toStringForRTI(const SgAccessModifier& m) {
194 return m.displayString();
195}
196
197static std::string toStringForRTI(const SgUPC_AccessModifier& m) {
198 return m.displayString();
199}
200
201static std::string toStringForRTI(const SgConstVolatileModifier& m) {
202 return m.displayString();
203}
204
205static std::string toStringForRTI(const SgElaboratedTypeModifier& m) {
206 return m.displayString();
207}
208
209static std::string toStringForRTI(const SgTypeModifier& m) {
210 return m.displayString();
211}
212
213static std::string toStringForRTI(const SgStorageModifier& m) {
214 return m.displayString();
215}
216
217static std::string toStringForRTI(const SgDeclarationModifier& m) {
218 return m.displayString();
219}
220
221static std::string toStringForRTI(const SgFunctionModifier& m) {
222 return m.displayString();
223}
224
225static std::string toStringForRTI(const SgSpecialFunctionModifier& m) {
226 return m.displayString();
227}
228
229static std::string toStringForRTI(const SgName& n) {
230 return n.getString();
231}
232
233static std::string toStringForRTI(const SgFunctionModifier::opencl_work_group_size_t & x) {
234 std::ostringstream os;
235 os << " ( " << x.x << ", " << x.y << ", " << x.z << " ) ";
236 return os.str();
237}
238
239// For scoped enumerations from ROSETTA
240static std::string toStringForRTI(SgJovialTableStatement::WordsPerEntry &e) {
241 return std::to_string(static_cast<int>(e));
242}
243static std::string toStringForRTI(SgJovialTableType::StructureSpecifier &e) {
244 return std::to_string(static_cast<int>(e));
245}
246#ifdef ROSE_ENABLE_BINARY_ANALYSIS
247static std::string toStringForRTI(Rose::BinaryAnalysis::JvmInstructionKind &e) {
248 std::ostringstream os;
249 Rose::BinaryAnalysis::JvmInstructionKind kind = Rose::BinaryAnalysis::JvmInstructionKind::nop;
250 int intKind = static_cast<int>(kind);
251 os << intKind;
252 return std::to_string(static_cast<int>(e));
253}
254#endif
255
256void 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);
257
258#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.