From 0ad1239522c70418990dc7b9da4e128da7cdd1d5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 3 Dec 2017 20:43:56 -0500 Subject: rework enums and unions and their relationship to each other * @enumTagName renamed to @tagName and it works on enums and union-enums * Remove the EnumTag type. Now there is only enum and union, and the tag type of a union is always an enum. * unions support specifying the tag enum type, and they support inferring an enum tag type. * Enums no longer support field types but they do support setting the tag values. Likewise union-enums when inferring an enum tag type support setting the tag values. * It is now an error for enums and unions to have 0 fields. * switch statements support union-enums closes #618 --- src/ast_render.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/ast_render.cpp') diff --git a/src/ast_render.cpp b/src/ast_render.cpp index cdc18c7252..4f4dc1decd 100644 --- a/src/ast_render.cpp +++ b/src/ast_render.cpp @@ -661,11 +661,18 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { const char *layout_str = layout_string(node->data.container_decl.layout); const char *container_str = container_string(node->data.container_decl.kind); fprintf(ar->f, "%s%s", layout_str, container_str); + if (node->data.container_decl.auto_enum) { + fprintf(ar->f, "(enum"); + } if (node->data.container_decl.init_arg_expr != nullptr) { fprintf(ar->f, "("); render_node_grouped(ar, node->data.container_decl.init_arg_expr); fprintf(ar->f, ")"); } + if (node->data.container_decl.auto_enum) { + fprintf(ar->f, ")"); + } + fprintf(ar->f, " {\n"); ar->indent += ar->indent_size; for (size_t field_i = 0; field_i < node->data.container_decl.fields.length; field_i += 1) { -- cgit v1.2.3