@@ -44,19 +44,80 @@ enum class idt:unsigned
4444#include " irep_ids.def" // NOLINT(build/include)
4545};
4646
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 ():dstringt()
55+ {
56+ }
57+
58+ // this is safe for static objects
59+ #ifdef __GNUC__
60+ constexpr
61+ #endif
62+ static irep_idt make_from_table_index (unsigned no)
63+ {
64+ return irep_idt (no);
65+ }
66+
67+ #ifdef __GNUC__
68+ // This conversion allows the use of irep_idts
69+ // in switch ... case statements.
70+ constexpr operator idt () const { return static_cast <idt>(no); }
71+ #endif
72+
73+ // this one is not safe for static objects
74+ // NOLINTNEXTLINE(runtime/explicit)
75+ irep_idt (const char *s):dstringt(s)
76+ {
77+ }
78+
79+ // this one is not safe for static objects
80+ // NOLINTNEXTLINE(runtime/explicit)
81+ irep_idt (const std::string &s):dstringt(s)
82+ {
83+ }
84+
85+ protected:
86+ #ifdef __GNUC__
87+ constexpr
88+ #endif
89+ explicit irep_idt (unsigned _no):dstringt(_no)
90+ {
91+ }
92+ };
93+
94+ // NOLINTNEXTLINE [allow specialisation within 'std']
95+ namespace std
96+ {
97+ // / Default hash function of `dstringt` for use with STL containers.
98+ template <>
99+ struct hash <irep_idt> // NOLINT(readability/identifiers)
100+ {
101+ size_t operator ()(const irep_idt &irep_id) const
102+ {
103+ return irep_id.hash ();
104+ }
105+ };
106+ }
107+
47108#ifdef __GNUC__
48109#define IREP_ID_ONE (the_id ) \
49- constexpr dstringt ID_##the_id=dstringt ::make_from_table_index( \
110+ constexpr irep_idt ID_##the_id=irep_idt ::make_from_table_index( \
50111 static_cast <unsigned >(idt::id_##the_id));
51112#define IREP_ID_TWO (the_id, str ) \
52- constexpr dstringt ID_##the_id=dstringt ::make_from_table_index( \
113+ constexpr irep_idt ID_##the_id=irep_idt ::make_from_table_index( \
53114 static_cast <unsigned >(idt::id_##the_id));
54115#else
55116#define IREP_ID_ONE (the_id ) \
56- const dstringt ID_##the_id=dstringt ::make_from_table_index( \
117+ const irep_idt ID_##the_id=irep_idt ::make_from_table_index( \
57118 static_cast <unsigned >(idt::id_##the_id));
58119#define IREP_ID_TWO (the_id, str ) \
59- const const dstringt ID_##the_id=dstringt ::make_from_table_index( \
120+ const const irep_idt ID_##the_id=irep_idt ::make_from_table_index( \
60121 static_cast <unsigned >(idt::id_##the_id));
61122#endif
62123
0 commit comments