ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rtiHelpers.h
Go to the documentation of this file.
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 template <typename T>
35 static std::string toStringForRTI(const std::vector<T>& x) {
36  std::ostringstream ss;
37  ss << "[";
38  for (typename std::vector<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
39  ss << "]";
40  return ss.str();
41 }
42 
43 // DQ (8/8/2008): Added support for type used in binary file format support.
44 template <typename T>
45 static std::string toStringForRTI(const std::vector<std::pair<T,T> >& x) {
46  std::ostringstream ss;
47  ss << "[";
48  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;}
49  ss << "]";
50  return ss.str();
51 }
52 
53 static std::string toStringForRTI(const ExtentMap &x)
54 {
55  std::ostringstream ss;
56  ss << "[";
57  for (ExtentMap::const_iterator i=x.begin(); i!=x.end(); ++i) {
58  if (i!=x.begin())
59  ss << ", ";
60  ss << i->first << "->" << i->second;
61  }
62  ss <<"]";
63  return ss.str();
64 }
65 
66 // DQ (8/29/2008): Added the support for the Robb's SgSharedVector class.
67 template <typename T>
68 static std::string toStringForRTI(const SgSharedVector<T>& x)
69  {
70  std::ostringstream ss;
71  ss << "[";
72 
73  printf ("Warning: SgSharedVector iterator support is not finished! \n");
74  // ROSE_ASSERT(false);
75 
76  // for (typename std::vector<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
77 
78  ss << "]";
79  return ss.str();
80  }
81 
82 static std::string toStringForRTI(const std::vector<bool>& x) {
83  std::ostringstream ss;
84  ss << "[";
85  for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
86  ss << "]";
87  return ss.str();
88 }
89 
90 template <typename T>
91 static std::string toStringForRTI(const std::list<T>& x) {
92  std::ostringstream ss;
93  ss << "[";
94  for (typename std::list<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
95  ss << "]";
96  return ss.str();
97 }
98 
99 template <typename T>
100 static std::string toStringForRTI(const std::set<T>& x) {
101  std::ostringstream ss;
102  ss << "[";
103  for (typename std::set<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
104  ss << "]";
105  return ss.str();
106 }
107 
108 template <typename K, typename V>
109 static std::string toStringForRTI(const std::map<K, V>& x) {
110  std::ostringstream ss;
111  ss << "[";
112  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);}
113  ss << "]";
114  return ss.str();
115 }
116 
117 // negara1 (06/27/2011): Added support for the map of including files (field p_preprocessorDirectivesAndCommentsList)
118 template <typename K>
119 static std::string toStringForRTI(const std::map<K, std::set<PreprocessingInfo*> >& x) {
120  std::ostringstream ss;
121  ss << "[";
122  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);}
123  ss << "]";
124  return ss.str();
125 }
126 
127 // DQ (4/30/2009): Added new support for std::multimap.
128 template <typename K, typename V>
129 static std::string toStringForRTI(const std::multimap<K, V>& x) {
130  std::ostringstream ss;
131  ss << "[";
132  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;}
133  ss << "]";
134  return ss.str();
135 }
136 
137 #if 0
138 static std::string toStringForRTI(const std::map<std::pair<int,std::pair<int,int> >, uint64_t > & x) {
139  std::ostringstream ss;
140  ss << "[";
141 // for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
142  ss << "]";
143  return ss.str();
144 }
145 #endif
146 
147 #if 0
148 static std::string toStringForRTI(const std::map<uint64_t ,std::pair<int,std::pair<int,int> > > & x) {
149  std::ostringstream ss;
150  ss << "[";
151 // for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
152  ss << "]";
153  return ss.str();
154 }
155 #endif
156 
157 #if 1
158 // #if !OLD_GRAPH_NODES
159 //#ifdef ROSE_USE_NEW_GRAPH_NODES
160 // DQ (8/18/2008): Added support for new Graph IR node.
161 
162 #ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
163 // static std::string toStringForRTI(const SgGraphNodeDirectedGraphEdgeMultimapPtrList & x)
164 static std::string toStringForRTI(const rose_graph_node_edge_hash_multimap & x)
165 {
166  std::ostringstream ss;
167  ss << "[";
168 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
169  ss << "]";
170  return ss.str();
171 }
172 #endif
173 
175 {
176  std::ostringstream ss;
177  ss << "[";
178 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
179  ss << "]";
180  return ss.str();
181 }
182 
184 {
185  std::ostringstream ss;
186  ss << "[";
187 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
188  ss << "]";
189  return ss.str();
190 }
191 
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 
202 {
203  std::ostringstream ss;
204  ss << "[";
205 // 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;}
206  ss << "]";
207  return ss.str();
208 }
209 
211 {
212  std::ostringstream ss;
213  ss << "[";
214 // 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;}
215  ss << "]";
216  return ss.str();
217 }
218 
219 #if 0
220 // DQ (4/30/2009): Removed these in favor of the hash_multimap using the SgGraphEdge class.
221 static std::string toStringForRTI(const rose_undirected_graph_hash_multimap & x)
222 {
223  std::ostringstream ss;
224  ss << "[";
225 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::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 #endif
230 
231 #if 0
232 // DQ (4/30/2009): Removed these in favor of the hash_multimap using the SgGraphEdge class.
233 static std::string toStringForRTI(const rose_directed_graph_hash_multimap & x)
234 {
235  std::ostringstream ss;
236  ss << "[";
237 // for (SgGraphNodeDirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
238  ss << "]";
239  return ss.str();
240 }
241 #endif
242 
243 #ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
244 // DQ (8/18/2008): Added support for new Graph IR node.
245 // static std::string toStringForRTI(const SgStringGraphNodeMapPtrList & x)
246 static std::string toStringForRTI(const rose_graph_hash_multimap & x)
247 {
248  std::ostringstream ss;
249  ss << "[";
250 // for (SgStringGraphNodeMapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
251  ss << "]";
252  return ss.str();
253 }
254 #endif
255 
256 #if 0
257 // DQ (5/1/2009): This is no longer used and is replaced by an implementation using a hash_map.
258 // DQ (8/18/2008): Added support for new Graph IR node.
259 // static std::string toStringForRTI(const SgIntegerGraphNodeMapPtrList & x)
260 static std::string toStringForRTI(const std::map<int, SgGraphNode*> & x)
261 {
262  std::ostringstream ss;
263  ss << "[";
264 // for (SgIntegerGraphNodeMapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
265  for (std::map<int, SgGraphNode*>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
266  ss << "]";
267  return ss.str();
268 }
269 #endif
270 
271 #if 0
272 // DQ (4/25/2009): This is now redundant...
273 // DQ (8/18/2008): Added support for new Graph IR node.
274 // static std::string toStringForRTI(const SgGraphNodeUndirectedGraphEdgeMultimapPtrList & x)
275 static std::string toStringForRTI(const rose_undirected_graph_hash_multimap & x)
276 {
277  std::ostringstream ss;
278  ss << "[";
279 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
280  ss << "]";
281  return ss.str();
282 }
283 #endif
284 #endif
285 //#endif
286 // end condition new_graph
287 
288 static std::string toStringForRTI(const SgAccessModifier& m) {
289  return m.displayString();
290 }
291 
292 static std::string toStringForRTI(const SgUPC_AccessModifier& m) {
293  return m.displayString();
294 }
295 
296 static std::string toStringForRTI(const SgConstVolatileModifier& m) {
297  return m.displayString();
298 }
299 
300 static std::string toStringForRTI(const SgElaboratedTypeModifier& m) {
301  return m.displayString();
302 }
303 
304 static std::string toStringForRTI(const SgTypeModifier& m) {
305  return m.displayString();
306 }
307 
308 static std::string toStringForRTI(const SgStorageModifier& m) {
309  return m.displayString();
310 }
311 
312 static std::string toStringForRTI(const SgDeclarationModifier& m) {
313  return m.displayString();
314 }
315 
316 static std::string toStringForRTI(const SgFunctionModifier& m) {
317  return m.displayString();
318 }
319 
320 static std::string toStringForRTI(const SgSpecialFunctionModifier& m) {
321  return m.displayString();
322 }
323 
324 static std::string toStringForRTI(const SgName& n) {
325  return n.getString();
326 }
327 
329  std::ostringstream os;
330  os << " ( " << x.x << ", " << x.y << ", " << x.z << " ) ";
331  return os.str();
332 }
333 
334 #if 0
335 // None of these seem to be used
336 
337 template <typename Sym>
338 static std::string toStringForRTISymbol(Sym* sym) {
339  std::ostringstream ss;
340  ss << sym;
341  if (sym) {
342  ss << ": varsym " << sym->get_name().str() << " declared at 0x" << std::hex << (sym->get_declaration());
343  }
344  return ss.str();
345 }
346 
347 static std::string toStringForRTI(SgVariableSymbol* sym) {return toStringForRTISymbol(sym);}
348 static std::string toStringForRTI(SgFunctionSymbol* sym) {return toStringForRTISymbol(sym);}
349 static std::string toStringForRTI(SgMemberFunctionSymbol* sym) {return toStringForRTISymbol(sym);}
350 
351 static std::string toStringForRTI(const SgSymbolTable&) {return "<no output operator defined for this type>";}
352 static std::string toStringForRTI(const SgSymbolHashBase::iterator&) {return "<no output operator defined for this type>";}
353 #endif
354 
355 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);
356 
357 #endif // ROSE_RTIHELPERS_H