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