MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / PostVisitArgDefault

Method PostVisitArgDefault

eval/compiler/flat_expr_builder.cc:2377–2452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2375}
2376
2377absl::Status ComprehensionVisitor::PostVisitArgDefault(
2378 cel::ComprehensionArg arg_num, const cel::Expr* expr) {
2379 if (visitor_->PlanRecursiveProgram()) {
2380 return absl::OkStatus();
2381 }
2382 switch (arg_num) {
2383 case cel::ITER_RANGE: {
2384 init_step_pos_ = visitor_->GetCurrentIndex();
2385 init_step_ = visitor_->AddStep(
2386 std::make_unique<ComprehensionInitStep>(expr->id()));
2387 break;
2388 }
2389 case cel::ACCU_INIT: {
2390 next_step_pos_ = visitor_->GetCurrentIndex();
2391 next_step_ = visitor_->AddStep(std::make_unique<ComprehensionNextStep>(
2392 iter_slot_, iter2_slot_, accu_slot_, expr->id()));
2393 break;
2394 }
2395 case cel::LOOP_CONDITION: {
2396 cond_step_pos_ = visitor_->GetCurrentIndex();
2397 cond_step_ = visitor_->AddStep(std::make_unique<ComprehensionCondStep>(
2398 iter_slot_, iter2_slot_, accu_slot_, short_circuiting_, expr->id()));
2399 break;
2400 }
2401 case cel::LOOP_STEP: {
2402 ProgramStepIndex index = visitor_->GetCurrentIndex();
2403 auto* jump_to_next = visitor_->AddStep(CreateJumpStep({}, expr->id()));
2404 if (!jump_to_next) {
2405 break;
2406 }
2407 Jump jump_helper(index, jump_to_next);
2408 visitor_->SetProgressStatusError(jump_helper.set_target(next_step_pos_));
2409
2410 // Set offsets jumping to the result step.
2411 if (cond_step_) {
2412 CEL_ASSIGN_OR_RETURN(
2413 int jump_from_cond,
2414 Jump::CalculateOffset(cond_step_pos_, visitor_->GetCurrentIndex()));
2415 cond_step_->set_jump_offset(jump_from_cond);
2416 }
2417
2418 if (next_step_) {
2419 CEL_ASSIGN_OR_RETURN(
2420 int jump_from_next,
2421 Jump::CalculateOffset(next_step_pos_, visitor_->GetCurrentIndex()));
2422
2423 next_step_->set_jump_offset(jump_from_next);
2424 }
2425 break;
2426 }
2427 case cel::RESULT: {
2428 if (!init_step_ || !next_step_ || !cond_step_) {
2429 // Encountered an error earlier. Can't determine where to jump.
2430 break;
2431 }
2432 visitor_->AddStep(CreateComprehensionFinishStep(accu_slot_, expr->id()));
2433 // Set offsets jumping past the result step in case of errors.
2434 CEL_ASSIGN_OR_RETURN(

Callers

nothing calls this directly

Calls 10

CreateJumpStepFunction · 0.85
PlanRecursiveProgramMethod · 0.80
GetCurrentIndexMethod · 0.80
AddStepMethod · 0.45
idMethod · 0.45
set_targetMethod · 0.45
set_jump_offsetMethod · 0.45
set_error_jump_offsetMethod · 0.45

Tested by

no test coverage detected