| 69 | } |
| 70 | |
| 71 | absl::Status AddMinMaxDecls(TypeCheckerBuilder& builder) { |
| 72 | const Type kNumerics[] = {IntType(), DoubleType(), UintType()}; |
| 73 | const Type kListNumerics[] = {ListIntType(), ListDoubleType(), |
| 74 | ListUintType()}; |
| 75 | |
| 76 | constexpr char kMinOverloadPrefix[] = "math_@min_"; |
| 77 | constexpr char kMaxOverloadPrefix[] = "math_@max_"; |
| 78 | |
| 79 | FunctionDecl min_decl; |
| 80 | min_decl.set_name("math.@min"); |
| 81 | |
| 82 | FunctionDecl max_decl; |
| 83 | max_decl.set_name("math.@max"); |
| 84 | |
| 85 | for (const Type& type : kNumerics) { |
| 86 | // Unary overloads |
| 87 | CEL_RETURN_IF_ERROR(min_decl.AddOverload(MakeOverloadDecl( |
| 88 | absl::StrCat(kMinOverloadPrefix, OverloadTypeName(type)), type, type))); |
| 89 | |
| 90 | CEL_RETURN_IF_ERROR(max_decl.AddOverload(MakeOverloadDecl( |
| 91 | absl::StrCat(kMaxOverloadPrefix, OverloadTypeName(type)), type, type))); |
| 92 | |
| 93 | // Pairwise overloads |
| 94 | for (const Type& other_type : kNumerics) { |
| 95 | Type out_type = DynType(); |
| 96 | if (type.kind() == other_type.kind()) { |
| 97 | out_type = type; |
| 98 | } |
| 99 | CEL_RETURN_IF_ERROR(min_decl.AddOverload(MakeOverloadDecl( |
| 100 | absl::StrCat(kMinOverloadPrefix, OverloadTypeName(type), "_", |
| 101 | OverloadTypeName(other_type)), |
| 102 | out_type, type, other_type))); |
| 103 | |
| 104 | CEL_RETURN_IF_ERROR(max_decl.AddOverload(MakeOverloadDecl( |
| 105 | absl::StrCat(kMaxOverloadPrefix, OverloadTypeName(type), "_", |
| 106 | OverloadTypeName(other_type)), |
| 107 | out_type, type, other_type))); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // List overloads |
| 112 | for (const Type& type : kListNumerics) { |
| 113 | CEL_RETURN_IF_ERROR(min_decl.AddOverload(MakeOverloadDecl( |
| 114 | absl::StrCat(kMinOverloadPrefix, OverloadTypeName(type)), |
| 115 | type.AsList()->GetElement(), type))); |
| 116 | |
| 117 | CEL_RETURN_IF_ERROR(max_decl.AddOverload(MakeOverloadDecl( |
| 118 | absl::StrCat(kMaxOverloadPrefix, OverloadTypeName(type)), |
| 119 | type.AsList()->GetElement(), type))); |
| 120 | } |
| 121 | |
| 122 | CEL_RETURN_IF_ERROR(builder.AddFunction(min_decl)); |
| 123 | CEL_RETURN_IF_ERROR(builder.AddFunction(max_decl)); |
| 124 | |
| 125 | return absl::OkStatus(); |
| 126 | } |
| 127 | |
| 128 | absl::Status AddSignednessDecls(TypeCheckerBuilder& builder) { |
no test coverage detected