github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/compiler/eval/eval_operators.go (about) 1 // Code generated - DO NOT EDIT. 2 3 package eval 4 5 import ( 6 "errors" 7 ) 8 9 func IntEquals(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 10 11 isDc := isArithmDeterministic(a, b, state) 12 13 if a.Field != "" { 14 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 15 return nil, err 16 } 17 } 18 19 if b.Field != "" { 20 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 21 return nil, err 22 } 23 } 24 25 if a.EvalFnc != nil && b.EvalFnc != nil { 26 ea, eb := a.EvalFnc, b.EvalFnc 27 28 evalFnc := func(ctx *Context) bool { 29 return ea(ctx) == eb(ctx) 30 } 31 32 return &BoolEvaluator{ 33 EvalFnc: evalFnc, 34 Weight: a.Weight + b.Weight, 35 isDeterministic: isDc, 36 }, nil 37 } 38 39 if a.EvalFnc == nil && b.EvalFnc == nil { 40 ea, eb := a.Value, b.Value 41 42 ctx := NewContext(nil) 43 _ = ctx 44 45 return &BoolEvaluator{ 46 Value: ea == eb, 47 isDeterministic: isDc, 48 }, nil 49 } 50 51 if a.EvalFnc != nil { 52 ea, eb := a.EvalFnc, b.Value 53 54 evalFnc := func(ctx *Context) bool { 55 return ea(ctx) == eb 56 } 57 58 return &BoolEvaluator{ 59 EvalFnc: evalFnc, 60 Field: a.Field, 61 Weight: a.Weight, 62 isDeterministic: isDc, 63 }, nil 64 } 65 66 ea, eb := a.Value, b.EvalFnc 67 68 evalFnc := func(ctx *Context) bool { 69 return ea == eb(ctx) 70 } 71 72 return &BoolEvaluator{ 73 EvalFnc: evalFnc, 74 Field: b.Field, 75 Weight: b.Weight, 76 isDeterministic: isDc, 77 }, nil 78 } 79 80 func IntAnd(a *IntEvaluator, b *IntEvaluator, state *State) (*IntEvaluator, error) { 81 82 isDc := isArithmDeterministic(a, b, state) 83 84 if a.Field != "" { 85 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: BitmaskValueType}); err != nil { 86 return nil, err 87 } 88 } 89 90 if b.Field != "" { 91 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: BitmaskValueType}); err != nil { 92 return nil, err 93 } 94 } 95 96 if a.EvalFnc != nil && b.EvalFnc != nil { 97 return nil, errors.New("full dynamic bitmask operation not supported") 98 } 99 100 if a.EvalFnc == nil && b.EvalFnc == nil { 101 ea, eb := a.Value, b.Value 102 103 ctx := NewContext(nil) 104 _ = ctx 105 106 return &IntEvaluator{ 107 Value: ea & eb, 108 isDeterministic: isDc, 109 }, nil 110 } 111 112 if a.EvalFnc != nil { 113 ea, eb := a.EvalFnc, b.Value 114 115 evalFnc := func(ctx *Context) int { 116 return ea(ctx) & eb 117 } 118 119 return &IntEvaluator{ 120 EvalFnc: evalFnc, 121 Field: a.Field, 122 Weight: a.Weight, 123 isDeterministic: isDc, 124 }, nil 125 } 126 127 ea, eb := a.Value, b.EvalFnc 128 129 evalFnc := func(ctx *Context) int { 130 return ea & eb(ctx) 131 } 132 133 return &IntEvaluator{ 134 EvalFnc: evalFnc, 135 Field: b.Field, 136 Weight: b.Weight, 137 isDeterministic: isDc, 138 }, nil 139 } 140 141 func IntOr(a *IntEvaluator, b *IntEvaluator, state *State) (*IntEvaluator, error) { 142 143 isDc := isArithmDeterministic(a, b, state) 144 145 if a.Field != "" { 146 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: BitmaskValueType}); err != nil { 147 return nil, err 148 } 149 } 150 151 if b.Field != "" { 152 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: BitmaskValueType}); err != nil { 153 return nil, err 154 } 155 } 156 157 if a.EvalFnc != nil && b.EvalFnc != nil { 158 return nil, errors.New("full dynamic bitmask operation not supported") 159 } 160 161 if a.EvalFnc == nil && b.EvalFnc == nil { 162 ea, eb := a.Value, b.Value 163 164 ctx := NewContext(nil) 165 _ = ctx 166 167 return &IntEvaluator{ 168 Value: ea | eb, 169 isDeterministic: isDc, 170 }, nil 171 } 172 173 if a.EvalFnc != nil { 174 ea, eb := a.EvalFnc, b.Value 175 176 evalFnc := func(ctx *Context) int { 177 return ea(ctx) | eb 178 } 179 180 return &IntEvaluator{ 181 EvalFnc: evalFnc, 182 Field: a.Field, 183 Weight: a.Weight, 184 isDeterministic: isDc, 185 }, nil 186 } 187 188 ea, eb := a.Value, b.EvalFnc 189 190 evalFnc := func(ctx *Context) int { 191 return ea | eb(ctx) 192 } 193 194 return &IntEvaluator{ 195 EvalFnc: evalFnc, 196 Field: b.Field, 197 Weight: b.Weight, 198 isDeterministic: isDc, 199 }, nil 200 } 201 202 func IntXor(a *IntEvaluator, b *IntEvaluator, state *State) (*IntEvaluator, error) { 203 204 isDc := isArithmDeterministic(a, b, state) 205 206 if a.Field != "" { 207 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: BitmaskValueType}); err != nil { 208 return nil, err 209 } 210 } 211 212 if b.Field != "" { 213 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: BitmaskValueType}); err != nil { 214 return nil, err 215 } 216 } 217 218 if a.EvalFnc != nil && b.EvalFnc != nil { 219 return nil, errors.New("full dynamic bitmask operation not supported") 220 } 221 222 if a.EvalFnc == nil && b.EvalFnc == nil { 223 ea, eb := a.Value, b.Value 224 225 ctx := NewContext(nil) 226 _ = ctx 227 228 return &IntEvaluator{ 229 Value: ea ^ eb, 230 isDeterministic: isDc, 231 }, nil 232 } 233 234 if a.EvalFnc != nil { 235 ea, eb := a.EvalFnc, b.Value 236 237 evalFnc := func(ctx *Context) int { 238 return ea(ctx) ^ eb 239 } 240 241 return &IntEvaluator{ 242 EvalFnc: evalFnc, 243 Field: a.Field, 244 Weight: a.Weight, 245 isDeterministic: isDc, 246 }, nil 247 } 248 249 ea, eb := a.Value, b.EvalFnc 250 251 evalFnc := func(ctx *Context) int { 252 return ea ^ eb(ctx) 253 } 254 255 return &IntEvaluator{ 256 EvalFnc: evalFnc, 257 Field: b.Field, 258 Weight: b.Weight, 259 isDeterministic: isDc, 260 }, nil 261 } 262 263 func IntPlus(a *IntEvaluator, b *IntEvaluator, state *State) (*IntEvaluator, error) { 264 265 isDc := isArithmDeterministic(a, b, state) 266 267 if a.Field != "" { 268 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 269 return nil, err 270 } 271 } 272 273 if b.Field != "" { 274 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 275 return nil, err 276 } 277 } 278 279 if a.EvalFnc != nil && b.EvalFnc != nil { 280 ea, eb := a.EvalFnc, b.EvalFnc 281 282 evalFnc := func(ctx *Context) int { 283 return ea(ctx) + eb(ctx) 284 } 285 286 return &IntEvaluator{ 287 EvalFnc: evalFnc, 288 Weight: a.Weight + b.Weight, 289 isDeterministic: isDc, 290 }, nil 291 } 292 293 if a.EvalFnc == nil && b.EvalFnc == nil { 294 ea, eb := a.Value, b.Value 295 296 ctx := NewContext(nil) 297 _ = ctx 298 299 return &IntEvaluator{ 300 Value: ea + eb, 301 isDeterministic: isDc, 302 }, nil 303 } 304 305 if a.EvalFnc != nil { 306 ea, eb := a.EvalFnc, b.Value 307 308 evalFnc := func(ctx *Context) int { 309 return ea(ctx) + eb 310 } 311 312 return &IntEvaluator{ 313 EvalFnc: evalFnc, 314 Field: a.Field, 315 Weight: a.Weight, 316 isDeterministic: isDc, 317 }, nil 318 } 319 320 ea, eb := a.Value, b.EvalFnc 321 322 evalFnc := func(ctx *Context) int { 323 return ea + eb(ctx) 324 } 325 326 return &IntEvaluator{ 327 EvalFnc: evalFnc, 328 Field: b.Field, 329 Weight: b.Weight, 330 isDeterministic: isDc, 331 }, nil 332 } 333 334 func IntMinus(a *IntEvaluator, b *IntEvaluator, state *State) (*IntEvaluator, error) { 335 336 isDc := isArithmDeterministic(a, b, state) 337 338 if a.Field != "" { 339 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 340 return nil, err 341 } 342 } 343 344 if b.Field != "" { 345 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 346 return nil, err 347 } 348 } 349 350 if a.EvalFnc != nil && b.EvalFnc != nil { 351 ea, eb := a.EvalFnc, b.EvalFnc 352 353 evalFnc := func(ctx *Context) int { 354 return ea(ctx) - eb(ctx) 355 } 356 357 return &IntEvaluator{ 358 EvalFnc: evalFnc, 359 Weight: a.Weight + b.Weight, 360 isDeterministic: isDc, 361 }, nil 362 } 363 364 if a.EvalFnc == nil && b.EvalFnc == nil { 365 ea, eb := a.Value, b.Value 366 367 ctx := NewContext(nil) 368 _ = ctx 369 370 return &IntEvaluator{ 371 Value: ea - eb, 372 isDeterministic: isDc, 373 }, nil 374 } 375 376 if a.EvalFnc != nil { 377 ea, eb := a.EvalFnc, b.Value 378 379 evalFnc := func(ctx *Context) int { 380 return ea(ctx) - eb 381 } 382 383 return &IntEvaluator{ 384 EvalFnc: evalFnc, 385 Field: a.Field, 386 Weight: a.Weight, 387 isDeterministic: isDc, 388 }, nil 389 } 390 391 ea, eb := a.Value, b.EvalFnc 392 393 evalFnc := func(ctx *Context) int { 394 return ea - eb(ctx) 395 } 396 397 return &IntEvaluator{ 398 EvalFnc: evalFnc, 399 Field: b.Field, 400 Weight: b.Weight, 401 isDeterministic: isDc, 402 }, nil 403 } 404 405 func BoolEquals(a *BoolEvaluator, b *BoolEvaluator, state *State) (*BoolEvaluator, error) { 406 407 isDc := isArithmDeterministic(a, b, state) 408 409 if a.Field != "" { 410 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 411 return nil, err 412 } 413 } 414 415 if b.Field != "" { 416 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 417 return nil, err 418 } 419 } 420 421 if a.EvalFnc != nil && b.EvalFnc != nil { 422 ea, eb := a.EvalFnc, b.EvalFnc 423 424 evalFnc := func(ctx *Context) bool { 425 return ea(ctx) == eb(ctx) 426 } 427 428 return &BoolEvaluator{ 429 EvalFnc: evalFnc, 430 Weight: a.Weight + b.Weight, 431 isDeterministic: isDc, 432 }, nil 433 } 434 435 if a.EvalFnc == nil && b.EvalFnc == nil { 436 ea, eb := a.Value, b.Value 437 438 ctx := NewContext(nil) 439 _ = ctx 440 441 return &BoolEvaluator{ 442 Value: ea == eb, 443 isDeterministic: isDc, 444 }, nil 445 } 446 447 if a.EvalFnc != nil { 448 ea, eb := a.EvalFnc, b.Value 449 450 evalFnc := func(ctx *Context) bool { 451 return ea(ctx) == eb 452 } 453 454 return &BoolEvaluator{ 455 EvalFnc: evalFnc, 456 Field: a.Field, 457 Weight: a.Weight, 458 isDeterministic: isDc, 459 }, nil 460 } 461 462 ea, eb := a.Value, b.EvalFnc 463 464 evalFnc := func(ctx *Context) bool { 465 return ea == eb(ctx) 466 } 467 468 return &BoolEvaluator{ 469 EvalFnc: evalFnc, 470 Field: b.Field, 471 Weight: b.Weight, 472 isDeterministic: isDc, 473 }, nil 474 } 475 476 func GreaterThan(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 477 478 isDc := isArithmDeterministic(a, b, state) 479 480 if a.Field != "" { 481 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 482 return nil, err 483 } 484 } 485 486 if b.Field != "" { 487 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 488 return nil, err 489 } 490 } 491 492 if a.EvalFnc != nil && b.EvalFnc != nil { 493 ea, eb := a.EvalFnc, b.EvalFnc 494 495 evalFnc := func(ctx *Context) bool { 496 return ea(ctx) > eb(ctx) 497 } 498 499 return &BoolEvaluator{ 500 EvalFnc: evalFnc, 501 Weight: a.Weight + b.Weight, 502 isDeterministic: isDc, 503 }, nil 504 } 505 506 if a.EvalFnc == nil && b.EvalFnc == nil { 507 ea, eb := a.Value, b.Value 508 509 ctx := NewContext(nil) 510 _ = ctx 511 512 return &BoolEvaluator{ 513 Value: ea > eb, 514 isDeterministic: isDc, 515 }, nil 516 } 517 518 if a.EvalFnc != nil { 519 ea, eb := a.EvalFnc, b.Value 520 521 evalFnc := func(ctx *Context) bool { 522 return ea(ctx) > eb 523 } 524 525 return &BoolEvaluator{ 526 EvalFnc: evalFnc, 527 Field: a.Field, 528 Weight: a.Weight, 529 isDeterministic: isDc, 530 }, nil 531 } 532 533 ea, eb := a.Value, b.EvalFnc 534 535 evalFnc := func(ctx *Context) bool { 536 return ea > eb(ctx) 537 } 538 539 return &BoolEvaluator{ 540 EvalFnc: evalFnc, 541 Field: b.Field, 542 Weight: b.Weight, 543 isDeterministic: isDc, 544 }, nil 545 } 546 547 func GreaterOrEqualThan(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 548 549 isDc := isArithmDeterministic(a, b, state) 550 551 if a.Field != "" { 552 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 553 return nil, err 554 } 555 } 556 557 if b.Field != "" { 558 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 559 return nil, err 560 } 561 } 562 563 if a.EvalFnc != nil && b.EvalFnc != nil { 564 ea, eb := a.EvalFnc, b.EvalFnc 565 566 evalFnc := func(ctx *Context) bool { 567 return ea(ctx) >= eb(ctx) 568 } 569 570 return &BoolEvaluator{ 571 EvalFnc: evalFnc, 572 Weight: a.Weight + b.Weight, 573 isDeterministic: isDc, 574 }, nil 575 } 576 577 if a.EvalFnc == nil && b.EvalFnc == nil { 578 ea, eb := a.Value, b.Value 579 580 ctx := NewContext(nil) 581 _ = ctx 582 583 return &BoolEvaluator{ 584 Value: ea >= eb, 585 isDeterministic: isDc, 586 }, nil 587 } 588 589 if a.EvalFnc != nil { 590 ea, eb := a.EvalFnc, b.Value 591 592 evalFnc := func(ctx *Context) bool { 593 return ea(ctx) >= eb 594 } 595 596 return &BoolEvaluator{ 597 EvalFnc: evalFnc, 598 Field: a.Field, 599 Weight: a.Weight, 600 isDeterministic: isDc, 601 }, nil 602 } 603 604 ea, eb := a.Value, b.EvalFnc 605 606 evalFnc := func(ctx *Context) bool { 607 return ea >= eb(ctx) 608 } 609 610 return &BoolEvaluator{ 611 EvalFnc: evalFnc, 612 Field: b.Field, 613 Weight: b.Weight, 614 isDeterministic: isDc, 615 }, nil 616 } 617 618 func LesserThan(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 619 620 isDc := isArithmDeterministic(a, b, state) 621 622 if a.Field != "" { 623 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 624 return nil, err 625 } 626 } 627 628 if b.Field != "" { 629 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 630 return nil, err 631 } 632 } 633 634 if a.EvalFnc != nil && b.EvalFnc != nil { 635 ea, eb := a.EvalFnc, b.EvalFnc 636 637 evalFnc := func(ctx *Context) bool { 638 return ea(ctx) < eb(ctx) 639 } 640 641 return &BoolEvaluator{ 642 EvalFnc: evalFnc, 643 Weight: a.Weight + b.Weight, 644 isDeterministic: isDc, 645 }, nil 646 } 647 648 if a.EvalFnc == nil && b.EvalFnc == nil { 649 ea, eb := a.Value, b.Value 650 651 ctx := NewContext(nil) 652 _ = ctx 653 654 return &BoolEvaluator{ 655 Value: ea < eb, 656 isDeterministic: isDc, 657 }, nil 658 } 659 660 if a.EvalFnc != nil { 661 ea, eb := a.EvalFnc, b.Value 662 663 evalFnc := func(ctx *Context) bool { 664 return ea(ctx) < eb 665 } 666 667 return &BoolEvaluator{ 668 EvalFnc: evalFnc, 669 Field: a.Field, 670 Weight: a.Weight, 671 isDeterministic: isDc, 672 }, nil 673 } 674 675 ea, eb := a.Value, b.EvalFnc 676 677 evalFnc := func(ctx *Context) bool { 678 return ea < eb(ctx) 679 } 680 681 return &BoolEvaluator{ 682 EvalFnc: evalFnc, 683 Field: b.Field, 684 Weight: b.Weight, 685 isDeterministic: isDc, 686 }, nil 687 } 688 689 func LesserOrEqualThan(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 690 691 isDc := isArithmDeterministic(a, b, state) 692 693 if a.Field != "" { 694 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 695 return nil, err 696 } 697 } 698 699 if b.Field != "" { 700 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 701 return nil, err 702 } 703 } 704 705 if a.EvalFnc != nil && b.EvalFnc != nil { 706 ea, eb := a.EvalFnc, b.EvalFnc 707 708 evalFnc := func(ctx *Context) bool { 709 return ea(ctx) <= eb(ctx) 710 } 711 712 return &BoolEvaluator{ 713 EvalFnc: evalFnc, 714 Weight: a.Weight + b.Weight, 715 isDeterministic: isDc, 716 }, nil 717 } 718 719 if a.EvalFnc == nil && b.EvalFnc == nil { 720 ea, eb := a.Value, b.Value 721 722 ctx := NewContext(nil) 723 _ = ctx 724 725 return &BoolEvaluator{ 726 Value: ea <= eb, 727 isDeterministic: isDc, 728 }, nil 729 } 730 731 if a.EvalFnc != nil { 732 ea, eb := a.EvalFnc, b.Value 733 734 evalFnc := func(ctx *Context) bool { 735 return ea(ctx) <= eb 736 } 737 738 return &BoolEvaluator{ 739 EvalFnc: evalFnc, 740 Field: a.Field, 741 Weight: a.Weight, 742 isDeterministic: isDc, 743 }, nil 744 } 745 746 ea, eb := a.Value, b.EvalFnc 747 748 evalFnc := func(ctx *Context) bool { 749 return ea <= eb(ctx) 750 } 751 752 return &BoolEvaluator{ 753 EvalFnc: evalFnc, 754 Field: b.Field, 755 Weight: b.Weight, 756 isDeterministic: isDc, 757 }, nil 758 } 759 760 func DurationLesserThan(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 761 762 isDc := isArithmDeterministic(a, b, state) 763 764 if a.Field != "" { 765 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 766 return nil, err 767 } 768 } 769 770 if b.Field != "" { 771 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 772 return nil, err 773 } 774 } 775 776 if a.EvalFnc != nil && b.EvalFnc != nil { 777 ea, eb := a.EvalFnc, b.EvalFnc 778 779 evalFnc := func(ctx *Context) bool { 780 return ctx.Now().UnixNano()-int64(ea(ctx)) < int64(eb(ctx)) 781 } 782 783 return &BoolEvaluator{ 784 EvalFnc: evalFnc, 785 Weight: a.Weight + b.Weight, 786 isDeterministic: isDc, 787 }, nil 788 } 789 790 if a.EvalFnc == nil && b.EvalFnc == nil { 791 ea, eb := a.Value, b.Value 792 793 ctx := NewContext(nil) 794 _ = ctx 795 796 return &BoolEvaluator{ 797 Value: ctx.Now().UnixNano()-int64(ea) < int64(eb), 798 isDeterministic: isDc, 799 }, nil 800 } 801 802 if a.EvalFnc != nil { 803 ea, eb := a.EvalFnc, b.Value 804 805 evalFnc := func(ctx *Context) bool { 806 return ctx.Now().UnixNano()-int64(ea(ctx)) < int64(eb) 807 } 808 809 return &BoolEvaluator{ 810 EvalFnc: evalFnc, 811 Field: a.Field, 812 Weight: a.Weight, 813 isDeterministic: isDc, 814 }, nil 815 } 816 817 ea, eb := a.Value, b.EvalFnc 818 819 evalFnc := func(ctx *Context) bool { 820 return ctx.Now().UnixNano()-int64(ea) < int64(eb(ctx)) 821 } 822 823 return &BoolEvaluator{ 824 EvalFnc: evalFnc, 825 Field: b.Field, 826 Weight: b.Weight, 827 isDeterministic: isDc, 828 }, nil 829 } 830 831 func DurationLesserOrEqualThan(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 832 833 isDc := isArithmDeterministic(a, b, state) 834 835 if a.Field != "" { 836 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 837 return nil, err 838 } 839 } 840 841 if b.Field != "" { 842 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 843 return nil, err 844 } 845 } 846 847 if a.EvalFnc != nil && b.EvalFnc != nil { 848 ea, eb := a.EvalFnc, b.EvalFnc 849 850 evalFnc := func(ctx *Context) bool { 851 return ctx.Now().UnixNano()-int64(ea(ctx)) <= int64(eb(ctx)) 852 } 853 854 return &BoolEvaluator{ 855 EvalFnc: evalFnc, 856 Weight: a.Weight + b.Weight, 857 isDeterministic: isDc, 858 }, nil 859 } 860 861 if a.EvalFnc == nil && b.EvalFnc == nil { 862 ea, eb := a.Value, b.Value 863 864 ctx := NewContext(nil) 865 _ = ctx 866 867 return &BoolEvaluator{ 868 Value: ctx.Now().UnixNano()-int64(ea) <= int64(eb), 869 isDeterministic: isDc, 870 }, nil 871 } 872 873 if a.EvalFnc != nil { 874 ea, eb := a.EvalFnc, b.Value 875 876 evalFnc := func(ctx *Context) bool { 877 return ctx.Now().UnixNano()-int64(ea(ctx)) <= int64(eb) 878 } 879 880 return &BoolEvaluator{ 881 EvalFnc: evalFnc, 882 Field: a.Field, 883 Weight: a.Weight, 884 isDeterministic: isDc, 885 }, nil 886 } 887 888 ea, eb := a.Value, b.EvalFnc 889 890 evalFnc := func(ctx *Context) bool { 891 return ctx.Now().UnixNano()-int64(ea) <= int64(eb(ctx)) 892 } 893 894 return &BoolEvaluator{ 895 EvalFnc: evalFnc, 896 Field: b.Field, 897 Weight: b.Weight, 898 isDeterministic: isDc, 899 }, nil 900 } 901 902 func DurationGreaterThan(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 903 904 isDc := isArithmDeterministic(a, b, state) 905 906 if a.Field != "" { 907 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 908 return nil, err 909 } 910 } 911 912 if b.Field != "" { 913 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 914 return nil, err 915 } 916 } 917 918 if a.EvalFnc != nil && b.EvalFnc != nil { 919 ea, eb := a.EvalFnc, b.EvalFnc 920 921 evalFnc := func(ctx *Context) bool { 922 return ctx.Now().UnixNano()-int64(ea(ctx)) > int64(eb(ctx)) 923 } 924 925 return &BoolEvaluator{ 926 EvalFnc: evalFnc, 927 Weight: a.Weight + b.Weight, 928 isDeterministic: isDc, 929 }, nil 930 } 931 932 if a.EvalFnc == nil && b.EvalFnc == nil { 933 ea, eb := a.Value, b.Value 934 935 ctx := NewContext(nil) 936 _ = ctx 937 938 return &BoolEvaluator{ 939 Value: ctx.Now().UnixNano()-int64(ea) > int64(eb), 940 isDeterministic: isDc, 941 }, nil 942 } 943 944 if a.EvalFnc != nil { 945 ea, eb := a.EvalFnc, b.Value 946 947 evalFnc := func(ctx *Context) bool { 948 return ctx.Now().UnixNano()-int64(ea(ctx)) > int64(eb) 949 } 950 951 return &BoolEvaluator{ 952 EvalFnc: evalFnc, 953 Field: a.Field, 954 Weight: a.Weight, 955 isDeterministic: isDc, 956 }, nil 957 } 958 959 ea, eb := a.Value, b.EvalFnc 960 961 evalFnc := func(ctx *Context) bool { 962 return ctx.Now().UnixNano()-int64(ea) > int64(eb(ctx)) 963 } 964 965 return &BoolEvaluator{ 966 EvalFnc: evalFnc, 967 Field: b.Field, 968 Weight: b.Weight, 969 isDeterministic: isDc, 970 }, nil 971 } 972 973 func DurationGreaterOrEqualThan(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 974 975 isDc := isArithmDeterministic(a, b, state) 976 977 if a.Field != "" { 978 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 979 return nil, err 980 } 981 } 982 983 if b.Field != "" { 984 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 985 return nil, err 986 } 987 } 988 989 if a.EvalFnc != nil && b.EvalFnc != nil { 990 ea, eb := a.EvalFnc, b.EvalFnc 991 992 evalFnc := func(ctx *Context) bool { 993 return ctx.Now().UnixNano()-int64(ea(ctx)) >= int64(eb(ctx)) 994 } 995 996 return &BoolEvaluator{ 997 EvalFnc: evalFnc, 998 Weight: a.Weight + b.Weight, 999 isDeterministic: isDc, 1000 }, nil 1001 } 1002 1003 if a.EvalFnc == nil && b.EvalFnc == nil { 1004 ea, eb := a.Value, b.Value 1005 1006 ctx := NewContext(nil) 1007 _ = ctx 1008 1009 return &BoolEvaluator{ 1010 Value: ctx.Now().UnixNano()-int64(ea) >= int64(eb), 1011 isDeterministic: isDc, 1012 }, nil 1013 } 1014 1015 if a.EvalFnc != nil { 1016 ea, eb := a.EvalFnc, b.Value 1017 1018 evalFnc := func(ctx *Context) bool { 1019 return ctx.Now().UnixNano()-int64(ea(ctx)) >= int64(eb) 1020 } 1021 1022 return &BoolEvaluator{ 1023 EvalFnc: evalFnc, 1024 Field: a.Field, 1025 Weight: a.Weight, 1026 isDeterministic: isDc, 1027 }, nil 1028 } 1029 1030 ea, eb := a.Value, b.EvalFnc 1031 1032 evalFnc := func(ctx *Context) bool { 1033 return ctx.Now().UnixNano()-int64(ea) >= int64(eb(ctx)) 1034 } 1035 1036 return &BoolEvaluator{ 1037 EvalFnc: evalFnc, 1038 Field: b.Field, 1039 Weight: b.Weight, 1040 isDeterministic: isDc, 1041 }, nil 1042 } 1043 1044 func DurationEqual(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 1045 1046 isDc := isArithmDeterministic(a, b, state) 1047 1048 if a.Field != "" { 1049 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 1050 return nil, err 1051 } 1052 } 1053 1054 if b.Field != "" { 1055 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1056 return nil, err 1057 } 1058 } 1059 1060 if a.EvalFnc != nil && b.EvalFnc != nil { 1061 ea, eb := a.EvalFnc, b.EvalFnc 1062 1063 evalFnc := func(ctx *Context) bool { 1064 return ctx.Now().UnixNano()-int64(ea(ctx)) == int64(eb(ctx)) 1065 } 1066 1067 return &BoolEvaluator{ 1068 EvalFnc: evalFnc, 1069 Weight: a.Weight + b.Weight, 1070 isDeterministic: isDc, 1071 }, nil 1072 } 1073 1074 if a.EvalFnc == nil && b.EvalFnc == nil { 1075 ea, eb := a.Value, b.Value 1076 1077 ctx := NewContext(nil) 1078 _ = ctx 1079 1080 return &BoolEvaluator{ 1081 Value: ctx.Now().UnixNano()-int64(ea) == int64(eb), 1082 isDeterministic: isDc, 1083 }, nil 1084 } 1085 1086 if a.EvalFnc != nil { 1087 ea, eb := a.EvalFnc, b.Value 1088 1089 evalFnc := func(ctx *Context) bool { 1090 return ctx.Now().UnixNano()-int64(ea(ctx)) == int64(eb) 1091 } 1092 1093 return &BoolEvaluator{ 1094 EvalFnc: evalFnc, 1095 Field: a.Field, 1096 Weight: a.Weight, 1097 isDeterministic: isDc, 1098 }, nil 1099 } 1100 1101 ea, eb := a.Value, b.EvalFnc 1102 1103 evalFnc := func(ctx *Context) bool { 1104 return ctx.Now().UnixNano()-int64(ea) == int64(eb(ctx)) 1105 } 1106 1107 return &BoolEvaluator{ 1108 EvalFnc: evalFnc, 1109 Field: b.Field, 1110 Weight: b.Weight, 1111 isDeterministic: isDc, 1112 }, nil 1113 } 1114 1115 func DurationLesserThanArithmeticOperation(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 1116 1117 isDc := isArithmDeterministic(a, b, state) 1118 1119 if a.Field != "" { 1120 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 1121 return nil, err 1122 } 1123 } 1124 1125 if b.Field != "" { 1126 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1127 return nil, err 1128 } 1129 } 1130 1131 if a.EvalFnc != nil && b.EvalFnc != nil { 1132 ea, eb := a.EvalFnc, b.EvalFnc 1133 1134 evalFnc := func(ctx *Context) bool { 1135 return int64(ea(ctx)) < int64(eb(ctx)) 1136 } 1137 1138 return &BoolEvaluator{ 1139 EvalFnc: evalFnc, 1140 Weight: a.Weight + b.Weight, 1141 isDeterministic: isDc, 1142 }, nil 1143 } 1144 1145 if a.EvalFnc == nil && b.EvalFnc == nil { 1146 ea, eb := a.Value, b.Value 1147 1148 ctx := NewContext(nil) 1149 _ = ctx 1150 1151 return &BoolEvaluator{ 1152 Value: int64(ea) < int64(eb), 1153 isDeterministic: isDc, 1154 }, nil 1155 } 1156 1157 if a.EvalFnc != nil { 1158 ea, eb := a.EvalFnc, b.Value 1159 1160 evalFnc := func(ctx *Context) bool { 1161 return int64(ea(ctx)) < int64(eb) 1162 } 1163 1164 return &BoolEvaluator{ 1165 EvalFnc: evalFnc, 1166 Field: a.Field, 1167 Weight: a.Weight, 1168 isDeterministic: isDc, 1169 }, nil 1170 } 1171 1172 ea, eb := a.Value, b.EvalFnc 1173 1174 evalFnc := func(ctx *Context) bool { 1175 return int64(ea) < int64(eb(ctx)) 1176 } 1177 1178 return &BoolEvaluator{ 1179 EvalFnc: evalFnc, 1180 Field: b.Field, 1181 Weight: b.Weight, 1182 isDeterministic: isDc, 1183 }, nil 1184 } 1185 1186 func DurationLesserOrEqualThanArithmeticOperation(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 1187 1188 isDc := isArithmDeterministic(a, b, state) 1189 1190 if a.Field != "" { 1191 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 1192 return nil, err 1193 } 1194 } 1195 1196 if b.Field != "" { 1197 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1198 return nil, err 1199 } 1200 } 1201 1202 if a.EvalFnc != nil && b.EvalFnc != nil { 1203 ea, eb := a.EvalFnc, b.EvalFnc 1204 1205 evalFnc := func(ctx *Context) bool { 1206 return int64(ea(ctx)) <= int64(eb(ctx)) 1207 } 1208 1209 return &BoolEvaluator{ 1210 EvalFnc: evalFnc, 1211 Weight: a.Weight + b.Weight, 1212 isDeterministic: isDc, 1213 }, nil 1214 } 1215 1216 if a.EvalFnc == nil && b.EvalFnc == nil { 1217 ea, eb := a.Value, b.Value 1218 1219 ctx := NewContext(nil) 1220 _ = ctx 1221 1222 return &BoolEvaluator{ 1223 Value: int64(ea) <= int64(eb), 1224 isDeterministic: isDc, 1225 }, nil 1226 } 1227 1228 if a.EvalFnc != nil { 1229 ea, eb := a.EvalFnc, b.Value 1230 1231 evalFnc := func(ctx *Context) bool { 1232 return int64(ea(ctx)) <= int64(eb) 1233 } 1234 1235 return &BoolEvaluator{ 1236 EvalFnc: evalFnc, 1237 Field: a.Field, 1238 Weight: a.Weight, 1239 isDeterministic: isDc, 1240 }, nil 1241 } 1242 1243 ea, eb := a.Value, b.EvalFnc 1244 1245 evalFnc := func(ctx *Context) bool { 1246 return int64(ea) <= int64(eb(ctx)) 1247 } 1248 1249 return &BoolEvaluator{ 1250 EvalFnc: evalFnc, 1251 Field: b.Field, 1252 Weight: b.Weight, 1253 isDeterministic: isDc, 1254 }, nil 1255 } 1256 1257 func DurationGreaterThanArithmeticOperation(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 1258 1259 isDc := isArithmDeterministic(a, b, state) 1260 1261 if a.Field != "" { 1262 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 1263 return nil, err 1264 } 1265 } 1266 1267 if b.Field != "" { 1268 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1269 return nil, err 1270 } 1271 } 1272 1273 if a.EvalFnc != nil && b.EvalFnc != nil { 1274 ea, eb := a.EvalFnc, b.EvalFnc 1275 1276 evalFnc := func(ctx *Context) bool { 1277 return int64(ea(ctx)) > int64(eb(ctx)) 1278 } 1279 1280 return &BoolEvaluator{ 1281 EvalFnc: evalFnc, 1282 Weight: a.Weight + b.Weight, 1283 isDeterministic: isDc, 1284 }, nil 1285 } 1286 1287 if a.EvalFnc == nil && b.EvalFnc == nil { 1288 ea, eb := a.Value, b.Value 1289 1290 ctx := NewContext(nil) 1291 _ = ctx 1292 1293 return &BoolEvaluator{ 1294 Value: int64(ea) > int64(eb), 1295 isDeterministic: isDc, 1296 }, nil 1297 } 1298 1299 if a.EvalFnc != nil { 1300 ea, eb := a.EvalFnc, b.Value 1301 1302 evalFnc := func(ctx *Context) bool { 1303 return int64(ea(ctx)) > int64(eb) 1304 } 1305 1306 return &BoolEvaluator{ 1307 EvalFnc: evalFnc, 1308 Field: a.Field, 1309 Weight: a.Weight, 1310 isDeterministic: isDc, 1311 }, nil 1312 } 1313 1314 ea, eb := a.Value, b.EvalFnc 1315 1316 evalFnc := func(ctx *Context) bool { 1317 return int64(ea) > int64(eb(ctx)) 1318 } 1319 1320 return &BoolEvaluator{ 1321 EvalFnc: evalFnc, 1322 Field: b.Field, 1323 Weight: b.Weight, 1324 isDeterministic: isDc, 1325 }, nil 1326 } 1327 1328 func DurationGreaterOrEqualThanArithmeticOperation(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 1329 1330 isDc := isArithmDeterministic(a, b, state) 1331 1332 if a.Field != "" { 1333 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 1334 return nil, err 1335 } 1336 } 1337 1338 if b.Field != "" { 1339 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1340 return nil, err 1341 } 1342 } 1343 1344 if a.EvalFnc != nil && b.EvalFnc != nil { 1345 ea, eb := a.EvalFnc, b.EvalFnc 1346 1347 evalFnc := func(ctx *Context) bool { 1348 return int64(ea(ctx)) >= int64(eb(ctx)) 1349 } 1350 1351 return &BoolEvaluator{ 1352 EvalFnc: evalFnc, 1353 Weight: a.Weight + b.Weight, 1354 isDeterministic: isDc, 1355 }, nil 1356 } 1357 1358 if a.EvalFnc == nil && b.EvalFnc == nil { 1359 ea, eb := a.Value, b.Value 1360 1361 ctx := NewContext(nil) 1362 _ = ctx 1363 1364 return &BoolEvaluator{ 1365 Value: int64(ea) >= int64(eb), 1366 isDeterministic: isDc, 1367 }, nil 1368 } 1369 1370 if a.EvalFnc != nil { 1371 ea, eb := a.EvalFnc, b.Value 1372 1373 evalFnc := func(ctx *Context) bool { 1374 return int64(ea(ctx)) >= int64(eb) 1375 } 1376 1377 return &BoolEvaluator{ 1378 EvalFnc: evalFnc, 1379 Field: a.Field, 1380 Weight: a.Weight, 1381 isDeterministic: isDc, 1382 }, nil 1383 } 1384 1385 ea, eb := a.Value, b.EvalFnc 1386 1387 evalFnc := func(ctx *Context) bool { 1388 return int64(ea) >= int64(eb(ctx)) 1389 } 1390 1391 return &BoolEvaluator{ 1392 EvalFnc: evalFnc, 1393 Field: b.Field, 1394 Weight: b.Weight, 1395 isDeterministic: isDc, 1396 }, nil 1397 } 1398 1399 func DurationEqualArithmeticOperation(a *IntEvaluator, b *IntEvaluator, state *State) (*BoolEvaluator, error) { 1400 1401 isDc := isArithmDeterministic(a, b, state) 1402 1403 if a.Field != "" { 1404 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: b.Value, Type: ScalarValueType}); err != nil { 1405 return nil, err 1406 } 1407 } 1408 1409 if b.Field != "" { 1410 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1411 return nil, err 1412 } 1413 } 1414 1415 if a.EvalFnc != nil && b.EvalFnc != nil { 1416 ea, eb := a.EvalFnc, b.EvalFnc 1417 1418 evalFnc := func(ctx *Context) bool { 1419 return int64(ea(ctx)) == int64(eb(ctx)) 1420 } 1421 1422 return &BoolEvaluator{ 1423 EvalFnc: evalFnc, 1424 Weight: a.Weight + b.Weight, 1425 isDeterministic: isDc, 1426 }, nil 1427 } 1428 1429 if a.EvalFnc == nil && b.EvalFnc == nil { 1430 ea, eb := a.Value, b.Value 1431 1432 ctx := NewContext(nil) 1433 _ = ctx 1434 1435 return &BoolEvaluator{ 1436 Value: int64(ea) == int64(eb), 1437 isDeterministic: isDc, 1438 }, nil 1439 } 1440 1441 if a.EvalFnc != nil { 1442 ea, eb := a.EvalFnc, b.Value 1443 1444 evalFnc := func(ctx *Context) bool { 1445 return int64(ea(ctx)) == int64(eb) 1446 } 1447 1448 return &BoolEvaluator{ 1449 EvalFnc: evalFnc, 1450 Field: a.Field, 1451 Weight: a.Weight, 1452 isDeterministic: isDc, 1453 }, nil 1454 } 1455 1456 ea, eb := a.Value, b.EvalFnc 1457 1458 evalFnc := func(ctx *Context) bool { 1459 return int64(ea) == int64(eb(ctx)) 1460 } 1461 1462 return &BoolEvaluator{ 1463 EvalFnc: evalFnc, 1464 Field: b.Field, 1465 Weight: b.Weight, 1466 isDeterministic: isDc, 1467 }, nil 1468 } 1469 1470 func IntArrayEquals(a *IntEvaluator, b *IntArrayEvaluator, state *State) (*BoolEvaluator, error) { 1471 1472 isDc := isArithmDeterministic(a, b, state) 1473 1474 if a.Field != "" { 1475 for _, value := range b.Values { 1476 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 1477 return nil, err 1478 } 1479 } 1480 } 1481 1482 if b.Field != "" { 1483 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1484 return nil, err 1485 } 1486 } 1487 1488 arrayOp := func(ctx *Context, a int, b []int) bool { 1489 for _, v := range b { 1490 if a == v { 1491 return true 1492 } 1493 } 1494 return false 1495 } 1496 1497 if a.EvalFnc != nil && b.EvalFnc != nil { 1498 ea, eb := a.EvalFnc, b.EvalFnc 1499 1500 evalFnc := func(ctx *Context) bool { 1501 return arrayOp(ctx, ea(ctx), eb(ctx)) 1502 } 1503 1504 return &BoolEvaluator{ 1505 EvalFnc: evalFnc, 1506 Weight: a.Weight + b.Weight, 1507 isDeterministic: isDc, 1508 }, nil 1509 } 1510 1511 if a.EvalFnc == nil && b.EvalFnc == nil { 1512 ea, eb := a.Value, b.Values 1513 1514 ctx := NewContext(nil) 1515 _ = ctx 1516 1517 return &BoolEvaluator{ 1518 Value: arrayOp(ctx, ea, eb), 1519 Weight: a.Weight + InArrayWeight*len(eb), 1520 isDeterministic: isDc, 1521 }, nil 1522 } 1523 1524 if a.EvalFnc != nil { 1525 ea, eb := a.EvalFnc, b.Values 1526 1527 evalFnc := func(ctx *Context) bool { 1528 return arrayOp(ctx, ea(ctx), eb) 1529 } 1530 1531 return &BoolEvaluator{ 1532 EvalFnc: evalFnc, 1533 Weight: a.Weight + InArrayWeight*len(eb), 1534 isDeterministic: isDc, 1535 }, nil 1536 } 1537 1538 ea, eb := a.Value, b.EvalFnc 1539 1540 evalFnc := func(ctx *Context) bool { 1541 return arrayOp(ctx, ea, eb(ctx)) 1542 } 1543 1544 return &BoolEvaluator{ 1545 EvalFnc: evalFnc, 1546 Weight: b.Weight, 1547 isDeterministic: isDc, 1548 }, nil 1549 } 1550 1551 func BoolArrayEquals(a *BoolEvaluator, b *BoolArrayEvaluator, state *State) (*BoolEvaluator, error) { 1552 1553 isDc := isArithmDeterministic(a, b, state) 1554 1555 if a.Field != "" { 1556 for _, value := range b.Values { 1557 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 1558 return nil, err 1559 } 1560 } 1561 } 1562 1563 if b.Field != "" { 1564 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1565 return nil, err 1566 } 1567 } 1568 1569 arrayOp := func(ctx *Context, a bool, b []bool) bool { 1570 for _, v := range b { 1571 if a == v { 1572 return true 1573 } 1574 } 1575 return false 1576 } 1577 1578 if a.EvalFnc != nil && b.EvalFnc != nil { 1579 ea, eb := a.EvalFnc, b.EvalFnc 1580 1581 evalFnc := func(ctx *Context) bool { 1582 return arrayOp(ctx, ea(ctx), eb(ctx)) 1583 } 1584 1585 return &BoolEvaluator{ 1586 EvalFnc: evalFnc, 1587 Weight: a.Weight + b.Weight, 1588 isDeterministic: isDc, 1589 }, nil 1590 } 1591 1592 if a.EvalFnc == nil && b.EvalFnc == nil { 1593 ea, eb := a.Value, b.Values 1594 1595 ctx := NewContext(nil) 1596 _ = ctx 1597 1598 return &BoolEvaluator{ 1599 Value: arrayOp(ctx, ea, eb), 1600 Weight: a.Weight + InArrayWeight*len(eb), 1601 isDeterministic: isDc, 1602 }, nil 1603 } 1604 1605 if a.EvalFnc != nil { 1606 ea, eb := a.EvalFnc, b.Values 1607 1608 evalFnc := func(ctx *Context) bool { 1609 return arrayOp(ctx, ea(ctx), eb) 1610 } 1611 1612 return &BoolEvaluator{ 1613 EvalFnc: evalFnc, 1614 Weight: a.Weight + InArrayWeight*len(eb), 1615 isDeterministic: isDc, 1616 }, nil 1617 } 1618 1619 ea, eb := a.Value, b.EvalFnc 1620 1621 evalFnc := func(ctx *Context) bool { 1622 return arrayOp(ctx, ea, eb(ctx)) 1623 } 1624 1625 return &BoolEvaluator{ 1626 EvalFnc: evalFnc, 1627 Weight: b.Weight, 1628 isDeterministic: isDc, 1629 }, nil 1630 } 1631 1632 func IntArrayGreaterThan(a *IntEvaluator, b *IntArrayEvaluator, state *State) (*BoolEvaluator, error) { 1633 1634 isDc := isArithmDeterministic(a, b, state) 1635 1636 if a.Field != "" { 1637 for _, value := range b.Values { 1638 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 1639 return nil, err 1640 } 1641 } 1642 } 1643 1644 if b.Field != "" { 1645 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1646 return nil, err 1647 } 1648 } 1649 1650 arrayOp := func(ctx *Context, a int, b []int) bool { 1651 for _, v := range b { 1652 if a > v { 1653 return true 1654 } 1655 } 1656 return false 1657 } 1658 1659 if a.EvalFnc != nil && b.EvalFnc != nil { 1660 ea, eb := a.EvalFnc, b.EvalFnc 1661 1662 evalFnc := func(ctx *Context) bool { 1663 return arrayOp(ctx, ea(ctx), eb(ctx)) 1664 } 1665 1666 return &BoolEvaluator{ 1667 EvalFnc: evalFnc, 1668 Weight: a.Weight + b.Weight, 1669 isDeterministic: isDc, 1670 }, nil 1671 } 1672 1673 if a.EvalFnc == nil && b.EvalFnc == nil { 1674 ea, eb := a.Value, b.Values 1675 1676 ctx := NewContext(nil) 1677 _ = ctx 1678 1679 return &BoolEvaluator{ 1680 Value: arrayOp(ctx, ea, eb), 1681 Weight: a.Weight + InArrayWeight*len(eb), 1682 isDeterministic: isDc, 1683 }, nil 1684 } 1685 1686 if a.EvalFnc != nil { 1687 ea, eb := a.EvalFnc, b.Values 1688 1689 evalFnc := func(ctx *Context) bool { 1690 return arrayOp(ctx, ea(ctx), eb) 1691 } 1692 1693 return &BoolEvaluator{ 1694 EvalFnc: evalFnc, 1695 Weight: a.Weight + InArrayWeight*len(eb), 1696 isDeterministic: isDc, 1697 }, nil 1698 } 1699 1700 ea, eb := a.Value, b.EvalFnc 1701 1702 evalFnc := func(ctx *Context) bool { 1703 return arrayOp(ctx, ea, eb(ctx)) 1704 } 1705 1706 return &BoolEvaluator{ 1707 EvalFnc: evalFnc, 1708 Weight: b.Weight, 1709 isDeterministic: isDc, 1710 }, nil 1711 } 1712 1713 func IntArrayGreaterOrEqualThan(a *IntEvaluator, b *IntArrayEvaluator, state *State) (*BoolEvaluator, error) { 1714 1715 isDc := isArithmDeterministic(a, b, state) 1716 1717 if a.Field != "" { 1718 for _, value := range b.Values { 1719 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 1720 return nil, err 1721 } 1722 } 1723 } 1724 1725 if b.Field != "" { 1726 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1727 return nil, err 1728 } 1729 } 1730 1731 arrayOp := func(ctx *Context, a int, b []int) bool { 1732 for _, v := range b { 1733 if a >= v { 1734 return true 1735 } 1736 } 1737 return false 1738 } 1739 1740 if a.EvalFnc != nil && b.EvalFnc != nil { 1741 ea, eb := a.EvalFnc, b.EvalFnc 1742 1743 evalFnc := func(ctx *Context) bool { 1744 return arrayOp(ctx, ea(ctx), eb(ctx)) 1745 } 1746 1747 return &BoolEvaluator{ 1748 EvalFnc: evalFnc, 1749 Weight: a.Weight + b.Weight, 1750 isDeterministic: isDc, 1751 }, nil 1752 } 1753 1754 if a.EvalFnc == nil && b.EvalFnc == nil { 1755 ea, eb := a.Value, b.Values 1756 1757 ctx := NewContext(nil) 1758 _ = ctx 1759 1760 return &BoolEvaluator{ 1761 Value: arrayOp(ctx, ea, eb), 1762 Weight: a.Weight + InArrayWeight*len(eb), 1763 isDeterministic: isDc, 1764 }, nil 1765 } 1766 1767 if a.EvalFnc != nil { 1768 ea, eb := a.EvalFnc, b.Values 1769 1770 evalFnc := func(ctx *Context) bool { 1771 return arrayOp(ctx, ea(ctx), eb) 1772 } 1773 1774 return &BoolEvaluator{ 1775 EvalFnc: evalFnc, 1776 Weight: a.Weight + InArrayWeight*len(eb), 1777 isDeterministic: isDc, 1778 }, nil 1779 } 1780 1781 ea, eb := a.Value, b.EvalFnc 1782 1783 evalFnc := func(ctx *Context) bool { 1784 return arrayOp(ctx, ea, eb(ctx)) 1785 } 1786 1787 return &BoolEvaluator{ 1788 EvalFnc: evalFnc, 1789 Weight: b.Weight, 1790 isDeterministic: isDc, 1791 }, nil 1792 } 1793 1794 func IntArrayLesserThan(a *IntEvaluator, b *IntArrayEvaluator, state *State) (*BoolEvaluator, error) { 1795 1796 isDc := isArithmDeterministic(a, b, state) 1797 1798 if a.Field != "" { 1799 for _, value := range b.Values { 1800 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 1801 return nil, err 1802 } 1803 } 1804 } 1805 1806 if b.Field != "" { 1807 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1808 return nil, err 1809 } 1810 } 1811 1812 arrayOp := func(ctx *Context, a int, b []int) bool { 1813 for _, v := range b { 1814 if a < v { 1815 return true 1816 } 1817 } 1818 return false 1819 } 1820 1821 if a.EvalFnc != nil && b.EvalFnc != nil { 1822 ea, eb := a.EvalFnc, b.EvalFnc 1823 1824 evalFnc := func(ctx *Context) bool { 1825 return arrayOp(ctx, ea(ctx), eb(ctx)) 1826 } 1827 1828 return &BoolEvaluator{ 1829 EvalFnc: evalFnc, 1830 Weight: a.Weight + b.Weight, 1831 isDeterministic: isDc, 1832 }, nil 1833 } 1834 1835 if a.EvalFnc == nil && b.EvalFnc == nil { 1836 ea, eb := a.Value, b.Values 1837 1838 ctx := NewContext(nil) 1839 _ = ctx 1840 1841 return &BoolEvaluator{ 1842 Value: arrayOp(ctx, ea, eb), 1843 Weight: a.Weight + InArrayWeight*len(eb), 1844 isDeterministic: isDc, 1845 }, nil 1846 } 1847 1848 if a.EvalFnc != nil { 1849 ea, eb := a.EvalFnc, b.Values 1850 1851 evalFnc := func(ctx *Context) bool { 1852 return arrayOp(ctx, ea(ctx), eb) 1853 } 1854 1855 return &BoolEvaluator{ 1856 EvalFnc: evalFnc, 1857 Weight: a.Weight + InArrayWeight*len(eb), 1858 isDeterministic: isDc, 1859 }, nil 1860 } 1861 1862 ea, eb := a.Value, b.EvalFnc 1863 1864 evalFnc := func(ctx *Context) bool { 1865 return arrayOp(ctx, ea, eb(ctx)) 1866 } 1867 1868 return &BoolEvaluator{ 1869 EvalFnc: evalFnc, 1870 Weight: b.Weight, 1871 isDeterministic: isDc, 1872 }, nil 1873 } 1874 1875 func IntArrayLesserOrEqualThan(a *IntEvaluator, b *IntArrayEvaluator, state *State) (*BoolEvaluator, error) { 1876 1877 isDc := isArithmDeterministic(a, b, state) 1878 1879 if a.Field != "" { 1880 for _, value := range b.Values { 1881 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 1882 return nil, err 1883 } 1884 } 1885 } 1886 1887 if b.Field != "" { 1888 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1889 return nil, err 1890 } 1891 } 1892 1893 arrayOp := func(ctx *Context, a int, b []int) bool { 1894 for _, v := range b { 1895 if a <= v { 1896 return true 1897 } 1898 } 1899 return false 1900 } 1901 1902 if a.EvalFnc != nil && b.EvalFnc != nil { 1903 ea, eb := a.EvalFnc, b.EvalFnc 1904 1905 evalFnc := func(ctx *Context) bool { 1906 return arrayOp(ctx, ea(ctx), eb(ctx)) 1907 } 1908 1909 return &BoolEvaluator{ 1910 EvalFnc: evalFnc, 1911 Weight: a.Weight + b.Weight, 1912 isDeterministic: isDc, 1913 }, nil 1914 } 1915 1916 if a.EvalFnc == nil && b.EvalFnc == nil { 1917 ea, eb := a.Value, b.Values 1918 1919 ctx := NewContext(nil) 1920 _ = ctx 1921 1922 return &BoolEvaluator{ 1923 Value: arrayOp(ctx, ea, eb), 1924 Weight: a.Weight + InArrayWeight*len(eb), 1925 isDeterministic: isDc, 1926 }, nil 1927 } 1928 1929 if a.EvalFnc != nil { 1930 ea, eb := a.EvalFnc, b.Values 1931 1932 evalFnc := func(ctx *Context) bool { 1933 return arrayOp(ctx, ea(ctx), eb) 1934 } 1935 1936 return &BoolEvaluator{ 1937 EvalFnc: evalFnc, 1938 Weight: a.Weight + InArrayWeight*len(eb), 1939 isDeterministic: isDc, 1940 }, nil 1941 } 1942 1943 ea, eb := a.Value, b.EvalFnc 1944 1945 evalFnc := func(ctx *Context) bool { 1946 return arrayOp(ctx, ea, eb(ctx)) 1947 } 1948 1949 return &BoolEvaluator{ 1950 EvalFnc: evalFnc, 1951 Weight: b.Weight, 1952 isDeterministic: isDc, 1953 }, nil 1954 } 1955 1956 func DurationArrayLesserThan(a *IntEvaluator, b *IntArrayEvaluator, state *State) (*BoolEvaluator, error) { 1957 1958 isDc := isArithmDeterministic(a, b, state) 1959 1960 if a.Field != "" { 1961 for _, value := range b.Values { 1962 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 1963 return nil, err 1964 } 1965 } 1966 } 1967 1968 if b.Field != "" { 1969 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 1970 return nil, err 1971 } 1972 } 1973 1974 arrayOp := func(ctx *Context, a int, b []int) bool { 1975 for _, v := range b { 1976 if ctx.Now().UnixNano()-int64(a) < int64(v) { 1977 return true 1978 } 1979 } 1980 return false 1981 } 1982 1983 if a.EvalFnc != nil && b.EvalFnc != nil { 1984 ea, eb := a.EvalFnc, b.EvalFnc 1985 1986 evalFnc := func(ctx *Context) bool { 1987 return arrayOp(ctx, ea(ctx), eb(ctx)) 1988 } 1989 1990 return &BoolEvaluator{ 1991 EvalFnc: evalFnc, 1992 Weight: a.Weight + b.Weight, 1993 isDeterministic: isDc, 1994 }, nil 1995 } 1996 1997 if a.EvalFnc == nil && b.EvalFnc == nil { 1998 ea, eb := a.Value, b.Values 1999 2000 ctx := NewContext(nil) 2001 _ = ctx 2002 2003 return &BoolEvaluator{ 2004 Value: arrayOp(ctx, ea, eb), 2005 Weight: a.Weight + InArrayWeight*len(eb), 2006 isDeterministic: isDc, 2007 }, nil 2008 } 2009 2010 if a.EvalFnc != nil { 2011 ea, eb := a.EvalFnc, b.Values 2012 2013 evalFnc := func(ctx *Context) bool { 2014 return arrayOp(ctx, ea(ctx), eb) 2015 } 2016 2017 return &BoolEvaluator{ 2018 EvalFnc: evalFnc, 2019 Weight: a.Weight + InArrayWeight*len(eb), 2020 isDeterministic: isDc, 2021 }, nil 2022 } 2023 2024 ea, eb := a.Value, b.EvalFnc 2025 2026 evalFnc := func(ctx *Context) bool { 2027 return arrayOp(ctx, ea, eb(ctx)) 2028 } 2029 2030 return &BoolEvaluator{ 2031 EvalFnc: evalFnc, 2032 Weight: b.Weight, 2033 isDeterministic: isDc, 2034 }, nil 2035 } 2036 2037 func DurationArrayLesserOrEqualThan(a *IntEvaluator, b *IntArrayEvaluator, state *State) (*BoolEvaluator, error) { 2038 2039 isDc := isArithmDeterministic(a, b, state) 2040 2041 if a.Field != "" { 2042 for _, value := range b.Values { 2043 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 2044 return nil, err 2045 } 2046 } 2047 } 2048 2049 if b.Field != "" { 2050 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 2051 return nil, err 2052 } 2053 } 2054 2055 arrayOp := func(ctx *Context, a int, b []int) bool { 2056 for _, v := range b { 2057 if ctx.Now().UnixNano()-int64(a) <= int64(v) { 2058 return true 2059 } 2060 } 2061 return false 2062 } 2063 2064 if a.EvalFnc != nil && b.EvalFnc != nil { 2065 ea, eb := a.EvalFnc, b.EvalFnc 2066 2067 evalFnc := func(ctx *Context) bool { 2068 return arrayOp(ctx, ea(ctx), eb(ctx)) 2069 } 2070 2071 return &BoolEvaluator{ 2072 EvalFnc: evalFnc, 2073 Weight: a.Weight + b.Weight, 2074 isDeterministic: isDc, 2075 }, nil 2076 } 2077 2078 if a.EvalFnc == nil && b.EvalFnc == nil { 2079 ea, eb := a.Value, b.Values 2080 2081 ctx := NewContext(nil) 2082 _ = ctx 2083 2084 return &BoolEvaluator{ 2085 Value: arrayOp(ctx, ea, eb), 2086 Weight: a.Weight + InArrayWeight*len(eb), 2087 isDeterministic: isDc, 2088 }, nil 2089 } 2090 2091 if a.EvalFnc != nil { 2092 ea, eb := a.EvalFnc, b.Values 2093 2094 evalFnc := func(ctx *Context) bool { 2095 return arrayOp(ctx, ea(ctx), eb) 2096 } 2097 2098 return &BoolEvaluator{ 2099 EvalFnc: evalFnc, 2100 Weight: a.Weight + InArrayWeight*len(eb), 2101 isDeterministic: isDc, 2102 }, nil 2103 } 2104 2105 ea, eb := a.Value, b.EvalFnc 2106 2107 evalFnc := func(ctx *Context) bool { 2108 return arrayOp(ctx, ea, eb(ctx)) 2109 } 2110 2111 return &BoolEvaluator{ 2112 EvalFnc: evalFnc, 2113 Weight: b.Weight, 2114 isDeterministic: isDc, 2115 }, nil 2116 } 2117 2118 func DurationArrayGreaterThan(a *IntEvaluator, b *IntArrayEvaluator, state *State) (*BoolEvaluator, error) { 2119 2120 isDc := isArithmDeterministic(a, b, state) 2121 2122 if a.Field != "" { 2123 for _, value := range b.Values { 2124 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 2125 return nil, err 2126 } 2127 } 2128 } 2129 2130 if b.Field != "" { 2131 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 2132 return nil, err 2133 } 2134 } 2135 2136 arrayOp := func(ctx *Context, a int, b []int) bool { 2137 for _, v := range b { 2138 if ctx.Now().UnixNano()-int64(a) > int64(v) { 2139 return true 2140 } 2141 } 2142 return false 2143 } 2144 2145 if a.EvalFnc != nil && b.EvalFnc != nil { 2146 ea, eb := a.EvalFnc, b.EvalFnc 2147 2148 evalFnc := func(ctx *Context) bool { 2149 return arrayOp(ctx, ea(ctx), eb(ctx)) 2150 } 2151 2152 return &BoolEvaluator{ 2153 EvalFnc: evalFnc, 2154 Weight: a.Weight + b.Weight, 2155 isDeterministic: isDc, 2156 }, nil 2157 } 2158 2159 if a.EvalFnc == nil && b.EvalFnc == nil { 2160 ea, eb := a.Value, b.Values 2161 2162 ctx := NewContext(nil) 2163 _ = ctx 2164 2165 return &BoolEvaluator{ 2166 Value: arrayOp(ctx, ea, eb), 2167 Weight: a.Weight + InArrayWeight*len(eb), 2168 isDeterministic: isDc, 2169 }, nil 2170 } 2171 2172 if a.EvalFnc != nil { 2173 ea, eb := a.EvalFnc, b.Values 2174 2175 evalFnc := func(ctx *Context) bool { 2176 return arrayOp(ctx, ea(ctx), eb) 2177 } 2178 2179 return &BoolEvaluator{ 2180 EvalFnc: evalFnc, 2181 Weight: a.Weight + InArrayWeight*len(eb), 2182 isDeterministic: isDc, 2183 }, nil 2184 } 2185 2186 ea, eb := a.Value, b.EvalFnc 2187 2188 evalFnc := func(ctx *Context) bool { 2189 return arrayOp(ctx, ea, eb(ctx)) 2190 } 2191 2192 return &BoolEvaluator{ 2193 EvalFnc: evalFnc, 2194 Weight: b.Weight, 2195 isDeterministic: isDc, 2196 }, nil 2197 } 2198 2199 func DurationArrayGreaterOrEqualThan(a *IntEvaluator, b *IntArrayEvaluator, state *State) (*BoolEvaluator, error) { 2200 2201 isDc := isArithmDeterministic(a, b, state) 2202 2203 if a.Field != "" { 2204 for _, value := range b.Values { 2205 if err := state.UpdateFieldValues(a.Field, FieldValue{Value: value, Type: ScalarValueType}); err != nil { 2206 return nil, err 2207 } 2208 } 2209 } 2210 2211 if b.Field != "" { 2212 if err := state.UpdateFieldValues(b.Field, FieldValue{Value: a.Value, Type: ScalarValueType}); err != nil { 2213 return nil, err 2214 } 2215 } 2216 2217 arrayOp := func(ctx *Context, a int, b []int) bool { 2218 for _, v := range b { 2219 if ctx.Now().UnixNano()-int64(a) >= int64(v) { 2220 return true 2221 } 2222 } 2223 return false 2224 } 2225 2226 if a.EvalFnc != nil && b.EvalFnc != nil { 2227 ea, eb := a.EvalFnc, b.EvalFnc 2228 2229 evalFnc := func(ctx *Context) bool { 2230 return arrayOp(ctx, ea(ctx), eb(ctx)) 2231 } 2232 2233 return &BoolEvaluator{ 2234 EvalFnc: evalFnc, 2235 Weight: a.Weight + b.Weight, 2236 isDeterministic: isDc, 2237 }, nil 2238 } 2239 2240 if a.EvalFnc == nil && b.EvalFnc == nil { 2241 ea, eb := a.Value, b.Values 2242 2243 ctx := NewContext(nil) 2244 _ = ctx 2245 2246 return &BoolEvaluator{ 2247 Value: arrayOp(ctx, ea, eb), 2248 Weight: a.Weight + InArrayWeight*len(eb), 2249 isDeterministic: isDc, 2250 }, nil 2251 } 2252 2253 if a.EvalFnc != nil { 2254 ea, eb := a.EvalFnc, b.Values 2255 2256 evalFnc := func(ctx *Context) bool { 2257 return arrayOp(ctx, ea(ctx), eb) 2258 } 2259 2260 return &BoolEvaluator{ 2261 EvalFnc: evalFnc, 2262 Weight: a.Weight + InArrayWeight*len(eb), 2263 isDeterministic: isDc, 2264 }, nil 2265 } 2266 2267 ea, eb := a.Value, b.EvalFnc 2268 2269 evalFnc := func(ctx *Context) bool { 2270 return arrayOp(ctx, ea, eb(ctx)) 2271 } 2272 2273 return &BoolEvaluator{ 2274 EvalFnc: evalFnc, 2275 Weight: b.Weight, 2276 isDeterministic: isDc, 2277 }, nil 2278 }