History

Convert static members to constexpr getters. This is hopefully going to avoid the built issues on Mac.

arr committed 9 years ago

Commit b0ff2261 parent c55b47f2 files · +44 −44Browse files

Showing the changes to src (2 of 2 files). Show all

Unified · Split

2 files
  1. src/asm/type_signature.cpp +3 −18
  2. src/include/vm_asm_sigkind.h +41 −26
src/asm/type_signature.cpp+3−18
@@ -34,8 +34,6 @@ namespace · 33 unmodified lines
3434 }
3535 }
3636
37−const char sig_stream_t::delim = ',';
38−
3937 uint32_t sig_stream_t::compute_signature_hash(const char *sig)
4038 {
4139 std::string sig_local{ sig };
@@ -142,12 +140,6 @@ sig_stream_t &disvm::assembly::sigkind::operator<<(sig_stream_t &os, const Tm &m · 100 unmodified lines
142140 return os << m._s;
143141 }
144142
145−template<> const char Ttuple::begin = '(';
146−template<> const char Ttuple::end = ')';
147−
148−template<> const char Tmodule::begin = '{';
149−template<> const char Tmodule::end = '}';
150−
151143 sig_stream_t &disvm::assembly::sigkind::operator<<(sig_stream_t &os, const Ttuple &t)
152144 {
153145 return os << t._s;
@@ -158,25 +150,21 @@ sig_stream_t &disvm::assembly::sigkind::operator<<(sig_stream_t &os, const Tmodu · 4 unmodified lines
158150 return os << m._s;
159151 }
160152
161−const char *Tadt_pick_tag::tag_delim = "=>";
162−const char Tadt_pick_tag::begin = '(';
163−const char Tadt_pick_tag::end = ')';
164−
165153 Tadt_pick_tag Tadt_pick_tag::create(const char *pick_tag, uint32_t adt_ref, std::initializer_list<const Tm> tms)
166154 {
167155 sig_stream_t ss;
168− ss << pick_tag << Tadt_pick_tag::tag_delim << Tbasic_type::id << Tadt_pick_tag::begin;
156+ ss << pick_tag << Tadt_pick_tag::tag_delim() << Tbasic_type::id << Tadt_pick_tag::begin();
169157
170158 auto tm = tms.begin();
171159 for (auto c = 0; tm != tms.end(); tm++, c++)
172160 {
173161 if (c > 0)
174− ss << sig_stream_t::delim;
162+ ss << sig_stream_t::delim();
175163
176164 ss << *tm;
177165 }
178166
179− ss << Tadt_pick_tag::end << Tref::id << adt_ref;
167+ ss << Tadt_pick_tag::end() << Tref::id << adt_ref;
180168
181169 return Tadt_pick_tag{ ss };
182170 }
@@ -186,9 +174,6 @@ sig_stream_t &disvm::assembly::sigkind::operator<<(sig_stream_t &os, const Tadt_ · 3 unmodified lines
186174 return os << t._s;
187175 }
188176
189−template<> const char Tnested_aggregate_type<type_id_t::adt>::begin = '(';
190−template<> const char Tnested_aggregate_type<type_id_t::adt>::end = ')';
191−
192177 sig_stream_t &disvm::assembly::sigkind::operator<<(sig_stream_t &os, const Tnested_aggregate_type<type_id_t::adt> &a)
193178 {
194179 return os << a._s;
src/include/vm_asm_sigkind.h+41−26
@@ -11,7 +11,6 @@ · 10 unmodified lines
1111 #include <sstream>
1212 #include <cassert>
1313 #include <cstdint>
14−#include "opcodes.h"
1514 #include "runtime.h"
1615
1716 namespace disvm
@@ -29,7 +28,7 @@ namespace disvm · 11 unmodified lines
2928 static uint32_t compute_signature_hash(const char *);
3029
3130 // Type delimiter
32− static const char delim;
31+ static constexpr char delim();
3332
3433 public:
3534 std::string get_signature() const;
@@ -45,6 +44,8 @@ namespace disvm · 9 unmodified lines
4544 mutable std::stringstream _ss;
4645 };
4746
47+ constexpr char sig_stream_t::delim() { return ','; }
48+
4849 // Type context modifiers
4950 enum class modifier_id_t : uint8_t
5051 {
@@ -196,7 +197,7 @@ namespace disvm · 145 unmodified lines
196197 template<typename T1, typename T2, typename ...S>
197198 void nested_type(sig_stream_t &ss, const T1 &t1, const T2 &t2, const S&...s)
198199 {
199− ss << t1 << sig_stream_t::delim;
200+ ss << t1 << sig_stream_t::delim();
200201 nested_type(ss, t2, s...);
201202 }
202203
@@ -205,18 +206,18 @@ namespace disvm · 2 unmodified lines
205206 class Tnested_aggregate_type : public Tbasic_type<ID>
206207 {
207208 public: // static
208− static const char begin;
209− static const char end;
209+ static constexpr char begin();
210+ static constexpr char end();
210211
211212 template<typename ...NT>
212213 static Tnested_aggregate_type create(const NT&... nestedTypes)
213214 {
214215 sig_stream_t ss;
215− ss << Tbasic_type<ID>::id << Tnested_aggregate_type::begin;
216+ ss << Tbasic_type<ID>::id << Tnested_aggregate_type::begin();
216217
217218 nested_type(ss, nestedTypes...);
218219
219− ss << Tnested_aggregate_type::end;
220+ ss << Tnested_aggregate_type::end();
220221
221222 return Tnested_aggregate_type{ ss };
222223 }
@@ -234,6 +235,16 @@ namespace disvm · 11 unmodified lines
234235
235236 using Ttuple = Tnested_aggregate_type<type_id_t::tuple>;
236237 using Tmodule = Tnested_aggregate_type<type_id_t::module>;
238+ using _Tadt = Tnested_aggregate_type<type_id_t::adt>;
239+
240+ template<> constexpr char Ttuple::begin() { return '('; }
241+ template<> constexpr char Ttuple::end() { return ')'; }
242+
243+ template<> constexpr char Tmodule::begin() { return '{'; }
244+ template<> constexpr char Tmodule::end() { return '}'; }
245+
246+ template<> constexpr char _Tadt::begin() { return '('; }
247+ template<> constexpr char _Tadt::end() { return ')'; }
237248
238249 sig_stream_t &operator<<(sig_stream_t &, const disvm::assembly::sigkind::Ttuple &);
239250 sig_stream_t &operator<<(sig_stream_t &, const disvm::assembly::sigkind::Tmodule &);
@@ -243,9 +254,9 @@ namespace disvm · 3 unmodified lines
243254 class Tadt_pick_tag final : public Tbasic_type<type_id_t::adt_pick_tag>
244255 {
245256 public: // static
246− static const char *tag_delim;
247− static const char begin;
248− static const char end;
257+ static constexpr char *tag_delim();
258+ static constexpr char begin();
259+ static constexpr char end();
249260
250261 static Tadt_pick_tag create(const char *pick_tag, uint32_t adt_ref, std::initializer_list<const Tm> tms);
251262
@@ -256,24 +267,28 @@ namespace disvm · 4 unmodified lines
256267 Tadt_pick_tag(sig_stream_t &s) : _s{ std::move(s) } { }
257268 };
258269
270+ constexpr char *Tadt_pick_tag::tag_delim() { return "=>"; }
271+ constexpr char Tadt_pick_tag::begin() { return '('; }
272+ constexpr char Tadt_pick_tag::end() { return ')'; }
273+
259274 sig_stream_t &operator<<(sig_stream_t &, const disvm::assembly::sigkind::Tadt_pick_tag &);
260275
261276 // Abstract data type (ADT)
262− class Tadt final : public Tnested_aggregate_type<type_id_t::adt>
277+ class Tadt final : public _Tadt
263278 {
264279 public: // static
265280 // Unhide base class version of function
266− using Tnested_aggregate_type::create;
281+ using _Tadt::create;
267282
268283 // Create an ADT with a single pick tag
269284 static Tadt create(const Tadt_pick_tag &p)
270285 {
271286 sig_stream_t ss;
272287 ss << Tbasic_type::id
273− << Tadt::begin
274− << sig_stream_t::delim
288+ << Tadt::begin()
289+ << sig_stream_t::delim()
275290 << p
276− << Tadt::end;
291+ << Tadt::end();
277292
278293 return Tadt{ ss };
279294 }
@@ -288,20 +303,20 @@ namespace disvm · 8 unmodified lines
288303 // single pick tag for an ADT must also be handled (above).
289304 sig_stream_t ss;
290305 ss << Tbasic_type::id
291− << Tadt::begin
292− << sig_stream_t::delim
306+ << Tadt::begin()
307+ << sig_stream_t::delim()
293308 << p
294− << sig_stream_t::delim;
309+ << sig_stream_t::delim();
295310
296311 nested_type(ss, t, nestedTypes...);
297312
298− ss << Tadt::end;
313+ ss << Tadt::end();
299314
300315 return Tadt{ ss };
301316 }
302317
303318 private:
304− Tadt(sig_stream_t &s) : Tnested_aggregate_type{ s } { }
319+ Tadt(sig_stream_t &s) : _Tadt{ s } { }
305320 };
306321
307322 sig_stream_t &operator<<(sig_stream_t &, const disvm::assembly::sigkind::Tnested_aggregate_type<type_id_t::adt> &);
@@ -311,18 +326,18 @@ namespace disvm · 3 unmodified lines
311326 class Tfunction_base_type final : public Tbasic_type<T>
312327 {
313328 public: // static
314− static const char begin;
315− static const char end;
329+ static constexpr char begin();
330+ static constexpr char end();
316331
317332 template<typename ...AT>
318333 static Tfunction_base_type create(AT... argTypes)
319334 {
320335 Tfunction_base_type a;
321− a._s << Tfunction_base_type::id << Tfunction_base_type::begin;
336+ a._s << Tfunction_base_type::id << Tfunction_base_type::begin();
322337
323338 nested_type(a._s, argTypes...);
324339
325− a._s << Tfunction_base_type::end;
340+ a._s << Tfunction_base_type::end();
326341 return a;
327342 }
328343
@@ -347,10 +362,10 @@ namespace disvm · 18 unmodified lines
347362 };
348363
349364 template<type_id_t T>
350− const char Tfunction_base_type<T>::begin = '(';
365+ constexpr char Tfunction_base_type<T>::begin() { return '('; }
351366
352367 template<type_id_t T>
353− const char Tfunction_base_type<T>::end = ')';
368+ constexpr char Tfunction_base_type<T>::end() { return ')'; }
354369
355370 using Tfunction = Tfunction_base_type<type_id_t::function>;
356371 using Tfunction_varargs = Tfunction_base_type<type_id_t::function_varargs>;