ROSE 0.11.145.147
sageHash.h
1// [Robb Matzke 2024-03-12]: This was copied here from src/ROSETTA/Grammar/Node.code because it doesn't need to be generated by
2// ROSETTA since it doesn't depend on any of the CxxGrammarMetaProgram inputs.
3#ifndef ROSE_sageHash_H
4#define ROSE_sageHash_H
5#include <RoseFirst.h>
6
7#include <boost/unordered_map.hpp>
8#include <boost/unordered_set.hpp>
9
10template<class T>
11class EasyStorage;
12
13// DQ (11/4/2009): Trying to use the boost hash_map support
14namespace rose_hash
15 {
16 // The condition here is not needed for GCC 4.2, but is needed (and does not completely work) for earlier versions
17 using boost::unordered_map;
18 using boost::unordered_multimap;
19 using boost::unordered_set;
20 using boost::hash;
21
22 // DQ (4/23/2009): These should be put into this namespace so that we don't contaminate the global scope.
23 // DQ (8/19/2008): This is already defined in src/frontend/SageIII/astMerge/buildMangledNameMap.h
25 {
26 bool operator()(const std::string & s1, const std::string & s2) const
27 {
28 return s1 == s2;
29 }
30 };
31
35 {
36 // tps (11/17/2009) : Changed this so that it works under Windows.
37 // CH (4/9/2010): Use boost::hash instead
38 size_t operator()(const int n) const
39 {
40 return n;
41 }
42 };
43
45 {
46 // tps (11/17/2009) : Changed this so that it works under Windows.
47 // CH (4/9/2010): Use boost::hash instead
48 size_t operator()(const std::pair<int,int> & p) const
49 {
50 // DQ (4/30/2009): This subject should be reviewed!
51 // Since this is a hash function, it might not a problem if we have
52 // overflow (also the values should not be so large as to be a problem).
53 return p.first+p.second;
54 }
55 };
56
57 // DQ (4/30/2009): This might already exist for std::pair<>
59 {
60 bool operator()(const std::pair<int,int> & p1, const std::pair<int,int> & p2) const
61 {
62 return (p1.first == p2.first) && (p1.second == p2.second);
63 }
64 };
65
67 {
68 bool operator()(const SgGraphNode* p1, const SgGraphNode* p2) const
69 {
70 return p1 == p2;
71 }
72 };
73
75 {
76 bool operator()(const SgGraphNode* p1, const SgGraphNode* p2) const
77 {
78 return p1 == p2;
79 }
80 };
81
83 {
84 // tps (11/17/2009) : Changed this so that it works under Windows.
85 // CH (4/9/2010): Use boost::hash instead
86 size_t operator()(const SgGraphNode* ptr) const
87 {
88 return (size_t) ptr;
89 }
90 };
91 }
92
93
97// DQ (8/19/2008): Note that "rose_hash" is a namespace defined above.
98// class rose_hash_multimap : public rose_hash::unordered_multimap<SgName, SgSymbol*, hash_Name, eqstr>
99// tps (11/18/2009) : This cannot be correct since the constructor takes a string not an int.
100// CH (4/9/2010): Use boost::unordered instead
101typedef rose_hash::unordered_multimap<std::string, SgGraphNode*> rose_graph_string_node_hash_multimap_base_type;
102
103class rose_graph_string_node_hash_multimap : public rose_graph_string_node_hash_multimap_base_type
104 {
105 // Need to document why we are using hash_multimap type here. Why a hash (obvious), then why a multimap?
106 // I think a multimap is used to support having no names on the nodes if they are unlabeled. If the
107 // nodes are labled then operations on the labled edges are possible using the multimap. But is there
108 // a performance trade-off for these choices?
109
110 protected:
111
112 // DQ (4/25/2009): We need to change this name since I think we just want the
113 // associated IR node in the AST, and not any concept of parent in the graph.
114 SgNode* parent;
115
116 public:
118 : rose_graph_string_node_hash_multimap_base_type(), parent(nullptr)
119 {}
120 // tps (11/18/2009) : This cannot be correct since the constructor takes a string not an int.
122 : rose_graph_string_node_hash_multimap_base_type(rhs),parent(rhs.parent)
123 {}
124 // See note (above) about name change to the associated data member for these access functions.
125 void set_parent(SgNode * new_parent)
126 {
127 parent = new_parent;
128 }
129 SgNode * get_parent()
130 {
131 return parent;
132 }
133
134 void delete_elements()
135 {
136 }
137
139 {
140 delete_elements();
141
142 parent = nullptr;
143 }
144
145
146 friend class AST_FILE_IO;
147 friend class SgSymbolTableStorageClass;
149 };
150
151std::ostream & operator<< ( std::ostream & os, const rose_graph_string_node_hash_multimap::iterator & rhm_it );
152
153// DQ (5/1/2009): Temporary typedef to use older name for compatability.
155
156
157
163// DQ (4/29/2009): Added to support ROSE Graph IR nodes
164// tps (11/18/2009) : This cannot be correct since the constructor takes a string not an int.
165// CH (4/9/2010): Use boost::unordered instead
166typedef rose_hash::unordered_multimap<SgGraphNode*, SgGraphEdge*, rose_hash::hash_graph_node, rose_hash::eqstr_graph_node> rose_graph_node_edge_hash_multimap_base_type;
167class rose_graph_node_edge_hash_multimap : public rose_graph_node_edge_hash_multimap_base_type
168 {
169 // This class is used to map nodes to edges in the highest level graph class.
170 // Different graph classes derived from the SgGraph class contain additional
171 // maps that contain specific types of edges.
172
173 protected:
174 SgNode * parent;
175
176 public:
178 : rose_graph_node_edge_hash_multimap_base_type()
179 {}
180 // tps (11/18/2009) : This cannot be correct since the constructor takes a string not an int.
182 // DQ (4/30/2009): This fixed a problem reported by Thomas Panas relative to seg-faults when using the copy constructor (forced his code to use references).
183 // : rose_hash::unordered_multimap<SgGraphNode*, SgGraphEdge*, rose_hash::hash_graph_node, rose_hash::eqstr_graph_node>((rose_graph_node_edge_hash_multimap)rhs)
184 : rose_graph_node_edge_hash_multimap_base_type(rhs),parent(rhs.parent)
185 {}
186
187 void set_parent(SgNode * new_parent)
188 {
189 parent = new_parent;
190 }
191 SgNode * get_parent()
192 {
193 return parent;
194 }
195
196 void delete_elements()
197 {
198 }
199
201 {
202 delete_elements();
203 }
204
205 friend class AST_FILE_IO;
206 friend class SgSymbolTableStorageClass;
208 };
209
210std::ostream & operator<< ( std::ostream & os, const rose_graph_node_edge_hash_multimap::iterator & rhm_it );
211
212
216// DQ (4/30/2009): Added to support more of the Graph functionality in new ROSE IR nodes
217// typedef rose_hash::unordered_map<int,SgGraphNode*, rose_hash::hash_integer, rose_hash::eqstr_graph_node> rose_graph_integer_node_hash_map_base_type
218// CH (4/9/2010): Use boost::unordered instead
219typedef rose_hash::unordered_map<int, SgGraphNode*, rose_hash::hash_integer> rose_graph_integer_node_hash_map_base_type;
220class rose_graph_integer_node_hash_map : public rose_graph_integer_node_hash_map_base_type
221 {
222 protected:
223 // I think this is required by the AST file I/O support.
224 SgNode * parent;
225
226 public:
228 : rose_graph_integer_node_hash_map_base_type()
229 {}
230// tps (11/18/2009) : Is this constructor wrong? Should it be a pair of (int,SgGraphNode)?
232 : rose_graph_integer_node_hash_map_base_type(rhs),parent(rhs.parent)
233 {}
234
235 void set_parent(SgNode * new_parent)
236 {
237 parent = new_parent;
238 }
239 SgNode * get_parent()
240 {
241 return parent;
242 }
243
244 void delete_elements()
245 {
246 }
247
249 {
250 delete_elements();
251 }
252
253 friend class AST_FILE_IO;
254 friend class SgSymbolTableStorageClass;
256 };
257
258std::ostream & operator<< ( std::ostream & os, const rose_graph_integer_node_hash_map::iterator & rhm_it );
259
260
261
265// DQ (4/30/2009): Added to support more of the Graph functionality in new ROSE IR nodes
266// typedef rose_hash::unordered_map<int,SgGraphEdge*, rose_hash::hash_integer, rose_hash::eqstr_graph_edge> rose_graph_integer_edge_hash_map_base_type;
267// CH (4/9/2010): Use boost::unordered instead
268typedef rose_hash::unordered_map<int,SgGraphEdge*, rose_hash::hash_integer> rose_graph_integer_edge_hash_map_base_type;
269class rose_graph_integer_edge_hash_map : public rose_graph_integer_edge_hash_map_base_type
270 {
271 // This class is used to map nodes to edges in the highest level graph class.
272 // Different graph classes derived from the SgGraph class contain additional
273 // maps that contain specific types of edges.
274
275 protected:
276 // I think this is required by the AST file I/O support.
277 SgNode * parent;
278
279 public:
281 : rose_graph_integer_edge_hash_map_base_type()
282 {}
284 : rose_graph_integer_edge_hash_map_base_type(rhs),parent(rhs.parent)
285 {}
286
287 void set_parent(SgNode * new_parent)
288 {
289 parent = new_parent;
290 }
291 SgNode * get_parent()
292 {
293 return parent;
294 }
295
296 void delete_elements()
297 {
298 }
299
301 {
302 delete_elements();
303 }
304
305 friend class AST_FILE_IO;
306 friend class SgSymbolTableStorageClass;
308 };
309
310std::ostream & operator<< ( std::ostream & os, const rose_graph_integer_edge_hash_map::iterator & rhm_it );
311
312
313
317// DQ (4/30/2009): Added to support more of the Graph functionality in new ROSE IR nodes
318// typedef rose_hash::unordered_map<int,SgGraphEdge*, rose_hash::hash_integer, rose_hash::eqstr_graph_edge> rose_graph_integer_edge_hash_multimap_base_type;
319
320typedef rose_hash::unordered_multimap<int,SgGraphEdge*> rose_graph_integer_edge_hash_multimap_base_type;
321class rose_graph_integer_edge_hash_multimap : public rose_graph_integer_edge_hash_multimap_base_type
322 {
323 // This class is used to map nodes to edges in the highest level graph class.
324 // Different graph classes derived from the SgGraph class contain additional
325 // maps that contain specific types of edges.
326
327 protected:
328 // I think this is required by the AST file I/O support.
329 SgNode * parent;
330
331 public:
333 : rose_graph_integer_edge_hash_multimap_base_type()
334 {}
336 : rose_graph_integer_edge_hash_multimap_base_type(rhs),parent(rhs.parent)
337 {}
338
339 void set_parent(SgNode * new_parent)
340 {
341 parent = new_parent;
342 }
343 SgNode * get_parent()
344 {
345 return parent;
346 }
347
348 void delete_elements()
349 {
350 }
351
353 {
354 delete_elements();
355 }
356
357 friend class AST_FILE_IO;
358 friend class SgSymbolTableStorageClass;
360 };
361
362std::ostream & operator<< ( std::ostream & os, const rose_graph_integer_edge_hash_multimap::iterator & rhm_it );
363
364
365
368typedef rose_hash::unordered_multimap<std::pair<int,int>,SgGraphEdge*, rose_hash::hash_integer_pair> rose_graph_integerpair_edge_hash_multimap_base_type;
369class rose_graph_integerpair_edge_hash_multimap : public rose_graph_integerpair_edge_hash_multimap_base_type
370 {
371 // This class is used to map nodes to edges in the highest level graph class.
372 // Different graph classes derived from the SgGraph class contain additional
373 // maps that contain specific types of edges.
374
375 protected:
376 // I think this is required by the AST file I/O support.
377 SgNode * parent;
378
379 public:
381 : rose_graph_integerpair_edge_hash_multimap_base_type()
382 {}
384 : rose_graph_integerpair_edge_hash_multimap_base_type(rhs),parent(rhs.parent)
385 {}
386
387 void set_parent(SgNode * new_parent)
388 {
389 parent = new_parent;
390 }
391 SgNode * get_parent()
392 {
393 return parent;
394 }
395
396 void delete_elements()
397 {
398 }
399
401 {
402 delete_elements();
403 }
404
405 friend class AST_FILE_IO;
406 friend class SgSymbolTableStorageClass;
408 };
409
410std::ostream & operator<< ( std::ostream & os, const rose_graph_integerpair_edge_hash_multimap::iterator & rhm_it );
411
412
413
417// DQ (5/1/2009): This is added to support lookup of indexes based on labels (can be used for nodes or edges).
418// tps (11/18/2009) : This cannot be correct since the constructor takes a string not an int.
419// CH (4/9/2010): Use boost::unordered instead
420typedef rose_hash::unordered_multimap<std::string, int> rose_graph_string_integer_hash_multimap_base_type;
421class rose_graph_string_integer_hash_multimap : public rose_graph_string_integer_hash_multimap_base_type
422 {
423 protected:
424 // DQ (4/25/2009): We need to change this name since I think we just want the
425 // associated IR node in the AST, and not any concept of parent in the graph.
426 SgNode* parent;
427
428 public:
430 : rose_graph_string_integer_hash_multimap_base_type(), parent(nullptr)
431 {}
433 : rose_graph_string_integer_hash_multimap_base_type(rhs),parent(rhs.parent)
434 {}
435
436 // See note (above) about name change to the associated data member for these access functions.
437 void set_parent(SgNode * new_parent)
438 {
439 parent = new_parent;
440 }
441 SgNode * get_parent()
442 {
443 return parent;
444 }
445
446 void delete_elements()
447 {
448 }
449
451 {
452 delete_elements();
453
454 parent = nullptr;
455 }
456
457 friend class AST_FILE_IO;
458 friend class SgSymbolTableStorageClass;
460 };
461
462std::ostream & operator<< ( std::ostream & os, const rose_graph_string_integer_hash_multimap::iterator & rhm_it );
463
464#endif
Class holding static data and functions supporting File I/O.
Definition AST_FILE_IO.h:19
This class represents the base class for all IR nodes within Sage III.
Hash name support for symbol tables within ROSE.
Definition sageHash.h:35