| 446 | } |
| 447 | |
| 448 | bool PostVisitRewrite(Expr& expr) override { |
| 449 | if (!progress_status_.ok()) { |
| 450 | return false; |
| 451 | } |
| 452 | path_.pop_back(); |
| 453 | auto candidate_iter = candidates_.find(&expr); |
| 454 | if (candidate_iter == candidates_.end()) { |
| 455 | return false; |
| 456 | } |
| 457 | |
| 458 | // On post visit, filter candidates that aren't rooted on a message or a |
| 459 | // select chain. |
| 460 | const QualifierInstruction& candidate = candidate_iter->second; |
| 461 | if (!HasOptimizeableRoot(&expr, candidate)) { |
| 462 | candidates_.erase(candidate_iter); |
| 463 | return false; |
| 464 | } |
| 465 | |
| 466 | if (!path_.empty() && candidates_.find(path_.back()) != candidates_.end()) { |
| 467 | // parent is optimizeable, defer rewriting until we consider the parent. |
| 468 | return false; |
| 469 | } |
| 470 | |
| 471 | SelectPath path = GetSelectPath(&expr); |
| 472 | |
| 473 | // generate the new cel.attribute call. |
| 474 | absl::string_view fn = path.test_only ? kCelHasField : kCelAttribute; |
| 475 | |
| 476 | Expr operand(std::move(*path.operand)); |
| 477 | Expr call; |
| 478 | call.set_id(expr.id()); |
| 479 | call.mutable_call_expr().set_function(std::string(fn)); |
| 480 | call.mutable_call_expr().mutable_args().reserve(2); |
| 481 | |
| 482 | call.mutable_call_expr().mutable_args().push_back(std::move(operand)); |
| 483 | call.mutable_call_expr().mutable_args().push_back( |
| 484 | MakeSelectPathExpr(path.select_instructions)); |
| 485 | |
| 486 | // TODO(uncreated-issue/54): support for optionals. |
| 487 | expr = std::move(call); |
| 488 | |
| 489 | return true; |
| 490 | } |
| 491 | |
| 492 | absl::Status GetProgressStatus() const { return progress_status_; } |
| 493 |
nothing calls this directly
no test coverage detected