From: Olivier Dion Date: Thu, 24 Oct 2024 15:11:00 +0000 (-0400) Subject: Refactor side_visit_type X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=a99e8bc9fc2da38a8a9d44a772e2294a5a24827e;p=libside.git Refactor side_visit_type Seperate the visiting of types and comparison testing. Change-Id: I85f43957ebc7bbc7bbb564d438141fccf4476510 Signed-off-by: Olivier Dion Signed-off-by: Mathieu Desnoyers --- diff --git a/src/visit-arg-vec.c b/src/visit-arg-vec.c index 4960ad3..aa3da94 100644 --- a/src/visit-arg-vec.c +++ b/src/visit-arg-vec.c @@ -1135,15 +1135,18 @@ void type_mismatch(const struct visit_context *ctx, abort(); } -void side_visit_type(const struct side_type_visitor *type_visitor, - const struct visit_context *ctx, - const struct side_type *type_desc, const struct side_arg *item, void *priv) +static void ensure_types_compatible(const struct visit_context *ctx, + const struct side_type *type_desc, + const struct side_arg *item) { - enum side_type_label type; + enum side_type_label want, got; - switch (side_enum_get(type_desc->type)) { + want = side_enum_get(type_desc->type); + got = side_enum_get(item->type); + + switch (want) { case SIDE_TYPE_ENUM: - switch (side_enum_get(item->type)) { + switch (got) { case SIDE_TYPE_U8: case SIDE_TYPE_U16: case SIDE_TYPE_U32: @@ -1156,15 +1159,13 @@ void side_visit_type(const struct side_type_visitor *type_visitor, case SIDE_TYPE_S128: break; default: - type_mismatch(ctx, - side_enum_get(type_desc->type), - side_enum_get(item->type)); + type_mismatch(ctx, want, got); break; } break; case SIDE_TYPE_ENUM_BITMAP: - switch (side_enum_get(item->type)) { + switch (got) { case SIDE_TYPE_U8: case SIDE_TYPE_BYTE: case SIDE_TYPE_U16: @@ -1175,27 +1176,23 @@ void side_visit_type(const struct side_type_visitor *type_visitor, case SIDE_TYPE_VLA: break; default: - type_mismatch(ctx, - side_enum_get(type_desc->type), - side_enum_get(item->type)); + type_mismatch(ctx, want, got); break; } break; case SIDE_TYPE_GATHER_ENUM: - switch (side_enum_get(item->type)) { + switch (got) { case SIDE_TYPE_GATHER_INTEGER: break; default: - type_mismatch(ctx, - side_enum_get(type_desc->type), - side_enum_get(item->type)); + type_mismatch(ctx, want, got); break; } break; case SIDE_TYPE_DYNAMIC: - switch (side_enum_get(item->type)) { + switch (got) { case SIDE_TYPE_DYNAMIC_NULL: case SIDE_TYPE_DYNAMIC_BOOL: case SIDE_TYPE_DYNAMIC_INTEGER: @@ -1215,15 +1212,21 @@ void side_visit_type(const struct side_type_visitor *type_visitor, break; } break; - default: - if (side_enum_get(type_desc->type) != side_enum_get(item->type)) { - type_mismatch(ctx, - side_enum_get(type_desc->type), - side_enum_get(item->type)); + if (want != got) { + type_mismatch(ctx, want, got); } break; } +} + +void side_visit_type(const struct side_type_visitor *type_visitor, + const struct visit_context *ctx, + const struct side_type *type_desc, const struct side_arg *item, void *priv) +{ + enum side_type_label type; + + ensure_types_compatible(ctx, type_desc, item); if (side_enum_get(type_desc->type) == SIDE_TYPE_ENUM || side_enum_get(type_desc->type) == SIDE_TYPE_ENUM_BITMAP || side_enum_get(type_desc->type) == SIDE_TYPE_GATHER_ENUM) type = side_enum_get(type_desc->type);