| 8024 | } |
| 8025 | |
| 8026 | ErrorOr<void> Jakt::codegen::CodeGenerator::codegen_constructor(NonnullRefPtr<Jakt::types::CheckedFunction> const function,bool const is_inline,ByteStringBuilder& output) { |
| 8027 | { |
| 8028 | Jakt::ids::TypeId const type_id = function->return_type_id; |
| 8029 | NonnullRefPtr<typename Jakt::types::Type> const type_ = this->program->get_type(type_id); |
| 8030 | NonnullRefPtr<typename Jakt::types::Type> __jakt_tmp293 = type_; |
| 8031 | if (__jakt_tmp293->__jakt_init_index() == 23 /* Struct */){ |
| 8032 | Jakt::ids::StructId const struct_id = __jakt_tmp293->as.Struct.value; |
| 8033 | Jakt::types::CheckedStruct const structure = this->program->get_struct(struct_id); |
| 8034 | ByteString const qualified_name = TRY((this->codegen_type_possibly_as_namespace(type_id,true))); |
| 8035 | if ((!is_inline) && (!structure.generic_parameters.is_empty())){ |
| 8036 | output.append(StringView::from_string_literal("template <"sv)); |
| 8037 | TRY((this->codegen_template_parameter_names(structure.generic_parameters,output))); |
| 8038 | output.append(StringView::from_string_literal(">\n"sv)); |
| 8039 | } |
| 8040 | if ((structure.record_type.__jakt_init_index() == 1 /* Class */) || (structure.record_type.__jakt_init_index() == 0 /* Struct */)){ |
| 8041 | if (is_inline){ |
| 8042 | output.append(function->name_for_codegen().as_name_for_definition()); |
| 8043 | output.append(StringView::from_string_literal("("sv)); |
| 8044 | } |
| 8045 | else { |
| 8046 | output.appendff(ByteString::from_utf8_without_validation("{}::{}("sv),qualified_name,function->name_for_codegen().as_name_for_definition()); |
| 8047 | } |
| 8048 | |
| 8049 | bool first = true; |
| 8050 | { |
| 8051 | JaktInternal::ArrayIterator<Jakt::types::CheckedParameter> _magic = function->params.iterator(); |
| 8052 | for (;;){ |
| 8053 | JaktInternal::Optional<Jakt::types::CheckedParameter> const _magic_value = _magic.next(); |
| 8054 | if (!_magic_value.has_value()){ |
| 8055 | break; |
| 8056 | } |
| 8057 | Jakt::types::CheckedParameter param = _magic_value.value(); |
| 8058 | { |
| 8059 | if (!first){ |
| 8060 | output.append(StringView::from_string_literal(", "sv)); |
| 8061 | } |
| 8062 | else { |
| 8063 | first = false; |
| 8064 | } |
| 8065 | |
| 8066 | Jakt::ids::TypeId const param_type_id = param.variable->type_id; |
| 8067 | output.append(TRY((this->codegen_type(param_type_id)))); |
| 8068 | output.append(StringView::from_string_literal(" a_"sv)); |
| 8069 | output.append(param.variable->name_for_codegen().as_name_for_definition()); |
| 8070 | } |
| 8071 | |
| 8072 | } |
| 8073 | } |
| 8074 | |
| 8075 | output.append(StringView::from_string_literal(")"sv)); |
| 8076 | if (!function->params.is_empty()){ |
| 8077 | output.append(StringView::from_string_literal(": "sv)); |
| 8078 | JaktInternal::DynamicArray<ByteString> initializers = DynamicArray<ByteString>::create_with({}); |
| 8079 | size_t const parent_constructor_parameter_count = JaktInternal::checked_sub(function->params.size(),structure.fields.size()); |
| 8080 | if (parent_constructor_parameter_count > static_cast<size_t>(0ULL)){ |
| 8081 | ByteString parent_initializer = ByteString::from_utf8_without_validation(""sv); |
| 8082 | [](ByteString& self, ByteString rhs) -> void {{ |
| 8083 | self = (self + rhs); |
no test coverage detected