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

Method codegen_statement

bootstrap/stage0/codegen.cpp:7062–7289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7060}
7061
7062ErrorOr<void> Jakt::codegen::CodeGenerator::codegen_statement(NonnullRefPtr<typename Jakt::types::CheckedStatement> const statement,ByteStringBuilder& output) {
7063{
7064bool add_newline = true;
7065if (this->debug_info.statement_span_comments && (statement->span().has_value() && add_newline)){
7066output.appendff(ByteString::from_utf8_without_validation("\n#line {}\n"sv),TRY((this->debug_info.span_to_source_location(statement->span().value()))));
7067}
7068{auto&& __jakt_match_variant = *statement;
7069switch(__jakt_match_variant.__jakt_init_index()) {
7070case 11 /* Throw */: {
7071auto&& __jakt_match_value = __jakt_match_variant.as.Throw;NonnullRefPtr<typename Jakt::types::CheckedExpression> const& expr = __jakt_match_value.expr;
7072{
7073this->yields_erroror = true;
7074output.append(StringView::from_string_literal("return "sv));
7075TRY((this->codegen_expression(expr,output,true,false)));
7076output.append(StringView::from_string_literal(";"sv));
7077}
7078goto __jakt_label_189;};/*case end*/
7079case 10 /* Continue */:{
7080output.append([&]() -> StringView { auto __jakt_enum_value = this->control_flow_state.directly_inside_match;
7081if (__jakt_enum_value) {return StringView::from_string_literal("return JaktInternal::LoopContinue{};"sv);}else if (!__jakt_enum_value) {return StringView::from_string_literal("continue;"sv);}VERIFY_NOT_REACHED();
7082
7083}());
7084}
7085goto __jakt_label_189;case 9 /* Break */:{
7086output.append(this->break_statement());
7087}
7088goto __jakt_label_189;case 0 /* Expression */: {
7089auto&& __jakt_match_value = __jakt_match_variant.as.Expression;NonnullRefPtr<typename Jakt::types::CheckedExpression> const& expr = __jakt_match_value.expr;
7090{
7091TRY((this->codegen_expression(expr,output,true,false)));
7092output.append(StringView::from_string_literal(";"sv));
7093}
7094goto __jakt_label_189;};/*case end*/
7095case 1 /* Defer */: {
7096auto&& __jakt_match_value = __jakt_match_variant.as.Defer;NonnullRefPtr<typename Jakt::types::CheckedStatement> const& statement = __jakt_match_value.statement;
7097{
7098output.append(StringView::from_string_literal("ScopeGuard "sv));
7099output.append(this->fresh_var());
7100output.append(StringView::from_string_literal("([&] {\n"sv));
7101Jakt::codegen::ControlFlowState const last_control_flow = this->control_flow_state;
7102bool const old_inside_defer = this->inside_defer;
7103this->control_flow_state.directly_inside_match = false;
7104this->control_flow_state.indirectly_inside_match = false;
7105this->inside_defer = true;
7106TRY((this->codegen_statement(statement,output)));
7107output.append(StringView::from_string_literal("});"sv));
7108this->control_flow_state = last_control_flow;
7109this->inside_defer = old_inside_defer;
7110}
7111goto __jakt_label_189;};/*case end*/
7112case 8 /* Return */: {
7113auto&& __jakt_match_value = __jakt_match_variant.as.Return;JaktInternal::Optional<NonnullRefPtr<typename Jakt::types::CheckedExpression>> const& val = __jakt_match_value.val;
7114TRY((this->codegen_return(val,output)));goto __jakt_label_189;};/*case end*/
7115case 6 /* Loop */: {
7116auto&& __jakt_match_value = __jakt_match_variant.as.Loop;Jakt::types::CheckedBlock const& block = __jakt_match_value.block;
7117{
7118if (this->debug_info.statement_span_comments && statement->span().has_value()){
7119output.appendff(ByteString::from_utf8_without_validation("\n#line {}\n"sv),TRY((this->debug_info.span_to_source_location(statement->span().value()))));

Callers 2

codegen_expressionMethod · 0.95
codegen_blockMethod · 0.95

Calls 15

codegen_expressionMethod · 0.95
break_statementMethod · 0.95
fresh_varMethod · 0.95
codegen_returnMethod · 0.95
codegen_blockMethod · 0.95
codegen_var_declMethod · 0.95
void_type_idFunction · 0.85
enter_loopMethod · 0.80
panicFunction · 0.70
has_valueMethod · 0.45
spanMethod · 0.45

Tested by

no test coverage detected