@@ -44,20 +44,96 @@ 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
+ // NOLINTNEXTLINE(runtime/explicit)
80
+ #ifdef __GNUC__
81
+ constexpr
82
+ #endif
83
+ irep_idt (dstringt s) : dstringt(s)
84
+ {
85
+ }
86
+
87
+ // this one is not safe for static objects
88
+ // NOLINTNEXTLINE(runtime/explicit)
89
+ irep_idt (const char *s) : dstringt(s)
90
+ {
91
+ }
92
+
93
+ // this one is not safe for static objects
94
+ // NOLINTNEXTLINE(runtime/explicit)
95
+ irep_idt (const std::string &s) : dstringt(s)
96
+ {
97
+ }
98
+
99
+ protected:
100
+ #ifdef __GNUC__
101
+ constexpr
102
+ #endif
103
+ explicit irep_idt (unsigned _no)
104
+ : dstringt(_no)
105
+ {
106
+ }
107
+ };
108
+
109
+ // NOLINTNEXTLINE [allow specialisation within 'std']
110
+ namespace std
111
+ {
112
+ // / Default hash function of `dstringt` for use with STL containers.
113
+ template <>
114
+ struct hash <irep_idt> // NOLINT(readability/identifiers)
115
+ {
116
+ size_t operator ()(const irep_idt &irep_id) const
117
+ {
118
+ return irep_id.hash ();
119
+ }
120
+ };
121
+ } // namespace std
122
+
47
123
#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));
124
+ #define IREP_ID_ONE (the_id ) \
125
+ constexpr irep_idt ID_##the_id = \
126
+ irep_idt::make_from_table_index ( static_cast <unsigned >(idt::id_##the_id));
127
+ #define IREP_ID_TWO (the_id, str ) \
128
+ constexpr irep_idt ID_##the_id = \
129
+ irep_idt::make_from_table_index ( static_cast <unsigned >(idt::id_##the_id));
54
130
#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));
131
+ #define IREP_ID_ONE (the_id ) \
132
+ const irep_idt ID_##the_id = \
133
+ irep_idt::make_from_table_index ( static_cast <unsigned >(idt::id_##the_id));
134
+ #define IREP_ID_TWO (the_id, str ) \
135
+ const const irep_idt ID_##the_id = \
136
+ irep_idt::make_from_table_index ( static_cast <unsigned >(idt::id_##the_id));
61
137
#endif
62
138
63
139
template <>
0 commit comments