| 558 | } |
| 559 | |
| 560 | absl::Status RegisterListsCheckerDecls(TypeCheckerBuilder& builder, |
| 561 | int version) { |
| 562 | CEL_ASSIGN_OR_RETURN( |
| 563 | FunctionDecl distinct_decl, |
| 564 | MakeFunctionDecl("distinct", MakeMemberOverloadDecl( |
| 565 | "list_distinct", ListTypeParamType(), |
| 566 | ListTypeParamType()))); |
| 567 | |
| 568 | CEL_ASSIGN_OR_RETURN( |
| 569 | FunctionDecl flatten_decl, |
| 570 | MakeFunctionDecl( |
| 571 | "flatten", |
| 572 | MakeMemberOverloadDecl("list_flatten_int", ListType(), ListType(), |
| 573 | IntType()), |
| 574 | MakeMemberOverloadDecl("list_flatten", ListType(), ListType()))); |
| 575 | |
| 576 | CEL_ASSIGN_OR_RETURN( |
| 577 | FunctionDecl range_decl, |
| 578 | MakeFunctionDecl( |
| 579 | "lists.range", |
| 580 | MakeOverloadDecl("list_range", ListIntType(), IntType()))); |
| 581 | |
| 582 | CEL_ASSIGN_OR_RETURN( |
| 583 | FunctionDecl reverse_decl, |
| 584 | MakeFunctionDecl( |
| 585 | "reverse", MakeMemberOverloadDecl("list_reverse", ListTypeParamType(), |
| 586 | ListTypeParamType()))); |
| 587 | |
| 588 | CEL_ASSIGN_OR_RETURN( |
| 589 | FunctionDecl slice_decl, |
| 590 | MakeFunctionDecl( |
| 591 | "slice", |
| 592 | MakeMemberOverloadDecl("list_slice", ListTypeParamType(), |
| 593 | ListTypeParamType(), IntType(), IntType()))); |
| 594 | |
| 595 | static const absl::NoDestructor<std::vector<Type>> kSortableListTypes([] { |
| 596 | std::vector<Type> instance; |
| 597 | instance.reserve(SortableTypes().size()); |
| 598 | for (const Type& type : SortableTypes()) { |
| 599 | instance.push_back(ListType(BuiltinsArena(), type)); |
| 600 | } |
| 601 | return instance; |
| 602 | }()); |
| 603 | |
| 604 | FunctionDecl sort_decl; |
| 605 | sort_decl.set_name("sort"); |
| 606 | FunctionDecl sort_by_key_decl; |
| 607 | sort_by_key_decl.set_name("@sortByAssociatedKeys"); |
| 608 | |
| 609 | for (const Type& list_type : *kSortableListTypes) { |
| 610 | std::string elem_type_name(list_type.AsList()->GetElement().name()); |
| 611 | |
| 612 | CEL_RETURN_IF_ERROR(sort_decl.AddOverload(MakeMemberOverloadDecl( |
| 613 | absl::StrCat("list_", elem_type_name, "_sort"), list_type, list_type))); |
| 614 | CEL_RETURN_IF_ERROR(sort_by_key_decl.AddOverload(MakeMemberOverloadDecl( |
| 615 | absl::StrCat("list_", elem_type_name, "_sortByAssociatedKeys"), |
| 616 | ListTypeParamType(), ListTypeParamType(), list_type))); |
| 617 | } |
no test coverage detected