| 361 | } |
| 362 | |
| 363 | absl::StatusOr<std::vector<SelectQualifier>> SelectInstructionsFromCall( |
| 364 | const CallExpr& call) { |
| 365 | if (call.args().size() < 2 || !call.args()[1].has_list_expr()) { |
| 366 | return absl::InvalidArgumentError("Invalid cel.attribute call"); |
| 367 | } |
| 368 | std::vector<SelectQualifier> instructions; |
| 369 | const auto& ast_path = call.args()[1].list_expr().elements(); |
| 370 | instructions.reserve(ast_path.size()); |
| 371 | |
| 372 | for (const ListExprElement& element : ast_path) { |
| 373 | // Optimized field select. |
| 374 | if (element.has_expr()) { |
| 375 | const auto& element_expr = element.expr(); |
| 376 | if (element_expr.has_list_expr()) { |
| 377 | CEL_ASSIGN_OR_RETURN(instructions.emplace_back(), |
| 378 | SelectQualifierFromList(element_expr.list_expr())); |
| 379 | } else if (element_expr.has_const_expr()) { |
| 380 | CEL_ASSIGN_OR_RETURN( |
| 381 | instructions.emplace_back(), |
| 382 | SelectQualifierFromConstant(element_expr.const_expr())); |
| 383 | } else { |
| 384 | return absl::InvalidArgumentError("Invalid cel.attribute call"); |
| 385 | } |
| 386 | } else { |
| 387 | return absl::InvalidArgumentError("Invalid cel.attribute call"); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | // TODO(uncreated-issue/54): support for optionals. |
| 392 | |
| 393 | return instructions; |
| 394 | } |
| 395 | |
| 396 | class RewriterImpl : public AstRewriterBase { |
| 397 | public: |
no test coverage detected