Merge pull request #41 from detly/enum_cast

Fix bug where enums were treated interchangeably with uint16_t.
This commit is contained in:
Jason Heeris 2021-05-10 17:35:12 +08:00 committed by GitHub
commit 515c06c689
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -236,9 +236,11 @@ static void decode_value(struct value* v, Type_ptr type, Value_ptr value, const
break; break;
case Value_int16: case Value_int16:
case Value_uint16: case Value_uint16:
case Value__enum:
v->intval = v->v.int16; v->intval = v->v.int16;
break; break;
case Value__enum:
v->intval = v->v._enum;
break;
case Value_int32: case Value_int32:
case Value_uint32: case Value_uint32:
case Value_float32: case Value_float32:
@ -750,8 +752,9 @@ static void do_union(struct strings *s, struct node *n, struct field *first_fiel
* only need to emit one switch block as the layout will line up * only need to emit one switch block as the layout will line up
* in the C union */ * in the C union */
union_cases(s, n, first_field, (1 << Type__bool)); union_cases(s, n, first_field, (1 << Type__bool));
union_cases(s, n, first_field, (1 << Type__enum));
union_cases(s, n, first_field, (1 << Type_int8) | (1 << Type_uint8)); union_cases(s, n, first_field, (1 << Type_int8) | (1 << Type_uint8));
union_cases(s, n, first_field, (1 << Type_int16) | (1 << Type_uint16) | (1 << Type__enum)); union_cases(s, n, first_field, (1 << Type_int16) | (1 << Type_uint16));
union_cases(s, n, first_field, (1 << Type_int32) | (1 << Type_uint32) | (1 << Type_float32)); union_cases(s, n, first_field, (1 << Type_int32) | (1 << Type_uint32) | (1 << Type_float32));
union_cases(s, n, first_field, (1 << Type_int64) | (1 << Type_uint64) | (1 << Type_float64)); union_cases(s, n, first_field, (1 << Type_int64) | (1 << Type_uint64) | (1 << Type_float64));
union_cases(s, n, first_field, (1 << Type_text)); union_cases(s, n, first_field, (1 << Type_text));