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

Method PreVisitComprehension

eval/compiler/flat_expr_builder.cc:1290–1382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1288 }
1289
1290 void PreVisitComprehension(
1291 const cel::Expr& expr,
1292 const cel::ComprehensionExpr& comprehension) override {
1293 if (!progress_status_.ok()) {
1294 return;
1295 }
1296 if (!ValidateOrError(options_.enable_comprehension,
1297 "Comprehension support is disabled")) {
1298 return;
1299 }
1300 const auto& accu_var = comprehension.accu_var();
1301 const auto& iter_var = comprehension.iter_var();
1302 const auto& iter_var2 = comprehension.iter_var2();
1303 ValidateOrError(!accu_var.empty(),
1304 "Invalid comprehension: 'accu_var' must not be empty");
1305 ValidateOrError(!iter_var.empty(),
1306 "Invalid comprehension: 'iter_var' must not be empty");
1307 ValidateOrError(
1308 accu_var != iter_var,
1309 "Invalid comprehension: 'accu_var' must not be the same as 'iter_var'");
1310 ValidateOrError(accu_var != iter_var2,
1311 "Invalid comprehension: 'accu_var' must not be the same as "
1312 "'iter_var2'");
1313 ValidateOrError(iter_var2 != iter_var,
1314 "Invalid comprehension: 'iter_var2' must not be the same "
1315 "as 'iter_var'");
1316 ValidateOrError(comprehension.has_accu_init(),
1317 "Invalid comprehension: 'accu_init' must be set");
1318 ValidateOrError(comprehension.has_loop_condition(),
1319 "Invalid comprehension: 'loop_condition' must be set");
1320 ValidateOrError(comprehension.has_loop_step(),
1321 "Invalid comprehension: 'loop_step' must be set");
1322 ValidateOrError(comprehension.has_result(),
1323 "Invalid comprehension: 'result' must be set");
1324
1325 size_t iter_slot, iter2_slot, accu_slot, slot_count;
1326 bool is_bind = IsBind(&comprehension);
1327
1328 if (is_bind) {
1329 accu_slot = iter_slot = iter2_slot = index_manager_.ReserveSlots(1);
1330 slot_count = 1;
1331 } else if (comprehension.iter_var2().empty()) {
1332 iter_slot = iter2_slot = index_manager_.ReserveSlots(2);
1333 accu_slot = iter_slot + 1;
1334 slot_count = 2;
1335 } else {
1336 iter_slot = index_manager_.ReserveSlots(3);
1337 iter2_slot = iter_slot + 1;
1338 accu_slot = iter2_slot + 1;
1339 slot_count = 3;
1340 }
1341
1342 if (block_.has_value()) {
1343 BlockInfo& block = *block_;
1344 if (block.in) {
1345 block.slot_count += slot_count;
1346 slot_count = 0;
1347 }

Callers

nothing calls this directly

Calls 12

IsBindFunction · 0.85
IsOptimizableListAppendFunction · 0.85
IsOptimizableMapInsertFunction · 0.85
has_accu_initMethod · 0.80
has_loop_conditionMethod · 0.80
has_loop_stepMethod · 0.80
has_resultMethod · 0.80
ReserveSlotsMethod · 0.80
PreVisitMethod · 0.80
okMethod · 0.45
emptyMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected