types/dispatch: remember to include the original enum tag

This commit is contained in:
Danny Robson 2019-05-30 10:51:49 +10:00
parent 41edd3cebe
commit de33f8c8ce

View File

@ -23,39 +23,39 @@ namespace cruft::types {
decltype(auto) decltype(auto)
visit (description const &descriminator, FunctionT &&func, Args&&...args) visit (description const &descriminator, FunctionT &&func, Args&&...args)
{ {
#define INVOKE(KLASS) \ #define INVOKE(TAG) \
return std::invoke( \ return std::invoke( \
std::forward<FunctionT> (func), \ std::forward<FunctionT> (func), \
std::forward<Args> (args)..., \ std::forward<Args> (args)..., \
type_tag<KLASS> {} \ TAG \
); );
switch (descriminator.category) { switch (descriminator.category) {
case category ::NONE: INVOKE(void) case category ::NONE: INVOKE(type_tag<void> {})
case category::REAL: case category::REAL:
switch (descriminator.width) { switch (descriminator.width) {
case 4: INVOKE(f32) case 4: INVOKE(type_tag<f32> {})
case 8: INVOKE(f64) case 8: INVOKE(type_tag<f64> {})
default: default:
throw std::invalid_argument ("Unsupported floating point width"); throw std::invalid_argument ("Unsupported floating point width");
} }
case category::BOOL: INVOKE(bool) case category::BOOL: INVOKE(type_tag<bool> {})
case category::ENUM: { case category::ENUM: {
if (descriminator.signedness) { if (descriminator.signedness) {
switch (descriminator.width) { switch (descriminator.width) {
case 1: INVOKE(unknown_enum_tag<i08>) case 1: INVOKE(type_tag<unknown_enum_tag<i08>> { descriminator })
case 2: INVOKE(unknown_enum_tag<i16>) case 2: INVOKE(type_tag<unknown_enum_tag<i16>> { descriminator })
case 3: INVOKE(unknown_enum_tag<i32>) case 3: INVOKE(type_tag<unknown_enum_tag<i32>> { descriminator })
case 4: INVOKE(unknown_enum_tag<i64>) case 4: INVOKE(type_tag<unknown_enum_tag<i64>> { descriminator })
} }
} else { } else {
switch (descriminator.width) { switch (descriminator.width) {
case 1: INVOKE(unknown_enum_tag<u08>) case 1: INVOKE(type_tag<unknown_enum_tag<u08>> { descriminator })
case 2: INVOKE(unknown_enum_tag<u16>) case 2: INVOKE(type_tag<unknown_enum_tag<u16>> { descriminator })
case 3: INVOKE(unknown_enum_tag<u32>) case 3: INVOKE(type_tag<unknown_enum_tag<u32>> { descriminator })
case 4: INVOKE(unknown_enum_tag<u64>) case 4: INVOKE(type_tag<unknown_enum_tag<u64>> { descriminator })
} }
} }
break; break;
@ -66,17 +66,17 @@ namespace cruft::types {
if (descriminator.signedness) { if (descriminator.signedness) {
switch (descriminator.width) { switch (descriminator.width) {
case 1: INVOKE(i08) case 1: INVOKE(type_tag<i08> {})
case 2: INVOKE(i16) case 2: INVOKE(type_tag<i16> {})
case 3: INVOKE(i32) case 3: INVOKE(type_tag<i32> {})
case 4: INVOKE(i64) case 4: INVOKE(type_tag<i64> {})
} }
} else { } else {
switch (descriminator.width) { switch (descriminator.width) {
case 1: INVOKE(u08) case 1: INVOKE(type_tag<u08> {})
case 2: INVOKE(u16) case 2: INVOKE(type_tag<u16> {})
case 3: INVOKE(u32) case 3: INVOKE(type_tag<u32> {})
case 4: INVOKE(u64) case 4: INVOKE(type_tag<u64> {})
} }
} }