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