MCPcopy Create free account
hub / github.com/SerenityOS/jakt / codegen_enum

Method codegen_enum

bootstrap/stage0/codegen.cpp:2900–3148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 15

codegen_typeMethod · 0.95
codegen_expressionMethod · 0.95
codegen_functionMethod · 0.95
codegen_ak_formatterMethod · 0.95
void_type_idFunction · 0.85
todoFunction · 0.85

Tested by

no test coverage detected