cprover
xml_irep_hashing.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: XML-irep conversions with hashing
4 
5 Author: CM Wintersteiger
6 
7 Date: July 2006
8 
9 \*******************************************************************/
10 
13 
14 #ifndef CPROVER_GOTO_CC_XML_BINARIES_XML_IREP_HASHING_H
15 #define CPROVER_GOTO_CC_XML_BINARIES_XML_IREP_HASHING_H
16 
17 #include <util/xml.h>
18 #include <util/irep.h>
19 
21 {
22 private:
23  // NOLINTNEXTLINE(readability/identifiers)
24  struct ul_hash
25  {
26  unsigned short operator()(const unsigned long l) const
27  {
28  return (l &0xFFFF);
29  }
30  };
31 
32  // NOLINTNEXTLINE(readability/identifiers)
33  struct ul_eq
34  {
35  bool operator()(const unsigned long l, const unsigned long r) const
36  {
37  return (l==r);
38  }
39  };
40 
41  // NOLINTNEXTLINE(readability/identifiers)
43  {
44  size_t operator()(const irept &i) const
45  {
46  return i.full_hash();
47  }
48  };
49 
50  // NOLINTNEXTLINE(readability/identifiers)
52  {
53  bool operator()(const irept &l, const irept &r) const
54  {
55  return l.full_eq(l, r);
56  }
57  };
58 
59 public:
61  {
62  typedef std::unordered_map<unsigned long, irept, ul_hash, ul_eq>
65 
66  typedef std::unordered_map<irept, unsigned long,
70 
71  typedef std::map<unsigned, unsigned> id_replace_mapt;
73 
74  void clear()
75  {
76  id_container.clear();
77  content_container.clear();
78  id_replace_map.clear();
79  }
80  };
81 
83  {
84  };
85 
86  unsigned long insert(unsigned long, const irept&);
87  unsigned long insert(const std::string&, const irept&);
88 
89  void convert(const irept &irep, xmlt &xml);
90  void convert(const xmlt &xml, irept &irep);
91  void reference_convert(const irept &irep, xmlt &xml);
92  void resolve_references(const irept &cur);
93 
94  void convert_map(xmlt &xml);
95  void output_map(std::ostream &out, unsigned indent);
96 
97  void clear()
98  {
100  }
101 
102 private:
104 
105  ireps_containert::id_containert::const_iterator
106  find_irep_by_id(const unsigned int);
107  ireps_containert::content_containert::const_iterator
108  find_irep_by_content(const irept &irep);
109 
110  std::string long_to_string(const unsigned long);
111  unsigned long string_to_long(const std::string &);
112 
113  unsigned long add_with_childs(const irept&);
114 };
115 
116 #endif // CPROVER_GOTO_CC_XML_BINARIES_XML_IREP_HASHING_H
static int8_t r
Definition: irep_hash.h:59
unsigned long string_to_long(const std::string &)
converts the string to an unsigned long that used to give a pointer to an irep in an old compilation ...
ireps_containert::content_containert::const_iterator find_irep_by_content(const irept &irep)
finds an irep in the ireps hash set by checking contents
std::unordered_map< irept, unsigned long, irep_full_hash, irep_content_eq > content_containert
bool full_eq(const irept &other) const
Definition: irep.cpp:380
void convert_map(xmlt &xml)
converts the current hash map of ireps into the given xml structure
unsigned short operator()(const unsigned long l) const
ireps_containert::id_containert::const_iterator find_irep_by_id(const unsigned int)
finds an irep in the ireps hash set by its id
void reference_convert(const irept &irep, xmlt &xml)
xmlt xml(const source_locationt &location)
Definition: xml_expr.cpp:25
ireps_containert & ireps_container
bool operator()(const unsigned long l, const unsigned long r) const
void resolve_references(const irept &cur)
resolves references to ireps from an irep after reading an irep hash map into memory.
void convert(const irept &irep, xmlt &xml)
bool operator()(const irept &l, const irept &r) const
Definition: xml.h:18
Base class for tree-like data structures with sharing.
Definition: irep.h:87
size_t operator()(const irept &i) const
std::unordered_map< unsigned long, irept, ul_hash, ul_eq > id_containert
unsigned long insert(unsigned long, const irept &)
inserts an irep into the hashtable
xml_irep_convertt(ireps_containert &ic)
std::size_t full_hash() const
Definition: irep.cpp:606
unsigned long add_with_childs(const irept &)
std::string long_to_string(const unsigned long)
converts the hash value to a readable string
std::map< unsigned, unsigned > id_replace_mapt
void output_map(std::ostream &out, unsigned indent)
converts the current hash map of ireps into xml nodes and outputs them to the stream ...