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

Method codegen_match

bootstrap/stage0/codegen.cpp:5276–5305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5274}
5275
5276ErrorOr<void> Jakt::codegen::CodeGenerator::codegen_match(NonnullRefPtr<typename Jakt::types::CheckedExpression> const expr,JaktInternal::DynamicArray<Jakt::types::CheckedMatchCase> const match_cases,Jakt::ids::TypeId const type_id,bool const all_variants_constant,bool const forward_error_with_try,ByteStringBuilder& output) {
5277{
5278if (!Jakt::codegen::has_cpp_value(type_id)){
5279TRY((this->codegen_void_match(expr,match_cases,type_id,output))); return {};
5280}
5281if (!Jakt::codegen::has_control_flow<Jakt::types::CheckedMatchCase>(match_cases,true)){
5282TRY((this->codegen_value_match(expr,match_cases,type_id,forward_error_with_try,output))); return {};
5283}
5284ByteStringBuilder builder = ByteStringBuilder::create();
5285Jakt::codegen::ControlFlowState const last_control_flow = this->control_flow_state;
5286this->control_flow_state = this->control_flow_state.enter_match();
5287ByteString const cpp_match_result_type = TRY((this->codegen_type(type_id)));
5288NonnullRefPtr<typename Jakt::types::Type> const expr_type = this->program->get_type(expr->type());
5289JaktInternal::Optional<Jakt::codegen::YieldMethod> const old_yield_method = this->yield_method;
5290this->yield_method = Jakt::codegen::YieldMethod::ReturnExplicitValue(__jakt_format(StringView::from_string_literal("JaktInternal::ExplicitValue<{}>"sv),cpp_match_result_type));
5291ScopeGuard __jakt_var_125([&] {
5292this->yield_method = old_yield_method;
5293});
5294builder.append(StringView::from_string_literal("([&]() -> JaktInternal::ExplicitValueOrControlFlow<"sv));
5295builder.append(cpp_match_result_type);
5296builder.append(StringView::from_string_literal(", "sv));
5297builder.append(TRY((this->codegen_function_return_type(this->current_function.value()))));
5298builder.append(StringView::from_string_literal(">{\n"sv));
5299TRY((this->codegen_inner_match(expr,match_cases,type_id,builder)));
5300builder.append(StringView::from_string_literal("}()\n)"sv));
5301this->control_flow_state = last_control_flow;
5302output.append(TRY((this->control_flow_state.apply_control_flow_macro(builder.to_string(),this->current_function.value()->return_type_id,this->current_function.value()->can_throw))));
5303}
5304return {};
5305}
5306
5307ErrorOr<void> Jakt::codegen::CodeGenerator::codegen_value_match(NonnullRefPtr<typename Jakt::types::CheckedExpression> const expr,JaktInternal::DynamicArray<Jakt::types::CheckedMatchCase> const match_cases,Jakt::ids::TypeId const type_id,bool const forward_error_with_try,ByteStringBuilder& output) {
5308{

Callers 1

codegen_expressionMethod · 0.95

Calls 14

codegen_void_matchMethod · 0.95
codegen_value_matchMethod · 0.95
codegen_typeMethod · 0.95
codegen_inner_matchMethod · 0.95
has_cpp_valueFunction · 0.85
enter_matchMethod · 0.80
__jakt_formatFunction · 0.50
get_typeMethod · 0.45
typeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected