aboutsummaryrefslogtreecommitdiff
path: root/enums.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-12 04:09:52 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-12 04:09:52 -0400
commit43f4f3610e5258afbfb9e313c989e1e52f477c38 (patch)
tree1f960cd930ed7e1e251ed24700c613a01221443b /enums.c
parentfb6dc0a8b9b5537ef708778bf013f71f98fad41f (diff)
For single-member structs/enums, don't print the member name
Diffstat (limited to 'enums.c')
-rw-r--r--enums.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/enums.c b/enums.c
index a0817b01..77ad1c14 100644
--- a/enums.c
+++ b/enums.c
@@ -42,11 +42,17 @@ static CORD compile_str_method(env_t *env, ast_t *ast)
continue;
}
- for (arg_ast_t *field = tag->fields; field; field = field->next) {
- type_t *field_t = get_arg_ast_type(env, field);
- CORD field_str = expr_as_text(env, CORD_all("obj->$", tag->name, ".$", field->name), field_t, "use_color");
- str_func = CORD_all(str_func, ", Text(\"", field->name, "=\"), ", field_str);
- if (field->next) str_func = CORD_cat(str_func, ", Text(\", \")");
+ if (tag->fields && !tag->fields->next) { // Single-member tags don't need to print member names:
+ type_t *field_t = get_arg_ast_type(env, tag->fields);
+ CORD field_str = expr_as_text(env, CORD_all("obj->$", tag->name, ".$", tag->fields->name), field_t, "use_color");
+ str_func = CORD_all(str_func, ", ", field_str);
+ } else {
+ for (arg_ast_t *field = tag->fields; field; field = field->next) {
+ type_t *field_t = get_arg_ast_type(env, field);
+ CORD field_str = expr_as_text(env, CORD_all("obj->$", tag->name, ".$", field->name), field_t, "use_color");
+ str_func = CORD_all(str_func, ", Text(\"", field->name, "=\"), ", field_str);
+ if (field->next) str_func = CORD_cat(str_func, ", Text(\", \")");
+ }
}
str_func = CORD_cat(str_func, ", Text(\")\"));\n");
}