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

Method codegen_expression

bootstrap/stage0/codegen.cpp:3999–5232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3997}
3998
3999ErrorOr<void> Jakt::codegen::CodeGenerator::codegen_expression(NonnullRefPtr<typename Jakt::types::CheckedExpression> const expression,ByteStringBuilder& output,bool const forward_error_with_try,bool const syntactically_self_contained) {
4000{
4001this->generic_inferences = expression->common.init_common.generic_inferences.value_or_lazy_evaluated_optional([&] { return this->generic_inferences; });
4002ScopeGuard __jakt_var_118([&] {
4003this->generic_inferences = JaktInternal::OptionalNone();
4004});
4005{auto&& __jakt_match_variant = *expression;
4006switch(__jakt_match_variant.__jakt_init_index()) {
4007case 34 /* Reflect */: {
4008auto&& __jakt_match_value = __jakt_match_variant.as.Reflect;Jakt::utility::Span const& span = __jakt_match_value.span;
4009{
4010Jakt::utility::panic(__jakt_format(StringView::from_string_literal("Unexpected reflect expression at {}"sv),span));
4011}
4012goto __jakt_label_165;};/*case end*/
4013case 9 /* Range */: {
4014auto&& __jakt_match_value = __jakt_match_variant.as.Range;JaktInternal::Optional<NonnullRefPtr<typename Jakt::types::CheckedExpression>> const& from = __jakt_match_value.from;
4015JaktInternal::Optional<NonnullRefPtr<typename Jakt::types::CheckedExpression>> const& to = __jakt_match_value.to;
4016Jakt::ids::TypeId const& type_id = __jakt_match_value.type_id;
4017{
4018NonnullRefPtr<typename Jakt::types::Type> const type = this->program->get_type(type_id);
4019Jakt::ids::TypeId const index_type = [&]() -> Jakt::ids::TypeId { auto&& __jakt_match_variant = *type;
4020switch(__jakt_match_variant.__jakt_init_index()) {
4021case 20 /* GenericInstance */: {
4022auto&& __jakt_match_value = __jakt_match_variant.as.GenericInstance;Jakt::ids::StructId const& id = __jakt_match_value.id;
4023JaktInternal::DynamicArray<Jakt::ids::TypeId> const& args = __jakt_match_value.args;
4024return args[static_cast<i64>(0LL)];};/*case end*/
4025default:{
4026Jakt::utility::panic(ByteString::from_utf8_without_validation("Internal error: range expression doesn't have Range type"sv));
4027}
4028}/*switch end*/
4029
4030}();
4031output.append(TRY((this->codegen_type(type_id))));
4032output.append(StringView::from_string_literal("{"sv));
4033output.append(StringView::from_string_literal("static_cast<"sv));
4034output.append(TRY((this->codegen_type(index_type))));
4035output.append(StringView::from_string_literal(">("sv));
4036if (from.has_value()){
4037TRY((this->codegen_expression(from.value(),output,true,false)));
4038}
4039else {
4040output.append(StringView::from_string_literal("0LL"sv));
4041}
4042
4043output.append(StringView::from_string_literal("),static_cast<"sv));
4044output.append(TRY((this->codegen_type(index_type))));
4045output.append(StringView::from_string_literal(">("sv));
4046if (to.has_value()){
4047TRY((this->codegen_expression(to.value(),output,true,false)));
4048}
4049else {
4050output.append(StringView::from_string_literal("9223372036854775807LL"sv));
4051}
4052
4053output.append(StringView::from_string_literal(")}"sv));
4054}
4055goto __jakt_label_165;};/*case end*/
4056case 25 /* OptionalNone */:{

Calls 15

codegen_typeMethod · 0.95
current_error_handlerMethod · 0.95
codegen_method_callMethod · 0.95
codegen_blockMethod · 0.95
codegen_callMethod · 0.95
codegen_prefix_unaryMethod · 0.95
codegen_postfix_unaryMethod · 0.95
codegen_matchMethod · 0.95

Tested by

no test coverage detected