From b62e2fd8703129fcf0dc80675800f005e84ee724 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 30 Nov 2017 21:46:02 -0500 Subject: [PATCH] ability to specify tag type of enums see #305 --- doc/langref.html.in | 8 +++++- src/all_types.hpp | 8 ++++++ src/analyze.cpp | 21 ++++++++++++++- src/ast_render.cpp | 8 +++++- src/codegen.cpp | 4 ++- src/ir.cpp | 57 +++++++++++++++++++++++++++++++++++++++++ src/ir_print.cpp | 9 +++++++ src/parser.cpp | 7 ++++- src/translate_c.cpp | 12 ++++++++- test/cases/enum.zig | 24 +++++++++++++++++ test/compile_errors.zig | 28 ++++++++++++++++++++ 11 files changed, 180 insertions(+), 6 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index e8f76e230b..32c099f547 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -137,6 +137,7 @@
  • @divTrunc
  • @embedFile
  • @enumTagName
  • +
  • @EnumTagType
  • @errorName
  • @fence
  • @fieldParentPtr
  • @@ -4256,6 +4257,11 @@ test.zig:6:2: error: found compile log statement

    Converts an enum tag name to a slice of bytes.

    +

    @EnumTagType

    +
    @EnumTagType(T: type) -> type
    +

    + Returns the integer type that is used to store the enumeration value. +

    @errorName

    @errorName(err: error) -> []u8

    @@ -5837,7 +5843,7 @@ GroupedExpression = "(" Expression ")" KeywordLiteral = "true" | "false" | "null" | "continue" | "undefined" | "error" | "this" | "unreachable" -ContainerDecl = option("extern" | "packed") ("struct" | "enum" | "union") "{" many(ContainerMember) "}" +ContainerDecl = option("extern" | "packed") ("struct" | "union" | ("enum" option(GroupedExpression))) "{" many(ContainerMember) "}"

    Zen