@@ -43,19 +43,80 @@ enum class idt:unsigned
43
43
#include " irep_ids.def" // NOLINT(build/include)
44
44
};
45
45
46
+ class irep_idt final :public dstringt
47
+ {
48
+ public:
49
+ // this is safe for static objects
50
+ #ifdef __GNUC__
51
+ constexpr
52
+ #endif
53
+ irep_idt ():dstringt()
54
+ {
55
+ }
56
+
57
+ // this is safe for static objects
58
+ #ifdef __GNUC__
59
+ constexpr
60
+ #endif
61
+ static irep_idt make_from_table_index (unsigned no)
62
+ {
63
+ return irep_idt (no);
64
+ }
65
+
66
+ #ifdef __GNUC__
67
+ // This conversion allows the use of irep_idts
68
+ // in switch ... case statements.
69
+ constexpr operator idt () const { return static_cast <idt>(no); }
70
+ #endif
71
+
72
+ // this one is not safe for static objects
73
+ // NOLINTNEXTLINE(runtime/explicit)
74
+ irep_idt (const char *s):dstringt(s)
75
+ {
76
+ }
77
+
78
+ // this one is not safe for static objects
79
+ // NOLINTNEXTLINE(runtime/explicit)
80
+ irep_idt (const std::string &s):dstringt(s)
81
+ {
82
+ }
83
+
84
+ protected:
85
+ #ifdef __GNUC__
86
+ constexpr
87
+ #endif
88
+ explicit irep_idt (unsigned _no):dstringt(_no)
89
+ {
90
+ }
91
+ };
92
+
93
+ // NOLINTNEXTLINE [allow specialisation within 'std']
94
+ namespace std
95
+ {
96
+ // / Default hash function of `dstringt` for use with STL containers.
97
+ template <>
98
+ struct hash <irep_idt> // NOLINT(readability/identifiers)
99
+ {
100
+ size_t operator ()(const irep_idt &irep_id) const
101
+ {
102
+ return irep_id.hash ();
103
+ }
104
+ };
105
+ }
106
+
46
107
#ifdef __GNUC__
47
108
#define IREP_ID_ONE (the_id ) \
48
- constexpr dstringt ID_##the_id=dstringt ::make_from_table_index( \
109
+ constexpr irep_idt ID_##the_id=irep_idt ::make_from_table_index( \
49
110
static_cast <unsigned >(idt::id_##the_id));
50
111
#define IREP_ID_TWO (the_id, str ) \
51
- constexpr dstringt ID_##the_id=dstringt ::make_from_table_index( \
112
+ constexpr irep_idt ID_##the_id=irep_idt ::make_from_table_index( \
52
113
static_cast <unsigned >(idt::id_##the_id));
53
114
#else
54
115
#define IREP_ID_ONE (the_id ) \
55
- const dstringt ID_##the_id=dstringt ::make_from_table_index( \
116
+ const irep_idt ID_##the_id=irep_idt ::make_from_table_index( \
56
117
static_cast <unsigned >(idt::id_##the_id));
57
118
#define IREP_ID_TWO (the_id, str ) \
58
- const const dstringt ID_##the_id=dstringt ::make_from_table_index( \
119
+ const const irep_idt ID_##the_id=irep_idt ::make_from_table_index( \
59
120
static_cast <unsigned >(idt::id_##the_id));
60
121
#endif
61
122
0 commit comments