| 2898 | } |
| 2899 | |
| 2900 | ErrorOr<void> Jakt::codegen::CodeGenerator::codegen_enum(Jakt::types::CheckedEnum const enum_,ByteStringBuilder& output) { |
| 2901 | { |
| 2902 | if ([](Jakt::ids::TypeId const& self, Jakt::ids::TypeId rhs) -> bool {{ |
| 2903 | return !self.equals(rhs); |
| 2904 | } |
| 2905 | } |
| 2906 | (enum_.underlying_type_id,Jakt::types::void_type_id())){ |
| 2907 | if (this->program->is_integer(enum_.underlying_type_id)){ |
| 2908 | output.appendff(ByteString::from_utf8_without_validation("enum class {} : {} {{\n"sv),enum_.name,TRY((this->codegen_type(enum_.underlying_type_id)))); |
| 2909 | { |
| 2910 | JaktInternal::ArrayIterator<Jakt::types::CheckedEnumVariant> _magic = enum_.variants.iterator(); |
| 2911 | for (;;){ |
| 2912 | JaktInternal::Optional<Jakt::types::CheckedEnumVariant> const _magic_value = _magic.next(); |
| 2913 | if (!_magic_value.has_value()){ |
| 2914 | break; |
| 2915 | } |
| 2916 | Jakt::types::CheckedEnumVariant variant = _magic_value.value(); |
| 2917 | { |
| 2918 | Jakt::types::CheckedEnumVariant __jakt_tmp259 = variant; |
| 2919 | if (__jakt_tmp259.__jakt_init_index() == 2 /* WithValue */){ |
| 2920 | ByteString const name = __jakt_tmp259.as.WithValue.name; |
| 2921 | NonnullRefPtr<typename Jakt::types::CheckedExpression> const expr = __jakt_tmp259.as.WithValue.expr; |
| 2922 | output.append(name); |
| 2923 | output.append(StringView::from_string_literal(" = "sv)); |
| 2924 | TRY((this->codegen_expression(expr,output,true,false))); |
| 2925 | output.append(StringView::from_string_literal(",\n"sv)); |
| 2926 | } |
| 2927 | else { |
| 2928 | Jakt::utility::todo(__jakt_format(StringView::from_string_literal("codegen_enum can't generate variant: {}"sv),variant)); |
| 2929 | } |
| 2930 | |
| 2931 | } |
| 2932 | |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | output.append(StringView::from_string_literal("};\n"sv)); |
| 2937 | return {}; |
| 2938 | } |
| 2939 | else { |
| 2940 | Jakt::utility::todo(ByteString::from_utf8_without_validation("Enums with a non-integer underlying type"sv)); |
| 2941 | } |
| 2942 | |
| 2943 | } |
| 2944 | bool const is_generic = !enum_.generic_parameters.is_empty(); |
| 2945 | JaktInternal::DynamicArray<ByteString> generic_parameter_names = DynamicArray<ByteString>::create_with({}); |
| 2946 | ByteStringBuilder template_args_builder = ByteStringBuilder::create(); |
| 2947 | TRY((this->codegen_template_parameter_names(enum_.generic_parameters,generic_parameter_names,template_args_builder))); |
| 2948 | ByteString const template_args = template_args_builder.to_string(); |
| 2949 | ByteString const generic_parameter_list = Jakt::utility::join(generic_parameter_names,ByteString::from_utf8_without_validation(", "sv)); |
| 2950 | if (is_generic){ |
| 2951 | output.append(StringView::from_string_literal("template<"sv)); |
| 2952 | output.append(template_args); |
| 2953 | output.append(StringView::from_string_literal(">\n"sv)); |
| 2954 | } |
| 2955 | output.appendff(ByteString::from_utf8_without_validation("struct {}"sv),enum_.name); |
| 2956 | if (enum_.is_boxed){ |
| 2957 | output.appendff(ByteString::from_utf8_without_validation(": public RefCounted<{}"sv),enum_.name); |
no test coverage detected