diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-12 04:09:52 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-12 04:09:52 -0400 |
| commit | 43f4f3610e5258afbfb9e313c989e1e52f477c38 (patch) | |
| tree | 1f960cd930ed7e1e251ed24700c613a01221443b /enums.c | |
| parent | fb6dc0a8b9b5537ef708778bf013f71f98fad41f (diff) | |
For single-member structs/enums, don't print the member name
Diffstat (limited to 'enums.c')
| -rw-r--r-- | enums.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -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"); } |
